-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·4477 lines (4442 loc) · 167 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/drand-client/version.js
var require_version = __commonJS({
"node_modules/drand-client/version.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LIB_VERSION = void 0;
exports.LIB_VERSION = "1.2.1";
}
});
// node_modules/drand-client/util.js
var require_util = __commonJS({
"node_modules/drand-client/util.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.retryOnError = exports.jsonOrError = exports.defaultHttpOptions = exports.roundTime = exports.roundAt = exports.sleep = void 0;
var version_1 = require_version();
function sleep(timeMs) {
return new Promise((resolve) => {
if (timeMs <= 0) {
resolve();
}
setTimeout(resolve, timeMs);
});
}
exports.sleep = sleep;
function roundAt2(time, chain) {
if (!Number.isFinite(time)) {
throw new Error("Cannot use Infinity or NaN as a beacon time");
}
if (time < chain.genesis_time * 1e3) {
throw Error("Cannot request a round before the genesis time");
}
return Math.floor((time - chain.genesis_time * 1e3) / (chain.period * 1e3)) + 1;
}
exports.roundAt = roundAt2;
function roundTime(chain, round) {
if (!Number.isFinite(round)) {
throw new Error("Cannot use Infinity or NaN as a round number");
}
round = round < 0 ? 0 : round;
return (chain.genesis_time + (round - 1) * chain.period) * 1e3;
}
exports.roundTime = roundTime;
exports.defaultHttpOptions = {
userAgent: `drand-client-${version_1.LIB_VERSION}`
};
async function jsonOrError(url, options = exports.defaultHttpOptions) {
const headers = { ...options.headers };
if (options.userAgent) {
headers["User-Agent"] = options.userAgent;
}
const response = await fetch(url, { headers });
if (!response.ok) {
throw Error(`Error response fetching ${url} - got ${response.status}`);
}
return await response.json();
}
exports.jsonOrError = jsonOrError;
async function retryOnError(fn, times) {
try {
return await fn();
} catch (err) {
if (times === 0) {
throw err;
}
return retryOnError(fn, times - 1);
}
}
exports.retryOnError = retryOnError;
}
});
// node_modules/drand-client/http-caching-chain.js
var require_http_caching_chain = __commonJS({
"node_modules/drand-client/http-caching-chain.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpChain = void 0;
var index_1 = require_drand_client();
var util_1 = require_util();
var HttpChain = class {
baseUrl;
options;
httpOptions;
constructor(baseUrl, options = index_1.defaultChainOptions, httpOptions = {}) {
this.baseUrl = baseUrl;
this.options = options;
this.httpOptions = httpOptions;
}
async info() {
const chainInfo = await (0, util_1.jsonOrError)(`${this.baseUrl}/info`, this.httpOptions);
if (!!this.options.chainVerificationParams && !isValidInfo(chainInfo, this.options.chainVerificationParams)) {
throw Error(`The chain info retrieved from ${this.baseUrl} did not match the verification params!`);
}
return chainInfo;
}
};
exports.HttpChain = HttpChain;
function isValidInfo(chainInfo, validParams) {
return chainInfo.hash === validParams.chainHash && chainInfo.public_key === validParams.publicKey;
}
var HttpCachingChain2 = class {
baseUrl;
options;
chain;
cachedInfo;
constructor(baseUrl, options = index_1.defaultChainOptions) {
this.baseUrl = baseUrl;
this.options = options;
this.chain = new HttpChain(baseUrl, options);
}
async info() {
if (!this.cachedInfo) {
this.cachedInfo = await this.chain.info();
}
return this.cachedInfo;
}
};
exports.default = HttpCachingChain2;
}
});
// node_modules/drand-client/http-chain-client.js
var require_http_chain_client = __commonJS({
"node_modules/drand-client/http-chain-client.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require_drand_client();
var util_1 = require_util();
var HttpChainClient2 = class {
someChain;
options;
httpOptions;
constructor(someChain, options = index_1.defaultChainOptions, httpOptions = util_1.defaultHttpOptions) {
this.someChain = someChain;
this.options = options;
this.httpOptions = httpOptions;
}
async get(roundNumber) {
const url = withCachingParams(`${this.someChain.baseUrl}/public/${roundNumber}`, this.options);
return await (0, util_1.jsonOrError)(url, this.httpOptions);
}
async latest() {
const url = withCachingParams(`${this.someChain.baseUrl}/public/latest`, this.options);
return await (0, util_1.jsonOrError)(url, this.httpOptions);
}
chain() {
return this.someChain;
}
};
function withCachingParams(url, config) {
if (config.noCache) {
return `${url}?${Date.now()}`;
}
return url;
}
exports.default = HttpChainClient2;
}
});
// node_modules/drand-client/speedtest.js
var require_speedtest = __commonJS({
"node_modules/drand-client/speedtest.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSpeedTest = void 0;
function createSpeedTest(test, frequencyMs, samples = 5) {
let queue = new DroppingQueue(samples);
let intervalId = null;
const executeSpeedTest = async () => {
const startTime = Date.now();
try {
await test();
queue.add(Date.now() - startTime);
} catch (err) {
queue.add(Number.MAX_SAFE_INTEGER);
}
};
return {
start: () => {
if (intervalId != null) {
console.warn("Attempted to start a speed test, but it had already been started!");
return;
}
intervalId = setInterval(executeSpeedTest, frequencyMs);
},
stop: () => {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
queue = new DroppingQueue(samples);
}
},
average: () => {
const values = queue.get();
if (values.length === 0) {
return Number.MAX_SAFE_INTEGER;
}
const total = values.reduce((acc, next) => acc + next, 0);
return total / values.length;
}
};
}
exports.createSpeedTest = createSpeedTest;
var DroppingQueue = class {
capacity;
values = [];
constructor(capacity) {
this.capacity = capacity;
}
add(value) {
this.values.push(value);
if (this.values.length > this.capacity) {
this.values.pop();
}
}
get() {
return this.values;
}
};
}
});
// node_modules/drand-client/fastest-node-client.js
var require_fastest_node_client = __commonJS({
"node_modules/drand-client/fastest-node-client.js"(exports) {
"use strict";
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
o[k2] = m[k];
});
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
} : function(o, v) {
o["default"] = v;
});
var __importStar = exports && exports.__importStar || function(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null) {
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
}
__setModuleDefault(result, mod);
return result;
};
var __importDefault = exports && exports.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require_drand_client();
var http_caching_chain_1 = __importStar(require_http_caching_chain());
var speedtest_1 = require_speedtest();
var http_chain_client_1 = __importDefault(require_http_chain_client());
var defaultSpeedTestInterval = 1e3 * 60 * 5;
var FastestNodeClient = class {
baseUrls;
options;
speedTestIntervalMs;
speedTests = [];
speedTestHttpOptions = { userAgent: "drand-web-client-speedtest" };
constructor(baseUrls, options = index_1.defaultChainOptions, speedTestIntervalMs = defaultSpeedTestInterval) {
this.baseUrls = baseUrls;
this.options = options;
this.speedTestIntervalMs = speedTestIntervalMs;
if (baseUrls.length === 0) {
throw Error("Can't optimise an empty `baseUrls` array!");
}
}
async latest() {
return new http_chain_client_1.default(this.current(), this.options).latest();
}
async get(roundNumber) {
return new http_chain_client_1.default(this.current(), this.options).get(roundNumber);
}
chain() {
return this.current();
}
start() {
if (this.baseUrls.length === 1) {
console.warn("There was only a single base URL in the `FastestNodeClient` - not running speed testing");
return;
}
this.speedTests = this.baseUrls.map((url) => {
const testFn = async () => {
await new http_caching_chain_1.HttpChain(url, this.options, this.speedTestHttpOptions).info();
return;
};
const test = (0, speedtest_1.createSpeedTest)(testFn, this.speedTestIntervalMs);
test.start();
return { test, url };
});
}
current() {
if (this.speedTests.length === 0) {
console.warn("You are not currently running speed tests to choose the fastest client. Run `.start()` to speed test");
}
const fastestEntry = this.speedTests.slice().sort((entry1, entry2) => entry1.test.average() - entry2.test.average()).shift();
if (!fastestEntry) {
throw Error("Somehow there were no entries to optimise! This should be impossible by now");
}
return new http_caching_chain_1.default(fastestEntry.url, this.options);
}
stop() {
this.speedTests.forEach((entry) => entry.test.stop());
this.speedTests = [];
}
};
exports.default = FastestNodeClient;
}
});
// node_modules/drand-client/multi-beacon-node.js
var require_multi_beacon_node = __commonJS({
"node_modules/drand-client/multi-beacon-node.js"(exports) {
"use strict";
var __importDefault = exports && exports.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require_drand_client();
var http_caching_chain_1 = __importDefault(require_http_caching_chain());
var util_1 = require_util();
var MultiBeaconNode = class {
baseUrl;
options;
constructor(baseUrl, options = index_1.defaultChainOptions) {
this.baseUrl = baseUrl;
this.options = options;
}
async chains() {
const chains = await (0, util_1.jsonOrError)(`${this.baseUrl}/chains`);
if (!Array.isArray(chains)) {
throw Error(`Expected an array from the chains endpoint but got: ${chains}`);
}
return chains.map((chainHash) => new http_caching_chain_1.default(`${this.baseUrl}/${chainHash}`), this.options);
}
async health() {
const response = await fetch(`${this.baseUrl}/health`);
if (!response.ok) {
return {
status: response.status,
current: -1,
expected: -1
};
}
const json = await response.json();
return {
status: response.status,
current: json.current ?? -1,
expected: json.expected ?? -1
};
}
};
exports.default = MultiBeaconNode;
}
});
// node_modules/@noble/hashes/_assert.js
var require_assert = __commonJS({
"node_modules/@noble/hashes/_assert.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.output = exports.exists = exports.hash = exports.bytes = exports.bool = exports.number = void 0;
function number(n) {
if (!Number.isSafeInteger(n) || n < 0)
throw new Error(`Wrong positive integer: ${n}`);
}
exports.number = number;
function bool(b) {
if (typeof b !== "boolean")
throw new Error(`Expected boolean, not ${b}`);
}
exports.bool = bool;
function bytes2(b, ...lengths) {
if (!(b instanceof Uint8Array))
throw new Error("Expected Uint8Array");
if (lengths.length > 0 && !lengths.includes(b.length))
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
}
exports.bytes = bytes2;
function hash(hash2) {
if (typeof hash2 !== "function" || typeof hash2.create !== "function")
throw new Error("Hash should be wrapped by utils.wrapConstructor");
number(hash2.outputLen);
number(hash2.blockLen);
}
exports.hash = hash;
function exists2(instance, checkFinished = true) {
if (instance.destroyed)
throw new Error("Hash instance has been destroyed");
if (checkFinished && instance.finished)
throw new Error("Hash#digest() has already been called");
}
exports.exists = exists2;
function output2(out, instance) {
bytes2(out);
const min = instance.outputLen;
if (out.length < min) {
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
}
}
exports.output = output2;
var assert = { number, bool, bytes: bytes2, hash, exists: exists2, output: output2 };
exports.default = assert;
}
});
// node_modules/@noble/hashes/cryptoNode.js
var require_cryptoNode = __commonJS({
"node_modules/@noble/hashes/cryptoNode.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.crypto = void 0;
var nc = require("node:crypto");
exports.crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : void 0;
}
});
// node_modules/@noble/hashes/utils.js
var require_utils = __commonJS({
"node_modules/@noble/hashes/utils.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomBytes = exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.utf8ToBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
var crypto_1 = require_cryptoNode();
var u8a2 = (a) => a instanceof Uint8Array;
var u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
exports.u8 = u8;
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
exports.u32 = u32;
var createView2 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
exports.createView = createView2;
var rotr2 = (word, shift) => word << 32 - shift | word >>> shift;
exports.rotr = rotr2;
exports.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
if (!exports.isLE)
throw new Error("Non little-endian hardware is not supported");
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
function bytesToHex(bytes2) {
if (!u8a2(bytes2))
throw new Error("Uint8Array expected");
let hex = "";
for (let i = 0; i < bytes2.length; i++) {
hex += hexes[bytes2[i]];
}
return hex;
}
exports.bytesToHex = bytesToHex;
function hexToBytes(hex) {
if (typeof hex !== "string")
throw new Error("hex string expected, got " + typeof hex);
const len = hex.length;
if (len % 2)
throw new Error("padded hex string expected, got unpadded hex of length " + len);
const array = new Uint8Array(len / 2);
for (let i = 0; i < array.length; i++) {
const j = i * 2;
const hexByte = hex.slice(j, j + 2);
const byte = Number.parseInt(hexByte, 16);
if (Number.isNaN(byte) || byte < 0)
throw new Error("Invalid byte sequence");
array[i] = byte;
}
return array;
}
exports.hexToBytes = hexToBytes;
var nextTick = async () => {
};
exports.nextTick = nextTick;
async function asyncLoop(iters, tick, cb) {
let ts = Date.now();
for (let i = 0; i < iters; i++) {
cb(i);
const diff = Date.now() - ts;
if (diff >= 0 && diff < tick)
continue;
await (0, exports.nextTick)();
ts += diff;
}
}
exports.asyncLoop = asyncLoop;
function utf8ToBytes2(str) {
if (typeof str !== "string")
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
return new Uint8Array(new TextEncoder().encode(str));
}
exports.utf8ToBytes = utf8ToBytes2;
function toBytes2(data) {
if (typeof data === "string")
data = utf8ToBytes2(data);
if (!u8a2(data))
throw new Error(`expected Uint8Array, got ${typeof data}`);
return data;
}
exports.toBytes = toBytes2;
function concatBytes(...arrays) {
const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
let pad = 0;
arrays.forEach((a) => {
if (!u8a2(a))
throw new Error("Uint8Array expected");
r.set(a, pad);
pad += a.length;
});
return r;
}
exports.concatBytes = concatBytes;
var Hash2 = class {
// Safe version that clones internal state
clone() {
return this._cloneInto();
}
};
exports.Hash = Hash2;
var toStr2 = {}.toString;
function checkOpts(defaults, opts) {
if (opts !== void 0 && toStr2.call(opts) !== "[object Object]")
throw new Error("Options should be object or undefined");
const merged = Object.assign(defaults, opts);
return merged;
}
exports.checkOpts = checkOpts;
function wrapConstructor2(hashCons) {
const hashC = (msg) => hashCons().update(toBytes2(msg)).digest();
const tmp = hashCons();
hashC.outputLen = tmp.outputLen;
hashC.blockLen = tmp.blockLen;
hashC.create = () => hashCons();
return hashC;
}
exports.wrapConstructor = wrapConstructor2;
function wrapConstructorWithOpts(hashCons) {
const hashC = (msg, opts) => hashCons(opts).update(toBytes2(msg)).digest();
const tmp = hashCons({});
hashC.outputLen = tmp.outputLen;
hashC.blockLen = tmp.blockLen;
hashC.create = (opts) => hashCons(opts);
return hashC;
}
exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
function wrapXOFConstructorWithOpts(hashCons) {
const hashC = (msg, opts) => hashCons(opts).update(toBytes2(msg)).digest();
const tmp = hashCons({});
hashC.outputLen = tmp.outputLen;
hashC.blockLen = tmp.blockLen;
hashC.create = (opts) => hashCons(opts);
return hashC;
}
exports.wrapXOFConstructorWithOpts = wrapXOFConstructorWithOpts;
function randomBytes(bytesLength = 32) {
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
}
throw new Error("crypto.getRandomValues must be defined");
}
exports.randomBytes = randomBytes;
}
});
// node_modules/@noble/hashes/_sha2.js
var require_sha2 = __commonJS({
"node_modules/@noble/hashes/_sha2.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SHA2 = void 0;
var _assert_js_1 = require_assert();
var utils_js_1 = require_utils();
function setBigUint642(view, byteOffset, value, isLE2) {
if (typeof view.setBigUint64 === "function")
return view.setBigUint64(byteOffset, value, isLE2);
const _32n = BigInt(32);
const _u32_max = BigInt(4294967295);
const wh = Number(value >> _32n & _u32_max);
const wl = Number(value & _u32_max);
const h = isLE2 ? 4 : 0;
const l = isLE2 ? 0 : 4;
view.setUint32(byteOffset + h, wh, isLE2);
view.setUint32(byteOffset + l, wl, isLE2);
}
var SHA22 = class extends utils_js_1.Hash {
constructor(blockLen, outputLen, padOffset, isLE2) {
super();
this.blockLen = blockLen;
this.outputLen = outputLen;
this.padOffset = padOffset;
this.isLE = isLE2;
this.finished = false;
this.length = 0;
this.pos = 0;
this.destroyed = false;
this.buffer = new Uint8Array(blockLen);
this.view = (0, utils_js_1.createView)(this.buffer);
}
update(data) {
(0, _assert_js_1.exists)(this);
const { view, buffer, blockLen } = this;
data = (0, utils_js_1.toBytes)(data);
const len = data.length;
for (let pos = 0; pos < len; ) {
const take = Math.min(blockLen - this.pos, len - pos);
if (take === blockLen) {
const dataView = (0, utils_js_1.createView)(data);
for (; blockLen <= len - pos; pos += blockLen)
this.process(dataView, pos);
continue;
}
buffer.set(data.subarray(pos, pos + take), this.pos);
this.pos += take;
pos += take;
if (this.pos === blockLen) {
this.process(view, 0);
this.pos = 0;
}
}
this.length += data.length;
this.roundClean();
return this;
}
digestInto(out) {
(0, _assert_js_1.exists)(this);
(0, _assert_js_1.output)(out, this);
this.finished = true;
const { buffer, view, blockLen, isLE: isLE2 } = this;
let { pos } = this;
buffer[pos++] = 128;
this.buffer.subarray(pos).fill(0);
if (this.padOffset > blockLen - pos) {
this.process(view, 0);
pos = 0;
}
for (let i = pos; i < blockLen; i++)
buffer[i] = 0;
setBigUint642(view, blockLen - 8, BigInt(this.length * 8), isLE2);
this.process(view, 0);
const oview = (0, utils_js_1.createView)(out);
const len = this.outputLen;
if (len % 4)
throw new Error("_sha2: outputLen should be aligned to 32bit");
const outLen = len / 4;
const state = this.get();
if (outLen > state.length)
throw new Error("_sha2: outputLen bigger than state");
for (let i = 0; i < outLen; i++)
oview.setUint32(4 * i, state[i], isLE2);
}
digest() {
const { buffer, outputLen } = this;
this.digestInto(buffer);
const res = buffer.slice(0, outputLen);
this.destroy();
return res;
}
_cloneInto(to) {
to || (to = new this.constructor());
to.set(...this.get());
const { blockLen, buffer, length, finished, destroyed, pos } = this;
to.length = length;
to.pos = pos;
to.finished = finished;
to.destroyed = destroyed;
if (length % blockLen)
to.buffer.set(buffer);
return to;
}
};
exports.SHA2 = SHA22;
}
});
// node_modules/@noble/hashes/sha256.js
var require_sha256 = __commonJS({
"node_modules/@noble/hashes/sha256.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha224 = exports.sha256 = void 0;
var _sha2_js_1 = require_sha2();
var utils_js_1 = require_utils();
var Chi2 = (a, b, c) => a & b ^ ~a & c;
var Maj2 = (a, b, c) => a & b ^ a & c ^ b & c;
var SHA256_K2 = /* @__PURE__ */ new Uint32Array([
1116352408,
1899447441,
3049323471,
3921009573,
961987163,
1508970993,
2453635748,
2870763221,
3624381080,
310598401,
607225278,
1426881987,
1925078388,
2162078206,
2614888103,
3248222580,
3835390401,
4022224774,
264347078,
604807628,
770255983,
1249150122,
1555081692,
1996064986,
2554220882,
2821834349,
2952996808,
3210313671,
3336571891,
3584528711,
113926993,
338241895,
666307205,
773529912,
1294757372,
1396182291,
1695183700,
1986661051,
2177026350,
2456956037,
2730485921,
2820302411,
3259730800,
3345764771,
3516065817,
3600352804,
4094571909,
275423344,
430227734,
506948616,
659060556,
883997877,
958139571,
1322822218,
1537002063,
1747873779,
1955562222,
2024104815,
2227730452,
2361852424,
2428436474,
2756734187,
3204031479,
3329325298
]);
var IV2 = /* @__PURE__ */ new Uint32Array([
1779033703,
3144134277,
1013904242,
2773480762,
1359893119,
2600822924,
528734635,
1541459225
]);
var SHA256_W2 = /* @__PURE__ */ new Uint32Array(64);
var SHA2562 = class extends _sha2_js_1.SHA2 {
constructor() {
super(64, 32, 8, false);
this.A = IV2[0] | 0;
this.B = IV2[1] | 0;
this.C = IV2[2] | 0;
this.D = IV2[3] | 0;
this.E = IV2[4] | 0;
this.F = IV2[5] | 0;
this.G = IV2[6] | 0;
this.H = IV2[7] | 0;
}
get() {
const { A, B, C, D, E, F, G, H } = this;
return [A, B, C, D, E, F, G, H];
}
// prettier-ignore
set(A, B, C, D, E, F, G, H) {
this.A = A | 0;
this.B = B | 0;
this.C = C | 0;
this.D = D | 0;
this.E = E | 0;
this.F = F | 0;
this.G = G | 0;
this.H = H | 0;
}
process(view, offset) {
for (let i = 0; i < 16; i++, offset += 4)
SHA256_W2[i] = view.getUint32(offset, false);
for (let i = 16; i < 64; i++) {
const W15 = SHA256_W2[i - 15];
const W2 = SHA256_W2[i - 2];
const s0 = (0, utils_js_1.rotr)(W15, 7) ^ (0, utils_js_1.rotr)(W15, 18) ^ W15 >>> 3;
const s1 = (0, utils_js_1.rotr)(W2, 17) ^ (0, utils_js_1.rotr)(W2, 19) ^ W2 >>> 10;
SHA256_W2[i] = s1 + SHA256_W2[i - 7] + s0 + SHA256_W2[i - 16] | 0;
}
let { A, B, C, D, E, F, G, H } = this;
for (let i = 0; i < 64; i++) {
const sigma1 = (0, utils_js_1.rotr)(E, 6) ^ (0, utils_js_1.rotr)(E, 11) ^ (0, utils_js_1.rotr)(E, 25);
const T1 = H + sigma1 + Chi2(E, F, G) + SHA256_K2[i] + SHA256_W2[i] | 0;
const sigma0 = (0, utils_js_1.rotr)(A, 2) ^ (0, utils_js_1.rotr)(A, 13) ^ (0, utils_js_1.rotr)(A, 22);
const T2 = sigma0 + Maj2(A, B, C) | 0;
H = G;
G = F;
F = E;
E = D + T1 | 0;
D = C;
C = B;
B = A;
A = T1 + T2 | 0;
}
A = A + this.A | 0;
B = B + this.B | 0;
C = C + this.C | 0;
D = D + this.D | 0;
E = E + this.E | 0;
F = F + this.F | 0;
G = G + this.G | 0;
H = H + this.H | 0;
this.set(A, B, C, D, E, F, G, H);
}
roundClean() {
SHA256_W2.fill(0);
}
destroy() {
this.set(0, 0, 0, 0, 0, 0, 0, 0);
this.buffer.fill(0);
}
};
var SHA224 = class extends SHA2562 {
constructor() {
super();
this.A = 3238371032 | 0;
this.B = 914150663 | 0;
this.C = 812702999 | 0;
this.D = 4144912697 | 0;
this.E = 4290775857 | 0;
this.F = 1750603025 | 0;
this.G = 1694076839 | 0;
this.H = 3204075428 | 0;
this.outputLen = 28;
}
};
exports.sha256 = (0, utils_js_1.wrapConstructor)(() => new SHA2562());
exports.sha224 = (0, utils_js_1.wrapConstructor)(() => new SHA224());
}
});
// node_modules/@noble/curves/abstract/utils.js
var require_utils2 = __commonJS({
"node_modules/@noble/curves/abstract/utils.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateObject = exports.createHmacDrbg = exports.bitMask = exports.bitSet = exports.bitGet = exports.bitLen = exports.utf8ToBytes = exports.equalBytes = exports.concatBytes = exports.ensureBytes = exports.numberToVarBytesBE = exports.numberToBytesLE = exports.numberToBytesBE = exports.bytesToNumberLE = exports.bytesToNumberBE = exports.hexToBytes = exports.hexToNumber = exports.numberToHexUnpadded = exports.bytesToHex = void 0;
var _0n = BigInt(0);
var _1n = BigInt(1);
var _2n = BigInt(2);
var u8a2 = (a) => a instanceof Uint8Array;
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
function bytesToHex(bytes2) {
if (!u8a2(bytes2))
throw new Error("Uint8Array expected");
let hex = "";
for (let i = 0; i < bytes2.length; i++) {
hex += hexes[bytes2[i]];
}
return hex;
}
exports.bytesToHex = bytesToHex;
function numberToHexUnpadded(num) {
const hex = num.toString(16);
return hex.length & 1 ? `0${hex}` : hex;
}
exports.numberToHexUnpadded = numberToHexUnpadded;
function hexToNumber(hex) {
if (typeof hex !== "string")
throw new Error("hex string expected, got " + typeof hex);
return BigInt(hex === "" ? "0" : `0x${hex}`);
}
exports.hexToNumber = hexToNumber;
function hexToBytes(hex) {
if (typeof hex !== "string")
throw new Error("hex string expected, got " + typeof hex);
const len = hex.length;
if (len % 2)
throw new Error("padded hex string expected, got unpadded hex of length " + len);
const array = new Uint8Array(len / 2);
for (let i = 0; i < array.length; i++) {
const j = i * 2;
const hexByte = hex.slice(j, j + 2);
const byte = Number.parseInt(hexByte, 16);
if (Number.isNaN(byte) || byte < 0)
throw new Error("Invalid byte sequence");
array[i] = byte;
}
return array;
}
exports.hexToBytes = hexToBytes;
function bytesToNumberBE(bytes2) {
return hexToNumber(bytesToHex(bytes2));
}
exports.bytesToNumberBE = bytesToNumberBE;
function bytesToNumberLE(bytes2) {
if (!u8a2(bytes2))
throw new Error("Uint8Array expected");
return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
}
exports.bytesToNumberLE = bytesToNumberLE;
function numberToBytesBE(n, len) {
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
}
exports.numberToBytesBE = numberToBytesBE;
function numberToBytesLE(n, len) {
return numberToBytesBE(n, len).reverse();
}
exports.numberToBytesLE = numberToBytesLE;
function numberToVarBytesBE(n) {
return hexToBytes(numberToHexUnpadded(n));
}
exports.numberToVarBytesBE = numberToVarBytesBE;
function ensureBytes(title, hex, expectedLength) {
let res;
if (typeof hex === "string") {
try {
res = hexToBytes(hex);
} catch (e) {
throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
}
} else if (u8a2(hex)) {
res = Uint8Array.from(hex);
} else {
throw new Error(`${title} must be hex string or Uint8Array`);
}
const len = res.length;
if (typeof expectedLength === "number" && len !== expectedLength)
throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
return res;
}
exports.ensureBytes = ensureBytes;
function concatBytes(...arrays) {
const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
let pad = 0;
arrays.forEach((a) => {
if (!u8a2(a))
throw new Error("Uint8Array expected");
r.set(a, pad);
pad += a.length;
});
return r;
}
exports.concatBytes = concatBytes;
function equalBytes(b1, b2) {
if (b1.length !== b2.length)
return false;
for (let i = 0; i < b1.length; i++)
if (b1[i] !== b2[i])