@metamask/snaps-execution-environments 6.12.0 → 6.14.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/browserify/iframe/bundle.js +3 -3
- package/dist/browserify/node-process/bundle.js +3 -3
- package/dist/browserify/node-thread/bundle.js +3 -3
- package/dist/browserify/webview/index.html +3 -3
- package/dist/browserify/worker-executor/bundle.js +3 -3
- package/dist/browserify/worker-pool/bundle.js +1 -1
- package/dist/common/commands.cjs +15 -0
- package/dist/common/commands.cjs.map +1 -1
- package/dist/common/commands.d.cts.map +1 -1
- package/dist/common/commands.d.mts.map +1 -1
- package/dist/common/commands.mjs +16 -1
- package/dist/common/commands.mjs.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.cjs +2 -0
- package/dist/common/endowments/commonEndowmentFactory.cjs.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.d.cts.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.d.mts.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.mjs +2 -0
- package/dist/common/endowments/commonEndowmentFactory.mjs.map +1 -1
- package/dist/common/validation.cjs +50 -1
- package/dist/common/validation.cjs.map +1 -1
- package/dist/common/validation.d.cts +86 -30
- package/dist/common/validation.d.cts.map +1 -1
- package/dist/common/validation.d.mts +86 -30
- package/dist/common/validation.d.mts.map +1 -1
- package/dist/common/validation.mjs +48 -2
- package/dist/common/validation.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { HandlerType } from "@metamask/snaps-utils";
|
|
2
|
-
import type { Infer } from "@metamask/superstruct";
|
|
3
|
-
import type { Json, JsonRpcSuccess } from "@metamask/utils";
|
|
4
|
-
export declare const JsonRpcRequestWithoutIdStruct:
|
|
2
|
+
import type { Infer, Struct } from "@metamask/superstruct";
|
|
3
|
+
import type { CaipChainId, Json, JsonRpcRequest, JsonRpcSuccess } from "@metamask/utils";
|
|
4
|
+
export declare const JsonRpcRequestWithoutIdStruct: Struct<{
|
|
5
5
|
method: string;
|
|
6
6
|
id?: string | number | null | undefined;
|
|
7
7
|
jsonrpc?: "2.0" | undefined;
|
|
8
8
|
params?: Record<string, Json> | Json[] | undefined;
|
|
9
9
|
}, {
|
|
10
|
-
jsonrpc:
|
|
11
|
-
id:
|
|
12
|
-
method:
|
|
13
|
-
params:
|
|
10
|
+
jsonrpc: Struct<"2.0" | undefined, "2.0">;
|
|
11
|
+
id: Struct<string | number | null | undefined, null>;
|
|
12
|
+
method: Struct<string, null>;
|
|
13
|
+
params: Struct<Record<string, Json> | Json[] | undefined, null>;
|
|
14
14
|
}>;
|
|
15
15
|
export type JsonRpcRequestWithoutId = Infer<typeof JsonRpcRequestWithoutIdStruct>;
|
|
16
|
-
export declare const EndowmentStruct:
|
|
16
|
+
export declare const EndowmentStruct: Struct<string, null>;
|
|
17
17
|
export type Endowment = Infer<typeof EndowmentStruct>;
|
|
18
18
|
/**
|
|
19
19
|
* Check if the given value is an endowment.
|
|
@@ -29,10 +29,10 @@ export declare function isEndowment(value: unknown): value is Endowment;
|
|
|
29
29
|
* @returns Whether the value is an array of endowments.
|
|
30
30
|
*/
|
|
31
31
|
export declare function isEndowmentsArray(value: unknown): value is Endowment[];
|
|
32
|
-
export declare const PingRequestArgumentsStruct:
|
|
33
|
-
export declare const TerminateRequestArgumentsStruct:
|
|
34
|
-
export declare const ExecuteSnapRequestArgumentsStruct:
|
|
35
|
-
export declare const SnapRpcRequestArgumentsStruct:
|
|
32
|
+
export declare const PingRequestArgumentsStruct: Struct<unknown[] | undefined, null>;
|
|
33
|
+
export declare const TerminateRequestArgumentsStruct: Struct<unknown[] | undefined, null>;
|
|
34
|
+
export declare const ExecuteSnapRequestArgumentsStruct: Struct<[string, string, string[]], null>;
|
|
35
|
+
export declare const SnapRpcRequestArgumentsStruct: Struct<[string, HandlerType, string, {
|
|
36
36
|
method: string;
|
|
37
37
|
id?: string | number | null | undefined;
|
|
38
38
|
jsonrpc?: "2.0" | undefined;
|
|
@@ -43,14 +43,14 @@ export type TerminateRequestArguments = Infer<typeof TerminateRequestArgumentsSt
|
|
|
43
43
|
export type ExecuteSnapRequestArguments = Infer<typeof ExecuteSnapRequestArgumentsStruct>;
|
|
44
44
|
export type SnapRpcRequestArguments = Infer<typeof SnapRpcRequestArgumentsStruct>;
|
|
45
45
|
export type RequestArguments = PingRequestArguments | TerminateRequestArguments | ExecuteSnapRequestArguments | SnapRpcRequestArguments;
|
|
46
|
-
export declare const OnTransactionRequestArgumentsStruct:
|
|
46
|
+
export declare const OnTransactionRequestArgumentsStruct: Struct<{
|
|
47
47
|
chainId: `${string}:${string}`;
|
|
48
48
|
transactionOrigin: string | null;
|
|
49
49
|
transaction: Record<string, Json>;
|
|
50
50
|
}, {
|
|
51
|
-
transaction:
|
|
52
|
-
chainId:
|
|
53
|
-
transactionOrigin:
|
|
51
|
+
transaction: Struct<Record<string, Json>, null>;
|
|
52
|
+
chainId: Struct<`${string}:${string}`, null>;
|
|
53
|
+
transactionOrigin: Struct<string | null, null>;
|
|
54
54
|
}>;
|
|
55
55
|
export type OnTransactionRequestArguments = Infer<typeof OnTransactionRequestArgumentsStruct>;
|
|
56
56
|
/**
|
|
@@ -62,12 +62,12 @@ export type OnTransactionRequestArguments = Infer<typeof OnTransactionRequestArg
|
|
|
62
62
|
* object.
|
|
63
63
|
*/
|
|
64
64
|
export declare function assertIsOnTransactionRequestArguments(value: unknown): asserts value is OnTransactionRequestArguments;
|
|
65
|
-
export declare const OnSignatureRequestArgumentsStruct:
|
|
65
|
+
export declare const OnSignatureRequestArgumentsStruct: Struct<{
|
|
66
66
|
signatureOrigin: string | null;
|
|
67
67
|
signature: Record<string, Json>;
|
|
68
68
|
}, {
|
|
69
|
-
signature:
|
|
70
|
-
signatureOrigin:
|
|
69
|
+
signature: Struct<Record<string, Json>, null>;
|
|
70
|
+
signatureOrigin: Struct<string | null, null>;
|
|
71
71
|
}>;
|
|
72
72
|
export type OnSignatureRequestArguments = Infer<typeof OnSignatureRequestArgumentsStruct>;
|
|
73
73
|
/**
|
|
@@ -80,9 +80,9 @@ export type OnSignatureRequestArguments = Infer<typeof OnSignatureRequestArgumen
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function assertIsOnSignatureRequestArguments(value: unknown): asserts value is OnSignatureRequestArguments;
|
|
82
82
|
declare const baseNameLookupArgs: {
|
|
83
|
-
chainId:
|
|
83
|
+
chainId: Struct<`${string}:${string}`, null>;
|
|
84
84
|
};
|
|
85
|
-
export declare const OnNameLookupRequestArgumentsStruct:
|
|
85
|
+
export declare const OnNameLookupRequestArgumentsStruct: Struct<{
|
|
86
86
|
address: string;
|
|
87
87
|
chainId: `${string}:${string}`;
|
|
88
88
|
} | {
|
|
@@ -103,7 +103,49 @@ export type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {
|
|
|
103
103
|
* object.
|
|
104
104
|
*/
|
|
105
105
|
export declare function assertIsOnNameLookupRequestArguments(value: unknown): asserts value is OnNameLookupRequestArguments;
|
|
106
|
-
export declare const
|
|
106
|
+
export declare const OnAssetsLookupRequestArgumentsStruct: Struct<{
|
|
107
|
+
assets: `${string}:${string}/${string}:${string}`[];
|
|
108
|
+
}, {
|
|
109
|
+
assets: Struct<`${string}:${string}/${string}:${string}`[], Struct<`${string}:${string}/${string}:${string}`, null>>;
|
|
110
|
+
}>;
|
|
111
|
+
export type OnAssetsLookupRequestArguments = Infer<typeof OnAssetsLookupRequestArgumentsStruct>;
|
|
112
|
+
/**
|
|
113
|
+
* Asserts that the given value is a valid {@link OnAssetsLookupRequestArguments}
|
|
114
|
+
* object.
|
|
115
|
+
*
|
|
116
|
+
* @param value - The value to validate.
|
|
117
|
+
* @throws If the value is not a valid {@link OnAssetsLookupRequestArguments}
|
|
118
|
+
* object.
|
|
119
|
+
*/
|
|
120
|
+
export declare function assertIsOnAssetsLookupRequestArguments(value: unknown): asserts value is OnAssetsLookupRequestArguments;
|
|
121
|
+
export declare const OnAssetsConversionRequestArgumentsStruct: Struct<{
|
|
122
|
+
conversions: {
|
|
123
|
+
from: `${string}:${string}/${string}:${string}`;
|
|
124
|
+
to: `${string}:${string}/${string}:${string}`;
|
|
125
|
+
}[];
|
|
126
|
+
}, {
|
|
127
|
+
conversions: Struct<{
|
|
128
|
+
from: `${string}:${string}/${string}:${string}`;
|
|
129
|
+
to: `${string}:${string}/${string}:${string}`;
|
|
130
|
+
}[], Struct<{
|
|
131
|
+
from: `${string}:${string}/${string}:${string}`;
|
|
132
|
+
to: `${string}:${string}/${string}:${string}`;
|
|
133
|
+
}, {
|
|
134
|
+
from: Struct<`${string}:${string}/${string}:${string}`, null>;
|
|
135
|
+
to: Struct<`${string}:${string}/${string}:${string}`, null>;
|
|
136
|
+
}>>;
|
|
137
|
+
}>;
|
|
138
|
+
export type OnAssetsConversionRequestArguments = Infer<typeof OnAssetsConversionRequestArgumentsStruct>;
|
|
139
|
+
/**
|
|
140
|
+
* Asserts that the given value is a valid {@link OnAssetsConversionRequestArguments}
|
|
141
|
+
* object.
|
|
142
|
+
*
|
|
143
|
+
* @param value - The value to validate.
|
|
144
|
+
* @throws If the value is not a valid {@link OnNameLookupRequestArguments}
|
|
145
|
+
* object.
|
|
146
|
+
*/
|
|
147
|
+
export declare function assertIsOnAssetsConversionRequestArguments(value: unknown): asserts value is OnAssetsConversionRequestArguments;
|
|
148
|
+
export declare const OnUserInputArgumentsStruct: Struct<{
|
|
107
149
|
id: string;
|
|
108
150
|
event: {
|
|
109
151
|
type: import("@metamask/snaps-sdk").UserInputEventType.ButtonClickEvent;
|
|
@@ -133,8 +175,8 @@ export declare const OnUserInputArgumentsStruct: import("@metamask/superstruct")
|
|
|
133
175
|
};
|
|
134
176
|
context?: Record<string, Json> | null | undefined;
|
|
135
177
|
}, {
|
|
136
|
-
id:
|
|
137
|
-
event:
|
|
178
|
+
id: Struct<string, null>;
|
|
179
|
+
event: Struct<{
|
|
138
180
|
type: import("@metamask/snaps-sdk").UserInputEventType.ButtonClickEvent;
|
|
139
181
|
name?: string | undefined;
|
|
140
182
|
} | {
|
|
@@ -160,7 +202,7 @@ export declare const OnUserInputArgumentsStruct: import("@metamask/superstruct")
|
|
|
160
202
|
} | null;
|
|
161
203
|
name: string;
|
|
162
204
|
}, null>;
|
|
163
|
-
context:
|
|
205
|
+
context: Struct<Record<string, Json> | null | undefined, null>;
|
|
164
206
|
}>;
|
|
165
207
|
export type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;
|
|
166
208
|
/**
|
|
@@ -172,16 +214,30 @@ export type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;
|
|
|
172
214
|
* object.
|
|
173
215
|
*/
|
|
174
216
|
export declare function assertIsOnUserInputRequestArguments(value: unknown): asserts value is OnUserInputArguments;
|
|
175
|
-
declare const
|
|
217
|
+
export declare const OnProtocolRequestArgumentsStruct: Struct<{
|
|
218
|
+
scope: CaipChainId;
|
|
219
|
+
request: JsonRpcRequest;
|
|
220
|
+
}, null>;
|
|
221
|
+
export type OnProtocolRequestArguments = Infer<typeof OnProtocolRequestArgumentsStruct>;
|
|
222
|
+
/**
|
|
223
|
+
* Asserts that the given value is a valid {@link OnProtocolRequestArguments}
|
|
224
|
+
* object.
|
|
225
|
+
*
|
|
226
|
+
* @param value - The value to validate.
|
|
227
|
+
* @throws If the value is not a valid {@link OnProtocolRequestArguments}
|
|
228
|
+
* object.
|
|
229
|
+
*/
|
|
230
|
+
export declare function assertIsOnProtocolRequestArguments(value: unknown): asserts value is OnProtocolRequestArguments;
|
|
231
|
+
declare const OkResponseStruct: Struct<{
|
|
176
232
|
id: string | number | null;
|
|
177
233
|
result: "OK";
|
|
178
234
|
jsonrpc: "2.0";
|
|
179
235
|
}, {
|
|
180
|
-
id:
|
|
181
|
-
jsonrpc:
|
|
182
|
-
result:
|
|
236
|
+
id: Struct<string | number | null, null>;
|
|
237
|
+
jsonrpc: Struct<"2.0", "2.0">;
|
|
238
|
+
result: Struct<"OK", "OK">;
|
|
183
239
|
}>;
|
|
184
|
-
declare const SnapRpcResponse:
|
|
240
|
+
declare const SnapRpcResponse: Struct<{
|
|
185
241
|
id: string | number | null;
|
|
186
242
|
jsonrpc: "2.0";
|
|
187
243
|
result: Json;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,WAAW,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,WAAW,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAiB3D,OAAO,KAAK,EACV,WAAW,EACX,IAAI,EACJ,cAAc,EACd,cAAc,EACf,wBAAwB;AAazB,eAAO,MAAM,6BAA6B;;;;;;;;;;EAKxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF,eAAO,MAAM,eAAe,sBAAW,CAAC;AACxC,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,EAAE,CAEtE;AAID,eAAO,MAAM,0BAA0B,qCAEtC,CAAC;AAEF,eAAO,MAAM,+BAA+B,qCAG1C,CAAC;AAEH,eAAO,MAAM,iCAAiC,0CAI5C,CAAC;AAEH,eAAO,MAAM,6BAA6B;;;;;SAaxC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,0BAA0B,C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D,KAAK,aAAa,CAAC,MAAM,SAAS,OAAO,EAAE,GAAG,SAAS,IACrD,MAAM,SAAS,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC;AAEzC,KAAK,eAAe,CAClB,IAAI,SAAS,gBAAgB,EAC7B,YAAY,SAAS,cAAc,CAAC,IAAI,CAAC,IACvC,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEtE,MAAM,MAAM,IAAI,GAAG,eAAe,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;AACrE,MAAM,MAAM,SAAS,GAAG,eAAe,CAAC,yBAAyB,EAAE,UAAU,CAAC,CAAC;AAC/E,MAAM,MAAM,WAAW,GAAG,eAAe,CACvC,2BAA2B,EAC3B,UAAU,CACX,CAAC;AACF,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
2
|
import { InterfaceContextStruct, UserInputEventStruct } from "@metamask/snaps-sdk";
|
|
3
3
|
import { ChainIdStruct, HandlerType } from "@metamask/snaps-utils";
|
|
4
|
-
import { any, array, assign, enums, is, literal, nullable, object, optional, record, string, tuple, union } from "@metamask/superstruct";
|
|
5
|
-
import { assertStruct, JsonRpcIdStruct, JsonRpcParamsStruct, JsonRpcSuccessStruct, JsonRpcVersionStruct, JsonStruct } from "@metamask/utils";
|
|
4
|
+
import { any, array, assign, enums, is, literal, nullable, object, optional, record, size, string, tuple, union } from "@metamask/superstruct";
|
|
5
|
+
import { assertStruct, CaipAssetTypeStruct, CaipChainIdStruct, JsonRpcIdStruct, JsonRpcParamsStruct, JsonRpcRequestStruct, JsonRpcSuccessStruct, JsonRpcVersionStruct, JsonStruct } from "@metamask/utils";
|
|
6
6
|
export const JsonRpcRequestWithoutIdStruct = object({
|
|
7
7
|
jsonrpc: optional(JsonRpcVersionStruct),
|
|
8
8
|
id: optional(JsonRpcIdStruct),
|
|
@@ -106,6 +106,37 @@ export const OnNameLookupRequestArgumentsStruct = union([
|
|
|
106
106
|
export function assertIsOnNameLookupRequestArguments(value) {
|
|
107
107
|
assertStruct(value, OnNameLookupRequestArgumentsStruct, 'Invalid request params', rpcErrors.invalidParams);
|
|
108
108
|
}
|
|
109
|
+
export const OnAssetsLookupRequestArgumentsStruct = object({
|
|
110
|
+
assets: size(array(CaipAssetTypeStruct), 1, Infinity),
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Asserts that the given value is a valid {@link OnAssetsLookupRequestArguments}
|
|
114
|
+
* object.
|
|
115
|
+
*
|
|
116
|
+
* @param value - The value to validate.
|
|
117
|
+
* @throws If the value is not a valid {@link OnAssetsLookupRequestArguments}
|
|
118
|
+
* object.
|
|
119
|
+
*/
|
|
120
|
+
export function assertIsOnAssetsLookupRequestArguments(value) {
|
|
121
|
+
assertStruct(value, OnAssetsLookupRequestArgumentsStruct, 'Invalid request params', rpcErrors.invalidParams);
|
|
122
|
+
}
|
|
123
|
+
export const OnAssetsConversionRequestArgumentsStruct = object({
|
|
124
|
+
conversions: size(array(object({
|
|
125
|
+
from: CaipAssetTypeStruct,
|
|
126
|
+
to: CaipAssetTypeStruct,
|
|
127
|
+
})), 1, Infinity),
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Asserts that the given value is a valid {@link OnAssetsConversionRequestArguments}
|
|
131
|
+
* object.
|
|
132
|
+
*
|
|
133
|
+
* @param value - The value to validate.
|
|
134
|
+
* @throws If the value is not a valid {@link OnNameLookupRequestArguments}
|
|
135
|
+
* object.
|
|
136
|
+
*/
|
|
137
|
+
export function assertIsOnAssetsConversionRequestArguments(value) {
|
|
138
|
+
assertStruct(value, OnAssetsConversionRequestArgumentsStruct, 'Invalid request params', rpcErrors.invalidParams);
|
|
139
|
+
}
|
|
109
140
|
export const OnUserInputArgumentsStruct = object({
|
|
110
141
|
id: string(),
|
|
111
142
|
event: UserInputEventStruct,
|
|
@@ -122,6 +153,21 @@ export const OnUserInputArgumentsStruct = object({
|
|
|
122
153
|
export function assertIsOnUserInputRequestArguments(value) {
|
|
123
154
|
assertStruct(value, OnUserInputArgumentsStruct, 'Invalid request params', rpcErrors.invalidParams);
|
|
124
155
|
}
|
|
156
|
+
export const OnProtocolRequestArgumentsStruct = object({
|
|
157
|
+
scope: CaipChainIdStruct,
|
|
158
|
+
request: JsonRpcRequestStruct,
|
|
159
|
+
});
|
|
160
|
+
/**
|
|
161
|
+
* Asserts that the given value is a valid {@link OnProtocolRequestArguments}
|
|
162
|
+
* object.
|
|
163
|
+
*
|
|
164
|
+
* @param value - The value to validate.
|
|
165
|
+
* @throws If the value is not a valid {@link OnProtocolRequestArguments}
|
|
166
|
+
* object.
|
|
167
|
+
*/
|
|
168
|
+
export function assertIsOnProtocolRequestArguments(value) {
|
|
169
|
+
assertStruct(value, OnProtocolRequestArgumentsStruct, 'Invalid request params', rpcErrors.invalidParams);
|
|
170
|
+
}
|
|
125
171
|
const OkResponseStruct = object({
|
|
126
172
|
id: JsonRpcIdStruct,
|
|
127
173
|
jsonrpc: JsonRpcVersionStruct,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACrB,4BAA4B;AAC7B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,8BAA8B;AAEnE,OAAO,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAO,EACP,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,KAAK,EACN,8BAA8B;AAE/B,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,E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IACnB,oBAAoB;CACrB,CAAC,CAAC;AAWH;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,KAAc;IAEd,YAAY,CACV,KAAK,EACL,kCAAkC,EAClC,wBAAwB,EACxB,SAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;IAC/C,EAAE,EAAE,MAAM,EAAE;IACZ,KAAK,EAAE,oBAAoB;IAC3B,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;CACpD,CAAC,CAAC;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CACjD,KAAc;IAEd,YAAY,CACV,KAAK,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,SAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;IAC9B,EAAE,EAAE,eAAe;IACnB,OAAO,EAAE,oBAAoB;IAC7B,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,oBAAoB,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport {\n InterfaceContextStruct,\n UserInputEventStruct,\n} from '@metamask/snaps-sdk';\nimport { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n any,\n array,\n assign,\n enums,\n is,\n literal,\n nullable,\n object,\n optional,\n record,\n string,\n tuple,\n union,\n} from '@metamask/superstruct';\nimport type { Json, JsonRpcSuccess } from '@metamask/utils';\nimport {\n assertStruct,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcSuccessStruct,\n JsonRpcVersionStruct,\n JsonStruct,\n} from '@metamask/utils';\n\nexport const JsonRpcRequestWithoutIdStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type JsonRpcRequestWithoutId = Infer<\n typeof JsonRpcRequestWithoutIdStruct\n>;\n\nexport const EndowmentStruct = string();\nexport type Endowment = Infer<typeof EndowmentStruct>;\n\n/**\n * Check if the given value is an endowment.\n *\n * @param value - The value to check.\n * @returns Whether the value is an endowment.\n */\nexport function isEndowment(value: unknown): value is Endowment {\n return is(value, EndowmentStruct);\n}\n\n/**\n * Check if the given value is an array of endowments.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of endowments.\n */\nexport function isEndowmentsArray(value: unknown): value is Endowment[] {\n return Array.isArray(value) && value.every(isEndowment);\n}\n\nconst OkStruct = literal('OK');\n\nexport const PingRequestArgumentsStruct = optional(\n union([literal(undefined), array()]),\n);\n\nexport const TerminateRequestArgumentsStruct = union([\n literal(undefined),\n array(),\n]);\n\nexport const ExecuteSnapRequestArgumentsStruct = tuple([\n string(),\n string(),\n array(EndowmentStruct),\n]);\n\nexport const SnapRpcRequestArgumentsStruct = tuple([\n string(),\n enums(Object.values(HandlerType)),\n string(),\n assign(\n JsonRpcRequestWithoutIdStruct,\n object({\n // Previously this would validate that the parameters were valid JSON.\n // This is already validated for all messages received by the executor.\n // If that assumption changes, this should once again validate JSON.\n params: optional(record(string(), any())),\n }),\n ),\n]);\n\nexport type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;\nexport type TerminateRequestArguments = Infer<\n typeof TerminateRequestArgumentsStruct\n>;\n\nexport type ExecuteSnapRequestArguments = Infer<\n typeof ExecuteSnapRequestArgumentsStruct\n>;\n\nexport type SnapRpcRequestArguments = Infer<\n typeof SnapRpcRequestArgumentsStruct\n>;\n\nexport type RequestArguments =\n | PingRequestArguments\n | TerminateRequestArguments\n | ExecuteSnapRequestArguments\n | SnapRpcRequestArguments;\n\nexport const OnTransactionRequestArgumentsStruct = object({\n // TODO: Improve `transaction` type.\n transaction: record(string(), JsonStruct),\n chainId: ChainIdStruct,\n transactionOrigin: nullable(string()),\n});\n\nexport type OnTransactionRequestArguments = Infer<\n typeof OnTransactionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnTransactionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnTransactionRequestArguments}\n * object.\n */\nexport function assertIsOnTransactionRequestArguments(\n value: unknown,\n): asserts value is OnTransactionRequestArguments {\n assertStruct(\n value,\n OnTransactionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnSignatureRequestArgumentsStruct = object({\n signature: record(string(), JsonStruct),\n signatureOrigin: nullable(string()),\n});\n\nexport type OnSignatureRequestArguments = Infer<\n typeof OnSignatureRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnSignatureRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnSignatureRequestArguments}\n * object.\n */\nexport function assertIsOnSignatureRequestArguments(\n value: unknown,\n): asserts value is OnSignatureRequestArguments {\n assertStruct(\n value,\n OnSignatureRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst baseNameLookupArgs = { chainId: ChainIdStruct };\nconst domainRequestStruct = object({\n ...baseNameLookupArgs,\n address: string(),\n});\nconst addressRequestStruct = object({\n ...baseNameLookupArgs,\n domain: string(),\n});\n\nexport const OnNameLookupRequestArgumentsStruct = union([\n domainRequestStruct,\n addressRequestStruct,\n]);\n\nexport type OnNameLookupRequestArguments = Infer<\n typeof OnNameLookupRequestArgumentsStruct\n>;\n\nexport type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {\n address?: string;\n domain?: string;\n};\n\n/**\n * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnNameLookupRequestArguments(\n value: unknown,\n): asserts value is OnNameLookupRequestArguments {\n assertStruct(\n value,\n OnNameLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnUserInputArgumentsStruct = object({\n id: string(),\n event: UserInputEventStruct,\n context: optional(nullable(InterfaceContextStruct)),\n});\n\nexport type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link OnUserInputArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnUserInputArguments}\n * object.\n */\nexport function assertIsOnUserInputRequestArguments(\n value: unknown,\n): asserts value is OnUserInputArguments {\n assertStruct(\n value,\n OnUserInputArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst OkResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: OkStruct,\n});\n\nconst SnapRpcResponse = JsonRpcSuccessStruct;\n\nexport type OkResponse = Infer<typeof OkResponseStruct>;\nexport type SnapRpcResponse = Infer<typeof SnapRpcResponse>;\n\nexport type Response = OkResponse | SnapRpcResponse;\n\ntype RequestParams<Params extends unknown[] | undefined> =\n Params extends undefined ? [] : Params;\n\ntype RequestFunction<\n Args extends RequestArguments,\n ResponseType extends JsonRpcSuccess<Json>,\n> = (...args: RequestParams<Args>) => Promise<ResponseType['result']>;\n\nexport type Ping = RequestFunction<PingRequestArguments, OkResponse>;\nexport type Terminate = RequestFunction<TerminateRequestArguments, OkResponse>;\nexport type ExecuteSnap = RequestFunction<\n ExecuteSnapRequestArguments,\n OkResponse\n>;\nexport type SnapRpc = RequestFunction<SnapRpcRequestArguments, SnapRpcResponse>;\n"]}
|
|
1
|
+
{"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACrB,4BAA4B;AAC7B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,8BAA8B;AAEnE,OAAO,EACL,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;IAC3B,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;CACpD,CAAC,CAAC;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CACjD,KAAc;IAEd,YAAY,CACV,KAAK,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,SAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;IACrD,KAAK,EAAE,iBAAiB;IACxB,OAAO,EAAE,oBAAoB;CAC9B,CAA6E,CAAC;AAM/E;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC,CAChD,KAAc;IAEd,YAAY,CACV,KAAK,EACL,gCAAgC,EAChC,wBAAwB,EACxB,SAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;IAC9B,EAAE,EAAE,eAAe;IACnB,OAAO,EAAE,oBAAoB;IAC7B,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,oBAAoB,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport {\n InterfaceContextStruct,\n UserInputEventStruct,\n} from '@metamask/snaps-sdk';\nimport { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport {\n any,\n array,\n assign,\n enums,\n is,\n literal,\n nullable,\n object,\n optional,\n record,\n size,\n string,\n tuple,\n union,\n} from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcRequest,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n CaipAssetTypeStruct,\n CaipChainIdStruct,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcRequestStruct,\n JsonRpcSuccessStruct,\n JsonRpcVersionStruct,\n JsonStruct,\n} from '@metamask/utils';\n\nexport const JsonRpcRequestWithoutIdStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type JsonRpcRequestWithoutId = Infer<\n typeof JsonRpcRequestWithoutIdStruct\n>;\n\nexport const EndowmentStruct = string();\nexport type Endowment = Infer<typeof EndowmentStruct>;\n\n/**\n * Check if the given value is an endowment.\n *\n * @param value - The value to check.\n * @returns Whether the value is an endowment.\n */\nexport function isEndowment(value: unknown): value is Endowment {\n return is(value, EndowmentStruct);\n}\n\n/**\n * Check if the given value is an array of endowments.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of endowments.\n */\nexport function isEndowmentsArray(value: unknown): value is Endowment[] {\n return Array.isArray(value) && value.every(isEndowment);\n}\n\nconst OkStruct = literal('OK');\n\nexport const PingRequestArgumentsStruct = optional(\n union([literal(undefined), array()]),\n);\n\nexport const TerminateRequestArgumentsStruct = union([\n literal(undefined),\n array(),\n]);\n\nexport const ExecuteSnapRequestArgumentsStruct = tuple([\n string(),\n string(),\n array(EndowmentStruct),\n]);\n\nexport const SnapRpcRequestArgumentsStruct = tuple([\n string(),\n enums(Object.values(HandlerType)),\n string(),\n assign(\n JsonRpcRequestWithoutIdStruct,\n object({\n // Previously this would validate that the parameters were valid JSON.\n // This is already validated for all messages received by the executor.\n // If that assumption changes, this should once again validate JSON.\n params: optional(record(string(), any())),\n }),\n ),\n]);\n\nexport type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;\nexport type TerminateRequestArguments = Infer<\n typeof TerminateRequestArgumentsStruct\n>;\n\nexport type ExecuteSnapRequestArguments = Infer<\n typeof ExecuteSnapRequestArgumentsStruct\n>;\n\nexport type SnapRpcRequestArguments = Infer<\n typeof SnapRpcRequestArgumentsStruct\n>;\n\nexport type RequestArguments =\n | PingRequestArguments\n | TerminateRequestArguments\n | ExecuteSnapRequestArguments\n | SnapRpcRequestArguments;\n\nexport const OnTransactionRequestArgumentsStruct = object({\n // TODO: Improve `transaction` type.\n transaction: record(string(), JsonStruct),\n chainId: ChainIdStruct,\n transactionOrigin: nullable(string()),\n});\n\nexport type OnTransactionRequestArguments = Infer<\n typeof OnTransactionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnTransactionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnTransactionRequestArguments}\n * object.\n */\nexport function assertIsOnTransactionRequestArguments(\n value: unknown,\n): asserts value is OnTransactionRequestArguments {\n assertStruct(\n value,\n OnTransactionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnSignatureRequestArgumentsStruct = object({\n signature: record(string(), JsonStruct),\n signatureOrigin: nullable(string()),\n});\n\nexport type OnSignatureRequestArguments = Infer<\n typeof OnSignatureRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnSignatureRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnSignatureRequestArguments}\n * object.\n */\nexport function assertIsOnSignatureRequestArguments(\n value: unknown,\n): asserts value is OnSignatureRequestArguments {\n assertStruct(\n value,\n OnSignatureRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst baseNameLookupArgs = { chainId: ChainIdStruct };\nconst domainRequestStruct = object({\n ...baseNameLookupArgs,\n address: string(),\n});\nconst addressRequestStruct = object({\n ...baseNameLookupArgs,\n domain: string(),\n});\n\nexport const OnNameLookupRequestArgumentsStruct = union([\n domainRequestStruct,\n addressRequestStruct,\n]);\n\nexport type OnNameLookupRequestArguments = Infer<\n typeof OnNameLookupRequestArgumentsStruct\n>;\n\nexport type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {\n address?: string;\n domain?: string;\n};\n\n/**\n * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnNameLookupRequestArguments(\n value: unknown,\n): asserts value is OnNameLookupRequestArguments {\n assertStruct(\n value,\n OnNameLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnAssetsLookupRequestArgumentsStruct = object({\n assets: size(array(CaipAssetTypeStruct), 1, Infinity),\n});\n\nexport type OnAssetsLookupRequestArguments = Infer<\n typeof OnAssetsLookupRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnAssetsLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnAssetsLookupRequestArguments}\n * object.\n */\nexport function assertIsOnAssetsLookupRequestArguments(\n value: unknown,\n): asserts value is OnAssetsLookupRequestArguments {\n assertStruct(\n value,\n OnAssetsLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnAssetsConversionRequestArgumentsStruct = object({\n conversions: size(\n array(\n object({\n from: CaipAssetTypeStruct,\n to: CaipAssetTypeStruct,\n }),\n ),\n 1,\n Infinity,\n ),\n});\n\nexport type OnAssetsConversionRequestArguments = Infer<\n typeof OnAssetsConversionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnAssetsConversionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnAssetsConversionRequestArguments(\n value: unknown,\n): asserts value is OnAssetsConversionRequestArguments {\n assertStruct(\n value,\n OnAssetsConversionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnUserInputArgumentsStruct = object({\n id: string(),\n event: UserInputEventStruct,\n context: optional(nullable(InterfaceContextStruct)),\n});\n\nexport type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link OnUserInputArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnUserInputArguments}\n * object.\n */\nexport function assertIsOnUserInputRequestArguments(\n value: unknown,\n): asserts value is OnUserInputArguments {\n assertStruct(\n value,\n OnUserInputArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnProtocolRequestArgumentsStruct = object({\n scope: CaipChainIdStruct,\n request: JsonRpcRequestStruct,\n}) as unknown as Struct<{ scope: CaipChainId; request: JsonRpcRequest }, null>;\n\nexport type OnProtocolRequestArguments = Infer<\n typeof OnProtocolRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnProtocolRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnProtocolRequestArguments}\n * object.\n */\nexport function assertIsOnProtocolRequestArguments(\n value: unknown,\n): asserts value is OnProtocolRequestArguments {\n assertStruct(\n value,\n OnProtocolRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst OkResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: OkStruct,\n});\n\nconst SnapRpcResponse = JsonRpcSuccessStruct;\n\nexport type OkResponse = Infer<typeof OkResponseStruct>;\nexport type SnapRpcResponse = Infer<typeof SnapRpcResponse>;\n\nexport type Response = OkResponse | SnapRpcResponse;\n\ntype RequestParams<Params extends unknown[] | undefined> =\n Params extends undefined ? [] : Params;\n\ntype RequestFunction<\n Args extends RequestArguments,\n ResponseType extends JsonRpcSuccess<Json>,\n> = (...args: RequestParams<Args>) => Promise<ResponseType['result']>;\n\nexport type Ping = RequestFunction<PingRequestArguments, OkResponse>;\nexport type Terminate = RequestFunction<TerminateRequestArguments, OkResponse>;\nexport type ExecuteSnap = RequestFunction<\n ExecuteSnapRequestArguments,\n OkResponse\n>;\nexport type SnapRpc = RequestFunction<SnapRpcRequestArguments, SnapRpcResponse>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-execution-environments",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.14.0",
|
|
4
4
|
"description": "Snap sandbox environments for executing SES javascript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@metamask/post-message-stream": "^9.0.0",
|
|
70
70
|
"@metamask/providers": "^18.3.1",
|
|
71
71
|
"@metamask/rpc-errors": "^7.0.2",
|
|
72
|
-
"@metamask/snaps-sdk": "^6.
|
|
73
|
-
"@metamask/snaps-utils": "^8.
|
|
72
|
+
"@metamask/snaps-sdk": "^6.17.0",
|
|
73
|
+
"@metamask/snaps-utils": "^8.10.0",
|
|
74
74
|
"@metamask/superstruct": "^3.1.0",
|
|
75
75
|
"@metamask/utils": "^11.0.1",
|
|
76
76
|
"nanoid": "^3.1.31",
|