Skip to content

A comprehensive Python library for seamless integration with the cNGN API, enabling secure cross-chain transactions and digital asset/crypto wallet management.

License

Notifications You must be signed in to change notification settings

wrappedcbdc/cngn-python-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.ETTH - 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

page = 1 #page
limit = 10 #limit
transactions = manager.get_transaction_history(page, limit)
print(transactions)

Withdraw from chains

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

withdraw_result = manager.withdraw(withdraw_params)
print(withdraw_result)

Verify Withdrawal Reference

tnxRef =  '123-456-789-789405' # Transaction Ref

verify_result = manager.verify_withdrawal(withdraw_params)
print(verify_result)

Redeem Asset

deposit_params = {
    "amount": 1000, # Amount
    "bankCode": "123", # bankCode
    "accountNumber": "1234567890", # Account Number
    "saveDetails": True
}

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

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

Create Virtual Account

mint_params = {
    "provider": ProviderType.KORAPAY, # provider
    "bank_code": '011' # bank_code
}

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

Bridge Asset

swap_data = {
    "destinationNetwork": Network.BSC, #destinationNetwork
    "destinationAddress": '0x123...', # destinationAddress
    "originNetwork": Network.ETH, # originNetwork
    "callbackUrl": 'https://your-callback-url.com' # optional
}

swap_result = manager.swap_asset(swap_data)
print(swap_result)

Swap Quotes

swap_data = {
    "destinationNetwork": Network.BSC, #destinationNetwork
    "destinationAddress": '0x123...', # destinationAddress
    "originNetwork": Network.ETH, # originNetwork
    "amount": 1000
}

swap_result = manager.swap_quote(swap_data)
print(swap_result)

Update Business

Address Options:

  • "xbnAddress": "string";
  • "bscAddress": "string";
  • "atcAddress": "string";
  • "polygonAddress": "string";
  • "ethAddress": "string";
  • "tronAddress": "string";
  • "baseAddress": "string";
  • "bantuUserId": "string";
updateData  = {
    "walletAddress": {
        "bscAddress": "0x1234...", #bscAddress
        #other chain addresses...
    },
    "bankDetails": {
        "bankName": 'Test Bank', # bankName
        "bankAccountName": 'Test Account', #bankAccountName
        "bankAccountNumber": '1234567890' # bankAccountNumber
    }
}

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

Get banks

banklist = manager.get_banks()
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

About

A comprehensive Python library for seamless integration with the cNGN API, enabling secure cross-chain transactions and digital asset/crypto wallet management.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages