@metamask/snaps-utils 10.0.0 → 10.1.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 +13 -1
- package/dist/handlers/exports.cjs +14 -0
- package/dist/handlers/exports.cjs.map +1 -1
- package/dist/handlers/exports.d.cts +11 -1
- package/dist/handlers/exports.d.cts.map +1 -1
- package/dist/handlers/exports.d.mts +11 -1
- package/dist/handlers/exports.d.mts.map +1 -1
- package/dist/handlers/exports.mjs +14 -0
- package/dist/handlers/exports.mjs.map +1 -1
- package/dist/handlers/types.cjs +2 -0
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +3 -1
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +3 -1
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs +2 -0
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/localization.d.cts +1 -1
- package/dist/localization.d.mts +1 -1
- package/dist/manifest/validation.d.cts +3 -3
- package/dist/manifest/validation.d.cts.map +1 -1
- package/dist/manifest/validation.d.mts +3 -3
- package/dist/manifest/validation.d.mts.map +1 -1
- package/dist/manifest/validators/unused-exports.cjs +12 -2
- package/dist/manifest/validators/unused-exports.cjs.map +1 -1
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -1
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -1
- package/dist/manifest/validators/unused-exports.mjs +12 -2
- package/dist/manifest/validators/unused-exports.mjs.map +1 -1
- package/dist/types.cjs +7 -3
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +8 -4
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [10.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add support for the `onWebSocketEvent` handler ([#3450](https://github.com/MetaMask/snaps/pull/3450), [#3459](https://github.com/MetaMask/snaps/pull/3459))
|
|
15
|
+
- Add support for the `onStart` handler ([#3455](https://github.com/MetaMask/snaps/pull/3455))
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Fix unused permission detection for endowments with multiple handlers ([#3452](https://github.com/MetaMask/snaps/pull/3452))
|
|
20
|
+
|
|
10
21
|
## [10.0.0]
|
|
11
22
|
|
|
12
23
|
### Added
|
|
@@ -637,7 +648,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
637
648
|
- The version of the package no longer needs to match the version of all other
|
|
638
649
|
MetaMask Snaps packages.
|
|
639
650
|
|
|
640
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@10.
|
|
651
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@10.1.0...HEAD
|
|
652
|
+
[10.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@10.0.0...@metamask/snaps-utils@10.1.0
|
|
641
653
|
[10.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.4.0...@metamask/snaps-utils@10.0.0
|
|
642
654
|
[9.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.3.0...@metamask/snaps-utils@9.4.0
|
|
643
655
|
[9.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.2...@metamask/snaps-utils@9.3.0
|
|
@@ -45,6 +45,13 @@ exports.SNAP_EXPORTS = {
|
|
|
45
45
|
return typeof snapExport === 'function';
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
|
+
[types_1.HandlerType.OnStart]: {
|
|
49
|
+
type: types_1.HandlerType.OnStart,
|
|
50
|
+
required: false,
|
|
51
|
+
validator: (snapExport) => {
|
|
52
|
+
return typeof snapExport === 'function';
|
|
53
|
+
},
|
|
54
|
+
},
|
|
48
55
|
[types_1.HandlerType.OnKeyringRequest]: {
|
|
49
56
|
type: types_1.HandlerType.OnKeyringRequest,
|
|
50
57
|
required: true,
|
|
@@ -115,6 +122,13 @@ exports.SNAP_EXPORTS = {
|
|
|
115
122
|
return typeof snapExport === 'function';
|
|
116
123
|
},
|
|
117
124
|
},
|
|
125
|
+
[types_1.HandlerType.OnWebSocketEvent]: {
|
|
126
|
+
type: types_1.HandlerType.OnWebSocketEvent,
|
|
127
|
+
required: true,
|
|
128
|
+
validator: (snapExport) => {
|
|
129
|
+
return typeof snapExport === 'function';
|
|
130
|
+
},
|
|
131
|
+
},
|
|
118
132
|
};
|
|
119
133
|
exports.SNAP_EXPORT_NAMES = Object.values(types_1.HandlerType);
|
|
120
134
|
//# sourceMappingURL=exports.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.cjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"exports.cjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":";;;AAqBA,uCAAsC;AAEzB,QAAA,YAAY,GAAG;IAC1B,CAAC,mBAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,mBAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,EAAE,mBAAW,CAAC,aAAa;QAC/B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAsC,EAAE;YACrE,OAAO,OAAO,UA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,SAAS,EAAE,CAAC,UAAmB,EAAuC,EAAE;YACtE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,kBAAkB,CAAC,EAAE;QAChC,IAAI,EAAE,mBAAW,CAAC,kBAAkB;QACpC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CACT,UAAmB,EACsB,EAAE;YAC3C,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,iBAAiB,CAAC,EAAE;QAC/B,IAAI,EAAE,mBAAW,CAAC,iBAAiB;QACnC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CACT,UAAmB,EACqB,EAAE;YAC1C,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,eAAe,CAAC,EAAE;QAC7B,IAAI,EAAE,mBAAW,CAAC,eAAe;QACjC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAwC,EAAE;YACvE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,gBAAgB,CAAC,EAAE;QAC9B,IAAI,EAAE,mBAAW,CAAC,gBAAgB;QAClC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAyC,EAAE;YACxE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;CACO,CAAC;AAEE,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAW,CAAC,CAAC","sourcesContent":["import type {\n OnAssetHistoricalPriceHandler,\n OnAssetsConversionHandler,\n OnAssetsLookupHandler,\n OnClientRequestHandler,\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnProtocolRequestHandler,\n OnRpcRequestHandler,\n OnSettingsPageHandler,\n OnSignatureHandler,\n OnStartHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n OnWebSocketEventHandler,\n} from '@metamask/snaps-sdk';\n\nimport { HandlerType } from './types';\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnStart]: {\n type: HandlerType.OnStart,\n required: false,\n validator: (snapExport: unknown): snapExport is OnStartHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSettingsPage]: {\n type: HandlerType.OnSettingsPage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSettingsPageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetHistoricalPrice]: {\n type: HandlerType.OnAssetHistoricalPrice,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetHistoricalPriceHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsLookup]: {\n type: HandlerType.OnAssetsLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnAssetsLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsConversion]: {\n type: HandlerType.OnAssetsConversion,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetsConversionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnProtocolRequest]: {\n type: HandlerType.OnProtocolRequest,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnProtocolRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnClientRequest]: {\n type: HandlerType.OnClientRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnClientRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnWebSocketEvent]: {\n type: HandlerType.OnWebSocketEvent,\n required: true,\n validator: (snapExport: unknown): snapExport is OnWebSocketEventHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
1
|
+
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler, OnWebSocketEventHandler } from "@metamask/snaps-sdk";
|
|
2
2
|
import { HandlerType } from "./types.cjs";
|
|
3
3
|
export declare const SNAP_EXPORTS: {
|
|
4
4
|
readonly onRpcRequest: {
|
|
@@ -31,6 +31,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
31
31
|
readonly required: false;
|
|
32
32
|
readonly validator: (snapExport: unknown) => snapExport is import("@metamask/snaps-sdk").LifecycleEventHandler;
|
|
33
33
|
};
|
|
34
|
+
readonly onStart: {
|
|
35
|
+
readonly type: HandlerType.OnStart;
|
|
36
|
+
readonly required: false;
|
|
37
|
+
readonly validator: (snapExport: unknown) => snapExport is import("@metamask/snaps-sdk").LifecycleEventHandler;
|
|
38
|
+
};
|
|
34
39
|
readonly onKeyringRequest: {
|
|
35
40
|
readonly type: HandlerType.OnKeyringRequest;
|
|
36
41
|
readonly required: true;
|
|
@@ -81,6 +86,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
81
86
|
readonly required: true;
|
|
82
87
|
readonly validator: (snapExport: unknown) => snapExport is OnClientRequestHandler;
|
|
83
88
|
};
|
|
89
|
+
readonly onWebSocketEvent: {
|
|
90
|
+
readonly type: HandlerType.OnWebSocketEvent;
|
|
91
|
+
readonly required: true;
|
|
92
|
+
readonly validator: (snapExport: unknown) => snapExport is OnWebSocketEventHandler;
|
|
93
|
+
};
|
|
84
94
|
};
|
|
85
95
|
export declare const SNAP_EXPORT_NAMES: HandlerType[];
|
|
86
96
|
//# sourceMappingURL=exports.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.cts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"exports.d.cts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAElB,oBAAoB,EAEpB,kBAAkB,EAClB,uBAAuB,EACxB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;;;;yCAQG,OAAO;;;;;yCAOP,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
1
|
+
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler, OnWebSocketEventHandler } from "@metamask/snaps-sdk";
|
|
2
2
|
import { HandlerType } from "./types.mjs";
|
|
3
3
|
export declare const SNAP_EXPORTS: {
|
|
4
4
|
readonly onRpcRequest: {
|
|
@@ -31,6 +31,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
31
31
|
readonly required: false;
|
|
32
32
|
readonly validator: (snapExport: unknown) => snapExport is import("@metamask/snaps-sdk").LifecycleEventHandler;
|
|
33
33
|
};
|
|
34
|
+
readonly onStart: {
|
|
35
|
+
readonly type: HandlerType.OnStart;
|
|
36
|
+
readonly required: false;
|
|
37
|
+
readonly validator: (snapExport: unknown) => snapExport is import("@metamask/snaps-sdk").LifecycleEventHandler;
|
|
38
|
+
};
|
|
34
39
|
readonly onKeyringRequest: {
|
|
35
40
|
readonly type: HandlerType.OnKeyringRequest;
|
|
36
41
|
readonly required: true;
|
|
@@ -81,6 +86,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
81
86
|
readonly required: true;
|
|
82
87
|
readonly validator: (snapExport: unknown) => snapExport is OnClientRequestHandler;
|
|
83
88
|
};
|
|
89
|
+
readonly onWebSocketEvent: {
|
|
90
|
+
readonly type: HandlerType.OnWebSocketEvent;
|
|
91
|
+
readonly required: true;
|
|
92
|
+
readonly validator: (snapExport: unknown) => snapExport is OnWebSocketEventHandler;
|
|
93
|
+
};
|
|
84
94
|
};
|
|
85
95
|
export declare const SNAP_EXPORT_NAMES: HandlerType[];
|
|
86
96
|
//# sourceMappingURL=exports.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.mts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"exports.d.mts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAElB,oBAAoB,EAEpB,kBAAkB,EAClB,uBAAuB,EACxB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;;;;yCAQG,OAAO;;;;;yCAOP,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
|
|
@@ -42,6 +42,13 @@ export const SNAP_EXPORTS = {
|
|
|
42
42
|
return typeof snapExport === 'function';
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
+
[HandlerType.OnStart]: {
|
|
46
|
+
type: HandlerType.OnStart,
|
|
47
|
+
required: false,
|
|
48
|
+
validator: (snapExport) => {
|
|
49
|
+
return typeof snapExport === 'function';
|
|
50
|
+
},
|
|
51
|
+
},
|
|
45
52
|
[HandlerType.OnKeyringRequest]: {
|
|
46
53
|
type: HandlerType.OnKeyringRequest,
|
|
47
54
|
required: true,
|
|
@@ -112,6 +119,13 @@ export const SNAP_EXPORTS = {
|
|
|
112
119
|
return typeof snapExport === 'function';
|
|
113
120
|
},
|
|
114
121
|
},
|
|
122
|
+
[HandlerType.OnWebSocketEvent]: {
|
|
123
|
+
type: HandlerType.OnWebSocketEvent,
|
|
124
|
+
required: true,
|
|
125
|
+
validator: (snapExport) => {
|
|
126
|
+
return typeof snapExport === 'function';
|
|
127
|
+
},
|
|
128
|
+
},
|
|
115
129
|
};
|
|
116
130
|
export const SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
117
131
|
//# sourceMappingURL=exports.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.mjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exports.mjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,WAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,EAAE,WAAW,CAAC,aAAa;QAC/B,QAAQ,EAAE,IAAI;QACd,SAAS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C,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAuC,EAAE;YACtE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE;QAChC,IAAI,EAAE,WAAW,CAAC,kBAAkB;QACpC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CACT,UAAmB,EACsB,EAAE;YAC3C,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE;QAC/B,IAAI,EAAE,WAAW,CAAC,iBAAiB;QACnC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CACT,UAAmB,EACqB,EAAE;YAC1C,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE;QAC7B,IAAI,EAAE,WAAW,CAAC,eAAe;QACjC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAwC,EAAE;YACvE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE;QAC9B,IAAI,EAAE,WAAW,CAAC,gBAAgB;QAClC,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAyC,EAAE;YACxE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import type {\n OnAssetHistoricalPriceHandler,\n OnAssetsConversionHandler,\n OnAssetsLookupHandler,\n OnClientRequestHandler,\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnProtocolRequestHandler,\n OnRpcRequestHandler,\n OnSettingsPageHandler,\n OnSignatureHandler,\n OnStartHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n OnWebSocketEventHandler,\n} from '@metamask/snaps-sdk';\n\nimport { HandlerType } from './types';\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnStart]: {\n type: HandlerType.OnStart,\n required: false,\n validator: (snapExport: unknown): snapExport is OnStartHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSettingsPage]: {\n type: HandlerType.OnSettingsPage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSettingsPageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetHistoricalPrice]: {\n type: HandlerType.OnAssetHistoricalPrice,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetHistoricalPriceHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsLookup]: {\n type: HandlerType.OnAssetsLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnAssetsLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsConversion]: {\n type: HandlerType.OnAssetsConversion,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetsConversionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnProtocolRequest]: {\n type: HandlerType.OnProtocolRequest,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnProtocolRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnClientRequest]: {\n type: HandlerType.OnClientRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnClientRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnWebSocketEvent]: {\n type: HandlerType.OnWebSocketEvent,\n required: true,\n validator: (snapExport: unknown): snapExport is OnWebSocketEventHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
|
package/dist/handlers/types.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var HandlerType;
|
|
|
9
9
|
HandlerType["OnCronjob"] = "onCronjob";
|
|
10
10
|
HandlerType["OnInstall"] = "onInstall";
|
|
11
11
|
HandlerType["OnUpdate"] = "onUpdate";
|
|
12
|
+
HandlerType["OnStart"] = "onStart";
|
|
12
13
|
HandlerType["OnNameLookup"] = "onNameLookup";
|
|
13
14
|
HandlerType["OnKeyringRequest"] = "onKeyringRequest";
|
|
14
15
|
HandlerType["OnHomePage"] = "onHomePage";
|
|
@@ -19,5 +20,6 @@ var HandlerType;
|
|
|
19
20
|
HandlerType["OnAssetHistoricalPrice"] = "onAssetHistoricalPrice";
|
|
20
21
|
HandlerType["OnProtocolRequest"] = "onProtocolRequest";
|
|
21
22
|
HandlerType["OnClientRequest"] = "onClientRequest";
|
|
23
|
+
HandlerType["OnWebSocketEvent"] = "onWebSocketEvent";
|
|
22
24
|
})(HandlerType || (exports.HandlerType = HandlerType = {}));
|
|
23
25
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,WAmBX;AAnBD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,gEAAiD,CAAA;IACjD,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;IACnC,oDAAqC,CAAA;AACvC,CAAC,EAnBW,WAAW,2BAAX,WAAW,QAmBtB","sourcesContent":["import type { SNAP_EXPORTS } from './exports';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnStart = 'onStart',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnAssetHistoricalPrice = 'onAssetHistoricalPrice',\n OnProtocolRequest = 'onProtocolRequest',\n OnClientRequest = 'onClientRequest',\n OnWebSocketEvent = 'onWebSocketEvent',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n"]}
|
|
@@ -25,6 +25,7 @@ export declare enum HandlerType {
|
|
|
25
25
|
OnCronjob = "onCronjob",
|
|
26
26
|
OnInstall = "onInstall",
|
|
27
27
|
OnUpdate = "onUpdate",
|
|
28
|
+
OnStart = "onStart",
|
|
28
29
|
OnNameLookup = "onNameLookup",
|
|
29
30
|
OnKeyringRequest = "onKeyringRequest",
|
|
30
31
|
OnHomePage = "onHomePage",
|
|
@@ -34,7 +35,8 @@ export declare enum HandlerType {
|
|
|
34
35
|
OnAssetsConversion = "onAssetsConversion",
|
|
35
36
|
OnAssetHistoricalPrice = "onAssetHistoricalPrice",
|
|
36
37
|
OnProtocolRequest = "onProtocolRequest",
|
|
37
|
-
OnClientRequest = "onClientRequest"
|
|
38
|
+
OnClientRequest = "onClientRequest",
|
|
39
|
+
OnWebSocketEvent = "onWebSocketEvent"
|
|
38
40
|
}
|
|
39
41
|
export type SnapHandler = {
|
|
40
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAkB;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,WAAW,IAClD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,KAAK,UAAU,IAAI,MAAM,OAAO,GAC1E,OAAO,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;KAC/B,GAAG,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,EAAE,eAAe,CAClD,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAC3B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE9C,oBAAY,WAAW;IACrB,YAAY,iBAAiB;IAC7B,WAAW,gBA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AmB;IACjC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;CACtC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC"}
|
|
@@ -25,6 +25,7 @@ export declare enum HandlerType {
|
|
|
25
25
|
OnCronjob = "onCronjob",
|
|
26
26
|
OnInstall = "onInstall",
|
|
27
27
|
OnUpdate = "onUpdate",
|
|
28
|
+
OnStart = "onStart",
|
|
28
29
|
OnNameLookup = "onNameLookup",
|
|
29
30
|
OnKeyringRequest = "onKeyringRequest",
|
|
30
31
|
OnHomePage = "onHomePage",
|
|
@@ -34,7 +35,8 @@ export declare enum HandlerType {
|
|
|
34
35
|
OnAssetsConversion = "onAssetsConversion",
|
|
35
36
|
OnAssetHistoricalPrice = "onAssetHistoricalPrice",
|
|
36
37
|
OnProtocolRequest = "onProtocolRequest",
|
|
37
|
-
OnClientRequest = "onClientRequest"
|
|
38
|
+
OnClientRequest = "onClientRequest",
|
|
39
|
+
OnWebSocketEvent = "onWebSocketEvent"
|
|
38
40
|
}
|
|
39
41
|
export type SnapHandler = {
|
|
40
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAkB;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OA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AC1E,OAAO,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;KAC/B,GAAG,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,EAAE,eAAe,CAClD,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAC3B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE9C,oBAAY,WAAW;IACrB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IACrC,UAAU,eAAe;IACzB,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;CACtC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC"}
|
package/dist/handlers/types.mjs
CHANGED
|
@@ -6,6 +6,7 @@ export var HandlerType;
|
|
|
6
6
|
HandlerType["OnCronjob"] = "onCronjob";
|
|
7
7
|
HandlerType["OnInstall"] = "onInstall";
|
|
8
8
|
HandlerType["OnUpdate"] = "onUpdate";
|
|
9
|
+
HandlerType["OnStart"] = "onStart";
|
|
9
10
|
HandlerType["OnNameLookup"] = "onNameLookup";
|
|
10
11
|
HandlerType["OnKeyringRequest"] = "onKeyringRequest";
|
|
11
12
|
HandlerType["OnHomePage"] = "onHomePage";
|
|
@@ -16,5 +17,6 @@ export var HandlerType;
|
|
|
16
17
|
HandlerType["OnAssetHistoricalPrice"] = "onAssetHistoricalPrice";
|
|
17
18
|
HandlerType["OnProtocolRequest"] = "onProtocolRequest";
|
|
18
19
|
HandlerType["OnClientRequest"] = "onClientRequest";
|
|
20
|
+
HandlerType["OnWebSocketEvent"] = "onWebSocketEvent";
|
|
19
21
|
})(HandlerType || (HandlerType = {}));
|
|
20
22
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,WAmBX;AAnBD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,gEAAiD,CAAA;IACjD,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;IACnC,oDAAqC,CAAA;AACvC,CAAC,EAnBW,WAAW,KAAX,WAAW,QAmBtB","sourcesContent":["import type { SNAP_EXPORTS } from './exports';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnStart = 'onStart',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnAssetHistoricalPrice = 'onAssetHistoricalPrice',\n OnProtocolRequest = 'onProtocolRequest',\n OnClientRequest = 'onClientRequest',\n OnWebSocketEvent = 'onWebSocketEvent',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n"]}
|
package/dist/localization.d.cts
CHANGED
|
@@ -135,7 +135,7 @@ export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, loc
|
|
|
135
135
|
type: string;
|
|
136
136
|
url: string;
|
|
137
137
|
} | undefined;
|
|
138
|
-
initialConnections?: Record<string
|
|
138
|
+
initialConnections?: Record<string, {}> | undefined;
|
|
139
139
|
platformVersion?: import("@metamask/utils").SemVerVersion | undefined;
|
|
140
140
|
$schema?: string | undefined;
|
|
141
141
|
};
|
package/dist/localization.d.mts
CHANGED
|
@@ -135,7 +135,7 @@ export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, loc
|
|
|
135
135
|
type: string;
|
|
136
136
|
url: string;
|
|
137
137
|
} | undefined;
|
|
138
|
-
initialConnections?: Record<string
|
|
138
|
+
initialConnections?: Record<string, {}> | undefined;
|
|
139
139
|
platformVersion?: import("@metamask/utils").SemVerVersion | undefined;
|
|
140
140
|
$schema?: string | undefined;
|
|
141
141
|
};
|
|
@@ -57,7 +57,7 @@ export declare const EmptyObjectStruct: Struct<EmptyObject, null>;
|
|
|
57
57
|
export declare const PermissionsStruct: Describe<InitialPermissions>;
|
|
58
58
|
export type SnapPermissions = InferMatching<typeof PermissionsStruct, InitialPermissions>;
|
|
59
59
|
export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
|
|
60
|
-
export declare const InitialConnectionsStruct: Struct<Record<string
|
|
60
|
+
export declare const InitialConnectionsStruct: Struct<Record<string, {}>, null>;
|
|
61
61
|
export type InitialConnections = Infer<typeof InitialConnectionsStruct>;
|
|
62
62
|
export declare const SnapManifestStruct: Struct<{
|
|
63
63
|
description: string;
|
|
@@ -132,7 +132,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
132
132
|
type: string;
|
|
133
133
|
url: string;
|
|
134
134
|
} | undefined;
|
|
135
|
-
initialConnections?: Record<string
|
|
135
|
+
initialConnections?: Record<string, {}> | undefined;
|
|
136
136
|
platformVersion?: import("@metamask/utils").SemVerVersion | undefined;
|
|
137
137
|
$schema?: string | undefined;
|
|
138
138
|
}, {
|
|
@@ -183,7 +183,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
183
183
|
files: Struct<string[] | undefined, Struct<string, null>>;
|
|
184
184
|
locales: Struct<string[] | undefined, Struct<string, null>>;
|
|
185
185
|
}>;
|
|
186
|
-
initialConnections: Struct<Record<string
|
|
186
|
+
initialConnections: Struct<Record<string, {}> | undefined, null>;
|
|
187
187
|
initialPermissions: Describe<Partial<{
|
|
188
188
|
'endowment:cronjob': {
|
|
189
189
|
jobs?: import("@metamask/snaps-sdk").Cronjob[] | undefined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;
|
|
|
57
57
|
export declare const PermissionsStruct: Describe<InitialPermissions>;
|
|
58
58
|
export type SnapPermissions = InferMatching<typeof PermissionsStruct, InitialPermissions>;
|
|
59
59
|
export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
|
|
60
|
-
export declare const InitialConnectionsStruct: Struct<Record<string
|
|
60
|
+
export declare const InitialConnectionsStruct: Struct<Record<string, {}>, null>;
|
|
61
61
|
export type InitialConnections = Infer<typeof InitialConnectionsStruct>;
|
|
62
62
|
export declare const SnapManifestStruct: Struct<{
|
|
63
63
|
description: string;
|
|
@@ -132,7 +132,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
132
132
|
type: string;
|
|
133
133
|
url: string;
|
|
134
134
|
} | undefined;
|
|
135
|
-
initialConnections?: Record<string
|
|
135
|
+
initialConnections?: Record<string, {}> | undefined;
|
|
136
136
|
platformVersion?: import("@metamask/utils").SemVerVersion | undefined;
|
|
137
137
|
$schema?: string | undefined;
|
|
138
138
|
}, {
|
|
@@ -183,7 +183,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
183
183
|
files: Struct<string[] | undefined, Struct<string, null>>;
|
|
184
184
|
locales: Struct<string[] | undefined, Struct<string, null>>;
|
|
185
185
|
}>;
|
|
186
|
-
initialConnections: Struct<Record<string
|
|
186
|
+
initialConnections: Struct<Record<string, {}> | undefined, null>;
|
|
187
187
|
initialPermissions: Describe<Partial<{
|
|
188
188
|
'endowment:cronjob': {
|
|
189
189
|
jobs?: import("@metamask/snaps-sdk").Cronjob[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,4BAA4B;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,8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AO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,kBAAkB,CAoEzD,CAAC;AAGH,MAAM,MAAM,eAAe,GAAG,aAAa,CACzC,OAAO,iBAAiB,EACxB,kBAAkB,CACnB,CAAC;AAEF,eAAO,MAAM,uBAAuB,wCAAkB,CAAC;AAEvD,eAAO,MAAM,wBAAwB,kCAGpC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAExE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+B7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,YAAY,CAM/B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAG/D"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unusedExports = void 0;
|
|
4
|
+
// Special case endowments that should be ignored.
|
|
5
|
+
const IGNORED_ENDOWMENTS = ['endowment:network-access'];
|
|
4
6
|
/**
|
|
5
7
|
* Check if the Snap exports handlers that are not requested in the manifest, or
|
|
6
8
|
* if the Snap requests permissions for handlers that are not exported.
|
|
@@ -14,6 +16,12 @@ exports.unusedExports = {
|
|
|
14
16
|
if (!handlerEndowments || !exports) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
19
|
+
// Endowments used based on the exports from the Snap. This is used to
|
|
20
|
+
// filter endowments that are used by multiple handlers, e.g., the lifecycle
|
|
21
|
+
// handlers.
|
|
22
|
+
const usedEndowments = Object.entries(handlerEndowments)
|
|
23
|
+
.filter(([handler, endowment]) => endowment === null || exports.includes(handler))
|
|
24
|
+
.map(([, endowment]) => endowment);
|
|
17
25
|
const unusedHandlers = Object.entries(handlerEndowments)
|
|
18
26
|
.filter(([handler, endowment]) => {
|
|
19
27
|
if (endowment === null) {
|
|
@@ -24,10 +32,12 @@ exports.unusedExports = {
|
|
|
24
32
|
})
|
|
25
33
|
.map(([handler, endowment]) => `${handler} (${endowment})`);
|
|
26
34
|
const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
|
|
27
|
-
if (endowment === null) {
|
|
35
|
+
if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {
|
|
28
36
|
return false;
|
|
29
37
|
}
|
|
30
|
-
return (
|
|
38
|
+
return (!usedEndowments.includes(endowment) &&
|
|
39
|
+
files.manifest.result.initialPermissions[endowment] &&
|
|
40
|
+
!exports.includes(handler));
|
|
31
41
|
});
|
|
32
42
|
if (unusedHandlers.length > 0) {
|
|
33
43
|
// We don't specify a fix function here, because:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACU,QAAA,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,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;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAoF3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAoF3B,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Special case endowments that should be ignored.
|
|
2
|
+
const IGNORED_ENDOWMENTS = ['endowment:network-access'];
|
|
1
3
|
/**
|
|
2
4
|
* Check if the Snap exports handlers that are not requested in the manifest, or
|
|
3
5
|
* if the Snap requests permissions for handlers that are not exported.
|
|
@@ -11,6 +13,12 @@ export const unusedExports = {
|
|
|
11
13
|
if (!handlerEndowments || !exports) {
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
16
|
+
// Endowments used based on the exports from the Snap. This is used to
|
|
17
|
+
// filter endowments that are used by multiple handlers, e.g., the lifecycle
|
|
18
|
+
// handlers.
|
|
19
|
+
const usedEndowments = Object.entries(handlerEndowments)
|
|
20
|
+
.filter(([handler, endowment]) => endowment === null || exports.includes(handler))
|
|
21
|
+
.map(([, endowment]) => endowment);
|
|
14
22
|
const unusedHandlers = Object.entries(handlerEndowments)
|
|
15
23
|
.filter(([handler, endowment]) => {
|
|
16
24
|
if (endowment === null) {
|
|
@@ -21,10 +29,12 @@ export const unusedExports = {
|
|
|
21
29
|
})
|
|
22
30
|
.map(([handler, endowment]) => `${handler} (${endowment})`);
|
|
23
31
|
const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
|
|
24
|
-
if (endowment === null) {
|
|
32
|
+
if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {
|
|
25
33
|
return false;
|
|
26
34
|
}
|
|
27
|
-
return (
|
|
35
|
+
return (!usedEndowments.includes(endowment) &&
|
|
36
|
+
files.manifest.result.initialPermissions[endowment] &&
|
|
37
|
+
!exports.includes(handler));
|
|
28
38
|
});
|
|
29
39
|
if (unusedHandlers.length > 0) {
|
|
30
40
|
// We don't specify a fix function here, because:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACvC,SAAqC,CACtC,CACF,CAAC;QACJ,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,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AAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WALLET_SNAP_PERMISSION_KEY = exports.isValidUrl = exports.uri = exports.SNAP_STREAM_NAMES = exports.SnapIdPrefixes = exports.NpmSnapPackageJsonStruct = exports.NameStruct = exports.NpmSnapFileNames = void 0;
|
|
4
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
4
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
6
|
const utils_1 = require("@metamask/utils");
|
|
6
7
|
var NpmSnapFileNames;
|
|
@@ -36,15 +37,18 @@ var SNAP_STREAM_NAMES;
|
|
|
36
37
|
SNAP_STREAM_NAMES["JSON_RPC"] = "jsonRpc";
|
|
37
38
|
SNAP_STREAM_NAMES["COMMAND"] = "command";
|
|
38
39
|
})(SNAP_STREAM_NAMES || (exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES = {}));
|
|
39
|
-
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.
|
|
40
|
+
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.string)(), 'uri', (value) => {
|
|
40
41
|
try {
|
|
41
42
|
const url = new URL(value);
|
|
42
43
|
const UrlStruct = (0, superstruct_1.type)(opts);
|
|
43
44
|
(0, superstruct_1.assert)(url, UrlStruct);
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
46
|
-
catch {
|
|
47
|
-
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof superstruct_1.StructError) {
|
|
49
|
+
return (0, snaps_sdk_1.getErrorMessage)(error);
|
|
50
|
+
}
|
|
51
|
+
return `Expected URL, got "${value.toString()}"`;
|
|
48
52
|
}
|
|
49
53
|
});
|
|
50
54
|
exports.uri = uri;
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,mDAAsD;AACtD,uDAS+B;AAG/B,2CAA+D;AAQ/D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,mDAA+B,CAAA;AACjC,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AAEY,QAAA,UAAU,GAAG,IAAA,kBAAI,EAC5B,IAAA,qBAAa,EACX,WAAW,EACX,6DAA6D,CAC9D,EACD,CAAC,EACD,GAAG,CACJ,CAAC;AAEF,2EAA2E;AAC3E,sBAAsB;AACT,QAAA,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IAC3C,OAAO,EAAE,qBAAa;IACtB,IAAI,EAAE,kBAAU;IAChB,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3C,UAAU,EAAE,IAAA,sBAAQ,EAClB,IAAA,kBAAI,EAAC;QACH,IAAI,EAAE,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC;QACjC,GAAG,EAAE,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE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":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n is,\n optional,\n refine,\n size,\n string,\n type,\n assert as assertSuperstruct,\n StructError,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { definePattern, VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n definePattern(\n 'Snap Name',\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(string(), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch (error) {\n if (error instanceof StructError) {\n return getErrorMessage(error);\n }\n return `Expected URL, got \"${value.toString()}\"`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ type UriOptions<Type extends string> = {
|
|
|
80
80
|
pathname?: Struct<Type>;
|
|
81
81
|
search?: Struct<Type>;
|
|
82
82
|
};
|
|
83
|
-
export declare const uri: (opts?: UriOptions<any>) => Struct<string
|
|
83
|
+
export declare const uri: (opts?: UriOptions<any>) => Struct<string, null>;
|
|
84
84
|
/**
|
|
85
85
|
* Returns whether a given value is a valid URL.
|
|
86
86
|
*
|
|
@@ -88,7 +88,7 @@ export declare const uri: (opts?: UriOptions<any>) => Struct<string | URL, null>
|
|
|
88
88
|
* @param opts - Optional constraints for url checking.
|
|
89
89
|
* @returns Whether `url` is valid URL or not.
|
|
90
90
|
*/
|
|
91
|
-
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string
|
|
91
|
+
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string;
|
|
92
92
|
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
93
93
|
export type SnapsPermissionRequest = {
|
|
94
94
|
[WALLET_SNAP_PERMISSION_KEY]: {
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,6BAAmB;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAuB;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,oBAAY,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,QAAQ,u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I,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IACtD,UAAU,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AAEjC,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;AAE1E,KAAK,UAAU,CAAC,IAAI,SAAS,MAAM,IAAI;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,GAAG,UAAU,WAAW,GAAG,CAAC,yBAcrC,CAAC;AAEL;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,IAAI,GAAE,UAAU,CAAC,GAAG,CAAM,GACzB,GAAG,IAAI,MAAM,CAEf;AAGD,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,0BAA0B,CAAC,EAAE;QAC5B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC;gBAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aAC7B;SACF,CAAC;KACH,CAAC;CACH,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -80,7 +80,7 @@ type UriOptions<Type extends string> = {
|
|
|
80
80
|
pathname?: Struct<Type>;
|
|
81
81
|
search?: Struct<Type>;
|
|
82
82
|
};
|
|
83
|
-
export declare const uri: (opts?: UriOptions<any>) => Struct<string
|
|
83
|
+
export declare const uri: (opts?: UriOptions<any>) => Struct<string, null>;
|
|
84
84
|
/**
|
|
85
85
|
* Returns whether a given value is a valid URL.
|
|
86
86
|
*
|
|
@@ -88,7 +88,7 @@ export declare const uri: (opts?: UriOptions<any>) => Struct<string | URL, null>
|
|
|
88
88
|
* @param opts - Optional constraints for url checking.
|
|
89
89
|
* @returns Whether `url` is valid URL or not.
|
|
90
90
|
*/
|
|
91
|
-
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string
|
|
91
|
+
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string;
|
|
92
92
|
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
93
93
|
export type SnapsPermissionRequest = {
|
|
94
94
|
[WALLET_SNAP_PERMISSION_KEY]: {
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,6BAAmB;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAuB;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,6BAAmB;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD,oBAAY,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,QAAQ,uBAAuB;CAChC;AAED,eAAO,MAAM,UAAU,sBAOtB,CAAC;AAIF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;EAUnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,GACrE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEtB;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AC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,GAAG,UAAU,WAAW,GAAG,CAAC,yBAcrC,CAAC;AAEL;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,OAAO,EACZ,IAAI,GAAE,UAAU,CAAC,GAAG,CAAM,GACzB,GAAG,IAAI,MAAM,CAEf;AAGD,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,0BAA0B,CAAC,EAAE;QAC5B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC;gBAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;aAC7B;SACF,CAAC;KACH,CAAC;CACH,CAAC"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getErrorMessage } from "@metamask/snaps-sdk";
|
|
2
|
+
import { is, optional, refine, size, string, type, assert as assertSuperstruct, StructError } from "@metamask/superstruct";
|
|
2
3
|
import { definePattern, VersionStruct } from "@metamask/utils";
|
|
3
4
|
export var NpmSnapFileNames;
|
|
4
5
|
(function (NpmSnapFileNames) {
|
|
@@ -33,15 +34,18 @@ export var SNAP_STREAM_NAMES;
|
|
|
33
34
|
SNAP_STREAM_NAMES["JSON_RPC"] = "jsonRpc";
|
|
34
35
|
SNAP_STREAM_NAMES["COMMAND"] = "command";
|
|
35
36
|
})(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
|
|
36
|
-
export const uri = (opts = {}) => refine(
|
|
37
|
+
export const uri = (opts = {}) => refine(string(), 'uri', (value) => {
|
|
37
38
|
try {
|
|
38
39
|
const url = new URL(value);
|
|
39
40
|
const UrlStruct = type(opts);
|
|
40
41
|
assertSuperstruct(url, UrlStruct);
|
|
41
42
|
return true;
|
|
42
43
|
}
|
|
43
|
-
catch {
|
|
44
|
-
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof StructError) {
|
|
46
|
+
return getErrorMessage(error);
|
|
47
|
+
}
|
|
48
|
+
return `Expected URL, got "${value.toString()}"`;
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
51
|
/**
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAA4B;AACtD,OAAO,EACL,EAAE,EACF,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,MAAM,IAAI,iBAAiB,EAC3B,WAAW,EACZ,8BAA8B;AAG/B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAQ/D,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,mDAA+B,CAAA;AACjC,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAC5B,aAAa,CACX,WAAW,EACX,6DAA6D,CAC9D,EACD,CAAC,EACD,GAAG,CACJ,CAAC;AAEF,2EAA2E;AAC3E,sBAAsB;AACtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;IAC3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IACnD,CAAC;AACH,CAAC,CAAC,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,GAAY,EACZ,OAAwB,EAAE;IAE1B,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CAAC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n is,\n optional,\n refine,\n size,\n string,\n type,\n assert as assertSuperstruct,\n StructError,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { definePattern, VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n definePattern(\n 'Snap Name',\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(string(), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch (error) {\n if (error instanceof StructError) {\n return getErrorMessage(error);\n }\n return `Expected URL, got \"${value.toString()}\"`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "A collection of utilities for MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@metamask/rpc-errors": "^7.0.2",
|
|
87
87
|
"@metamask/slip44": "^4.2.0",
|
|
88
88
|
"@metamask/snaps-registry": "^3.2.3",
|
|
89
|
-
"@metamask/snaps-sdk": "^8.
|
|
89
|
+
"@metamask/snaps-sdk": "^8.1.0",
|
|
90
90
|
"@metamask/superstruct": "^3.2.1",
|
|
91
91
|
"@metamask/utils": "^11.4.0",
|
|
92
92
|
"@noble/hashes": "^1.7.1",
|