snap_getBip32Entropy
Description
Enables you to manage users' non-EVM accounts
by deriving the SLIP-10
keys specified by the path and curve parameters. The keys are derived
using the entropy from the user's Secret Recovery Phrase.
If the keys you want to derive conform to the BIP-44 structure, use snap_getBip44Entropy instead. Otherwise, use this method.
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
curve
"ed25519" | "ed25519Bip32" | "secp256k1"requiredThe curve to use for the derived key. This must be a curve supported by
@metamask/key-tree.
path
string[]requiredThe derivation path to use for the derived key, represented as an array of
path segments. For example, the path m/44'/1'/0'/0/0 would be represented
as ['m', "44'", "1'", "0'", '0', '0'].
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
numberThe 0-indexed path depth of this node.
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 (optional) private key of this node.
publicKey
stringThe public key of this node.
chainCode
stringThe chain code of this node.
curve
"ed25519" | "ed25519Bip32" | "secp256k1"The name of the curve used by the node.
Example
- Manifest
- Usage
{
"initialPermissions": {
"snap_getBip32Entropy": [
{
"path": ["m", "44'", "3'"],
"curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
}
]
}
}
import { SLIP10Node } from "@metamask/key-tree";
// This example uses Dogecoin, which has a derivation path starting with
// m/44'/3'.
const dogecoinNode = await snap.request({
method: "snap_getBip32Entropy",
params: {
// The path and curve must be specified in the initial permissions.
path: ["m", "44'", "3'"],
curve: "secp256k1",
},
});
// Next, create an instance of a SLIP-10 node for the Dogecoin node.
const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode);
// m/44'/3'/0'
const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"]);
// m/44'/3'/1'
const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"]);
// Now, you can ask the user to sign transactions, etc.