Crypto APIs - Key Management System Tool (KMS)

Overview

Crypto APIs - Key Management System Tool (KMS)

Crypto APIs KMS (Key Management System) is an open-source Node.js library. It gives companies full custody of master private keys, master seeds, and mnemonics. The library allows businesses to create HD wallets (xPubs) and sign transactions locally without a network connection (offline). It can be used in combination with Crypto APIs product suite for syncing xPub, deriving wallet addresses, listing wallet addresses, getting fee recommendations, preparing the transaction with the right data, broadcasting locally signed transactions. The KMS is perfect for B2C companies, including hardware wallets and digital wallets, as well as custodial or non-custodial exchanges. By using Crypto API's open-source library, they can easily scale to satisfy the demand and create wallets for millions of users. The businesses can decide whether to hold custody of their clients' master keys, master seed, and mnemonic or give them to their customers instead.

  • Package version: 0.2.0
  • For more information, please visit https://cryptoapis.io
  • minimum requirement NodeJS >= 14.0

Installation

For Node.js

npm

Then install it via:

npm install cryptoapis-kms

Usage

generateAddress

This method generates and returns a new public and private key pair, and the associated address with it.

Example

 const { Enumerations, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;

 const addressService = new Services.AddressService(blockchain, network)
 const address = addressService.generateAddress();
 console.dir('New address generated successfully. Returned data:');
 console.dir(address)
 console.dir(address.address)
 console.dir(address.privateKey)
 console.dir(address.publicKey)

Return type

AddressDTO

createHDWallet (xPub, yPub, zPub)

This method generates a new HD Wallet for a specific blockchain and network. The response from the endpoint should be stored, otherwise the data is lost and cannot be recovered.

Example

 const { Enumerations, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;

 (async () => {
   const walletService = new Services.WalletService(blockchain, network);
   const wallet = await walletService.createHDWallet().then((data) => {
         console.dir('HD Wallet created successfully. Returned data:');
         console.dir(data);
         console.dir(data.xPub.accountXpriv);
         console.dir(data.xPub.accountXpub);
   }, (error) => {
      console.log(error)
   });
 })();

Parameters

Name Type Description Notes
mnemonicWordsCount Number Mnemonic words count. Possible values are 12(default), 18 or 24. [optional]

Return type

WalletDTO

syncNewHDWallet (xPub, yPub, zPub)

After initial sync we keep updating the synced xpub all the time.

Example

 const {Enumerations, Client, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';

 client.syncNewHDWallet(xPub).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
    console.log(error);
 });

Parameters

Name Type Description Notes
xPub String Defines the account extended publicly known key which is used to derive all child public keys.
context String In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. [optional]

Return type

HDWalletDTO

Authorization

ApiKey

deriveAndSyncNewChangeAddresses

Through this endpoint users can derive 100 change addresses, starting from the last index we have data for, which are then added to the xPub, subscribed for syncing, and start recording data. If no data is available, it will start from index 0.

Example

 const {Enumerations, Client, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';

 client.deriveAndSyncNewChangeAddresses(xPub).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
    console.log(error);
 });

Parameters

Name Type Description Notes
xPub String Defines the account extended publicly known key which is used to derive all child public keys.
context String In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. [optional]

Return type

HDWalletDTO

Authorization

ApiKey

deriveAndSyncNewReceivingAddresses

Through this endpoint users can derive 100 receiving addresses, starting from the last index we have data for, which are then added to the xPub, subscribed for syncing, and start recording data. If no data is available, it will start from index 0.

Example

 const {Enumerations, Client, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';

 client.deriveAndSyncNewReceivingAddresses(xPub).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
    console.log(error);
 });

Parameters

Name Type Description Notes
xPub String Defines the account extended publicly known key which is used to derive all child public keys.
context String In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. [optional]

Return type

HDWalletDTO

Authorization

ApiKey

listSyncedAddresses

Through this endpoint users can list all addresses that Crypto APIs has synced for a specific xPub. This includes previous and current/new xPubs, what addresses we’ve synced for them, etc.

Example

 const {Enumerations, Client, Services } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';
 const opts = {
            context: 'yourExampleString',
            addressFormat: "P2WPKH",
            isChangeAddress: true,
            limit: 15,
       };
 client.listSyncedAddresses(xPub, opts).then((data) => {
      console.dir('API called successfully. Returned data:');
      console.dir(data);
 }, (error) => {
      console.log(error);
 });

Parameters

Name Type Description Notes
xPub String Defines the account extended publicly known key which is used to derive all child public keys.
opts Object Optional parameters [optional]
opts.context String In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. [optional]
opts.addressFormat String Defines if the address is change addres or not. (default to true) [optional]
opts.isChangeAddress String Represents the format of the address [optional]
opts.limit String Defines how many items should be returned in the response per page basis. [optional]
opts.offset String The starting index of the response items, i.e. where the response should start listing the returned items [optional]

Return type

ListSyncedAddressesDTO

Authorization

ApiKey

prepareUTXOBasedTransactionFromHDWallet (xPub, yPub, zPub)

Through the “Prepare a UTXO-based transaction from HD Wallet” endpoint users can prepare a transaction for signing from all synced with Crypto APIs addresses for the specific xPub. This is based on the selectionStrategy and the addresses’ balances. In the case a user has an address not synced with Crypto APIs, it will not be included. This endpoint applies to all supported UTXO-based blockchain protocols, e.g. Bitcoin, Litecoin, etc.

Example

 const {Enumerations, Client, Services, Models } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = "xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB"
 const feeOptions = new Models.UTXOBasedFeeOptionsModel({
    prepareStrategy: Enumerations.PrepareStrategies.MINIMIZE_DUST,
    priority: Enumerations.FeePriorities.FAST,
 });
 const recipients = [ 
     new Models.RecipientModel("tb1q8qrk9pxkjcuk4a29ec7snskaxll55jzfhrcq24", '0.000031')
 ];

 const preparedUTXOTransaction = await client.prepareUTXOBasedTransactionFromHDWallet({
     xPub: xPub,
     recipients: recipients,
     feeOptions,
 }).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
     console.log(error)
 })

Parameters

Name Type Description Notes
xPub String Account Extended Public Key
recipients Array<RecipientModel> Represents a list of recipient addresses with the respective amounts
feeOptions UTXOBasedFeeOptions Represents the fee options
feeOptions.address string Represents the fee address [optional]
feeOptions.priority string Represents the fee priority [optional]
feeOptions.feeAmount string Represents the fee amount [optional]
locktime Number Represents the time at which a particular transaction can be added to the blockchain [optional]
replaceable Boolean Representation of whether the transaction is replaceable [optional]
data string Representation of the additional data [optional]

Return type

UTXOBasedTransactionDTO

Authorization

ApiKey

prepareAccountBasedTransactionFromHDWallet (xPub, yPub, zPub)

Through the “Prepare an account-based transaction from HD Wallet” endpoint users can prepare a transaction for signing from a synced with Crypto APIs address from the specific xPub. This endpoint applies to all supported account-based blockchain protocols, e.g. Ethereum, BSC, etc

Example

 const {Enumerations, Client, Services, Models } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.ETHEREUM;
 const network = Enumerations.Networks[blockchain].NETWORK_ETHEREUM_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const xPub = "xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB
 const sender = '0x0b7155094947d785530f66d250b097b25c30a557';
 const recipient = '0xd4e2a5949359e95c7c604050dd9d54af419689c0';
 const amount = '1.2123';
 const feeOptions = new Models.AccountBasedFeeOptionsModel({
    priority: Enumerations.FeePriorities.FAST,
 });
 const preparedAccountTransaction = await client.prepareAccountBasedTransactionFromHDWallet({
     xPub,
     sender,
     recipient,
     amount,
     feeOptions
 }).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
     console.log(error)
 })

Parameters

Name Type Description Notes
xPub string Account Extended Public Key
sender string Represents a sender address
recipient string Represents a recipient addresses
amount string Representation of the amount of the transaction
feeOptions UTXOBasedFeeOptions Represents the fee options
feeOptions.priority string Represents the fee priority [optional]
feeOptions.feeAmount string Represents the fee amount [optional]
nonce string Representation of the nonce value [optional]
data string Representation of the additional data [optional]

Return type

AccountBasedTransactionDTO

Authorization

ApiKey

signPreparedTransactionLocally

Through this endpoint users sign their transactions locally(offline) using the transaction response from Prepare Transaction From HD Wallet endpoint, both for account-based and UTXO-based

Example

const {Enumerations, Client, Services, Models} = require('cryptoapis-kms');
const blockchain = Enumerations.Blockchains.BITCOIN;
const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
const client = new Client('YOUR API KEY', blockchain, network);
const signService = new Services.SignService(blockchain, network)
const accountXpriv = 'xprv8gdau6KURKnX7mcKNjLMWx3a3tEzHCMiJDBtFCJrvmXCsHNj3wvSuJ3T8g67WvN9hkFa4y1Mnr9ZbyUzs9fdhi8mhegLufkEuwSdmDeBXvz';
const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';

const preparedUTXO = await client.prepareUTXOBasedTransactionFromHDWallet({
    xPub: xPub,
    recipients: [
        new Models.RecipientModel("tb1q8qrk9pxkjcuk4a29ec7snskaxll55jzfhrcq24", '0.000031')
    ],
    feeOptions: new Models.UTXOBasedFeeOptionsModel({
        prepareStrategy: Enumerations.PrepareStrategies.MINIMIZE_DUST,
        priority: Enumerations.FeePriorities.FAST,
    })
});

const signedTx = signService.signPreparedTransactionLocally(accountXpriv, preparedUTXO);
const callbackSecretKey = 'yourSecretString';
const callbackUrl = 'https://example.com'; // your URL for callback must be verifyed from dashboard  

client.broadcastSignedTx(signedTx.raw, callbackSecretKey, callbackUrl).then((data) => {
    console.dir('API called successfully. Returned data:');
    console.dir(data);
}, (error) => {
    console.log(error);
});

Parameters

Name Type Description Notes
accountXpriv String Account Extended Private Key
transaction TransactionDTO Prepared Transaction From Xpub (Account-based or UTXO-based)

Return type

SignDTO

Authorization

ApiKey

broadcastSignedTx

broadcast locally signed transaction

Example

 const {Enumerations, Client, Services, Models } = require('cryptoapis-kms');
 const blockchain = Enumerations.Blockchains.BITCOIN;
 const network = Enumerations.Networks[blockchain].NETWORK_BITCOIN_MAINNET;
 const client = new Client('YOUR API KEY', blockchain, network);
 const signService = new Services.SignService(blockchain, network)
 const accountXpriv = 'xprv8gdau6KURKnX7mcKNjLMWx3a3tEzHCMiJDBtFCJrvmXCsHNj3wvSuJ3T8g67WvN9hkFa4y1Mnr9ZbyUzs9fdhi8mhegLufkEuwSdmDeBXvz';
 const xPub = 'xpub6BsFsonVJR5vPChKQamp55R7veBCMD2CL3LtL83B3FS5DiayYgmoHCGQodeLTukaa4anZRQD9kNtPFHuPnCzjCiT9nrXdf3voNLhXQryBRB';

 const preparedUTXO = await client.prepareUTXOBasedTransactionFromHDWallet({
     xPub: xPub,
     recipients: [
         new Models.RecipientModel("tb1q8qrk9pxkjcuk4a29ec7snskaxll55jzfhrcq24", '0.000031')
     ],
     feeOptions: new Models.UTXOBasedFeeOptionsModel({
         prepareStrategy: Enumerations.PrepareStrategies.MINIMIZE_DUST,
         priority: Enumerations.FeePriorities.FAST,
     })
 });

 const signedTx = signService.signPreparedTransactionLocally(accountXpriv, preparedUTXO);
 const callbackSecretKey = 'yourSecretString';
 const callbackUrl = 'https://example.com'; // your URL for callback must be verifyed from dashboard  
 
 client.broadcastSignedTx(signedTx.raw, callbackSecretKey, callbackUrl).then((data) => {
     console.dir('API called successfully. Returned data:');
     console.dir(data);
 }, (error) => {
     console.log(error);
 });

Parameters

Name Type Description Notes
signedTransactionHex String String identifier of the transaction
callbackSecretKey String Represents the Secret Key value provided by the customer. This field is used for security purposes during the callback notification, in order to prove the sender of the callback as Crypto APIs
callbackUrl String Represents the URL that is set by the customer where the callback will be received at. The callback notification will be received only if and when the event occurs.
context String In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. [optional]

Return type

BroadcastSignedTxDTO

Authorization

ApiKey

ApiKey

  • Type: API key
  • API key parameter name: x-api-key
  • Location: HTTP header

Contributing

Anyone who wants to contribute is welcome. Use the Issues as a way to make suggestions that you want to see or even want to create.

You might also like...

A library management system that built with JavaScript, HTML, and CSS. Allows the user to add new books and delete books.

Awesome books: with ES6 in this project: Set up the linters for html, css, and JavaScript. Create a popup window for desktop and mobile. Built With Ht

Dec 18, 2022

Employee Management System is a web application developed using Django(Backend) which manages the record of employees, their salary, attendance. publish public notices, assign works to employees, make requests to employees.

Employee Management System is a web application developed using Django(Backend) which manages the record of employees, their salary, attendance. publish public notices, assign works to employees, make requests to employees.

Employee_Management_System Employee Management System is a web application developed using Django(Backend) which manages the record of employees, thei

Dec 16, 2022

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

介绍 项目集成了工作流引擎、报表引擎和组织机构权限管理后台,可以应用于OA、HR、CRM、PM等系统开发。配合使用tlv8 ide可以快速实现业务系统开发、测试、部署。 后台采用Spring MVC架构简单方便,前端使用流行的layui界面美观大方。 采用组件开发技术,提高系统的灵活性和可扩展性;采

Dec 27, 2022

Evolve is an online investment portfolio management system where users can keep track of all the assets that they have invested in and how well their assets are performing.

Evolve is an online investment portfolio management system where users can keep track of all the assets that they have invested in and how well their assets are performing.

Evolve is an online investment portfolio management system where users can keep track of all the assets that they have invested in and how well their assets are performing.

Oct 16, 2022

Arabic-first task management system

Arabic-first task management system

Labeeb An Arabic-first, open-source Tasks Management System created for Damascus University's third year project, Faculty of Information Technology. F

Dec 30, 2022

A Nest.js API for a restaurant storage management system.

Restaurant Storage Management System Description A Nest.js API for a restaurant storage management system. Installation $ yarn install Database Seeder

Sep 12, 2022

Its a Advanced Content Management System built on top of Frappe.

Its a Advanced Content Management System built on top of Frappe.

Go1 CMS Go1 CMS - Its a Advanced Content Management System built on top of Frappe with Advanced Page builder. Lead your business towards the future of

Dec 29, 2022

[WIP] A micro content management system

T8 CMS T8 is a minimal CMS for static sites and blogs. Tech Stack ReactJS TypeScript Material UI Styled Components Supabase(BaaS) Project Folder Struc

Oct 15, 2022

The Main Purpose The main purpose of creating an anaonline information system, as an effort responsive to the management of the data of the Members of the Persis Youth based on information technology systems

landing-page-pp landing-page-pp.vercel.app #The Main Purpose The main purpose of creating an anaonline information system, as an effort responsive to

Oct 21, 2022
Releases(v0.4.0)
Owner
Crypto APIs
The easiest way to interact with Blockchains.
Crypto APIs
The LMS (Life Management System) is a free tool for personal knowledge management and goal management based on Obsidian.md.

README Documentation | 中文帮助 The LMS (Life Management System) is a tool for personal knowledge management and goal management based on Obsidian.md. It

null 27 Dec 21, 2022
Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Martin Lang 11 Dec 21, 2022
Hasbik is a community based social token and the new paradigm in the crypto space. With the goal to build a community around a crypto token.

Hasbik is a community based social token and the new paradigm in the crypto space. With the goal to build a community around a crypto token.

null 2 Jan 5, 2022
Crypto-tracker - Get crypto currency data in one click. Followed by a few more clicks.

https://crypto-tracker-ayaanzaveri08.vercel.app/ Crypto Tracker Crypto Tracker tracks crypto with the CoinGecko API. This app uses the React framework

Ayaan Zaveri 0 Apr 30, 2022
🌈 Put a date and a crypto, optionally a quantity of that crypto, to see how much has augmented/increased in dollars & percentage

crypif Put a date and a crypto, optionally a quantity of that crypto, to see how much has augmented/increased in dollars & percentage Figma I still ha

Eliaz Bobadilla 8 Apr 4, 2022
Firebase Angular Skeleton - Quickly create an application with a fully functional authentication, authorization and user management system.

FAngS - Firebase Angular Skeleton FAngS lets you quickly create an application with a fully functional authentication, authorization and user manageme

Ryan Lefebvre 7 Sep 21, 2022
Full Stack Server management system

This is Full Stack Server management system. which is build in Spring boot and Angular 11. with full Security Auth and JWT in Backend and session based surity in frontend. with two 2 dashboard and public content.

Rohit Ghadge 2 Mar 20, 2022
An event management system.

What is the purpose? It's a very tiny library for publish/subscribe(pubsub) operations. There's no dependency. It's only 933(gziped: 437) byte. Writte

Can Küçükyılmaz 7 Mar 2, 2022
A 👩‍💻 developer-friendly entity management system for 🕹 games and similarly demanding applications, based on 🛠 ECS architecture.

Miniplex Ecosystem miniplex miniplex-react Introduction Miniplex is an entity management system for games and similarly demanding applications. Instea

Hendrik Mans 253 Dec 31, 2022