The quick start guide will help you to quickly start integrating Silent Shard Duo React-Native SDK into your application. You can use either hooks or async functionsat your will.
Let's start!
Note: All MPC related functions functions(key-generation, sign-generation, key-rotation) are WS requests to the cloud node, and to secure the communications, the application needs a userToken and partyKey(ECDSAP1PartyKeys) to authenticate the user.
As a recap, a client user is authenticated to the server node through the admin which issues a JWT for that user. For the issuance of the token the admin needs a public Ed25519 key for that user which is provided by the user as partyKey. Then the user side has to make an HTTP request to the Admin SDK in order to get the token to be further used in MPC operations for authorization purposes. We have an example of user-side code that queries the Admin SDK to create the token. The flow is as follows: The user creates an Ed25519 signing key pair, queries the Admin SDK for token issuance with a createUserToken call, and the Admin SDK creates the token and returns it to the user.
1. Run server node locally
Please refer to this from the Server Node page.
2. Create an application backend
In this guide using bun run time to create a simple HTTP server to serve userToken JWT using Adming-SDK. Bun 1.0.15 higher is required.
Initialize Project
First, run the following command to initialize the HTTP project.
bun init
# Project name - simple-backend
# Entry point - index.ts
Populate an index.ts file in the root directory in the root directory with the following content.
import {Elysia, t} from'elysia'import {cors} from"@elysiajs/cors";import {SigpairAdmin} from"sigpair-admin-v2";// Example admin token.// DO NOT hardcode in production code!constadminToken="1ec3804afc23258f767b9d38825dc7ab0a2ea44ef4adf3254e4d7c6059c3b55a";// Base URL of the server nodeconstbaseUrl="http://localhost:8080";constapp=newElysia({ serve: { hostname:'0.0.0.0' }});app.use(cors());app.post('/get-access-token',async ({body}) => {constadmin=newSigpairAdmin(adminToken, cloudNodeUrl);constuserId=awaitadmin.createUser('test-user-demo-application');constaccessToken=admin.genUserToken(userId,body.pk);return { accessToken };}, { body:t.Object({ pk:t.String(), })});app.listen(8000);console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`);
Run HTTP server
bunrunindex.ts
If successful in the terminal logs 🦊 Elysia is running at 0.0.0.0:8000
3. Mobile application - quick start
Create a fetch function to get userToken JWT from the backend. We will be using this function to generate userToken before each MPC action.
This part assume, Server node and simple backend are running on local PC
Simple backend running at localhost:8000
Server node running at localhost:8080
constSIMPLE_API_URL="http://localhost:8000";// For the Android use http://10.0.2.2:8080exportconstcreateUserToken=async ( userPartyKey:ECDSAP1PartyKeys,):Promise<string> => {constresponse=awaitfetch(`${SIMPLE_API_URL}/get-access-token`, { method:'POST', headers: {'Content-Type':'application/json', }, body:JSON.stringify({ pk:Buffer.from(awaituserPartyKey.extractPk(),'base64').toString('hex'), }), });constjson=awaitresponse.json();if (json.accessToken) {returnjson.accessToken; }thrownewError('Failed to get access token');};