snap_getBip44Entropy
Description
Enables you to manage users' non-EVM accounts
by deriving the BIP-44
keys specified by the coinType parameter. The keys are derived using the
entropy from the user's Secret Recovery Phrase.
If the keys you want to derive don't conform to the BIP-44 structure, use
snap_getBip32Entropy
instead.
This method is designed to be used with the @metamask/key-tree
module. @metamask/key-tree can help you get the extended private keys
for user addresses, but it's your responsibility to know how to use those
keys to, for example, derive an address for the relevant protocol or sign a
transaction for the user.
Parameters
coinType
numberrequiredThe coin type to use for the derived key, as specified in the SLIP-44 registry.
source
string | nullThe ID of the entropy source to use. If not specified, the primary entropy
source will be used. For a list of available entropy sources, see the
snap_listEntropySources method.
Returns
depth
0 | 1 | 2 | 3 | 4 | 5The 0-indexed BIP-44 path depth of this node.
A BIP-44 path is of the form:
m / 44' / coin_type' / account' / change / address_index
With the following depths:
0 / 1 / 2 / 3 / 4 / 5
masterFingerprint
number | nullThe fingerprint of the master node, i.e., the node at depth 0. May be undefined if this node was created from an extended key.
parentFingerprint
numberThe fingerprint of the parent key, or 0 if this is a master node.
index
numberThe index of the node, or 0 if this is a master node.
network
"mainnet" | "testnet" | nullThe network for the node. This is only used for extended keys, and defaults
to mainnet.
privateKey
string | nullThe hexadecimal string representation of the private key for this node.
May be undefined if the node is a public node.
publicKey
stringThe hexadecimal string representation of the public key for this node.
chainCode
stringThe hexadecimal string representation of the chain code for this node.
coin_type
numberpath
`m / bip32:${number}' / bip32:${number}'`Example
- Manifest
- Usage
{
"initialPermissions": {
"snap_getBip44Entropy": [
{
"coinType": 3
}
]
}
}
import { getBIP44AddressKeyDeriver } from "@metamask/key-tree";
// This example uses Dogecoin, which has coin_type 3.
const dogecoinNode = await snap.request({
method: "snap_getBip44Entropy",
params: {
coinType: 3,
},
});
// Next, create an address key deriver function for the Dogecoin coin_type
// node. In this case, its path is: m/44'/3'/0'/0/address_index
const deriveDogecoinAddress = await getBIP44AddressKeyDeriver(dogecoinNode);
// These are BIP-44 nodes containing the extended private keys for the
// respective derivation paths.
// m/44'/3'/0'/0/0
const addressKey0 = await deriveDogecoinAddress(0);
// m/44'/3'/0'/0/1
const addressKey1 = await deriveDogecoinAddress(1);