Signing with a Mnemonic
The LocalSigner
in the Chorus One SDK is a specialized implementation of the Signer
interface that utilizes a BIP39 mnemonic for signing operations.
This signer is ideal for local environments where you need a straightforward and secure method to generate and manage cryptographic keys from mnemonic phrases.
Obtaining the Mnemonic and HD Path
Before initializing the LocalSigner
you will need to prepare a BIP39 mnemonic and define the hierarchical deterministic (HD) path for key derivation.
Let's look at what these two key concepts are below:
mnemonic: A string containing your BIP39 mnemonic phrase. This should be stored securely and kept private as it controls access to all addresses derived from it.
hdPath: The BIP39 address derivation path, which is used to derive the specific key pair needed for signing. Commonly, this path follows the format
m/44'/60'/0'/0/0
for Ethereum-compatible addresses.addressDerivationFn: A function that derives the address from the public key, implementing the
AddressDerivationFn
type and provided by Staker classes as static methods, i.e.CosmosStaker.getAddressDerivationFn
,NearStaker.getAddressDerivationFn
, etc.
type AddressDerivationFn = (
publicKey: Uint8Array,
hdPath: string
) => Array<string>
Setting Up the LocalSigner
With your mnemonic and HD path ready, you can now configure and initialize the LocalSigner:
import { CosmosStaker } from '@chorus-one/cosmos';
import { LocalSigner } from '@chorus-one/signer-local';
const signer = new LocalSigner({
mnemonic: 'your-mnemonic-phrase',
accounts: [{ hdPath: 'your-hd-path' }]
addressDerivationFn: CosmosStaker.getAddressDerivationFn({
bechPrefix: 'celestia'
})
});
await signer.init();
Further Reading
Last updated
Was this helpful?