@metamask/utils 3.5.0 → 4.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/dist/encryption-types.d.ts +6 -0
- package/dist/encryption-types.js +3 -0
- package/dist/encryption-types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +25 -16
- package/dist/json.js +83 -131
- package/dist/json.js.map +1 -1
- package/dist/keyring.d.ts +210 -0
- package/dist/keyring.js +3 -0
- package/dist/keyring.js.map +1 -0
- package/dist/transaction-types.d.ts +116 -0
- package/dist/transaction-types.js +3 -0
- package/dist/transaction-types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption-types.js","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,14 @@ export * from './bytes';
|
|
|
4
4
|
export * from './checksum';
|
|
5
5
|
export * from './coercers';
|
|
6
6
|
export * from './collections';
|
|
7
|
+
export * from './encryption-types';
|
|
7
8
|
export * from './hex';
|
|
8
9
|
export * from './json';
|
|
10
|
+
export * from './keyring';
|
|
9
11
|
export * from './logging';
|
|
10
12
|
export * from './misc';
|
|
11
13
|
export * from './number';
|
|
12
14
|
export * from './opaque';
|
|
13
15
|
export * from './time';
|
|
16
|
+
export * from './transaction-types';
|
|
14
17
|
export * from './versions';
|
package/dist/index.js
CHANGED
|
@@ -20,12 +20,15 @@ __exportStar(require("./bytes"), exports);
|
|
|
20
20
|
__exportStar(require("./checksum"), exports);
|
|
21
21
|
__exportStar(require("./coercers"), exports);
|
|
22
22
|
__exportStar(require("./collections"), exports);
|
|
23
|
+
__exportStar(require("./encryption-types"), exports);
|
|
23
24
|
__exportStar(require("./hex"), exports);
|
|
24
25
|
__exportStar(require("./json"), exports);
|
|
26
|
+
__exportStar(require("./keyring"), exports);
|
|
25
27
|
__exportStar(require("./logging"), exports);
|
|
26
28
|
__exportStar(require("./misc"), exports);
|
|
27
29
|
__exportStar(require("./number"), exports);
|
|
28
30
|
__exportStar(require("./opaque"), exports);
|
|
29
31
|
__exportStar(require("./time"), exports);
|
|
32
|
+
__exportStar(require("./transaction-types"), exports);
|
|
30
33
|
__exportStar(require("./versions"), exports);
|
|
31
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B;AAC3B,gDAA8B;AAC9B,wCAAsB;AACtB,yCAAuB;AACvB,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB;AACvB,6CAA2B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './hex';\nexport * from './json';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './time';\nexport * from './versions';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B;AAC3B,gDAA8B;AAC9B,qDAAmC;AACnC,wCAAsB;AACtB,yCAAuB;AACvB,4CAA0B;AAC1B,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB;AACvB,sDAAoC;AACpC,6CAA2B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './encryption-types';\nexport * from './hex';\nexport * from './json';\nexport * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './time';\nexport * from './transaction-types';\nexport * from './versions';\n"]}
|
package/dist/json.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { Infer, Struct } from 'superstruct';
|
|
2
2
|
import { AssertionErrorConstructor } from './assert';
|
|
3
|
-
export declare const JsonStruct: Struct<Json, null>;
|
|
4
3
|
/**
|
|
5
4
|
* Any JSON-compatible value.
|
|
6
5
|
*/
|
|
7
6
|
export declare type Json = null | boolean | number | string | Json[] | {
|
|
8
7
|
[prop: string]: Json;
|
|
9
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
11
|
+
*
|
|
12
|
+
* Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.
|
|
13
|
+
*/
|
|
14
|
+
export declare const UnsafeJsonStruct: Struct<Json>;
|
|
15
|
+
/**
|
|
16
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
17
|
+
*
|
|
18
|
+
* This struct sanitizes the value before validating it, so that it is safe to
|
|
19
|
+
* use with untrusted input.
|
|
20
|
+
*/
|
|
21
|
+
export declare const JsonStruct: Struct<Json, null>;
|
|
10
22
|
/**
|
|
11
23
|
* Check if the given value is a valid {@link Json} value, i.e., a value that is
|
|
12
24
|
* serializable to JSON.
|
|
@@ -15,6 +27,13 @@ export declare type Json = null | boolean | number | string | Json[] | {
|
|
|
15
27
|
* @returns Whether the value is a valid {@link Json} value.
|
|
16
28
|
*/
|
|
17
29
|
export declare function isValidJson(value: unknown): value is Json;
|
|
30
|
+
/**
|
|
31
|
+
* Get the size of a JSON value in bytes. This also validates the value.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The JSON value to get the size of.
|
|
34
|
+
* @returns The size of the JSON value in bytes.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getJsonSize(value: unknown): number;
|
|
18
37
|
/**
|
|
19
38
|
* The string '2.0'.
|
|
20
39
|
*/
|
|
@@ -56,18 +75,18 @@ export declare type OptionalField<Type extends Record<string, unknown>, Key exte
|
|
|
56
75
|
* `OptionalField` helper, to explicitly make it optional.
|
|
57
76
|
*/
|
|
58
77
|
export declare type JsonRpcError = OptionalField<Infer<typeof JsonRpcErrorStruct>, 'data'>;
|
|
59
|
-
export declare const JsonRpcParamsStruct: Struct<Record<string, Json> |
|
|
78
|
+
export declare const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json> | undefined, null>;
|
|
60
79
|
export declare type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;
|
|
61
80
|
export declare const JsonRpcRequestStruct: Struct<{
|
|
62
81
|
id: string | number | null;
|
|
63
82
|
method: string;
|
|
64
83
|
jsonrpc: "2.0";
|
|
65
|
-
params?: Record<string, Json> |
|
|
84
|
+
params?: Json[] | Record<string, Json> | undefined;
|
|
66
85
|
}, {
|
|
67
86
|
id: Struct<string | number | null, null>;
|
|
68
87
|
jsonrpc: Struct<"2.0", "2.0">;
|
|
69
88
|
method: Struct<string, null>;
|
|
70
|
-
params: Struct<Record<string, Json> |
|
|
89
|
+
params: Struct<Json[] | Record<string, Json> | undefined, null>;
|
|
71
90
|
}>;
|
|
72
91
|
export declare type InferWithParams<Type extends Struct<any>, Params extends JsonRpcParams> = Omit<Infer<Type>, 'params'> & (keyof Params extends undefined ? {
|
|
73
92
|
params?: Params;
|
|
@@ -81,12 +100,12 @@ export declare type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams>
|
|
|
81
100
|
export declare const JsonRpcNotificationStruct: Struct<{
|
|
82
101
|
method: string;
|
|
83
102
|
jsonrpc: "2.0";
|
|
84
|
-
params?: Record<string, Json> |
|
|
103
|
+
params?: Json[] | Record<string, Json> | undefined;
|
|
85
104
|
}, Omit<{
|
|
86
105
|
id: Struct<string | number | null, null>;
|
|
87
106
|
jsonrpc: Struct<"2.0", "2.0">;
|
|
88
107
|
method: Struct<string, null>;
|
|
89
|
-
params: Struct<Record<string, Json> |
|
|
108
|
+
params: Struct<Json[] | Record<string, Json> | undefined, null>;
|
|
90
109
|
}, "id">>;
|
|
91
110
|
/**
|
|
92
111
|
* A JSON-RPC notification object.
|
|
@@ -312,14 +331,4 @@ declare type JsonRpcValidatorOptions = {
|
|
|
312
331
|
* @returns The JSON-RPC ID validator function.
|
|
313
332
|
*/
|
|
314
333
|
export declare function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions): (id: unknown) => id is string | number | null;
|
|
315
|
-
/**
|
|
316
|
-
* Checks whether a value is JSON serializable and counts the total number
|
|
317
|
-
* of bytes needed to store the serialized version of the value.
|
|
318
|
-
*
|
|
319
|
-
* @param jsObject - Potential JSON serializable object.
|
|
320
|
-
* @param skipSizingProcess - Skip JSON size calculation (default: false).
|
|
321
|
-
* @returns Tuple [isValid, plainTextSizeInBytes] containing a boolean that signals whether
|
|
322
|
-
* the value was serializable and a number of bytes that it will use when serialized to JSON.
|
|
323
|
-
*/
|
|
324
|
-
export declare function validateJsonAndGetSize(jsObject: unknown, skipSizingProcess?: boolean): [isValid: boolean, plainTextSizeInBytes: number];
|
|
325
334
|
export {};
|
package/dist/json.js
CHANGED
|
@@ -1,15 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getJsonRpcIdValidator = exports.assertIsJsonRpcError = exports.isJsonRpcError = exports.assertIsJsonRpcFailure = exports.isJsonRpcFailure = exports.assertIsJsonRpcSuccess = exports.isJsonRpcSuccess = exports.assertIsJsonRpcResponse = exports.isJsonRpcResponse = exports.assertIsPendingJsonRpcResponse = exports.isPendingJsonRpcResponse = exports.JsonRpcResponseStruct = exports.JsonRpcFailureStruct = exports.JsonRpcSuccessStruct = exports.PendingJsonRpcResponseStruct = exports.assertIsJsonRpcRequest = exports.isJsonRpcRequest = exports.assertIsJsonRpcNotification = exports.isJsonRpcNotification = exports.JsonRpcNotificationStruct = exports.JsonRpcRequestStruct = exports.JsonRpcParamsStruct = exports.JsonRpcErrorStruct = exports.JsonRpcIdStruct = exports.JsonRpcVersionStruct = exports.jsonrpc2 = exports.getJsonSize = exports.isValidJson = exports.JsonStruct = exports.UnsafeJsonStruct = void 0;
|
|
4
4
|
const superstruct_1 = require("superstruct");
|
|
5
5
|
const assert_1 = require("./assert");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* A struct to check if the given value is finite number. Superstruct's
|
|
8
|
+
* `number()` struct does not check if the value is finite.
|
|
9
|
+
*
|
|
10
|
+
* @returns A struct to check if the given value is finite number.
|
|
11
|
+
*/
|
|
12
|
+
const finiteNumber = () => (0, superstruct_1.define)('finite number', (value) => {
|
|
13
|
+
return (0, superstruct_1.is)(value, (0, superstruct_1.number)()) && Number.isFinite(value);
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
17
|
+
*
|
|
18
|
+
* Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.
|
|
19
|
+
*/
|
|
20
|
+
// We cannot infer the type of the struct, because it is recursive.
|
|
21
|
+
exports.UnsafeJsonStruct = (0, superstruct_1.union)([
|
|
22
|
+
(0, superstruct_1.literal)(null),
|
|
23
|
+
(0, superstruct_1.boolean)(),
|
|
24
|
+
finiteNumber(),
|
|
25
|
+
(0, superstruct_1.string)(),
|
|
26
|
+
(0, superstruct_1.array)((0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct)),
|
|
27
|
+
(0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct)),
|
|
28
|
+
]);
|
|
29
|
+
/**
|
|
30
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
31
|
+
*
|
|
32
|
+
* This struct sanitizes the value before validating it, so that it is safe to
|
|
33
|
+
* use with untrusted input.
|
|
34
|
+
*/
|
|
35
|
+
exports.JsonStruct = (0, superstruct_1.define)('Json', (value, context) => {
|
|
36
|
+
/**
|
|
37
|
+
* Helper function that runs the given struct validator and returns the
|
|
38
|
+
* validation errors, if any. If the value is valid, it returns `true`.
|
|
39
|
+
*
|
|
40
|
+
* @param innerValue - The value to validate.
|
|
41
|
+
* @param struct - The struct to use for validation.
|
|
42
|
+
* @returns The validation errors, or `true` if the value is valid.
|
|
43
|
+
*/
|
|
44
|
+
function checkStruct(innerValue, struct) {
|
|
45
|
+
const iterator = struct.validator(innerValue, context);
|
|
46
|
+
const errors = [...iterator];
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
return errors;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
// The plain value must be a valid JSON value, but it may be altered in the
|
|
54
|
+
// process of JSON serialization, so we need to validate it again after
|
|
55
|
+
// serialization. This has the added benefit that the returned error messages
|
|
56
|
+
// will be more helpful, as they will point to the exact location of the
|
|
57
|
+
// invalid value.
|
|
58
|
+
//
|
|
59
|
+
// This seems overcomplicated, but without checking the plain value first,
|
|
60
|
+
// there are some cases where the validation passes, even though the value is
|
|
61
|
+
// not valid JSON. For example, `undefined` is not valid JSON, but serializing
|
|
62
|
+
// it will remove it from the object, so the validation will pass.
|
|
63
|
+
const unsafeResult = checkStruct(value, exports.UnsafeJsonStruct);
|
|
64
|
+
if (unsafeResult !== true) {
|
|
65
|
+
return unsafeResult;
|
|
66
|
+
}
|
|
67
|
+
// JavaScript engines are highly optimized for this specific use case of
|
|
68
|
+
// JSON parsing and stringifying, so there should be no performance impact.
|
|
69
|
+
return checkStruct(JSON.parse(JSON.stringify(value)), exports.UnsafeJsonStruct);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof RangeError) {
|
|
73
|
+
return 'Circular reference detected';
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
11
76
|
}
|
|
12
|
-
return true;
|
|
13
77
|
});
|
|
14
78
|
/**
|
|
15
79
|
* Check if the given value is a valid {@link Json} value, i.e., a value that is
|
|
@@ -22,6 +86,18 @@ function isValidJson(value) {
|
|
|
22
86
|
return (0, superstruct_1.is)(value, exports.JsonStruct);
|
|
23
87
|
}
|
|
24
88
|
exports.isValidJson = isValidJson;
|
|
89
|
+
/**
|
|
90
|
+
* Get the size of a JSON value in bytes. This also validates the value.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The JSON value to get the size of.
|
|
93
|
+
* @returns The size of the JSON value in bytes.
|
|
94
|
+
*/
|
|
95
|
+
function getJsonSize(value) {
|
|
96
|
+
(0, assert_1.assertStruct)(value, exports.JsonStruct, 'Invalid JSON value');
|
|
97
|
+
const json = JSON.stringify(value);
|
|
98
|
+
return new TextEncoder().encode(json).byteLength;
|
|
99
|
+
}
|
|
100
|
+
exports.getJsonSize = getJsonSize;
|
|
25
101
|
/**
|
|
26
102
|
* The string '2.0'.
|
|
27
103
|
*/
|
|
@@ -273,128 +349,4 @@ function getJsonRpcIdValidator(options) {
|
|
|
273
349
|
return isValidJsonRpcId;
|
|
274
350
|
}
|
|
275
351
|
exports.getJsonRpcIdValidator = getJsonRpcIdValidator;
|
|
276
|
-
/**
|
|
277
|
-
* Checks whether a value is JSON serializable and counts the total number
|
|
278
|
-
* of bytes needed to store the serialized version of the value.
|
|
279
|
-
*
|
|
280
|
-
* @param jsObject - Potential JSON serializable object.
|
|
281
|
-
* @param skipSizingProcess - Skip JSON size calculation (default: false).
|
|
282
|
-
* @returns Tuple [isValid, plainTextSizeInBytes] containing a boolean that signals whether
|
|
283
|
-
* the value was serializable and a number of bytes that it will use when serialized to JSON.
|
|
284
|
-
*/
|
|
285
|
-
function validateJsonAndGetSize(jsObject, skipSizingProcess = false) {
|
|
286
|
-
const seenObjects = new Set();
|
|
287
|
-
/**
|
|
288
|
-
* Checks whether a value is JSON serializable and counts the total number
|
|
289
|
-
* of bytes needed to store the serialized version of the value.
|
|
290
|
-
*
|
|
291
|
-
* This function assumes the encoding of the JSON is done in UTF-8.
|
|
292
|
-
*
|
|
293
|
-
* @param value - Potential JSON serializable value.
|
|
294
|
-
* @param skipSizing - Skip JSON size calculation (default: false).
|
|
295
|
-
* @returns Tuple [isValid, plainTextSizeInBytes] containing a boolean that signals whether
|
|
296
|
-
* the value was serializable and a number of bytes that it will use when serialized to JSON.
|
|
297
|
-
*/
|
|
298
|
-
function getJsonSerializableInfo(value, skipSizing) {
|
|
299
|
-
if (value === undefined) {
|
|
300
|
-
return [false, 0];
|
|
301
|
-
}
|
|
302
|
-
else if (value === null) {
|
|
303
|
-
// Return already specified constant size for null (special object)
|
|
304
|
-
return [true, skipSizing ? 0 : misc_1.JsonSize.Null];
|
|
305
|
-
}
|
|
306
|
-
// Check and calculate sizes for basic (and some special) types
|
|
307
|
-
const typeOfValue = typeof value;
|
|
308
|
-
try {
|
|
309
|
-
if (typeOfValue === 'function') {
|
|
310
|
-
return [false, 0];
|
|
311
|
-
}
|
|
312
|
-
else if (typeOfValue === 'string' || value instanceof String) {
|
|
313
|
-
return [
|
|
314
|
-
true,
|
|
315
|
-
skipSizing
|
|
316
|
-
? 0
|
|
317
|
-
: (0, misc_1.calculateStringSize)(value) + misc_1.JsonSize.Quote * 2,
|
|
318
|
-
];
|
|
319
|
-
}
|
|
320
|
-
else if (typeOfValue === 'boolean' || value instanceof Boolean) {
|
|
321
|
-
if (skipSizing) {
|
|
322
|
-
return [true, 0];
|
|
323
|
-
}
|
|
324
|
-
// eslint-disable-next-line eqeqeq
|
|
325
|
-
return [true, value == true ? misc_1.JsonSize.True : misc_1.JsonSize.False];
|
|
326
|
-
}
|
|
327
|
-
else if (typeOfValue === 'number' || value instanceof Number) {
|
|
328
|
-
if (skipSizing) {
|
|
329
|
-
return [true, 0];
|
|
330
|
-
}
|
|
331
|
-
return [true, (0, misc_1.calculateNumberSize)(value)];
|
|
332
|
-
}
|
|
333
|
-
else if (value instanceof Date) {
|
|
334
|
-
if (skipSizing) {
|
|
335
|
-
return [true, 0];
|
|
336
|
-
}
|
|
337
|
-
return [
|
|
338
|
-
true,
|
|
339
|
-
// Note: Invalid dates will serialize to null
|
|
340
|
-
isNaN(value.getDate())
|
|
341
|
-
? misc_1.JsonSize.Null
|
|
342
|
-
: misc_1.JsonSize.Date + misc_1.JsonSize.Quote * 2,
|
|
343
|
-
];
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
catch (_) {
|
|
347
|
-
return [false, 0];
|
|
348
|
-
}
|
|
349
|
-
// If object is not plain and cannot be serialized properly,
|
|
350
|
-
// stop here and return false for serialization
|
|
351
|
-
if (!(0, misc_1.isPlainObject)(value) && !Array.isArray(value)) {
|
|
352
|
-
return [false, 0];
|
|
353
|
-
}
|
|
354
|
-
// Circular object detection (handling)
|
|
355
|
-
// Check if the same object already exists
|
|
356
|
-
if (seenObjects.has(value)) {
|
|
357
|
-
return [false, 0];
|
|
358
|
-
}
|
|
359
|
-
// Add new object to the seen objects set
|
|
360
|
-
// Only the plain objects should be added (Primitive types are skipped)
|
|
361
|
-
seenObjects.add(value);
|
|
362
|
-
// Continue object decomposition
|
|
363
|
-
try {
|
|
364
|
-
return [
|
|
365
|
-
true,
|
|
366
|
-
Object.entries(value).reduce((sum, [key, nestedValue], idx, arr) => {
|
|
367
|
-
// Recursively process next nested object or primitive type
|
|
368
|
-
// eslint-disable-next-line prefer-const
|
|
369
|
-
let [valid, size] = getJsonSerializableInfo(nestedValue, skipSizing);
|
|
370
|
-
if (!valid) {
|
|
371
|
-
throw new Error('JSON validation did not pass. Validation process stopped.');
|
|
372
|
-
}
|
|
373
|
-
// Circular object detection
|
|
374
|
-
// Once a child node is visited and processed remove it from the set.
|
|
375
|
-
// This will prevent false positives with the same adjacent objects.
|
|
376
|
-
seenObjects.delete(value);
|
|
377
|
-
if (skipSizing) {
|
|
378
|
-
return 0;
|
|
379
|
-
}
|
|
380
|
-
// Objects will have be serialized with "key": value,
|
|
381
|
-
// therefore we include the key in the calculation here
|
|
382
|
-
const keySize = Array.isArray(value)
|
|
383
|
-
? 0
|
|
384
|
-
: key.length + misc_1.JsonSize.Comma + misc_1.JsonSize.Colon * 2;
|
|
385
|
-
const separator = idx < arr.length - 1 ? misc_1.JsonSize.Comma : 0;
|
|
386
|
-
return sum + keySize + size + separator;
|
|
387
|
-
},
|
|
388
|
-
// Starts at 2 because the serialized JSON string data (plain text)
|
|
389
|
-
// will minimally contain {}/[]
|
|
390
|
-
skipSizing ? 0 : misc_1.JsonSize.Wrapper * 2),
|
|
391
|
-
];
|
|
392
|
-
}
|
|
393
|
-
catch (_) {
|
|
394
|
-
return [false, 0];
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return getJsonSerializableInfo(jsObject, skipSizingProcess);
|
|
398
|
-
}
|
|
399
|
-
exports.validateJsonAndGetSize = validateJsonAndGetSize;
|
|
400
352
|
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AAAA,6CAiBqB;AAErB,qCAAmE;AACnE,iCAKgB;AAEH,QAAA,UAAU,GAAG,IAAA,oBAAM,EAAO,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;IACvD,MAAM,CAAC,OAAO,CAAC,GAAG,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,0CAA0C,CAAC;KACnD;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAaH;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,kBAAU,CAAC,CAAC;AAC/B,CAAC;AAFD,kCAEC;AAED;;GAEG;AACU,QAAA,QAAQ,GAAG,KA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AAM,GAAG,eAAQ,CAAC,KAAK,GAAG,eAAQ,CAAC,KAAK,GAAG,CAAC,CAAC;oBAErD,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBAE5D,OAAO,GAAG,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;gBAC1C,CAAC;gBACD,mEAAmE;gBACnE,+BAA+B;gBAC/B,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAQ,CAAC,OAAO,GAAG,CAAC,CACtC;aACF,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACnB;IACH,CAAC;IAED,OAAO,uBAAuB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;AAC9D,CAAC;AAjID,wDAiIC","sourcesContent":["import {\n array,\n define,\n Infer,\n integer,\n is,\n literal,\n nullable,\n number,\n object,\n omit,\n optional,\n record,\n string,\n Struct,\n union,\n unknown,\n} from 'superstruct';\n\nimport { AssertionErrorConstructor, assertStruct } from './assert';\nimport {\n calculateNumberSize,\n calculateStringSize,\n isPlainObject,\n JsonSize,\n} from './misc';\n\nexport const JsonStruct = define<Json>('Json', (value) => {\n const [isValid] = validateJsonAndGetSize(value, true);\n if (!isValid) {\n return 'Expected a valid JSON-serializable value';\n }\n return true;\n});\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n return is(value, JsonStruct);\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct = optional(\n union([record(string(), JsonStruct), array(JsonStruct)]),\n);\nexport type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Omit<Infer<Type>, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse<Json> {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse<Json> {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse<Json> {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse<Json> {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess<Json> {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess<Json> {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n\n/**\n * Checks whether a value is JSON serializable and counts the total number\n * of bytes needed to store the serialized version of the value.\n *\n * @param jsObject - Potential JSON serializable object.\n * @param skipSizingProcess - Skip JSON size calculation (default: false).\n * @returns Tuple [isValid, plainTextSizeInBytes] containing a boolean that signals whether\n * the value was serializable and a number of bytes that it will use when serialized to JSON.\n */\nexport function validateJsonAndGetSize(\n jsObject: unknown,\n skipSizingProcess = false,\n): [isValid: boolean, plainTextSizeInBytes: number] {\n const seenObjects = new Set();\n /**\n * Checks whether a value is JSON serializable and counts the total number\n * of bytes needed to store the serialized version of the value.\n *\n * This function assumes the encoding of the JSON is done in UTF-8.\n *\n * @param value - Potential JSON serializable value.\n * @param skipSizing - Skip JSON size calculation (default: false).\n * @returns Tuple [isValid, plainTextSizeInBytes] containing a boolean that signals whether\n * the value was serializable and a number of bytes that it will use when serialized to JSON.\n */\n function getJsonSerializableInfo(\n value: unknown,\n skipSizing: boolean,\n ): [isValid: boolean, plainTextSizeInBytes: number] {\n if (value === undefined) {\n return [false, 0];\n } else if (value === null) {\n // Return already specified constant size for null (special object)\n return [true, skipSizing ? 0 : JsonSize.Null];\n }\n\n // Check and calculate sizes for basic (and some special) types\n const typeOfValue = typeof value;\n try {\n if (typeOfValue === 'function') {\n return [false, 0];\n } else if (typeOfValue === 'string' || value instanceof String) {\n return [\n true,\n skipSizing\n ? 0\n : calculateStringSize(value as string) + JsonSize.Quote * 2,\n ];\n } else if (typeOfValue === 'boolean' || value instanceof Boolean) {\n if (skipSizing) {\n return [true, 0];\n }\n // eslint-disable-next-line eqeqeq\n return [true, value == true ? JsonSize.True : JsonSize.False];\n } else if (typeOfValue === 'number' || value instanceof Number) {\n if (skipSizing) {\n return [true, 0];\n }\n return [true, calculateNumberSize(value as number)];\n } else if (value instanceof Date) {\n if (skipSizing) {\n return [true, 0];\n }\n return [\n true,\n // Note: Invalid dates will serialize to null\n isNaN(value.getDate())\n ? JsonSize.Null\n : JsonSize.Date + JsonSize.Quote * 2,\n ];\n }\n } catch (_) {\n return [false, 0];\n }\n\n // If object is not plain and cannot be serialized properly,\n // stop here and return false for serialization\n if (!isPlainObject(value) && !Array.isArray(value)) {\n return [false, 0];\n }\n\n // Circular object detection (handling)\n // Check if the same object already exists\n if (seenObjects.has(value)) {\n return [false, 0];\n }\n // Add new object to the seen objects set\n // Only the plain objects should be added (Primitive types are skipped)\n seenObjects.add(value);\n\n // Continue object decomposition\n try {\n return [\n true,\n Object.entries(value).reduce(\n (sum, [key, nestedValue], idx, arr) => {\n // Recursively process next nested object or primitive type\n // eslint-disable-next-line prefer-const\n let [valid, size] = getJsonSerializableInfo(\n nestedValue,\n skipSizing,\n );\n if (!valid) {\n throw new Error(\n 'JSON validation did not pass. Validation process stopped.',\n );\n }\n\n // Circular object detection\n // Once a child node is visited and processed remove it from the set.\n // This will prevent false positives with the same adjacent objects.\n seenObjects.delete(value);\n\n if (skipSizing) {\n return 0;\n }\n\n // Objects will have be serialized with \"key\": value,\n // therefore we include the key in the calculation here\n const keySize = Array.isArray(value)\n ? 0\n : key.length + JsonSize.Comma + JsonSize.Colon * 2;\n\n const separator = idx < arr.length - 1 ? JsonSize.Comma : 0;\n\n return sum + keySize + size + separator;\n },\n // Starts at 2 because the serialized JSON string data (plain text)\n // will minimally contain {}/[]\n skipSizing ? 0 : JsonSize.Wrapper * 2,\n ),\n ];\n } catch (_) {\n return [false, 0];\n }\n }\n\n return getJsonSerializableInfo(jsObject, skipSizingProcess);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AAAA,6CAmBqB;AAErB,qCAAmE;AAanE;;;;;GAKG;AACH,MAAM,YAAY,GAAG,GAAG,EAAE,CACxB,IAAA,oBAAM,EAAS,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,IAAA,oBAAM,GAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEL;;;;GAIG;AACH,mEAAmE;AACtD,QAAA,gBAAgB,GAAiB,IAAA,mBAAK,EAAC;IAClD,IAAA,qBAAO,EAAC,IAAI,CAAC;IACb,IAAA,qBAAO,GAAE;IACT,YAAY,EAAE;IACd,IAAA,oBAAM,GAAE;IACR,IAAA,mBAAK,EAAC,IAAA,kBAAI,EAAC,GAAG,EAAE,CAAC,wBAAgB,CAAC,CAAC;IACnC,IAAA,oBAAM,EACJ,IAAA,oBAAM,GAAE,EACR,IAAA,kBAAI,EAAC,GAAG,EAAE,CAAC,wBAAgB,CAAC,CAC7B;CACF,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,UAAU,GAAG,IAAA,oBAAM,EAAO,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAChE;;;;;;;OAOG;IACH,SAAS,WAAW,CAAO,UAAmB,EAAE,MAAoB;QAClE,MAAM,QA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;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,KAAc;AACd,gEAAgE;AAChE,YAAwC;IAExC,IAAA,qBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,wBAAwB,EACxB,YAAY,CACb,CAAC;AACJ,CAAC;AAXD,oDAWC;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,qBAAqB,CAAC,OAAiC;IACrE,MAAM,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,mBACtD,iBAAiB,EAAE,IAAI,EACvB,eAAe,EAAE,KAAK,EACtB,UAAU,EAAE,IAAI,IACb,OAAO,CACX,CAAC;IAEF;;;;;;OAMG;IACH,MAAM,gBAAgB,GAAG,CAAC,EAAW,EAAmB,EAAE;QACxD,OAAO,OAAO,CACZ,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC,UAAU,IAAI,EAAE,KAAK,IAAI,CAAC,CAC9B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAxBD,sDAwBC","sourcesContent":["import {\n array,\n boolean,\n define,\n Infer,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n omit,\n optional,\n record,\n string,\n Struct,\n union,\n unknown,\n} from 'superstruct';\n\nimport { AssertionErrorConstructor, assertStruct } from './assert';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define<number>('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct<Json> = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = define<Json>('Json', (value, context) => {\n /**\n * Helper function that runs the given struct validator and returns the\n * validation errors, if any. If the value is valid, it returns `true`.\n *\n * @param innerValue - The value to validate.\n * @param struct - The struct to use for validation.\n * @returns The validation errors, or `true` if the value is valid.\n */\n function checkStruct<Type>(innerValue: unknown, struct: Struct<Type>) {\n const iterator = struct.validator(innerValue, context);\n const errors = [...iterator];\n\n if (errors.length > 0) {\n return errors;\n }\n\n return true;\n }\n\n try {\n // The plain value must be a valid JSON value, but it may be altered in the\n // process of JSON serialization, so we need to validate it again after\n // serialization. This has the added benefit that the returned error messages\n // will be more helpful, as they will point to the exact location of the\n // invalid value.\n //\n // This seems overcomplicated, but without checking the plain value first,\n // there are some cases where the validation passes, even though the value is\n // not valid JSON. For example, `undefined` is not valid JSON, but serializing\n // it will remove it from the object, so the validation will pass.\n const unsafeResult = checkStruct(value, UnsafeJsonStruct);\n if (unsafeResult !== true) {\n return unsafeResult;\n }\n\n // JavaScript engines are highly optimized for this specific use case of\n // JSON parsing and stringifying, so there should be no performance impact.\n return checkStruct(JSON.parse(JSON.stringify(value)), UnsafeJsonStruct);\n } catch (error) {\n if (error instanceof RangeError) {\n return 'Circular reference detected';\n }\n\n return false;\n }\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n return is(value, JsonStruct);\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct = optional(\n union([record(string(), JsonStruct), array(JsonStruct)]),\n);\nexport type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Omit<Infer<Type>, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse<Json> {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse<Json> {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse<Json> {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse<Json> {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess<Json> {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess<Json> {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"]}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { Eip1024EncryptedData } from './encryption-types';
|
|
2
|
+
import { Hex } from './hex';
|
|
3
|
+
import { Json } from './json';
|
|
4
|
+
import type { Transaction, SignedTransaction } from './transaction-types';
|
|
5
|
+
/**
|
|
6
|
+
* A Keyring class.
|
|
7
|
+
*
|
|
8
|
+
* This type is used to validate the constructor signature and the `type`
|
|
9
|
+
* static property on Keyring classes. See the {@link Keyring} type for more
|
|
10
|
+
* information.
|
|
11
|
+
*/
|
|
12
|
+
export declare type KeyringClass<State extends Json> = {
|
|
13
|
+
/**
|
|
14
|
+
* The Keyring constructor. Takes a single parameter, an "options" object.
|
|
15
|
+
* See the documentation for the specific keyring for more information about
|
|
16
|
+
* what these options are.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The constructor options. Differs between keyring
|
|
19
|
+
* implementations.
|
|
20
|
+
*/
|
|
21
|
+
new (options?: Record<string, unknown>): Keyring<State>;
|
|
22
|
+
/**
|
|
23
|
+
* The name of this type of keyring. This must uniquely identify the
|
|
24
|
+
* keyring type.
|
|
25
|
+
*/
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A keyring is something that can sign messages. Keyrings are used to add new
|
|
30
|
+
* signing strategies; each strategy is a new keyring.
|
|
31
|
+
*
|
|
32
|
+
* Each keyring manages a collection of key pairs, which we call "accounts".
|
|
33
|
+
* Each account is referred to by its "address", which is a unique identifier
|
|
34
|
+
* derived from the public key. The address is always a "0x"-prefixed
|
|
35
|
+
* hexidecimal string.
|
|
36
|
+
*
|
|
37
|
+
* The keyring might store the private key for each account as well, but it's
|
|
38
|
+
* not guaranteed. Some keyrings delegate signing, so they don't need the
|
|
39
|
+
* private key directly. The keyring (and in particular the keyring state)
|
|
40
|
+
* should be treated with care though, just in case it does contain sensitive
|
|
41
|
+
* material such as a private key.
|
|
42
|
+
*/
|
|
43
|
+
export declare type Keyring<State extends Json> = {
|
|
44
|
+
/**
|
|
45
|
+
* The name of this type of keyring. This must match the `type` property of
|
|
46
|
+
* the keyring class.
|
|
47
|
+
*/
|
|
48
|
+
type: string;
|
|
49
|
+
/**
|
|
50
|
+
* Get the addresses for all accounts in this keyring.
|
|
51
|
+
*
|
|
52
|
+
* @returns A list of the account addresses for this keyring
|
|
53
|
+
*/
|
|
54
|
+
getAccounts(): Promise<Hex[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Add an account to the keyring.
|
|
57
|
+
*
|
|
58
|
+
* @param number - The number of accounts to add. Usually defaults to 1.
|
|
59
|
+
* @returns A list of the newly added account addresses.
|
|
60
|
+
*/
|
|
61
|
+
addAccounts(number: number): Promise<Hex[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Serialize the keyring state as a JSON-serializable object.
|
|
64
|
+
*
|
|
65
|
+
* @returns A JSON-serializable representation of the keyring state.
|
|
66
|
+
*/
|
|
67
|
+
serialize(): Promise<State>;
|
|
68
|
+
/**
|
|
69
|
+
* Deserialize the given keyring state, overwriting any existing state with
|
|
70
|
+
* the serialized state provided.
|
|
71
|
+
*
|
|
72
|
+
* @param state - A JSON-serializable representation of the keyring state.
|
|
73
|
+
*/
|
|
74
|
+
deserialize(state: State): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Remove an account from the keyring.
|
|
77
|
+
*
|
|
78
|
+
* @param address - The address of the account to remove.
|
|
79
|
+
*/
|
|
80
|
+
removeAccount?(address: Hex): void;
|
|
81
|
+
/**
|
|
82
|
+
* Export the private key for one of the keyring accounts.
|
|
83
|
+
*
|
|
84
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
85
|
+
* for the specific keyring for more information about what these options
|
|
86
|
+
* are. For some keyrings, the options parameter is used to allow exporting a
|
|
87
|
+
* private key that is derived from the given account, rather than exporting
|
|
88
|
+
* that account's private key directly.
|
|
89
|
+
*
|
|
90
|
+
* @param address - The address of the account to export.
|
|
91
|
+
* @param options - Export options; differs between keyrings.
|
|
92
|
+
* @returns The non-prefixed, hex-encoded private key that was requested.
|
|
93
|
+
*/
|
|
94
|
+
exportAccount?(address: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Get the "app key" address for the given account and origin. An app key is
|
|
97
|
+
* an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}
|
|
98
|
+
* for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}
|
|
99
|
+
* is used as the unique identifier for the application, and it's used as
|
|
100
|
+
* part of the key derivation process.
|
|
101
|
+
*
|
|
102
|
+
* @param address - The address of the account the app key is derived from.
|
|
103
|
+
* @param origin - The origin of the application.
|
|
104
|
+
* @returns The address of the app key for the given account and origin.
|
|
105
|
+
*/
|
|
106
|
+
getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;
|
|
107
|
+
/**
|
|
108
|
+
* Sign a transaction. This is equivalent to the `eth_signTransaction`
|
|
109
|
+
* Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for
|
|
110
|
+
* more details.
|
|
111
|
+
*
|
|
112
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
113
|
+
* for the specific keyring for more information about what these options
|
|
114
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
115
|
+
* used for signing (e.g. signing with app keys).
|
|
116
|
+
*
|
|
117
|
+
* @param address - The address of the account to use for signing.
|
|
118
|
+
* @param transaction - The transaction to sign.
|
|
119
|
+
* @param options - Signing options; differs between keyrings.
|
|
120
|
+
* @returns The signed transaction.
|
|
121
|
+
*/
|
|
122
|
+
signTransaction?(address: Hex, transaction: Transaction, options?: Record<string, unknown>): Promise<SignedTransaction>;
|
|
123
|
+
/**
|
|
124
|
+
* Sign a message. This is equivalent to an older version of the the
|
|
125
|
+
* `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,
|
|
126
|
+
* using the curve secp256k1 the Keccak-256 hash function.
|
|
127
|
+
*
|
|
128
|
+
* For more information about this method and why we still support it, see
|
|
129
|
+
* the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
130
|
+
*
|
|
131
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
132
|
+
* for the specific keyring for more information about what these options
|
|
133
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
134
|
+
* used for signing (e.g. signing with app keys).
|
|
135
|
+
*
|
|
136
|
+
* @param address - The address of the account to use for signing.
|
|
137
|
+
* @param message - The message to sign.
|
|
138
|
+
* @param options - Signing options; differs between keyrings.
|
|
139
|
+
* @returns The signed message.
|
|
140
|
+
*/
|
|
141
|
+
signMessage?(address: Hex, message: string, options?: Record<string, unknown>): Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC
|
|
144
|
+
* method, which is exposed by MetaMask as the method `personal_sign`. See
|
|
145
|
+
* the Ethereum JSON-RPC API documentation for more details.
|
|
146
|
+
*
|
|
147
|
+
* For more information about this method and why we call it `personal_sign`,
|
|
148
|
+
* see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
149
|
+
*
|
|
150
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
151
|
+
* for the specific keyring for more information about what these options
|
|
152
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
153
|
+
* used for signing (e.g. signing with app keys).
|
|
154
|
+
*
|
|
155
|
+
* @param address - The address of the account to use for signing.
|
|
156
|
+
* @param message - The message to sign.
|
|
157
|
+
* @param options - Signing options; differs between keyrings.
|
|
158
|
+
* @returns The signed message.
|
|
159
|
+
*/
|
|
160
|
+
signPersonalMessage?(address: Hex, message: Hex, options?: {
|
|
161
|
+
version?: string;
|
|
162
|
+
} & Record<string, unknown>): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Sign a message. This is equivalent to the `eth_signTypedData` Ethereum
|
|
165
|
+
* JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}
|
|
166
|
+
* for more details.
|
|
167
|
+
*
|
|
168
|
+
* The "version" option dictates which version of `eth_signTypedData` is
|
|
169
|
+
* used. The latest version reflects the specification most closely, whereas
|
|
170
|
+
* earlier versions reflect earlier drafts of the specification that are
|
|
171
|
+
* still supported for backwards-compatibility reasons. For more information
|
|
172
|
+
* about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
173
|
+
*
|
|
174
|
+
* Some keyrings accept additional options as well. See the documentation for
|
|
175
|
+
* the specific keyring for more information about what these options are.
|
|
176
|
+
* For some keyrings, the options parameter can even change which key is used
|
|
177
|
+
* for signing (e.g. signing with app keys).
|
|
178
|
+
*
|
|
179
|
+
* @param address - The address of the account to use for signing.
|
|
180
|
+
* @param typedData - The data to sign.
|
|
181
|
+
* @param options - Signing options; differs between keyrings.
|
|
182
|
+
* @returns The signed message.
|
|
183
|
+
*/
|
|
184
|
+
signTypedData?(address: Hex, typedData: Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
|
|
185
|
+
/**
|
|
186
|
+
* Get a public key to use for encryption. This is equivalent to the
|
|
187
|
+
* ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}
|
|
188
|
+
* for more information.
|
|
189
|
+
*
|
|
190
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
191
|
+
* for the specific keyring for more information about what these options
|
|
192
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
193
|
+
* used (e.g. encrypting with app keys).
|
|
194
|
+
*
|
|
195
|
+
* @param account - The address of the account you want the encryption key for.
|
|
196
|
+
* @param options - Options; differs between keyrings.
|
|
197
|
+
*/
|
|
198
|
+
getEncryptionPublicKey?(account: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`
|
|
201
|
+
* JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}
|
|
202
|
+
* for more information.
|
|
203
|
+
*
|
|
204
|
+
* @param account - The address of the account you want to use to decrypt
|
|
205
|
+
* the message.
|
|
206
|
+
* @param encryptedData - The encrypted data that you want to decrypt.
|
|
207
|
+
* @returns The decrypted data.
|
|
208
|
+
*/
|
|
209
|
+
decryptMessage?(account: Hex, encryptedData: Eip1024EncryptedData): Promise<string>;
|
|
210
|
+
};
|
package/dist/keyring.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.js","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Eip1024EncryptedData } from './encryption-types';\nimport { Hex } from './hex';\nimport { Json } from './json';\nimport type { Transaction, SignedTransaction } from './transaction-types';\n\n/**\n * A Keyring class.\n *\n * This type is used to validate the constructor signature and the `type`\n * static property on Keyring classes. See the {@link Keyring} type for more\n * information.\n */\nexport type KeyringClass<State extends Json> = {\n /**\n * The Keyring constructor. Takes a single parameter, an \"options\" object.\n * See the documentation for the specific keyring for more information about\n * what these options are.\n *\n * @param options - The constructor options. Differs between keyring\n * implementations.\n */\n new (options?: Record<string, unknown>): Keyring<State>;\n\n /**\n * The name of this type of keyring. This must uniquely identify the\n * keyring type.\n */\n type: string;\n};\n\n/**\n * A keyring is something that can sign messages. Keyrings are used to add new\n * signing strategies; each strategy is a new keyring.\n *\n * Each keyring manages a collection of key pairs, which we call \"accounts\".\n * Each account is referred to by its \"address\", which is a unique identifier\n * derived from the public key. The address is always a \"0x\"-prefixed\n * hexidecimal string.\n *\n * The keyring might store the private key for each account as well, but it's\n * not guaranteed. Some keyrings delegate signing, so they don't need the\n * private key directly. The keyring (and in particular the keyring state)\n * should be treated with care though, just in case it does contain sensitive\n * material such as a private key.\n */\nexport type Keyring<State extends Json> = {\n /**\n * The name of this type of keyring. This must match the `type` property of\n * the keyring class.\n */\n type: string;\n\n /**\n * Get the addresses for all accounts in this keyring.\n *\n * @returns A list of the account addresses for this keyring\n */\n getAccounts(): Promise<Hex[]>;\n\n /**\n * Add an account to the keyring.\n *\n * @param number - The number of accounts to add. Usually defaults to 1.\n * @returns A list of the newly added account addresses.\n */\n addAccounts(number: number): Promise<Hex[]>;\n\n /**\n * Serialize the keyring state as a JSON-serializable object.\n *\n * @returns A JSON-serializable representation of the keyring state.\n */\n serialize(): Promise<State>;\n\n /**\n * Deserialize the given keyring state, overwriting any existing state with\n * the serialized state provided.\n *\n * @param state - A JSON-serializable representation of the keyring state.\n */\n deserialize(state: State): Promise<void>;\n\n /**\n * Remove an account from the keyring.\n *\n * @param address - The address of the account to remove.\n */\n removeAccount?(address: Hex): void;\n\n /**\n * Export the private key for one of the keyring accounts.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter is used to allow exporting a\n * private key that is derived from the given account, rather than exporting\n * that account's private key directly.\n *\n * @param address - The address of the account to export.\n * @param options - Export options; differs between keyrings.\n * @returns The non-prefixed, hex-encoded private key that was requested.\n */\n exportAccount?(\n address: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get the \"app key\" address for the given account and origin. An app key is\n * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}\n * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}\n * is used as the unique identifier for the application, and it's used as\n * part of the key derivation process.\n *\n * @param address - The address of the account the app key is derived from.\n * @param origin - The origin of the application.\n * @returns The address of the app key for the given account and origin.\n */\n getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;\n\n /**\n * Sign a transaction. This is equivalent to the `eth_signTransaction`\n * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for\n * more details.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param transaction - The transaction to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed transaction.\n */\n signTransaction?(\n address: Hex,\n transaction: Transaction,\n options?: Record<string, unknown>,\n ): Promise<SignedTransaction>;\n\n /**\n * Sign a message. This is equivalent to an older version of the the\n * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,\n * using the curve secp256k1 the Keccak-256 hash function.\n *\n * For more information about this method and why we still support it, see\n * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signMessage?(\n address: Hex,\n message: string,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n};\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Bytes } from './bytes';
|
|
2
|
+
import { Hex } from './hex';
|
|
3
|
+
export declare type Transaction = LegacyTransaction | EIP2930Transaction | EIP1559Transaction;
|
|
4
|
+
export declare type SignedTransaction = Transaction & Signature;
|
|
5
|
+
export declare type Signature = {
|
|
6
|
+
/**
|
|
7
|
+
* EC signature parameter
|
|
8
|
+
* 32 bytes long sequence.
|
|
9
|
+
*/
|
|
10
|
+
r: Bytes;
|
|
11
|
+
/**
|
|
12
|
+
* EC signature parameter
|
|
13
|
+
* Signature proof.
|
|
14
|
+
* 32 bytes long sequence
|
|
15
|
+
*/
|
|
16
|
+
s: Bytes;
|
|
17
|
+
/**
|
|
18
|
+
* Recovery identifier. It can be either 0x1b or 0x1c
|
|
19
|
+
* 1 byte long sequence
|
|
20
|
+
*/
|
|
21
|
+
yParity: Bytes;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Base Ethereum Transaction
|
|
25
|
+
*/
|
|
26
|
+
export declare type BaseTransaction = {
|
|
27
|
+
/**
|
|
28
|
+
* Sequentially incrementing counter which indicates the transaction
|
|
29
|
+
* number from the account
|
|
30
|
+
*/
|
|
31
|
+
nonce: Bytes;
|
|
32
|
+
/**
|
|
33
|
+
* The address of the sender, that will be signing the transaction
|
|
34
|
+
*/
|
|
35
|
+
from: Hex | Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* The receiving address.
|
|
38
|
+
* If an externally-owned account, the transaction will transfer value.
|
|
39
|
+
* If a contract account, the transaction will execute the contract code.
|
|
40
|
+
*/
|
|
41
|
+
to: Hex | Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* The amount of Ether sent.
|
|
44
|
+
*/
|
|
45
|
+
value: Bytes;
|
|
46
|
+
/**
|
|
47
|
+
* Maximum amount of gas units that this transaction can consume.
|
|
48
|
+
*/
|
|
49
|
+
gasLimit: Bytes;
|
|
50
|
+
/**
|
|
51
|
+
* Arbitrary data.
|
|
52
|
+
*/
|
|
53
|
+
data?: Bytes;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Typed Ethereum Transaction
|
|
57
|
+
*/
|
|
58
|
+
export declare type TypedTransaction = BaseTransaction & {
|
|
59
|
+
/**
|
|
60
|
+
* Transaction type.
|
|
61
|
+
*/
|
|
62
|
+
type: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Ethereum Legacy Transaction
|
|
66
|
+
* Reference: https://ethereum.org/en/developers/docs/transactions/
|
|
67
|
+
*/
|
|
68
|
+
export declare type LegacyTransaction = BaseTransaction & {
|
|
69
|
+
/**
|
|
70
|
+
* Transaction's gas price.
|
|
71
|
+
*/
|
|
72
|
+
gasPrice: Bytes | null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* EIP-2930 Transaction: Optional Access Lists
|
|
76
|
+
* Reference: https://eips.ethereum.org/EIPS/eip-2930
|
|
77
|
+
*/
|
|
78
|
+
export declare type EIP2930Transaction = TypedTransaction & {
|
|
79
|
+
/**
|
|
80
|
+
* Transaction type.
|
|
81
|
+
*/
|
|
82
|
+
type: 1;
|
|
83
|
+
/**
|
|
84
|
+
* Transaction chain ID
|
|
85
|
+
*/
|
|
86
|
+
chainId: Bytes;
|
|
87
|
+
/**
|
|
88
|
+
* List of addresses and storage keys that the transaction plans to access
|
|
89
|
+
*/
|
|
90
|
+
accessList: {
|
|
91
|
+
address: Hex;
|
|
92
|
+
storageKeys: Hex[];
|
|
93
|
+
}[] | {
|
|
94
|
+
address: Uint8Array;
|
|
95
|
+
storageKeys: Uint8Array[];
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* EIP-1559 Transaction: Fee market change for ETH 1.0 chain (Type-2)
|
|
100
|
+
*
|
|
101
|
+
* Reference: https://eips.ethereum.org/EIPS/eip-1559
|
|
102
|
+
*/
|
|
103
|
+
export declare type EIP1559Transaction = TypedTransaction & {
|
|
104
|
+
/**
|
|
105
|
+
* Transaction type.
|
|
106
|
+
*/
|
|
107
|
+
type: 2;
|
|
108
|
+
/**
|
|
109
|
+
* Maximum fee to give to the miner
|
|
110
|
+
*/
|
|
111
|
+
maxPriorityFeePerGas: Bytes;
|
|
112
|
+
/**
|
|
113
|
+
* Maximum total fee
|
|
114
|
+
*/
|
|
115
|
+
maxFeePerGas: Bytes;
|
|
116
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-types.js","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"","sourcesContent":["import { Bytes } from './bytes';\nimport { Hex } from './hex';\n\nexport type Transaction =\n | LegacyTransaction\n | EIP2930Transaction\n | EIP1559Transaction;\n\nexport type SignedTransaction = Transaction & Signature;\n\nexport type Signature = {\n /**\n * EC signature parameter\n * 32 bytes long sequence.\n */\n r: Bytes;\n\n /**\n * EC signature parameter\n * Signature proof.\n * 32 bytes long sequence\n */\n s: Bytes;\n\n /**\n * Recovery identifier. It can be either 0x1b or 0x1c\n * 1 byte long sequence\n */\n yParity: Bytes;\n};\n\n/**\n * Base Ethereum Transaction\n */\nexport type BaseTransaction = {\n /**\n * Sequentially incrementing counter which indicates the transaction\n * number from the account\n */\n nonce: Bytes;\n\n /**\n * The address of the sender, that will be signing the transaction\n */\n from: Hex | Uint8Array;\n\n /**\n * The receiving address.\n * If an externally-owned account, the transaction will transfer value.\n * If a contract account, the transaction will execute the contract code.\n */\n to: Hex | Uint8Array;\n\n /**\n * The amount of Ether sent.\n */\n value: Bytes;\n\n /**\n * Maximum amount of gas units that this transaction can consume.\n */\n gasLimit: Bytes;\n\n /**\n * Arbitrary data.\n */\n data?: Bytes;\n};\n\n/**\n * Typed Ethereum Transaction\n */\nexport type TypedTransaction = BaseTransaction & {\n /**\n * Transaction type.\n */\n type: number;\n};\n\n/**\n * Ethereum Legacy Transaction\n * Reference: https://ethereum.org/en/developers/docs/transactions/\n */\nexport type LegacyTransaction = BaseTransaction & {\n /**\n * Transaction's gas price.\n */\n gasPrice: Bytes | null;\n};\n\n/**\n * EIP-2930 Transaction: Optional Access Lists\n * Reference: https://eips.ethereum.org/EIPS/eip-2930\n */\nexport type EIP2930Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 1;\n\n /**\n * Transaction chain ID\n */\n chainId: Bytes;\n\n /**\n * List of addresses and storage keys that the transaction plans to access\n */\n accessList:\n | { address: Hex; storageKeys: Hex[] }[]\n | { address: Uint8Array; storageKeys: Uint8Array[] }[];\n};\n\n/**\n * EIP-1559 Transaction: Fee market change for ETH 1.0 chain (Type-2)\n *\n * Reference: https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 2;\n\n /**\n * Maximum fee to give to the miner\n */\n maxPriorityFeePerGas: Bytes;\n\n /**\n * Maximum total fee\n */\n maxFeePerGas: Bytes;\n};\n"]}
|