Node.js SDK

This tutorial has been tested on Linux and Mac OS. If you use another OS, some steps may be a bit different.

Prerequisites

  • Node.js version 16 or higher.
  • URLs and API keys for the MPC nodes in a running instance of the Builder Vault TSM. You can follow one of the tutorials Local Deployment, Hosted Sandbox, or AWS Marketplace to get access to a Builder Vault TSM.
  • Check our public repo here.

Step 1: Create a Node.js Project and Fetch the TSM SDK

In the following steps, we will create a small Node.js project that uses the Builder Vault Node.js SDK:

  • Create a new folder for your project on your local machine
  • Open a terminal window and go to the project folder.
  • Initiate a new Node.js project with default values by using the following command:
npm init -y
  • Set the public repository with the following command:
npm config set @sepior:registry=https://gitlab.com/api/v4/projects/56306653/packages/npm/
  • Install the TSM SDK by using the following command:
npm install @sepior/tsmsdkv2

📘

TSM Version

When you connect to an MPC node with the SDK, it is important that the version of the SDK matches the version of the MPC node. You can see the actual version of an MPC node in the demo TSM using this Linux command:

curl https://node1.tsm.sepior.net/version

If the returned version is for example 65.0.0, you can fetch the corresponding version of the SDK with this:

npm install @sepior/[email protected]

For the full list of SDK versions, please see here.

Step 2: Run the TSM SDK

In the following steps we connect to three MPC nodes in the Builder Vault, each with its own instance of the SDK. The SDKs are called concurrently to obtain a partial signature from each MPC node. These partial signatures are then combined to form the final signature.

  • Create a file example.js in the project folder with the following code:
const {  
  TSMClient,  
  Configuration,  
  SessionConfig,  
  curves,  
} = require("@sepior/tsmsdkv2");  
const main = async function () {  
  const urls = ["https://node1.tsm.sepior.net", "https://node2.tsm.sepior.net"];  
  const config0 = await new Configuration(urls[0]);  
  const config1 = await new Configuration(urls[1]);  
  await config0.withAPIKeyAuthentication("NODE1_API_KEY");  
  await config1.withAPIKeyAuthentication("NODE2_API_KEY");  
  const tsmClient0 = await TSMClient.withConfiguration(config0);  
  const tsmClient1 = await TSMClient.withConfiguration(config1);  
  const sessionID = await SessionConfig.GenerateSessionID();  
  const sessionConfig = await SessionConfig.newStaticSessionConfig(  
    sessionID,  
    2  
  );  
  let generateKeyPromises = [  
    tsmClient0.ECDSA().generateKey(sessionConfig, 1, curves.SECP256K1),  
    tsmClient1.ECDSA().generateKey(sessionConfig, 1, curves.SECP256K1),  
  ];  
  const keyIDResults = await Promise.allSettled(generateKeyPromises);  
  ecdsaKeyID = keyIDResults[0].value;  
  generateKeyPromises = [  
    tsmClient0.Schnorr().generateKey(sessionConfig, 1, curves.ED25519),  
    tsmClient1.Schnorr().generateKey(sessionConfig, 1, curves.ED25519),  
  ];  
  const keyIDResultsSchnorr = await Promise.allSettled(generateKeyPromises);  
  schnorrKeyID = keyIDResultsSchnorr[0].value;  
  console.log(schnorrKeyID);  
};  
main();

  • Remember to replace the MPC node URLs and API keys above with the URLs and API keys for the actual Builder Vault TSM instance that you use.
  • Run the following commands to execute the SDK:
node key_derivation.js

The code above should return the random Key IDs as follows:

FX1SkfJ1pAjTg1sRgxPQaQ8R1jsu

This means that you have successfully generated a new ECDSA key in the Builder Vault and used it for signing.

If you get error messages instead, you can consult our troubleshooting guide or contact our support team.