@metamask/utils 6.2.0 → 7.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.
Files changed (170) hide show
  1. package/CHANGELOG.md +11 -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/checksum.js +17 -0
  9. package/dist/cjs/checksum.js.map +1 -0
  10. package/dist/cjs/coercers.js +96 -0
  11. package/dist/cjs/coercers.js.map +1 -0
  12. package/dist/cjs/collections.js +157 -0
  13. package/dist/cjs/collections.js.map +1 -0
  14. package/dist/cjs/encryption-types.js +6 -0
  15. package/dist/cjs/encryption-types.js.map +1 -0
  16. package/dist/cjs/hex.js +107 -0
  17. package/dist/cjs/hex.js.map +1 -0
  18. package/dist/cjs/index.js +36 -0
  19. package/dist/cjs/index.js.map +1 -0
  20. package/dist/cjs/json.js +263 -0
  21. package/dist/cjs/json.js.map +1 -0
  22. package/dist/cjs/keyring.js +6 -0
  23. package/dist/cjs/keyring.js.map +1 -0
  24. package/dist/cjs/logging.js +33 -0
  25. package/dist/cjs/logging.js.map +1 -0
  26. package/dist/cjs/misc.js +111 -0
  27. package/dist/cjs/misc.js.map +1 -0
  28. package/dist/cjs/number.js +52 -0
  29. package/dist/cjs/number.js.map +1 -0
  30. package/dist/cjs/opaque.js +8 -0
  31. package/dist/cjs/opaque.js.map +1 -0
  32. package/dist/cjs/time.js +63 -0
  33. package/dist/cjs/time.js.map +1 -0
  34. package/dist/cjs/transaction-types.js +6 -0
  35. package/dist/cjs/transaction-types.js.map +1 -0
  36. package/dist/cjs/versions.js +79 -0
  37. package/dist/cjs/versions.js.map +1 -0
  38. package/dist/{assert.js → esm/assert.js} +30 -35
  39. package/dist/esm/assert.js.map +1 -0
  40. package/dist/{base64.js → esm/base64.js} +10 -16
  41. package/dist/esm/base64.js.map +1 -0
  42. package/dist/{bytes.js → esm/bytes.js} +50 -93
  43. package/dist/esm/bytes.js.map +1 -0
  44. package/dist/esm/checksum.js +7 -0
  45. package/dist/esm/checksum.js.map +1 -0
  46. package/dist/{coercers.js → esm/coercers.js} +43 -52
  47. package/dist/esm/coercers.js.map +1 -0
  48. package/dist/esm/collections.js +140 -0
  49. package/dist/esm/collections.js.map +1 -0
  50. package/dist/esm/encryption-types.js +3 -0
  51. package/dist/esm/encryption-types.js.map +1 -0
  52. package/dist/esm/hex.js +108 -0
  53. package/dist/esm/hex.js.map +1 -0
  54. package/dist/{index.d.ts → esm/index.js} +2 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/json.js +301 -0
  57. package/dist/esm/json.js.map +1 -0
  58. package/dist/esm/keyring.js +3 -0
  59. package/dist/esm/keyring.js.map +1 -0
  60. package/dist/{logging.js → esm/logging.js} +5 -14
  61. package/dist/esm/logging.js.map +1 -0
  62. package/dist/{misc.js → esm/misc.js} +37 -42
  63. package/dist/esm/misc.js.map +1 -0
  64. package/dist/{number.js → esm/number.js} +18 -28
  65. package/dist/esm/number.js.map +1 -0
  66. package/dist/esm/opaque.js +5 -0
  67. package/dist/esm/opaque.js.map +1 -0
  68. package/dist/esm/package.json +1 -0
  69. package/dist/esm/time.js +53 -0
  70. package/dist/esm/time.js.map +1 -0
  71. package/dist/esm/transaction-types.js +3 -0
  72. package/dist/esm/transaction-types.js.map +1 -0
  73. package/dist/esm/versions.js +78 -0
  74. package/dist/esm/versions.js.map +1 -0
  75. package/dist/{assert.d.ts → types/assert.d.ts} +3 -2
  76. package/dist/types/assert.d.ts.map +1 -0
  77. package/dist/{base64.d.ts → types/base64.d.ts} +3 -2
  78. package/dist/types/base64.d.ts.map +1 -0
  79. package/dist/{bytes.d.ts → types/bytes.d.ts} +2 -1
  80. package/dist/types/bytes.d.ts.map +1 -0
  81. package/dist/{checksum.d.ts → types/checksum.d.ts} +1 -0
  82. package/dist/types/checksum.d.ts.map +1 -0
  83. package/dist/{coercers.d.ts → types/coercers.d.ts} +3 -2
  84. package/dist/types/coercers.d.ts.map +1 -0
  85. package/dist/{collections.d.ts → types/collections.d.ts} +1 -0
  86. package/dist/types/collections.d.ts.map +1 -0
  87. package/dist/{encryption-types.d.ts → types/encryption-types.d.ts} +1 -0
  88. package/dist/types/encryption-types.d.ts.map +1 -0
  89. package/dist/{hex.d.ts → types/hex.d.ts} +2 -1
  90. package/dist/types/hex.d.ts.map +1 -0
  91. package/dist/types/hex.test-d.d.ts +2 -0
  92. package/dist/types/hex.test-d.d.ts.map +1 -0
  93. package/dist/types/index.d.ts +18 -0
  94. package/dist/types/index.d.ts.map +1 -0
  95. package/dist/{json.d.ts → types/json.d.ts} +3 -2
  96. package/dist/types/json.d.ts.map +1 -0
  97. package/dist/types/json.test-d.d.ts +2 -0
  98. package/dist/types/json.test-d.d.ts.map +1 -0
  99. package/dist/{keyring.d.ts → types/keyring.d.ts} +3 -2
  100. package/dist/types/keyring.d.ts.map +1 -0
  101. package/dist/{logging.d.ts → types/logging.d.ts} +2 -1
  102. package/dist/types/logging.d.ts.map +1 -0
  103. package/dist/{misc.d.ts → types/misc.d.ts} +13 -0
  104. package/dist/types/misc.d.ts.map +1 -0
  105. package/dist/types/misc.test-d.d.ts +2 -0
  106. package/dist/types/misc.test-d.d.ts.map +1 -0
  107. package/dist/{number.d.ts → types/number.d.ts} +1 -0
  108. package/dist/types/number.d.ts.map +1 -0
  109. package/dist/{opaque.d.ts → types/opaque.d.ts} +1 -0
  110. package/dist/types/opaque.d.ts.map +1 -0
  111. package/dist/{time.d.ts → types/time.d.ts} +1 -0
  112. package/dist/types/time.d.ts.map +1 -0
  113. package/dist/{transaction-types.d.ts → types/transaction-types.d.ts} +3 -2
  114. package/dist/types/transaction-types.d.ts.map +1 -0
  115. package/dist/{versions.d.ts → types/versions.d.ts} +3 -2
  116. package/dist/types/versions.d.ts.map +1 -0
  117. package/package.json +40 -20
  118. package/dist/__fixtures__/bytes.d.ts +0 -25
  119. package/dist/__fixtures__/bytes.js +0 -234
  120. package/dist/__fixtures__/bytes.js.map +0 -1
  121. package/dist/__fixtures__/coercions.d.ts +0 -5
  122. package/dist/__fixtures__/coercions.js +0 -22
  123. package/dist/__fixtures__/coercions.js.map +0 -1
  124. package/dist/__fixtures__/index.d.ts +0 -4
  125. package/dist/__fixtures__/index.js +0 -21
  126. package/dist/__fixtures__/index.js.map +0 -1
  127. package/dist/__fixtures__/json.d.ts +0 -1226
  128. package/dist/__fixtures__/json.js +0 -1491
  129. package/dist/__fixtures__/json.js.map +0 -1
  130. package/dist/__fixtures__/numbers.d.ts +0 -5
  131. package/dist/__fixtures__/numbers.js +0 -56
  132. package/dist/__fixtures__/numbers.js.map +0 -1
  133. package/dist/assert.js.map +0 -1
  134. package/dist/base64.js.map +0 -1
  135. package/dist/bytes.js.map +0 -1
  136. package/dist/checksum.js +0 -7
  137. package/dist/checksum.js.map +0 -1
  138. package/dist/coercers.js.map +0 -1
  139. package/dist/collections.js +0 -109
  140. package/dist/collections.js.map +0 -1
  141. package/dist/encryption-types.js +0 -3
  142. package/dist/encryption-types.js.map +0 -1
  143. package/dist/hex.js +0 -134
  144. package/dist/hex.js.map +0 -1
  145. package/dist/hex.test-d.d.ts +0 -1
  146. package/dist/hex.test-d.js +0 -16
  147. package/dist/hex.test-d.js.map +0 -1
  148. package/dist/index.js +0 -34
  149. package/dist/index.js.map +0 -1
  150. package/dist/json.js +0 -346
  151. package/dist/json.js.map +0 -1
  152. package/dist/json.test-d.d.ts +0 -1
  153. package/dist/json.test-d.js +0 -62
  154. package/dist/json.test-d.js.map +0 -1
  155. package/dist/keyring.js +0 -3
  156. package/dist/keyring.js.map +0 -1
  157. package/dist/logging.js.map +0 -1
  158. package/dist/misc.js.map +0 -1
  159. package/dist/misc.test-d.d.ts +0 -1
  160. package/dist/misc.test-d.js +0 -97
  161. package/dist/misc.test-d.js.map +0 -1
  162. package/dist/number.js.map +0 -1
  163. package/dist/opaque.js +0 -3
  164. package/dist/opaque.js.map +0 -1
  165. package/dist/time.js +0 -67
  166. package/dist/time.js.map +0 -1
  167. package/dist/transaction-types.js +0 -3
  168. package/dist/transaction-types.js.map +0 -1
  169. package/dist/versions.js +0 -95
  170. package/dist/versions.js.map +0 -1
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDataView = exports.concatBytes = exports.valueToBytes = exports.stringToBytes = exports.numberToBytes = exports.signedBigIntToBytes = exports.bigIntToBytes = exports.hexToBytes = exports.bytesToString = exports.bytesToNumber = exports.bytesToSignedBigInt = exports.bytesToBigInt = exports.bytesToHex = exports.assertIsBytes = exports.isBytes = void 0;
4
- const assert_1 = require("./assert");
5
- const hex_1 = require("./hex");
1
+ import { assert } from './assert';
2
+ import { add0x, assertIsHexString, remove0x } from './hex';
6
3
  // '0'.charCodeAt(0) === 48
7
4
  const HEX_MINIMUM_NUMBER_CHARACTER = 48;
8
5
  // '9'.charCodeAt(0) === 57
@@ -21,16 +18,15 @@ const HEX_CHARACTER_OFFSET = 87;
21
18
  * elements long.
22
19
  *
23
20
  * @returns A function that returns the lookup table.
24
- */
25
- function getPrecomputedHexValuesBuilder() {
21
+ */ function getPrecomputedHexValuesBuilder() {
26
22
  // To avoid issues with tree shaking, we need to use a function to return the
27
23
  // array. This is because the array is only used in the `bytesToHex` function
28
24
  // and if we were to use a global variable, the array might be removed by the
29
25
  // tree shaker.
30
26
  const lookupTable = [];
31
- return () => {
27
+ return ()=>{
32
28
  if (lookupTable.length === 0) {
33
- for (let i = 0; i < 256; i++) {
29
+ for(let i = 0; i < 256; i++){
34
30
  lookupTable.push(i.toString(16).padStart(2, '0'));
35
31
  }
36
32
  }
@@ -40,48 +36,41 @@ function getPrecomputedHexValuesBuilder() {
40
36
  /**
41
37
  * Function implementation of the {@link getPrecomputedHexValuesBuilder}
42
38
  * function.
43
- */
44
- const getPrecomputedHexValues = getPrecomputedHexValuesBuilder();
39
+ */ const getPrecomputedHexValues = getPrecomputedHexValuesBuilder();
45
40
  /**
46
41
  * Check if a value is a `Uint8Array`.
47
42
  *
48
43
  * @param value - The value to check.
49
44
  * @returns Whether the value is a `Uint8Array`.
50
- */
51
- function isBytes(value) {
45
+ */ export function isBytes(value) {
52
46
  return value instanceof Uint8Array;
53
47
  }
54
- exports.isBytes = isBytes;
55
48
  /**
56
49
  * Assert that a value is a `Uint8Array`.
57
50
  *
58
51
  * @param value - The value to check.
59
52
  * @throws If the value is not a `Uint8Array`.
60
- */
61
- function assertIsBytes(value) {
62
- (0, assert_1.assert)(isBytes(value), 'Value must be a Uint8Array.');
53
+ */ export function assertIsBytes(value) {
54
+ assert(isBytes(value), 'Value must be a Uint8Array.');
63
55
  }
64
- exports.assertIsBytes = assertIsBytes;
65
56
  /**
66
57
  * Convert a `Uint8Array` to a hexadecimal string.
67
58
  *
68
59
  * @param bytes - The bytes to convert to a hexadecimal string.
69
60
  * @returns The hexadecimal string.
70
- */
71
- function bytesToHex(bytes) {
61
+ */ export function bytesToHex(bytes) {
72
62
  assertIsBytes(bytes);
73
63
  if (bytes.length === 0) {
74
64
  return '0x';
75
65
  }
76
66
  const lookupTable = getPrecomputedHexValues();
77
67
  const hexadecimal = new Array(bytes.length);
78
- for (let i = 0; i < bytes.length; i++) {
68
+ for(let i = 0; i < bytes.length; i++){
79
69
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
80
70
  hexadecimal[i] = lookupTable[bytes[i]];
81
71
  }
82
- return (0, hex_1.add0x)(hexadecimal.join(''));
72
+ return add0x(hexadecimal.join(''));
83
73
  }
84
- exports.bytesToHex = bytesToHex;
85
74
  /**
86
75
  * Convert a `Uint8Array` to a `bigint`.
87
76
  *
@@ -91,13 +80,11 @@ exports.bytesToHex = bytesToHex;
91
80
  *
92
81
  * @param bytes - The bytes to convert to a `bigint`.
93
82
  * @returns The `bigint`.
94
- */
95
- function bytesToBigInt(bytes) {
83
+ */ export function bytesToBigInt(bytes) {
96
84
  assertIsBytes(bytes);
97
85
  const hexadecimal = bytesToHex(bytes);
98
86
  return BigInt(hexadecimal);
99
87
  }
100
- exports.bytesToBigInt = bytesToBigInt;
101
88
  /**
102
89
  * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are
103
90
  * encoded in two's complement.
@@ -108,17 +95,15 @@ exports.bytesToBigInt = bytesToBigInt;
108
95
  * @see https://en.wikipedia.org/wiki/Two%27s_complement
109
96
  * @param bytes - The bytes to convert to a signed `bigint`.
110
97
  * @returns The signed `bigint`.
111
- */
112
- function bytesToSignedBigInt(bytes) {
98
+ */ export function bytesToSignedBigInt(bytes) {
113
99
  assertIsBytes(bytes);
114
100
  let value = BigInt(0);
115
- for (const byte of bytes) {
101
+ for (const byte of bytes){
116
102
  // eslint-disable-next-line no-bitwise
117
103
  value = (value << BigInt(8)) + BigInt(byte);
118
104
  }
119
105
  return BigInt.asIntN(bytes.length * 8, value);
120
106
  }
121
- exports.bytesToSignedBigInt = bytesToSignedBigInt;
122
107
  /**
123
108
  * Convert a `Uint8Array` to a `number`.
124
109
  *
@@ -127,25 +112,21 @@ exports.bytesToSignedBigInt = bytesToSignedBigInt;
127
112
  * @param bytes - The bytes to convert to a number.
128
113
  * @returns The number.
129
114
  * @throws If the resulting number is not a safe integer.
130
- */
131
- function bytesToNumber(bytes) {
115
+ */ export function bytesToNumber(bytes) {
132
116
  assertIsBytes(bytes);
133
117
  const bigint = bytesToBigInt(bytes);
134
- (0, assert_1.assert)(bigint <= BigInt(Number.MAX_SAFE_INTEGER), 'Number is not a safe integer. Use `bytesToBigInt` instead.');
118
+ assert(bigint <= BigInt(Number.MAX_SAFE_INTEGER), 'Number is not a safe integer. Use `bytesToBigInt` instead.');
135
119
  return Number(bigint);
136
120
  }
137
- exports.bytesToNumber = bytesToNumber;
138
121
  /**
139
122
  * Convert a UTF-8 encoded `Uint8Array` to a `string`.
140
123
  *
141
124
  * @param bytes - The bytes to convert to a string.
142
125
  * @returns The string.
143
- */
144
- function bytesToString(bytes) {
126
+ */ export function bytesToString(bytes) {
145
127
  assertIsBytes(bytes);
146
128
  return new TextDecoder().decode(bytes);
147
129
  }
148
- exports.bytesToString = bytesToString;
149
130
  /**
150
131
  * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be
151
132
  * prefixed with `0x`. It accepts even and odd length strings.
@@ -154,37 +135,29 @@ exports.bytesToString = bytesToString;
154
135
  *
155
136
  * @param value - The hexadecimal string to convert to bytes.
156
137
  * @returns The bytes as `Uint8Array`.
157
- */
158
- function hexToBytes(value) {
138
+ */ export function hexToBytes(value) {
159
139
  // "0x" is often used as empty byte array.
160
140
  if (value?.toLowerCase?.() === '0x') {
161
141
  return new Uint8Array();
162
142
  }
163
- (0, hex_1.assertIsHexString)(value);
143
+ assertIsHexString(value);
164
144
  // Remove the `0x` prefix if it exists, and pad the string to have an even
165
145
  // number of characters.
166
- const strippedValue = (0, hex_1.remove0x)(value).toLowerCase();
146
+ const strippedValue = remove0x(value).toLowerCase();
167
147
  const normalizedValue = strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;
168
148
  const bytes = new Uint8Array(normalizedValue.length / 2);
169
- for (let i = 0; i < bytes.length; i++) {
149
+ for(let i = 0; i < bytes.length; i++){
170
150
  // While this is not the prettiest way to convert a hexadecimal string to a
171
151
  // `Uint8Array`, it is a lot faster than using `parseInt` to convert each
172
152
  // character.
173
153
  const c1 = normalizedValue.charCodeAt(i * 2);
174
154
  const c2 = normalizedValue.charCodeAt(i * 2 + 1);
175
- const n1 = c1 -
176
- (c1 < HEX_MAXIMUM_NUMBER_CHARACTER
177
- ? HEX_MINIMUM_NUMBER_CHARACTER
178
- : HEX_CHARACTER_OFFSET);
179
- const n2 = c2 -
180
- (c2 < HEX_MAXIMUM_NUMBER_CHARACTER
181
- ? HEX_MINIMUM_NUMBER_CHARACTER
182
- : HEX_CHARACTER_OFFSET);
155
+ const n1 = c1 - (c1 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
156
+ const n2 = c2 - (c2 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
183
157
  bytes[i] = n1 * 16 + n2;
184
158
  }
185
159
  return bytes;
186
160
  }
187
- exports.hexToBytes = hexToBytes;
188
161
  /**
189
162
  * Convert a `bigint` to a `Uint8Array`.
190
163
  *
@@ -193,28 +166,23 @@ exports.hexToBytes = hexToBytes;
193
166
  *
194
167
  * @param value - The bigint to convert to bytes.
195
168
  * @returns The bytes as `Uint8Array`.
196
- */
197
- function bigIntToBytes(value) {
198
- (0, assert_1.assert)(typeof value === 'bigint', 'Value must be a bigint.');
199
- (0, assert_1.assert)(value >= BigInt(0), 'Value must be a non-negative bigint.');
169
+ */ export function bigIntToBytes(value) {
170
+ assert(typeof value === 'bigint', 'Value must be a bigint.');
171
+ assert(value >= BigInt(0), 'Value must be a non-negative bigint.');
200
172
  const hexadecimal = value.toString(16);
201
173
  return hexToBytes(hexadecimal);
202
174
  }
203
- exports.bigIntToBytes = bigIntToBytes;
204
175
  /**
205
176
  * Check if a `bigint` fits in a certain number of bytes.
206
177
  *
207
178
  * @param value - The `bigint` to check.
208
179
  * @param bytes - The number of bytes.
209
180
  * @returns Whether the `bigint` fits in the number of bytes.
210
- */
211
- function bigIntFits(value, bytes) {
212
- (0, assert_1.assert)(bytes > 0);
213
- /* eslint-disable no-bitwise */
214
- const mask = value >> BigInt(31);
215
- return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));
216
- /* eslint-enable no-bitwise */
217
- }
181
+ */ function bigIntFits(value, bytes) {
182
+ assert(bytes > 0);
183
+ /* eslint-disable no-bitwise */ const mask = value >> BigInt(31);
184
+ return !((~value & mask) + (value & ~mask) >> BigInt(bytes * 8 + ~0));
185
+ /* eslint-enable no-bitwise */ }
218
186
  /**
219
187
  * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement
220
188
  * encoding to represent negative numbers.
@@ -228,50 +196,44 @@ function bigIntFits(value, bytes) {
228
196
  * is larger than the maximum value that can be represented by the given length,
229
197
  * an error is thrown.
230
198
  * @returns The bytes as `Uint8Array`.
231
- */
232
- function signedBigIntToBytes(value, byteLength) {
233
- (0, assert_1.assert)(typeof value === 'bigint', 'Value must be a bigint.');
234
- (0, assert_1.assert)(typeof byteLength === 'number', 'Byte length must be a number.');
235
- (0, assert_1.assert)(byteLength > 0, 'Byte length must be greater than 0.');
236
- (0, assert_1.assert)(bigIntFits(value, byteLength), 'Byte length is too small to represent the given value.');
199
+ */ export function signedBigIntToBytes(value, byteLength) {
200
+ assert(typeof value === 'bigint', 'Value must be a bigint.');
201
+ assert(typeof byteLength === 'number', 'Byte length must be a number.');
202
+ assert(byteLength > 0, 'Byte length must be greater than 0.');
203
+ assert(bigIntFits(value, byteLength), 'Byte length is too small to represent the given value.');
237
204
  // ESLint doesn't like mutating function parameters, so to avoid having to
238
205
  // disable the rule, we create a new variable.
239
206
  let numberValue = value;
240
207
  const bytes = new Uint8Array(byteLength);
241
- for (let i = 0; i < bytes.length; i++) {
208
+ for(let i = 0; i < bytes.length; i++){
242
209
  bytes[i] = Number(BigInt.asUintN(8, numberValue));
243
210
  // eslint-disable-next-line no-bitwise
244
211
  numberValue >>= BigInt(8);
245
212
  }
246
213
  return bytes.reverse();
247
214
  }
248
- exports.signedBigIntToBytes = signedBigIntToBytes;
249
215
  /**
250
216
  * Convert a `number` to a `Uint8Array`.
251
217
  *
252
218
  * @param value - The number to convert to bytes.
253
219
  * @returns The bytes as `Uint8Array`.
254
220
  * @throws If the number is not a safe integer.
255
- */
256
- function numberToBytes(value) {
257
- (0, assert_1.assert)(typeof value === 'number', 'Value must be a number.');
258
- (0, assert_1.assert)(value >= 0, 'Value must be a non-negative number.');
259
- (0, assert_1.assert)(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToBytes` instead.');
221
+ */ export function numberToBytes(value) {
222
+ assert(typeof value === 'number', 'Value must be a number.');
223
+ assert(value >= 0, 'Value must be a non-negative number.');
224
+ assert(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToBytes` instead.');
260
225
  const hexadecimal = value.toString(16);
261
226
  return hexToBytes(hexadecimal);
262
227
  }
263
- exports.numberToBytes = numberToBytes;
264
228
  /**
265
229
  * Convert a `string` to a UTF-8 encoded `Uint8Array`.
266
230
  *
267
231
  * @param value - The string to convert to bytes.
268
232
  * @returns The bytes as `Uint8Array`.
269
- */
270
- function stringToBytes(value) {
271
- (0, assert_1.assert)(typeof value === 'string', 'Value must be a string.');
233
+ */ export function stringToBytes(value) {
234
+ assert(typeof value === 'string', 'Value must be a string.');
272
235
  return new TextEncoder().encode(value);
273
236
  }
274
- exports.stringToBytes = stringToBytes;
275
237
  /**
276
238
  * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,
277
239
  * a `bigint`, a `number`, or a `string`.
@@ -292,8 +254,7 @@ exports.stringToBytes = stringToBytes;
292
254
  *
293
255
  * @param value - The value to convert to bytes.
294
256
  * @returns The bytes as `Uint8Array`.
295
- */
296
- function valueToBytes(value) {
257
+ */ export function valueToBytes(value) {
297
258
  if (typeof value === 'bigint') {
298
259
  return bigIntToBytes(value);
299
260
  }
@@ -311,7 +272,6 @@ function valueToBytes(value) {
311
272
  }
312
273
  throw new TypeError(`Unsupported value type: "${typeof value}".`);
313
274
  }
314
- exports.valueToBytes = valueToBytes;
315
275
  /**
316
276
  * Concatenate multiple byte-like values into a single `Uint8Array`. The values
317
277
  * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses
@@ -320,18 +280,17 @@ exports.valueToBytes = valueToBytes;
320
280
  *
321
281
  * @param values - The values to concatenate.
322
282
  * @returns The concatenated bytes as `Uint8Array`.
323
- */
324
- function concatBytes(values) {
283
+ */ export function concatBytes(values) {
325
284
  const normalizedValues = new Array(values.length);
326
285
  let byteLength = 0;
327
- for (let i = 0; i < values.length; i++) {
286
+ for(let i = 0; i < values.length; i++){
328
287
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
329
288
  const value = valueToBytes(values[i]);
330
289
  normalizedValues[i] = value;
331
290
  byteLength += value.length;
332
291
  }
333
292
  const bytes = new Uint8Array(byteLength);
334
- for (let i = 0, offset = 0; i < normalizedValues.length; i++) {
293
+ for(let i = 0, offset = 0; i < normalizedValues.length; i++){
335
294
  // While we could simply spread the values into an array and use
336
295
  // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.
337
296
  bytes.set(normalizedValues[i], offset);
@@ -339,7 +298,6 @@ function concatBytes(values) {
339
298
  }
340
299
  return bytes;
341
300
  }
342
- exports.concatBytes = concatBytes;
343
301
  /**
344
302
  * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience
345
303
  * function that avoids having to create a {@link DataView} manually, which
@@ -361,8 +319,7 @@ exports.concatBytes = concatBytes;
361
319
  * ```
362
320
  * @param bytes - The bytes to create the {@link DataView} from.
363
321
  * @returns The {@link DataView}.
364
- */
365
- function createDataView(bytes) {
322
+ */ export function createDataView(bytes) {
366
323
  // To maintain compatibility with Node.js, we need to check if the bytes are
367
324
  // a Buffer. If so, we need to slice the buffer to get the underlying
368
325
  // ArrayBuffer.
@@ -373,5 +330,5 @@ function createDataView(bytes) {
373
330
  }
374
331
  return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
375
332
  }
376
- exports.createDataView = createDataView;
333
+
377
334
  //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bytes.ts"],"sourcesContent":["import { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\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 `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n"],"names":["assert","add0x","assertIsHexString","remove0x","HEX_MINIMUM_NUMBER_CHARACTER","HEX_MAXIMUM_NUMBER_CHARACTER","HEX_CHARACTER_OFFSET","getPrecomputedHexValuesBuilder","lookupTable","length","i","push","toString","padStart","getPrecomputedHexValues","isBytes","value","Uint8Array","assertIsBytes","bytesToHex","bytes","hexadecimal","Array","join","bytesToBigInt","BigInt","bytesToSignedBigInt","byte","asIntN","bytesToNumber","bigint","Number","MAX_SAFE_INTEGER","bytesToString","TextDecoder","decode","hexToBytes","toLowerCase","strippedValue","normalizedValue","c1","charCodeAt","c2","n1","n2","bigIntToBytes","bigIntFits","mask","signedBigIntToBytes","byteLength","numberValue","asUintN","reverse","numberToBytes","isSafeInteger","stringToBytes","TextEncoder","encode","valueToBytes","startsWith","TypeError","concatBytes","values","normalizedValues","offset","set","createDataView","Buffer","buffer","slice","byteOffset","DataView"],"mappings":"AAAA,SAASA,MAAM,QAAQ,WAAW;AAElC,SAASC,KAAK,EAAEC,iBAAiB,EAAEC,QAAQ,QAAQ,QAAQ;AAE3D,2BAA2B;AAC3B,MAAMC,+BAA+B;AAErC,2BAA2B;AAC3B,MAAMC,+BAA+B;AACrC,MAAMC,uBAAuB;AAI7B;;;;;;;;;;;;;CAaC,GACD,SAASC;IACP,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,eAAe;IACf,MAAMC,cAAwB,EAAE;IAEhC,OAAO;QACL,IAAIA,YAAYC,MAAM,KAAK,GAAG;YAC5B,IAAK,IAAIC,IAAI,GAAGA,IAAI,KAAKA,IAAK;gBAC5BF,YAAYG,IAAI,CAACD,EAAEE,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG;YAC9C;QACF;QAEA,OAAOL;IACT;AACF;AAEA;;;CAGC,GACD,MAAMM,0BAA0BP;AAEhC;;;;;CAKC,GACD,OAAO,SAASQ,QAAQC,KAAc;IACpC,OAAOA,iBAAiBC;AAC1B;AAEA;;;;;CAKC,GACD,OAAO,SAASC,cAAcF,KAAc;IAC1ChB,OAAOe,QAAQC,QAAQ;AACzB;AAEA;;;;;CAKC,GACD,OAAO,SAASG,WAAWC,KAAiB;IAC1CF,cAAcE;IAEd,IAAIA,MAAMX,MAAM,KAAK,GAAG;QACtB,OAAO;IACT;IAEA,MAAMD,cAAcM;IACpB,MAAMO,cAAc,IAAIC,MAAMF,MAAMX,MAAM;IAE1C,IAAK,IAAIC,IAAI,GAAGA,IAAIU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AACpD,EAAE;QAEpCqD,gBAAgB,CAACrD,EAAE,GAAGM;QACtBiC,cAAcjC,MAAMP,MAAM;IAC5B;IAEA,MAAMW,QAAQ,IAAIH,WAAWgC;IAC7B,IAAK,IAAIvC,IAAI,GAAGsD,SAAS,GAAGtD,IAAIqD,iBAAiBtD,MAAM,EAAEC,IAAK;QAC5D,gEAAgE;QAChE,uEAAuE;QACvEU,MAAM6C,GAAG,CAACF,gBAAgB,CAACrD,EAAE,EAAEsD;QAC/BA,UAAUD,gBAAgB,CAACrD,EAAE,CAACD,MAAM;IACtC;IAEA,OAAOW;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAAS8C,eAAe9C,KAAiB;IAC9C,4EAA4E;IAC5E,qEAAqE;IACrE,eAAe;IACf,iDAAiD;IACjD,IAAI,OAAO+C,WAAW,eAAe/C,iBAAiB+C,QAAQ;QAC5D,MAAMC,SAAShD,MAAMgD,MAAM,CAACC,KAAK,CAC/BjD,MAAMkD,UAAU,EAChBlD,MAAMkD,UAAU,GAAGlD,MAAM6B,UAAU;QAGrC,OAAO,IAAIsB,SAASH;IACtB;IAEA,OAAO,IAAIG,SAASnD,MAAMgD,MAAM,EAAEhD,MAAMkD,UAAU,EAAElD,MAAM6B,UAAU;AACtE"}
@@ -0,0 +1,7 @@
1
+ import { size, string } from 'superstruct';
2
+ import { base64 } from './base64';
3
+ export const ChecksumStruct = size(base64(string(), {
4
+ paddingRequired: true
5
+ }), 44, 44);
6
+
7
+ //# sourceMappingURL=checksum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/checksum.ts"],"sourcesContent":["import { size, string } from 'superstruct';\n\nimport { base64 } from './base64';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"],"names":["size","string","base64","ChecksumStruct","paddingRequired"],"mappings":"AAAA,SAASA,IAAI,EAAEC,MAAM,QAAQ,cAAc;AAE3C,SAASC,MAAM,QAAQ,WAAW;AAElC,OAAO,MAAMC,iBAAiBH,KAC5BE,OAAOD,UAAU;IAAEG,iBAAiB;AAAK,IACzC,IACA,IACA"}
@@ -1,16 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createHex = exports.createBytes = exports.createBigInt = exports.createNumber = void 0;
4
- const superstruct_1 = require("superstruct");
5
- const assert_1 = require("./assert");
6
- const bytes_1 = require("./bytes");
7
- const hex_1 = require("./hex");
8
- const NumberLikeStruct = (0, superstruct_1.union)([(0, superstruct_1.number)(), (0, superstruct_1.bigint)(), (0, superstruct_1.string)(), hex_1.StrictHexStruct]);
9
- const NumberCoercer = (0, superstruct_1.coerce)((0, superstruct_1.number)(), NumberLikeStruct, Number);
10
- const BigIntCoercer = (0, superstruct_1.coerce)((0, superstruct_1.bigint)(), NumberLikeStruct, BigInt);
11
- const BytesLikeStruct = (0, superstruct_1.union)([hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array)]);
12
- const BytesCoercer = (0, superstruct_1.coerce)((0, superstruct_1.instance)(Uint8Array), (0, superstruct_1.union)([hex_1.StrictHexStruct]), bytes_1.hexToBytes);
13
- const HexCoercer = (0, superstruct_1.coerce)(hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array), bytes_1.bytesToHex);
1
+ import { bigint, coerce, create, instance, number, string, StructError, union } from 'superstruct';
2
+ import { assert } from './assert';
3
+ import { bytesToHex, hexToBytes } from './bytes';
4
+ import { StrictHexStruct } from './hex';
5
+ const NumberLikeStruct = union([
6
+ number(),
7
+ bigint(),
8
+ string(),
9
+ StrictHexStruct
10
+ ]);
11
+ const NumberCoercer = coerce(number(), NumberLikeStruct, Number);
12
+ const BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);
13
+ const BytesLikeStruct = union([
14
+ StrictHexStruct,
15
+ instance(Uint8Array)
16
+ ]);
17
+ const BytesCoercer = coerce(instance(Uint8Array), union([
18
+ StrictHexStruct
19
+ ]), hexToBytes);
20
+ const HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);
14
21
  /**
15
22
  * Create a number from a number-like value.
16
23
  *
@@ -35,22 +42,18 @@ const HexCoercer = (0, superstruct_1.coerce)(hex_1.StrictHexStruct, (0, superstr
35
42
  * @returns The created number.
36
43
  * @throws If the value is not a number-like value, or if the resulting number
37
44
  * is `NaN` or `Infinity`.
38
- */
39
- function createNumber(value) {
45
+ */ export function createNumber(value) {
40
46
  try {
41
- const result = (0, superstruct_1.create)(value, NumberCoercer);
42
- (0, assert_1.assert)(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
47
+ const result = create(value, NumberCoercer);
48
+ assert(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
43
49
  return result;
44
- }
45
- catch (error) {
46
- if (error instanceof superstruct_1.StructError) {
50
+ } catch (error) {
51
+ if (error instanceof StructError) {
47
52
  throw new Error(`Expected a number-like value, got "${value}".`);
48
53
  }
49
- /* istanbul ignore next */
50
- throw error;
54
+ /* istanbul ignore next */ throw error;
51
55
  }
52
56
  }
53
- exports.createNumber = createNumber;
54
57
  /**
55
58
  * Create a `bigint` from a number-like value.
56
59
  *
@@ -72,22 +75,18 @@ exports.createNumber = createNumber;
72
75
  * @param value - The value to create the bigint from.
73
76
  * @returns The created bigint.
74
77
  * @throws If the value is not a number-like value.
75
- */
76
- function createBigInt(value) {
78
+ */ export function createBigInt(value) {
77
79
  try {
78
80
  // The `BigInt` constructor throws if the value is not a number-like value.
79
81
  // There is no need to validate the value manually.
80
- return (0, superstruct_1.create)(value, BigIntCoercer);
81
- }
82
- catch (error) {
83
- if (error instanceof superstruct_1.StructError) {
82
+ return create(value, BigIntCoercer);
83
+ } catch (error) {
84
+ if (error instanceof StructError) {
84
85
  throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
85
86
  }
86
- /* istanbul ignore next */
87
- throw error;
87
+ /* istanbul ignore next */ throw error;
88
88
  }
89
89
  }
90
- exports.createBigInt = createBigInt;
91
90
  /**
92
91
  * Create a byte array from a bytes-like value.
93
92
  *
@@ -106,23 +105,19 @@ exports.createBigInt = createBigInt;
106
105
  * @param value - The value to create the byte array from.
107
106
  * @returns The created byte array.
108
107
  * @throws If the value is not a bytes-like value.
109
- */
110
- function createBytes(value) {
108
+ */ export function createBytes(value) {
111
109
  if (typeof value === 'string' && value.toLowerCase() === '0x') {
112
110
  return new Uint8Array();
113
111
  }
114
112
  try {
115
- return (0, superstruct_1.create)(value, BytesCoercer);
116
- }
117
- catch (error) {
118
- if (error instanceof superstruct_1.StructError) {
113
+ return create(value, BytesCoercer);
114
+ } catch (error) {
115
+ if (error instanceof StructError) {
119
116
  throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
120
117
  }
121
- /* istanbul ignore next */
122
- throw error;
118
+ /* istanbul ignore next */ throw error;
123
119
  }
124
120
  }
125
- exports.createBytes = createBytes;
126
121
  /**
127
122
  * Create a hexadecimal string from a bytes-like value.
128
123
  *
@@ -141,22 +136,18 @@ exports.createBytes = createBytes;
141
136
  * @param value - The value to create the hex string from.
142
137
  * @returns The created hex string.
143
138
  * @throws If the value is not a bytes-like value.
144
- */
145
- function createHex(value) {
146
- if ((value instanceof Uint8Array && value.length === 0) ||
147
- (typeof value === 'string' && value.toLowerCase() === '0x')) {
139
+ */ export function createHex(value) {
140
+ if (value instanceof Uint8Array && value.length === 0 || typeof value === 'string' && value.toLowerCase() === '0x') {
148
141
  return '0x';
149
142
  }
150
143
  try {
151
- return (0, superstruct_1.create)(value, HexCoercer);
152
- }
153
- catch (error) {
154
- if (error instanceof superstruct_1.StructError) {
144
+ return create(value, HexCoercer);
145
+ } catch (error) {
146
+ if (error instanceof StructError) {
155
147
  throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
156
148
  }
157
- /* istanbul ignore next */
158
- throw error;
149
+ /* istanbul ignore next */ throw error;
159
150
  }
160
151
  }
161
- exports.createHex = createHex;
152
+
162
153
  //# sourceMappingURL=coercers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/coercers.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from 'superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport type { Hex } from './hex';\nimport { StrictHexStruct } from './hex';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"],"names":["bigint","coerce","create","instance","number","string","StructError","union","assert","bytesToHex","hexToBytes","StrictHexStruct","NumberLikeStruct","NumberCoercer","Number","BigIntCoercer","BigInt","BytesLikeStruct","Uint8Array","BytesCoercer","HexCoercer","createNumber","value","result","isFinite","error","Error","createBigInt","String","createBytes","toLowerCase","createHex","length"],"mappings":"AACA,SACEA,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,KAAK,QACA,cAAc;AAErB,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,UAAU,EAAEC,UAAU,QAAQ,UAAU;AAEjD,SAASC,eAAe,QAAQ,QAAQ;AAExC,MAAMC,mBAAmBL,MAAM;IAACH;IAAUJ;IAAUK;IAAUM;CAAgB;AAC9E,MAAME,gBAAgBZ,OAAOG,UAAUQ,kBAAkBE;AACzD,MAAMC,gBAAgBd,OAAOD,UAAUY,kBAAkBI;AAEzD,MAAMC,kBAAkBV,MAAM;IAACI;IAAiBR,SAASe;CAAY;AACrE,MAAMC,eAAelB,OACnBE,SAASe,aACTX,MAAM;IAACI;CAAgB,GACvBD;AAGF,MAAMU,aAAanB,OAAOU,iBAAiBR,SAASe,aAAaT;AAKjE;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,SAASY,aAAaC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