cryptoforce-sdk
v1.0.5
Published
CryptoForce SDK is a TypeScript library for interacting with the Crypto Force API. It provides a convenient way to integrate your application with the CryptoForce services. Below is a guide on how to use the SDK.
Downloads
344
Readme
CryptoForce SDK
CryptoForce SDK is a TypeScript library for interacting with the Crypto Force API. It provides a convenient way to integrate your application with the CryptoForce services. Below is a guide on how to use the SDK.
Installation
Using npm:
npm install cryptoforce-sdk
Usage
importing CryptoForceProvider:
import { CryptoForceProvider } from 'cryptoforce-sdk';
Instantiate it as:
const cryptoForceProvider = new CryptoForceProvider({
baseUrl: 'https://crypto-node.test.url/api/v1',
tenantName: 'testTenant',
apiKey: '48e7fbdf-65f3-4fa3-9b44-149d2d593d8d',
// NOTE: not used for now
// auth: {
// username: 'admin',
// password: 'admin',
// },
sslConfig: {
ca: fs.readFileSync('./certificates/ca.crt'),
cert: fs.readFileSync('./certificates/cert.crt'),
key: fs.readFileSync('./certificates/key.crt'),
},
});
Configuration
- baseUrl: base URL of the CryptoForce API.
- tenantName: tenant name.
- apiKey: API key for authentication.
- sslConfig: object with SSL certificate configurations.
CryptoForceProvider Clients
CryptoForceProvider
includes the following clients:
- walletApiClient: allows to interact with the CryptoForce API for wallet-related operations.
- undeliveredCallbackApiClient: allows to resend callbacks on tenant`s callback URL
- payoutApiClient allows to create Payment Orders
- depositApiClient allows to revert Deposits
- infoApiClient allows to receive information about tenant/address/deposit/payout
- AMLApiClient allows to interact with AML System
Examples
Wallet creation
import { WalletCreateRequestDto, WalletCreateResponseDto } from 'cryptoforce-sdk';
const createWalletData: WalletCreateRequestDto = {
client_id: 'test',
payway: 'tron',
};
const res: WalletCreateResponseDto = await cryptoForceProvider.walletApiClient.createWallet(createWalletData);
Note: Since the operation is asynchronous, CNW will send the Wallet Creation Notification at the end of this operation to Callback URL configured for the tenant (client).
Callback DTOs are also defined and can be imported:
import { BaseCallbackDto, WalletCreateCallbackDto } from 'cryptoforce-sdk';
let callback: BaseCallbackDto<WalletCreateCallbackDto>;
Get wallet creation request status
import { GetWalletCreationStatusRequestDto, GetWalletCreationStatusResponseDto } from 'cryptoforce-sdk';
const getCreateWalletStatusData: GetWalletCreationStatusRequestDto = {
request_id: '61da5793-0424-4ecb-8233-ba98833aacc3',
};
const res: GetWalletCreationStatusResponseDto = await cryptoForceProvider.walletApiClient.getWalletCreationStatus(getCreateWalletStatusData);
Wallet assignation
import { WalletAssignRequestDto, WalletAssignResponseDto } from 'cryptoforce-sdk';
const assignWalletData: WalletAssignRequestDto = {
client_id: 'test',
address: 'testAddress',
};
const res: WalletAssignResponseDto = await cryptoForceProvider.walletApiClient.assignWallet(assignWalletData);
Note: Since the operation is asynchronous, CNW will send the Wallet Assignation Notification at the end of this operation to Callback URL configured for the tenant (client).
Callback DTOs are also defined and can be imported:
import { BaseCallbackDto, WalletAssignCallbackDto } from 'cryptoforce-sdk';
let callback: BaseCallbackDto<WalletAssignCallbackDto>;
Resend Undelivered Callbacks
import { CallbackResendRequestDto, CallbackResendResponseDto } from 'cryptoforce-sdk';
const callbackResendData: CallbackResendRequestDto = {
client_id: 'test',
startdate: 1641902222000,
enddate: 1641902223000,
limit: 10,
};
const res: CallbackResendResponseDto = await cryptoForceProvider.undeliveredCallbackClient.resendCallbacks(callbackResendData);
Note: Please, check additional properties of CallbackResendRequestDto.
Verify callback signature (static function)
import { CallbackClient } from 'cryptoforce-sdk';
const res: boolean = CallbackClient.verifyCallbackSignature(payload, signature, date, apiKey);
Properties:
payload - callback payload;
signature - callback signature, usually headers['x-signature'];
date - callback date, usually headers['x-date'];
apiKey - tenant`s API Key;