cngn-typescript-library
v1.0.5
Published
A lightweight Typescript library to give you the best experience with managing your cngn merchant account
Downloads
497
Maintainers
Readme
cngn-typescript-library
cngn-typescript-library is a TypeScript library for interacting with the cNGN API. It provides a simple interface for various operations such as checking balance, withdraw from chains, depositing for redemption, creating virtual accounts, generating wallet addresses, and more.
Table of Contents
- Installation
- Usage
- Networks
- Available Methods
- Testing
- Error Handling
- Types
- Security
- Contributing
- Support
- License
Installation
To install cngn-typescript-library and its dependencies, run:
npm install cngn-typescript-library
Usage
First, import the necessary classes and types:
import {
cNGNManager,
WalletManager,
Secrets,
IWithdraw,
RedeemAsset,
CreateVirtualAccount,
UpdateExternalAccount,
Network
} from 'cngn-typescript-library';
Then, create an instance of cNGNManager
with your secrets:
const secrets: Secrets = {
apiKey: 'your-api-key',
privateKey: 'your-private-key',
encryptionKey: 'your-encryption-key'
};
const manager = new cNGNManager(secrets);
// Example: Get balance
manager.getBalance().then(balance => console.log(balance));
Networks
The library supports multiple blockchain networks:
Network.bsc
- Binance Smart ChainNetwork.atc
- Asset ChainNetwork.xbn
- Bantu ChainNetwork.eth
- EthereumNetwork.matic
- Polygon (Matic)Network.trx
- TronNetwork.base
- Base
Available Methods
cNGNManager Methods
Get Balance
const balance = await manager.getBalance();
Get Transaction History
const transactions = await manager.getTransactionHistory();
Withdraw from chains
const withdrawData: IWithdraw = {
amount: 1000,
address: '0x789...',
network: Network.bsc,
shouldSaveAddress: true
};
const withdrawResult = await manager.withdraw(withdrawData);
Redeem Asset
const redeemData: RedeemAsset = {
amount: 1000,
bankCode: '123',
accountNumber: '1234567890',
saveDetails: true
};
const redeemResult = await manager.redeemAsset(redeemData);
Create Virtual Account
const mintData: CreateVirtualAccount = {
provider: 'korapay', // default provider
bank_code: '011'
};
const virtualAccount = await manager.createVirtualAccount(mintData);
Update Business
const updateData: UpdateExternalAccount = {
walletAddress: {
bscAddress: '0x123...',
// other chain addresses...
},
bankDetails: {
bankName: 'Test Bank',
bankAccountName: 'Test Account',
bankAccountNumber: '1234567890'
}
};
const updateResult = await manager.updateExternalAccounts(updateData);
Get Banks
const banks = await manager.getBanks();
WalletManager Methods
Generate Wallet Address
const wallet = await WalletManager.generateWalletAddress(Network.bsc);
Response format:
interface GeneratedWalletAddress {
mnemonic: string;
address: string;
network: Network;
privateKey: string;
}
Testing
To run the tests:
- Install dependencies:
npm install
- Run tests:
npm test
- Run tests with coverage:
npm test --coverage
Test files follow the naming convention: *.test.ts
and are located in the __tests__
directory.
Error Handling
The library implements comprehensive error handling:
try {
const result = await manager.getBalance();
} catch (error) {
// Error will contain detailed message about the failure
console.error(error.message);
}
Common error types:
- API errors (with status codes)
- Network connectivity issues
- Invalid parameters
- Wallet generation errors
Types
The library includes TypeScript definitions for all parameters and return types:
Secrets
- API credentials and keysIResponse<T>
- Standard API response wrapperBalance
- Account balance informationTransactions
- Transaction detailsWithdraw
- Withdraw parametersRedeemAsset
- Asset redemption detailsCreateVirtualAccount
- Virtual account creation parametersUpdateExternalAccount
- Business update parameters and wallet addressesGeneratedWalletAddress
- Wallet generation response
Security
- Uses AES encryption for request data
- Implements Ed25519 decryption for responses
- Requires secure storage of API credentials
Contributing
To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a Pull Request
Support
For support, please:
- Open an issue in the GitHub repository
- Check existing documentation
- Contact the support team