Skip to main content

Python HTTP for Humans.

Project description

cngn-python-library

CNGnManager is a Python library for interacting with a CNGN API. It provides a simple interface for various operations such as checking balance, swapping between chains, depositing for redemption, creating virtual accounts, and more.

Table of Contents

Installation

To install CNGnManager and its dependencies, run:

pip install cngn-manager

Usage

First, import the CNGnManager WalletManager class using and all necessary constants.

from cngn_manager import CNGnManager, WalletManager, Network, ProviderType, AssetType

Then, create an instance of CNGnManager with your secrets:

import os

api_key = "cngn_live_sk**********"
encryption_key = "yourencryptionkey"
ssh_private_key = """-----BEGIN OPENSSH PRIVATE KEY-----
your ssh key
-----END OPENSSH PRIVATE KEY-----"""

# NOTE: You can also get your private key from a file using
# ssh_private_key = os.open("/path/to/sshkey.key").read()

manager = CNGnManager(api_key, ssh_private_key, encryption_key)
# Example: Get balance
balance = manager.get_balance()
print(balance)

Networks

The library supports multiple blockchain networks:

  • Network.bsc - Binance Smart Chain
  • Network.atc - Asset Chain
  • Network.xbn - Bantu Chain
  • Network.eth - Ethereum
  • Network.matic - Polygon (Matic)
  • Network.trx - Tron
  • Network.base - Base

Available Methods

cNGNManager Methods

Get Balance

balance = manager.get_balance()
print(balance)

Get Transaction History

transactions = manager.get_transaction_history()
print(transactions)

Swap Between Chains

swap_params = {
    "amount": 100,
    "address": "0x1234...",
    "network": Network.BSC,
    "shouldSaveAddress": True
}

swap_result = manager.swap_between_chains(swap_params)
print(swap_result)

Redeem Asset

deposit_params = {
    "amount": 1000,
    "bankCode": "123",
    "accountNumber": "1234567890",
    "saveDetails": True
}

deposit_result = manager.deposit_for_redemption(deposit_params)
print(deposit_result)

NOTE: to get bank codes please use the getBanks method to fetch the list of banks and ther codes

Create Virtual Account

mint_params = {
    "provider": ProviderType.KORAPAY
}

virtual_account = manager.create_virtual_account(mint_params)
print(virtual_account)

NOTE: before creating the virtual account you need to have updated your BVN on the dashboard

Generate Wallet Address

wallet_address = manager.generate_wallet_address(Network.BSC)
print(wallet_address)

Update Business

Address Options: "xbnAddress": "string"; "bscAddress": "string"; "atcAddress": "string"; "polygonAddress": "string"; "ethAddress": "string"; "tronAddress": "string"; "baseAddress": "string"; "bantuUserId": "string";

updateData  = {
    "walletAddress": {
        "bscAddress": "0x1234...",
        #other chain addresses...
    },
    "bankDetails": {
        "bankName": 'Test Bank',
        "bankAccountName": 'Test Account',
        "bankAccountNumber": '1234567890'
    }
}

updateResult = manager.update_external_accounts(updateData)
print(updateResult)

Get banks

banklist = manager.get_banks(updateData)
print(banklist)

WalletManager Methods

Generate Wallet Address

    wallet = WalletManager.generate_wallet_address(Network.bsc);

Response format:

 {
    "mnemonic" : "string";
    "address": "string";
    "network": Network;
    "privateKey": "string";
}

Testing

This project uses Jest for testing. To run the tests, follow these steps:

  1. Run the test command:
python3 -m unittest discover tests

This will run all tests in the tests directory.

Test Structure

The tests are located in the tests directory. They cover various aspects of the CNGnManager class, including:

  • API calls for different endpoints (GET and POST requests)
  • Encryption and decryption of data
  • Error handling for various scenarios

Error Handling

The library uses a custom error handling mechanism. All API errors are caught and thrown as Error objects with descriptive messages.

Constants

The library includes python constant classes for all parameters:

  • Network - token network
  • AssetType - Asset constants
  • ProviderType - provider constants

Security

  • Uses AES encryption for request data
  • Implements Ed25519 decryption for responses
  • Requires secure storage of API credentials

Contributing

To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Create a Pull Request

Support

For support, please:

  • Open an issue in the GitHub repository
  • Check existing documentation
  • Contact the support team

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cngn_manager-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cngn_manager-1.0.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file cngn_manager-1.0.0.tar.gz.

File metadata

  • Download URL: cngn_manager-1.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for cngn_manager-1.0.0.tar.gz
Algorithm Hash digest
SHA256 319a8b64a1df4db84f2d4d8d6d0d334932f24400b8a492ac5e19d6f7dfa71b24
MD5 e8b064d99f3c82b46c27680e281884f7
BLAKE2b-256 d662f3c11ca3ee3aabfd124dea953a65b131648e04b6ef27407c6f2442258643

See more details on using hashes here.

File details

Details for the file cngn_manager-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cngn_manager-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for cngn_manager-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7cf5daa7f00f0da75b4b46404d7432ba04ea763256f488b60b33bb1473f24331
MD5 558adb9c3885d4b6c4575a11b2f2b05c
BLAKE2b-256 e11ccd81aa16af873397f942c0aead1dec8440f1d708cdf4abd3d556f49e45da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page