@metamask/snaps-rpc-methods 11.5.1 → 11.7.0
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 +17 -1
- package/dist/permitted/createInterface.cjs.map +1 -1
- package/dist/permitted/createInterface.d.cts +6 -18
- package/dist/permitted/createInterface.d.cts.map +1 -1
- package/dist/permitted/createInterface.d.mts +6 -18
- package/dist/permitted/createInterface.d.mts.map +1 -1
- package/dist/permitted/createInterface.mjs.map +1 -1
- package/dist/permitted/getInterfaceContext.cjs +62 -0
- package/dist/permitted/getInterfaceContext.cjs.map +1 -0
- package/dist/permitted/getInterfaceContext.d.cts +19 -0
- package/dist/permitted/getInterfaceContext.d.cts.map +1 -0
- package/dist/permitted/getInterfaceContext.d.mts +19 -0
- package/dist/permitted/getInterfaceContext.d.mts.map +1 -0
- package/dist/permitted/getInterfaceContext.mjs +59 -0
- package/dist/permitted/getInterfaceContext.mjs.map +1 -0
- package/dist/permitted/handlers.cjs +2 -0
- package/dist/permitted/handlers.cjs.map +1 -1
- package/dist/permitted/handlers.d.cts +2 -1
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +2 -1
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/handlers.mjs +2 -0
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +2 -2
- package/dist/permitted/updateInterface.d.mts +2 -2
- package/dist/restricted/dialog.cjs.map +1 -1
- package/dist/restricted/dialog.d.cts +62 -62
- package/dist/restricted/dialog.d.cts.map +1 -1
- package/dist/restricted/dialog.d.mts +62 -62
- package/dist/restricted/dialog.d.mts.map +1 -1
- package/dist/restricted/dialog.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +5 -1
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +12 -1
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +12 -1
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +5 -1
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +5 -1
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +12 -1
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +12 -1
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +5 -1
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +5 -6
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +12 -1
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +12 -1
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +5 -6
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +5 -1
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +12 -1
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +12 -1
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +5 -1
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/manageState.cjs +4 -1
- package/dist/restricted/manageState.cjs.map +1 -1
- package/dist/restricted/manageState.d.cts +5 -1
- package/dist/restricted/manageState.d.cts.map +1 -1
- package/dist/restricted/manageState.d.mts +5 -1
- package/dist/restricted/manageState.d.mts.map +1 -1
- package/dist/restricted/manageState.mjs +4 -1
- package/dist/restricted/manageState.mjs.map +1 -1
- package/dist/restricted/notify.cjs +49 -5
- package/dist/restricted/notify.cjs.map +1 -1
- package/dist/restricted/notify.d.cts +311 -13
- package/dist/restricted/notify.d.cts.map +1 -1
- package/dist/restricted/notify.d.mts +311 -13
- package/dist/restricted/notify.d.mts.map +1 -1
- package/dist/restricted/notify.mjs +52 -8
- package/dist/restricted/notify.mjs.map +1 -1
- package/dist/utils.cjs +8 -4
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +12 -3
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +12 -3
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +8 -4
- package/dist/utils.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
2
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
3
|
import { DialogType } from "@metamask/snaps-sdk";
|
|
4
|
-
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
|
|
5
5
|
import type { InferMatching } from "@metamask/snaps-utils";
|
|
6
6
|
import type { Infer } from "@metamask/superstruct";
|
|
7
7
|
import type { Json, NonEmptyArray } from "@metamask/utils";
|
|
@@ -28,7 +28,7 @@ type RequestUserApprovalOptions = {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
type RequestUserApproval = (opts: RequestUserApprovalOptions) => Promise<boolean | null | string | Json>;
|
|
31
|
-
type CreateInterface = (snapId: string, content: ComponentOrElement) => Promise<string>;
|
|
31
|
+
type CreateInterface = (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
|
|
32
32
|
type GetInterface = (snapId: string, id: string) => {
|
|
33
33
|
content: ComponentOrElement;
|
|
34
34
|
snapId: SnapId;
|
|
@@ -75,7 +75,7 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
75
75
|
id: string;
|
|
76
76
|
} | {
|
|
77
77
|
type: "alert";
|
|
78
|
-
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
78
|
+
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
79
79
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
80
80
|
value: string;
|
|
81
81
|
sensitive?: boolean | undefined;
|
|
@@ -128,23 +128,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
128
128
|
} | {
|
|
129
129
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
130
130
|
name: string;
|
|
131
|
-
/**
|
|
132
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
133
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
134
|
-
* - An alert, for displaying information.
|
|
135
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
136
|
-
* - A prompt, for inputting some information.
|
|
137
|
-
*
|
|
138
|
-
* @param options - The specification builder options.
|
|
139
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
140
|
-
* permission.
|
|
141
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
142
|
-
* implementation.
|
|
143
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
144
|
-
*/
|
|
145
131
|
children: ({
|
|
146
132
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
147
133
|
name: string;
|
|
134
|
+
/**
|
|
135
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
136
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
137
|
+
* - An alert, for displaying information.
|
|
138
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
139
|
+
* - A prompt, for inputting some information.
|
|
140
|
+
*
|
|
141
|
+
* @param options - The specification builder options.
|
|
142
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
143
|
+
* permission.
|
|
144
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
145
|
+
* implementation.
|
|
146
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
147
|
+
*/
|
|
148
148
|
error?: string | undefined;
|
|
149
149
|
inputType?: "number" | "text" | "password" | undefined;
|
|
150
150
|
value?: string | undefined;
|
|
@@ -176,7 +176,7 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
176
176
|
id: string;
|
|
177
177
|
} | {
|
|
178
178
|
type: "confirmation";
|
|
179
|
-
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
179
|
+
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
180
180
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
181
181
|
value: string;
|
|
182
182
|
sensitive?: boolean | undefined;
|
|
@@ -229,23 +229,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
229
229
|
} | {
|
|
230
230
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
231
231
|
name: string;
|
|
232
|
-
/**
|
|
233
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
234
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
235
|
-
* - An alert, for displaying information.
|
|
236
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
237
|
-
* - A prompt, for inputting some information.
|
|
238
|
-
*
|
|
239
|
-
* @param options - The specification builder options.
|
|
240
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
241
|
-
* permission.
|
|
242
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
243
|
-
* implementation.
|
|
244
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
245
|
-
*/
|
|
246
232
|
children: ({
|
|
247
233
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
248
234
|
name: string;
|
|
235
|
+
/**
|
|
236
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
237
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
238
|
+
* - An alert, for displaying information.
|
|
239
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
240
|
+
* - A prompt, for inputting some information.
|
|
241
|
+
*
|
|
242
|
+
* @param options - The specification builder options.
|
|
243
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
244
|
+
* permission.
|
|
245
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
246
|
+
* implementation.
|
|
247
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
248
|
+
*/
|
|
249
249
|
error?: string | undefined;
|
|
250
250
|
inputType?: "number" | "text" | "password" | undefined;
|
|
251
251
|
value?: string | undefined;
|
|
@@ -278,7 +278,7 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
278
278
|
placeholder?: string | undefined;
|
|
279
279
|
} | {
|
|
280
280
|
type: "prompt";
|
|
281
|
-
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
281
|
+
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
282
282
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
283
283
|
value: string;
|
|
284
284
|
sensitive?: boolean | undefined;
|
|
@@ -331,23 +331,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
331
331
|
} | {
|
|
332
332
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
333
333
|
name: string;
|
|
334
|
-
/**
|
|
335
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
336
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
337
|
-
* - An alert, for displaying information.
|
|
338
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
339
|
-
* - A prompt, for inputting some information.
|
|
340
|
-
*
|
|
341
|
-
* @param options - The specification builder options.
|
|
342
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
343
|
-
* permission.
|
|
344
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
345
|
-
* implementation.
|
|
346
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
347
|
-
*/
|
|
348
334
|
children: ({
|
|
349
335
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
350
336
|
name: string;
|
|
337
|
+
/**
|
|
338
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
339
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
340
|
+
* - An alert, for displaying information.
|
|
341
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
342
|
+
* - A prompt, for inputting some information.
|
|
343
|
+
*
|
|
344
|
+
* @param options - The specification builder options.
|
|
345
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
346
|
+
* permission.
|
|
347
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
348
|
+
* implementation.
|
|
349
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
350
|
+
*/
|
|
351
351
|
error?: string | undefined;
|
|
352
352
|
inputType?: "number" | "text" | "password" | undefined;
|
|
353
353
|
value?: string | undefined;
|
|
@@ -378,7 +378,7 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
378
378
|
} | {
|
|
379
379
|
id: string;
|
|
380
380
|
} | {
|
|
381
|
-
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
381
|
+
content: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
382
382
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
383
383
|
value: string;
|
|
384
384
|
sensitive?: boolean | undefined;
|
|
@@ -431,23 +431,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
431
431
|
} | {
|
|
432
432
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
433
433
|
name: string;
|
|
434
|
-
/**
|
|
435
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
436
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
437
|
-
* - An alert, for displaying information.
|
|
438
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
439
|
-
* - A prompt, for inputting some information.
|
|
440
|
-
*
|
|
441
|
-
* @param options - The specification builder options.
|
|
442
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
443
|
-
* permission.
|
|
444
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
445
|
-
* implementation.
|
|
446
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
447
|
-
*/
|
|
448
434
|
children: ({
|
|
449
435
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
450
436
|
name: string;
|
|
437
|
+
/**
|
|
438
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
439
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
440
|
+
* - An alert, for displaying information.
|
|
441
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
442
|
+
* - A prompt, for inputting some information.
|
|
443
|
+
*
|
|
444
|
+
* @param options - The specification builder options.
|
|
445
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
446
|
+
* permission.
|
|
447
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
448
|
+
* implementation.
|
|
449
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
450
|
+
*/
|
|
451
451
|
error?: string | undefined;
|
|
452
452
|
inputType?: "number" | "text" | "password" | undefined;
|
|
453
453
|
value?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.mts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,O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E,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,MAAwB;IAC7C,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","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 {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm 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 confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.mjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,cAAc,EACf,4BAA4B;AAa7B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,8BAA8B;AAE/E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAwB;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAkE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GACuB,EAAE,EAAE;IACtC,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,uBAAuB,CAAC,WAAW,CAAC;QAC1D,YAAY,EAAE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;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","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 {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm 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 confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
@@ -36,6 +36,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
36
36
|
const methodHooks = {
|
|
37
37
|
getMnemonic: true,
|
|
38
38
|
getUnlockPromise: true,
|
|
39
|
+
getClientCryptography: true,
|
|
39
40
|
};
|
|
40
41
|
exports.getBip32EntropyBuilder = Object.freeze({
|
|
41
42
|
targetName,
|
|
@@ -49,10 +50,12 @@ exports.getBip32EntropyBuilder = Object.freeze({
|
|
|
49
50
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
50
51
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
51
52
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
53
|
+
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
54
|
+
* functions to use for the client.
|
|
52
55
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
53
56
|
* @throws If the params are invalid.
|
|
54
57
|
*/
|
|
55
|
-
function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
58
|
+
function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
56
59
|
return async function getBip32Entropy(args) {
|
|
57
60
|
await getUnlockPromise(true);
|
|
58
61
|
const { params } = args;
|
|
@@ -61,6 +64,7 @@ function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
|
61
64
|
curve: params.curve,
|
|
62
65
|
path: params.path,
|
|
63
66
|
secretRecoveryPhrase: await getMnemonic(),
|
|
67
|
+
cryptographicFunctions: getClientCryptography(),
|
|
64
68
|
});
|
|
65
69
|
return node.toJSON();
|
|
66
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2CAAyC;AAGzC,wCAAmC;AAEnC,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAqC1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,E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AW,EAAE;YACzC,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAtBD,sEAsBC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CryptographicFunctions } from "@metamask/key-tree";
|
|
1
2
|
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
3
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
4
|
import type { GetBip32EntropyParams, GetBip32EntropyResult } from "@metamask/snaps-sdk";
|
|
@@ -15,6 +16,14 @@ export type GetBip32EntropyMethodHooks = {
|
|
|
15
16
|
* @returns A promise that resolves once the extension is unlocked.
|
|
16
17
|
*/
|
|
17
18
|
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the cryptographic functions to use for the client. This may return an
|
|
21
|
+
* empty object or `undefined` to fall back to the default cryptographic
|
|
22
|
+
* functions.
|
|
23
|
+
*
|
|
24
|
+
* @returns The cryptographic functions to use for the client.
|
|
25
|
+
*/
|
|
26
|
+
getClientCryptography: () => CryptographicFunctions | undefined;
|
|
18
27
|
};
|
|
19
28
|
type GetBip32EntropySpecificationBuilderOptions = {
|
|
20
29
|
methodHooks: GetBip32EntropyMethodHooks;
|
|
@@ -37,9 +46,11 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
37
46
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
38
47
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
39
48
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
49
|
+
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
50
|
+
* functions to use for the client.
|
|
40
51
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
41
52
|
* @throws If the params are invalid.
|
|
42
53
|
*/
|
|
43
|
-
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
54
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
44
55
|
export {};
|
|
45
56
|
//# sourceMappingURL=getBip32Entropy.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAiDF,eAAO,MAAM,sBAAsB;;;wBA9CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA8C/B,CAAC;AAEZ;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAelC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CryptographicFunctions } from "@metamask/key-tree";
|
|
1
2
|
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
3
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
4
|
import type { GetBip32EntropyParams, GetBip32EntropyResult } from "@metamask/snaps-sdk";
|
|
@@ -15,6 +16,14 @@ export type GetBip32EntropyMethodHooks = {
|
|
|
15
16
|
* @returns A promise that resolves once the extension is unlocked.
|
|
16
17
|
*/
|
|
17
18
|
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the cryptographic functions to use for the client. This may return an
|
|
21
|
+
* empty object or `undefined` to fall back to the default cryptographic
|
|
22
|
+
* functions.
|
|
23
|
+
*
|
|
24
|
+
* @returns The cryptographic functions to use for the client.
|
|
25
|
+
*/
|
|
26
|
+
getClientCryptography: () => CryptographicFunctions | undefined;
|
|
18
27
|
};
|
|
19
28
|
type GetBip32EntropySpecificationBuilderOptions = {
|
|
20
29
|
methodHooks: GetBip32EntropyMethodHooks;
|
|
@@ -37,9 +46,11 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
37
46
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
38
47
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
39
48
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
49
|
+
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
50
|
+
* functions to use for the client.
|
|
40
51
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
41
52
|
* @throws If the params are invalid.
|
|
42
53
|
*/
|
|
43
|
-
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
54
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
44
55
|
export {};
|
|
45
56
|
//# sourceMappingURL=getBip32Entropy.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,E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,CAAC;CACzC,CAAC;AAiDF,eAAO,MAAM,sBAAsB;;;wBA9CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA8C/B,CAAC;AAEZ;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAelC"}
|
|
@@ -33,6 +33,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
33
33
|
const methodHooks = {
|
|
34
34
|
getMnemonic: true,
|
|
35
35
|
getUnlockPromise: true,
|
|
36
|
+
getClientCryptography: true,
|
|
36
37
|
};
|
|
37
38
|
export const getBip32EntropyBuilder = Object.freeze({
|
|
38
39
|
targetName,
|
|
@@ -46,10 +47,12 @@ export const getBip32EntropyBuilder = Object.freeze({
|
|
|
46
47
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
47
48
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
48
49
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
50
|
+
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
51
|
+
* functions to use for the client.
|
|
49
52
|
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
50
53
|
* @throws If the params are invalid.
|
|
51
54
|
*/
|
|
52
|
-
export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
55
|
+
export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
53
56
|
return async function getBip32Entropy(args) {
|
|
54
57
|
await getUnlockPromise(true);
|
|
55
58
|
const { params } = args;
|
|
@@ -58,6 +61,7 @@ export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }
|
|
|
58
61
|
curve: params.curve,
|
|
59
62
|
path: params.path,
|
|
60
63
|
secretRecoveryPhrase: await getMnemonic(),
|
|
64
|
+
cryptographicFunctions: getClientCryptography(),
|
|
61
65
|
});
|
|
62
66
|
return node.toJSON();
|
|
63
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBip32Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,OAAO,EAAE,qBAAiB;AAEnC,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAqC1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,wBAAwB,EAC3D,CAAC;gBACD,MAAM,SAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,cAAc,CAAC,wBAAwB,WAAW;iBAClF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACM;IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC,CAAC;QAEf,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB,EAAE,MAAM,WAAW,EAAE;YACzC,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\n};\n\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n getClientCryptography,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -42,6 +42,7 @@ const specificationBuilder = ({ methodHooks }) => {
|
|
|
42
42
|
const methodHooks = {
|
|
43
43
|
getMnemonic: true,
|
|
44
44
|
getUnlockPromise: true,
|
|
45
|
+
getClientCryptography: true,
|
|
45
46
|
};
|
|
46
47
|
exports.getBip32PublicKeyBuilder = Object.freeze({
|
|
47
48
|
targetName,
|
|
@@ -55,10 +56,12 @@ exports.getBip32PublicKeyBuilder = Object.freeze({
|
|
|
55
56
|
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
56
57
|
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
57
58
|
* and prompts the user to unlock their MetaMask if it is locked.
|
|
59
|
+
* @param hooks.getClientCryptography - A function to retrieve the cryptographic
|
|
60
|
+
* functions to use for the client.
|
|
58
61
|
* @returns The method implementation which returns a public key.
|
|
59
62
|
* @throws If the params are invalid.
|
|
60
63
|
*/
|
|
61
|
-
function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
64
|
+
function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, getClientCryptography, }) {
|
|
62
65
|
return async function getBip32PublicKey(args) {
|
|
63
66
|
await getUnlockPromise(true);
|
|
64
67
|
(0, utils_1.assertStruct)(args.params, exports.Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpc_errors_1.rpcErrors.invalidParams);
|
|
@@ -67,6 +70,7 @@ function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
|
67
70
|
curve: params.curve,
|
|
68
71
|
path: params.path,
|
|
69
72
|
secretRecoveryPhrase: await getMnemonic(),
|
|
73
|
+
cryptographicFunctions: getClientCryptography(),
|
|
70
74
|
});
|
|
71
75
|
if (params.compressed) {
|
|
72
76
|
return node.compressedPublicKey;
|