@arcblock/did-noise 0.0.0-stage → 1.30.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/esm/chacha20poly1305.d.mts +18 -0
- package/esm/chacha20poly1305.mjs +152 -0
- package/esm/chain-node-mesh.d.mts +79 -0
- package/esm/chain-node-mesh.mjs +187 -0
- package/esm/http-transport.d.mts +72 -0
- package/esm/http-transport.mjs +216 -0
- package/esm/index.d.mts +6 -0
- package/esm/index.mjs +7 -0
- package/esm/mesh-tunnel.d.mts +165 -0
- package/esm/mesh-tunnel.mjs +350 -0
- package/esm/noise-session.d.mts +157 -0
- package/esm/noise-session.mjs +491 -0
- package/lib/_vendor/@noble/curves/LICENSE +21 -0
- package/lib/_vendor/@noble/curves/abstract/curve.cjs +338 -0
- package/lib/_vendor/@noble/curves/abstract/edwards.cjs +542 -0
- package/lib/_vendor/@noble/curves/abstract/hash-to-curve.cjs +72 -0
- package/lib/_vendor/@noble/curves/abstract/modular.cjs +557 -0
- package/lib/_vendor/@noble/curves/abstract/montgomery.cjs +149 -0
- package/lib/_vendor/@noble/curves/ed25519.cjs +302 -0
- package/lib/_vendor/@noble/curves/utils.cjs +436 -0
- package/lib/_vendor/@noble/hashes/LICENSE +21 -0
- package/lib/_vendor/@noble/hashes/_blake.cjs +300 -0
- package/lib/_vendor/@noble/hashes/_md.cjs +194 -0
- package/lib/_vendor/@noble/hashes/_u64.cjs +60 -0
- package/lib/_vendor/@noble/hashes/blake2.cjs +291 -0
- package/lib/_vendor/@noble/hashes/hkdf.cjs +104 -0
- package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
- package/lib/_vendor/@noble/hashes/sha2.cjs +417 -0
- package/lib/_vendor/@noble/hashes/utils.cjs +422 -0
- package/lib/chacha20poly1305.cjs +153 -0
- package/lib/chacha20poly1305.d.cts +18 -0
- package/lib/chain-node-mesh.cjs +189 -0
- package/lib/chain-node-mesh.d.cts +79 -0
- package/lib/http-transport.cjs +219 -0
- package/lib/http-transport.d.cts +72 -0
- package/lib/index.cjs +31 -0
- package/lib/index.d.cts +6 -0
- package/lib/mesh-tunnel.cjs +354 -0
- package/lib/mesh-tunnel.d.cts +165 -0
- package/lib/noise-session.cjs +503 -0
- package/lib/noise-session.d.cts +157 -0
- package/package.json +80 -4
- package/README.md +0 -3
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
const require_utils = require('../hashes/utils.cjs');
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/@noble/curves/utils.js
|
|
4
|
+
/**
|
|
5
|
+
* Hex, bytes and number utilities.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
+
/**
|
|
10
|
+
* Validates that a value is a byte array.
|
|
11
|
+
* @param value - Value to validate.
|
|
12
|
+
* @param length - Optional exact byte length.
|
|
13
|
+
* @param title - Optional field name.
|
|
14
|
+
* @returns Original byte array.
|
|
15
|
+
* @example
|
|
16
|
+
* Reject non-byte input before passing data into curve code.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* abytes(new Uint8Array(1));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const abytes = (value, length, title) => require_utils.abytes(value, length, title);
|
|
23
|
+
/**
|
|
24
|
+
* Validates that a value is a non-negative safe integer.
|
|
25
|
+
* @param n - Value to validate.
|
|
26
|
+
* @param title - Optional field name.
|
|
27
|
+
* @example
|
|
28
|
+
* Validate a numeric length before allocating buffers.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* anumber(1);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const anumber = require_utils.anumber;
|
|
35
|
+
/**
|
|
36
|
+
* Encodes bytes as lowercase hex.
|
|
37
|
+
* @param bytes - Bytes to encode.
|
|
38
|
+
* @returns Lowercase hex string.
|
|
39
|
+
* @example
|
|
40
|
+
* Serialize bytes as hex for logging or fixtures.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* bytesToHex(Uint8Array.of(1, 2, 3));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const bytesToHex = require_utils.bytesToHex;
|
|
47
|
+
/**
|
|
48
|
+
* Concatenates byte arrays.
|
|
49
|
+
* @param arrays - Byte arrays to join.
|
|
50
|
+
* @returns Concatenated bytes.
|
|
51
|
+
* @example
|
|
52
|
+
* Join domain-separated chunks into one buffer.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* concatBytes(Uint8Array.of(1), Uint8Array.of(2));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const concatBytes = (...arrays) => require_utils.concatBytes(...arrays);
|
|
59
|
+
/**
|
|
60
|
+
* Decodes lowercase or uppercase hex into bytes.
|
|
61
|
+
* @param hex - Hex string to decode.
|
|
62
|
+
* @returns Decoded bytes.
|
|
63
|
+
* @example
|
|
64
|
+
* Parse fixture hex into bytes before hashing.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* hexToBytes('0102');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
const hexToBytes = (hex) => require_utils.hexToBytes(hex);
|
|
71
|
+
/**
|
|
72
|
+
* Checks whether a value is a Uint8Array.
|
|
73
|
+
* @param a - Value to inspect.
|
|
74
|
+
* @returns `true` when `a` is a Uint8Array.
|
|
75
|
+
* @example
|
|
76
|
+
* Branch on byte input before decoding it.
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* isBytes(new Uint8Array(1));
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
const isBytes = require_utils.isBytes;
|
|
83
|
+
/**
|
|
84
|
+
* Reads random bytes from the platform CSPRNG.
|
|
85
|
+
* @param bytesLength - Number of random bytes to read.
|
|
86
|
+
* @returns Fresh random bytes.
|
|
87
|
+
* @example
|
|
88
|
+
* Generate a random seed for a keypair.
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* randomBytes(2);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
const randomBytes = (bytesLength) => require_utils.randomBytes(bytesLength);
|
|
95
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
96
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
97
|
+
/**
|
|
98
|
+
* Validates that a flag is boolean.
|
|
99
|
+
* @param value - Value to validate.
|
|
100
|
+
* @param title - Optional field name.
|
|
101
|
+
* @returns Original value.
|
|
102
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
103
|
+
* @example
|
|
104
|
+
* Reject non-boolean option flags early.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* abool(true);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function abool(value, title = "") {
|
|
111
|
+
if (typeof value !== "boolean") {
|
|
112
|
+
const prefix = title && `"${title}" `;
|
|
113
|
+
throw new TypeError(prefix + "expected boolean, got type=" + typeof value);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Validates that a value is a non-negative bigint or safe integer.
|
|
119
|
+
* @param n - Value to validate.
|
|
120
|
+
* @returns The same validated value.
|
|
121
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
122
|
+
* @example
|
|
123
|
+
* Validate one integer-like value before serializing it.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* abignumber(1n);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
function abignumber(n) {
|
|
130
|
+
if (typeof n === "bigint") {
|
|
131
|
+
if (!isPosBig(n)) throw new RangeError("positive bigint expected, got " + n);
|
|
132
|
+
} else anumber(n);
|
|
133
|
+
return n;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Validates that a value is a safe integer.
|
|
137
|
+
* @param value - Integer to validate.
|
|
138
|
+
* @param title - Optional field name.
|
|
139
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
140
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
141
|
+
* @example
|
|
142
|
+
* Validate a window size before scalar arithmetic uses it.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* asafenumber(1);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function asafenumber(value, title = "") {
|
|
149
|
+
if (typeof value !== "number") {
|
|
150
|
+
const prefix = title && `"${title}" `;
|
|
151
|
+
throw new TypeError(prefix + "expected number, got type=" + typeof value);
|
|
152
|
+
}
|
|
153
|
+
if (!Number.isSafeInteger(value)) {
|
|
154
|
+
const prefix = title && `"${title}" `;
|
|
155
|
+
throw new RangeError(prefix + "expected safe integer, got " + value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parses a big-endian hex string into bigint.
|
|
160
|
+
* Accepts odd-length hex through the native `BigInt('0x' + hex)` parser and currently surfaces the
|
|
161
|
+
* same native `SyntaxError` for malformed hex instead of wrapping it in a library-specific error.
|
|
162
|
+
* @param hex - Hex string without `0x`.
|
|
163
|
+
* @returns Parsed bigint value.
|
|
164
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
165
|
+
* @example
|
|
166
|
+
* Parse a scalar from fixture hex.
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* hexToNumber('ff');
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
function hexToNumber(hex) {
|
|
173
|
+
if (typeof hex !== "string") throw new TypeError("hex string expected, got " + typeof hex);
|
|
174
|
+
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Parses big-endian bytes into bigint.
|
|
178
|
+
* @param bytes - Bytes in big-endian order.
|
|
179
|
+
* @returns Parsed bigint value.
|
|
180
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
181
|
+
* @example
|
|
182
|
+
* Read a scalar encoded in network byte order.
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* bytesToNumberBE(Uint8Array.of(1, 0));
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
function bytesToNumberBE(bytes) {
|
|
189
|
+
return hexToNumber(require_utils.bytesToHex(bytes));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parses little-endian bytes into bigint.
|
|
193
|
+
* @param bytes - Bytes in little-endian order.
|
|
194
|
+
* @returns Parsed bigint value.
|
|
195
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
196
|
+
* @example
|
|
197
|
+
* Read a scalar encoded in little-endian form.
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* bytesToNumberLE(Uint8Array.of(1, 0));
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
function bytesToNumberLE(bytes) {
|
|
204
|
+
return hexToNumber(require_utils.bytesToHex(copyBytes(require_utils.abytes(bytes)).reverse()));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Encodes a bigint into fixed-length big-endian bytes.
|
|
208
|
+
* @param n - Number to encode.
|
|
209
|
+
* @param len - Output length in bytes. Must be greater than zero.
|
|
210
|
+
* @returns Big-endian byte array.
|
|
211
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
212
|
+
* @example
|
|
213
|
+
* Serialize a scalar into a 32-byte field element.
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* numberToBytesBE(255n, 2);
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
function numberToBytesBE(n, len) {
|
|
220
|
+
require_utils.anumber(len);
|
|
221
|
+
if (len === 0) throw new RangeError("zero length");
|
|
222
|
+
n = abignumber(n);
|
|
223
|
+
const hex = n.toString(16);
|
|
224
|
+
if (hex.length > len * 2) throw new RangeError("number too large");
|
|
225
|
+
return require_utils.hexToBytes(hex.padStart(len * 2, "0"));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Encodes a bigint into fixed-length little-endian bytes.
|
|
229
|
+
* @param n - Number to encode.
|
|
230
|
+
* @param len - Output length in bytes.
|
|
231
|
+
* @returns Little-endian byte array.
|
|
232
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
233
|
+
* @example
|
|
234
|
+
* Serialize a scalar for little-endian protocols.
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* numberToBytesLE(255n, 2);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
function numberToBytesLE(n, len) {
|
|
241
|
+
return numberToBytesBE(n, len).reverse();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Compares two byte arrays in constant-ish time.
|
|
245
|
+
* @param a - Left byte array.
|
|
246
|
+
* @param b - Right byte array.
|
|
247
|
+
* @returns `true` when bytes match.
|
|
248
|
+
* @example
|
|
249
|
+
* Compare two encoded points without early exit.
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* equalBytes(Uint8Array.of(1), Uint8Array.of(1));
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
function equalBytes(a, b) {
|
|
256
|
+
a = abytes(a);
|
|
257
|
+
b = abytes(b);
|
|
258
|
+
if (a.length !== b.length) return false;
|
|
259
|
+
let diff = 0;
|
|
260
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
261
|
+
return diff === 0;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Copies Uint8Array. We can't use u8a.slice(), because u8a can be Buffer,
|
|
265
|
+
* and Buffer#slice creates mutable copy. Never use Buffers!
|
|
266
|
+
* @param bytes - Bytes to copy.
|
|
267
|
+
* @returns Detached copy.
|
|
268
|
+
* @example
|
|
269
|
+
* Make an isolated copy before mutating serialized bytes.
|
|
270
|
+
*
|
|
271
|
+
* ```ts
|
|
272
|
+
* copyBytes(Uint8Array.of(1, 2, 3));
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
function copyBytes(bytes) {
|
|
276
|
+
return Uint8Array.from(abytes(bytes));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Decodes 7-bit ASCII string to Uint8Array, throws on non-ascii symbols
|
|
280
|
+
* Should be safe to use for things expected to be ASCII.
|
|
281
|
+
* Returns exact same result as `TextEncoder` for ASCII or throws.
|
|
282
|
+
* @param ascii - ASCII input text.
|
|
283
|
+
* @returns Encoded bytes.
|
|
284
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
285
|
+
* @example
|
|
286
|
+
* Encode an ASCII domain-separation tag.
|
|
287
|
+
*
|
|
288
|
+
* ```ts
|
|
289
|
+
* asciiToBytes('ABC');
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
function asciiToBytes(ascii) {
|
|
293
|
+
if (typeof ascii !== "string") throw new TypeError("ascii string expected, got " + typeof ascii);
|
|
294
|
+
return Uint8Array.from(ascii, (c, i) => {
|
|
295
|
+
const charCode = c.charCodeAt(0);
|
|
296
|
+
if (c.length !== 1 || charCode > 127) throw new RangeError(`string contains non-ASCII character "${ascii[i]}" with code ${charCode} at position ${i}`);
|
|
297
|
+
return charCode;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const isPosBig = (n) => typeof n === "bigint" && _0n <= n;
|
|
301
|
+
/**
|
|
302
|
+
* Checks whether a bigint lies inside a half-open range.
|
|
303
|
+
* @param n - Candidate value.
|
|
304
|
+
* @param min - Inclusive lower bound.
|
|
305
|
+
* @param max - Exclusive upper bound.
|
|
306
|
+
* @returns `true` when the value is inside the range.
|
|
307
|
+
* @example
|
|
308
|
+
* Check whether a candidate scalar fits the field order.
|
|
309
|
+
*
|
|
310
|
+
* ```ts
|
|
311
|
+
* inRange(2n, 1n, 3n);
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
function inRange(n, min, max) {
|
|
315
|
+
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Asserts `min <= n < max`. NOTE: upper bound is exclusive.
|
|
319
|
+
* @param title - Value label for error messages.
|
|
320
|
+
* @param n - Candidate value.
|
|
321
|
+
* @param min - Inclusive lower bound.
|
|
322
|
+
* @param max - Exclusive upper bound.
|
|
323
|
+
* Wrong-type inputs are not separated from out-of-range values here: they still flow through the
|
|
324
|
+
* shared `RangeError` path because this is only a throwing wrapper around `inRange(...)`.
|
|
325
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
326
|
+
* @example
|
|
327
|
+
* Assert that a bigint stays within one half-open range.
|
|
328
|
+
*
|
|
329
|
+
* ```ts
|
|
330
|
+
* aInRange('x', 2n, 1n, 256n);
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
function aInRange(title, n, min, max) {
|
|
334
|
+
if (!inRange(n, min, max)) throw new RangeError("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Calculates amount of bits in a bigint.
|
|
338
|
+
* Same as `n.toString(2).length`
|
|
339
|
+
* TODO: merge with nLength in modular
|
|
340
|
+
* @param n - Value to inspect.
|
|
341
|
+
* @returns Bit length.
|
|
342
|
+
* @throws If the value is negative. {@link Error}
|
|
343
|
+
* @example
|
|
344
|
+
* Measure the bit length of a scalar before serialization.
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* bitLen(8n);
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
function bitLen(n) {
|
|
351
|
+
if (n < _0n) throw new Error("expected non-negative bigint, got " + n);
|
|
352
|
+
let len;
|
|
353
|
+
for (len = 0; n > _0n; n >>= _1n, len += 1);
|
|
354
|
+
return len;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Calculate mask for N bits. Not using ** operator with bigints because of old engines.
|
|
358
|
+
* Same as BigInt(`0b${Array(i).fill('1').join('')}`)
|
|
359
|
+
* @param n - Number of bits. Negative widths are currently passed through to raw bigint shift
|
|
360
|
+
* semantics and therefore produce `-1n`.
|
|
361
|
+
* @returns Bitmask value.
|
|
362
|
+
* @example
|
|
363
|
+
* Calculate mask for N bits.
|
|
364
|
+
*
|
|
365
|
+
* ```ts
|
|
366
|
+
* bitMask(4);
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
const bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
370
|
+
/**
|
|
371
|
+
* Validates declared required and optional field types on a plain object.
|
|
372
|
+
* Extra keys are intentionally ignored because many callers validate only the subset they use from
|
|
373
|
+
* richer option bags or runtime objects.
|
|
374
|
+
* @param object - Object to validate.
|
|
375
|
+
* @param fields - Required field types.
|
|
376
|
+
* @param optFields - Optional field types.
|
|
377
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
378
|
+
* @example
|
|
379
|
+
* Check user options before building a curve helper.
|
|
380
|
+
*
|
|
381
|
+
* ```ts
|
|
382
|
+
* validateObject({ flag: true }, { flag: 'boolean' });
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
function validateObject(object, fields = {}, optFields = {}) {
|
|
386
|
+
if (Object.prototype.toString.call(object) !== "[object Object]") throw new TypeError("expected valid options object");
|
|
387
|
+
function checkField(fieldName, expectedType, isOpt) {
|
|
388
|
+
if (!isOpt && expectedType !== "function" && !Object.hasOwn(object, fieldName)) throw new TypeError(`param "${fieldName}" is invalid: expected own property`);
|
|
389
|
+
const val = object[fieldName];
|
|
390
|
+
if (isOpt && val === void 0) return;
|
|
391
|
+
const current = typeof val;
|
|
392
|
+
if (current !== expectedType || val === null) throw new TypeError(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
393
|
+
}
|
|
394
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
|
|
395
|
+
iter(fields, false);
|
|
396
|
+
iter(optFields, true);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Throws not implemented error.
|
|
400
|
+
* @returns Never returns.
|
|
401
|
+
* @throws If the unfinished code path is reached. {@link Error}
|
|
402
|
+
* @example
|
|
403
|
+
* Surface the placeholder error from an unfinished code path.
|
|
404
|
+
*
|
|
405
|
+
* ```ts
|
|
406
|
+
* try {
|
|
407
|
+
* notImplemented();
|
|
408
|
+
* } catch {}
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
const notImplemented = () => {
|
|
412
|
+
throw new Error("not implemented");
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
exports.aInRange = aInRange;
|
|
417
|
+
exports.abool = abool;
|
|
418
|
+
exports.abytes = abytes;
|
|
419
|
+
exports.anumber = anumber;
|
|
420
|
+
exports.asafenumber = asafenumber;
|
|
421
|
+
exports.asciiToBytes = asciiToBytes;
|
|
422
|
+
exports.bitLen = bitLen;
|
|
423
|
+
exports.bitMask = bitMask;
|
|
424
|
+
exports.bytesToHex = bytesToHex;
|
|
425
|
+
exports.bytesToNumberBE = bytesToNumberBE;
|
|
426
|
+
exports.bytesToNumberLE = bytesToNumberLE;
|
|
427
|
+
exports.concatBytes = concatBytes;
|
|
428
|
+
exports.copyBytes = copyBytes;
|
|
429
|
+
exports.equalBytes = equalBytes;
|
|
430
|
+
exports.hexToBytes = hexToBytes;
|
|
431
|
+
exports.isBytes = isBytes;
|
|
432
|
+
exports.notImplemented = notImplemented;
|
|
433
|
+
exports.numberToBytesBE = numberToBytesBE;
|
|
434
|
+
exports.numberToBytesLE = numberToBytesLE;
|
|
435
|
+
exports.randomBytes = randomBytes;
|
|
436
|
+
exports.validateObject = validateObject;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|