@metamask/snaps-utils 1.0.2 → 2.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 +33 -223
- package/dist/cjs/array.js +23 -0
- package/dist/cjs/array.js.map +1 -0
- package/dist/cjs/caveats.js +36 -0
- package/dist/cjs/caveats.js.map +1 -0
- package/dist/cjs/checksum.js +38 -0
- package/dist/cjs/checksum.js.map +1 -0
- package/dist/cjs/cronjob.js +84 -0
- package/dist/cjs/cronjob.js.map +1 -0
- package/dist/cjs/deep-clone.js +22 -0
- package/dist/cjs/deep-clone.js.map +1 -0
- package/dist/cjs/default-endowments.js +49 -0
- package/dist/cjs/default-endowments.js.map +1 -0
- package/dist/cjs/entropy.js +23 -0
- package/dist/cjs/entropy.js.map +1 -0
- package/dist/cjs/enum.js +16 -0
- package/dist/cjs/enum.js.map +1 -0
- package/dist/cjs/errors.js +19 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/{eval-worker.js → cjs/eval-worker.js} +22 -21
- package/dist/cjs/eval-worker.js.map +1 -0
- package/dist/cjs/eval.js +77 -0
- package/dist/cjs/eval.js.map +1 -0
- package/dist/cjs/fs.js +126 -0
- package/dist/cjs/fs.js.map +1 -0
- package/dist/cjs/handlers.js +80 -0
- package/dist/cjs/handlers.js.map +1 -0
- package/dist/cjs/icon.js +37 -0
- package/dist/cjs/icon.js.map +1 -0
- package/dist/cjs/iframe.js +59 -0
- package/dist/cjs/iframe.js.map +1 -0
- package/dist/cjs/index.browser.js +43 -0
- package/dist/cjs/index.browser.js.map +1 -0
- package/dist/cjs/index.executionenv.js +24 -0
- package/dist/cjs/index.executionenv.js.map +1 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/json-rpc.js +46 -0
- package/dist/cjs/json-rpc.js.map +1 -0
- package/dist/cjs/json.js +16 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/logging.js +40 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/manifest/index.browser.js +20 -0
- package/dist/cjs/manifest/index.browser.js.map +1 -0
- package/dist/cjs/manifest/index.js +21 -0
- package/dist/cjs/manifest/index.js.map +1 -0
- package/dist/cjs/manifest/manifest.js +239 -0
- package/dist/cjs/manifest/manifest.js.map +1 -0
- package/dist/cjs/manifest/validation.js +189 -0
- package/dist/cjs/manifest/validation.js.map +1 -0
- package/dist/cjs/mock.js +128 -0
- package/dist/cjs/mock.js.map +1 -0
- package/dist/cjs/namespace.js +132 -0
- package/dist/cjs/namespace.js.map +1 -0
- package/dist/cjs/npm.js +81 -0
- package/dist/cjs/npm.js.map +1 -0
- package/dist/cjs/path.js +21 -0
- package/dist/cjs/path.js.map +1 -0
- package/dist/cjs/post-process.js +328 -0
- package/dist/cjs/post-process.js.map +1 -0
- package/dist/cjs/snaps.js +230 -0
- package/dist/cjs/snaps.js.map +1 -0
- package/dist/cjs/strings.js +21 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/structs.js +163 -0
- package/dist/cjs/structs.js.map +1 -0
- package/dist/cjs/types.js +109 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validation.js +22 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/cjs/versions.js +47 -0
- package/dist/cjs/versions.js.map +1 -0
- package/dist/cjs/virtual-file/VirtualFile.js +85 -0
- package/dist/cjs/virtual-file/VirtualFile.js.map +1 -0
- package/dist/cjs/virtual-file/index.browser.js +20 -0
- package/dist/cjs/virtual-file/index.browser.js.map +1 -0
- package/dist/cjs/virtual-file/index.js +21 -0
- package/dist/cjs/virtual-file/index.js.map +1 -0
- package/dist/cjs/virtual-file/toVirtualFile.js +33 -0
- package/dist/cjs/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/{array.js → esm/array.js} +3 -7
- package/dist/esm/array.js.map +1 -0
- package/dist/esm/caveats.js +26 -0
- package/dist/esm/caveats.js.map +1 -0
- package/dist/esm/checksum.js +36 -0
- package/dist/esm/checksum.js.map +1 -0
- package/dist/esm/cronjob.js +66 -0
- package/dist/esm/cronjob.js.map +1 -0
- package/dist/esm/deep-clone.js +7 -0
- package/dist/esm/deep-clone.js.map +1 -0
- package/dist/{default-endowments.js → esm/default-endowments.js} +3 -6
- package/dist/esm/default-endowments.js.map +1 -0
- package/dist/esm/entropy.js +6 -0
- package/dist/esm/entropy.js.map +1 -0
- package/dist/esm/enum.js +12 -0
- package/dist/esm/enum.js.map +1 -0
- package/dist/esm/errors.js +17 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/eval-worker.js +47 -0
- package/dist/esm/eval-worker.js.map +1 -0
- package/dist/esm/eval.js +65 -0
- package/dist/esm/eval.js.map +1 -0
- package/dist/{fs.js → esm/fs.js} +33 -56
- package/dist/esm/fs.js.map +1 -0
- package/dist/esm/handlers.js +59 -0
- package/dist/esm/handlers.js.map +1 -0
- package/dist/esm/icon.js +11 -0
- package/dist/esm/icon.js.map +1 -0
- package/dist/{iframe.js → esm/iframe.js} +16 -18
- package/dist/esm/iframe.js.map +1 -0
- package/dist/esm/index.browser.js +26 -0
- package/dist/esm/index.browser.js.map +1 -0
- package/dist/esm/index.executionenv.js +7 -0
- package/dist/esm/index.executionenv.js.map +1 -0
- package/dist/esm/index.js +31 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-rpc.js +39 -0
- package/dist/esm/json-rpc.js.map +1 -0
- package/dist/esm/json.js +17 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/{logging.js → esm/logging.js} +6 -14
- package/dist/esm/logging.js.map +1 -0
- package/dist/esm/manifest/index.browser.js +3 -0
- package/dist/esm/manifest/index.browser.js.map +1 -0
- package/dist/esm/manifest/index.js +4 -0
- package/dist/esm/manifest/index.js.map +1 -0
- package/dist/{manifest → esm/manifest}/manifest.js +101 -115
- package/dist/esm/manifest/manifest.js.map +1 -0
- package/dist/esm/manifest/validation.js +155 -0
- package/dist/esm/manifest/validation.js.map +1 -0
- package/dist/{mock.js → esm/mock.js} +42 -40
- package/dist/esm/mock.js.map +1 -0
- package/dist/esm/namespace.js +112 -0
- package/dist/esm/namespace.js.map +1 -0
- package/dist/esm/npm.js +70 -0
- package/dist/esm/npm.js.map +1 -0
- package/dist/esm/path.js +17 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/{post-process.js → esm/post-process.js} +110 -99
- package/dist/esm/post-process.js.map +1 -0
- package/dist/esm/snaps.js +215 -0
- package/dist/esm/snaps.js.map +1 -0
- package/dist/esm/strings.js +11 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/structs.js +230 -0
- package/dist/esm/structs.js.map +1 -0
- package/dist/esm/types.js +80 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.js +17 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/{versions.js → esm/versions.js} +15 -18
- package/dist/esm/versions.js.map +1 -0
- package/dist/{virtual-file → esm/virtual-file}/VirtualFile.js +47 -33
- package/dist/esm/virtual-file/VirtualFile.js.map +1 -0
- package/dist/esm/virtual-file/index.browser.js +3 -0
- package/dist/esm/virtual-file/index.browser.js.map +1 -0
- package/dist/esm/virtual-file/index.js +4 -0
- package/dist/esm/virtual-file/index.js.map +1 -0
- package/dist/esm/virtual-file/toVirtualFile.js +26 -0
- package/dist/esm/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/{caveats.d.ts → types/caveats.d.ts} +5 -5
- package/dist/{cronjob.d.ts → types/cronjob.d.ts} +1 -1
- package/dist/types/enum.d.ts +30 -0
- package/dist/types/errors.d.ts +10 -0
- package/dist/{eval.d.ts → types/eval.d.ts} +9 -1
- package/dist/{fs.d.ts → types/fs.d.ts} +2 -2
- package/dist/types/handlers.d.ts +196 -0
- package/dist/types/icon.d.ts +4 -0
- package/dist/{iframe.d.ts → types/iframe.d.ts} +3 -2
- package/dist/{index.browser.d.ts → types/index.browser.d.ts} +5 -1
- package/dist/{index.d.ts → types/index.d.ts} +5 -1
- package/dist/{json-rpc.d.ts → types/json-rpc.d.ts} +2 -2
- package/dist/types/json.d.ts +13 -0
- package/dist/{manifest → types/manifest}/manifest.d.ts +6 -4
- package/dist/{manifest → types/manifest}/validation.d.ts +40 -76
- package/dist/types/namespace.d.ts +128 -0
- package/dist/{npm.d.ts → types/npm.d.ts} +2 -3
- package/dist/{snaps.d.ts → types/snaps.d.ts} +17 -9
- package/dist/types/strings.d.ts +8 -0
- package/dist/types/structs.d.ts +158 -0
- package/dist/{types.d.ts → types/types.d.ts} +15 -22
- package/dist/types/validation.d.ts +8 -0
- package/dist/{versions.d.ts → types/versions.d.ts} +1 -1
- package/package.json +66 -46
- package/dist/array.js.map +0 -1
- package/dist/caveats.js +0 -35
- package/dist/caveats.js.map +0 -1
- package/dist/checksum.js +0 -42
- package/dist/checksum.js.map +0 -1
- package/dist/cronjob.js +0 -71
- package/dist/cronjob.js.map +0 -1
- package/dist/deep-clone.js +0 -9
- package/dist/deep-clone.js.map +0 -1
- package/dist/default-endowments.js.map +0 -1
- package/dist/entropy.js +0 -8
- package/dist/entropy.js.map +0 -1
- package/dist/eval-worker.js.map +0 -1
- package/dist/eval.js +0 -27
- package/dist/eval.js.map +0 -1
- package/dist/fs.js.map +0 -1
- package/dist/handlers.d.ts +0 -105
- package/dist/handlers.js +0 -3
- package/dist/handlers.js.map +0 -1
- package/dist/iframe.js.map +0 -1
- package/dist/iframe.test.browser.js +0 -15
- package/dist/iframe.test.browser.js.map +0 -1
- package/dist/index.browser.js +0 -37
- package/dist/index.browser.js.map +0 -1
- package/dist/index.executionenv.js +0 -22
- package/dist/index.executionenv.js.map +0 -1
- package/dist/index.js +0 -42
- package/dist/index.js.map +0 -1
- package/dist/json-rpc.js +0 -46
- package/dist/json-rpc.js.map +0 -1
- package/dist/json.d.ts +0 -9
- package/dist/json.js +0 -18
- package/dist/json.js.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/manifest/index.browser.js +0 -18
- package/dist/manifest/index.browser.js.map +0 -1
- package/dist/manifest/index.js +0 -19
- package/dist/manifest/index.js.map +0 -1
- package/dist/manifest/manifest.js.map +0 -1
- package/dist/manifest/validation.js +0 -141
- package/dist/manifest/validation.js.map +0 -1
- package/dist/mock.js.map +0 -1
- package/dist/namespace.d.ts +0 -275
- package/dist/namespace.js +0 -225
- package/dist/namespace.js.map +0 -1
- package/dist/notification.d.ts +0 -66
- package/dist/notification.js +0 -58
- package/dist/notification.js.map +0 -1
- package/dist/npm.js +0 -74
- package/dist/npm.js.map +0 -1
- package/dist/path.js +0 -21
- package/dist/path.js.map +0 -1
- package/dist/post-process.js.map +0 -1
- package/dist/snaps.js +0 -202
- package/dist/snaps.js.map +0 -1
- package/dist/types.js +0 -103
- package/dist/types.js.map +0 -1
- package/dist/versions.js.map +0 -1
- package/dist/virtual-file/VirtualFile.js.map +0 -1
- package/dist/virtual-file/index.browser.js +0 -18
- package/dist/virtual-file/index.browser.js.map +0 -1
- package/dist/virtual-file/index.js +0 -19
- package/dist/virtual-file/index.js.map +0 -1
- package/dist/virtual-file/toVirtualFile.js +0 -30
- package/dist/virtual-file/toVirtualFile.js.map +0 -1
- /package/dist/{array.d.ts → types/array.d.ts} +0 -0
- /package/dist/{checksum.d.ts → types/checksum.d.ts} +0 -0
- /package/dist/{deep-clone.d.ts → types/deep-clone.d.ts} +0 -0
- /package/dist/{default-endowments.d.ts → types/default-endowments.d.ts} +0 -0
- /package/dist/{entropy.d.ts → types/entropy.d.ts} +0 -0
- /package/dist/{eval-worker.d.ts → types/eval-worker.d.ts} +0 -0
- /package/dist/{iframe.test.browser.d.ts → types/iframe.test.browser.d.ts} +0 -0
- /package/dist/{index.executionenv.d.ts → types/index.executionenv.d.ts} +0 -0
- /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
- /package/dist/{manifest → types/manifest}/index.browser.d.ts +0 -0
- /package/dist/{manifest → types/manifest}/index.d.ts +0 -0
- /package/dist/{mock.d.ts → types/mock.d.ts} +0 -0
- /package/dist/{path.d.ts → types/path.d.ts} +0 -0
- /package/dist/{post-process.d.ts → types/post-process.d.ts} +0 -0
- /package/dist/{virtual-file → types/virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/index.d.ts +0 -0
- /package/dist/{virtual-file → types/virtual-file}/toVirtualFile.d.ts +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Json } from '@metamask/utils';
|
|
1
|
+
import type { Json } from '@metamask/utils';
|
|
2
2
|
import { ProgrammaticallyFixableSnapError } from '../snaps';
|
|
3
|
-
import { SnapFiles } from '../types';
|
|
3
|
+
import type { SnapFiles } from '../types';
|
|
4
4
|
import { VirtualFile } from '../virtual-file';
|
|
5
|
-
import { SnapManifest } from './validation';
|
|
5
|
+
import type { SnapManifest } from './validation';
|
|
6
6
|
/**
|
|
7
7
|
* The result from the `checkManifest` function.
|
|
8
8
|
*
|
|
@@ -23,6 +23,7 @@ export declare type CheckManifestResult = {
|
|
|
23
23
|
warnings: string[];
|
|
24
24
|
errors: string[];
|
|
25
25
|
};
|
|
26
|
+
export declare type WriteFileFunction = (path: string, data: string) => Promise<void>;
|
|
26
27
|
/**
|
|
27
28
|
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
28
29
|
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
@@ -31,10 +32,11 @@ export declare type CheckManifestResult = {
|
|
|
31
32
|
* @param basePath - The path to the folder with the manifest files.
|
|
32
33
|
* @param writeManifest - Whether to write the fixed manifest to disk.
|
|
33
34
|
* @param sourceCode - The source code of the Snap.
|
|
35
|
+
* @param writeFileFn - The function to use to write the manifest to disk.
|
|
34
36
|
* @returns Whether the manifest was updated, and an array of warnings that
|
|
35
37
|
* were encountered during processing of the manifest files.
|
|
36
38
|
*/
|
|
37
|
-
export declare function checkManifest(basePath: string, writeManifest?: boolean, sourceCode?: string): Promise<CheckManifestResult>;
|
|
39
|
+
export declare function checkManifest(basePath: string, writeManifest?: boolean, sourceCode?: string, writeFileFn?: WriteFileFunction): Promise<CheckManifestResult>;
|
|
38
40
|
/**
|
|
39
41
|
* Given the relevant Snap files (manifest, `package.json`, and bundle) and a
|
|
40
42
|
* Snap manifest validation error, fixes the fault in the manifest that caused
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Infer, Struct } from 'superstruct';
|
|
1
|
+
import type { Infer, Struct } from 'superstruct';
|
|
2
2
|
export declare const FORBIDDEN_COIN_TYPES: number[];
|
|
3
3
|
export declare const Bip32PathStruct: Struct<string[], Struct<string, null>>;
|
|
4
|
-
export declare const bip32entropy: <
|
|
4
|
+
export declare const bip32entropy: <Type extends {
|
|
5
5
|
path: string[];
|
|
6
6
|
curve: string;
|
|
7
|
-
},
|
|
7
|
+
}, Schema>(struct: Struct<Type, Schema>) => Struct<Type, Schema>;
|
|
8
8
|
export declare const Bip32EntropyStruct: Struct<{
|
|
9
9
|
path: string[];
|
|
10
10
|
curve: "ed25519" | "secp256k1";
|
|
@@ -29,6 +29,12 @@ export declare const SnapGetBip32EntropyPermissionsStruct: Struct<{
|
|
|
29
29
|
secp256k1: "secp256k1";
|
|
30
30
|
}>;
|
|
31
31
|
}>>;
|
|
32
|
+
export declare const SemVerRangeStruct: Struct<string, null>;
|
|
33
|
+
export declare const SnapIdsStruct: Struct<Record<string, {
|
|
34
|
+
version?: string | undefined;
|
|
35
|
+
}>, null>;
|
|
36
|
+
export declare type SnapIds = Infer<typeof SnapIdsStruct>;
|
|
37
|
+
export declare const ChainIdsStruct: Struct<string[], Struct<string, null>>;
|
|
32
38
|
export declare const PermissionsStruct: Struct<{
|
|
33
39
|
'endowment:long-running'?: {} | undefined;
|
|
34
40
|
'endowment:network-access'?: {} | undefined;
|
|
@@ -51,9 +57,11 @@ export declare const PermissionsStruct: Struct<{
|
|
|
51
57
|
dapps?: boolean | undefined;
|
|
52
58
|
snaps?: boolean | undefined;
|
|
53
59
|
} | undefined;
|
|
60
|
+
'endowment:name-lookup'?: string[] | undefined;
|
|
54
61
|
snap_dialog?: {} | undefined;
|
|
55
62
|
snap_confirm?: {} | undefined;
|
|
56
63
|
snap_manageState?: {} | undefined;
|
|
64
|
+
snap_manageAccounts?: {} | undefined;
|
|
57
65
|
snap_notify?: {} | undefined;
|
|
58
66
|
snap_getBip32Entropy?: {
|
|
59
67
|
path: string[];
|
|
@@ -67,16 +75,9 @@ export declare const PermissionsStruct: Struct<{
|
|
|
67
75
|
coinType: number;
|
|
68
76
|
}[] | undefined;
|
|
69
77
|
snap_getEntropy?: {} | undefined;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
name: string;
|
|
74
|
-
id: string;
|
|
75
|
-
}[];
|
|
76
|
-
methods?: string[] | undefined;
|
|
77
|
-
events?: string[] | undefined;
|
|
78
|
-
}>;
|
|
79
|
-
} | undefined;
|
|
78
|
+
wallet_snap?: Record<string, {
|
|
79
|
+
version?: string | undefined;
|
|
80
|
+
}> | undefined;
|
|
80
81
|
}, {
|
|
81
82
|
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
82
83
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
@@ -135,9 +136,11 @@ export declare const PermissionsStruct: Struct<{
|
|
|
135
136
|
dapps: Struct<boolean | undefined, null>;
|
|
136
137
|
snaps: Struct<boolean | undefined, null>;
|
|
137
138
|
}>;
|
|
139
|
+
'endowment:name-lookup': Struct<string[] | undefined, Struct<string, null>>;
|
|
138
140
|
snap_dialog: Struct<{} | undefined, {}>;
|
|
139
141
|
snap_confirm: Struct<{} | undefined, {}>;
|
|
140
142
|
snap_manageState: Struct<{} | undefined, {}>;
|
|
143
|
+
snap_manageAccounts: Struct<{} | undefined, {}>;
|
|
141
144
|
snap_notify: Struct<{} | undefined, {}>;
|
|
142
145
|
snap_getBip32Entropy: Struct<{
|
|
143
146
|
path: string[];
|
|
@@ -173,25 +176,9 @@ export declare const PermissionsStruct: Struct<{
|
|
|
173
176
|
coinType: Struct<number, null>;
|
|
174
177
|
}>>;
|
|
175
178
|
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
name: string;
|
|
180
|
-
id: string;
|
|
181
|
-
}[];
|
|
182
|
-
methods?: string[] | undefined;
|
|
183
|
-
events?: string[] | undefined;
|
|
184
|
-
}>;
|
|
185
|
-
} | undefined, {
|
|
186
|
-
namespaces: Struct<Record<string, {
|
|
187
|
-
chains: {
|
|
188
|
-
name: string;
|
|
189
|
-
id: string;
|
|
190
|
-
}[];
|
|
191
|
-
methods?: string[] | undefined;
|
|
192
|
-
events?: string[] | undefined;
|
|
193
|
-
}>, null>;
|
|
194
|
-
}>;
|
|
179
|
+
wallet_snap: Struct<Record<string, {
|
|
180
|
+
version?: string | undefined;
|
|
181
|
+
}> | undefined, null>;
|
|
195
182
|
}>;
|
|
196
183
|
export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
|
|
197
184
|
export declare const SnapManifestStruct: Struct<{
|
|
@@ -201,9 +188,9 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
201
188
|
source: {
|
|
202
189
|
location: {
|
|
203
190
|
npm: {
|
|
191
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
204
192
|
filePath: string;
|
|
205
193
|
packageName: string;
|
|
206
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
207
194
|
iconPath?: string | undefined;
|
|
208
195
|
};
|
|
209
196
|
};
|
|
@@ -231,9 +218,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
231
218
|
dapps?: boolean | undefined;
|
|
232
219
|
snaps?: boolean | undefined;
|
|
233
220
|
} | undefined;
|
|
221
|
+
'endowment:name-lookup'?: string[] | undefined;
|
|
234
222
|
snap_dialog?: {} | undefined;
|
|
235
223
|
snap_confirm?: {} | undefined;
|
|
236
224
|
snap_manageState?: {} | undefined;
|
|
225
|
+
snap_manageAccounts?: {} | undefined;
|
|
237
226
|
snap_notify?: {} | undefined;
|
|
238
227
|
snap_getBip32Entropy?: {
|
|
239
228
|
path: string[];
|
|
@@ -247,22 +236,16 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
247
236
|
coinType: number;
|
|
248
237
|
}[] | undefined;
|
|
249
238
|
snap_getEntropy?: {} | undefined;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
name: string;
|
|
254
|
-
id: string;
|
|
255
|
-
}[];
|
|
256
|
-
methods?: string[] | undefined;
|
|
257
|
-
events?: string[] | undefined;
|
|
258
|
-
}>;
|
|
259
|
-
} | undefined;
|
|
239
|
+
wallet_snap?: Record<string, {
|
|
240
|
+
version?: string | undefined;
|
|
241
|
+
}> | undefined;
|
|
260
242
|
};
|
|
261
243
|
manifestVersion: "0.1";
|
|
262
244
|
repository?: {
|
|
263
245
|
type: string;
|
|
264
246
|
url: string;
|
|
265
247
|
} | undefined;
|
|
248
|
+
$schema?: string | undefined;
|
|
266
249
|
}, {
|
|
267
250
|
version: Struct<import("@metamask/utils").SemVerVersion, null>;
|
|
268
251
|
description: Struct<string, null>;
|
|
@@ -277,9 +260,9 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
277
260
|
source: Struct<{
|
|
278
261
|
location: {
|
|
279
262
|
npm: {
|
|
263
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
280
264
|
filePath: string;
|
|
281
265
|
packageName: string;
|
|
282
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
283
266
|
iconPath?: string | undefined;
|
|
284
267
|
};
|
|
285
268
|
};
|
|
@@ -288,16 +271,16 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
288
271
|
shasum: Struct<string, null>;
|
|
289
272
|
location: Struct<{
|
|
290
273
|
npm: {
|
|
274
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
291
275
|
filePath: string;
|
|
292
276
|
packageName: string;
|
|
293
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
294
277
|
iconPath?: string | undefined;
|
|
295
278
|
};
|
|
296
279
|
}, {
|
|
297
280
|
npm: Struct<{
|
|
281
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
298
282
|
filePath: string;
|
|
299
283
|
packageName: string;
|
|
300
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
301
284
|
iconPath?: string | undefined;
|
|
302
285
|
}, {
|
|
303
286
|
filePath: Struct<string, null>;
|
|
@@ -329,9 +312,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
329
312
|
dapps?: boolean | undefined;
|
|
330
313
|
snaps?: boolean | undefined;
|
|
331
314
|
} | undefined;
|
|
315
|
+
'endowment:name-lookup'?: string[] | undefined;
|
|
332
316
|
snap_dialog?: {} | undefined;
|
|
333
317
|
snap_confirm?: {} | undefined;
|
|
334
318
|
snap_manageState?: {} | undefined;
|
|
319
|
+
snap_manageAccounts?: {} | undefined;
|
|
335
320
|
snap_notify?: {} | undefined;
|
|
336
321
|
snap_getBip32Entropy?: {
|
|
337
322
|
path: string[];
|
|
@@ -345,16 +330,9 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
345
330
|
coinType: number;
|
|
346
331
|
}[] | undefined;
|
|
347
332
|
snap_getEntropy?: {} | undefined;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
name: string;
|
|
352
|
-
id: string;
|
|
353
|
-
}[];
|
|
354
|
-
methods?: string[] | undefined;
|
|
355
|
-
events?: string[] | undefined;
|
|
356
|
-
}>;
|
|
357
|
-
} | undefined;
|
|
333
|
+
wallet_snap?: Record<string, {
|
|
334
|
+
version?: string | undefined;
|
|
335
|
+
}> | undefined;
|
|
358
336
|
}, {
|
|
359
337
|
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
360
338
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
@@ -413,9 +391,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
413
391
|
dapps: Struct<boolean | undefined, null>;
|
|
414
392
|
snaps: Struct<boolean | undefined, null>;
|
|
415
393
|
}>;
|
|
394
|
+
'endowment:name-lookup': Struct<string[] | undefined, Struct<string, null>>;
|
|
416
395
|
snap_dialog: Struct<{} | undefined, {}>;
|
|
417
396
|
snap_confirm: Struct<{} | undefined, {}>;
|
|
418
397
|
snap_manageState: Struct<{} | undefined, {}>;
|
|
398
|
+
snap_manageAccounts: Struct<{} | undefined, {}>;
|
|
419
399
|
snap_notify: Struct<{} | undefined, {}>;
|
|
420
400
|
snap_getBip32Entropy: Struct<{
|
|
421
401
|
path: string[];
|
|
@@ -451,27 +431,12 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
451
431
|
coinType: Struct<number, null>;
|
|
452
432
|
}>>;
|
|
453
433
|
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
name: string;
|
|
458
|
-
id: string;
|
|
459
|
-
}[];
|
|
460
|
-
methods?: string[] | undefined;
|
|
461
|
-
events?: string[] | undefined;
|
|
462
|
-
}>;
|
|
463
|
-
} | undefined, {
|
|
464
|
-
namespaces: Struct<Record<string, {
|
|
465
|
-
chains: {
|
|
466
|
-
name: string;
|
|
467
|
-
id: string;
|
|
468
|
-
}[];
|
|
469
|
-
methods?: string[] | undefined;
|
|
470
|
-
events?: string[] | undefined;
|
|
471
|
-
}>, null>;
|
|
472
|
-
}>;
|
|
434
|
+
wallet_snap: Struct<Record<string, {
|
|
435
|
+
version?: string | undefined;
|
|
436
|
+
}> | undefined, null>;
|
|
473
437
|
}>;
|
|
474
438
|
manifestVersion: Struct<"0.1", "0.1">;
|
|
439
|
+
$schema: Struct<string | undefined, null>;
|
|
475
440
|
}>;
|
|
476
441
|
export declare type SnapManifest = Infer<typeof SnapManifestStruct>;
|
|
477
442
|
/**
|
|
@@ -491,7 +456,6 @@ export declare function assertIsSnapManifest(value: unknown): asserts value is S
|
|
|
491
456
|
/**
|
|
492
457
|
* Creates a {@link SnapManifest} object from JSON.
|
|
493
458
|
*
|
|
494
|
-
*
|
|
495
459
|
* @param value - The value to check.
|
|
496
460
|
* @throws If the value cannot be coerced to a {@link SnapManifest} object.
|
|
497
461
|
* @returns The created {@link SnapManifest} object.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Infer } from 'superstruct';
|
|
2
|
+
export declare const CHAIN_ID_REGEX: RegExp;
|
|
3
|
+
export declare const ACCOUNT_ID_REGEX: RegExp;
|
|
4
|
+
export declare const ACCOUNT_ADDRESS_REGEX: RegExp;
|
|
5
|
+
/**
|
|
6
|
+
* Parse a chain ID string to an object containing the namespace and reference.
|
|
7
|
+
* This validates the chain ID before parsing it.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain ID to validate and parse.
|
|
10
|
+
* @returns The parsed chain ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseChainId(chainId: ChainId): {
|
|
13
|
+
namespace: NamespaceId;
|
|
14
|
+
reference: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parse an account ID to an object containing the chain, chain ID and address.
|
|
18
|
+
* This validates the account ID before parsing it.
|
|
19
|
+
*
|
|
20
|
+
* @param accountId - The account ID to validate and parse.
|
|
21
|
+
* @returns The parsed account ID.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseAccountId(accountId: AccountId): {
|
|
24
|
+
chain: {
|
|
25
|
+
namespace: NamespaceId;
|
|
26
|
+
reference: string;
|
|
27
|
+
};
|
|
28
|
+
chainId: ChainId;
|
|
29
|
+
address: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A helper struct for a string with a minimum length of 1 and a maximum length
|
|
33
|
+
* of 40.
|
|
34
|
+
*/
|
|
35
|
+
export declare const LimitedString: import("superstruct").Struct<string, null>;
|
|
36
|
+
/**
|
|
37
|
+
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ChainIdStruct: import("superstruct").Struct<string, null>;
|
|
40
|
+
export declare type ChainId = `${string}:${string}`;
|
|
41
|
+
export declare type Caip2ChainId = Infer<typeof ChainIdStruct>;
|
|
42
|
+
export declare const AccountIdStruct: import("superstruct").Struct<string, null>;
|
|
43
|
+
export declare type AccountId = `${ChainId}:${string}`;
|
|
44
|
+
export declare const AccountIdArrayStruct: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
|
|
45
|
+
export declare const AccountAddressStruct: import("superstruct").Struct<string, null>;
|
|
46
|
+
export declare type AccountAddress = Infer<typeof AccountAddressStruct>;
|
|
47
|
+
/**
|
|
48
|
+
* A chain descriptor.
|
|
49
|
+
*/
|
|
50
|
+
export declare const ChainStruct: import("superstruct").Struct<{
|
|
51
|
+
name: string;
|
|
52
|
+
id: string;
|
|
53
|
+
}, {
|
|
54
|
+
id: import("superstruct").Struct<string, null>;
|
|
55
|
+
name: import("superstruct").Struct<string, null>;
|
|
56
|
+
}>;
|
|
57
|
+
export declare type Chain = Infer<typeof ChainStruct>;
|
|
58
|
+
export declare const NamespaceStruct: import("superstruct").Struct<{
|
|
59
|
+
chains: {
|
|
60
|
+
name: string;
|
|
61
|
+
id: string;
|
|
62
|
+
}[];
|
|
63
|
+
methods?: string[] | undefined;
|
|
64
|
+
events?: string[] | undefined;
|
|
65
|
+
}, {
|
|
66
|
+
/**
|
|
67
|
+
* A list of supported chains in the namespace.
|
|
68
|
+
*/
|
|
69
|
+
chains: import("superstruct").Struct<{
|
|
70
|
+
name: string;
|
|
71
|
+
id: string;
|
|
72
|
+
}[], import("superstruct").Struct<{
|
|
73
|
+
name: string;
|
|
74
|
+
id: string;
|
|
75
|
+
}, {
|
|
76
|
+
id: import("superstruct").Struct<string, null>;
|
|
77
|
+
name: import("superstruct").Struct<string, null>;
|
|
78
|
+
}>>;
|
|
79
|
+
/**
|
|
80
|
+
* A list of supported RPC methods on the namespace, that a DApp can call.
|
|
81
|
+
*/
|
|
82
|
+
methods: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
|
|
83
|
+
/**
|
|
84
|
+
* A list of supported RPC events on the namespace, that a DApp can listen to.
|
|
85
|
+
*/
|
|
86
|
+
events: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
|
|
87
|
+
}>;
|
|
88
|
+
export declare type Namespace = Infer<typeof NamespaceStruct>;
|
|
89
|
+
/**
|
|
90
|
+
* A CAIP-2 namespace, i.e., the first part of a chain ID.
|
|
91
|
+
*/
|
|
92
|
+
export declare const NamespaceIdStruct: import("superstruct").Struct<string, null>;
|
|
93
|
+
export declare type NamespaceId = Infer<typeof NamespaceIdStruct>;
|
|
94
|
+
/**
|
|
95
|
+
* Check if the given value is a CAIP-2 namespace ID.
|
|
96
|
+
*
|
|
97
|
+
* @param value - The value to check.
|
|
98
|
+
* @returns Whether the value is a CAIP-2 namespace ID.
|
|
99
|
+
*/
|
|
100
|
+
export declare function isNamespaceId(value: unknown): value is NamespaceId;
|
|
101
|
+
/**
|
|
102
|
+
* Check if the given value is a CAIP-2 chain ID.
|
|
103
|
+
*
|
|
104
|
+
* @param value - The value to check.
|
|
105
|
+
* @returns Whether the value is a CAIP-2 chain ID.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isChainId(value: unknown): value is ChainId;
|
|
108
|
+
/**
|
|
109
|
+
* Check if the given value is a CAIP-10 account ID.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to check.
|
|
112
|
+
* @returns Whether the value is a CAIP-10 account ID.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isAccountId(value: unknown): value is AccountId;
|
|
115
|
+
/**
|
|
116
|
+
* Check if the given value is an array of CAIP-10 account IDs.
|
|
117
|
+
*
|
|
118
|
+
* @param value - The value to check.
|
|
119
|
+
* @returns Whether the value is an array of CAIP-10 account IDs.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isAccountIdArray(value: unknown): value is AccountId[];
|
|
122
|
+
/**
|
|
123
|
+
* Check if a value is a {@link Namespace}.
|
|
124
|
+
*
|
|
125
|
+
* @param value - The value to validate.
|
|
126
|
+
* @returns True if the value is a valid {@link Namespace}.
|
|
127
|
+
*/
|
|
128
|
+
export declare function isNamespace(value: unknown): value is Namespace;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const SVG_MAX_BYTE_SIZE_TEXT: string;
|
|
1
|
+
import type { SnapFiles, UnvalidatedSnapFiles } from './types';
|
|
2
|
+
import { NpmSnapFileNames } from './types';
|
|
4
3
|
export declare const EXPECTED_SNAP_FILES: readonly ["manifest", "packageJson", "sourceCode"];
|
|
5
4
|
export declare const SnapFileNameFromKey: {
|
|
6
5
|
readonly manifest: NpmSnapFileNames.Manifest;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { SubjectPermissions, PermissionConstraint } from '@metamask/permission-controller';
|
|
2
|
-
import { BlockReason } from '@metamask/snaps-registry';
|
|
3
|
-
import { Json, SemVerVersion, Opaque } from '@metamask/utils';
|
|
4
|
-
import { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes';
|
|
5
|
-
import { Struct } from 'superstruct';
|
|
6
|
-
import { SnapManifest, SnapPermissions } from './manifest/validation';
|
|
7
|
-
import { SnapFiles, SnapId,
|
|
1
|
+
import type { SubjectPermissions, PermissionConstraint } from '@metamask/permission-controller';
|
|
2
|
+
import type { BlockReason } from '@metamask/snaps-registry';
|
|
3
|
+
import type { Json, SemVerVersion, Opaque } from '@metamask/utils';
|
|
4
|
+
import type { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes';
|
|
5
|
+
import type { Struct } from 'superstruct';
|
|
6
|
+
import type { SnapManifest, SnapPermissions } from './manifest/validation';
|
|
7
|
+
import type { SnapFiles, SnapId, SnapsPermissionRequest } from './types';
|
|
8
|
+
import { SnapIdPrefixes, SnapValidationFailureReason } from './types';
|
|
8
9
|
export declare const PROPOSED_NAME_REGEX: RegExp;
|
|
9
10
|
/**
|
|
10
11
|
* wallet_enable / wallet_installSnaps permission typing.
|
|
@@ -28,7 +29,7 @@ export declare enum SnapStatusEvents {
|
|
|
28
29
|
Update = "UPDATE"
|
|
29
30
|
}
|
|
30
31
|
export declare type StatusContext = {
|
|
31
|
-
snapId:
|
|
32
|
+
snapId: ValidatedSnapId;
|
|
32
33
|
};
|
|
33
34
|
export declare type StatusEvents = {
|
|
34
35
|
type: SnapStatusEvents;
|
|
@@ -55,7 +56,7 @@ export declare type Snap = {
|
|
|
55
56
|
/**
|
|
56
57
|
* The ID of the Snap.
|
|
57
58
|
*/
|
|
58
|
-
id:
|
|
59
|
+
id: ValidatedSnapId;
|
|
59
60
|
/**
|
|
60
61
|
* The initial permissions of the Snap, which will be requested when it is
|
|
61
62
|
* installed.
|
|
@@ -139,6 +140,13 @@ declare const snapIdSymbol: unique symbol;
|
|
|
139
140
|
* @returns The snap prefix from a snap id, e.g. `npm:`.
|
|
140
141
|
*/
|
|
141
142
|
export declare function getSnapPrefix(snapId: string): SnapIdPrefixes;
|
|
143
|
+
/**
|
|
144
|
+
* Strips snap prefix from a full snap ID.
|
|
145
|
+
*
|
|
146
|
+
* @param snapId - The snap ID to strip.
|
|
147
|
+
* @returns The stripped snap ID.
|
|
148
|
+
*/
|
|
149
|
+
export declare function stripSnapPrefix(snapId: string): string;
|
|
142
150
|
/**
|
|
143
151
|
* Assert that the given value is a valid snap ID.
|
|
144
152
|
*
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indent a message by adding a number of spaces to the beginning of each line.
|
|
3
|
+
*
|
|
4
|
+
* @param message - The message to indent.
|
|
5
|
+
* @param spaces - The number of spaces to indent by. Defaults to 2.
|
|
6
|
+
* @returns The indented message.
|
|
7
|
+
*/
|
|
8
|
+
export declare function indent(message: string, spaces?: number): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Failure, Infer } from 'superstruct';
|
|
2
|
+
import { Struct, StructError } from 'superstruct';
|
|
3
|
+
import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
|
|
4
|
+
/**
|
|
5
|
+
* A wrapper of `superstruct`'s `literal` struct that also defines the name of
|
|
6
|
+
* the struct as the literal value.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for improving the error messages returned by `superstruct`.
|
|
9
|
+
* For example, instead of returning an error like:
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* Expected the value to satisfy a union of `literal | literal`, but received: \"baz\"
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* This struct will return an error like:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* Expected the value to satisfy a union of `"foo" | "bar"`, but received: \"baz\"
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param value - The literal value.
|
|
22
|
+
* @returns The `superstruct` struct, which validates that the value is equal
|
|
23
|
+
* to the literal value.
|
|
24
|
+
*/
|
|
25
|
+
export declare function literal<Type extends string | number | boolean>(value: Type): Struct<Type, null>;
|
|
26
|
+
/**
|
|
27
|
+
* A wrapper of `superstruct`'s `union` struct that also defines the schema as
|
|
28
|
+
* the union of the schemas of the structs.
|
|
29
|
+
*
|
|
30
|
+
* This is useful for improving the error messages returned by `superstruct`.
|
|
31
|
+
*
|
|
32
|
+
* @param structs - The structs to union.
|
|
33
|
+
* @param structs."0" - The first struct.
|
|
34
|
+
* @param structs."1" - The remaining structs.
|
|
35
|
+
* @returns The `superstruct` struct, which validates that the value satisfies
|
|
36
|
+
* one of the structs.
|
|
37
|
+
*/
|
|
38
|
+
export declare function union<Head extends AnyStruct, Tail extends AnyStruct[]>([head, ...tail]: [head: Head, ...tail: Tail]): Struct<Infer<Head> | InferStructTuple<Tail>[number], [
|
|
39
|
+
head: Head,
|
|
40
|
+
...tail: Tail
|
|
41
|
+
]>;
|
|
42
|
+
/**
|
|
43
|
+
* A wrapper of `superstruct`'s `string` struct that coerces a value to a string
|
|
44
|
+
* and resolves it relative to the current working directory. This is useful
|
|
45
|
+
* for specifying file paths in a configuration file, as it allows the user to
|
|
46
|
+
* use both relative and absolute paths.
|
|
47
|
+
*
|
|
48
|
+
* @returns The `superstruct` struct, which validates that the value is a
|
|
49
|
+
* string, and resolves it relative to the current working directory.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const config = struct({
|
|
53
|
+
* file: file(),
|
|
54
|
+
* // ...
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* const value = create({ file: 'path/to/file' }, config);
|
|
58
|
+
* console.log(value.file); // /process/cwd/path/to/file
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function file(): Struct<string, null>;
|
|
62
|
+
/**
|
|
63
|
+
* Define a struct, and also define the name of the struct as the given name.
|
|
64
|
+
*
|
|
65
|
+
* This is useful for improving the error messages returned by `superstruct`.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The name of the struct.
|
|
68
|
+
* @param struct - The struct.
|
|
69
|
+
* @returns The struct.
|
|
70
|
+
*/
|
|
71
|
+
export declare function named<Type, Schema>(name: string, struct: Struct<Type, Schema>): Struct<Type, Schema>;
|
|
72
|
+
export declare class SnapsStructError<Type, Schema> extends StructError {
|
|
73
|
+
constructor(struct: Struct<Type, Schema>, prefix: string, suffix: string, failure: StructError, failures: () => Generator<Failure>);
|
|
74
|
+
}
|
|
75
|
+
declare type GetErrorOptions<Type, Schema> = {
|
|
76
|
+
struct: Struct<Type, Schema>;
|
|
77
|
+
prefix: string;
|
|
78
|
+
suffix?: string;
|
|
79
|
+
error: StructError;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Converts an array to a generator function that yields the items in the
|
|
83
|
+
* array.
|
|
84
|
+
*
|
|
85
|
+
* @param array - The array.
|
|
86
|
+
* @returns A generator function.
|
|
87
|
+
* @yields The items in the array.
|
|
88
|
+
*/
|
|
89
|
+
export declare function arrayToGenerator<Type>(array: Type[]): Generator<Type, void, undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns a `SnapsStructError` with the given prefix and suffix.
|
|
92
|
+
*
|
|
93
|
+
* @param options - The options.
|
|
94
|
+
* @param options.struct - The struct that caused the error.
|
|
95
|
+
* @param options.prefix - The prefix to add to the error message.
|
|
96
|
+
* @param options.suffix - The suffix to add to the error message. Defaults to
|
|
97
|
+
* an empty string.
|
|
98
|
+
* @param options.error - The `superstruct` error to wrap.
|
|
99
|
+
* @returns The `SnapsStructError`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getError<Type, Schema>({ struct, prefix, suffix, error, }: GetErrorOptions<Type, Schema>): SnapsStructError<Type, Schema>;
|
|
102
|
+
/**
|
|
103
|
+
* A wrapper of `superstruct`'s `create` function that throws a
|
|
104
|
+
* `SnapsStructError` instead of a `StructError`. This is useful for improving
|
|
105
|
+
* the error messages returned by `superstruct`.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The value to validate.
|
|
108
|
+
* @param struct - The `superstruct` struct to validate the value against.
|
|
109
|
+
* @param prefix - The prefix to add to the error message.
|
|
110
|
+
* @param suffix - The suffix to add to the error message. Defaults to an empty
|
|
111
|
+
* string.
|
|
112
|
+
* @returns The validated value.
|
|
113
|
+
*/
|
|
114
|
+
export declare function createFromStruct<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, prefix: string, suffix?: string): Type;
|
|
115
|
+
/**
|
|
116
|
+
* Get a struct from a failure path.
|
|
117
|
+
*
|
|
118
|
+
* @param struct - The struct.
|
|
119
|
+
* @param path - The failure path.
|
|
120
|
+
* @returns The struct at the failure path.
|
|
121
|
+
*/
|
|
122
|
+
export declare function getStructFromPath<Type, Schema>(struct: Struct<Type, Schema>, path: string[]): AnyStruct;
|
|
123
|
+
/**
|
|
124
|
+
* Get the union struct names from a struct.
|
|
125
|
+
*
|
|
126
|
+
* @param struct - The struct.
|
|
127
|
+
* @returns The union struct names, or `null` if the struct is not a union
|
|
128
|
+
* struct.
|
|
129
|
+
*/
|
|
130
|
+
export declare function getUnionStructNames<Type, Schema>(struct: Struct<Type, Schema>): string[] | null;
|
|
131
|
+
/**
|
|
132
|
+
* Get a error prefix from a `superstruct` failure. This is useful for
|
|
133
|
+
* formatting the error message returned by `superstruct`.
|
|
134
|
+
*
|
|
135
|
+
* @param failure - The `superstruct` failure.
|
|
136
|
+
* @returns The error prefix.
|
|
137
|
+
*/
|
|
138
|
+
export declare function getStructErrorPrefix(failure: Failure): string;
|
|
139
|
+
/**
|
|
140
|
+
* Get a string describing the failure. This is similar to the `message`
|
|
141
|
+
* property of `superstruct`'s `Failure` type, but formats the value in a more
|
|
142
|
+
* readable way.
|
|
143
|
+
*
|
|
144
|
+
* @param struct - The struct that caused the failure.
|
|
145
|
+
* @param failure - The `superstruct` failure.
|
|
146
|
+
* @returns A string describing the failure.
|
|
147
|
+
*/
|
|
148
|
+
export declare function getStructFailureMessage<Type, Schema>(struct: Struct<Type, Schema>, failure: Failure): string;
|
|
149
|
+
/**
|
|
150
|
+
* Get a string describing the errors. This formats all the errors in a
|
|
151
|
+
* human-readable way.
|
|
152
|
+
*
|
|
153
|
+
* @param struct - The struct that caused the failures.
|
|
154
|
+
* @param failures - The `superstruct` failures.
|
|
155
|
+
* @returns A string describing the errors.
|
|
156
|
+
*/
|
|
157
|
+
export declare function getStructErrorMessage<Type, Schema>(struct: Struct<Type, Schema>, failures: Failure[]): string;
|
|
158
|
+
export {};
|