@metamask/snaps-rpc-methods 11.1.1 → 11.3.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 +95 -1
- package/dist/permitted/createInterface.d.cts +2 -0
- package/dist/permitted/createInterface.d.cts.map +1 -1
- package/dist/permitted/createInterface.d.mts +2 -0
- package/dist/permitted/createInterface.d.mts.map +1 -1
- package/dist/permitted/getCurrencyRate.cjs +63 -0
- package/dist/permitted/getCurrencyRate.cjs.map +1 -0
- package/dist/permitted/getCurrencyRate.d.cts +20 -0
- package/dist/permitted/getCurrencyRate.d.cts.map +1 -0
- package/dist/permitted/getCurrencyRate.d.mts +20 -0
- package/dist/permitted/getCurrencyRate.d.mts.map +1 -0
- package/dist/permitted/getCurrencyRate.mjs +60 -0
- package/dist/permitted/getCurrencyRate.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/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +2 -1
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +2 -1
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +2 -0
- package/dist/permitted/updateInterface.d.cts.map +1 -1
- package/dist/permitted/updateInterface.d.mts +2 -0
- package/dist/permitted/updateInterface.d.mts.map +1 -1
- package/dist/restricted/dialog.d.cts +4 -0
- package/dist/restricted/dialog.d.cts.map +1 -1
- package/dist/restricted/dialog.d.mts +4 -0
- package/dist/restricted/dialog.d.mts.map +1 -1
- package/dist/restricted/notify.cjs +61 -5
- package/dist/restricted/notify.cjs.map +1 -1
- package/dist/restricted/notify.d.cts +96 -15
- package/dist/restricted/notify.d.cts.map +1 -1
- package/dist/restricted/notify.d.mts +96 -15
- package/dist/restricted/notify.d.mts.map +1 -1
- package/dist/restricted/notify.mjs +64 -8
- package/dist/restricted/notify.mjs.map +1 -1
- package/package.json +30 -15
|
@@ -1,33 +1,109 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from "@metamask/permission-controller";
|
|
2
2
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import type { NotifyParams, NotifyResult, NotificationComponent } from "@metamask/snaps-sdk";
|
|
4
|
+
import { type Snap } from "@metamask/snaps-utils";
|
|
5
|
+
import type { InferMatching } from "@metamask/snaps-utils";
|
|
5
6
|
import type { NonEmptyArray } from "@metamask/utils";
|
|
6
7
|
import { type MethodHooksObject } from "../utils.mjs";
|
|
7
8
|
declare const methodName = "snap_notify";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Enum type to determine notification type.
|
|
11
|
-
*/
|
|
12
|
-
type: EnumToUnion<NotificationType>;
|
|
13
|
-
/**
|
|
14
|
-
* A message to show on the notification.
|
|
15
|
-
*/
|
|
9
|
+
declare const NotificationParametersStruct: import("@metamask/superstruct").Struct<{
|
|
10
|
+
type: "native";
|
|
16
11
|
message: string;
|
|
17
|
-
}
|
|
12
|
+
} | {
|
|
13
|
+
type: "inApp";
|
|
14
|
+
message: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "inApp";
|
|
17
|
+
message: string;
|
|
18
|
+
content: 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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
19
|
+
src: string;
|
|
20
|
+
alt?: string | undefined;
|
|
21
|
+
}, "Image">;
|
|
22
|
+
title: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "inApp";
|
|
25
|
+
message: string;
|
|
26
|
+
content: 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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
27
|
+
src: string;
|
|
28
|
+
alt?: string | undefined;
|
|
29
|
+
}, "Image">;
|
|
30
|
+
title: string;
|
|
31
|
+
footerLink: {
|
|
32
|
+
text: string;
|
|
33
|
+
href: string;
|
|
34
|
+
};
|
|
35
|
+
}, [head: import("@metamask/superstruct").Struct<{
|
|
36
|
+
type: "inApp";
|
|
37
|
+
message: string;
|
|
38
|
+
}, {
|
|
39
|
+
type: import("@metamask/superstruct").Struct<"inApp", null>;
|
|
40
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
41
|
+
}>, import("@metamask/superstruct").Struct<{
|
|
42
|
+
type: "inApp";
|
|
43
|
+
message: string;
|
|
44
|
+
content: 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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
45
|
+
src: string;
|
|
46
|
+
alt?: string | undefined;
|
|
47
|
+
}, "Image">;
|
|
48
|
+
title: string;
|
|
49
|
+
}, {
|
|
50
|
+
type: import("@metamask/superstruct").Struct<"inApp", null>;
|
|
51
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
52
|
+
content: import("@metamask/superstruct").Struct<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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
53
|
+
src: string;
|
|
54
|
+
alt?: string | undefined;
|
|
55
|
+
}, "Image">, null>;
|
|
56
|
+
title: import("@metamask/superstruct").Struct<string, null>;
|
|
57
|
+
}>, import("@metamask/superstruct").Struct<{
|
|
58
|
+
type: "inApp";
|
|
59
|
+
message: string;
|
|
60
|
+
content: 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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
61
|
+
src: string;
|
|
62
|
+
alt?: string | undefined;
|
|
63
|
+
}, "Image">;
|
|
64
|
+
title: string;
|
|
65
|
+
footerLink: {
|
|
66
|
+
text: string;
|
|
67
|
+
href: string;
|
|
68
|
+
};
|
|
69
|
+
}, {
|
|
70
|
+
type: import("@metamask/superstruct").Struct<"inApp", null>;
|
|
71
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
72
|
+
content: import("@metamask/superstruct").Struct<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").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").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").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
73
|
+
src: string;
|
|
74
|
+
alt?: string | undefined;
|
|
75
|
+
}, "Image">, null>;
|
|
76
|
+
title: import("@metamask/superstruct").Struct<string, null>;
|
|
77
|
+
footerLink: import("@metamask/superstruct").Struct<{
|
|
78
|
+
text: string;
|
|
79
|
+
href: string;
|
|
80
|
+
}, {
|
|
81
|
+
href: import("@metamask/superstruct").Struct<string, null>;
|
|
82
|
+
text: import("@metamask/superstruct").Struct<string, null>;
|
|
83
|
+
}>;
|
|
84
|
+
}>, import("@metamask/superstruct").Struct<{
|
|
85
|
+
type: "native";
|
|
86
|
+
message: string;
|
|
87
|
+
}, {
|
|
88
|
+
type: import("@metamask/superstruct").Struct<"native", null>;
|
|
89
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
90
|
+
}>]>;
|
|
91
|
+
export type NotificationParameters = InferMatching<typeof NotificationParametersStruct, NotifyParams>;
|
|
18
92
|
export type NotifyMethodHooks = {
|
|
19
93
|
/**
|
|
20
94
|
* @param snapId - The ID of the Snap that created the notification.
|
|
21
95
|
* @param args - The notification arguments.
|
|
22
96
|
*/
|
|
23
|
-
showNativeNotification: (snapId: string, args:
|
|
97
|
+
showNativeNotification: (snapId: string, args: NotificationParameters) => Promise<null>;
|
|
24
98
|
/**
|
|
25
99
|
* @param snapId - The ID of the Snap that created the notification.
|
|
26
100
|
* @param args - The notification arguments.
|
|
27
101
|
*/
|
|
28
|
-
showInAppNotification: (snapId: string, args:
|
|
102
|
+
showInAppNotification: (snapId: string, args: NotificationParameters) => Promise<null>;
|
|
29
103
|
isOnPhishingList: (url: string) => boolean;
|
|
30
104
|
maybeUpdatePhishingList: () => Promise<void>;
|
|
105
|
+
createInterface: (origin: string, content: NotificationComponent) => Promise<string>;
|
|
106
|
+
getSnap: (snapId: string) => Snap | undefined;
|
|
31
107
|
};
|
|
32
108
|
type SpecificationBuilderOptions = {
|
|
33
109
|
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
|
|
@@ -67,17 +143,22 @@ export declare const notifyBuilder: Readonly<{
|
|
|
67
143
|
* @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
|
|
68
144
|
* @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
69
145
|
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
146
|
+
* @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
|
|
147
|
+
* @param hooks.getSnap - A function that checks if a snap is installed.
|
|
70
148
|
* @returns The method implementation which returns `null` on success.
|
|
71
149
|
* @throws If the params are invalid.
|
|
72
150
|
*/
|
|
73
|
-
export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
|
|
151
|
+
export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
|
|
74
152
|
/**
|
|
75
153
|
* Validates the notify method `params` and returns them cast to the correct
|
|
76
154
|
* type. Throws if validation fails.
|
|
77
155
|
*
|
|
78
156
|
* @param params - The unvalidated params object from the method request.
|
|
157
|
+
* @param isOnPhishingList - The function that checks for links against the phishing list.
|
|
158
|
+
* @param getSnap - A function that checks if a snap is installed.
|
|
79
159
|
* @returns The validated method parameter object.
|
|
160
|
+
* @throws If the params are invalid.
|
|
80
161
|
*/
|
|
81
|
-
export declare function getValidatedParams(params: unknown): NotifyParams;
|
|
162
|
+
export declare function getValidatedParams(params: unknown, isOnPhishingList: NotifyMethodHooks['isOnPhishingList'], getSnap: NotifyMethodHooks['getSnap']): NotifyParams;
|
|
82
163
|
export {};
|
|
83
164
|
//# sourceMappingURL=notify.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.d.mts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;
|
|
1
|
+
{"version":3,"file":"notify.d.mts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAG9E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,EAIL,KAAK,IAAI,EACV,8BAA8B;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE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AAC;IAC3D,cAAc,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;CACxD,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,8BAA8B,CAC/D,cAAc,CAAC,gBAAgB,EAC/B,2BAA2B,EAC3B,aAAa,CASd,CAAC;AAWF,eAAO,MAAM,aAAa;;;wBAtCR,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,wBAAwB,CAAC;wBAC1C,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;EAuC7C,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,OAAO,GACR,EAAE,iBAAiB,UAEV,wBAAwB,YAAY,CAAC,KAC1C,QAAQ,YAAY,CAAC,CAkCzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,EACvD,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,GACpC,YAAY,CAiEd"}
|
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
-
import { NotificationType } from "@metamask/snaps-sdk";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { enumValue, NotificationType, union } from "@metamask/snaps-sdk";
|
|
4
|
+
import { NotificationComponentsStruct } from "@metamask/snaps-sdk/jsx";
|
|
5
|
+
import { createUnion, validateLink, validateTextLinks } from "@metamask/snaps-utils";
|
|
6
|
+
import { object, string } from "@metamask/superstruct";
|
|
7
|
+
import { hasProperty, isObject } from "@metamask/utils";
|
|
6
8
|
const methodName = 'snap_notify';
|
|
9
|
+
const NativeNotificationStruct = object({
|
|
10
|
+
type: enumValue(NotificationType.Native),
|
|
11
|
+
message: string(),
|
|
12
|
+
});
|
|
13
|
+
const InAppNotificationStruct = object({
|
|
14
|
+
type: enumValue(NotificationType.InApp),
|
|
15
|
+
message: string(),
|
|
16
|
+
});
|
|
17
|
+
const InAppNotificationWithDetailsStruct = object({
|
|
18
|
+
type: enumValue(NotificationType.InApp),
|
|
19
|
+
message: string(),
|
|
20
|
+
content: NotificationComponentsStruct,
|
|
21
|
+
title: string(),
|
|
22
|
+
});
|
|
23
|
+
const InAppNotificationWithDetailsAndFooterStruct = object({
|
|
24
|
+
type: enumValue(NotificationType.InApp),
|
|
25
|
+
message: string(),
|
|
26
|
+
content: NotificationComponentsStruct,
|
|
27
|
+
title: string(),
|
|
28
|
+
footerLink: object({
|
|
29
|
+
href: string(),
|
|
30
|
+
text: string(),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
const NotificationParametersStruct = union([
|
|
34
|
+
InAppNotificationStruct,
|
|
35
|
+
InAppNotificationWithDetailsStruct,
|
|
36
|
+
InAppNotificationWithDetailsAndFooterStruct,
|
|
37
|
+
NativeNotificationStruct,
|
|
38
|
+
]);
|
|
7
39
|
/**
|
|
8
40
|
* The specification builder for the `snap_notify` permission.
|
|
9
41
|
* `snap_notify` allows snaps to send multiple types of notifications to its users.
|
|
@@ -27,6 +59,8 @@ const methodHooks = {
|
|
|
27
59
|
showInAppNotification: true,
|
|
28
60
|
isOnPhishingList: true,
|
|
29
61
|
maybeUpdatePhishingList: true,
|
|
62
|
+
createInterface: true,
|
|
63
|
+
getSnap: true,
|
|
30
64
|
};
|
|
31
65
|
export const notifyBuilder = Object.freeze({
|
|
32
66
|
targetName: methodName,
|
|
@@ -41,15 +75,21 @@ export const notifyBuilder = Object.freeze({
|
|
|
41
75
|
* @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
|
|
42
76
|
* @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
43
77
|
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
78
|
+
* @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
|
|
79
|
+
* @param hooks.getSnap - A function that checks if a snap is installed.
|
|
44
80
|
* @returns The method implementation which returns `null` on success.
|
|
45
81
|
* @throws If the params are invalid.
|
|
46
82
|
*/
|
|
47
|
-
export function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }) {
|
|
83
|
+
export function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }) {
|
|
48
84
|
return async function implementation(args) {
|
|
49
85
|
const { params, context: { origin }, } = args;
|
|
50
|
-
const validatedParams = getValidatedParams(params);
|
|
51
86
|
await maybeUpdatePhishingList();
|
|
52
|
-
|
|
87
|
+
const validatedParams = getValidatedParams(params, isOnPhishingList, getSnap);
|
|
88
|
+
let id;
|
|
89
|
+
if (hasProperty(validatedParams, 'content')) {
|
|
90
|
+
id = await createInterface(origin, validatedParams.content);
|
|
91
|
+
validatedParams.content = id;
|
|
92
|
+
}
|
|
53
93
|
switch (validatedParams.type) {
|
|
54
94
|
case NotificationType.Native:
|
|
55
95
|
return await showNativeNotification(origin, validatedParams);
|
|
@@ -67,9 +107,12 @@ export function getImplementation({ showNativeNotification, showInAppNotificatio
|
|
|
67
107
|
* type. Throws if validation fails.
|
|
68
108
|
*
|
|
69
109
|
* @param params - The unvalidated params object from the method request.
|
|
110
|
+
* @param isOnPhishingList - The function that checks for links against the phishing list.
|
|
111
|
+
* @param getSnap - A function that checks if a snap is installed.
|
|
70
112
|
* @returns The validated method parameter object.
|
|
113
|
+
* @throws If the params are invalid.
|
|
71
114
|
*/
|
|
72
|
-
export function getValidatedParams(params) {
|
|
115
|
+
export function getValidatedParams(params, isOnPhishingList, getSnap) {
|
|
73
116
|
if (!isObject(params)) {
|
|
74
117
|
throw rpcErrors.invalidParams({
|
|
75
118
|
message: 'Expected params to be a single object.',
|
|
@@ -97,6 +140,19 @@ export function getValidatedParams(params) {
|
|
|
97
140
|
message: 'Must specify a non-empty string "message" less than 500 characters long.',
|
|
98
141
|
});
|
|
99
142
|
}
|
|
100
|
-
|
|
143
|
+
try {
|
|
144
|
+
const validatedParams = createUnion(params, NotificationParametersStruct, 'type');
|
|
145
|
+
validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);
|
|
146
|
+
if (hasProperty(validatedParams, 'footerLink')) {
|
|
147
|
+
validateTextLinks(validatedParams.footerLink.text, isOnPhishingList, getSnap);
|
|
148
|
+
validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);
|
|
149
|
+
}
|
|
150
|
+
return validatedParams;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
throw rpcErrors.invalidParams({
|
|
154
|
+
message: `Invalid params: ${error.message}`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
101
157
|
}
|
|
102
158
|
//# sourceMappingURL=notify.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EAAE,gBAAgB,EAAE,4BAA4B;AAMvD,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAE1D,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAI3C,MAAM,UAAU,GAAG,aAAa,CAAC;AAkDjC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAI7B,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,EAA+B,EAAE,EAAE;IAC1E,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,iBAAiB,CAAC,WAAW,CAAC;QACpD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tB,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,wCAAwC;SAClD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEjC,IACE,CAAC,IAAI;QACL,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,IAAwB,CAAC,EACnE,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,gBAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAA0B,CAAC;AACpC,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 { 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 const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n return params as NotificationArgs;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,4BAA4B;AAMzE,OAAO,EAAE,4BAA4B,EAAE,gCAAgC;AACvE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,EAElB,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAEvD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAIxD,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,MAAM,CAAC;IACrC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,kCAAkC,GAAG,MAAM,CAAC;IAChD,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;IACjB,OAAO,EAAE,4BAA4B;IACrC,KAAK,EAAE,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,2CAA2C,GAAG,MAAM,CAAC;IACzD,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;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L,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,gBAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,WAAW,CACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,iBAAiB,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,WAAW,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,iBAAiB,CACf,eAAe,CAAC,UAAU,CAAC,IAAI,EAC/B,gBAAgB,EAChB,OAAO,CACR,CAAC;YACF,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,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 { enumValue, NotificationType, union } from '@metamask/snaps-sdk';\nimport type {\n NotifyParams,\n NotifyResult,\n NotificationComponent,\n} from '@metamask/snaps-sdk';\nimport { NotificationComponentsStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n type Snap,\n} from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: NotificationComponentsStruct,\n title: string(),\n});\n\nconst InAppNotificationWithDetailsAndFooterStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: NotificationComponentsStruct,\n title: string(),\n footerLink: object({\n href: string(),\n text: string(),\n }),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n InAppNotificationWithDetailsAndFooterStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationParameters = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\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: NotificationParameters,\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: NotificationParameters,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: NotificationComponent,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | undefined;\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 createInterface: true,\n getSnap: 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 * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\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 createInterface,\n getSnap,\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 await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n let id;\n if (hasProperty(validatedParams, 'content')) {\n id = await createInterface(\n origin,\n validatedParams.content as NotificationComponent,\n );\n validatedParams.content = id;\n }\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 * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): 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 const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateTextLinks(\n validatedParams.footerLink.text,\n isOnPhishingList,\n getSnap,\n );\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "11.
|
|
4
|
-
"description": "MetaMask Snaps JSON-RPC method implementations
|
|
3
|
+
"version": "11.3.0",
|
|
4
|
+
"description": "MetaMask Snaps JSON-RPC method implementations",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Snaps",
|
|
8
|
+
"Ethereum"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/MetaMask/snaps/tree/main/packages/snaps-rpc-methods#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/MetaMask/snaps/issues"
|
|
13
|
+
},
|
|
5
14
|
"repository": {
|
|
6
15
|
"type": "git",
|
|
7
16
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
8
17
|
},
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
9
19
|
"sideEffects": false,
|
|
10
20
|
"exports": {
|
|
11
21
|
".": {
|
|
@@ -27,25 +37,29 @@
|
|
|
27
37
|
"dist"
|
|
28
38
|
],
|
|
29
39
|
"scripts": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
40
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
41
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/snaps-rpc-methods",
|
|
42
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/snaps-rpc-methods",
|
|
43
|
+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn changelog:validate && yarn lint:dependencies",
|
|
44
|
+
"lint:ci": "yarn lint",
|
|
45
|
+
"lint:dependencies": "depcheck",
|
|
33
46
|
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
|
|
34
|
-
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
|
|
35
|
-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
|
|
36
47
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
37
|
-
"lint:
|
|
38
|
-
"build": "ts-bridge --project tsconfig.build.json --verbose --no-references",
|
|
48
|
+
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
|
|
39
49
|
"publish:preview": "yarn npm publish --tag preview",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
50
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
51
|
+
"test": "jest --reporters=jest-silent-reporter",
|
|
52
|
+
"test:clean": "jest --clearCache",
|
|
53
|
+
"test:post": "jest-it-up",
|
|
54
|
+
"test:verbose": "jest --verbose",
|
|
55
|
+
"test:watch": "jest --watch"
|
|
42
56
|
},
|
|
43
57
|
"dependencies": {
|
|
44
58
|
"@metamask/key-tree": "^9.1.2",
|
|
45
59
|
"@metamask/permission-controller": "^11.0.0",
|
|
46
60
|
"@metamask/rpc-errors": "^6.3.1",
|
|
47
|
-
"@metamask/snaps-sdk": "^6.
|
|
48
|
-
"@metamask/snaps-utils": "^8.
|
|
61
|
+
"@metamask/snaps-sdk": "^6.7.0",
|
|
62
|
+
"@metamask/snaps-utils": "^8.3.0",
|
|
49
63
|
"@metamask/superstruct": "^3.1.0",
|
|
50
64
|
"@metamask/utils": "^9.2.1",
|
|
51
65
|
"@noble/hashes": "^1.3.1"
|
|
@@ -76,8 +90,9 @@
|
|
|
76
90
|
"eslint-plugin-promise": "^6.1.1",
|
|
77
91
|
"jest": "^29.0.2",
|
|
78
92
|
"jest-it-up": "^2.0.0",
|
|
79
|
-
"
|
|
80
|
-
"prettier
|
|
93
|
+
"jest-silent-reporter": "^0.6.0",
|
|
94
|
+
"prettier": "^2.8.8",
|
|
95
|
+
"prettier-plugin-packagejson": "^2.5.2",
|
|
81
96
|
"typescript": "~5.3.3"
|
|
82
97
|
},
|
|
83
98
|
"engines": {
|