@metamask/snaps-rpc-methods 12.3.0 → 13.0.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 +21 -1
- package/dist/permitted/createInterface.d.cts +2 -2
- package/dist/permitted/createInterface.d.mts +2 -2
- package/dist/permitted/getClientStatus.cjs +4 -2
- package/dist/permitted/getClientStatus.cjs.map +1 -1
- package/dist/permitted/getClientStatus.d.cts +4 -0
- package/dist/permitted/getClientStatus.d.cts.map +1 -1
- package/dist/permitted/getClientStatus.d.mts +4 -0
- package/dist/permitted/getClientStatus.d.mts.map +1 -1
- package/dist/permitted/getClientStatus.mjs +4 -2
- package/dist/permitted/getClientStatus.mjs.map +1 -1
- package/dist/permitted/handlers.d.cts +12 -0
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +12 -0
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.cjs +12 -16
- package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.mjs +13 -17
- package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +2 -2
- package/dist/permitted/updateInterface.d.mts +2 -2
- package/dist/restricted/dialog.d.cts +4 -4
- package/dist/restricted/dialog.d.mts +4 -4
- package/dist/restricted/notify.d.cts +3 -3
- package/dist/restricted/notify.d.mts +3 -3
- package/package.json +7 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [13.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Drop support for Node.js 18 and 21 ([#3447](https://github.com/MetaMask/snaps/pull/3447))
|
|
15
|
+
- **BREAKING:** Refactor background event methods to reduce duplication ([#3421](https://github.com/MetaMask/snaps/pull/3421))
|
|
16
|
+
- This requires `@metamask/snaps-controllers` version `13.0.0` or later.
|
|
17
|
+
|
|
18
|
+
## [12.4.0]
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- Add `active` flag for `snap_getClientStatus` ([#3424](https://github.com/MetaMask/snaps/pull/3424))
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Prevent scheduling background events less than 1 second in the future ([#3414](https://github.com/MetaMask/snaps/pull/3414))
|
|
27
|
+
|
|
10
28
|
## [12.3.0]
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -437,7 +455,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
437
455
|
- The version of the package no longer needs to match the version of all other
|
|
438
456
|
MetaMask Snaps packages.
|
|
439
457
|
|
|
440
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@
|
|
458
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.0.0...HEAD
|
|
459
|
+
[13.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.4.0...@metamask/snaps-rpc-methods@13.0.0
|
|
460
|
+
[12.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.3.0...@metamask/snaps-rpc-methods@12.4.0
|
|
441
461
|
[12.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.2.0...@metamask/snaps-rpc-methods@12.3.0
|
|
442
462
|
[12.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.1.0...@metamask/snaps-rpc-methods@12.2.0
|
|
443
463
|
[12.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@12.0.0...@metamask/snaps-rpc-methods@12.1.0
|
|
@@ -10,7 +10,7 @@ export type CreateInterfaceMethodHooks = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare const createInterfaceHandler: PermittedHandlerExport<CreateInterfaceMethodHooks, CreateInterfaceParameters, CreateInterfaceResult>;
|
|
12
12
|
declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
13
|
-
ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
13
|
+
ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | 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"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SkeletonProps, "Skeleton"> | {
|
|
14
14
|
value: string;
|
|
15
15
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
16
16
|
sensitive?: boolean | undefined;
|
|
@@ -97,7 +97,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
97
97
|
}, "Heading">;
|
|
98
98
|
context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
|
|
99
99
|
}, {
|
|
100
|
-
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
100
|
+
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | 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"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SkeletonProps, "Skeleton"> | {
|
|
101
101
|
value: string;
|
|
102
102
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
103
103
|
sensitive?: boolean | undefined;
|
|
@@ -10,7 +10,7 @@ export type CreateInterfaceMethodHooks = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare const createInterfaceHandler: PermittedHandlerExport<CreateInterfaceMethodHooks, CreateInterfaceParameters, CreateInterfaceResult>;
|
|
12
12
|
declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
13
|
-
ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
13
|
+
ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | 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"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SkeletonProps, "Skeleton"> | {
|
|
14
14
|
value: string;
|
|
15
15
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
16
16
|
sensitive?: boolean | undefined;
|
|
@@ -97,7 +97,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
97
97
|
}, "Heading">;
|
|
98
98
|
context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
|
|
99
99
|
}, {
|
|
100
|
-
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
100
|
+
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | 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"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SkeletonProps, "Skeleton"> | {
|
|
101
101
|
value: string;
|
|
102
102
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
103
103
|
sensitive?: boolean | undefined;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getClientStatusHandler = void 0;
|
|
4
4
|
const hookNames = {
|
|
5
5
|
getIsLocked: true,
|
|
6
|
+
getIsActive: true,
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* `snap_getClientStatus` returns useful information about the client running the snap.
|
|
@@ -23,10 +24,11 @@ exports.getClientStatusHandler = {
|
|
|
23
24
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
24
25
|
* @param hooks - The RPC method hooks.
|
|
25
26
|
* @param hooks.getIsLocked - A function that returns whether the client is locked or not.
|
|
27
|
+
* @param hooks.getIsActive - A function that returns whether the client is opened or not.
|
|
26
28
|
* @returns Nothing.
|
|
27
29
|
*/
|
|
28
|
-
async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked }) {
|
|
29
|
-
response.result = { locked: getIsLocked() };
|
|
30
|
+
async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive }) {
|
|
31
|
+
response.result = { locked: getIsLocked(), active: getIsActive() };
|
|
30
32
|
return end();
|
|
31
33
|
}
|
|
32
34
|
//# sourceMappingURL=getClientStatus.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientStatus.cjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":";;;AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;
|
|
1
|
+
{"version":3,"file":"getClientStatus.cjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":";;;AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAwB;IAElD,QAAQ,CAAC,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC;IACnE,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive }: GetClientStatusHooks,\n): Promise<void> {\n response.result = { locked: getIsLocked(), active: getIsActive() };\n return end();\n}\n"]}
|
|
@@ -10,5 +10,9 @@ export type GetClientStatusHooks = {
|
|
|
10
10
|
* @returns Whether the client is locked or not.
|
|
11
11
|
*/
|
|
12
12
|
getIsLocked: () => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @returns Whether the client is active or not.
|
|
15
|
+
*/
|
|
16
|
+
getIsActive: () => boolean;
|
|
13
17
|
};
|
|
14
18
|
//# sourceMappingURL=getClientStatus.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientStatus.d.cts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;
|
|
1
|
+
{"version":3,"file":"getClientStatus.d.cts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AASzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC"}
|
|
@@ -10,5 +10,9 @@ export type GetClientStatusHooks = {
|
|
|
10
10
|
* @returns Whether the client is locked or not.
|
|
11
11
|
*/
|
|
12
12
|
getIsLocked: () => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @returns Whether the client is active or not.
|
|
15
|
+
*/
|
|
16
|
+
getIsActive: () => boolean;
|
|
13
17
|
};
|
|
14
18
|
//# sourceMappingURL=getClientStatus.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientStatus.d.mts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;
|
|
1
|
+
{"version":3,"file":"getClientStatus.d.mts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AASzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const hookNames = {
|
|
2
2
|
getIsLocked: true,
|
|
3
|
+
getIsActive: true,
|
|
3
4
|
};
|
|
4
5
|
/**
|
|
5
6
|
* `snap_getClientStatus` returns useful information about the client running the snap.
|
|
@@ -20,10 +21,11 @@ export const getClientStatusHandler = {
|
|
|
20
21
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
21
22
|
* @param hooks - The RPC method hooks.
|
|
22
23
|
* @param hooks.getIsLocked - A function that returns whether the client is locked or not.
|
|
24
|
+
* @param hooks.getIsActive - A function that returns whether the client is opened or not.
|
|
23
25
|
* @returns Nothing.
|
|
24
26
|
*/
|
|
25
|
-
async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked }) {
|
|
26
|
-
response.result = { locked: getIsLocked() };
|
|
27
|
+
async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive }) {
|
|
28
|
+
response.result = { locked: getIsLocked(), active: getIsActive() };
|
|
27
29
|
return end();
|
|
28
30
|
}
|
|
29
31
|
//# sourceMappingURL=getClientStatus.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientStatus.mjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;
|
|
1
|
+
{"version":3,"file":"getClientStatus.mjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAwB;IAElD,QAAQ,CAAC,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC;IACnE,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive }: GetClientStatusHooks,\n): Promise<void> {\n response.result = { locked: getIsLocked(), active: getIsActive() };\n return end();\n}\n"]}
|
|
@@ -11,6 +11,9 @@ export declare const methodHandlers: {
|
|
|
11
11
|
snap_createInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string>;
|
|
12
12
|
snap_updateInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null>;
|
|
13
13
|
snap_getInterfaceState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
14
|
+
addresses: `${string}:${string}:${string}`[];
|
|
15
|
+
accountId: string;
|
|
16
|
+
} | {
|
|
14
17
|
name: string;
|
|
15
18
|
size: number;
|
|
16
19
|
contentType: string;
|
|
@@ -20,6 +23,9 @@ export declare const methodHandlers: {
|
|
|
20
23
|
name: string;
|
|
21
24
|
asset: `${string}:${string}/${string}:${string}`;
|
|
22
25
|
} | Record<string, string | boolean | {
|
|
26
|
+
addresses: `${string}:${string}:${string}`[];
|
|
27
|
+
accountId: string;
|
|
28
|
+
} | {
|
|
23
29
|
name: string;
|
|
24
30
|
size: number;
|
|
25
31
|
contentType: string;
|
|
@@ -41,6 +47,9 @@ export declare const methodHandlers: {
|
|
|
41
47
|
snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
|
|
42
48
|
};
|
|
43
49
|
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
50
|
+
addresses: `${string}:${string}:${string}`[];
|
|
51
|
+
accountId: string;
|
|
52
|
+
} | {
|
|
44
53
|
name: string;
|
|
45
54
|
size: number;
|
|
46
55
|
contentType: string;
|
|
@@ -50,6 +59,9 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
50
59
|
name: string;
|
|
51
60
|
asset: `${string}:${string}/${string}:${string}`;
|
|
52
61
|
} | Record<string, string | boolean | {
|
|
62
|
+
addresses: `${string}:${string}:${string}`[];
|
|
63
|
+
accountId: string;
|
|
64
|
+
} | {
|
|
53
65
|
name: string;
|
|
54
66
|
size: number;
|
|
55
67
|
contentType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;26EAAgC,CAAC"}
|
|
@@ -11,6 +11,9 @@ export declare const methodHandlers: {
|
|
|
11
11
|
snap_createInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string>;
|
|
12
12
|
snap_updateInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null>;
|
|
13
13
|
snap_getInterfaceState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
14
|
+
addresses: `${string}:${string}:${string}`[];
|
|
15
|
+
accountId: string;
|
|
16
|
+
} | {
|
|
14
17
|
name: string;
|
|
15
18
|
size: number;
|
|
16
19
|
contentType: string;
|
|
@@ -20,6 +23,9 @@ export declare const methodHandlers: {
|
|
|
20
23
|
name: string;
|
|
21
24
|
asset: `${string}:${string}/${string}:${string}`;
|
|
22
25
|
} | Record<string, string | boolean | {
|
|
26
|
+
addresses: `${string}:${string}:${string}`[];
|
|
27
|
+
accountId: string;
|
|
28
|
+
} | {
|
|
23
29
|
name: string;
|
|
24
30
|
size: number;
|
|
25
31
|
contentType: string;
|
|
@@ -41,6 +47,9 @@ export declare const methodHandlers: {
|
|
|
41
47
|
snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
|
|
42
48
|
};
|
|
43
49
|
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
50
|
+
addresses: `${string}:${string}:${string}`[];
|
|
51
|
+
accountId: string;
|
|
52
|
+
} | {
|
|
44
53
|
name: string;
|
|
45
54
|
size: number;
|
|
46
55
|
contentType: string;
|
|
@@ -50,6 +59,9 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
50
59
|
name: string;
|
|
51
60
|
asset: `${string}:${string}/${string}:${string}`;
|
|
52
61
|
} | Record<string, string | boolean | {
|
|
62
|
+
addresses: `${string}:${string}:${string}`[];
|
|
63
|
+
accountId: string;
|
|
64
|
+
} | {
|
|
53
65
|
name: string;
|
|
54
66
|
size: number;
|
|
55
67
|
contentType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;26EAAgC,CAAC"}
|
|
@@ -6,7 +6,6 @@ const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
|
6
6
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
7
|
const superstruct_1 = require("@metamask/superstruct");
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const luxon_1 = require("luxon");
|
|
10
9
|
const endowments_1 = require("../endowments/index.cjs");
|
|
11
10
|
const methodName = 'snap_scheduleBackgroundEvent';
|
|
12
11
|
const hookNames = {
|
|
@@ -33,18 +32,17 @@ const ScheduleBackgroundEventParametersStruct = (0, snaps_sdk_1.selectiveUnion)(
|
|
|
33
32
|
return ScheduleBackgroundEventParametersWithDurationStruct;
|
|
34
33
|
});
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
35
|
+
* Get the schedule for a background event based on the provided parameters.
|
|
37
36
|
*
|
|
38
|
-
* @param params - The
|
|
39
|
-
* @returns
|
|
37
|
+
* @param params - The parameters for the background event.
|
|
38
|
+
* @returns The schedule parameters for the background event.
|
|
40
39
|
*/
|
|
41
|
-
function
|
|
42
|
-
if ('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.plus(luxon_1.Duration.fromISO(params.duration));
|
|
40
|
+
function getSchedule(params) {
|
|
41
|
+
if ((0, utils_1.hasProperty)(params, 'date')) {
|
|
42
|
+
// TODO: Check why `params.date` is not a string.
|
|
43
|
+
return params.date;
|
|
46
44
|
}
|
|
47
|
-
return
|
|
45
|
+
return params.duration;
|
|
48
46
|
}
|
|
49
47
|
/**
|
|
50
48
|
* The `snap_scheduleBackgroundEvent` method implementation.
|
|
@@ -67,13 +65,11 @@ async function getScheduleBackgroundEventImplementation(req, res, _next, end, {
|
|
|
67
65
|
try {
|
|
68
66
|
const validatedParams = getValidatedParams(params);
|
|
69
67
|
const { request } = validatedParams;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const schedule = getSchedule(validatedParams);
|
|
69
|
+
const id = scheduleBackgroundEvent({
|
|
70
|
+
schedule,
|
|
71
|
+
request,
|
|
74
72
|
});
|
|
75
|
-
(0, utils_1.assert)(truncatedDate);
|
|
76
|
-
const id = scheduleBackgroundEvent({ date: truncatedDate, request });
|
|
77
73
|
res.result = id;
|
|
78
74
|
}
|
|
79
75
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduleBackgroundEvent.cjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AACjE,mDAK6B;AAE7B,uDAI+B;AAC/B,uDAAoE;AACpE,
|
|
1
|
+
{"version":3,"file":"scheduleBackgroundEvent.cjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AACjE,mDAK6B;AAE7B,uDAI+B;AAC/B,uDAAoE;AACpE,2CAA2E;AAE3E,wDAA+C;AAG/C,MAAM,UAAU,GAAG,8BAA8B,CAAC;AAElD,MAAM,SAAS,GAA0D;IACvE,uBAAuB,EAAE,IAAI;IAC7B,aAAa,EAAE,IAAI;CACpB,CAAC;AAeW,QAAA,8BAA8B,GAIvC;IACF,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,cAAc,EAAE,wCAAwC;IACxD,SAAS;CACV,CAAC;AAEF,MAAM,+CAA+C,GAAG,IAAA,oBAAM,EAAC;IAC7D,IAAI,EAAE,+BAAiB;IACvB,OAAO,EAAE,qCAAuB;CACjC,CAAC,CAAC;AAEH,MAAM,mDAAmD,GAAG,IAAA,oBAAM,EAAC;IACjE,QAAQ,EAAE,mCAAqB;IAC/B,OAAO,EAAE,qCAAuB;CACjC,CAAC,CAAC;AAEH,MAAM,uCAAuC,GAAG,IAAA,0BAAc,EAAC,CAAC,GAAG,EAAE,EAAE;IACrE,IAAI,IAAA,mBAAW,EAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,+CAA+C,CAAC;IACzD,CAAC;IACD,OAAO,mDAAmD,CAAC;AAC7D,CAAC,CAAC,CAAC;AAOH;;;;;GAKG;AACH,SAAS,WAAW,CAAC,MAAyC;IAC5D,IAAI,IAAA,mBAAW,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAChC,iDAAiD;QACjD,OAAO,MAAM,CAAC,IAAc,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,wCAAwC,CACrD,GAAsD,EACtD,GAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,uBAAuB,EACvB,aAAa,GACsB;IAErC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC,aAAa,CAAC,2BAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;QAE9C,MAAM,EAAE,GAAG,uBAAuB,CAAC;YACjC,QAAQ;YACR,OAAO;SACR,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,MAAe;IAEf,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n selectiveUnion,\n type JsonRpcRequest,\n type ScheduleBackgroundEventParams,\n type ScheduleBackgroundEventResult,\n} from '@metamask/snaps-sdk';\nimport type { CronjobRpcRequest, InferMatching } from '@metamask/snaps-utils';\nimport {\n CronjobRpcRequestStruct,\n ISO8601DateStruct,\n ISO8601DurationStruct,\n} from '@metamask/snaps-utils';\nimport { StructError, create, object } from '@metamask/superstruct';\nimport { hasProperty, type PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_scheduleBackgroundEvent';\n\nconst hookNames: MethodHooksObject<ScheduleBackgroundEventMethodHooks> = {\n scheduleBackgroundEvent: true,\n hasPermission: true,\n};\n\ntype ScheduleBackgroundEventHookParams = {\n schedule: string;\n request: CronjobRpcRequest;\n};\n\nexport type ScheduleBackgroundEventMethodHooks = {\n scheduleBackgroundEvent: (\n snapEvent: ScheduleBackgroundEventHookParams,\n ) => string;\n\n hasPermission: (permissionName: string) => boolean;\n};\n\nexport const scheduleBackgroundEventHandler: PermittedHandlerExport<\n ScheduleBackgroundEventMethodHooks,\n ScheduleBackgroundEventParameters,\n ScheduleBackgroundEventResult\n> = {\n methodNames: [methodName],\n implementation: getScheduleBackgroundEventImplementation,\n hookNames,\n};\n\nconst ScheduleBackgroundEventParametersWithDateStruct = object({\n date: ISO8601DateStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersWithDurationStruct = object({\n duration: ISO8601DurationStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersStruct = selectiveUnion((val) => {\n if (hasProperty(val, 'date')) {\n return ScheduleBackgroundEventParametersWithDateStruct;\n }\n return ScheduleBackgroundEventParametersWithDurationStruct;\n});\n\nexport type ScheduleBackgroundEventParameters = InferMatching<\n typeof ScheduleBackgroundEventParametersStruct,\n ScheduleBackgroundEventParams\n>;\n\n/**\n * Get the schedule for a background event based on the provided parameters.\n *\n * @param params - The parameters for the background event.\n * @returns The schedule parameters for the background event.\n */\nfunction getSchedule(params: ScheduleBackgroundEventParameters): string {\n if (hasProperty(params, 'date')) {\n // TODO: Check why `params.date` is not a string.\n return params.date as string;\n }\n\n return params.duration;\n}\n\n/**\n * The `snap_scheduleBackgroundEvent` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.scheduleBackgroundEvent - The function to schedule a background event.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.\n * @returns An id representing the background event.\n */\nasync function getScheduleBackgroundEventImplementation(\n req: JsonRpcRequest<ScheduleBackgroundEventParameters>,\n res: PendingJsonRpcResponse<ScheduleBackgroundEventResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n scheduleBackgroundEvent,\n hasPermission,\n }: ScheduleBackgroundEventMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n if (!hasPermission(SnapEndowments.Cronjob)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { request } = validatedParams;\n const schedule = getSchedule(validatedParams);\n\n const id = scheduleBackgroundEvent({\n schedule,\n request,\n });\n\n res.result = id;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the scheduleBackgroundEvent 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 resolveInterface method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n): ScheduleBackgroundEventParameters {\n try {\n return create(params, ScheduleBackgroundEventParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
|
2
2
|
import { type ScheduleBackgroundEventParams, type ScheduleBackgroundEventResult } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { CronjobRpcRequest, InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
type ScheduleBackgroundEventHookParams = {
|
|
5
|
-
|
|
5
|
+
schedule: string;
|
|
6
6
|
request: CronjobRpcRequest;
|
|
7
7
|
};
|
|
8
8
|
export type ScheduleBackgroundEventMethodHooks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduleBackgroundEvent.d.cts","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,4BAA4B;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"scheduleBackgroundEvent.d.cts","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,4BAA4B;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,8BAA8B;AAmB9E,KAAK,iCAAiC,GAAG;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,uBAAuB,EAAE,CACvB,SAAS,EAAE,iCAAiC,KACzC,MAAM,CAAC;IAEZ,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,sBAAsB,CACjE,kCAAkC,EAClC,iCAAiC,EACjC,6BAA6B,CAK9B,CAAC;AAYF,QAAA,MAAM,uCAAuC;;;;;;;;;;;;;;;;QAK3C,CAAC;AAEH,MAAM,MAAM,iCAAiC,GAAG,aAAa,CAC3D,OAAO,uCAAuC,EAC9C,6BAA6B,CAC9B,CAAC"}
|
|
@@ -2,7 +2,7 @@ import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
|
2
2
|
import { type ScheduleBackgroundEventParams, type ScheduleBackgroundEventResult } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { CronjobRpcRequest, InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
type ScheduleBackgroundEventHookParams = {
|
|
5
|
-
|
|
5
|
+
schedule: string;
|
|
6
6
|
request: CronjobRpcRequest;
|
|
7
7
|
};
|
|
8
8
|
export type ScheduleBackgroundEventMethodHooks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduleBackgroundEvent.d.mts","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,4BAA4B;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"scheduleBackgroundEvent.d.mts","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,4BAA4B;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,8BAA8B;AAmB9E,KAAK,iCAAiC,GAAG;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,uBAAuB,EAAE,CACvB,SAAS,EAAE,iCAAiC,KACzC,MAAM,CAAC;IAEZ,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,sBAAsB,CACjE,kCAAkC,EAClC,iCAAiC,EACjC,6BAA6B,CAK9B,CAAC;AAYF,QAAA,MAAM,uCAAuC;;;;;;;;;;;;;;;;QAK3C,CAAC;AAEH,MAAM,MAAM,iCAAiC,GAAG,aAAa,CAC3D,OAAO,uCAAuC,EAC9C,6BAA6B,CAC9B,CAAC"}
|
|
@@ -2,8 +2,7 @@ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
|
|
|
2
2
|
import { selectiveUnion } from "@metamask/snaps-sdk";
|
|
3
3
|
import { CronjobRpcRequestStruct, ISO8601DateStruct, ISO8601DurationStruct } from "@metamask/snaps-utils";
|
|
4
4
|
import { StructError, create, object } from "@metamask/superstruct";
|
|
5
|
-
import {
|
|
6
|
-
import { DateTime, Duration } from "luxon";
|
|
5
|
+
import { hasProperty } from "@metamask/utils";
|
|
7
6
|
import { SnapEndowments } from "../endowments/index.mjs";
|
|
8
7
|
const methodName = 'snap_scheduleBackgroundEvent';
|
|
9
8
|
const hookNames = {
|
|
@@ -30,18 +29,17 @@ const ScheduleBackgroundEventParametersStruct = selectiveUnion((val) => {
|
|
|
30
29
|
return ScheduleBackgroundEventParametersWithDurationStruct;
|
|
31
30
|
});
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
32
|
+
* Get the schedule for a background event based on the provided parameters.
|
|
34
33
|
*
|
|
35
|
-
* @param params - The
|
|
36
|
-
* @returns
|
|
34
|
+
* @param params - The parameters for the background event.
|
|
35
|
+
* @returns The schedule parameters for the background event.
|
|
37
36
|
*/
|
|
38
|
-
function
|
|
39
|
-
if ('
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.plus(Duration.fromISO(params.duration));
|
|
37
|
+
function getSchedule(params) {
|
|
38
|
+
if (hasProperty(params, 'date')) {
|
|
39
|
+
// TODO: Check why `params.date` is not a string.
|
|
40
|
+
return params.date;
|
|
43
41
|
}
|
|
44
|
-
return
|
|
42
|
+
return params.duration;
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
45
|
* The `snap_scheduleBackgroundEvent` method implementation.
|
|
@@ -64,13 +62,11 @@ async function getScheduleBackgroundEventImplementation(req, res, _next, end, {
|
|
|
64
62
|
try {
|
|
65
63
|
const validatedParams = getValidatedParams(params);
|
|
66
64
|
const { request } = validatedParams;
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const schedule = getSchedule(validatedParams);
|
|
66
|
+
const id = scheduleBackgroundEvent({
|
|
67
|
+
schedule,
|
|
68
|
+
request,
|
|
71
69
|
});
|
|
72
|
-
assert(truncatedDate);
|
|
73
|
-
const id = scheduleBackgroundEvent({ date: truncatedDate, request });
|
|
74
70
|
res.result = id;
|
|
75
71
|
}
|
|
76
72
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduleBackgroundEvent.mjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AACjE,OAAO,EACL,cAAc,EAIf,4BAA4B;AAE7B,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACtB,8BAA8B;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACpE,OAAO,
|
|
1
|
+
{"version":3,"file":"scheduleBackgroundEvent.mjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AACjE,OAAO,EACL,cAAc,EAIf,4BAA4B;AAE7B,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACtB,8BAA8B;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACpE,OAAO,EAAE,WAAW,EAA+B,wBAAwB;AAE3E,OAAO,EAAE,cAAc,EAAE,gCAAsB;AAG/C,MAAM,UAAU,GAAG,8BAA8B,CAAC;AAElD,MAAM,SAAS,GAA0D;IACvE,uBAAuB,EAAE,IAAI;IAC7B,aAAa,EAAE,IAAI;CACpB,CAAC;AAeF,MAAM,CAAC,MAAM,8BAA8B,GAIvC;IACF,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,cAAc,EAAE,wCAAwC;IACxD,SAAS;CACV,CAAC;AAEF,MAAM,+CAA+C,GAAG,MAAM,CAAC;IAC7D,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,uBAAuB;CACjC,CAAC,CAAC;AAEH,MAAM,mDAAmD,GAAG,MAAM,CAAC;IACjE,QAAQ,EAAE,qBAAqB;IAC/B,OAAO,EAAE,uBAAuB;CACjC,CAAC,CAAC;AAEH,MAAM,uCAAuC,GAAG,cAAc,CAAC,CAAC,GAAG,EAAE,EAAE;IACrE,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,+CAA+C,CAAC;IACzD,CAAC;IACD,OAAO,mDAAmD,CAAC;AAC7D,CAAC,CAAC,CAAC;AAOH;;;;;GAKG;AACH,SAAS,WAAW,CAAC,MAAyC;IAC5D,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAChC,iDAAiD;QACjD,OAAO,MAAM,CAAC,IAAc,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,wCAAwC,CACrD,GAAsD,EACtD,GAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,uBAAuB,EACvB,aAAa,GACsB;IAErC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;QAE9C,MAAM,EAAE,GAAG,uBAAuB,CAAC;YACjC,QAAQ;YACR,OAAO;SACR,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,MAAe;IAEf,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n selectiveUnion,\n type JsonRpcRequest,\n type ScheduleBackgroundEventParams,\n type ScheduleBackgroundEventResult,\n} from '@metamask/snaps-sdk';\nimport type { CronjobRpcRequest, InferMatching } from '@metamask/snaps-utils';\nimport {\n CronjobRpcRequestStruct,\n ISO8601DateStruct,\n ISO8601DurationStruct,\n} from '@metamask/snaps-utils';\nimport { StructError, create, object } from '@metamask/superstruct';\nimport { hasProperty, type PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_scheduleBackgroundEvent';\n\nconst hookNames: MethodHooksObject<ScheduleBackgroundEventMethodHooks> = {\n scheduleBackgroundEvent: true,\n hasPermission: true,\n};\n\ntype ScheduleBackgroundEventHookParams = {\n schedule: string;\n request: CronjobRpcRequest;\n};\n\nexport type ScheduleBackgroundEventMethodHooks = {\n scheduleBackgroundEvent: (\n snapEvent: ScheduleBackgroundEventHookParams,\n ) => string;\n\n hasPermission: (permissionName: string) => boolean;\n};\n\nexport const scheduleBackgroundEventHandler: PermittedHandlerExport<\n ScheduleBackgroundEventMethodHooks,\n ScheduleBackgroundEventParameters,\n ScheduleBackgroundEventResult\n> = {\n methodNames: [methodName],\n implementation: getScheduleBackgroundEventImplementation,\n hookNames,\n};\n\nconst ScheduleBackgroundEventParametersWithDateStruct = object({\n date: ISO8601DateStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersWithDurationStruct = object({\n duration: ISO8601DurationStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersStruct = selectiveUnion((val) => {\n if (hasProperty(val, 'date')) {\n return ScheduleBackgroundEventParametersWithDateStruct;\n }\n return ScheduleBackgroundEventParametersWithDurationStruct;\n});\n\nexport type ScheduleBackgroundEventParameters = InferMatching<\n typeof ScheduleBackgroundEventParametersStruct,\n ScheduleBackgroundEventParams\n>;\n\n/**\n * Get the schedule for a background event based on the provided parameters.\n *\n * @param params - The parameters for the background event.\n * @returns The schedule parameters for the background event.\n */\nfunction getSchedule(params: ScheduleBackgroundEventParameters): string {\n if (hasProperty(params, 'date')) {\n // TODO: Check why `params.date` is not a string.\n return params.date as string;\n }\n\n return params.duration;\n}\n\n/**\n * The `snap_scheduleBackgroundEvent` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.scheduleBackgroundEvent - The function to schedule a background event.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.\n * @returns An id representing the background event.\n */\nasync function getScheduleBackgroundEventImplementation(\n req: JsonRpcRequest<ScheduleBackgroundEventParameters>,\n res: PendingJsonRpcResponse<ScheduleBackgroundEventResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n scheduleBackgroundEvent,\n hasPermission,\n }: ScheduleBackgroundEventMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n if (!hasPermission(SnapEndowments.Cronjob)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { request } = validatedParams;\n const schedule = getSchedule(validatedParams);\n\n const id = scheduleBackgroundEvent({\n schedule,\n request,\n });\n\n res.result = id;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the scheduleBackgroundEvent 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 resolveInterface method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n): ScheduleBackgroundEventParameters {\n try {\n return create(params, ScheduleBackgroundEventParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|