UNPKG

@metamask/snaps-rpc-methods

Version:
105 lines 4.8 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 { GetBip32PublicKeyParams, GetBip32PublicKeyResult } 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_getBip32PublicKey"; export type GetBip32PublicKeyMethodHooks = { /** * 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 GetBip32PublicKeyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction; type GetBip32PublicKeySpecificationBuilderOptions = { methodHooks: GetBip32PublicKeyMethodHooks; messenger: Messenger<string, GetBip32PublicKeyMessengerActions>; }; export declare const Bip32PublicKeyArgsStruct: import("@metamask/superstruct").Struct<{ curve: "secp256k1" | "ed25519" | "ed25519Bip32"; path: string[]; source?: string | undefined; compressed?: boolean | undefined; }, { path: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>; curve: import("@metamask/superstruct").Describe<"secp256k1" | "ed25519" | "ed25519Bip32">; compressed: import("@metamask/superstruct").Struct<boolean | undefined, null>; source: import("@metamask/superstruct").Struct<string | undefined, null>; }>; /** * Gets the [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) * 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. * * @example * ```json name="Manifest" * { * "initialPermissions": { * "snap_getBip32PublicKey": [ * { * "path": ["m", "44'", "3'", "0'", "0", "0"], * "curve": "secp256k1" * } * ] * } * } * ``` * ```ts name="Usage" * // 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) * ``` */ export declare const getBip32PublicKeyBuilder: Readonly<{ readonly targetName: "snap_getBip32PublicKey"; readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32PublicKeySpecificationBuilderOptions, { permissionType: PermissionType.RestrictedMethod; targetName: typeof targetName; methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>; allowedCaveats: Readonly<NonEmptyArray<string>> | null; validator: PermissionValidatorConstraint; }>; readonly methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks>; readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"]; }>; /** * Builds the method implementation for `snap_getBip32PublicKey`. * * @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 public key. * @throws If the params are invalid. */ export declare function getBip32PublicKeyImplementation({ methodHooks: { getUnlockPromise, getClientCryptography }, messenger, }: GetBip32PublicKeySpecificationBuilderOptions): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>; export {}; //# sourceMappingURL=getBip32PublicKey.d.cts.map