UNPKG

@metamask/snaps-rpc-methods

Version:
112 lines 5.13 kB
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 { GetBip44EntropyParams, GetBip44EntropyResult } from "@metamask/snaps-sdk"; import type { NonEmptyArray } from "@metamask/utils"; import type { KeyringControllerWithKeyringV2UnsafeAction } from "../types.mjs"; import type { MethodHooksObject } from "../utils.mjs"; declare const targetName = "snap_getBip44Entropy"; export type GetBip44EntropyMethodHooks = { /** * 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 GetBip44EntropyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction; type GetBip44EntropySpecificationBuilderOptions = { methodHooks: GetBip44EntropyMethodHooks; messenger: Messenger<string, GetBip44EntropyMessengerActions>; }; /** * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/) * by deriving the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) * 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`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip32entropy) * instead. * * 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_getBip44Entropy": [ * { * "coinType": 3 * } * ] * } * } * ``` * ```ts name="Usage" * 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) * ``` */ export declare const getBip44EntropyBuilder: Readonly<{ readonly targetName: "snap_getBip44Entropy"; readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip44EntropySpecificationBuilderOptions, { permissionType: PermissionType.RestrictedMethod; targetName: typeof targetName; methodImplementation: ReturnType<typeof getBip44EntropyImplementation>; allowedCaveats: Readonly<NonEmptyArray<string>> | null; validator: PermissionValidatorConstraint; }>; readonly methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks>; readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"]; }>; /** * Builds the method implementation for `snap_getBip44Entropy`. * * @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 `BIP44CoinTypeNode`. * @throws If the params are invalid. */ export declare function getBip44EntropyImplementation({ methodHooks: { getUnlockPromise, getClientCryptography }, messenger, }: GetBip44EntropySpecificationBuilderOptions): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>; export {}; //# sourceMappingURL=getBip44Entropy.d.mts.map