The SSV Key Distributor SDK is a JS/TS library that enables developers to integrate the distribution of validator keys to KeyShares to their application.
Returns a validator key from an existing Keystore file.
// Importsimport { EthereumKeyStore } from'ssv-keys'// Get the private key from the keystore using the keystore password// Get required data from the keystore fileconstkeyStore=newEthereumKeyStore(JSON.stringify(keystore));// Get public key using the keystore passwordconstpublicKey=awaitkeyStore.getPublicKey(keystorePassword); // Get private key using the keystore passwordconstprivateKey=awaitkeyStore.getPrivateKey(keystorePassword); // Log the public keyconsole.debug('Public Key: '+ publicKey); // Log the private keyconsole.debug('Private Key: '+ privateKey);
KeyShares Method
Returns KeyShares (SharesPublicKey & SharesEncrypted) from a validator key and set of operator keys.
// Build the shares// Importsimport { Encryption, Threshold } from'ssv-keys'import { encode } from'js-base64'constoperators=require('./operators.json');// Initialize the Threshold classconstthresholdInstance=newThreshold();// Create the threshold instance using the private keyconstthreshold=awaitthresholdInstance.create(privateKey); // Build the shares using an array of operator public keyslet shares =newEncryption(operators,threshold.shares).encrypt(); // Loop through the operators RSA keys and format them as base64 shares =shares.map((share) => {share.operatorPublicKey =encode(share.operatorPublicKey); // Return the operator key and KeyShares (sharePublicKey & shareEncrypted) return share; });
Register Validator Payload Method
Returns the registerValidator() transaction payload from a validator key and set of operator keys
// Build transaction payload// Importsimport { encode } from'js-base64'import { Web3 } from'web3'constoperatorIds=require('./operatorIds.json');// Initialize the web3 classconstweb3=newWeb3(); // Loop through the operators and encode them as ABI parametersconstoperatorsPublicKeys=operators.map((operator) =>web3.eth.abi.encodeParameter('string',encode(operator)));// Get all the public keys from the sharesconstsharePublicKeys=shares.map((share) =>share.publicKey);// Get all the private keys from the shares and encode them as ABI parametersconstshareEncrypted=shares.map((share) =>web3.eth.abi.encodeParameter('string',share.privateKey));// Token amount (liquidation collateral and operational runway balance to be funded)consttokenAmount=web3.utils.toBN(123456789).toString(); /// Return all the needed params to build a transaction payloadreturn [threshold.validatorPublicKey,`[${operatorIds.join(',')}]`, operatorsPublicKeys, sharesPublicKeys, sharesEncrypted, tokenAmount ]