@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
111 lines • 4.72 kB
text/typescript
import type { CryptographicFunctions } from "@metamask/key-tree";
import type { Messenger } from "@metamask/messenger";
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
import { PermissionType } from "@metamask/permission-controller";
import type { GetEntropyParams, GetEntropyResult } from "@metamask/snaps-sdk";
import type { Infer } from "@metamask/superstruct";
import type { NonEmptyArray } from "@metamask/utils";
import type { KeyringControllerWithKeyringV2UnsafeAction } from "../types.mjs";
import type { MethodHooksObject } from "../utils.mjs";
declare const targetName = "snap_getEntropy";
export type GetEntropyMessengerActions = KeyringControllerWithKeyringV2UnsafeAction;
type GetEntropySpecificationBuilderOptions = {
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
methodHooks: GetEntropyHooks;
messenger: Messenger<string, GetEntropyMessengerActions>;
};
export declare const GetEntropyArgsStruct: import("@metamask/superstruct").Struct<{
version: 1;
salt?: string | undefined;
source?: string | undefined;
}, {
version: import("@metamask/superstruct").Struct<1, 1>;
salt: import("@metamask/superstruct").Struct<string | undefined, null>;
source: import("@metamask/superstruct").Struct<string | undefined, null>;
}>;
/**
* @property version - The version of the `snap_getEntropy` method. This must be
* the numeric literal `1`.
* @property salt - A string to use as the salt when deriving the entropy. If
* omitted, the salt will be an empty string.
*/
export type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;
/**
* Get a deterministic 256-bit entropy value, specific to the Snap and the
* user's account. You can use this entropy to generate a private key, or any
* other value that requires a high level of randomness. Other Snaps can't
* access this entropy, and it changes if the user's secret recovery phrase
* changes.
*
* You can optionally specify a salt to generate different entropy for different
* purposes. Using a salt results in entropy unrelated to the entropy generated
* without a salt.
*
* This value is deterministic: it's always the same for the same Snap, user
* account, and salt.
*
* @example
* ```json name="Manifest"
* {
* "initialPermissions": {
* "snap_getEntropy": {}
* }
* }
* ```
* ```ts name="Usage"
* const entropy = await snap.request({
* method: 'snap_getEntropy',
* params: {
* version: 1,
* salt: 'foo', // Optional.
* },
* })
*
* // '0x...'
* console.log(entropy)
* ```
*/
export declare const getEntropyBuilder: Readonly<{
readonly targetName: "snap_getEntropy";
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetEntropySpecificationBuilderOptions, {
permissionType: PermissionType.RestrictedMethod;
targetName: typeof targetName;
methodImplementation: ReturnType<typeof getEntropyImplementation>;
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
}>;
readonly methodHooks: MethodHooksObject<GetEntropyHooks>;
readonly actionNames: readonly ["KeyringController:withKeyringV2Unsafe"];
}>;
export type GetEntropyHooks = {
/**
* 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;
};
/**
* Builds the method implementation for `snap_getEntropy`. The implementation
* is based on the reference implementation of
* [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
*
* @param options - The options.
* @param options.messenger - The messenger.
* @param options.methodHooks - The RPC method hooks.
* @param options.methodHooks.getUnlockPromise - The method to get a promise that resolves
* once the extension is unlocked.
* @param options.methodHooks.getClientCryptography - A function to retrieve the cryptographic
* functions to use for the client.
* @returns The method implementation.
*/
declare function getEntropyImplementation({ methodHooks: { getUnlockPromise, getClientCryptography }, messenger, }: GetEntropySpecificationBuilderOptions): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
export {};
//# sourceMappingURL=getEntropy.d.mts.map