@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
113 lines • 5.32 kB
text/typescript
import type { CryptographicFunctions } from "@metamask/key-tree";
import type { Messenger } from "@metamask/messenger";
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
import { PermissionType } from "@metamask/permission-controller";
import type { GetBip32EntropyParams, GetBip32EntropyResult } from "@metamask/snaps-sdk";
import type { NonEmptyArray } from "@metamask/utils";
import type { KeyringControllerWithKeyringV2UnsafeAction } from "../types.cjs";
import type { MethodHooksObject } from "../utils.cjs";
declare const targetName = "snap_getBip32Entropy";
export type GetBip32EntropyMethodHooks = {
/**
* Waits for the extension to be unlocked.
*
* @returns A promise that resolves once the extension is unlocked.
*/
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
/**
* Get the cryptographic functions to use for the client. This may return an
* empty object or `undefined` to fall back to the default cryptographic
* functions.
*
* @returns The cryptographic functions to use for the client.
*/
getClientCryptography: () => CryptographicFunctions | undefined;
};
export type GetBip32EntropyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction;
type GetBip32EntropySpecificationBuilderOptions = {
methodHooks: GetBip32EntropyMethodHooks;
messenger: Messenger<string, GetBip32EntropyMessengerActions>;
};
/**
* Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)
* by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)
* 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](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)
* structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)
* instead. Otherwise, use this method.
*
* This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)
* module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-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.
*
* @example
* ```json name="Manifest"
* {
* "initialPermissions": {
* "snap_getBip32Entropy": [
* {
* "path": ["m", "44'", "3'"],
* "curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
* }
* ]
* }
* }
* ```
* ```ts name="Usage"
* 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.
* ```
*/
export declare const getBip32EntropyBuilder: Readonly<{
readonly targetName: "snap_getBip32Entropy";
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32EntropySpecificationBuilderOptions, {
permissionType: PermissionType.RestrictedMethod;
targetName: typeof targetName;
methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
validator: PermissionValidatorConstraint;
}>;
readonly methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks>;
readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"];
}>;
/**
* Builds the method implementation for `snap_getBip32Entropy`.
*
* @param options - The options.
* @param options.messenger - The messenger.
* @param options.methodHooks - The RPC method hooks.
* @param options.methodHooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
* and prompts the user to unlock their MetaMask if it is locked.
* @param options.methodHooks.getClientCryptography - A function to retrieve the cryptographic
* functions to use for the client.
* @returns The method implementation which returns a `JsonSLIP10Node`.
* @throws If the params are invalid.
*/
export declare function getBip32EntropyImplementation({ methodHooks: { getUnlockPromise, getClientCryptography }, messenger, }: GetBip32EntropySpecificationBuilderOptions): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
export {};
//# sourceMappingURL=getBip32Entropy.d.cts.map