Skip to main content

Class: Secp256k1HdWallet

@shareledgerjs/signing.Secp256k1HdWallet

A wallet for protobuf based signing using SIGN_MODE_DIRECT

Implements

Constructors

constructor

Protected new Secp256k1HdWallet(mnemonic, options)

Parameters

NameType
mnemonicEnglishMnemonic
optionsSecp256k1HdWalletConstructorOptions

Properties

accounts

Private Readonly accounts: readonly Secp256k1Derivation[]

Derivation instructions


secret

Private Readonly secret: EnglishMnemonic

Base secret


seed

Private Readonly seed: Uint8Array

BIP39 seed

Accessors

mnemonic

get mnemonic(): string

Returns

string

Methods

getAccounts

getAccounts(): Promise<readonly AccountData[]>

Returns

Promise<readonly AccountData[]>

Implementation of

OfflineDirectSigner.getAccounts


getAccountsWithPrivkeys

getAccountsWithPrivkeys(): Promise<readonly AccountDataWithPrivkey[]>

Returns

Promise<readonly AccountDataWithPrivkey[]>


getKeyPair

Private getKeyPair(hdPath): Promise<Secp256k1Keypair>

Parameters

NameType
hdPathHdPath

Returns

Promise<Secp256k1Keypair>


serialize

serialize(password): Promise<string>

Generates an encrypted serialization of this wallet.

Parameters

NameTypeDescription
passwordstringThe user provided password used to generate an encryption key via a KDF. This is not normalized internally (see "Unicode normalization" to learn more).

Returns

Promise<string>


serializeWithEncryptionKey

serializeWithEncryptionKey(encryptionKey, kdfConfiguration): Promise<string>

Generates an encrypted serialization of this wallet.

This is an advanced alternative to calling serialize(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 options. If this is not the case, the wallet cannot be restored with the original password.

Parameters

NameType
encryptionKeyUint8Array
kdfConfigurationKdfConfiguration

Returns

Promise<string>


signDirect

signDirect(signerAddress, signDoc): Promise<DirectSignResponse>

Parameters

NameType
signerAddressstring
signDocSignDoc

Returns

Promise<DirectSignResponse>

Implementation of

OfflineDirectSigner.signDirect


deserialize

Static deserialize(serialization, password): Promise<Secp256k1HdWallet>

Restores a wallet from an encrypted serialization.

Parameters

NameTypeDescription
serializationstring-
passwordstringThe user provided password used to generate an encryption key via a KDF. This is not normalized internally (see "Unicode normalization" to learn more).

Returns

Promise<Secp256k1HdWallet>


deserializeTypeV1

Static Private deserializeTypeV1(serialization, password): Promise<Secp256k1HdWallet>

Parameters

NameType
serializationstring
passwordstring

Returns

Promise<Secp256k1HdWallet>


deserializeWithEncryptionKey

Static deserializeWithEncryptionKey(serialization, encryptionKey): Promise<Secp256k1HdWallet>

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.

Parameters

NameType
serializationstring
encryptionKeyUint8Array

Returns

Promise<Secp256k1HdWallet>


fromMnemonic

Static fromMnemonic(mnemonic, options?): Promise<Secp256k1HdWallet>

Restores a wallet from the given BIP39 mnemonic.

Parameters

NameTypeDescription
mnemonicstringAny valid English mnemonic.
optionsPartial<Secp256k1HdWalletOptions>An optional Secp256k1HdWalletOptions object optionally containing a bip39Password, hdPaths, and prefix.

Returns

Promise<Secp256k1HdWallet>


generate

Static generate(length?, options?): Promise<Secp256k1HdWallet>

Generates a new wallet with a BIP39 mnemonic of the given length.

Parameters

NameTypeDefault valueDescription
length18 | 24 | 12 | 15 | 2112The number of words in the mnemonic (12, 15, 18, 21 or 24).
optionsPartial<Secp256k1HdWalletOptions>{}An optional Secp256k1HdWalletOptions object optionally containing a bip39Password, hdPaths, and prefix.

Returns

Promise<Secp256k1HdWallet>


validateMnemonic

Static validateMnemonic(mnemonic): boolean

Validates whether the input mnemonic is valid.

Parameters

NameTypeDescription
mnemonicstringAny valid English mnemonic.

Returns

boolean

true if the input mnemonic is valid, otherwise false.