Share Serialization Module - tKey JS SDK
@tkey/share-serialization
The Share Serialization Module helps you serialize the share so you can import/ export a share from
tKey
.
Installation
- npm
- Yarn
- pnpm
npm install --save @tkey/share-serialization
yarn add @tkey/share-serialization
pnpm add @tkey/share-serialization
Initialization
import { ShareSerializationModule } from "@tkey/share-serialization";
const shareSerializationModule = new ShareSerializationModule();
Usage
With the ShareSerializationModule
, you have access to the multiple functions as mentioned in the
type reference, however, the most important ones are:
Serialize a Share
serialize(share: BN, type: string): Promise<unknown>;
Return
Promise<unknown>
: The serialized share.
Example
const generateShareResult = await tKeyInstance.generateNewShare();
const share = await tKeyInstance.outputShareStore(generateShareResult.newShareIndex).share.share;
const mnemonic = await(
tKeyInstance.modules.shareSerialization as ShareSerializationModule,
).serialize(share, "mnemonic");
Deserialize a Share
deserialize(serializedShare: unknown, type: string): Promise<BN>;
Return
Promise<BN>
: The deserialized share.
Example
const share = await(
tKeyInstance.modules.shareSerialization as ShareSerializationModule,
).deserialize(mnemonic, "mnemonic");
await tKeyInstance.inputShare(share);
Type Reference
ShareSerializationModule
declare class ShareSerializationModule implements IModule {
moduleName: string;
tbSDK: ITKeyApi;
constructor();
static serializeMnemonic(share: BN): string;
static deserializeMnemonic(share: string): BN;
setModuleReferences(tbSDK: ITKeyApi): void;
initialize(): Promise<void>;
serialize(share: BN, type: string): Promise<unknown>;
deserialize(serializedShare: unknown, type: string): Promise<BN>;
}