Improve documentation of Secp256k1Wallet.serialize/deserialize

This commit is contained in:
Simon Warta 2020-07-23 16:15:28 +02:00
parent a75be1406c
commit ef7d171a64
4 changed files with 34 additions and 4 deletions

View File

@ -85,5 +85,5 @@ export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export { OfflineSigner, makeCosmoshubPath } from "./wallet";
export { Secp256k1Wallet } from "./secp256k1wallet";
export { OfflineSigner, makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet";
export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet";

View File

@ -152,6 +152,12 @@ export class Secp256k1Wallet implements OfflineSigner {
return Secp256k1Wallet.fromMnemonic(mnemonic.toString(), hdPath, prefix);
}
/**
* Restores a wallet from an encrypted serialization.
*
* @param password The user provided password used to generate an encryption key via a KDF.
* This is not normalized internally (see "Unicode normalization" to learn more).
*/
public static async deserialize(serialization: string, password: string): Promise<Secp256k1Wallet> {
const root = JSON.parse(serialization);
if (!isNonNullObject(root)) throw new Error("Root document is not an object.");
@ -163,6 +169,15 @@ export class Secp256k1Wallet implements OfflineSigner {
}
}
/**
* Restores a wallet from an encrypted serialization.
*
* This is an advanced alternative to calling `deserialize(serialization, password)` directly, which allows
* you to offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
*
* The caller is responsible for ensuring the key was derived with the given KDF configuration. This can be
* done using `extractKdfConfiguration(serialization)` and `executeKdf(password, kdfConfiguration)` from this package.
*/
public static async deserializeWithEncryptionKey(
serialization: string,
encryptionKey: Uint8Array,

View File

@ -83,5 +83,5 @@ export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export { OfflineSigner, makeCosmoshubPath } from "./wallet";
export { Secp256k1Wallet } from "./secp256k1wallet";
export { OfflineSigner, makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet";
export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet";

View File

@ -57,7 +57,22 @@ export declare class Secp256k1Wallet implements OfflineSigner {
hdPath?: readonly Slip10RawIndex[],
prefix?: string,
): Promise<Secp256k1Wallet>;
/**
* Restores a wallet from an encrypted serialization.
*
* @param password The user provided password used to generate an encryption key via a KDF.
* This is not normalized internally (see "Unicode normalization" to learn more).
*/
static deserialize(serialization: string, password: string): Promise<Secp256k1Wallet>;
/**
* Restores a wallet from an encrypted serialization.
*
* This is an advanced alternative to calling `deserialize(serialization, password)` directly, which allows
* you to offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
*
* The caller is responsible for ensuring the key was derived with the given KDF configuration. This can be
* done using `extractKdfConfiguration(serialization)` and `executeKdf(password, kdfConfiguration)` from this package.
*/
static deserializeWithEncryptionKey(
serialization: string,
encryptionKey: Uint8Array,