snap_getBip32PublicKey
Description
Gets the BIP-32
public key for the derivation path specified by the path parameter. Note
that this returns the public key, not the extended public key (xpub), or
Ethereum address.
Parameters
The request parameters for the snap_getBip32PublicKey method.
curve
"ed25519" | "ed25519Bip32" | "secp256k1"The curve to use for the derived key. This must be a curve supported by
@metamask/key-tree.
path
arrayThe 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'].
compressed
booleanWhether to return the compressed public key. Defaults to false.
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
The public key as hexadecimal string. May be compressed or uncompressed
depending on the compressed parameter provided in the request parameters.
Example
- Manifest
- Usage
{
"initialPermissions": {
"snap_getBip32PublicKey": [
{
"path": ["m", "44'", "3'", "0'", "0", "0"],
"curve": "secp256k1"
}
]
}
}
// This example uses Dogecoin, which has a derivation path starting with
// "m / 44' / 3'".
const dogecoinPublicKey = await snap.request({
method: "snap_getBip32PublicKey",
params: {
// The path and curve must be specified in the initial permissions.
path: ["m", "44'", "3'", "0'", "0", "0"],
curve: "secp256k1",
compressed: false,
},
});
// '0x...'
console.log(dogecoinPublicKey);