Installation

1
2
3
$ npm i @trustology/trustvault-nodejs-sdk
# Or:
$ yarn add @trustology/trustvault-nodejs-sdk

Creating a TrustVault Client

1
2
3
4
5
6
7
8
9
10
// common
const { TrustVault } = require("@trustology/trustvault-nodejs-sdk");

// es6
import { TrustVault } from "@trustology/trustvault-nodejs-sdk";

// sandbox env
const trustVaultSandbox = new TrustVault({ apiKey: "<TRUST_VAULT_API_KEY>", environment: "sandbox" });

const trustVault = new TrustVault({ apiKey: "<TRUST_VAULT_API_KEY>"});

Overview

The SDK wraps the TrustVault GraphQL interface and gives you easy access to core functionalities within the API.

The API can be configured against sandbox (ETH ropsten, BTC testnet3) or production environments.

If you use the SDK with an external instruction key the SDK provides callbacks for you to sign the correct data.

The SDK includes helper methods to ensure you data integrity including validating policy template, publicKey provenance, HMAC webhook payload and digests. It also includes an AWS KMS wrapper class for data signing.

The SDK requires an API key, please contact Trustology to get one.

See TrustVault Node.js SDK in github

Sign callback

The function that will be called with the data that needs to be signed.

AWS KMS wrapper class (AwsKmsKeyStore)

AwsKmsKeyStore class ensures that the correct key from the correct curve is used for signing. It has a method sign which is an implementation of the signCallback.

You will need to ensure that your code has the relevant AWS permissions to access your KMS key.

Get list of subWallets

Retrieve the list of subWallets associated with the API key. Use this method to get the subWalletId of the wallet you wish to create transactions from or get the walletId where the subWallets belongs to.

1
const subWallets = await trustVault.getSubWallets();

Send a Bitcoin Transaction

Send a bitcoin transaction to TrustVault

1
const requestId = await trustVault.sendBitcoin(fromSubWalletId, toAddress, amount, speed, signCallback);

Send an Ethereum Transaction

Send an ethereum transaction to TrustVault

1
const requestId = await trustVault.sendEthereum(fromAddress, toAddress, amount, asset, speed, currency, signCallback)

Changing the external instruction key of a wallet

Change the external public instruction key of a wallet

1
const requestId = await trustVault.replacePublicKeyInDefaultSchedule(walletId, publicKey, signCallback);

Validating and signing a webhook request

Validate the webhook, sign and submit the signature to TrustVault

1
2
3
TrustVault.validateWebhookSignature(req.body, "<YOUR_WEBHOOK_SECRET>", req.headers["X-Sha2-Signature"]);
const webhookMessage = JSON.parse(req.body);
const requestId = await trustVault.signAndSubmitSignature(webhookMessage, signCallback);

NOTE: validateWebhookSignature is a static method

Create a new Bitcoin Address

Create a new bitcoin address for the given subWalletId

1
const address = await trustVault.createBitcoinAddress(subWalletId)

Get request

Retrieve the request item associated with the given requestId. Use this method to query the status of your request.

1
const request = await trustVault.getRequest(requestId)

Returns

1
2
3
4
5
{
"requestId": "12b40615-ab28-5917-d576-5e05ab5d2944",
"type": "BTC_TRANSACTION",
"status": "SUBMITTED"
}

Request Statuses

Request Status Description
AWAITING_SIGNATURES the request is still awaiting signatures enough signature before it can be processed
SIGNED the request has received enough signatures to be processed
SUBMITTED the transaction request has been processed and submitted to the network
CONFIRMED the transaction request has been confirmed by the network (1+ confirmation)
PROCESSED the request has been successfully processed
USER_CANCELLED the request has been cancelled by the user
ERROR an error occurred when processing the request