@metamask/snaps-sdk 2.0.0 → 3.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 +17 -1
- package/dist/index.js +883 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +810 -0
- package/dist/index.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/error-wrappers.d.ts +464 -48
- package/dist/types/errors.d.ts +2 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internals/error-wrappers.d.ts +29 -3
- package/dist/types/internals/index.d.ts +1 -0
- package/dist/types/internals/svg.d.ts +14 -0
- package/package.json +19 -16
- package/dist/cjs/error-wrappers.js +0 -80
- package/dist/cjs/error-wrappers.js.map +0 -1
- package/dist/cjs/errors.js +0 -157
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/images.js +0 -54
- package/dist/cjs/images.js.map +0 -1
- package/dist/cjs/index.js +0 -62
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internals/error-wrappers.js +0 -25
- package/dist/cjs/internals/error-wrappers.js.map +0 -1
- package/dist/cjs/internals/errors.js +0 -59
- package/dist/cjs/internals/errors.js.map +0 -1
- package/dist/cjs/internals/helpers.js +0 -6
- package/dist/cjs/internals/helpers.js.map +0 -1
- package/dist/cjs/internals/index.js +0 -23
- package/dist/cjs/internals/index.js.map +0 -1
- package/dist/cjs/internals/structs.js +0 -43
- package/dist/cjs/internals/structs.js.map +0 -1
- package/dist/cjs/types/caip.js +0 -10
- package/dist/cjs/types/caip.js.map +0 -1
- package/dist/cjs/types/global.js +0 -6
- package/dist/cjs/types/global.js.map +0 -1
- package/dist/cjs/types/handlers/cronjob.js +0 -6
- package/dist/cjs/types/handlers/cronjob.js.map +0 -1
- package/dist/cjs/types/handlers/home-page.js +0 -6
- package/dist/cjs/types/handlers/home-page.js.map +0 -1
- package/dist/cjs/types/handlers/index.js +0 -28
- package/dist/cjs/types/handlers/index.js.map +0 -1
- package/dist/cjs/types/handlers/keyring.js +0 -6
- package/dist/cjs/types/handlers/keyring.js.map +0 -1
- package/dist/cjs/types/handlers/lifecycle.js +0 -6
- package/dist/cjs/types/handlers/lifecycle.js.map +0 -1
- package/dist/cjs/types/handlers/name-lookup.js +0 -6
- package/dist/cjs/types/handlers/name-lookup.js.map +0 -1
- package/dist/cjs/types/handlers/rpc-request.js +0 -6
- package/dist/cjs/types/handlers/rpc-request.js.map +0 -1
- package/dist/cjs/types/handlers/signature.js +0 -6
- package/dist/cjs/types/handlers/signature.js.map +0 -1
- package/dist/cjs/types/handlers/transaction.js +0 -16
- package/dist/cjs/types/handlers/transaction.js.map +0 -1
- package/dist/cjs/types/handlers/user-input.js +0 -51
- package/dist/cjs/types/handlers/user-input.js.map +0 -1
- package/dist/cjs/types/index.js +0 -29
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/interface.js +0 -26
- package/dist/cjs/types/interface.js.map +0 -1
- package/dist/cjs/types/methods/create-interface.js +0 -6
- package/dist/cjs/types/methods/create-interface.js.map +0 -1
- package/dist/cjs/types/methods/dialog.js +0 -18
- package/dist/cjs/types/methods/dialog.js.map +0 -1
- package/dist/cjs/types/methods/get-bip32-entropy.js +0 -6
- package/dist/cjs/types/methods/get-bip32-entropy.js.map +0 -1
- package/dist/cjs/types/methods/get-bip32-public-key.js +0 -6
- package/dist/cjs/types/methods/get-bip32-public-key.js.map +0 -1
- package/dist/cjs/types/methods/get-bip44-entropy.js +0 -6
- package/dist/cjs/types/methods/get-bip44-entropy.js.map +0 -1
- package/dist/cjs/types/methods/get-client-status.js +0 -10
- package/dist/cjs/types/methods/get-client-status.js.map +0 -1
- package/dist/cjs/types/methods/get-entropy.js +0 -6
- package/dist/cjs/types/methods/get-entropy.js.map +0 -1
- package/dist/cjs/types/methods/get-file.js +0 -18
- package/dist/cjs/types/methods/get-file.js.map +0 -1
- package/dist/cjs/types/methods/get-interface-state.js +0 -6
- package/dist/cjs/types/methods/get-interface-state.js.map +0 -1
- package/dist/cjs/types/methods/get-locale.js +0 -10
- package/dist/cjs/types/methods/get-locale.js.map +0 -1
- package/dist/cjs/types/methods/get-snaps.js +0 -6
- package/dist/cjs/types/methods/get-snaps.js.map +0 -1
- package/dist/cjs/types/methods/index.js +0 -38
- package/dist/cjs/types/methods/index.js.map +0 -1
- package/dist/cjs/types/methods/invoke-keyring.js +0 -6
- package/dist/cjs/types/methods/invoke-keyring.js.map +0 -1
- package/dist/cjs/types/methods/invoke-snap.js +0 -6
- package/dist/cjs/types/methods/invoke-snap.js.map +0 -1
- package/dist/cjs/types/methods/manage-accounts.js +0 -6
- package/dist/cjs/types/methods/manage-accounts.js.map +0 -1
- package/dist/cjs/types/methods/manage-state.js +0 -18
- package/dist/cjs/types/methods/manage-state.js.map +0 -1
- package/dist/cjs/types/methods/methods.js +0 -6
- package/dist/cjs/types/methods/methods.js.map +0 -1
- package/dist/cjs/types/methods/notify.js +0 -17
- package/dist/cjs/types/methods/notify.js.map +0 -1
- package/dist/cjs/types/methods/request-snaps.js +0 -6
- package/dist/cjs/types/methods/request-snaps.js.map +0 -1
- package/dist/cjs/types/methods/update-interface.js +0 -6
- package/dist/cjs/types/methods/update-interface.js.map +0 -1
- package/dist/cjs/types/permissions.js +0 -6
- package/dist/cjs/types/permissions.js.map +0 -1
- package/dist/cjs/types/provider.js +0 -6
- package/dist/cjs/types/provider.js.map +0 -1
- package/dist/cjs/types/snap.js +0 -6
- package/dist/cjs/types/snap.js.map +0 -1
- package/dist/cjs/ui/builder.js +0 -44
- package/dist/cjs/ui/builder.js.map +0 -1
- package/dist/cjs/ui/component.js +0 -29
- package/dist/cjs/ui/component.js.map +0 -1
- package/dist/cjs/ui/components/address.js +0 -30
- package/dist/cjs/ui/components/address.js.map +0 -1
- package/dist/cjs/ui/components/button.js +0 -59
- package/dist/cjs/ui/components/button.js.map +0 -1
- package/dist/cjs/ui/components/copyable.js +0 -32
- package/dist/cjs/ui/components/copyable.js.map +0 -1
- package/dist/cjs/ui/components/divider.js +0 -27
- package/dist/cjs/ui/components/divider.js.map +0 -1
- package/dist/cjs/ui/components/form.js +0 -41
- package/dist/cjs/ui/components/form.js.map +0 -1
- package/dist/cjs/ui/components/heading.js +0 -30
- package/dist/cjs/ui/components/heading.js.map +0 -1
- package/dist/cjs/ui/components/image.js +0 -47
- package/dist/cjs/ui/components/image.js.map +0 -1
- package/dist/cjs/ui/components/index.js +0 -54
- package/dist/cjs/ui/components/index.js.map +0 -1
- package/dist/cjs/ui/components/input.js +0 -52
- package/dist/cjs/ui/components/input.js.map +0 -1
- package/dist/cjs/ui/components/panel.js +0 -65
- package/dist/cjs/ui/components/panel.js.map +0 -1
- package/dist/cjs/ui/components/row.js +0 -57
- package/dist/cjs/ui/components/row.js.map +0 -1
- package/dist/cjs/ui/components/spinner.js +0 -27
- package/dist/cjs/ui/components/spinner.js.map +0 -1
- package/dist/cjs/ui/components/text.js +0 -32
- package/dist/cjs/ui/components/text.js.map +0 -1
- package/dist/cjs/ui/index.js +0 -28
- package/dist/cjs/ui/index.js.map +0 -1
- package/dist/cjs/ui/nodes.js +0 -46
- package/dist/cjs/ui/nodes.js.map +0 -1
- package/dist/esm/error-wrappers.js +0 -128
- package/dist/esm/error-wrappers.js.map +0 -1
- package/dist/esm/errors.js +0 -150
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/images.js +0 -84
- package/dist/esm/images.js.map +0 -1
- package/dist/esm/index.js +0 -10
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internals/error-wrappers.js +0 -25
- package/dist/esm/internals/error-wrappers.js.map +0 -1
- package/dist/esm/internals/errors.js +0 -58
- package/dist/esm/internals/errors.js.map +0 -1
- package/dist/esm/internals/helpers.js +0 -3
- package/dist/esm/internals/helpers.js.map +0 -1
- package/dist/esm/internals/index.js +0 -6
- package/dist/esm/internals/index.js.map +0 -1
- package/dist/esm/internals/structs.js +0 -59
- package/dist/esm/internals/structs.js.map +0 -1
- package/dist/esm/types/caip.js +0 -7
- package/dist/esm/types/caip.js.map +0 -1
- package/dist/esm/types/global.js +0 -3
- package/dist/esm/types/global.js.map +0 -1
- package/dist/esm/types/handlers/cronjob.js +0 -3
- package/dist/esm/types/handlers/cronjob.js.map +0 -1
- package/dist/esm/types/handlers/home-page.js +0 -3
- package/dist/esm/types/handlers/home-page.js.map +0 -1
- package/dist/esm/types/handlers/index.js +0 -11
- package/dist/esm/types/handlers/index.js.map +0 -1
- package/dist/esm/types/handlers/keyring.js +0 -3
- package/dist/esm/types/handlers/keyring.js.map +0 -1
- package/dist/esm/types/handlers/lifecycle.js +0 -3
- package/dist/esm/types/handlers/lifecycle.js.map +0 -1
- package/dist/esm/types/handlers/name-lookup.js +0 -3
- package/dist/esm/types/handlers/name-lookup.js.map +0 -1
- package/dist/esm/types/handlers/rpc-request.js +0 -3
- package/dist/esm/types/handlers/rpc-request.js.map +0 -1
- package/dist/esm/types/handlers/signature.js +0 -3
- package/dist/esm/types/handlers/signature.js.map +0 -1
- package/dist/esm/types/handlers/transaction.js +0 -6
- package/dist/esm/types/handlers/transaction.js.map +0 -1
- package/dist/esm/types/handlers/user-input.js +0 -24
- package/dist/esm/types/handlers/user-input.js.map +0 -1
- package/dist/esm/types/index.js +0 -12
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/types/interface.js +0 -12
- package/dist/esm/types/interface.js.map +0 -1
- package/dist/esm/types/methods/create-interface.js +0 -3
- package/dist/esm/types/methods/create-interface.js.map +0 -1
- package/dist/esm/types/methods/dialog.js +0 -8
- package/dist/esm/types/methods/dialog.js.map +0 -1
- package/dist/esm/types/methods/get-bip32-entropy.js +0 -3
- package/dist/esm/types/methods/get-bip32-entropy.js.map +0 -1
- package/dist/esm/types/methods/get-bip32-public-key.js +0 -3
- package/dist/esm/types/methods/get-bip32-public-key.js.map +0 -1
- package/dist/esm/types/methods/get-bip44-entropy.js +0 -3
- package/dist/esm/types/methods/get-bip44-entropy.js.map +0 -1
- package/dist/esm/types/methods/get-client-status.js +0 -7
- package/dist/esm/types/methods/get-client-status.js.map +0 -1
- package/dist/esm/types/methods/get-entropy.js +0 -3
- package/dist/esm/types/methods/get-entropy.js.map +0 -1
- package/dist/esm/types/methods/get-file.js +0 -8
- package/dist/esm/types/methods/get-file.js.map +0 -1
- package/dist/esm/types/methods/get-interface-state.js +0 -3
- package/dist/esm/types/methods/get-interface-state.js.map +0 -1
- package/dist/esm/types/methods/get-locale.js +0 -7
- package/dist/esm/types/methods/get-locale.js.map +0 -1
- package/dist/esm/types/methods/get-snaps.js +0 -3
- package/dist/esm/types/methods/get-snaps.js.map +0 -1
- package/dist/esm/types/methods/index.js +0 -21
- package/dist/esm/types/methods/index.js.map +0 -1
- package/dist/esm/types/methods/invoke-keyring.js +0 -3
- package/dist/esm/types/methods/invoke-keyring.js.map +0 -1
- package/dist/esm/types/methods/invoke-snap.js +0 -3
- package/dist/esm/types/methods/invoke-snap.js.map +0 -1
- package/dist/esm/types/methods/manage-accounts.js +0 -3
- package/dist/esm/types/methods/manage-accounts.js.map +0 -1
- package/dist/esm/types/methods/manage-state.js +0 -8
- package/dist/esm/types/methods/manage-state.js.map +0 -1
- package/dist/esm/types/methods/methods.js +0 -3
- package/dist/esm/types/methods/methods.js.map +0 -1
- package/dist/esm/types/methods/notify.js +0 -7
- package/dist/esm/types/methods/notify.js.map +0 -1
- package/dist/esm/types/methods/request-snaps.js +0 -3
- package/dist/esm/types/methods/request-snaps.js.map +0 -1
- package/dist/esm/types/methods/update-interface.js +0 -3
- package/dist/esm/types/methods/update-interface.js.map +0 -1
- package/dist/esm/types/permissions.js +0 -3
- package/dist/esm/types/permissions.js.map +0 -1
- package/dist/esm/types/provider.js +0 -3
- package/dist/esm/types/provider.js.map +0 -1
- package/dist/esm/types/snap.js +0 -3
- package/dist/esm/types/snap.js.map +0 -1
- package/dist/esm/ui/builder.js +0 -50
- package/dist/esm/ui/builder.js.map +0 -1
- package/dist/esm/ui/component.js +0 -23
- package/dist/esm/ui/component.js.map +0 -1
- package/dist/esm/ui/components/address.js +0 -22
- package/dist/esm/ui/components/address.js.map +0 -1
- package/dist/esm/ui/components/button.js +0 -50
- package/dist/esm/ui/components/button.js.map +0 -1
- package/dist/esm/ui/components/copyable.js +0 -27
- package/dist/esm/ui/components/copyable.js.map +0 -1
- package/dist/esm/ui/components/divider.js +0 -15
- package/dist/esm/ui/components/divider.js.map +0 -1
- package/dist/esm/ui/components/form.js +0 -39
- package/dist/esm/ui/components/form.js.map +0 -1
- package/dist/esm/ui/components/heading.js +0 -22
- package/dist/esm/ui/components/heading.js.map +0 -1
- package/dist/esm/ui/components/image.js +0 -37
- package/dist/esm/ui/components/image.js.map +0 -1
- package/dist/esm/ui/components/index.js +0 -14
- package/dist/esm/ui/components/index.js.map +0 -1
- package/dist/esm/ui/components/input.js +0 -47
- package/dist/esm/ui/components/input.js.map +0 -1
- package/dist/esm/ui/components/panel.js +0 -66
- package/dist/esm/ui/components/panel.js.map +0 -1
- package/dist/esm/ui/components/row.js +0 -50
- package/dist/esm/ui/components/row.js.map +0 -1
- package/dist/esm/ui/components/spinner.js +0 -15
- package/dist/esm/ui/components/spinner.js.map +0 -1
- package/dist/esm/ui/components/text.js +0 -29
- package/dist/esm/ui/components/text.js.map +0 -1
- package/dist/esm/ui/index.js +0 -5
- package/dist/esm/ui/index.js.map +0 -1
- package/dist/esm/ui/nodes.js +0 -29
- package/dist/esm/ui/nodes.js.map +0 -1
package/dist/types/errors.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class SnapError extends Error {
|
|
|
42
42
|
*
|
|
43
43
|
* @returns Additional data for the error.
|
|
44
44
|
*/
|
|
45
|
-
get data(): Record<string, Json
|
|
45
|
+
get data(): Record<string, Json> | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* The error stack.
|
|
48
48
|
*
|
|
@@ -81,8 +81,6 @@ export declare type SerializedSnapError = {
|
|
|
81
81
|
code: typeof SNAP_ERROR_CODE;
|
|
82
82
|
message: typeof SNAP_ERROR_MESSAGE;
|
|
83
83
|
data: {
|
|
84
|
-
cause: JsonRpcError
|
|
85
|
-
data: Record<string, Json>;
|
|
86
|
-
};
|
|
84
|
+
cause: JsonRpcError;
|
|
87
85
|
};
|
|
88
86
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { EnumToUnion } from './internals';
|
|
2
|
-
export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE, literal, union, enumValue, } from './internals';
|
|
2
|
+
export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE, literal, union, enumValue, parseSvg, isSvg, } from './internals';
|
|
3
3
|
export type { Json, JsonRpcError, JsonRpcRequest, JsonRpcParams, } from '@metamask/utils';
|
|
4
4
|
export { assert } from '@metamask/utils';
|
|
5
5
|
export * from './errors';
|
|
@@ -14,15 +14,41 @@ export declare type JsonRpcErrorFunction = typeof rpcErrors.parse;
|
|
|
14
14
|
* @returns The created `SnapError` class.
|
|
15
15
|
*/
|
|
16
16
|
export declare function createSnapError(fn: JsonRpcErrorFunction): {
|
|
17
|
-
new (message?: string
|
|
17
|
+
new (message?: string): {
|
|
18
18
|
readonly "__#3@#code": number;
|
|
19
19
|
readonly "__#3@#message": string;
|
|
20
|
-
readonly "__#3@#data"
|
|
20
|
+
readonly "__#3@#data"?: Record<string, Json> | undefined;
|
|
21
21
|
readonly "__#3@#stack"?: string | undefined;
|
|
22
22
|
readonly name: string;
|
|
23
23
|
readonly code: number;
|
|
24
24
|
readonly message: string;
|
|
25
|
-
readonly data: Record<string, Json
|
|
25
|
+
readonly data: Record<string, Json> | undefined;
|
|
26
|
+
readonly stack: string | undefined;
|
|
27
|
+
toJSON(): import("../errors").SerializedSnapError;
|
|
28
|
+
serialize(): import("../errors").SerializedSnapError;
|
|
29
|
+
};
|
|
30
|
+
new (data?: Record<string, Json>): {
|
|
31
|
+
readonly "__#3@#code": number;
|
|
32
|
+
readonly "__#3@#message": string;
|
|
33
|
+
readonly "__#3@#data"?: Record<string, Json> | undefined;
|
|
34
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly code: number;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
readonly data: Record<string, Json> | undefined;
|
|
39
|
+
readonly stack: string | undefined;
|
|
40
|
+
toJSON(): import("../errors").SerializedSnapError;
|
|
41
|
+
serialize(): import("../errors").SerializedSnapError;
|
|
42
|
+
};
|
|
43
|
+
new (message?: string | Record<string, Json>, data?: Record<string, Json>): {
|
|
44
|
+
readonly "__#3@#code": number;
|
|
45
|
+
readonly "__#3@#message": string;
|
|
46
|
+
readonly "__#3@#data"?: Record<string, Json> | undefined;
|
|
47
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly code: number;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly data: Record<string, Json> | undefined;
|
|
26
52
|
readonly stack: string | undefined;
|
|
27
53
|
toJSON(): import("../errors").SerializedSnapError;
|
|
28
54
|
serialize(): import("../errors").SerializedSnapError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate a string as an SVG.
|
|
3
|
+
*
|
|
4
|
+
* @param svg - An SVG string.
|
|
5
|
+
* @returns The SVG, its attributes and children in an object format.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseSvg(svg: string): any;
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a string is a valid SVG.
|
|
10
|
+
*
|
|
11
|
+
* @param svg - An SVG string.
|
|
12
|
+
* @returns True if the SVG is valid otherwise false.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSvg(svg: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
7
7
|
},
|
|
8
8
|
"sideEffects": false,
|
|
9
|
-
"
|
|
10
|
-
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
11
19
|
"types": "./dist/types/index.d.ts",
|
|
12
20
|
"files": [
|
|
13
|
-
"dist
|
|
14
|
-
"dist/esm/**",
|
|
15
|
-
"dist/types/**"
|
|
21
|
+
"dist"
|
|
16
22
|
],
|
|
17
23
|
"scripts": {
|
|
18
24
|
"test": "jest && yarn posttest",
|
|
@@ -23,33 +29,29 @@
|
|
|
23
29
|
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
|
|
24
30
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
25
31
|
"lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-sdk",
|
|
26
|
-
"build": "
|
|
27
|
-
"build:source": "yarn build:esm && yarn build:cjs",
|
|
32
|
+
"build": "tsup --clean && yarn build:types",
|
|
28
33
|
"build:types": "tsc --project tsconfig.build.json",
|
|
29
|
-
"build:esm": "swc src --out-dir dist/esm --config-file ../../.swcrc.build.json --config module.type=es6",
|
|
30
|
-
"build:cjs": "swc src --out-dir dist/cjs --config-file ../../.swcrc.build.json --config module.type=commonjs",
|
|
31
|
-
"build:clean": "yarn clean && yarn build",
|
|
32
34
|
"clean": "rimraf '*.tsbuildinfo' 'dist'",
|
|
33
35
|
"publish:preview": "yarn npm publish --tag preview",
|
|
34
36
|
"lint:ci": "yarn lint",
|
|
35
|
-
"lint:dependencies": "depcheck"
|
|
37
|
+
"lint:dependencies": "depcheck",
|
|
38
|
+
"build:ci": "tsup --clean"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
|
38
41
|
"@metamask/key-tree": "^9.0.0",
|
|
39
42
|
"@metamask/providers": "^14.0.2",
|
|
40
|
-
"@metamask/rpc-errors": "^6.1
|
|
43
|
+
"@metamask/rpc-errors": "^6.2.1",
|
|
41
44
|
"@metamask/utils": "^8.3.0",
|
|
42
|
-
"
|
|
45
|
+
"fast-xml-parser": "^4.3.4",
|
|
43
46
|
"superstruct": "^1.0.3"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
|
-
"@lavamoat/allow-scripts": "^3.0.
|
|
49
|
+
"@lavamoat/allow-scripts": "^3.0.2",
|
|
47
50
|
"@metamask/auto-changelog": "^3.4.4",
|
|
48
51
|
"@metamask/eslint-config": "^12.1.0",
|
|
49
52
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
50
53
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
51
54
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
52
|
-
"@swc/cli": "^0.1.62",
|
|
53
55
|
"@swc/core": "1.3.78",
|
|
54
56
|
"@types/jest": "^27.5.1",
|
|
55
57
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
@@ -72,6 +74,7 @@
|
|
|
72
74
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
73
75
|
"rimraf": "^4.1.2",
|
|
74
76
|
"ts-jest": "^29.1.1",
|
|
77
|
+
"tsup": "^8.0.1",
|
|
75
78
|
"typescript": "~4.8.4"
|
|
76
79
|
},
|
|
77
80
|
"engines": {
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
InternalError: function() {
|
|
13
|
-
return InternalError;
|
|
14
|
-
},
|
|
15
|
-
InvalidInputError: function() {
|
|
16
|
-
return InvalidInputError;
|
|
17
|
-
},
|
|
18
|
-
InvalidParamsError: function() {
|
|
19
|
-
return InvalidParamsError;
|
|
20
|
-
},
|
|
21
|
-
InvalidRequestError: function() {
|
|
22
|
-
return InvalidRequestError;
|
|
23
|
-
},
|
|
24
|
-
LimitExceededError: function() {
|
|
25
|
-
return LimitExceededError;
|
|
26
|
-
},
|
|
27
|
-
MethodNotFoundError: function() {
|
|
28
|
-
return MethodNotFoundError;
|
|
29
|
-
},
|
|
30
|
-
MethodNotSupportedError: function() {
|
|
31
|
-
return MethodNotSupportedError;
|
|
32
|
-
},
|
|
33
|
-
ParseError: function() {
|
|
34
|
-
return ParseError;
|
|
35
|
-
},
|
|
36
|
-
ResourceNotFoundError: function() {
|
|
37
|
-
return ResourceNotFoundError;
|
|
38
|
-
},
|
|
39
|
-
ResourceUnavailableError: function() {
|
|
40
|
-
return ResourceUnavailableError;
|
|
41
|
-
},
|
|
42
|
-
TransactionRejected: function() {
|
|
43
|
-
return TransactionRejected;
|
|
44
|
-
},
|
|
45
|
-
ChainDisconnectedError: function() {
|
|
46
|
-
return ChainDisconnectedError;
|
|
47
|
-
},
|
|
48
|
-
DisconnectedError: function() {
|
|
49
|
-
return DisconnectedError;
|
|
50
|
-
},
|
|
51
|
-
UnauthorizedError: function() {
|
|
52
|
-
return UnauthorizedError;
|
|
53
|
-
},
|
|
54
|
-
UnsupportedMethodError: function() {
|
|
55
|
-
return UnsupportedMethodError;
|
|
56
|
-
},
|
|
57
|
-
UserRejectedRequestError: function() {
|
|
58
|
-
return UserRejectedRequestError;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const _rpcerrors = require("@metamask/rpc-errors");
|
|
62
|
-
const _internals = require("./internals");
|
|
63
|
-
const InternalError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.internal);
|
|
64
|
-
const InvalidInputError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidInput);
|
|
65
|
-
const InvalidParamsError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidParams);
|
|
66
|
-
const InvalidRequestError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidRequest);
|
|
67
|
-
const LimitExceededError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.limitExceeded);
|
|
68
|
-
const MethodNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotFound);
|
|
69
|
-
const MethodNotSupportedError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotSupported);
|
|
70
|
-
const ParseError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.parse);
|
|
71
|
-
const ResourceNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceNotFound);
|
|
72
|
-
const ResourceUnavailableError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceUnavailable);
|
|
73
|
-
const TransactionRejected = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.transactionRejected);
|
|
74
|
-
const ChainDisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.chainDisconnected);
|
|
75
|
-
const DisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.disconnected);
|
|
76
|
-
const UnauthorizedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unauthorized);
|
|
77
|
-
const UnsupportedMethodError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unsupportedMethod);
|
|
78
|
-
const UserRejectedRequestError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.userRejectedRequest);
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/error-wrappers.ts"],"sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { createSnapError } from './internals';\n\n/**\n * A JSON-RPC 2.0 Internal (-32603) error.\n *\n * This can be thrown by a Snap to indicate that an internal error occurred,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InternalError = createSnapError(rpcErrors.internal);\n\n/**\n * An Ethereum JSON-RPC Invalid Input (-32000) error.\n *\n * This can be thrown by a Snap to indicate that the input to a method is\n * invalid, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const InvalidInputError = createSnapError(rpcErrors.invalidInput);\n\n/**\n * A JSON-RPC 2.0 Invalid Params (-32602) error.\n *\n * This can be thrown by a Snap to indicate that the parameters to a method are\n * invalid, without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidParamsError = createSnapError(rpcErrors.invalidParams);\n\n/**\n * A JSON-RPC 2.0 Invalid Request (-32600) error.\n *\n * This can be thrown by a Snap to indicate that the request is invalid, without\n * crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidRequestError = createSnapError(rpcErrors.invalidRequest);\n\n/**\n * An Ethereum JSON-RPC Limit Exceeded (-32005) error.\n *\n * This can be thrown by a Snap to indicate that a limit has been exceeded,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const LimitExceededError = createSnapError(rpcErrors.limitExceeded);\n\n/**\n * An Ethereum JSON-RPC Method Not Found (-32601) error.\n *\n * This can be thrown by a Snap to indicate that a method does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const MethodNotFoundError = createSnapError(rpcErrors.methodNotFound);\n\n/**\n * An Ethereum JSON-RPC Method Not Supported (-32004) error.\n *\n * This can be thrown by a Snap to indicate that a method is not supported,\n * without crashing the Snap.\n */\nexport const MethodNotSupportedError = createSnapError(\n rpcErrors.methodNotSupported,\n);\n\n/**\n * A JSON-RPC 2.0 Parse (-32700) error.\n *\n * This can be thrown by a Snap to indicate that a request is not valid JSON,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const ParseError = createSnapError(rpcErrors.parse);\n\n/**\n * An Ethereum JSON-RPC Resource Not Found (-32001) error.\n *\n * This can be thrown by a Snap to indicate that a resource does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceNotFoundError = createSnapError(\n rpcErrors.resourceNotFound,\n);\n\n/**\n * An Ethereum JSON-RPC Resource Unavailable (-32002) error.\n *\n * This can be thrown by a Snap to indicate that a resource is unavailable,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceUnavailableError = createSnapError(\n rpcErrors.resourceUnavailable,\n);\n\n/**\n * An Ethereum JSON-RPC Transaction Rejected (-32003) error.\n *\n * This can be thrown by a Snap to indicate that a transaction was rejected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const TransactionRejected = createSnapError(\n rpcErrors.transactionRejected,\n);\n\n/**\n * An Ethereum Provider Chain Disconnected (4901) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected\n * from the requested chain, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const ChainDisconnectedError = createSnapError(\n providerErrors.chainDisconnected,\n);\n\n/**\n * An Ethereum Provider Disconnected (4900) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const DisconnectedError = createSnapError(providerErrors.disconnected);\n\n/**\n * An Ethereum Provider Unauthorized (4100) error.\n *\n * This can be thrown by a Snap to indicate that the requested method / account\n * is not authorized by the user, without crashing the Snap.\n */\nexport const UnauthorizedError = createSnapError(providerErrors.unauthorized);\n\n/**\n * An Ethereum Provider Unsupported Method (4200) error.\n *\n * This can be thrown by a Snap to indicate that the requested method is not\n * supported by the provider, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UnsupportedMethodError = createSnapError(\n providerErrors.unsupportedMethod,\n);\n\n/**\n * An Ethereum Provider User Rejected Request (4001) error.\n *\n * This can be thrown by a Snap to indicate that the user rejected the request,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UserRejectedRequestError = createSnapError(\n providerErrors.userRejectedRequest,\n);\n"],"names":["InternalError","InvalidInputError","InvalidParamsError","InvalidRequestError","LimitExceededError","MethodNotFoundError","MethodNotSupportedError","ParseError","ResourceNotFoundError","ResourceUnavailableError","TransactionRejected","ChainDisconnectedError","DisconnectedError","UnauthorizedError","UnsupportedMethodError","UserRejectedRequestError","createSnapError","rpcErrors","internal","invalidInput","invalidParams","invalidRequest","limitExceeded","methodNotFound","methodNotSupported","parse","resourceNotFound","resourceUnavailable","transactionRejected","providerErrors","chainDisconnected","disconnected","unauthorized","unsupportedMethod","userRejectedRequest"],"mappings":";;;;;;;;;;;IAYaA,aAAa;eAAbA;;IAUAC,iBAAiB;eAAjBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAQAC,uBAAuB;eAAvBA;;IAYAC,UAAU;eAAVA;;IAUAC,qBAAqB;eAArBA;;IAYAC,wBAAwB;eAAxBA;;IAYAC,mBAAmB;eAAnBA;;IAYAC,sBAAsB;eAAtBA;;IAYAC,iBAAiB;eAAjBA;;IAQAC,iBAAiB;eAAjBA;;IAUAC,sBAAsB;eAAtBA;;IAYAC,wBAAwB;eAAxBA;;;2BA1K6B;2BAEV;AAUzB,MAAMf,gBAAgBgB,IAAAA,0BAAe,EAACC,oBAAS,CAACC,QAAQ;AAUxD,MAAMjB,oBAAoBe,IAAAA,0BAAe,EAACC,oBAAS,CAACE,YAAY;AAUhE,MAAMjB,qBAAqBc,IAAAA,0BAAe,EAACC,oBAAS,CAACG,aAAa;AAUlE,MAAMjB,sBAAsBa,IAAAA,0BAAe,EAACC,oBAAS,CAACI,cAAc;AAUpE,MAAMjB,qBAAqBY,IAAAA,0BAAe,EAACC,oBAAS,CAACK,aAAa;AAUlE,MAAMjB,sBAAsBW,IAAAA,0BAAe,EAACC,oBAAS,CAACM,cAAc;AAQpE,MAAMjB,0BAA0BU,IAAAA,0BAAe,EACpDC,oBAAS,CAACO,kBAAkB;AAWvB,MAAMjB,aAAaS,IAAAA,0BAAe,EAACC,oBAAS,CAACQ,KAAK;AAUlD,MAAMjB,wBAAwBQ,IAAAA,0BAAe,EAClDC,oBAAS,CAACS,gBAAgB;AAWrB,MAAMjB,2BAA2BO,IAAAA,0BAAe,EACrDC,oBAAS,CAACU,mBAAmB;AAWxB,MAAMjB,sBAAsBM,IAAAA,0BAAe,EAChDC,oBAAS,CAACW,mBAAmB;AAWxB,MAAMjB,yBAAyBK,IAAAA,0BAAe,EACnDa,yBAAc,CAACC,iBAAiB;AAW3B,MAAMlB,oBAAoBI,IAAAA,0BAAe,EAACa,yBAAc,CAACE,YAAY;AAQrE,MAAMlB,oBAAoBG,IAAAA,0BAAe,EAACa,yBAAc,CAACG,YAAY;AAUrE,MAAMlB,yBAAyBE,IAAAA,0BAAe,EACnDa,yBAAc,CAACI,iBAAiB;AAW3B,MAAMlB,2BAA2BC,IAAAA,0BAAe,EACrDa,yBAAc,CAACK,mBAAmB"}
|
package/dist/cjs/errors.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "SnapError", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return SnapError;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _internals = require("./internals");
|
|
12
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
13
|
-
if (privateCollection.has(obj)) {
|
|
14
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
18
|
-
if (descriptor.get) {
|
|
19
|
-
return descriptor.get.call(receiver);
|
|
20
|
-
}
|
|
21
|
-
return descriptor.value;
|
|
22
|
-
}
|
|
23
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
24
|
-
if (descriptor.set) {
|
|
25
|
-
descriptor.set.call(receiver, value);
|
|
26
|
-
} else {
|
|
27
|
-
if (!descriptor.writable) {
|
|
28
|
-
throw new TypeError("attempted to set read only private field");
|
|
29
|
-
}
|
|
30
|
-
descriptor.value = value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
34
|
-
if (!privateMap.has(receiver)) {
|
|
35
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
36
|
-
}
|
|
37
|
-
return privateMap.get(receiver);
|
|
38
|
-
}
|
|
39
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
40
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
41
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
42
|
-
}
|
|
43
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
44
|
-
_check_private_redeclaration(obj, privateMap);
|
|
45
|
-
privateMap.set(obj, value);
|
|
46
|
-
}
|
|
47
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
48
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
49
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
var _code = /*#__PURE__*/ new WeakMap(), _message = /*#__PURE__*/ new WeakMap(), _data = /*#__PURE__*/ new WeakMap(), _stack = /*#__PURE__*/ new WeakMap();
|
|
53
|
-
class SnapError extends Error {
|
|
54
|
-
/**
|
|
55
|
-
* The error name.
|
|
56
|
-
*
|
|
57
|
-
* @returns The error name.
|
|
58
|
-
*/ get name() {
|
|
59
|
-
return 'SnapError';
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The error code.
|
|
63
|
-
*
|
|
64
|
-
* @returns The error code.
|
|
65
|
-
*/ get code() {
|
|
66
|
-
return _class_private_field_get(this, _code);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* The error message.
|
|
70
|
-
*
|
|
71
|
-
* @returns The error message.
|
|
72
|
-
*/ // This line is covered, but Jest doesn't pick it up for some reason.
|
|
73
|
-
/* istanbul ignore next */ get message() {
|
|
74
|
-
return _class_private_field_get(this, _message);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Additional data for the error.
|
|
78
|
-
*
|
|
79
|
-
* @returns Additional data for the error.
|
|
80
|
-
*/ get data() {
|
|
81
|
-
return _class_private_field_get(this, _data);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The error stack.
|
|
85
|
-
*
|
|
86
|
-
* @returns The error stack.
|
|
87
|
-
*/ // This line is covered, but Jest doesn't pick it up for some reason.
|
|
88
|
-
/* istanbul ignore next */ get stack() {
|
|
89
|
-
return _class_private_field_get(this, _stack);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Convert the error to a JSON object.
|
|
93
|
-
*
|
|
94
|
-
* @returns The JSON object.
|
|
95
|
-
*/ toJSON() {
|
|
96
|
-
return {
|
|
97
|
-
code: _internals.SNAP_ERROR_CODE,
|
|
98
|
-
message: _internals.SNAP_ERROR_MESSAGE,
|
|
99
|
-
data: {
|
|
100
|
-
cause: {
|
|
101
|
-
code: this.code,
|
|
102
|
-
message: this.message,
|
|
103
|
-
stack: this.stack,
|
|
104
|
-
data: this.data
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Serialize the error to a JSON object. This is called by
|
|
111
|
-
* `@metamask/rpc-errors` when serializing the error.
|
|
112
|
-
*
|
|
113
|
-
* @returns The JSON object.
|
|
114
|
-
*/ serialize() {
|
|
115
|
-
return this.toJSON();
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Create a new `SnapError`.
|
|
119
|
-
*
|
|
120
|
-
* @param error - The error to create the `SnapError` from. If this is a
|
|
121
|
-
* `string`, it will be used as the error message. If this is an `Error`, its
|
|
122
|
-
* `message` property will be used as the error message. If this is a
|
|
123
|
-
* `JsonRpcError`, its `message` property will be used as the error message
|
|
124
|
-
* and its `code` property will be used as the error code. Otherwise, the
|
|
125
|
-
* error will be converted to a string and used as the error message.
|
|
126
|
-
* @param data - Additional data to include in the error. This will be merged
|
|
127
|
-
* with the error data, if any.
|
|
128
|
-
*/ constructor(error, data = {}){
|
|
129
|
-
const message = (0, _internals.getErrorMessage)(error);
|
|
130
|
-
super(message);
|
|
131
|
-
_class_private_field_init(this, _code, {
|
|
132
|
-
writable: true,
|
|
133
|
-
value: void 0
|
|
134
|
-
});
|
|
135
|
-
_class_private_field_init(this, _message, {
|
|
136
|
-
writable: true,
|
|
137
|
-
value: void 0
|
|
138
|
-
});
|
|
139
|
-
_class_private_field_init(this, _data, {
|
|
140
|
-
writable: true,
|
|
141
|
-
value: void 0
|
|
142
|
-
});
|
|
143
|
-
_class_private_field_init(this, _stack, {
|
|
144
|
-
writable: true,
|
|
145
|
-
value: void 0
|
|
146
|
-
});
|
|
147
|
-
_class_private_field_set(this, _message, message);
|
|
148
|
-
_class_private_field_set(this, _code, (0, _internals.getErrorCode)(error));
|
|
149
|
-
_class_private_field_set(this, _data, {
|
|
150
|
-
...(0, _internals.getErrorData)(error),
|
|
151
|
-
...data
|
|
152
|
-
});
|
|
153
|
-
_class_private_field_set(this, _stack, super.stack);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/cjs/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import type { Json, JsonRpcError } from '@metamask/utils';\n\nimport {\n getErrorCode,\n getErrorData,\n getErrorMessage,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n/**\n * A generic error which can be thrown by a Snap, without it causing the Snap to\n * crash.\n */\nexport class SnapError extends Error {\n readonly #code: number;\n\n readonly #message: string;\n\n readonly #data: Record<string, Json>;\n\n readonly #stack?: string;\n\n /**\n * Create a new `SnapError`.\n *\n * @param error - The error to create the `SnapError` from. If this is a\n * `string`, it will be used as the error message. If this is an `Error`, its\n * `message` property will be used as the error message. If this is a\n * `JsonRpcError`, its `message` property will be used as the error message\n * and its `code` property will be used as the error code. Otherwise, the\n * error will be converted to a string and used as the error message.\n * @param data - Additional data to include in the error. This will be merged\n * with the error data, if any.\n */\n constructor(\n error: string | Error | JsonRpcError,\n data: Record<string, Json> = {},\n ) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#message = message;\n this.#code = getErrorCode(error);\n this.#data = { ...getErrorData(error), ...data };\n this.#stack = super.stack;\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'SnapError';\n }\n\n /**\n * The error code.\n *\n * @returns The error code.\n */\n get code() {\n return this.#code;\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get message() {\n return this.#message;\n }\n\n /**\n * Additional data for the error.\n *\n * @returns Additional data for the error.\n */\n get data() {\n return this.#data;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapError {\n return {\n code: SNAP_ERROR_CODE,\n message: SNAP_ERROR_MESSAGE,\n data: {\n cause: {\n code: this.code,\n message: this.message,\n stack: this.stack,\n data: this.data,\n },\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * A serialized {@link SnapError}. It's JSON-serializable, so it can be sent\n * over the RPC. The original error is wrapped in the `cause` property.\n *\n * @property code - The error code. This is always `-31002`.\n * @property message - The error message. This is always `'Snap Error'`.\n * @property data - The error data.\n * @property data.cause - The cause of the error.\n * @property data.cause.code - The error code.\n * @property data.cause.message - The error message.\n * @property data.cause.stack - The error stack.\n * @property data.cause.data - Additional data for the error.\n * @see SnapError\n */\nexport type SerializedSnapError = {\n code: typeof SNAP_ERROR_CODE;\n message: typeof SNAP_ERROR_MESSAGE;\n data: {\n cause: JsonRpcError & {\n data: Record<string, Json>;\n };\n };\n};\n"],"names":["SnapError","Error","name","code","message","data","stack","toJSON","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","cause","serialize","constructor","error","getErrorMessage","getErrorCode","getErrorData"],"mappings":";;;;+BAcaA;;;eAAAA;;;2BANN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOI,qCAEA,wCAEA,qCAEA;AAPJ,MAAMA,kBAAkBC;IAkC7B;;;;GAIC,GACD,IAAIC,OAAO;QACT,OAAO;IACT;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,UAAU;QACZ,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,QAAQ;QACV,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACDC,SAA8B;QAC5B,OAAO;YACLJ,MAAMK,0BAAe;YACrBJ,SAASK,6BAAkB;YAC3BJ,MAAM;gBACJK,OAAO;oBACLP,MAAM,IAAI,CAACA,IAAI;oBACfC,SAAS,IAAI,CAACA,OAAO;oBACrBE,OAAO,IAAI,CAACA,KAAK;oBACjBD,MAAM,IAAI,CAACA,IAAI;gBACjB;YACF;QACF;IACF;IAEA;;;;;GAKC,GACDM,YAAY;QACV,OAAO,IAAI,CAACJ,MAAM;IACpB;IAtGA;;;;;;;;;;;GAWC,GACDK,YACEC,KAAoC,EACpCR,OAA6B,CAAC,CAAC,CAC/B;QACA,MAAMD,UAAUU,IAAAA,0BAAe,EAACD;QAChC,KAAK,CAACT;QAzBR,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAqBQA,UAAUA;uCACVD,OAAOY,IAAAA,uBAAY,EAACF;uCACpBR,OAAO;YAAE,GAAGW,IAAAA,uBAAY,EAACH,MAAM;YAAE,GAAGR,IAAI;QAAC;uCACzCC,QAAQ,KAAK,CAACA;IACtB;AAgFF"}
|
package/dist/cjs/images.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getImageData: function() {
|
|
13
|
-
return getImageData;
|
|
14
|
-
},
|
|
15
|
-
getImageComponent: function() {
|
|
16
|
-
return getImageComponent;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _utils = require("@metamask/utils");
|
|
20
|
-
const _ui = require("./ui");
|
|
21
|
-
/**
|
|
22
|
-
* Get raw image data from a URL.
|
|
23
|
-
*
|
|
24
|
-
* @param url - The URL to get the image data from.
|
|
25
|
-
* @param options - The options to use when fetching the image data. This is
|
|
26
|
-
* passed directly to `fetch`.
|
|
27
|
-
* @returns A promise that resolves to the image data as a blob.
|
|
28
|
-
*/ async function getRawImageData(url, options) {
|
|
29
|
-
if (typeof fetch !== 'function') {
|
|
30
|
-
throw new Error(`Failed to fetch image data from "${url}": Using this function requires the "endowment:network-access" permission.`);
|
|
31
|
-
}
|
|
32
|
-
return fetch(url, options).then(async (response)=>{
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
throw new Error(`Failed to fetch image data from "${url}": ${response.status} ${response.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
const blob = await response.blob();
|
|
37
|
-
(0, _utils.assert)(blob.type === 'image/jpeg' || blob.type === 'image/png', 'Expected image data to be a JPEG or PNG image.');
|
|
38
|
-
return blob;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
async function getImageData(url, options) {
|
|
42
|
-
const blob = await getRawImageData(url, options);
|
|
43
|
-
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
44
|
-
return `data:${blob.type};base64,${(0, _utils.bytesToBase64)(bytes)}`;
|
|
45
|
-
}
|
|
46
|
-
async function getImageComponent(url, { width, height = width, request }) {
|
|
47
|
-
(0, _utils.assert)(typeof width === 'number' && width > 0, 'Expected width to be a number greater than 0.');
|
|
48
|
-
(0, _utils.assert)(typeof height === 'number' && height > 0, 'Expected height to be a number greater than 0.');
|
|
49
|
-
const imageData = await getImageData(url, request);
|
|
50
|
-
const size = `width="${width}" height="${height}"`;
|
|
51
|
-
return (0, _ui.image)(`<svg ${size.trim()} xmlns="http://www.w3.org/2000/svg"><image ${size.trim()} href="${imageData}" /></svg>`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=images.js.map
|
package/dist/cjs/images.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/images.ts"],"sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\n\nimport { image } from './ui';\n\n/**\n * Get raw image data from a URL.\n *\n * @param url - The URL to get the image data from.\n * @param options - The options to use when fetching the image data. This is\n * passed directly to `fetch`.\n * @returns A promise that resolves to the image data as a blob.\n */\nasync function getRawImageData(url: string, options?: RequestInit) {\n if (typeof fetch !== 'function') {\n throw new Error(\n `Failed to fetch image data from \"${url}\": Using this function requires the \"endowment:network-access\" permission.`,\n );\n }\n\n return fetch(url, options).then(async (response) => {\n if (!response.ok) {\n throw new Error(\n `Failed to fetch image data from \"${url}\": ${response.status} ${response.statusText}`,\n );\n }\n\n const blob = await response.blob();\n assert(\n blob.type === 'image/jpeg' || blob.type === 'image/png',\n 'Expected image data to be a JPEG or PNG image.',\n );\n\n return blob;\n });\n}\n\n/**\n * Get image data as data-string from a URL. This is useful for embedding images\n * inside of SVGs. Only JPEG and PNG images are supported.\n *\n * Note: This function uses `fetch` to get the image data. This means that using\n * it requires the `endowment:network-access` permission.\n *\n * @example\n * const imageData = await getImageData('https://cataas.com/cat');\n * const svg = `\n * <svg width=\"100\" height=\"100\" xmlns=\"http://www.w3.org/2000/svg\">\n * <image href=\"${imageData}\" />\n * </svg>\n * `;\n *\n * // Render the SVG in a Snap UI.\n * const ui = image(svg);\n * @param url - The URL to get the image data from.\n * @param options - The options to use when fetching the image data. This is\n * passed directly to `fetch`.\n * @returns A promise that resolves to the image data as a data-string.\n */\nexport async function getImageData(url: string, options?: RequestInit) {\n const blob = await getRawImageData(url, options);\n const bytes = new Uint8Array(await blob.arrayBuffer());\n\n return `data:${blob.type};base64,${bytesToBase64(bytes)}`;\n}\n\n/**\n * Options for getting an SVG image element from a URL.\n *\n * @property width - The width of the image.\n * @property height - The height of the image. If this is not provided, the\n * width will be used as the height.\n * @property request - The options to use when fetching the image data. This is\n * passed directly to `fetch`.\n */\nexport type ImageOptions = {\n width: number;\n height?: number;\n request?: RequestInit;\n};\n\n/**\n * Get an image component from a URL. This is useful for embedding images inside\n * Snap UIs. Only JPEG and PNG images are supported.\n *\n * Note: This function uses `fetch` to get the image data. This means that using\n * it requires the `endowment:network-access` permission.\n *\n * @example\n * const component = await getImage('https://cataas.com/cat');\n *\n * return await snap.request({\n * method: 'snap_dialog',\n * params: {\n * type: 'alert',\n * content: panel([\n * component,\n * ]),\n * },\n * });\n * @param url - The URL to get the image data from.\n * @param options - The options to use when fetching and rendering the image.\n * @param options.width - The width of the image.\n * @param options.height - The height of the image. If this is not provided, the\n * width will be used as the height.\n * @param options.request - The options to use when fetching the image data.\n * This is passed directly to `fetch`.\n * @returns A promise that resolves to the image data as an image component.\n */\nexport async function getImageComponent(\n url: string,\n { width, height = width, request }: ImageOptions,\n) {\n assert(\n typeof width === 'number' && width > 0,\n 'Expected width to be a number greater than 0.',\n );\n\n assert(\n typeof height === 'number' && height > 0,\n 'Expected height to be a number greater than 0.',\n );\n\n const imageData = await getImageData(url, request);\n const size = `width=\"${width}\" height=\"${height}\"`;\n\n return image(\n `<svg ${size.trim()} xmlns=\"http://www.w3.org/2000/svg\"><image ${size.trim()} href=\"${imageData}\" /></svg>`,\n );\n}\n"],"names":["getImageData","getImageComponent","getRawImageData","url","options","fetch","Error","then","response","ok","status","statusText","blob","assert","type","bytes","Uint8Array","arrayBuffer","bytesToBase64","width","height","request","imageData","size","image","trim"],"mappings":";;;;;;;;;;;IA0DsBA,YAAY;eAAZA;;IAkDAC,iBAAiB;eAAjBA;;;uBA5GgB;oBAEhB;AAEtB;;;;;;;CAOC,GACD,eAAeC,gBAAgBC,GAAW,EAAEC,OAAqB;IAC/D,IAAI,OAAOC,UAAU,YAAY;QAC/B,MAAM,IAAIC,MACR,CAAC,iCAAiC,EAAEH,IAAI,0EAA0E,CAAC;IAEvH;IAEA,OAAOE,MAAMF,KAAKC,SAASG,IAAI,CAAC,OAAOC;QACrC,IAAI,CAACA,SAASC,EAAE,EAAE;YAChB,MAAM,IAAIH,MACR,CAAC,iCAAiC,EAAEH,IAAI,GAAG,EAAEK,SAASE,MAAM,CAAC,CAAC,EAAEF,SAASG,UAAU,CAAC,CAAC;QAEzF;QAEA,MAAMC,OAAO,MAAMJ,SAASI,IAAI;QAChCC,IAAAA,aAAM,EACJD,KAAKE,IAAI,KAAK,gBAAgBF,KAAKE,IAAI,KAAK,aAC5C;QAGF,OAAOF;IACT;AACF;AAwBO,eAAeZ,aAAaG,GAAW,EAAEC,OAAqB;IACnE,MAAMQ,OAAO,MAAMV,gBAAgBC,KAAKC;IACxC,MAAMW,QAAQ,IAAIC,WAAW,MAAMJ,KAAKK,WAAW;IAEnD,OAAO,CAAC,KAAK,EAAEL,KAAKE,IAAI,CAAC,QAAQ,EAAEI,IAAAA,oBAAa,EAACH,OAAO,CAAC;AAC3D;AA6CO,eAAed,kBACpBE,GAAW,EACX,EAAEgB,KAAK,EAAEC,SAASD,KAAK,EAAEE,OAAO,EAAgB;IAEhDR,IAAAA,aAAM,EACJ,OAAOM,UAAU,YAAYA,QAAQ,GACrC;IAGFN,IAAAA,aAAM,EACJ,OAAOO,WAAW,YAAYA,SAAS,GACvC;IAGF,MAAME,YAAY,MAAMtB,aAAaG,KAAKkB;IAC1C,MAAME,OAAO,CAAC,OAAO,EAAEJ,MAAM,UAAU,EAAEC,OAAO,CAAC,CAAC;IAElD,OAAOI,IAAAA,SAAK,EACV,CAAC,KAAK,EAAED,KAAKE,IAAI,GAAG,2CAA2C,EAAEF,KAAKE,IAAI,GAAG,OAAO,EAAEH,UAAU,UAAU,CAAC;AAE/G"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// Only internals that are used by other Snaps packages should be exported here.
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
function _export(target, all) {
|
|
7
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: all[name]
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
_export(exports, {
|
|
13
|
-
getErrorData: function() {
|
|
14
|
-
return _internals.getErrorData;
|
|
15
|
-
},
|
|
16
|
-
getErrorMessage: function() {
|
|
17
|
-
return _internals.getErrorMessage;
|
|
18
|
-
},
|
|
19
|
-
getErrorStack: function() {
|
|
20
|
-
return _internals.getErrorStack;
|
|
21
|
-
},
|
|
22
|
-
SNAP_ERROR_CODE: function() {
|
|
23
|
-
return _internals.SNAP_ERROR_CODE;
|
|
24
|
-
},
|
|
25
|
-
SNAP_ERROR_MESSAGE: function() {
|
|
26
|
-
return _internals.SNAP_ERROR_MESSAGE;
|
|
27
|
-
},
|
|
28
|
-
literal: function() {
|
|
29
|
-
return _internals.literal;
|
|
30
|
-
},
|
|
31
|
-
union: function() {
|
|
32
|
-
return _internals.union;
|
|
33
|
-
},
|
|
34
|
-
enumValue: function() {
|
|
35
|
-
return _internals.enumValue;
|
|
36
|
-
},
|
|
37
|
-
assert: function() {
|
|
38
|
-
return _utils.assert;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const _internals = require("./internals");
|
|
42
|
-
const _utils = require("@metamask/utils");
|
|
43
|
-
_export_star(require("./errors"), exports);
|
|
44
|
-
_export_star(require("./error-wrappers"), exports);
|
|
45
|
-
_export_star(require("./images"), exports);
|
|
46
|
-
_export_star(require("./types"), exports);
|
|
47
|
-
_export_star(require("./ui"), exports);
|
|
48
|
-
function _export_star(from, to) {
|
|
49
|
-
Object.keys(from).forEach(function(k) {
|
|
50
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
51
|
-
Object.defineProperty(to, k, {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function() {
|
|
54
|
-
return from[k];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return from;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n literal,\n union,\n enumValue,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\nexport { assert } from '@metamask/utils';\n\nexport * from './errors';\nexport * from './error-wrappers';\nexport * from './images';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","literal","union","enumValue","assert"],"mappings":"AAAA,gFAAgF;;;;;;;;;;;;IAG9EA,YAAY;eAAZA,uBAAY;;IACZC,eAAe;eAAfA,0BAAe;;IACfC,aAAa;eAAbA,wBAAa;;IACbC,eAAe;eAAfA,0BAAe;;IACfC,kBAAkB;eAAlBA,6BAAkB;;IAClBC,OAAO;eAAPA,kBAAO;;IACPC,KAAK;eAALA,gBAAK;;IACLC,SAAS;eAATA,oBAAS;;IAUFC,MAAM;eAANA,aAAM;;;2BATR;uBASgB;qBAET;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createSnapError", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createSnapError;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _errors = require("../errors");
|
|
12
|
-
function createSnapError(fn) {
|
|
13
|
-
return class SnapJsonRpcError extends _errors.SnapError {
|
|
14
|
-
constructor(message, data){
|
|
15
|
-
const error = fn(message);
|
|
16
|
-
super({
|
|
17
|
-
code: error.code,
|
|
18
|
-
message: error.message,
|
|
19
|
-
data
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n constructor(message?: string, data?: Record<string, Json>) {\n const error = fn(message);\n\n super({\n code: error.code,\n message: error.message,\n data,\n });\n }\n };\n}\n"],"names":["createSnapError","fn","SnapJsonRpcError","SnapError","constructor","message","data","error","code"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;wBAfU;AAenB,SAASA,gBAAgBC,EAAwB;IACtD,OAAO,MAAMC,yBAAyBC,iBAAS;QAC7CC,YAAYC,OAAgB,EAAEC,IAA2B,CAAE;YACzD,MAAMC,QAAQN,GAAGI;YAEjB,KAAK,CAAC;gBACJG,MAAMD,MAAMC,IAAI;gBAChBH,SAASE,MAAMF,OAAO;gBACtBC;YACF;QACF;IACF;AACF"}
|