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.
  • Credentials for accessing https://nexus.sepior.net. Contact the Blockdaemon support team to get the required credentials. In the following we will use NEXUS_USERNAME and NEXUS_PASSWORD, but remember to replace these with the actual credentials obtained.
  • 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.

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
  • Add your sepior credentials to ~/.npmrc by using the following commands:
npm config set @sepior:registry=<https://nexus.sepior.net/repository/sepior-nodejs-tsm-sdk-group/>  
npm config set //nexus.sepior.net/repository/sepior-nodejs-tsm-sdk-group/:username=NEXUS_USERNAME  
npm config set //nexus.sepior.net/repository/sepior-nodejs-tsm-sdk-group/:\_password=`echo -n 'NEXUS_PASSWORD' | base64`  
npm config set //nexus.sepior.net/repository/sepior-nodejs-tsm-sdk-group/:email=YOURMAILADDRESS

πŸ“˜

Note:

  • Using backticks (`) in the provided command is important because they ensure that the command is executed before the assignment takes place.
  • Replace NEXUS_USERNAME, NEXUS_PASSWOLRD and YOURMAILADDRESS with your Nexus credentials.

After setting the credentials, 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 62.1.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 such 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.