npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

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

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

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:

  1. Install dependencies:
npm install
  1. Run tests:
npm test
  1. 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 keys
  • IResponse<T> - Standard API response wrapper
  • Balance - Account balance information
  • Transactions - Transaction details
  • Withdraw - Withdraw parameters
  • RedeemAsset - Asset redemption details
  • CreateVirtualAccount - Virtual account creation parameters
  • UpdateExternalAccount - Business update parameters and wallet addresses
  • GeneratedWalletAddress - Wallet generation response

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

ISC