@metamask/keyring-api 0.2.1 → 0.2.3
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 +26 -1
- package/dist/JsonRpcRequest.d.ts +8 -7
- package/dist/JsonRpcRequest.js +5 -10
- package/dist/JsonRpcRequest.js.map +1 -1
- package/dist/KeyringClient.js +13 -12
- package/dist/KeyringClient.js.map +1 -1
- package/dist/KeyringSnapRpcClient.d.ts +2 -1
- package/dist/KeyringSnapRpcClient.js.map +1 -1
- package/dist/api.d.ts +26 -29
- package/dist/api.js +20 -12
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/api.d.ts +48 -76
- package/dist/internal/api.js.map +1 -1
- package/dist/internal/events.d.ts +6 -12
- package/dist/internal/types.d.ts +10 -7
- package/dist/internal/types.js +7 -5
- package/dist/internal/types.js.map +1 -1
- package/dist/rpc-handler.d.ts +1 -1
- package/dist/rpc-handler.js.map +1 -1
- package/dist/superstruct.d.ts +57 -0
- package/dist/superstruct.js +49 -0
- package/dist/superstruct.js.map +1 -0
- package/dist/superstruct.test-d.d.ts +1 -0
- package/dist/superstruct.test-d.js +17 -0
- package/dist/superstruct.test-d.js.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +10 -4
package/dist/internal/api.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import type { Infer } from 'superstruct';
|
2
2
|
export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
|
3
3
|
jsonrpc: "2.0";
|
4
4
|
id: string;
|
@@ -10,17 +10,17 @@ export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
|
|
10
10
|
}>;
|
11
11
|
export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;
|
12
12
|
export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
|
13
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
13
14
|
id: string;
|
14
15
|
address: string;
|
15
16
|
options: Record<string, import("@metamask/utils").Json>;
|
16
17
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
17
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
18
18
|
}[], import("superstruct").Struct<{
|
19
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
19
20
|
id: string;
|
20
21
|
address: string;
|
21
22
|
options: Record<string, import("@metamask/utils").Json>;
|
22
23
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
23
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
24
24
|
}, {
|
25
25
|
id: import("superstruct").Struct<string, null>;
|
26
26
|
address: import("superstruct").Struct<string, null>;
|
@@ -59,11 +59,11 @@ export declare const GetAccountRequestStruct: import("superstruct").Struct<{
|
|
59
59
|
}>;
|
60
60
|
export declare type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;
|
61
61
|
export declare const GetAccountResponseStruct: import("superstruct").Struct<{
|
62
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
62
63
|
id: string;
|
63
64
|
address: string;
|
64
65
|
options: Record<string, import("@metamask/utils").Json>;
|
65
66
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
66
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
67
67
|
}, {
|
68
68
|
id: import("superstruct").Struct<string, null>;
|
69
69
|
address: import("superstruct").Struct<string, null>;
|
@@ -102,11 +102,11 @@ export declare const CreateAccountRequestStruct: import("superstruct").Struct<{
|
|
102
102
|
}>;
|
103
103
|
export declare type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;
|
104
104
|
export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
|
105
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
105
106
|
id: string;
|
106
107
|
address: string;
|
107
108
|
options: Record<string, import("@metamask/utils").Json>;
|
108
109
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
109
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
110
110
|
}, {
|
111
111
|
id: import("superstruct").Struct<string, null>;
|
112
112
|
address: import("superstruct").Struct<string, null>;
|
@@ -155,30 +155,30 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
|
|
155
155
|
method: "keyring_updateAccount";
|
156
156
|
params: {
|
157
157
|
account: {
|
158
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
158
159
|
id: string;
|
159
160
|
address: string;
|
160
161
|
options: Record<string, import("@metamask/utils").Json>;
|
161
162
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
162
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
163
163
|
};
|
164
164
|
};
|
165
165
|
}, {
|
166
166
|
method: import("superstruct").Struct<"keyring_updateAccount", "keyring_updateAccount">;
|
167
167
|
params: import("superstruct").Struct<{
|
168
168
|
account: {
|
169
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
169
170
|
id: string;
|
170
171
|
address: string;
|
171
172
|
options: Record<string, import("@metamask/utils").Json>;
|
172
173
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
173
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
174
174
|
};
|
175
175
|
}, {
|
176
176
|
account: import("superstruct").Struct<{
|
177
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
177
178
|
id: string;
|
178
179
|
address: string;
|
179
180
|
options: Record<string, import("@metamask/utils").Json>;
|
180
181
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
181
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
182
182
|
}, {
|
183
183
|
id: import("superstruct").Struct<string, null>;
|
184
184
|
address: import("superstruct").Struct<string, null>;
|
@@ -255,44 +255,32 @@ export declare const ListRequestsRequestStruct: import("superstruct").Struct<{
|
|
255
255
|
}>;
|
256
256
|
export declare type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;
|
257
257
|
export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
|
258
|
-
|
258
|
+
id: string;
|
259
259
|
scope: string;
|
260
|
+
account: string;
|
260
261
|
request: {
|
261
|
-
jsonrpc: "2.0";
|
262
|
-
id: string | number | null;
|
263
|
-
method: string;
|
264
|
-
} | {
|
265
|
-
jsonrpc: "2.0";
|
266
|
-
id: string | number | null;
|
267
262
|
method: string;
|
268
|
-
params
|
263
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
269
264
|
};
|
270
265
|
}[], import("superstruct").Struct<{
|
271
|
-
|
266
|
+
id: string;
|
272
267
|
scope: string;
|
268
|
+
account: string;
|
273
269
|
request: {
|
274
|
-
jsonrpc: "2.0";
|
275
|
-
id: string | number | null;
|
276
270
|
method: string;
|
277
|
-
|
278
|
-
jsonrpc: "2.0";
|
279
|
-
id: string | number | null;
|
280
|
-
method: string;
|
281
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
271
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
282
272
|
};
|
283
273
|
}, {
|
284
|
-
|
274
|
+
id: import("superstruct").Struct<string, null>;
|
285
275
|
scope: import("superstruct").Struct<string, null>;
|
276
|
+
account: import("superstruct").Struct<string, null>;
|
286
277
|
request: import("superstruct").Struct<{
|
287
|
-
jsonrpc: "2.0";
|
288
|
-
id: string | number | null;
|
289
|
-
method: string;
|
290
|
-
} | {
|
291
|
-
jsonrpc: "2.0";
|
292
|
-
id: string | number | null;
|
293
278
|
method: string;
|
294
|
-
params
|
295
|
-
},
|
279
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
280
|
+
}, {
|
281
|
+
method: import("superstruct").Struct<string, null>;
|
282
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
283
|
+
}>;
|
296
284
|
}>>;
|
297
285
|
export declare type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;
|
298
286
|
export declare const GetRequestRequestStruct: import("superstruct").Struct<{
|
@@ -314,31 +302,24 @@ export declare const GetRequestRequestStruct: import("superstruct").Struct<{
|
|
314
302
|
}>;
|
315
303
|
export declare type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;
|
316
304
|
export declare const GetRequestResponseStruct: import("superstruct").Struct<{
|
317
|
-
|
305
|
+
id: string;
|
318
306
|
scope: string;
|
307
|
+
account: string;
|
319
308
|
request: {
|
320
|
-
jsonrpc: "2.0";
|
321
|
-
id: string | number | null;
|
322
309
|
method: string;
|
323
|
-
|
324
|
-
jsonrpc: "2.0";
|
325
|
-
id: string | number | null;
|
326
|
-
method: string;
|
327
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
310
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
328
311
|
};
|
329
312
|
}, {
|
330
|
-
|
313
|
+
id: import("superstruct").Struct<string, null>;
|
331
314
|
scope: import("superstruct").Struct<string, null>;
|
315
|
+
account: import("superstruct").Struct<string, null>;
|
332
316
|
request: import("superstruct").Struct<{
|
333
|
-
jsonrpc: "2.0";
|
334
|
-
id: string | number | null;
|
335
|
-
method: string;
|
336
|
-
} | {
|
337
|
-
jsonrpc: "2.0";
|
338
|
-
id: string | number | null;
|
339
317
|
method: string;
|
340
|
-
params
|
341
|
-
},
|
318
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
319
|
+
}, {
|
320
|
+
method: import("superstruct").Struct<string, null>;
|
321
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
322
|
+
}>;
|
342
323
|
}>;
|
343
324
|
export declare type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;
|
344
325
|
export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
@@ -346,47 +327,35 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
346
327
|
id: string;
|
347
328
|
method: "keyring_submitRequest";
|
348
329
|
params: {
|
349
|
-
|
330
|
+
id: string;
|
350
331
|
scope: string;
|
332
|
+
account: string;
|
351
333
|
request: {
|
352
|
-
jsonrpc: "2.0";
|
353
|
-
id: string | number | null;
|
354
|
-
method: string;
|
355
|
-
} | {
|
356
|
-
jsonrpc: "2.0";
|
357
|
-
id: string | number | null;
|
358
334
|
method: string;
|
359
|
-
params
|
335
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
360
336
|
};
|
361
337
|
};
|
362
338
|
}, {
|
363
339
|
method: import("superstruct").Struct<"keyring_submitRequest", "keyring_submitRequest">;
|
364
340
|
params: import("superstruct").Struct<{
|
365
|
-
|
341
|
+
id: string;
|
366
342
|
scope: string;
|
343
|
+
account: string;
|
367
344
|
request: {
|
368
|
-
jsonrpc: "2.0";
|
369
|
-
id: string | number | null;
|
370
|
-
method: string;
|
371
|
-
} | {
|
372
|
-
jsonrpc: "2.0";
|
373
|
-
id: string | number | null;
|
374
345
|
method: string;
|
375
|
-
params
|
346
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
376
347
|
};
|
377
348
|
}, {
|
378
|
-
|
349
|
+
id: import("superstruct").Struct<string, null>;
|
379
350
|
scope: import("superstruct").Struct<string, null>;
|
351
|
+
account: import("superstruct").Struct<string, null>;
|
380
352
|
request: import("superstruct").Struct<{
|
381
|
-
jsonrpc: "2.0";
|
382
|
-
id: string | number | null;
|
383
|
-
method: string;
|
384
|
-
} | {
|
385
|
-
jsonrpc: "2.0";
|
386
|
-
id: string | number | null;
|
387
353
|
method: string;
|
388
|
-
params
|
389
|
-
},
|
354
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
355
|
+
}, {
|
356
|
+
method: import("superstruct").Struct<string, null>;
|
357
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
358
|
+
}>;
|
390
359
|
}>;
|
391
360
|
jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
|
392
361
|
id: import("superstruct").Struct<string, null>;
|
@@ -394,7 +363,10 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
394
363
|
export declare type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;
|
395
364
|
export declare const SubmitRequestResponseStruct: import("superstruct").Struct<{
|
396
365
|
pending: true;
|
397
|
-
redirect
|
366
|
+
redirect?: {
|
367
|
+
message?: string;
|
368
|
+
url?: string;
|
369
|
+
};
|
398
370
|
} | {
|
399
371
|
pending: false;
|
400
372
|
result: import("@metamask/utils").Json;
|
package/dist/internal/api.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAAqE;AAErE,gCAKgB;AAChB,oCAAsC;AAEtC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,IAAA,qBA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superstruct';\nimport { array, literal, object, record, string } from 'superstruct';\n\nimport {\n KeyringAccountDataStruct,\n KeyringAccountStruct,\n KeyringRequestStruct,\n KeyringResponseStruct,\n} from '../api';\nimport { UuidStruct } from '../utils';\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: UuidStruct,\n};\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_createAccount'),\n params: object({\n options: record(string(), JsonStruct),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n ...CommonHeader,\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: string(),\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = literal(null);\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_deleteAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_exportAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = KeyringAccountDataStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = KeyringResponseStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_approveRequest'),\n params: object({\n id: string(),\n data: record(string(), JsonStruct),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = literal(null);\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_rejectRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = literal(null);\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n"]}
|
@@ -2,40 +2,37 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
|
|
2
2
|
method: "event:accountCreated";
|
3
3
|
params: {
|
4
4
|
account: {
|
5
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
5
6
|
id: string;
|
6
7
|
address: string;
|
7
8
|
options: Record<string, import("@metamask/utils").Json>;
|
8
9
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
9
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
10
10
|
};
|
11
11
|
};
|
12
12
|
}, {
|
13
13
|
method: import("superstruct").Struct<"event:accountCreated", "event:accountCreated">;
|
14
14
|
params: import("superstruct").Struct<{
|
15
15
|
account: {
|
16
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
16
17
|
id: string;
|
17
18
|
address: string;
|
18
19
|
options: Record<string, import("@metamask/utils").Json>;
|
19
20
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
20
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
21
21
|
};
|
22
22
|
}, {
|
23
23
|
/**
|
24
24
|
* New account object.
|
25
25
|
*/
|
26
26
|
account: import("superstruct").Struct<{
|
27
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
27
28
|
id: string;
|
28
29
|
address: string;
|
29
30
|
options: Record<string, import("@metamask/utils").Json>;
|
30
31
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
31
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
32
32
|
}, {
|
33
33
|
id: import("superstruct").Struct<string, null>;
|
34
34
|
address: import("superstruct").Struct<string, null>;
|
35
35
|
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
36
|
-
/**
|
37
|
-
* Request result.
|
38
|
-
*/
|
39
36
|
methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
|
40
37
|
personal_sign: "personal_sign";
|
41
38
|
eth_sign: "eth_sign";
|
@@ -56,40 +53,37 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
|
|
56
53
|
method: "event:accountUpdated";
|
57
54
|
params: {
|
58
55
|
account: {
|
56
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
59
57
|
id: string;
|
60
58
|
address: string;
|
61
59
|
options: Record<string, import("@metamask/utils").Json>;
|
62
60
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
63
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
64
61
|
};
|
65
62
|
};
|
66
63
|
}, {
|
67
64
|
method: import("superstruct").Struct<"event:accountUpdated", "event:accountUpdated">;
|
68
65
|
params: import("superstruct").Struct<{
|
69
66
|
account: {
|
67
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
70
68
|
id: string;
|
71
69
|
address: string;
|
72
70
|
options: Record<string, import("@metamask/utils").Json>;
|
73
71
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
74
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
75
72
|
};
|
76
73
|
}, {
|
77
74
|
/**
|
78
75
|
* Updated account object.
|
79
76
|
*/
|
80
77
|
account: import("superstruct").Struct<{
|
78
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
81
79
|
id: string;
|
82
80
|
address: string;
|
83
81
|
options: Record<string, import("@metamask/utils").Json>;
|
84
82
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
85
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
86
83
|
}, {
|
87
84
|
id: import("superstruct").Struct<string, null>;
|
88
85
|
address: import("superstruct").Struct<string, null>;
|
89
86
|
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
90
|
-
/**
|
91
|
-
* Request result.
|
92
|
-
*/
|
93
87
|
methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
|
94
88
|
personal_sign: "personal_sign";
|
95
89
|
eth_sign: "eth_sign";
|
package/dist/internal/types.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import type { Infer } from 'superstruct';
|
2
2
|
export declare const InternalAccountStruct: import("superstruct").Struct<{
|
3
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
3
4
|
id: string;
|
4
5
|
address: string;
|
5
6
|
options: Record<string, import("@metamask/utils").Json>;
|
6
7
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
7
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
8
8
|
metadata: {
|
9
9
|
name: string;
|
10
10
|
keyring: {
|
@@ -14,7 +14,8 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
|
|
14
14
|
id: string;
|
15
15
|
enabled: boolean;
|
16
16
|
name: string;
|
17
|
-
}
|
17
|
+
};
|
18
|
+
lastSelected?: number;
|
18
19
|
};
|
19
20
|
}, {
|
20
21
|
metadata: import("superstruct").Struct<{
|
@@ -26,18 +27,20 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
|
|
26
27
|
id: string;
|
27
28
|
enabled: boolean;
|
28
29
|
name: string;
|
29
|
-
}
|
30
|
+
};
|
31
|
+
lastSelected?: number;
|
30
32
|
}, {
|
31
|
-
|
33
|
+
name: import("superstruct").Struct<string, null>;
|
34
|
+
snap: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | {
|
32
35
|
id: string;
|
33
36
|
enabled: boolean;
|
34
37
|
name: string;
|
35
|
-
}
|
38
|
+
}, {
|
36
39
|
id: import("superstruct").Struct<string, null>;
|
37
40
|
enabled: import("superstruct").Struct<boolean, null>;
|
38
41
|
name: import("superstruct").Struct<string, null>;
|
39
42
|
}>;
|
40
|
-
|
43
|
+
lastSelected: import("superstruct").Struct<number | import("../superstruct").ExactOptionalTag, null>;
|
41
44
|
keyring: import("superstruct").Struct<{
|
42
45
|
type: string;
|
43
46
|
}, {
|
package/dist/internal/types.js
CHANGED
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InternalAccountStruct = void 0;
|
4
4
|
const superstruct_1 = require("superstruct");
|
5
5
|
const api_1 = require("../api");
|
6
|
-
|
6
|
+
const superstruct_2 = require("../superstruct");
|
7
|
+
exports.InternalAccountStruct = (0, superstruct_2.object)({
|
7
8
|
...api_1.KeyringAccountStruct.schema,
|
8
|
-
metadata: (0,
|
9
|
-
|
9
|
+
metadata: (0, superstruct_2.object)({
|
10
|
+
name: (0, superstruct_1.string)(),
|
11
|
+
snap: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
|
10
12
|
id: (0, superstruct_1.string)(),
|
11
13
|
enabled: (0, superstruct_1.boolean)(),
|
12
14
|
name: (0, superstruct_1.string)(),
|
13
15
|
})),
|
14
|
-
|
15
|
-
keyring: (0,
|
16
|
+
lastSelected: (0, superstruct_2.exactOptional)((0, superstruct_1.number)()),
|
17
|
+
keyring: (0, superstruct_2.object)({
|
16
18
|
type: (0, superstruct_1.string)(),
|
17
19
|
}),
|
18
20
|
}),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,gCAA8C;AAC9C,gDAAuD;AAE1C,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,2BAAa,EACjB,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,YAAY,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QACrC,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { boolean, string, number } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\nimport { exactOptional, object } from '../superstruct';\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
|
package/dist/rpc-handler.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { OnRpcRequestHandler } from '@metamask/snaps-utils';
|
2
2
|
import type { Json } from '@metamask/utils';
|
3
3
|
import type { Keyring } from './api';
|
4
|
-
import {
|
4
|
+
import type { JsonRpcRequest } from './JsonRpcRequest';
|
5
5
|
/**
|
6
6
|
* Error thrown when a keyring JSON-RPC method is not supported.
|
7
7
|
*/
|
package/dist/rpc-handler.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAEA,6CAAqC;AAGrC,wCAawB;
|
1
|
+
{"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mapp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AM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACvE;QAED,KAAK,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE;gBACvC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AA3FD,oDA2FC","sourcesContent":["import type { OnRpcRequestHandler } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Build a chain of handlers for a JSON-RPC request.\n *\n * If a handler throws a MethodNotSupportedError, the next handler in the chain\n * is called. If all handlers throw a MethodNotSupportedError, the error is re-\n * thrown.\n *\n * Any other error thrown by a handler is re-thrown.\n *\n * @param handlers - Handlers to chain.\n * @returns A handler that chains the given handlers.\n */\nexport function buildHandlersChain(\n ...handlers: OnRpcRequestHandler[]\n): OnRpcRequestHandler {\n return async ({ origin, request }) => {\n for (const handler of handlers) {\n try {\n return await handler({ origin, request });\n } catch (error) {\n if (!(error instanceof MethodNotSupportedError)) {\n throw error;\n }\n }\n }\n\n // All handlers failed to handle the request.\n throw new MethodNotSupportedError(request.method);\n };\n}\n\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n"]}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { type Infer, Struct } from 'superstruct';
|
2
|
+
import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct/dist/utils';
|
3
|
+
declare const ExactOptionalSymbol: unique symbol;
|
4
|
+
export declare type ExactOptionalTag = {
|
5
|
+
type: typeof ExactOptionalSymbol;
|
6
|
+
};
|
7
|
+
/**
|
8
|
+
* Exclude a type from the properties of a type.
|
9
|
+
*
|
10
|
+
* ```ts
|
11
|
+
* type Foo = { a: string | null; b: number };
|
12
|
+
* type Bar = ExcludeType<Foo, null>;
|
13
|
+
* // Bar = { a: string, b: number }
|
14
|
+
* ```
|
15
|
+
*/
|
16
|
+
export declare type ExcludeType<T, V> = {
|
17
|
+
[K in keyof T]: Exclude<T[K], V>;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Make optional all properties that have the `ExactOptionalTag` type.
|
21
|
+
*
|
22
|
+
* ```ts
|
23
|
+
* type Foo = { a: string | ExactOptionalTag; b: number};
|
24
|
+
* type Bar = ExactOptionalize<Foo>;
|
25
|
+
* // Bar = { a?: string; b: number}
|
26
|
+
* ```
|
27
|
+
*/
|
28
|
+
export declare type ExactOptionalize<S extends object> = OmitBy<S, ExactOptionalTag> & Partial<ExcludeType<PickBy<S, ExactOptionalTag>, ExactOptionalTag>>;
|
29
|
+
/**
|
30
|
+
* Infer a type from an superstruct object schema.
|
31
|
+
*/
|
32
|
+
export declare type ObjectType<S extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
33
|
+
[K in keyof S]: Infer<S[K]>;
|
34
|
+
}>>>;
|
35
|
+
/**
|
36
|
+
* Change the return type of a superstruct object struct to support exact
|
37
|
+
* optional properties.
|
38
|
+
*
|
39
|
+
* @param schema - The object schema.
|
40
|
+
* @returns A struct representing an object with a known set of properties.
|
41
|
+
*/
|
42
|
+
export declare function object<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
|
43
|
+
/**
|
44
|
+
* Augment a struct to allow exact-optional values. Exact-optional values can
|
45
|
+
* be omitted but cannot be `undefined`.
|
46
|
+
*
|
47
|
+
* ```ts
|
48
|
+
* const foo = object({ bar: exactOptional(string()) });
|
49
|
+
* type Foo = Infer<typeof foo>;
|
50
|
+
* // Foo = { bar?: string }
|
51
|
+
* ```
|
52
|
+
*
|
53
|
+
* @param struct - The struct to augment.
|
54
|
+
* @returns The augmented struct.
|
55
|
+
*/
|
56
|
+
export declare function exactOptional<T, S>(struct: Struct<T, S>): Struct<T | ExactOptionalTag, S>;
|
57
|
+
export {};
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.exactOptional = exports.object = void 0;
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
5
|
+
const superstruct_1 = require("superstruct");
|
6
|
+
/**
|
7
|
+
* Change the return type of a superstruct object struct to support exact
|
8
|
+
* optional properties.
|
9
|
+
*
|
10
|
+
* @param schema - The object schema.
|
11
|
+
* @returns A struct representing an object with a known set of properties.
|
12
|
+
*/
|
13
|
+
function object(schema) {
|
14
|
+
return (0, superstruct_1.object)(schema);
|
15
|
+
}
|
16
|
+
exports.object = object;
|
17
|
+
/**
|
18
|
+
* Check if the current property is present in its parent object.
|
19
|
+
*
|
20
|
+
* @param ctx - The context to check.
|
21
|
+
* @returns `true` if the property is present, `false` otherwise.
|
22
|
+
*/
|
23
|
+
function hasOptional(ctx) {
|
24
|
+
const property = ctx.path[ctx.path.length - 1];
|
25
|
+
const parent = ctx.branch[ctx.branch.length - 2];
|
26
|
+
return property in parent;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Augment a struct to allow exact-optional values. Exact-optional values can
|
30
|
+
* be omitted but cannot be `undefined`.
|
31
|
+
*
|
32
|
+
* ```ts
|
33
|
+
* const foo = object({ bar: exactOptional(string()) });
|
34
|
+
* type Foo = Infer<typeof foo>;
|
35
|
+
* // Foo = { bar?: string }
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* @param struct - The struct to augment.
|
39
|
+
* @returns The augmented struct.
|
40
|
+
*/
|
41
|
+
function exactOptional(struct) {
|
42
|
+
return new superstruct_1.Struct({
|
43
|
+
...struct,
|
44
|
+
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
45
|
+
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
46
|
+
});
|
47
|
+
}
|
48
|
+
exports.exactOptional = exactOptional;
|
49
|
+
//# sourceMappingURL=superstruct.js.map
|