@metamask/snaps-rpc-methods 3.3.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/permitted/common/snapInstallation.js.map +1 -1
- package/dist/cjs/permitted/getFile.js +5 -5
- package/dist/cjs/permitted/getFile.js.map +1 -1
- package/dist/cjs/permitted/getSnaps.js.map +1 -1
- package/dist/cjs/permitted/invokeKeyring.js.map +1 -1
- package/dist/cjs/permitted/invokeSnapSugar.js.map +1 -1
- package/dist/cjs/permitted/requestSnaps.js.map +1 -1
- package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +1 -1
- package/dist/cjs/restricted/dialog.js +16 -25
- package/dist/cjs/restricted/dialog.js.map +1 -1
- package/dist/cjs/restricted/getBip32Entropy.js.map +1 -1
- package/dist/cjs/restricted/getBip32PublicKey.js.map +1 -1
- package/dist/cjs/restricted/getBip44Entropy.js +0 -1
- package/dist/cjs/restricted/getBip44Entropy.js.map +1 -1
- package/dist/cjs/restricted/getEntropy.js.map +1 -1
- package/dist/cjs/restricted/getLocale.js.map +1 -1
- package/dist/cjs/restricted/index.js +0 -9
- package/dist/cjs/restricted/index.js.map +1 -1
- package/dist/cjs/restricted/invokeSnap.js.map +1 -1
- package/dist/cjs/restricted/manageAccounts.js.map +1 -1
- package/dist/cjs/restricted/manageState.js +13 -22
- package/dist/cjs/restricted/manageState.js.map +1 -1
- package/dist/cjs/restricted/notify.js +6 -13
- package/dist/cjs/restricted/notify.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/permitted/common/snapInstallation.js.map +1 -1
- package/dist/esm/permitted/getFile.js +1 -1
- package/dist/esm/permitted/getFile.js.map +1 -1
- package/dist/esm/permitted/getSnaps.js.map +1 -1
- package/dist/esm/permitted/invokeKeyring.js.map +1 -1
- package/dist/esm/permitted/invokeSnapSugar.js.map +1 -1
- package/dist/esm/permitted/requestSnaps.js.map +1 -1
- package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +1 -1
- package/dist/esm/restricted/dialog.js +3 -9
- package/dist/esm/restricted/dialog.js.map +1 -1
- package/dist/esm/restricted/getBip32Entropy.js.map +1 -1
- package/dist/esm/restricted/getBip32PublicKey.js.map +1 -1
- package/dist/esm/restricted/getBip44Entropy.js +0 -1
- package/dist/esm/restricted/getBip44Entropy.js.map +1 -1
- package/dist/esm/restricted/getEntropy.js.map +1 -1
- package/dist/esm/restricted/getLocale.js.map +1 -1
- package/dist/esm/restricted/index.js +0 -3
- package/dist/esm/restricted/index.js.map +1 -1
- package/dist/esm/restricted/invokeSnap.js.map +1 -1
- package/dist/esm/restricted/manageAccounts.js.map +1 -1
- package/dist/esm/restricted/manageState.js +8 -14
- package/dist/esm/restricted/manageState.js.map +1 -1
- package/dist/esm/restricted/notify.js +3 -7
- package/dist/esm/restricted/notify.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/permitted/common/snapInstallation.d.ts +3 -5
- package/dist/types/permitted/getFile.d.ts +5 -4
- package/dist/types/permitted/getSnaps.d.ts +3 -3
- package/dist/types/permitted/handlers.d.ts +6 -12
- package/dist/types/permitted/invokeKeyring.d.ts +5 -7
- package/dist/types/permitted/invokeSnapSugar.d.ts +5 -8
- package/dist/types/permitted/requestSnaps.d.ts +3 -2
- package/dist/types/restricted/caveats/permittedCoinTypes.d.ts +1 -1
- package/dist/types/restricted/dialog.d.ts +82 -29
- package/dist/types/restricted/getBip32Entropy.d.ts +2 -3
- package/dist/types/restricted/getBip32PublicKey.d.ts +2 -6
- package/dist/types/restricted/getBip44Entropy.d.ts +2 -5
- package/dist/types/restricted/getEntropy.d.ts +3 -2
- package/dist/types/restricted/getLocale.d.ts +2 -1
- package/dist/types/restricted/index.d.ts +9 -90
- package/dist/types/restricted/invokeSnap.d.ts +8 -7
- package/dist/types/restricted/manageAccounts.d.ts +5 -4
- package/dist/types/restricted/manageState.d.ts +3 -13
- package/dist/types/restricted/notify.d.ts +4 -7
- package/package.json +7 -8
- package/dist/cjs/request.js +0 -6
- package/dist/cjs/request.js.map +0 -1
- package/dist/esm/request.js +0 -3
- package/dist/esm/request.js.map +0 -1
- package/dist/types/request.d.ts +0 -99
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/notify.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/restricted/notify.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport type {\n NotifyParams,\n NotifyResult,\n EnumToUnion,\n} from '@metamask/snaps-sdk';\nimport { validateTextLinks } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nexport type NotificationArgs = {\n /**\n * Enum type to determine notification type.\n */\n type: EnumToUnion<NotificationType>;\n\n /**\n * A message to show on the notification.\n */\n message: string;\n};\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedParams = getValidatedParams(params);\n\n await maybeUpdatePhishingList();\n\n validateTextLinks(validatedParams.message, isOnPhishingList);\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n // Set to the max message length on a Mac notification for now.\n if (!message || typeof message !== 'string' || message.length >= 50) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n return params as NotificationArgs;\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","NotificationType","validateTextLinks","isObject","methodName","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","targetName","methodImplementation","getImplementation","subjectTypes","Snap","showNativeNotification","showInAppNotification","isOnPhishingList","maybeUpdatePhishingList","notifyBuilder","Object","freeze","implementation","args","params","context","origin","validatedParams","getValidatedParams","message","type","Native","InApp","invalidParams","values","includes","length"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,gBAAgB,QAAQ,sBAAsB;AAMvD,SAASC,iBAAiB,QAAQ,wBAAwB;AAE1D,SAASC,QAAQ,QAAQ,kBAAkB;AAI3C,MAAMC,aAAa;AAkDnB;;;;;;;;CAQC,GACD,OAAO,MAAMC,uBAIT,CAAC,EAAEC,iBAAiB,IAAI,EAAEC,WAAW,EAA+B;IACtE,OAAO;QACLC,gBAAgBV,eAAeW,gBAAgB;QAC/CC,YAAYN;QACZE;QACAK,sBAAsBC,kBAAkBL;QACxCM,cAAc;YAACd,YAAYe,IAAI;SAAC;IAClC;AACF,EAAE;AAEF,MAAMP,cAAoD;IACxDQ,wBAAwB;IACxBC,uBAAuB;IACvBC,kBAAkB;IAClBC,yBAAyB;AAC3B;AAEA,OAAO,MAAMC,gBAAgBC,OAAOC,MAAM,CAAC;IACzCX,YAAYN;IACZC;IACAE;AACF,GAAY;AAEZ;;;;;;;;;;CAUC,GACD,OAAO,SAASK,kBAAkB,EAChCG,sBAAsB,EACtBC,qBAAqB,EACrBC,gBAAgB,EAChBC,uBAAuB,EACL;IAClB,OAAO,eAAeI,eACpBC,IAA2C;QAE3C,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGH;QAEJ,MAAMI,kBAAkBC,mBAAmBJ;QAE3C,MAAMN;QAENhB,kBAAkByB,gBAAgBE,OAAO,EAAEZ;QAE3C,OAAQU,gBAAgBG,IAAI;YAC1B,KAAK7B,iBAAiB8B,MAAM;gBAC1B,OAAO,MAAMhB,uBAAuBW,QAAQC;YAC9C,KAAK1B,iBAAiB+B,KAAK;gBACzB,OAAO,MAAMhB,sBAAsBU,QAAQC;YAC7C;gBACE,MAAM3B,UAAUiC,aAAa,CAAC;oBAC5BJ,SAAS;gBACX;QACJ;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASD,mBAAmBJ,MAAe;IAChD,IAAI,CAACrB,SAASqB,SAAS;QACrB,MAAMxB,UAAUiC,aAAa,CAAC;YAC5BJ,SAAS;QACX;IACF;IAEA,MAAM,EAAEC,IAAI,EAAED,OAAO,EAAE,GAAGL;IAE1B,IACE,CAACM,QACD,OAAOA,SAAS,YAChB,CAACV,OAAOc,MAAM,CAACjC,kBAAkBkC,QAAQ,CAACL,OAC1C;QACA,MAAM9B,UAAUiC,aAAa,CAAC;YAC5BJ,SAAS;QACX;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAACA,WAAW,OAAOA,YAAY,YAAYA,QAAQO,MAAM,IAAI,IAAI;QACnE,MAAMpC,UAAUiC,aAAa,CAAC;YAC5BJ,SACE;QACJ;IACF;IAEA,OAAOL;AACT"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ export { handlers as permittedMethods, createSnapsMethodMiddleware, } from './pe
|
|
|
3
3
|
export * from './restricted';
|
|
4
4
|
export { SnapCaveatType } from '@metamask/snaps-utils';
|
|
5
5
|
export { selectHooks } from './utils';
|
|
6
|
-
export type { RequestFunction, SnapsGlobalObject } from './request';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export type { InstallSnapsResult } from '@metamask/snaps-utils';
|
|
4
|
-
export declare type InstallSnapsHook = (requestedSnaps: RequestedPermissions) => Promise<InstallSnapsResult>;
|
|
1
|
+
import type { RequestSnapsParams, RequestSnapsResult } from '@metamask/snaps-sdk';
|
|
2
|
+
export declare type InstallSnapsHook = (requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>;
|
|
5
3
|
/**
|
|
6
4
|
* Typechecks the requested snaps and passes them to the permissions
|
|
7
5
|
* controller for installation.
|
|
@@ -13,4 +11,4 @@ export declare type InstallSnapsHook = (requestedSnaps: RequestedPermissions) =>
|
|
|
13
11
|
* @returns An object containing the installed snaps.
|
|
14
12
|
* @throws If the params are invalid or the snap installation fails.
|
|
15
13
|
*/
|
|
16
|
-
export declare function handleInstallSnaps(requestedSnaps:
|
|
14
|
+
export declare function handleInstallSnaps(requestedSnaps: RequestSnapsParams, installSnaps: InstallSnapsHook): Promise<RequestSnapsResult>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from '@metamask/permission-controller';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GetFileParams } from '@metamask/snaps-sdk';
|
|
3
|
+
import type { InferMatching } from '@metamask/snaps-utils';
|
|
3
4
|
export declare const GetFileArgsStruct: import("superstruct").Struct<{
|
|
4
5
|
path: string;
|
|
5
6
|
encoding?: "base64" | "utf8" | "hex" | undefined;
|
|
@@ -7,8 +8,8 @@ export declare const GetFileArgsStruct: import("superstruct").Struct<{
|
|
|
7
8
|
path: import("superstruct").Struct<string, null>;
|
|
8
9
|
encoding: import("superstruct").Struct<"base64" | "utf8" | "hex" | undefined, null>;
|
|
9
10
|
}>;
|
|
10
|
-
export declare type
|
|
11
|
-
export declare const getFileHandler: PermittedHandlerExport<GetFileHooks,
|
|
11
|
+
export declare type InferredGetFileParams = InferMatching<typeof GetFileArgsStruct, GetFileParams>;
|
|
12
|
+
export declare const getFileHandler: PermittedHandlerExport<GetFileHooks, InferredGetFileParams, string>;
|
|
12
13
|
export declare type GetFileHooks = {
|
|
13
|
-
getSnapFile: (path:
|
|
14
|
+
getSnapFile: (path: InferredGetFileParams['path'], encoding: InferredGetFileParams['encoding']) => Promise<string>;
|
|
14
15
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from '@metamask/permission-controller';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GetSnapsResult } from '@metamask/snaps-sdk';
|
|
3
3
|
import type { JsonRpcParams } from '@metamask/utils';
|
|
4
4
|
/**
|
|
5
5
|
* `wallet_getSnaps` gets the requester's permitted and installed Snaps.
|
|
6
6
|
*/
|
|
7
|
-
export declare const getSnapsHandler: PermittedHandlerExport<GetSnapsHooks, JsonRpcParams,
|
|
7
|
+
export declare const getSnapsHandler: PermittedHandlerExport<GetSnapsHooks, JsonRpcParams, GetSnapsResult>;
|
|
8
8
|
export declare type GetSnapsHooks = {
|
|
9
9
|
/**
|
|
10
10
|
* @returns The permitted and installed snaps for the requesting origin.
|
|
11
11
|
*/
|
|
12
|
-
getSnaps: () => Promise<
|
|
12
|
+
getSnaps: () => Promise<GetSnapsResult>;
|
|
13
13
|
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
export declare const methodHandlers: {
|
|
2
|
-
wallet_getSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-
|
|
3
|
-
wallet_requestSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps").RequestSnapsHooks, import("@metamask/
|
|
4
|
-
wallet_invokeSnap: import("@metamask/permission-controller").PermittedHandlerExport<void, import("
|
|
5
|
-
wallet_invokeKeyring: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring").InvokeKeyringHooks, import("@metamask/
|
|
6
|
-
snap_getFile: import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile").GetFileHooks,
|
|
7
|
-
path: string;
|
|
8
|
-
encoding?: "base64" | "utf8" | "hex" | undefined;
|
|
9
|
-
}, string>;
|
|
2
|
+
wallet_getSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult>;
|
|
3
|
+
wallet_requestSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult>;
|
|
4
|
+
wallet_invokeSnap: import("@metamask/permission-controller").PermittedHandlerExport<void, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
|
|
5
|
+
wallet_invokeKeyring: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
|
|
6
|
+
snap_getFile: import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string>;
|
|
10
7
|
};
|
|
11
|
-
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-
|
|
12
|
-
path: string;
|
|
13
|
-
encoding?: "base64" | "utf8" | "hex" | undefined;
|
|
14
|
-
}, string> | import("@metamask/permission-controller").PermittedHandlerExport<void, import("./invokeSnapSugar").InvokeSnapSugarArgs, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring").InvokeKeyringHooks, import("@metamask/utils").JsonRpcRequest<import("@metamask/utils").JsonRpcParams>, import("@metamask/utils").Json>)[];
|
|
8
|
+
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<void, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from '@metamask/permission-controller';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type { JsonRpcRequest } from '@metamask/utils';
|
|
5
|
-
import { type Json } from '@metamask/utils';
|
|
2
|
+
import type { InvokeKeyringResult, InvokeSnapParams } from '@metamask/snaps-sdk';
|
|
3
|
+
import type { Snap, SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
6
4
|
/**
|
|
7
5
|
* `wallet_invokeKeyring` gets the requester's permitted and installed Snaps.
|
|
8
6
|
*/
|
|
9
|
-
export declare const invokeKeyringHandler: PermittedHandlerExport<InvokeKeyringHooks,
|
|
7
|
+
export declare const invokeKeyringHandler: PermittedHandlerExport<InvokeKeyringHooks, InvokeSnapParams, InvokeKeyringResult>;
|
|
10
8
|
export declare type InvokeKeyringHooks = {
|
|
11
9
|
hasPermission: (origin: string, permissionName: string) => boolean;
|
|
12
10
|
handleSnapRpcRequest: ({ snapId, origin, handler, request, }: SnapRpcHookArgs & {
|
|
13
|
-
snapId:
|
|
11
|
+
snapId: string;
|
|
14
12
|
}) => Promise<unknown>;
|
|
15
|
-
getSnap: (snapId:
|
|
13
|
+
getSnap: (snapId: string) => Snap | undefined;
|
|
16
14
|
getAllowedKeyringMethods: (origin: string) => string[];
|
|
17
15
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from '@metamask/json-rpc-engine';
|
|
2
2
|
import type { PermittedHandlerExport } from '@metamask/permission-controller';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
snapId: string;
|
|
6
|
-
request: Record<string, Json>;
|
|
7
|
-
};
|
|
3
|
+
import type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { JsonRpcRequest } from '@metamask/utils';
|
|
8
5
|
/**
|
|
9
6
|
* `wallet_invokeSnap` attempts to invoke an RPC method of the specified Snap.
|
|
10
7
|
*/
|
|
11
|
-
export declare const invokeSnapSugarHandler: PermittedHandlerExport<void,
|
|
8
|
+
export declare const invokeSnapSugarHandler: PermittedHandlerExport<void, InvokeSnapParams, InvokeSnapResult>;
|
|
12
9
|
/**
|
|
13
10
|
* The `wallet_invokeSnap` method implementation.
|
|
14
11
|
* Reroutes incoming JSON-RPC requests that are targeting snaps, by modifying the method and params.
|
|
@@ -21,7 +18,7 @@ export declare const invokeSnapSugarHandler: PermittedHandlerExport<void, Invoke
|
|
|
21
18
|
* @returns Nothing.
|
|
22
19
|
* @throws If the params are invalid.
|
|
23
20
|
*/
|
|
24
|
-
export declare function invokeSnapSugar(req: JsonRpcRequest<
|
|
21
|
+
export declare function invokeSnapSugar(req: JsonRpcRequest<InvokeSnapParams>, _res: unknown, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): void;
|
|
25
22
|
/**
|
|
26
23
|
* Validates the wallet_invokeSnap method `params` and returns them cast to the correct
|
|
27
24
|
* type. Throws if validation fails.
|
|
@@ -29,4 +26,4 @@ export declare function invokeSnapSugar(req: JsonRpcRequest<InvokeSnapSugarArgs>
|
|
|
29
26
|
* @param params - The unvalidated params object from the method request.
|
|
30
27
|
* @returns The validated method parameter object.
|
|
31
28
|
*/
|
|
32
|
-
export declare function getValidatedParams(params: unknown):
|
|
29
|
+
export declare function getValidatedParams(params: unknown): InvokeSnapParams;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PermissionConstraint, RequestedPermissions, PermittedHandlerExport } from '@metamask/permission-controller';
|
|
2
|
+
import type { RequestSnapsParams, RequestSnapsResult } from '@metamask/snaps-sdk';
|
|
2
3
|
import type { SnapsPermissionRequest } from '@metamask/snaps-utils';
|
|
3
|
-
import type { InstallSnapsHook
|
|
4
|
+
import type { InstallSnapsHook } from './common/snapInstallation';
|
|
4
5
|
/**
|
|
5
6
|
* `wallet_requestSnaps` installs the requested Snaps and requests permission to use them if necessary.
|
|
6
7
|
*/
|
|
7
|
-
export declare const requestSnapsHandler: PermittedHandlerExport<RequestSnapsHooks,
|
|
8
|
+
export declare const requestSnapsHandler: PermittedHandlerExport<RequestSnapsHooks, RequestSnapsParams, RequestSnapsResult>;
|
|
8
9
|
export declare type RequestSnapsHooks = {
|
|
9
10
|
/**
|
|
10
11
|
* Installs the requested snaps if they are permitted.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PermissionConstraint, RestrictedMethodCaveatSpecificationConstraint, Caveat } from '@metamask/permission-controller';
|
|
2
|
+
import type { GetBip44EntropyParams } from '@metamask/snaps-sdk';
|
|
2
3
|
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
3
4
|
import type { Json } from '@metamask/utils';
|
|
4
|
-
import type { GetBip44EntropyParams } from '../getBip44Entropy';
|
|
5
5
|
/**
|
|
6
6
|
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
7
7
|
* Note that this function does not do any validation, that's handled by the
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
-
import
|
|
4
|
-
import type { EnumToUnion } from '@metamask/snaps-
|
|
3
|
+
import { DialogType } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { DialogParams, EnumToUnion, Component } from '@metamask/snaps-sdk';
|
|
5
|
+
import type { InferMatching } from '@metamask/snaps-utils';
|
|
5
6
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
6
7
|
import type { Infer, Struct } from 'superstruct';
|
|
7
8
|
import { type MethodHooksObject } from '../utils';
|
|
8
9
|
declare const methodName = "snap_dialog";
|
|
9
|
-
export declare enum DialogType {
|
|
10
|
-
Alert = "alert",
|
|
11
|
-
Confirmation = "confirmation",
|
|
12
|
-
Prompt = "prompt"
|
|
13
|
-
}
|
|
14
10
|
declare const PlaceholderStruct: Struct<string | undefined, null>;
|
|
15
11
|
export declare type Placeholder = Infer<typeof PlaceholderStruct>;
|
|
16
12
|
declare type ShowDialog = (snapId: string, type: EnumToUnion<DialogType>, content: Component, placeholder?: Placeholder) => Promise<null | boolean | string>;
|
|
@@ -46,67 +42,124 @@ export declare const dialogBuilder: Readonly<{
|
|
|
46
42
|
}>;
|
|
47
43
|
declare const DialogParametersStruct: Struct<{
|
|
48
44
|
type: "alert";
|
|
49
|
-
content: import("@metamask/snaps-
|
|
45
|
+
content: import("@metamask/snaps-sdk").Panel | {
|
|
50
46
|
value: string;
|
|
51
|
-
type: import("@metamask/snaps-
|
|
47
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
48
|
+
sensitive?: boolean | undefined;
|
|
52
49
|
} | {
|
|
53
|
-
type: import("@metamask/snaps-
|
|
50
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
54
51
|
} | {
|
|
55
52
|
value: string;
|
|
56
|
-
type: import("@metamask/snaps-
|
|
53
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
57
54
|
} | {
|
|
58
|
-
|
|
55
|
+
value: string;
|
|
56
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
57
|
+
} | {
|
|
58
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
59
59
|
} | {
|
|
60
60
|
value: string;
|
|
61
|
-
type: import("@metamask/snaps-
|
|
61
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
62
62
|
markdown?: boolean | undefined;
|
|
63
63
|
} | {
|
|
64
64
|
value: string;
|
|
65
|
-
type: import("@metamask/snaps-
|
|
65
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
66
|
+
} | {
|
|
67
|
+
value: {
|
|
68
|
+
value: string;
|
|
69
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
70
|
+
} | {
|
|
71
|
+
value: string;
|
|
72
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
73
|
+
markdown?: boolean | undefined;
|
|
74
|
+
} | {
|
|
75
|
+
value: string;
|
|
76
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
77
|
+
};
|
|
78
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
79
|
+
label: string;
|
|
80
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
66
81
|
};
|
|
67
82
|
} | {
|
|
68
83
|
type: "confirmation";
|
|
69
|
-
content: import("@metamask/snaps-
|
|
84
|
+
content: import("@metamask/snaps-sdk").Panel | {
|
|
70
85
|
value: string;
|
|
71
|
-
type: import("@metamask/snaps-
|
|
86
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
87
|
+
sensitive?: boolean | undefined;
|
|
72
88
|
} | {
|
|
73
|
-
type: import("@metamask/snaps-
|
|
89
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
90
|
+
} | {
|
|
91
|
+
value: string;
|
|
92
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
74
93
|
} | {
|
|
75
94
|
value: string;
|
|
76
|
-
type: import("@metamask/snaps-
|
|
95
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
77
96
|
} | {
|
|
78
|
-
type: import("@metamask/snaps-
|
|
97
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
79
98
|
} | {
|
|
80
99
|
value: string;
|
|
81
|
-
type: import("@metamask/snaps-
|
|
100
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
82
101
|
markdown?: boolean | undefined;
|
|
83
102
|
} | {
|
|
84
103
|
value: string;
|
|
85
|
-
type: import("@metamask/snaps-
|
|
104
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
105
|
+
} | {
|
|
106
|
+
value: {
|
|
107
|
+
value: string;
|
|
108
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
109
|
+
} | {
|
|
110
|
+
value: string;
|
|
111
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
112
|
+
markdown?: boolean | undefined;
|
|
113
|
+
} | {
|
|
114
|
+
value: string;
|
|
115
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
116
|
+
};
|
|
117
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
118
|
+
label: string;
|
|
119
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
86
120
|
};
|
|
87
121
|
} | {
|
|
88
122
|
type: "prompt";
|
|
89
|
-
content: import("@metamask/snaps-
|
|
123
|
+
content: import("@metamask/snaps-sdk").Panel | {
|
|
90
124
|
value: string;
|
|
91
|
-
type: import("@metamask/snaps-
|
|
125
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
126
|
+
sensitive?: boolean | undefined;
|
|
127
|
+
} | {
|
|
128
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
92
129
|
} | {
|
|
93
|
-
|
|
130
|
+
value: string;
|
|
131
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
94
132
|
} | {
|
|
95
133
|
value: string;
|
|
96
|
-
type: import("@metamask/snaps-
|
|
134
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
97
135
|
} | {
|
|
98
|
-
type: import("@metamask/snaps-
|
|
136
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
99
137
|
} | {
|
|
100
138
|
value: string;
|
|
101
|
-
type: import("@metamask/snaps-
|
|
139
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
102
140
|
markdown?: boolean | undefined;
|
|
103
141
|
} | {
|
|
104
142
|
value: string;
|
|
105
|
-
type: import("@metamask/snaps-
|
|
143
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
144
|
+
} | {
|
|
145
|
+
value: {
|
|
146
|
+
value: string;
|
|
147
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
148
|
+
} | {
|
|
149
|
+
value: string;
|
|
150
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
151
|
+
markdown?: boolean | undefined;
|
|
152
|
+
} | {
|
|
153
|
+
value: string;
|
|
154
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
155
|
+
};
|
|
156
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
157
|
+
label: string;
|
|
158
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
106
159
|
};
|
|
107
160
|
placeholder?: string | undefined;
|
|
108
161
|
}, null>;
|
|
109
|
-
export declare type DialogParameters =
|
|
162
|
+
export declare type DialogParameters = InferMatching<typeof DialogParametersStruct, DialogParams>;
|
|
110
163
|
/**
|
|
111
164
|
* Builds the method implementation for `snap_dialog`.
|
|
112
165
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { JsonSLIP10Node } from '@metamask/key-tree';
|
|
2
1
|
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
3
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
4
|
-
import type {
|
|
3
|
+
import type { GetBip32EntropyParams, GetBip32EntropyResult } from '@metamask/snaps-sdk';
|
|
5
4
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
6
5
|
import type { MethodHooksObject } from '../utils';
|
|
7
6
|
declare const targetName = "snap_getBip32Entropy";
|
|
@@ -41,5 +40,5 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
41
40
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
42
41
|
* @throws If the params are invalid.
|
|
43
42
|
*/
|
|
44
|
-
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<
|
|
43
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
45
44
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { GetBip32PublicKeyParams, GetBip32PublicKeyResult } from '@metamask/snaps-sdk';
|
|
3
4
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
5
|
import type { MethodHooksObject } from '../utils';
|
|
5
6
|
declare const targetName = "snap_getBip32PublicKey";
|
|
@@ -18,11 +19,6 @@ export declare type GetBip32PublicKeyMethodHooks = {
|
|
|
18
19
|
declare type GetBip32PublicKeySpecificationBuilderOptions = {
|
|
19
20
|
methodHooks: GetBip32PublicKeyMethodHooks;
|
|
20
21
|
};
|
|
21
|
-
declare type GetBip32PublicKeyParameters = {
|
|
22
|
-
path: ['m', ...(`${number}` | `${number}'`)[]];
|
|
23
|
-
curve: 'secp256k1' | 'ed25519';
|
|
24
|
-
compressed?: boolean;
|
|
25
|
-
};
|
|
26
22
|
export declare const Bip32PublicKeyArgsStruct: import("superstruct").Struct<{
|
|
27
23
|
path: string[];
|
|
28
24
|
curve: "ed25519" | "secp256k1";
|
|
@@ -56,5 +52,5 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
56
52
|
* @returns The method implementation which returns a public key.
|
|
57
53
|
* @throws If the params are invalid.
|
|
58
54
|
*/
|
|
59
|
-
export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<
|
|
55
|
+
export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
60
56
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { JsonBIP44CoinTypeNode } from '@metamask/key-tree';
|
|
2
1
|
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
3
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { GetBip44EntropyParams, GetBip44EntropyResult } from '@metamask/snaps-sdk';
|
|
4
4
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
5
5
|
import type { MethodHooksObject } from '../utils';
|
|
6
6
|
declare const targetName = "snap_getBip44Entropy";
|
|
@@ -19,9 +19,6 @@ export declare type GetBip44EntropyMethodHooks = {
|
|
|
19
19
|
declare type GetBip44EntropySpecificationBuilderOptions = {
|
|
20
20
|
methodHooks: GetBip44EntropyMethodHooks;
|
|
21
21
|
};
|
|
22
|
-
export declare type GetBip44EntropyParams = {
|
|
23
|
-
coinType: number;
|
|
24
|
-
};
|
|
25
22
|
export declare const getBip44EntropyBuilder: Readonly<{
|
|
26
23
|
readonly targetName: "snap_getBip44Entropy";
|
|
27
24
|
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip44EntropySpecificationBuilderOptions, {
|
|
@@ -45,5 +42,5 @@ export declare const getBip44EntropyBuilder: Readonly<{
|
|
|
45
42
|
* @returns The method implementation which returns a `BIP44CoinTypeNode`.
|
|
46
43
|
* @throws If the params are invalid.
|
|
47
44
|
*/
|
|
48
|
-
export declare function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<
|
|
45
|
+
export declare function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<GetBip44EntropyResult>;
|
|
49
46
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
-
import type {
|
|
3
|
+
import type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
5
|
import type { Infer } from 'superstruct';
|
|
5
6
|
import type { MethodHooksObject } from '../utils';
|
|
6
7
|
declare const targetName = "snap_getEntropy";
|
|
@@ -56,5 +57,5 @@ export declare type GetEntropyHooks = {
|
|
|
56
57
|
* once the extension is unlocked.
|
|
57
58
|
* @returns The method implementation.
|
|
58
59
|
*/
|
|
59
|
-
declare function getEntropyImplementation({ getMnemonic, getUnlockPromise, }: GetEntropyHooks): (options: RestrictedMethodOptions<
|
|
60
|
+
declare function getEntropyImplementation({ getMnemonic, getUnlockPromise, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyParams>) => Promise<GetEntropyResult>;
|
|
60
61
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, ValidPermissionSpecification, RestrictedMethodOptions, RestrictedMethodParameters } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { GetLocaleResult } from '@metamask/snaps-sdk';
|
|
3
4
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
4
5
|
import type { MethodHooksObject } from '../utils';
|
|
5
6
|
declare const methodName = "snap_getLocale";
|
|
@@ -43,5 +44,5 @@ export declare const getLocaleBuilder: Readonly<{
|
|
|
43
44
|
* @param hooks.getLocale - A function that returns the user selected locale.
|
|
44
45
|
* @returns The user selected locale.
|
|
45
46
|
*/
|
|
46
|
-
export declare function getImplementation({ getLocale }: GetLocaleMethodHooks): (_args: RestrictedMethodOptions<RestrictedMethodParameters>) => Promise<
|
|
47
|
+
export declare function getImplementation({ getLocale }: GetLocaleMethodHooks): (_args: RestrictedMethodOptions<RestrictedMethodParameters>) => Promise<GetLocaleResult>;
|
|
47
48
|
export {};
|