Skip to main content

Private Key Module - tKey JS SDK

@tkey/private-keys

The Private Key Module helps you to store extra private keys on the metadata.

Installation

npm install --save @tkey/private-keys

Initialization

import { PrivateKeyModule } from "@tkey/private-keys";
const privateKeyModule = new PrivateKeyModule();

Usage

With the PrivateKeyModule, you have access to the multiple functions as mentioned in the type reference, however, the most important ones are:

Set Private Key

setPrivateKey(privateKeyType: string, privateKey?: BN): Promise<void>;

  • privateKeyType: The type of private key to set. Allowed values secp256k1n and ed25519
  • privateKey: The private key to set.

Return

  • Promise<void>

Example

await tKey.modules.privateKeyModule.setPrivateKey("secp256k1n", privateKey);

Get Private Keys

getPrivateKeys(): Promise<IPrivateKeyStore[]>;

Return

  • Promise<IPrivateKeyStore[]>- The private keys stored.

Example

const privataKeyStore = await tKey.modules.privateKeyModule.getPrivateKeys();

Type Reference

PrivateKeyModule

declare class PrivateKeyModule implements IModule {
moduleName: string;
tbSDK: ITKeyApi;
privateKeyFormats: IPrivateKeyFormat[];
constructor(formats: IPrivateKeyFormat[]);
setModuleReferences(tbSDK: ITKeyApi): void;
initialize(): Promise<void>;
setPrivateKey(privateKeyType: string, privateKey?: BN): Promise<void>;
getPrivateKeys(): Promise<IPrivateKeyStore[]>;
getAccounts(): Promise<BN[]>;
}