@metamask/utils 6.2.0 → 7.1.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.
Files changed (178) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/cjs/assert.js +116 -0
  3. package/dist/cjs/assert.js.map +1 -0
  4. package/dist/cjs/base64.js +32 -0
  5. package/dist/cjs/base64.js.map +1 -0
  6. package/dist/cjs/bytes.js +255 -0
  7. package/dist/cjs/bytes.js.map +1 -0
  8. package/dist/cjs/caip-types.js +115 -0
  9. package/dist/cjs/caip-types.js.map +1 -0
  10. package/dist/cjs/checksum.js +17 -0
  11. package/dist/cjs/checksum.js.map +1 -0
  12. package/dist/cjs/coercers.js +96 -0
  13. package/dist/cjs/coercers.js.map +1 -0
  14. package/dist/cjs/collections.js +157 -0
  15. package/dist/cjs/collections.js.map +1 -0
  16. package/dist/cjs/encryption-types.js +6 -0
  17. package/dist/cjs/encryption-types.js.map +1 -0
  18. package/dist/cjs/hex.js +107 -0
  19. package/dist/cjs/hex.js.map +1 -0
  20. package/dist/cjs/index.js +37 -0
  21. package/dist/cjs/index.js.map +1 -0
  22. package/dist/cjs/json.js +263 -0
  23. package/dist/cjs/json.js.map +1 -0
  24. package/dist/cjs/keyring.js +6 -0
  25. package/dist/cjs/keyring.js.map +1 -0
  26. package/dist/cjs/logging.js +33 -0
  27. package/dist/cjs/logging.js.map +1 -0
  28. package/dist/cjs/misc.js +111 -0
  29. package/dist/cjs/misc.js.map +1 -0
  30. package/dist/cjs/number.js +52 -0
  31. package/dist/cjs/number.js.map +1 -0
  32. package/dist/cjs/opaque.js +8 -0
  33. package/dist/cjs/opaque.js.map +1 -0
  34. package/dist/cjs/time.js +63 -0
  35. package/dist/cjs/time.js.map +1 -0
  36. package/dist/cjs/transaction-types.js +6 -0
  37. package/dist/cjs/transaction-types.js.map +1 -0
  38. package/dist/cjs/versions.js +79 -0
  39. package/dist/cjs/versions.js.map +1 -0
  40. package/dist/{assert.js → esm/assert.js} +30 -35
  41. package/dist/esm/assert.js.map +1 -0
  42. package/dist/{base64.js → esm/base64.js} +10 -16
  43. package/dist/esm/base64.js.map +1 -0
  44. package/dist/{bytes.js → esm/bytes.js} +50 -93
  45. package/dist/esm/bytes.js.map +1 -0
  46. package/dist/esm/caip-types.js +99 -0
  47. package/dist/esm/caip-types.js.map +1 -0
  48. package/dist/esm/checksum.js +7 -0
  49. package/dist/esm/checksum.js.map +1 -0
  50. package/dist/{coercers.js → esm/coercers.js} +43 -52
  51. package/dist/esm/coercers.js.map +1 -0
  52. package/dist/esm/collections.js +140 -0
  53. package/dist/esm/collections.js.map +1 -0
  54. package/dist/esm/encryption-types.js +3 -0
  55. package/dist/esm/encryption-types.js.map +1 -0
  56. package/dist/esm/hex.js +108 -0
  57. package/dist/esm/hex.js.map +1 -0
  58. package/dist/{index.d.ts → esm/index.js} +3 -0
  59. package/dist/esm/index.js.map +1 -0
  60. package/dist/esm/json.js +301 -0
  61. package/dist/esm/json.js.map +1 -0
  62. package/dist/esm/keyring.js +3 -0
  63. package/dist/esm/keyring.js.map +1 -0
  64. package/dist/{logging.js → esm/logging.js} +5 -14
  65. package/dist/esm/logging.js.map +1 -0
  66. package/dist/{misc.js → esm/misc.js} +37 -42
  67. package/dist/esm/misc.js.map +1 -0
  68. package/dist/{number.js → esm/number.js} +18 -28
  69. package/dist/esm/number.js.map +1 -0
  70. package/dist/esm/opaque.js +5 -0
  71. package/dist/esm/opaque.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/time.js +53 -0
  74. package/dist/esm/time.js.map +1 -0
  75. package/dist/esm/transaction-types.js +3 -0
  76. package/dist/esm/transaction-types.js.map +1 -0
  77. package/dist/esm/versions.js +78 -0
  78. package/dist/esm/versions.js.map +1 -0
  79. package/dist/{assert.d.ts → types/assert.d.ts} +3 -2
  80. package/dist/types/assert.d.ts.map +1 -0
  81. package/dist/{base64.d.ts → types/base64.d.ts} +3 -2
  82. package/dist/types/base64.d.ts.map +1 -0
  83. package/dist/{bytes.d.ts → types/bytes.d.ts} +2 -1
  84. package/dist/types/bytes.d.ts.map +1 -0
  85. package/dist/types/caip-types.d.ts +93 -0
  86. package/dist/types/caip-types.d.ts.map +1 -0
  87. package/dist/types/caip-types.test-d.d.ts +2 -0
  88. package/dist/types/caip-types.test-d.d.ts.map +1 -0
  89. package/dist/{checksum.d.ts → types/checksum.d.ts} +1 -0
  90. package/dist/types/checksum.d.ts.map +1 -0
  91. package/dist/{coercers.d.ts → types/coercers.d.ts} +3 -2
  92. package/dist/types/coercers.d.ts.map +1 -0
  93. package/dist/{collections.d.ts → types/collections.d.ts} +1 -0
  94. package/dist/types/collections.d.ts.map +1 -0
  95. package/dist/{encryption-types.d.ts → types/encryption-types.d.ts} +1 -0
  96. package/dist/types/encryption-types.d.ts.map +1 -0
  97. package/dist/{hex.d.ts → types/hex.d.ts} +2 -1
  98. package/dist/types/hex.d.ts.map +1 -0
  99. package/dist/types/hex.test-d.d.ts +2 -0
  100. package/dist/types/hex.test-d.d.ts.map +1 -0
  101. package/dist/types/index.d.ts +19 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/{json.d.ts → types/json.d.ts} +3 -2
  104. package/dist/types/json.d.ts.map +1 -0
  105. package/dist/types/json.test-d.d.ts +2 -0
  106. package/dist/types/json.test-d.d.ts.map +1 -0
  107. package/dist/{keyring.d.ts → types/keyring.d.ts} +3 -2
  108. package/dist/types/keyring.d.ts.map +1 -0
  109. package/dist/{logging.d.ts → types/logging.d.ts} +2 -1
  110. package/dist/types/logging.d.ts.map +1 -0
  111. package/dist/{misc.d.ts → types/misc.d.ts} +13 -0
  112. package/dist/types/misc.d.ts.map +1 -0
  113. package/dist/types/misc.test-d.d.ts +2 -0
  114. package/dist/types/misc.test-d.d.ts.map +1 -0
  115. package/dist/{number.d.ts → types/number.d.ts} +1 -0
  116. package/dist/types/number.d.ts.map +1 -0
  117. package/dist/{opaque.d.ts → types/opaque.d.ts} +1 -0
  118. package/dist/types/opaque.d.ts.map +1 -0
  119. package/dist/{time.d.ts → types/time.d.ts} +1 -0
  120. package/dist/types/time.d.ts.map +1 -0
  121. package/dist/{transaction-types.d.ts → types/transaction-types.d.ts} +3 -2
  122. package/dist/types/transaction-types.d.ts.map +1 -0
  123. package/dist/{versions.d.ts → types/versions.d.ts} +3 -2
  124. package/dist/types/versions.d.ts.map +1 -0
  125. package/package.json +40 -20
  126. package/dist/__fixtures__/bytes.d.ts +0 -25
  127. package/dist/__fixtures__/bytes.js +0 -234
  128. package/dist/__fixtures__/bytes.js.map +0 -1
  129. package/dist/__fixtures__/coercions.d.ts +0 -5
  130. package/dist/__fixtures__/coercions.js +0 -22
  131. package/dist/__fixtures__/coercions.js.map +0 -1
  132. package/dist/__fixtures__/index.d.ts +0 -4
  133. package/dist/__fixtures__/index.js +0 -21
  134. package/dist/__fixtures__/index.js.map +0 -1
  135. package/dist/__fixtures__/json.d.ts +0 -1226
  136. package/dist/__fixtures__/json.js +0 -1491
  137. package/dist/__fixtures__/json.js.map +0 -1
  138. package/dist/__fixtures__/numbers.d.ts +0 -5
  139. package/dist/__fixtures__/numbers.js +0 -56
  140. package/dist/__fixtures__/numbers.js.map +0 -1
  141. package/dist/assert.js.map +0 -1
  142. package/dist/base64.js.map +0 -1
  143. package/dist/bytes.js.map +0 -1
  144. package/dist/checksum.js +0 -7
  145. package/dist/checksum.js.map +0 -1
  146. package/dist/coercers.js.map +0 -1
  147. package/dist/collections.js +0 -109
  148. package/dist/collections.js.map +0 -1
  149. package/dist/encryption-types.js +0 -3
  150. package/dist/encryption-types.js.map +0 -1
  151. package/dist/hex.js +0 -134
  152. package/dist/hex.js.map +0 -1
  153. package/dist/hex.test-d.d.ts +0 -1
  154. package/dist/hex.test-d.js +0 -16
  155. package/dist/hex.test-d.js.map +0 -1
  156. package/dist/index.js +0 -34
  157. package/dist/index.js.map +0 -1
  158. package/dist/json.js +0 -346
  159. package/dist/json.js.map +0 -1
  160. package/dist/json.test-d.d.ts +0 -1
  161. package/dist/json.test-d.js +0 -62
  162. package/dist/json.test-d.js.map +0 -1
  163. package/dist/keyring.js +0 -3
  164. package/dist/keyring.js.map +0 -1
  165. package/dist/logging.js.map +0 -1
  166. package/dist/misc.js.map +0 -1
  167. package/dist/misc.test-d.d.ts +0 -1
  168. package/dist/misc.test-d.js +0 -97
  169. package/dist/misc.test-d.js.map +0 -1
  170. package/dist/number.js.map +0 -1
  171. package/dist/opaque.js +0 -3
  172. package/dist/opaque.js.map +0 -1
  173. package/dist/time.js +0 -67
  174. package/dist/time.js.map +0 -1
  175. package/dist/transaction-types.js +0 -3
  176. package/dist/transaction-types.js.map +0 -1
  177. package/dist/versions.js +0 -95
  178. package/dist/versions.js.map +0 -1
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ UnsafeJsonStruct: function() {
13
+ return UnsafeJsonStruct;
14
+ },
15
+ JsonStruct: function() {
16
+ return JsonStruct;
17
+ },
18
+ isValidJson: function() {
19
+ return isValidJson;
20
+ },
21
+ getSafeJson: function() {
22
+ return getSafeJson;
23
+ },
24
+ getJsonSize: function() {
25
+ return getJsonSize;
26
+ },
27
+ jsonrpc2: function() {
28
+ return jsonrpc2;
29
+ },
30
+ JsonRpcVersionStruct: function() {
31
+ return JsonRpcVersionStruct;
32
+ },
33
+ JsonRpcIdStruct: function() {
34
+ return JsonRpcIdStruct;
35
+ },
36
+ JsonRpcErrorStruct: function() {
37
+ return JsonRpcErrorStruct;
38
+ },
39
+ JsonRpcParamsStruct: function() {
40
+ return JsonRpcParamsStruct;
41
+ },
42
+ JsonRpcRequestStruct: function() {
43
+ return JsonRpcRequestStruct;
44
+ },
45
+ JsonRpcNotificationStruct: function() {
46
+ return JsonRpcNotificationStruct;
47
+ },
48
+ isJsonRpcNotification: function() {
49
+ return isJsonRpcNotification;
50
+ },
51
+ assertIsJsonRpcNotification: function() {
52
+ return assertIsJsonRpcNotification;
53
+ },
54
+ isJsonRpcRequest: function() {
55
+ return isJsonRpcRequest;
56
+ },
57
+ assertIsJsonRpcRequest: function() {
58
+ return assertIsJsonRpcRequest;
59
+ },
60
+ PendingJsonRpcResponseStruct: function() {
61
+ return PendingJsonRpcResponseStruct;
62
+ },
63
+ JsonRpcSuccessStruct: function() {
64
+ return JsonRpcSuccessStruct;
65
+ },
66
+ JsonRpcFailureStruct: function() {
67
+ return JsonRpcFailureStruct;
68
+ },
69
+ JsonRpcResponseStruct: function() {
70
+ return JsonRpcResponseStruct;
71
+ },
72
+ isPendingJsonRpcResponse: function() {
73
+ return isPendingJsonRpcResponse;
74
+ },
75
+ assertIsPendingJsonRpcResponse: function() {
76
+ return assertIsPendingJsonRpcResponse;
77
+ },
78
+ isJsonRpcResponse: function() {
79
+ return isJsonRpcResponse;
80
+ },
81
+ assertIsJsonRpcResponse: function() {
82
+ return assertIsJsonRpcResponse;
83
+ },
84
+ isJsonRpcSuccess: function() {
85
+ return isJsonRpcSuccess;
86
+ },
87
+ assertIsJsonRpcSuccess: function() {
88
+ return assertIsJsonRpcSuccess;
89
+ },
90
+ isJsonRpcFailure: function() {
91
+ return isJsonRpcFailure;
92
+ },
93
+ assertIsJsonRpcFailure: function() {
94
+ return assertIsJsonRpcFailure;
95
+ },
96
+ isJsonRpcError: function() {
97
+ return isJsonRpcError;
98
+ },
99
+ assertIsJsonRpcError: function() {
100
+ return assertIsJsonRpcError;
101
+ },
102
+ getJsonRpcIdValidator: function() {
103
+ return getJsonRpcIdValidator;
104
+ }
105
+ });
106
+ const _superstruct = require("superstruct");
107
+ const _assert = require("./assert");
108
+ /**
109
+ * A struct to check if the given value is finite number. Superstruct's
110
+ * `number()` struct does not check if the value is finite.
111
+ *
112
+ * @returns A struct to check if the given value is finite number.
113
+ */ const finiteNumber = ()=>(0, _superstruct.define)('finite number', (value)=>{
114
+ return (0, _superstruct.is)(value, (0, _superstruct.number)()) && Number.isFinite(value);
115
+ });
116
+ const UnsafeJsonStruct = (0, _superstruct.union)([
117
+ (0, _superstruct.literal)(null),
118
+ (0, _superstruct.boolean)(),
119
+ finiteNumber(),
120
+ (0, _superstruct.string)(),
121
+ (0, _superstruct.array)((0, _superstruct.lazy)(()=>UnsafeJsonStruct)),
122
+ (0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.lazy)(()=>UnsafeJsonStruct))
123
+ ]);
124
+ const JsonStruct = (0, _superstruct.coerce)(UnsafeJsonStruct, (0, _superstruct.any)(), (value)=>{
125
+ (0, _assert.assertStruct)(value, UnsafeJsonStruct);
126
+ return JSON.parse(JSON.stringify(value, (propKey, propValue)=>{
127
+ // Strip __proto__ and constructor properties to prevent prototype pollution.
128
+ if (propKey === '__proto__' || propKey === 'constructor') {
129
+ return undefined;
130
+ }
131
+ return propValue;
132
+ }));
133
+ });
134
+ function isValidJson(value) {
135
+ try {
136
+ getSafeJson(value);
137
+ return true;
138
+ } catch {
139
+ return false;
140
+ }
141
+ }
142
+ function getSafeJson(value) {
143
+ return (0, _superstruct.create)(value, JsonStruct);
144
+ }
145
+ function getJsonSize(value) {
146
+ (0, _assert.assertStruct)(value, JsonStruct, 'Invalid JSON value');
147
+ const json = JSON.stringify(value);
148
+ return new TextEncoder().encode(json).byteLength;
149
+ }
150
+ const jsonrpc2 = '2.0';
151
+ const JsonRpcVersionStruct = (0, _superstruct.literal)(jsonrpc2);
152
+ const JsonRpcIdStruct = (0, _superstruct.nullable)((0, _superstruct.union)([
153
+ (0, _superstruct.number)(),
154
+ (0, _superstruct.string)()
155
+ ]));
156
+ const JsonRpcErrorStruct = (0, _superstruct.object)({
157
+ code: (0, _superstruct.integer)(),
158
+ message: (0, _superstruct.string)(),
159
+ data: (0, _superstruct.optional)(JsonStruct),
160
+ stack: (0, _superstruct.optional)((0, _superstruct.string)())
161
+ });
162
+ const JsonRpcParamsStruct = (0, _superstruct.optional)((0, _superstruct.union)([
163
+ (0, _superstruct.record)((0, _superstruct.string)(), JsonStruct),
164
+ (0, _superstruct.array)(JsonStruct)
165
+ ]));
166
+ const JsonRpcRequestStruct = (0, _superstruct.object)({
167
+ id: JsonRpcIdStruct,
168
+ jsonrpc: JsonRpcVersionStruct,
169
+ method: (0, _superstruct.string)(),
170
+ params: JsonRpcParamsStruct
171
+ });
172
+ const JsonRpcNotificationStruct = (0, _superstruct.omit)(JsonRpcRequestStruct, [
173
+ 'id'
174
+ ]);
175
+ function isJsonRpcNotification(value) {
176
+ return (0, _superstruct.is)(value, JsonRpcNotificationStruct);
177
+ }
178
+ function assertIsJsonRpcNotification(value, // eslint-disable-next-line @typescript-eslint/naming-convention
179
+ ErrorWrapper) {
180
+ (0, _assert.assertStruct)(value, JsonRpcNotificationStruct, 'Invalid JSON-RPC notification', ErrorWrapper);
181
+ }
182
+ function isJsonRpcRequest(value) {
183
+ return (0, _superstruct.is)(value, JsonRpcRequestStruct);
184
+ }
185
+ function assertIsJsonRpcRequest(value, // eslint-disable-next-line @typescript-eslint/naming-convention
186
+ ErrorWrapper) {
187
+ (0, _assert.assertStruct)(value, JsonRpcRequestStruct, 'Invalid JSON-RPC request', ErrorWrapper);
188
+ }
189
+ const PendingJsonRpcResponseStruct = (0, _superstruct.object)({
190
+ id: JsonRpcIdStruct,
191
+ jsonrpc: JsonRpcVersionStruct,
192
+ result: (0, _superstruct.optional)((0, _superstruct.unknown)()),
193
+ error: (0, _superstruct.optional)(JsonRpcErrorStruct)
194
+ });
195
+ const JsonRpcSuccessStruct = (0, _superstruct.object)({
196
+ id: JsonRpcIdStruct,
197
+ jsonrpc: JsonRpcVersionStruct,
198
+ result: JsonStruct
199
+ });
200
+ const JsonRpcFailureStruct = (0, _superstruct.object)({
201
+ id: JsonRpcIdStruct,
202
+ jsonrpc: JsonRpcVersionStruct,
203
+ error: JsonRpcErrorStruct
204
+ });
205
+ const JsonRpcResponseStruct = (0, _superstruct.union)([
206
+ JsonRpcSuccessStruct,
207
+ JsonRpcFailureStruct
208
+ ]);
209
+ function isPendingJsonRpcResponse(response) {
210
+ return (0, _superstruct.is)(response, PendingJsonRpcResponseStruct);
211
+ }
212
+ function assertIsPendingJsonRpcResponse(response, // eslint-disable-next-line @typescript-eslint/naming-convention
213
+ ErrorWrapper) {
214
+ (0, _assert.assertStruct)(response, PendingJsonRpcResponseStruct, 'Invalid pending JSON-RPC response', ErrorWrapper);
215
+ }
216
+ function isJsonRpcResponse(response) {
217
+ return (0, _superstruct.is)(response, JsonRpcResponseStruct);
218
+ }
219
+ function assertIsJsonRpcResponse(value, // eslint-disable-next-line @typescript-eslint/naming-convention
220
+ ErrorWrapper) {
221
+ (0, _assert.assertStruct)(value, JsonRpcResponseStruct, 'Invalid JSON-RPC response', ErrorWrapper);
222
+ }
223
+ function isJsonRpcSuccess(value) {
224
+ return (0, _superstruct.is)(value, JsonRpcSuccessStruct);
225
+ }
226
+ function assertIsJsonRpcSuccess(value, // eslint-disable-next-line @typescript-eslint/naming-convention
227
+ ErrorWrapper) {
228
+ (0, _assert.assertStruct)(value, JsonRpcSuccessStruct, 'Invalid JSON-RPC success response', ErrorWrapper);
229
+ }
230
+ function isJsonRpcFailure(value) {
231
+ return (0, _superstruct.is)(value, JsonRpcFailureStruct);
232
+ }
233
+ function assertIsJsonRpcFailure(value, // eslint-disable-next-line @typescript-eslint/naming-convention
234
+ ErrorWrapper) {
235
+ (0, _assert.assertStruct)(value, JsonRpcFailureStruct, 'Invalid JSON-RPC failure response', ErrorWrapper);
236
+ }
237
+ function isJsonRpcError(value) {
238
+ return (0, _superstruct.is)(value, JsonRpcErrorStruct);
239
+ }
240
+ function assertIsJsonRpcError(value, // eslint-disable-next-line @typescript-eslint/naming-convention
241
+ ErrorWrapper) {
242
+ (0, _assert.assertStruct)(value, JsonRpcErrorStruct, 'Invalid JSON-RPC error', ErrorWrapper);
243
+ }
244
+ function getJsonRpcIdValidator(options) {
245
+ const { permitEmptyString, permitFractions, permitNull } = {
246
+ permitEmptyString: true,
247
+ permitFractions: false,
248
+ permitNull: true,
249
+ ...options
250
+ };
251
+ /**
252
+ * Type guard for {@link JsonRpcId}.
253
+ *
254
+ * @param id - The JSON-RPC ID value to check.
255
+ * @returns Whether the given ID is valid per the options given to the
256
+ * factory.
257
+ */ const isValidJsonRpcId = (id)=>{
258
+ return Boolean(typeof id === 'number' && (permitFractions || Number.isInteger(id)) || typeof id === 'string' && (permitEmptyString || id.length > 0) || permitNull && id === null);
259
+ };
260
+ return isValidJsonRpcId;
261
+ }
262
+
263
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n omit,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { 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 = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\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 try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson<Type extends Json = Json>(value: unknown): Type {\n return create(value, JsonStruct) as Type;\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"],"names":["UnsafeJsonStruct","JsonStruct","isValidJson","getSafeJson","getJsonSize","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","JsonRpcParamsStruct","JsonRpcRequestStruct","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","finiteNumber","define","value","is","number","Number","isFinite","union","literal","boolean","string","array","lazy","record","coerce","any","assertStruct","JSON","parse","stringify","propKey","propValue","undefined","create","json","TextEncoder","encode","byteLength","nullable","object","code","integer","message","data","optional","stack","id","jsonrpc","method","params","omit","ErrorWrapper","result","unknown","error","response","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":";;;;;;;;;;;IAsDaA,gBAAgB;eAAhBA;;IAkBAC,UAAU;eAAVA;;IAoBGC,WAAW;eAAXA;;IAqBAC,WAAW;eAAXA;;IAUAC,WAAW;eAAXA;;IAUHC,QAAQ;eAARA;;IACAC,oBAAoB;eAApBA;;IAQAC,eAAe;eAAfA;;IAUAC,kBAAkB;eAAlBA;;IA2BAC,mBAAmB;eAAnBA;;IAKAC,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AY,EACVd,OACAhB,sBACA,qCACAuD;AAEJ;AAQO,SAAS9C,iBAAiBO,KAAc;IAC7C,OAAOC,IAAAA,eAAE,EAACD,OAAOf;AACnB;AAUO,SAASS,uBACdM,KAAc,EACd,gEAAgE;AAChEuC,YAAwC;IAExCzB,IAAAA,oBAAY,EACVd,OACAf,sBACA,qCACAsD;AAEJ;AAQO,SAAS5C,eAAeK,KAAc;IAC3C,OAAOC,IAAAA,eAAE,EAACD,OAAOzB;AACnB;AAUO,SAASqB,qBACdI,KAAc,EACd,gEAAgE;AAChEuC,YAAwC;IAExCzB,IAAAA,oBAAY,EACVd,OACAzB,oBACA,0BACAgE;AAEJ;AA+BO,SAAS1C,sBAAsB+C,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAACd;QACxB,OAAOe,QACL,AAAC,OAAOf,OAAO,YAAaY,CAAAA,mBAAmB3C,OAAO+C,SAAS,CAAChB,GAAE,KAC/D,OAAOA,OAAO,YAAaW,CAAAA,qBAAqBX,GAAGiB,MAAM,GAAG,CAAA,KAC5DJ,cAAcb,OAAO;IAE5B;IAEA,OAAOc;AACT"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/keyring.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ createProjectLogger: function() {
13
+ return createProjectLogger;
14
+ },
15
+ createModuleLogger: function() {
16
+ return createModuleLogger;
17
+ }
18
+ });
19
+ const _debug = /*#__PURE__*/ _interop_require_default(require("debug"));
20
+ function _interop_require_default(obj) {
21
+ return obj && obj.__esModule ? obj : {
22
+ default: obj
23
+ };
24
+ }
25
+ const globalLogger = (0, _debug.default)('metamask');
26
+ function createProjectLogger(projectName) {
27
+ return globalLogger.extend(projectName);
28
+ }
29
+ function createModuleLogger(projectLogger, moduleName) {
30
+ return projectLogger.extend(moduleName);
31
+ }
32
+
33
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/logging.ts"],"sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"],"names":["createProjectLogger","createModuleLogger","globalLogger","debug","projectName","extend","projectLogger","moduleName"],"mappings":";;;;;;;;;;;IAiBgBA,mBAAmB;eAAnBA;;IAkBAC,kBAAkB;eAAlBA;;;8DAlCE;;;;;;AAElB,MAAMC,eAAeC,IAAAA,cAAK,EAAC;AAcpB,SAASH,oBAAoBI,WAAmB;IACrD,OAAOF,aAAaG,MAAM,CAACD;AAC7B;AAgBO,SAASH,mBACdK,aAAuB,EACvBC,UAAkB;IAElB,OAAOD,cAAcD,MAAM,CAACE;AAC9B"}
@@ -0,0 +1,111 @@
1
+ //
2
+ // Types
3
+ //
4
+ /**
5
+ * Makes every specified property of the specified object type mutable.
6
+ *
7
+ * @template ObjectValue - The object whose readonly properties to make mutable.
8
+ * @template TargetKey - The property key(s) to make mutable.
9
+ */ "use strict";
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ function _export(target, all) {
14
+ for(var name in all)Object.defineProperty(target, name, {
15
+ enumerable: true,
16
+ get: all[name]
17
+ });
18
+ }
19
+ _export(exports, {
20
+ JsonSize: function() {
21
+ return JsonSize;
22
+ },
23
+ isNonEmptyArray: function() {
24
+ return isNonEmptyArray;
25
+ },
26
+ isNullOrUndefined: function() {
27
+ return isNullOrUndefined;
28
+ },
29
+ isObject: function() {
30
+ return isObject;
31
+ },
32
+ hasProperty: function() {
33
+ return hasProperty;
34
+ },
35
+ getKnownPropertyNames: function() {
36
+ return getKnownPropertyNames;
37
+ },
38
+ ESCAPE_CHARACTERS_REGEXP: function() {
39
+ return ESCAPE_CHARACTERS_REGEXP;
40
+ },
41
+ isPlainObject: function() {
42
+ return isPlainObject;
43
+ },
44
+ isASCII: function() {
45
+ return isASCII;
46
+ },
47
+ calculateStringSize: function() {
48
+ return calculateStringSize;
49
+ },
50
+ calculateNumberSize: function() {
51
+ return calculateNumberSize;
52
+ }
53
+ });
54
+ function isNonEmptyArray(value) {
55
+ return Array.isArray(value) && value.length > 0;
56
+ }
57
+ function isNullOrUndefined(value) {
58
+ return value === null || value === undefined;
59
+ }
60
+ function isObject(value) {
61
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
62
+ }
63
+ const hasProperty = (objectToCheck, name)=>Object.hasOwnProperty.call(objectToCheck, name);
64
+ function getKnownPropertyNames(object) {
65
+ return Object.getOwnPropertyNames(object);
66
+ }
67
+ var JsonSize;
68
+ (function(JsonSize) {
69
+ JsonSize[JsonSize["Null"] = 4] = "Null";
70
+ JsonSize[JsonSize["Comma"] = 1] = "Comma";
71
+ JsonSize[JsonSize["Wrapper"] = 1] = "Wrapper";
72
+ JsonSize[JsonSize["True"] = 4] = "True";
73
+ JsonSize[JsonSize["False"] = 5] = "False";
74
+ JsonSize[JsonSize["Quote"] = 1] = "Quote";
75
+ JsonSize[JsonSize["Colon"] = 1] = "Colon";
76
+ JsonSize[JsonSize[// eslint-disable-next-line @typescript-eslint/no-shadow
77
+ "Date"] = 24] = "Date";
78
+ })(JsonSize || (JsonSize = {}));
79
+ const ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
80
+ function isPlainObject(value) {
81
+ if (typeof value !== 'object' || value === null) {
82
+ return false;
83
+ }
84
+ try {
85
+ let proto = value;
86
+ while(Object.getPrototypeOf(proto) !== null){
87
+ proto = Object.getPrototypeOf(proto);
88
+ }
89
+ return Object.getPrototypeOf(value) === proto;
90
+ } catch (_) {
91
+ return false;
92
+ }
93
+ }
94
+ function isASCII(character) {
95
+ return character.charCodeAt(0) <= 127;
96
+ }
97
+ function calculateStringSize(value) {
98
+ const size = value.split('').reduce((total, character)=>{
99
+ if (isASCII(character)) {
100
+ return total + 1;
101
+ }
102
+ return total + 2;
103
+ }, 0);
104
+ // Also detect characters that need backslash escape
105
+ return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;
106
+ }
107
+ function calculateNumberSize(value) {
108
+ return value.toString().length;
109
+ }
110
+
111
+ //# sourceMappingURL=misc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/misc.ts"],"sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck &\n Record<\n Property,\n Property extends keyof ObjectToCheck ? ObjectToCheck[Property] : unknown\n > => Object.hasOwnProperty.call(objectToCheck, name);\n\n/**\n * `Object.getOwnPropertyNames()` is intentionally generic: it returns the\n * immediate property names of an object, but it cannot make guarantees about\n * the contents of that object, so the type of the property names is merely\n * `string[]`. While this is technically accurate, it is also unnecessary if we\n * have an object with a type that we own (such as an enum).\n *\n * @param object - The plain object.\n * @returns The own property names of the object which are assigned a type\n * derived from the object itself.\n */\nexport function getKnownPropertyNames<Key extends PropertyKey>(\n object: Partial<Record<Key, any>>,\n): Key[] {\n return Object.getOwnPropertyNames(object) as Key[];\n}\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"],"names":["isNonEmptyArray","isNullOrUndefined","isObject","hasProperty","getKnownPropertyNames","ESCAPE_CHARACTERS_REGEXP","isPlainObject","isASCII","calculateStringSize","calculateNumberSize","value","Array","isArray","length","undefined","Boolean","objectToCheck","name","Object","hasOwnProperty","call","object","getOwnPropertyNames","JsonSize","Null","Comma","Wrapper","True","False","Quote","Colon","Date","proto","getPrototypeOf","_","character","charCodeAt","size","split","reduce","total","match","toString"],"mappings":"AAAA,EAAE;AACF,QAAQ;AACR,EAAE;AAEF;;;;;CAKC;;;;;;;;;;;;;;IAwCeA,eAAe;eAAfA;;IAYAC,iBAAiB;eAAjBA;;IAWAC,QAAQ;eAARA;;IAgBHC,WAAW;eAAXA;;IAwBGC,qBAAqB;eAArBA;;IA0BHC,wBAAwB;eAAxBA;;IASGC,aAAa;eAAbA;;IAuBAC,OAAO;eAAPA;;IAUAC,mBAAmB;eAAnBA;;IAkBAC,mBAAmB;eAAnBA;;;AArJT,SAAST,gBACdU,KAAgB;IAEhB,OAAOC,MAAMC,OAAO,CAACF,UAAUA,MAAMG,MAAM,GAAG;AAChD;AAQO,SAASZ,kBAAkBS,KAAc;IAC9C,OAAOA,UAAU,QAAQA,UAAUI;AACrC;AASO,SAASZ,SAASQ,KAAc;IACrC,OAAOK,QAAQL,UAAU,OAAOA,UAAU,YAAY,CAACC,MAAMC,OAAO,CAACF;AACvE;AAcO,MAAMP,cAAc,CAKzBa,eACAC,OAKKC,OAAOC,cAAc,CAACC,IAAI,CAAC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defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ numberToHex: function() {
13
+ return numberToHex;
14
+ },
15
+ bigIntToHex: function() {
16
+ return bigIntToHex;
17
+ },
18
+ hexToNumber: function() {
19
+ return hexToNumber;
20
+ },
21
+ hexToBigInt: function() {
22
+ return hexToBigInt;
23
+ }
24
+ });
25
+ const _assert = require("./assert");
26
+ const _hex = require("./hex");
27
+ const numberToHex = (value)=>{
28
+ (0, _assert.assert)(typeof value === 'number', 'Value must be a number.');
29
+ (0, _assert.assert)(value >= 0, 'Value must be a non-negative number.');
30
+ (0, _assert.assert)(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToHex` instead.');
31
+ return (0, _hex.add0x)(value.toString(16));
32
+ };
33
+ const bigIntToHex = (value)=>{
34
+ (0, _assert.assert)(typeof value === 'bigint', 'Value must be a bigint.');
35
+ (0, _assert.assert)(value >= 0, 'Value must be a non-negative bigint.');
36
+ return (0, _hex.add0x)(value.toString(16));
37
+ };
38
+ const hexToNumber = (value)=>{
39
+ (0, _hex.assertIsHexString)(value);
40
+ // `parseInt` accepts values without the "0x"-prefix, whereas `Number` does
41
+ // not. Using this is slightly faster than `Number(add0x(value))`.
42
+ const numberValue = parseInt(value, 16);
43
+ (0, _assert.assert)(Number.isSafeInteger(numberValue), 'Value is not a safe integer. Use `hexToBigInt` instead.');
44
+ return numberValue;
45
+ };
46
+ const hexToBigInt = (value)=>{
47
+ (0, _hex.assertIsHexString)(value);
48
+ // The `BigInt` constructor requires the "0x"-prefix to parse a hex string.
49
+ return BigInt((0, _hex.add0x)(value));
50
+ };
51
+
52
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/number.ts"],"sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString } from './hex';\n\n/**\n * Convert a number to a hexadecimal string. This verifies that the number is a\n * non-negative safe integer.\n *\n * To convert a `bigint` to a hexadecimal string instead, use\n * {@link bigIntToHex}.\n *\n * @example\n * ```typescript\n * numberToHex(0); // '0x0'\n * numberToHex(1); // '0x1'\n * numberToHex(16); // '0x10'\n * ```\n * @param value - The number to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the number is not a non-negative safe integer.\n */\nexport const numberToHex = (value: number): string => {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToHex` instead.',\n );\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`\n * is a non-negative integer.\n *\n * To convert a number to a hexadecimal string instead, use {@link numberToHex}.\n *\n * @example\n * ```typescript\n * bigIntToHex(0n); // '0x0'\n * bigIntToHex(1n); // '0x1'\n * bigIntToHex(16n); // '0x10'\n * ```\n * @param value - The `bigint` to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the `bigint` is not a non-negative integer.\n */\nexport const bigIntToHex = (value: bigint): string => {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= 0, 'Value must be a non-negative bigint.');\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a hexadecimal string to a number. This verifies that the string is a\n * valid hex string, and that the resulting number is a safe integer. Both\n * \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a `bigint` instead, use\n * {@link hexToBigInt}.\n *\n * @example\n * ```typescript\n * hexToNumber('0x0'); // 0\n * hexToNumber('0x1'); // 1\n * hexToNumber('0x10'); // 16\n * ```\n * @param value - The hexadecimal string to convert to a number.\n * @returns The number.\n * @throws If the value is not a valid hexadecimal string, or if the resulting\n * number is not a safe integer.\n */\nexport const hexToNumber = (value: string): number => {\n assertIsHexString(value);\n\n // `parseInt` accepts values without the \"0x\"-prefix, whereas `Number` does\n // not. Using this is slightly faster than `Number(add0x(value))`.\n const numberValue = parseInt(value, 16);\n\n assert(\n Number.isSafeInteger(numberValue),\n 'Value is not a safe integer. Use `hexToBigInt` instead.',\n );\n\n return numberValue;\n};\n\n/**\n * Convert a hexadecimal string to a `bigint`. This verifies that the string is\n * a valid hex string. Both \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a number instead, use {@link hexToNumber}.\n *\n * @example\n * ```typescript\n * hexToBigInt('0x0'); // 0n\n * hexToBigInt('0x1'); // 1n\n * hexToBigInt('0x10'); // 16n\n * ```\n * @param value - The hexadecimal string to convert to a `bigint`.\n * @returns The `bigint`.\n * @throws If the value is not a valid hexadecimal string.\n */\nexport const hexToBigInt = (value: string): bigint => {\n assertIsHexString(value);\n\n // The `BigInt` constructor requires the \"0x\"-prefix to parse a hex string.\n return BigInt(add0x(value));\n};\n"],"names":["numberToHex","bigIntToHex","hexToNumber","hexToBigInt","value","assert","Number","isSafeInteger","add0x","toString","assertIsHexString","numberValue","parseInt","BigInt"],"mappings":";;;;;;;;;;;IAoBaA,WAAW;eAAXA;;IA2BAC,WAAW;eAAXA;;IA0BAC,WAAW;eAAXA;;IA+BAC,WAAW;eAAXA;;;wBAxGU;qBACkB;AAmBlC,MAAMH,cAAc,CAACI;IAC1BC,IAAAA,cAAM,EAAC,OAAOD,UAAU,UAAU;IAClCC,IAAAA,cAAM,EAACD,SAAS,GAAG;IACnBC,IAAAA,cAAM,EACJC,OAAOC,aAAa,CAACH,QACrB;IAGF,OAAOI,IAAAA,UAAK,EAACJ,MAAMK,QAAQ,CAAC;AAC9B;AAkBO,MAAMR,cAAc,CAACG;IAC1BC,IAAAA,cAAM,EAAC,OAAOD,UAAU,UAAU;IAClCC,IAAAA,cAAM,EAACD,SAAS,GAAG;IAEnB,OAAOI,IAAAA,UAAK,EAACJ,MAAMK,QAAQ,CAAC;AAC9B;AAqBO,MAAMP,cAAc,CAACE;IAC1BM,IAAAA,sBAAiB,EAACN;IAElB,2EAA2E;IAC3E,kEAAkE;IAClE,MAAMO,cAAcC,SAASR,OAAO;IAEpCC,IAAAA,cAAM,EACJC,OAAOC,aAAa,CAACI,cACrB;IAGF,OAAOA;AACT;AAkBO,MAAMR,cAAc,CAACC;IAC1BM,IAAAA,sBAAiB,EAACN;IAElB,2EAA2E;IAC3E,OAAOS,OAAOL,IAAAA,UAAK,EAACJ;AACtB"}
@@ -0,0 +1,8 @@
1
+ // We use a symbol property name instead of { _type: Brand }, because that would show up in IDE suggestions,
2
+ // while internal symbols do not.
3
+ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+
8
+ //# sourceMappingURL=opaque.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/opaque.ts"],"sourcesContent":["// We use a symbol property name instead of { _type: Brand }, because that would show up in IDE suggestions,\n// while internal symbols do not.\ndeclare const brand: unique symbol;\nexport type Opaque<Base, Brand extends symbol> = Base & { [brand]: Brand };\n"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,iCAAiC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Common duration constants, in milliseconds.
3
+ */ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ function _export(target, all) {
8
+ for(var name in all)Object.defineProperty(target, name, {
9
+ enumerable: true,
10
+ get: all[name]
11
+ });
12
+ }
13
+ _export(exports, {
14
+ Duration: function() {
15
+ return Duration;
16
+ },
17
+ inMilliseconds: function() {
18
+ return inMilliseconds;
19
+ },
20
+ timeSince: function() {
21
+ return timeSince;
22
+ }
23
+ });
24
+ var Duration;
25
+ (function(Duration) {
26
+ Duration[Duration[/**
27
+ * A millisecond.
28
+ */ "Millisecond"] = 1] = "Millisecond";
29
+ Duration[Duration[/**
30
+ * A second, in milliseconds.
31
+ */ "Second"] = 1000] = "Second";
32
+ Duration[Duration[/**
33
+ * A minute, in milliseconds.
34
+ */ "Minute"] = 60000] = "Minute";
35
+ Duration[Duration[/**
36
+ * An hour, in milliseconds.
37
+ */ "Hour"] = 3600000] = "Hour";
38
+ Duration[Duration[/**
39
+ * A day, in milliseconds.
40
+ */ "Day"] = 86400000] = "Day";
41
+ Duration[Duration[/**
42
+ * A week, in milliseconds.
43
+ */ "Week"] = 604800000] = "Week";
44
+ Duration[Duration[/**
45
+ * A year, in milliseconds.
46
+ */ "Year"] = 31536000000] = "Year";
47
+ })(Duration || (Duration = {}));
48
+ const isNonNegativeInteger = (number)=>Number.isInteger(number) && number >= 0;
49
+ const assertIsNonNegativeInteger = (number, name)=>{
50
+ if (!isNonNegativeInteger(number)) {
51
+ throw new Error(`"${name}" must be a non-negative integer. Received: "${number}".`);
52
+ }
53
+ };
54
+ function inMilliseconds(count, duration) {
55
+ assertIsNonNegativeInteger(count, 'count');
56
+ return count * duration;
57
+ }
58
+ function timeSince(timestamp) {
59
+ assertIsNonNegativeInteger(timestamp, 'timestamp');
60
+ return Date.now() - timestamp;
61
+ }
62
+
63
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/time.ts"],"sourcesContent":["/**\n * Common duration constants, in milliseconds.\n */\nexport enum Duration {\n /**\n * A millisecond.\n */\n Millisecond = 1,\n\n /**\n * A second, in milliseconds.\n */\n Second = 1000, // Millisecond * 1000\n\n /**\n * A minute, in milliseconds.\n */\n Minute = 60_000, // Second * 60\n\n /**\n * An hour, in milliseconds.\n */\n Hour = 3_600_000, // Minute * 60\n\n /**\n * A day, in milliseconds.\n */\n Day = 86_400_000, // Hour * 24\n\n /**\n * A week, in milliseconds.\n */\n Week = 604_800_000, // Day * 7\n\n /**\n * A year, in milliseconds.\n */\n Year = 31_536_000_000, // Day * 365\n}\n\nconst isNonNegativeInteger = (number: number) =>\n Number.isInteger(number) && number >= 0;\n\nconst assertIsNonNegativeInteger = (number: number, name: string) => {\n if (!isNonNegativeInteger(number)) {\n throw new Error(\n `\"${name}\" must be a non-negative integer. Received: \"${number}\".`,\n );\n }\n};\n\n/**\n * Calculates the millisecond value of the specified number of units of time.\n *\n * @param count - The number of units of time.\n * @param duration - The unit of time to count.\n * @returns The count multiplied by the specified duration.\n */\nexport function inMilliseconds(count: number, duration: Duration): number {\n assertIsNonNegativeInteger(count, 'count');\n return count * duration;\n}\n\n/**\n * Gets the milliseconds since a particular Unix epoch timestamp.\n *\n * @param timestamp - A Unix millisecond timestamp.\n * @returns The number of milliseconds elapsed since the specified timestamp.\n */\nexport function timeSince(timestamp: number): number {\n assertIsNonNegativeInteger(timestamp, 'timestamp');\n return Date.now() - timestamp;\n}\n"],"names":["inMilliseconds","timeSince","Duration","Millisecond","Second","Minute","Hour","Day","Week","Year","isNonNegativeInteger","number","Number","isInteger","assertIsNonNegativeInteger","name","Error","count","duration","timestamp","Date","now"],"mappings":"AAAA;;CAEC;;;;;;;;;;;;;;IAwDeA,cAAc;eAAdA;;IAWAC,SAAS;eAATA;;;IAlET;UAAKC,QAAQ;IAARA,SAAAA,SACV;;GAEC,GACDC,iBAAc,KAAdA;IAJUD,SAAAA,SAMV;;GAEC,GACDE,YAAS,QAATA;IATUF,SAAAA,SAWV;;GAEC,GACDG,YAAS,SAATA;IAdUH,SAAAA,SAgBV;;GAEC,GACDI,UAAO,WAAPA;IAnBUJ,SAAAA,SAqBV;;GAEC,GACDK,SAAM,YAANA;IAxBUL,SAAAA,SA0BV;;GAEC,GACDM,UAAO,aAAPA;IA7BUN,SAAAA,SA+BV;;GAEC,GACDO,UAAO,eAAPA;GAlCUP,aAAAA;AAqCZ,MAAMQ,uBAAuB,CAACC,SAC5BC,OAAOC,SAAS,CAACF,WAAWA,UAAU;AAExC,MAAMG,6BAA6B,CAACH,QAAgBI;IAClD,IAAI,CAACL,qBAAqBC,SAAS;QACjC,MAAM,IAAIK,MACR,CAAC,CAAC,EAAED,KAAK,6CAA6C,EAAEJ,OAAO,EAAE,CAAC;IAEtE;AACF;AASO,SAASX,eAAeiB,KAAa,EAAEC,QAAkB;IAC9DJ,2BAA2BG,OAAO;IAClC,OAAOA,QAAQC;AACjB;AAQO,SAASjB,UAAUkB,SAAiB;IACzCL,2BAA2BK,WAAW;IACtC,OAAOC,KAAKC,GAAG,KAAKF;AACtB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=transaction-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/transaction-types.ts"],"names":[],"mappings":""}