@leofcoin/peernet 0.18.8 → 1.0.1

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.
@@ -1,2999 +0,0 @@
1
- import { K as KeyValue } from './value-40634404.js';
2
-
3
- if (!globalThis.DEBUG) {
4
- if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
5
- }
6
-
7
- globalThis.debug = text => {
8
- if (globalThis.DEBUG) console.log('\x1b[34m\x1b[1m%s', text, '\x1b[0m'); // bright blue
9
- };
10
-
11
- class LittlePubSub {
12
- subscribers = {};
13
- verbose;
14
- constructor(verbose = false) {
15
- this.verbose = verbose;
16
- }
17
- #handleContext(handler, context) {
18
- if (typeof context === 'undefined') {
19
- context = handler;
20
- }
21
- return context;
22
- }
23
- hasSubscribers(event) {
24
- return this.subscribers[event] ? true : false;
25
- }
26
- subscribe(event, handler, context) {
27
- if (!this.hasSubscribers(event))
28
- this.subscribers[event] = { handlers: [], value: undefined };
29
- context = this.#handleContext(handler, context);
30
- this.subscribers[event].handlers.push(handler.bind(context));
31
- }
32
- unsubscribe(event, handler, context) {
33
- if (!this.hasSubscribers(event))
34
- return;
35
- context = this.#handleContext(handler, context);
36
- const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
37
- this.subscribers[event].handlers.splice(index);
38
- if (this.subscribers[event].handlers.length === 0)
39
- delete this.subscribers[event];
40
- }
41
- publish(event, change) {
42
- if (!this.hasSubscribers(event))
43
- return;
44
- if (this.verbose || this.subscribers[event].value !== change) {
45
- this.subscribers[event].value = change;
46
- this.subscribers[event].handlers.forEach((handler) => {
47
- handler(change, this.subscribers[event].value);
48
- });
49
- }
50
- }
51
- once(event) {
52
- return new Promise((resolve) => {
53
- const cb = (value) => {
54
- this.unsubscribe(event, cb);
55
- resolve(value);
56
- };
57
- this.subscribe(event, cb);
58
- });
59
- }
60
- }
61
-
62
- // base-x encoding / decoding
63
- // Copyright (c) 2018 base-x contributors
64
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
65
- // Distributed under the MIT software license, see the accompanying
66
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
67
- const base = (ALPHABET) => {
68
- if (ALPHABET.length >= 255) {
69
- throw new TypeError('Alphabet too long');
70
- }
71
- const BASE_MAP = new Uint8Array(256);
72
- for (let j = 0; j < BASE_MAP.length; j++) {
73
- BASE_MAP[j] = 255;
74
- }
75
- for (let i = 0; i < ALPHABET.length; i++) {
76
- const x = ALPHABET.charAt(i);
77
- const xc = x.charCodeAt(0);
78
- if (BASE_MAP[xc] !== 255) {
79
- throw new TypeError(x + ' is ambiguous');
80
- }
81
- BASE_MAP[xc] = i;
82
- }
83
- const BASE = ALPHABET.length;
84
- const LEADER = ALPHABET.charAt(0);
85
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
86
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
87
- const encode = (source) => {
88
- if (source instanceof Uint8Array) ;
89
- else if (ArrayBuffer.isView(source)) {
90
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
91
- }
92
- else if (Array.isArray(source)) {
93
- source = Uint8Array.from(source);
94
- }
95
- if (!(source instanceof Uint8Array)) {
96
- throw new TypeError('Expected Uint8Array');
97
- }
98
- if (source.length === 0) {
99
- return '';
100
- }
101
- // Skip & count leading zeroes.
102
- let zeroes = 0;
103
- let length = 0;
104
- let pbegin = 0;
105
- const pend = source.length;
106
- while (pbegin !== pend && source[pbegin] === 0) {
107
- pbegin++;
108
- zeroes++;
109
- }
110
- // Allocate enough space in big-endian base58 representation.
111
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
112
- const b58 = new Uint8Array(size);
113
- // Process the bytes.
114
- while (pbegin !== pend) {
115
- let carry = source[pbegin];
116
- // Apply "b58 = b58 * 256 + ch".
117
- let i = 0;
118
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
119
- carry += (256 * b58[it1]) >>> 0;
120
- b58[it1] = (carry % BASE) >>> 0;
121
- carry = (carry / BASE) >>> 0;
122
- }
123
- if (carry !== 0) {
124
- throw new Error('Non-zero carry');
125
- }
126
- length = i;
127
- pbegin++;
128
- }
129
- // Skip leading zeroes in base58 result.
130
- let it2 = size - length;
131
- while (it2 !== size && b58[it2] === 0) {
132
- it2++;
133
- }
134
- // Translate the result into a string.
135
- let str = LEADER.repeat(zeroes);
136
- for (; it2 < size; ++it2) {
137
- str += ALPHABET.charAt(b58[it2]);
138
- }
139
- return str;
140
- };
141
- const decodeUnsafe = (source) => {
142
- if (typeof source !== 'string') {
143
- throw new TypeError('Expected String');
144
- }
145
- if (source.length === 0) {
146
- return new Uint8Array();
147
- }
148
- let psz = 0;
149
- // Skip and count leading '1's.
150
- let zeroes = 0;
151
- let length = 0;
152
- while (source[psz] === LEADER) {
153
- zeroes++;
154
- psz++;
155
- }
156
- // Allocate enough space in big-endian base256 representation.
157
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
158
- let b256 = new Uint8Array(size);
159
- // Process the characters.
160
- while (source[psz]) {
161
- // Decode character
162
- let carry = BASE_MAP[source.charCodeAt(psz)];
163
- // Invalid character
164
- if (carry === 255) {
165
- return;
166
- }
167
- let i = 0;
168
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
169
- carry += (BASE * b256[it3]) >>> 0;
170
- b256[it3] = (carry % 256) >>> 0;
171
- carry = (carry / 256) >>> 0;
172
- }
173
- if (carry !== 0) {
174
- throw new Error('Non-zero carry');
175
- }
176
- length = i;
177
- psz++;
178
- }
179
- // Skip leading zeroes in b256.
180
- let it4 = size - length;
181
- while (it4 !== size && b256[it4] === 0) {
182
- it4++;
183
- }
184
- let vch = new Uint8Array(zeroes + (size - it4));
185
- let j = zeroes;
186
- while (it4 !== size) {
187
- vch[j++] = b256[it4++];
188
- }
189
- return vch;
190
- };
191
- const decode = (string) => {
192
- const buffer = decodeUnsafe(string);
193
- if (buffer) {
194
- return buffer;
195
- }
196
- throw new Error('Non-base' + BASE + ' character');
197
- };
198
- return {
199
- encode,
200
- decodeUnsafe,
201
- decode
202
- };
203
- };
204
-
205
- const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
206
- const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
207
- const base32 = base(ALPHABET$3);
208
- const base32Hex = base(ALPHABET_HEX$1);
209
- const decode$6 = base32.decode;
210
- const decodeHex$1 = base32Hex.decode;
211
- const encode$6 = base32.encode;
212
- const encodeHex$1 = base32Hex.encode;
213
- const isBase32 = (string, hex = false) => {
214
- try {
215
- if (hex)
216
- decodeHex$1(string);
217
- else
218
- decode$6(string);
219
- return true;
220
- }
221
- catch (e) {
222
- return false;
223
- }
224
- };
225
- const isBase32Hex = (string) => {
226
- return isBase32(string, true);
227
- };
228
- var index$7 = {
229
- encode: encode$6,
230
- decode: decode$6,
231
- encodeHex: encodeHex$1,
232
- decodeHex: decodeHex$1,
233
- isBase32,
234
- isBase32Hex
235
- };
236
-
237
- var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
238
- var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
239
- var base58 = base(ALPHABET$2);
240
- var base58Hex = base(ALPHABET_HEX);
241
- var encode$5 = base58.encode;
242
- var decode$5 = base58.decode;
243
- var encodeHex = base58Hex.encode;
244
- var decodeHex = base58Hex.decode;
245
- var isBase58 = function (string) {
246
- try {
247
- decode$5(string);
248
- return true;
249
- }
250
- catch (e) {
251
- return false;
252
- }
253
- };
254
- var isBase58Hex = function (string) {
255
- try {
256
- decodeHex(string);
257
- return true;
258
- }
259
- catch (e) {
260
- return false;
261
- }
262
- };
263
- var whatType = function (string) {
264
- try {
265
- decode$5(string);
266
- return 'base58';
267
- }
268
- catch (e) {
269
- try {
270
- decodeHex(string);
271
- return 'base58Hex';
272
- }
273
- catch (_a) {
274
- return;
275
- }
276
- }
277
- };
278
- var base58$1 = { encode: encode$5, decode: decode$5, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex, decodeHex: decodeHex, whatType: whatType };
279
-
280
- const MSB$1 = 0x80;
281
- const REST$1 = 0x7F;
282
- const MSBALL = ~REST$1;
283
- const INT = Math.pow(2, 31);
284
- const encode$4 = (num, out, offset) => {
285
- if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
286
- encode$4.bytes = 0;
287
- throw new RangeError('Could not encode varint');
288
- }
289
- out = out || [];
290
- offset = offset || 0;
291
- const oldOffset = offset;
292
- while (num >= INT) {
293
- out[offset++] = (num & 0xFF) | MSB$1;
294
- num /= 128;
295
- }
296
- while (num & MSBALL) {
297
- out[offset++] = (num & 0xFF) | MSB$1;
298
- num >>>= 7;
299
- }
300
- out[offset] = num | 0;
301
- encode$4.bytes = offset - oldOffset + 1;
302
- return out;
303
- };
304
-
305
- const MSB = 0x80;
306
- const REST = 0x7F;
307
- const decode$4 = (buf, offset) => {
308
- offset = offset || 0;
309
- const l = buf.length;
310
- let counter = offset;
311
- let result = 0;
312
- let shift = 0;
313
- let b;
314
- do {
315
- if (counter >= l || shift > 49) {
316
- decode$4.bytes = 0;
317
- throw new RangeError('Could not decode varint');
318
- }
319
- b = buf[counter++];
320
- result += shift < 28
321
- ? (b & REST) << shift
322
- : (b & REST) * Math.pow(2, shift);
323
- shift += 7;
324
- } while (b >= MSB);
325
- decode$4.bytes = counter - offset;
326
- return result;
327
- };
328
-
329
- const N1 = Math.pow(2, 7);
330
- const N2 = Math.pow(2, 14);
331
- const N3 = Math.pow(2, 21);
332
- const N4 = Math.pow(2, 28);
333
- const N5 = Math.pow(2, 35);
334
- const N6 = Math.pow(2, 42);
335
- const N7 = Math.pow(2, 49);
336
- const N8 = Math.pow(2, 56);
337
- const N9 = Math.pow(2, 63);
338
- var encodingLength = (value) => (value < N1 ? 1
339
- : value < N2 ? 2
340
- : value < N3 ? 3
341
- : value < N4 ? 4
342
- : value < N5 ? 5
343
- : value < N6 ? 6
344
- : value < N7 ? 7
345
- : value < N8 ? 8
346
- : value < N9 ? 9
347
- : 10);
348
-
349
- var index$6 = {
350
- encode: encode$4,
351
- decode: decode$4,
352
- encodingLength
353
- };
354
-
355
- var index$5 = (input, prefix) => {
356
- const encodedArray = [];
357
- const length = input.reduce((total, current) => {
358
- const encoded = index$6.encode(current.length);
359
- encodedArray.push(encoded);
360
- total += current.length + encoded.length;
361
- return total;
362
- }, 0);
363
- const typedArray = new Uint8Array(prefix ? prefix.length + length : length);
364
- let currentIndex = 0;
365
- let index = 0;
366
- if (prefix) {
367
- typedArray.set(prefix);
368
- currentIndex += prefix.length;
369
- }
370
- for (const source of input) {
371
- typedArray.set(encodedArray[index], currentIndex);
372
- currentIndex += encodedArray[index].length;
373
- typedArray.set(source, currentIndex);
374
- currentIndex += source.length;
375
- index += 1;
376
- }
377
- return typedArray;
378
- };
379
-
380
- var index$4 = (typedArray, prefix) => {
381
- const set = [];
382
- if (prefix)
383
- typedArray = typedArray.subarray(prefix.length);
384
- const varintAndSub = (typedArray) => {
385
- const length = index$6.decode(typedArray);
386
- // remove length
387
- typedArray = typedArray.subarray(index$6.decode.bytes);
388
- // push value
389
- set.push(typedArray.subarray(0, length));
390
- // remove value
391
- typedArray = typedArray.subarray(length);
392
- if (typedArray.length !== 0)
393
- return varintAndSub(typedArray);
394
- return set;
395
- };
396
- return varintAndSub(typedArray);
397
- };
398
-
399
- const ALPHABET$1 = '0123456789ABCDEF';
400
- const base16 = base(ALPHABET$1);
401
- const decode$3 = base16.decode;
402
- const encode$3 = base16.encode;
403
- const isBase16 = (string) => {
404
- try {
405
- decode$3(string);
406
- return true;
407
- }
408
- catch (e) {
409
- return false;
410
- }
411
- };
412
- var index$3 = {
413
- encode: encode$3,
414
- decode: decode$3,
415
- isBase16
416
- };
417
-
418
- const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
419
- const base64 = base(ALPHABET);
420
- const decode$2 = base64.decode;
421
- const encode$2 = base64.encode;
422
- const isBase64 = (string) => {
423
- try {
424
- decode$2(string);
425
- return true;
426
- }
427
- catch (e) {
428
- return false;
429
- }
430
- };
431
- var index$2 = {
432
- encode: encode$2,
433
- decode: decode$2,
434
- isBase64
435
- };
436
-
437
- const isTypedArrayCompatible = (possibleUint8Array) => {
438
- if (typeof possibleUint8Array === 'string') {
439
- possibleUint8Array = possibleUint8Array.split(',').map(number => Number(number));
440
- for (const number of possibleUint8Array) {
441
- if (isNaN(number))
442
- return false;
443
- }
444
- }
445
- for (const number of possibleUint8Array) {
446
- if (isNaN(number))
447
- return false;
448
- }
449
- return true;
450
- };
451
- /**
452
- * Returns a String as Uint8Array
453
- * @param string string to encode to Uint8Array
454
- * @returns Uint8Array
455
- */
456
- const fromString$1 = (string) => new TextEncoder().encode(string);
457
- /**
458
- * Returns a Uint8Array as String
459
- * @param uint8Array Uint8Array to encode to String
460
- * @returns String
461
- */
462
- const toString$1 = (uint8Array) => new TextDecoder().decode(uint8Array);
463
- /**
464
- * Returns a String as Uint8Array
465
- * @param string string to encode to Uint8Array
466
- * @returns Uint8Array
467
- */
468
- const fromUintArrayString = (string) => Uint8Array.from(string.split(',').map(string => Number(string)));
469
- /**
470
- * Returns a Uint8Array as String
471
- * @param uint8Array Uint8Array to encode to String
472
- * @returns String
473
- */
474
- const toUintArrayString = (uint8Array) => uint8Array.toString();
475
- /**
476
- * hexString -> uint8Array
477
- * @param string hex encoded string
478
- * @returns UintArray
479
- */
480
- const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
481
- /**
482
- * uint8Array -> hexString
483
- * @param bytes number[]
484
- * @returns hexString
485
- */
486
- const toHex = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
487
- /**
488
- * number[] -> Uint8Array
489
- * @param array number[]
490
- * @returns Uint8Array
491
- */
492
- const fromArrayLike = (array) => Uint8Array.from(array);
493
- /**
494
- * Uint8Array -> number[]
495
- * @param uint8Array Uint8Array
496
- * @returns Uint8Array
497
- */
498
- const toArrayLike = (uint8Array) => [...uint8Array.values()];
499
- const toBase64 = (uint8Array) => index$2.encode(uint8Array);
500
- const fromBase64 = (string) => index$2.decode(string);
501
- const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
502
- const fromBase58 = (string) => base58$1.decode(string);
503
- const toBase32 = (uint8Array) => index$7.encode(uint8Array);
504
- const fromBase32 = (string) => index$7.decode(string);
505
- const toBase16 = (uint8Array) => index$3.encode(uint8Array);
506
- const fromBase16 = (string) => index$3.decode(string);
507
- let FormatInterface$2 = class FormatInterface {
508
- encoded;
509
- constructor(input) {
510
- if (input) {
511
- if (index$3.isBase16(input))
512
- this.encoded = this.fromBase16(input);
513
- else if (index$7.isBase32(input))
514
- this.encoded = this.fromBase32(input);
515
- else if (base58$1.isBase58(input))
516
- this.encoded = this.fromBase58(input);
517
- else if (index$2.isBase64(input))
518
- this.encoded = this.fromBase64(input);
519
- else if (typeof input === 'string') {
520
- let isCompatible = isTypedArrayCompatible(input);
521
- if (isCompatible)
522
- this.encoded = fromUintArrayString(input);
523
- else
524
- this.encoded = this.fromString(input); // normal string
525
- }
526
- else if (typeof input === 'object')
527
- this.encoded = this.fromObject(input);
528
- else if (input instanceof Uint8Array)
529
- this.encoded = input;
530
- else if (Array.isArray(input) && isTypedArrayCompatible(input))
531
- this.encoded = this.fromArrayLike(input);
532
- }
533
- }
534
- /**
535
- * Returns a String as Uint8Array
536
- * @param string string to encode to Uint8Array
537
- * @returns Uint8Array
538
- */
539
- fromString(string) {
540
- return new TextEncoder().encode(string);
541
- }
542
- /**
543
- * Returns a Uint8Array as String
544
- * @param uint8Array Uint8Array to encode to String
545
- * @returns String
546
- */
547
- toString(uint8Array) {
548
- return new TextDecoder().decode(uint8Array);
549
- }
550
- /**
551
- * Returns a String as Uint8Array
552
- * @param string string to encode to Uint8Array
553
- * @returns Uint8Array
554
- */
555
- fromUintArrayString(string) {
556
- return Uint8Array.from(string.split(',').map(string => Number(string)));
557
- }
558
- /**
559
- * Returns a Uint8Array as String
560
- * @param uint8Array Uint8Array to encode to String
561
- * @returns String
562
- */
563
- toUintArrayString(uint8Array) {
564
- return uint8Array.toString();
565
- }
566
- /**
567
- * hexString -> uint8Array
568
- * @param string hex encoded string
569
- * @returns UintArray
570
- */
571
- fromHex(string) {
572
- return Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
573
- }
574
- /**
575
- * uint8Array -> hexString
576
- * @param bytes number[]
577
- * @returns hexString
578
- */
579
- toHex(bytes) {
580
- return bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
581
- }
582
- /**
583
- * number[] -> Uint8Array
584
- * @param array number[]
585
- * @returns Uint8Array
586
- */
587
- fromArrayLike(array) {
588
- return Uint8Array.from(array);
589
- }
590
- /**
591
- * Uint8Array -> number[]
592
- * @param uint8Array Uint8Array
593
- * @returns Uint8Array
594
- */
595
- toArrayLike(uint8Array) {
596
- return [...uint8Array.values()];
597
- }
598
- fromObject(object) {
599
- return new TextEncoder().encode(JSON.stringify(object));
600
- }
601
- toObject(uint8Array) {
602
- return JSON.parse(new TextDecoder().decode(uint8Array));
603
- }
604
- toBase64(uint8Array) {
605
- return index$2.encode(uint8Array);
606
- }
607
- fromBase64(string) {
608
- return index$2.decode(string);
609
- }
610
- toBase58(uint8Array) {
611
- return base58$1.encode(uint8Array);
612
- }
613
- fromBase58(string) {
614
- return base58$1.decode(string);
615
- }
616
- toBase32(uint8Array) {
617
- return index$7.encode(uint8Array);
618
- }
619
- fromBase32(string) {
620
- return index$7.decode(string);
621
- }
622
- toBase16(uint8Array) {
623
- return index$3.encode(uint8Array);
624
- }
625
- fromBase16(string) {
626
- return index$3.decode(string);
627
- }
628
- };
629
- var index$1 = {
630
- fromString: fromString$1,
631
- toString: toString$1,
632
- fromHex,
633
- toHex,
634
- fromArrayLike,
635
- toArrayLike,
636
- fromUintArrayString,
637
- toUintArrayString,
638
- toBase64,
639
- fromBase64,
640
- toBase58,
641
- fromBase58,
642
- toBase32,
643
- fromBase32,
644
- toBase16,
645
- fromBase16,
646
- FormatInterface: FormatInterface$2
647
- };
648
-
649
- const { fromString, toString } = index$1;
650
- const isJson = (type) => type === 'object' || 'array';
651
- const isString = (type) => type === 'string';
652
- const isNumber = (type) => type === 'number';
653
- const isUint8Array = (type) => type === 'uint8Array';
654
- const tokenize = (key, value) => {
655
- const optional = key.endsWith('?');
656
- let type = value;
657
- type = Array.isArray(type) ? 'array' : typeof type;
658
- if (value instanceof Uint8Array)
659
- type = 'uint8Array';
660
- const parts = key.split('?');
661
- const minimumLength = parts[2]?.includes('min') ? parts[2].split['min:'][1] : 0;
662
- return { type, optional, key: parts[0], minimumLength };
663
- };
664
- const encode$1 = (proto, input) => {
665
- const keys = Object.keys(proto);
666
- const values = Object.values(proto);
667
- const set = [];
668
- for (let i = 0; i < keys.length; i++) {
669
- const token = tokenize(keys[i], values[i]);
670
- const data = input[token.key];
671
- if (!token.optional && data === undefined)
672
- throw new Error(`requires: ${token.key}`);
673
- if (token.type !== 'object' && token.minimumLength > data.length || token.type === 'object' && token.minimumLength > Object.keys(data).length)
674
- throw new Error(`minimumLength for ${token.key} is set to ${token.minimumLength} but got ${data.length}`);
675
- if (isUint8Array(token.type))
676
- set.push(data);
677
- else if (isString(token.type))
678
- set.push(fromString(data));
679
- else if (isNumber(token.type))
680
- set.push(new TextEncoder().encode(data.toString()));
681
- else if (isJson(token.type))
682
- set.push(new TextEncoder().encode(JSON.stringify(data)));
683
- }
684
- return index$5(set);
685
- };
686
- const decode$1 = (proto, uint8Array) => {
687
- let deconcated = index$4(uint8Array);
688
- const output = {};
689
- const keys = Object.keys(proto);
690
- const values = Object.values(proto);
691
- if (keys.length !== deconcated.length)
692
- console.warn(`length mismatch: expected ${keys.length} got ${uint8Array.length}`);
693
- for (let i = 0; i < keys.length; i++) {
694
- const token = tokenize(keys[i], values[i]);
695
- if (isUint8Array(token.type))
696
- output[token.key] = deconcated[i];
697
- else if (isString(token.type))
698
- output[token.key] = toString(deconcated[i]);
699
- else if (isNumber(token.type))
700
- output[token.key] = Number(new TextDecoder().decode(deconcated[i]));
701
- else if (isJson(token.type))
702
- output[token.key] = JSON.parse(new TextDecoder().decode(deconcated[i]));
703
- if (!token.optional && output[token.key] === undefined)
704
- throw new Error(`missing required property: ${token.key}`);
705
- }
706
- return output;
707
- };
708
- var index = {
709
- encode: encode$1,
710
- decode: decode$1
711
- };
712
-
713
- /*!
714
- * hash-wasm (https://www.npmjs.com/package/hash-wasm)
715
- * (c) Dani Biro
716
- * @license MIT
717
- */
718
-
719
- /*! *****************************************************************************
720
- Copyright (c) Microsoft Corporation.
721
-
722
- Permission to use, copy, modify, and/or distribute this software for any
723
- purpose with or without fee is hereby granted.
724
-
725
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
726
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
727
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
728
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
729
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
730
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
731
- PERFORMANCE OF THIS SOFTWARE.
732
- ***************************************************************************** */
733
-
734
- function __awaiter(thisArg, _arguments, P, generator) {
735
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
736
- return new (P || (P = Promise))(function (resolve, reject) {
737
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
738
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
739
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
740
- step((generator = generator.apply(thisArg, _arguments || [])).next());
741
- });
742
- }
743
-
744
- class Mutex {
745
- constructor() {
746
- this.mutex = Promise.resolve();
747
- }
748
- lock() {
749
- let begin = () => { };
750
- this.mutex = this.mutex.then(() => new Promise(begin));
751
- return new Promise((res) => {
752
- begin = res;
753
- });
754
- }
755
- dispatch(fn) {
756
- return __awaiter(this, void 0, void 0, function* () {
757
- const unlock = yield this.lock();
758
- try {
759
- return yield Promise.resolve(fn());
760
- }
761
- finally {
762
- unlock();
763
- }
764
- });
765
- }
766
- }
767
-
768
- /* eslint-disable import/prefer-default-export */
769
- /* eslint-disable no-bitwise */
770
- var _a;
771
- function getGlobal() {
772
- if (typeof globalThis !== 'undefined')
773
- return globalThis;
774
- // eslint-disable-next-line no-restricted-globals
775
- if (typeof self !== 'undefined')
776
- return self;
777
- if (typeof window !== 'undefined')
778
- return window;
779
- return global;
780
- }
781
- const globalObject = getGlobal();
782
- const nodeBuffer = (_a = globalObject.Buffer) !== null && _a !== void 0 ? _a : null;
783
- const textEncoder = globalObject.TextEncoder ? new globalObject.TextEncoder() : null;
784
- function hexCharCodesToInt(a, b) {
785
- return (((a & 0xF) + ((a >> 6) | ((a >> 3) & 0x8))) << 4) | ((b & 0xF) + ((b >> 6) | ((b >> 3) & 0x8)));
786
- }
787
- function writeHexToUInt8(buf, str) {
788
- const size = str.length >> 1;
789
- for (let i = 0; i < size; i++) {
790
- const index = i << 1;
791
- buf[i] = hexCharCodesToInt(str.charCodeAt(index), str.charCodeAt(index + 1));
792
- }
793
- }
794
- function hexStringEqualsUInt8(str, buf) {
795
- if (str.length !== buf.length * 2) {
796
- return false;
797
- }
798
- for (let i = 0; i < buf.length; i++) {
799
- const strIndex = i << 1;
800
- if (buf[i] !== hexCharCodesToInt(str.charCodeAt(strIndex), str.charCodeAt(strIndex + 1))) {
801
- return false;
802
- }
803
- }
804
- return true;
805
- }
806
- const alpha = 'a'.charCodeAt(0) - 10;
807
- const digit = '0'.charCodeAt(0);
808
- function getDigestHex(tmpBuffer, input, hashLength) {
809
- let p = 0;
810
- /* eslint-disable no-plusplus */
811
- for (let i = 0; i < hashLength; i++) {
812
- let nibble = input[i] >>> 4;
813
- tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
814
- nibble = input[i] & 0xF;
815
- tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
816
- }
817
- /* eslint-enable no-plusplus */
818
- return String.fromCharCode.apply(null, tmpBuffer);
819
- }
820
- const getUInt8Buffer = nodeBuffer !== null
821
- ? (data) => {
822
- if (typeof data === 'string') {
823
- const buf = nodeBuffer.from(data, 'utf8');
824
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
825
- }
826
- if (nodeBuffer.isBuffer(data)) {
827
- return new Uint8Array(data.buffer, data.byteOffset, data.length);
828
- }
829
- if (ArrayBuffer.isView(data)) {
830
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
831
- }
832
- throw new Error('Invalid data type!');
833
- }
834
- : (data) => {
835
- if (typeof data === 'string') {
836
- return textEncoder.encode(data);
837
- }
838
- if (ArrayBuffer.isView(data)) {
839
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
840
- }
841
- throw new Error('Invalid data type!');
842
- };
843
- const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
844
- const base64Lookup = new Uint8Array(256);
845
- for (let i = 0; i < base64Chars.length; i++) {
846
- base64Lookup[base64Chars.charCodeAt(i)] = i;
847
- }
848
- function getDecodeBase64Length(data) {
849
- let bufferLength = Math.floor(data.length * 0.75);
850
- const len = data.length;
851
- if (data[len - 1] === '=') {
852
- bufferLength -= 1;
853
- if (data[len - 2] === '=') {
854
- bufferLength -= 1;
855
- }
856
- }
857
- return bufferLength;
858
- }
859
- function decodeBase64(data) {
860
- const bufferLength = getDecodeBase64Length(data);
861
- const len = data.length;
862
- const bytes = new Uint8Array(bufferLength);
863
- let p = 0;
864
- for (let i = 0; i < len; i += 4) {
865
- const encoded1 = base64Lookup[data.charCodeAt(i)];
866
- const encoded2 = base64Lookup[data.charCodeAt(i + 1)];
867
- const encoded3 = base64Lookup[data.charCodeAt(i + 2)];
868
- const encoded4 = base64Lookup[data.charCodeAt(i + 3)];
869
- bytes[p] = (encoded1 << 2) | (encoded2 >> 4);
870
- p += 1;
871
- bytes[p] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
872
- p += 1;
873
- bytes[p] = ((encoded3 & 3) << 6) | (encoded4 & 63);
874
- p += 1;
875
- }
876
- return bytes;
877
- }
878
-
879
- const MAX_HEAP = 16 * 1024;
880
- const WASM_FUNC_HASH_LENGTH = 4;
881
- const wasmMutex = new Mutex();
882
- const wasmModuleCache = new Map();
883
- function WASMInterface(binary, hashLength) {
884
- return __awaiter(this, void 0, void 0, function* () {
885
- let wasmInstance = null;
886
- let memoryView = null;
887
- let initialized = false;
888
- if (typeof WebAssembly === 'undefined') {
889
- throw new Error('WebAssembly is not supported in this environment!');
890
- }
891
- const writeMemory = (data, offset = 0) => {
892
- memoryView.set(data, offset);
893
- };
894
- const getMemory = () => memoryView;
895
- const getExports = () => wasmInstance.exports;
896
- const setMemorySize = (totalSize) => {
897
- wasmInstance.exports.Hash_SetMemorySize(totalSize);
898
- const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
899
- const memoryBuffer = wasmInstance.exports.memory.buffer;
900
- memoryView = new Uint8Array(memoryBuffer, arrayOffset, totalSize);
901
- };
902
- const getStateSize = () => {
903
- const view = new DataView(wasmInstance.exports.memory.buffer);
904
- const stateSize = view.getUint32(wasmInstance.exports.STATE_SIZE, true);
905
- return stateSize;
906
- };
907
- const loadWASMPromise = wasmMutex.dispatch(() => __awaiter(this, void 0, void 0, function* () {
908
- if (!wasmModuleCache.has(binary.name)) {
909
- const asm = decodeBase64(binary.data);
910
- const promise = WebAssembly.compile(asm);
911
- wasmModuleCache.set(binary.name, promise);
912
- }
913
- const module = yield wasmModuleCache.get(binary.name);
914
- wasmInstance = yield WebAssembly.instantiate(module, {
915
- // env: {
916
- // emscripten_memcpy_big: (dest, src, num) => {
917
- // const memoryBuffer = wasmInstance.exports.memory.buffer;
918
- // const memView = new Uint8Array(memoryBuffer, 0);
919
- // memView.set(memView.subarray(src, src + num), dest);
920
- // },
921
- // print_memory: (offset, len) => {
922
- // const memoryBuffer = wasmInstance.exports.memory.buffer;
923
- // const memView = new Uint8Array(memoryBuffer, 0);
924
- // console.log('print_int32', memView.subarray(offset, offset + len));
925
- // },
926
- // },
927
- });
928
- // wasmInstance.exports._start();
929
- }));
930
- const setupInterface = () => __awaiter(this, void 0, void 0, function* () {
931
- if (!wasmInstance) {
932
- yield loadWASMPromise;
933
- }
934
- const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
935
- const memoryBuffer = wasmInstance.exports.memory.buffer;
936
- memoryView = new Uint8Array(memoryBuffer, arrayOffset, MAX_HEAP);
937
- });
938
- const init = (bits = null) => {
939
- initialized = true;
940
- wasmInstance.exports.Hash_Init(bits);
941
- };
942
- const updateUInt8Array = (data) => {
943
- let read = 0;
944
- while (read < data.length) {
945
- const chunk = data.subarray(read, read + MAX_HEAP);
946
- read += chunk.length;
947
- memoryView.set(chunk);
948
- wasmInstance.exports.Hash_Update(chunk.length);
949
- }
950
- };
951
- const update = (data) => {
952
- if (!initialized) {
953
- throw new Error('update() called before init()');
954
- }
955
- const Uint8Buffer = getUInt8Buffer(data);
956
- updateUInt8Array(Uint8Buffer);
957
- };
958
- const digestChars = new Uint8Array(hashLength * 2);
959
- const digest = (outputType, padding = null) => {
960
- if (!initialized) {
961
- throw new Error('digest() called before init()');
962
- }
963
- initialized = false;
964
- wasmInstance.exports.Hash_Final(padding);
965
- if (outputType === 'binary') {
966
- // the data is copied to allow GC of the original memory object
967
- return memoryView.slice(0, hashLength);
968
- }
969
- return getDigestHex(digestChars, memoryView, hashLength);
970
- };
971
- const save = () => {
972
- if (!initialized) {
973
- throw new Error('save() can only be called after init() and before digest()');
974
- }
975
- const stateOffset = wasmInstance.exports.Hash_GetState();
976
- const stateLength = getStateSize();
977
- const memoryBuffer = wasmInstance.exports.memory.buffer;
978
- const internalState = new Uint8Array(memoryBuffer, stateOffset, stateLength);
979
- // prefix is 4 bytes from SHA1 hash of the WASM binary
980
- // it is used to detect incompatible internal states between different versions of hash-wasm
981
- const prefixedState = new Uint8Array(WASM_FUNC_HASH_LENGTH + stateLength);
982
- writeHexToUInt8(prefixedState, binary.hash);
983
- prefixedState.set(internalState, WASM_FUNC_HASH_LENGTH);
984
- return prefixedState;
985
- };
986
- const load = (state) => {
987
- if (!(state instanceof Uint8Array)) {
988
- throw new Error('load() expects an Uint8Array generated by save()');
989
- }
990
- const stateOffset = wasmInstance.exports.Hash_GetState();
991
- const stateLength = getStateSize();
992
- const overallLength = WASM_FUNC_HASH_LENGTH + stateLength;
993
- const memoryBuffer = wasmInstance.exports.memory.buffer;
994
- if (state.length !== overallLength) {
995
- throw new Error(`Bad state length (expected ${overallLength} bytes, got ${state.length})`);
996
- }
997
- if (!hexStringEqualsUInt8(binary.hash, state.subarray(0, WASM_FUNC_HASH_LENGTH))) {
998
- throw new Error('This state was written by an incompatible hash implementation');
999
- }
1000
- const internalState = state.subarray(WASM_FUNC_HASH_LENGTH);
1001
- new Uint8Array(memoryBuffer, stateOffset, stateLength).set(internalState);
1002
- initialized = true;
1003
- };
1004
- const isDataShort = (data) => {
1005
- if (typeof data === 'string') {
1006
- // worst case is 4 bytes / char
1007
- return data.length < MAX_HEAP / 4;
1008
- }
1009
- return data.byteLength < MAX_HEAP;
1010
- };
1011
- let canSimplify = isDataShort;
1012
- switch (binary.name) {
1013
- case 'argon2':
1014
- case 'scrypt':
1015
- canSimplify = () => true;
1016
- break;
1017
- case 'blake2b':
1018
- case 'blake2s':
1019
- // if there is a key at blake2 then cannot simplify
1020
- canSimplify = (data, initParam) => initParam <= 512 && isDataShort(data);
1021
- break;
1022
- case 'blake3':
1023
- // if there is a key at blake3 then cannot simplify
1024
- canSimplify = (data, initParam) => initParam === 0 && isDataShort(data);
1025
- break;
1026
- case 'xxhash64': // cannot simplify
1027
- case 'xxhash3':
1028
- case 'xxhash128':
1029
- canSimplify = () => false;
1030
- break;
1031
- }
1032
- // shorthand for (init + update + digest) for better performance
1033
- const calculate = (data, initParam = null, digestParam = null) => {
1034
- if (!canSimplify(data, initParam)) {
1035
- init(initParam);
1036
- update(data);
1037
- return digest('hex', digestParam);
1038
- }
1039
- const buffer = getUInt8Buffer(data);
1040
- memoryView.set(buffer);
1041
- wasmInstance.exports.Hash_Calculate(buffer.length, initParam, digestParam);
1042
- return getDigestHex(digestChars, memoryView, hashLength);
1043
- };
1044
- yield setupInterface();
1045
- return {
1046
- getMemory,
1047
- writeMemory,
1048
- getExports,
1049
- setMemorySize,
1050
- init,
1051
- update,
1052
- digest,
1053
- save,
1054
- load,
1055
- calculate,
1056
- hashLength,
1057
- };
1058
- });
1059
- }
1060
-
1061
- new Mutex();
1062
-
1063
- new Mutex();
1064
-
1065
- new Mutex();
1066
-
1067
- new Mutex();
1068
-
1069
- new Mutex();
1070
-
1071
- new Mutex();
1072
-
1073
- new Mutex();
1074
-
1075
- new Mutex();
1076
-
1077
- new Mutex();
1078
-
1079
- var name$b = "sha3";
1080
- var data$b = "AGFzbQEAAAABDwNgAAF/YAF/AGADf39/AAMIBwABAQIBAAIEBQFwAQEBBQQBAQICBg4CfwFBkI0FC38AQcAJCwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACUhhc2hfSW5pdAABC0hhc2hfVXBkYXRlAAIKSGFzaF9GaW5hbAAEDUhhc2hfR2V0U3RhdGUABQ5IYXNoX0NhbGN1bGF0ZQAGClNUQVRFX1NJWkUDAQrLFwcFAEGACgvXAwBBAEIANwOAjQFBAEIANwP4jAFBAEIANwPwjAFBAEIANwPojAFBAEIANwPgjAFBAEIANwPYjAFBAEIANwPQjAFBAEIANwPIjAFBAEIANwPAjAFBAEIANwO4jAFBAEIANwOwjAFBAEIANwOojAFBAEIANwOgjAFBAEIANwOYjAFBAEIANwOQjAFBAEIANwOIjAFBAEIANwOAjAFBAEIANwP4iwFBAEIANwPwiwFBAEIANwPoiwFBAEIANwPgiwFBAEIANwPYiwFBAEIANwPQiwFBAEIANwPIiwFBAEIANwPAiwFBAEIANwO4iwFBAEIANwOwiwFBAEIANwOoiwFBAEIANwOgiwFBAEIANwOYiwFBAEIANwOQiwFBAEIANwOIiwFBAEIANwOAiwFBAEIANwP4igFBAEIANwPwigFBAEIANwPoigFBAEIANwPgigFBAEIANwPYigFBAEIANwPQigFBAEIANwPIigFBAEIANwPAigFBAEIANwO4igFBAEIANwOwigFBAEIANwOoigFBAEIANwOgigFBAEIANwOYigFBAEIANwOQigFBAEIANwOIigFBAEIANwOAigFBAEHADCAAQQF0a0EDdjYCjI0BQQBBADYCiI0BC/8BAQZ/AkBBACgCiI0BIgFBAEgNAEEAIAEgAGpBACgCjI0BIgJwNgKIjQECQAJAIAENAEGACiEBDAELAkAgACACIAFrIgMgAyAASyIEGyIFRQ0AIAFByIsBaiEGQQAhAQNAIAYgAWogAUGACmotAAA6AAAgBSABQQFqIgFHDQALCyAEDQFBgIoBQciLASACEAMgACADayEAIANBgApqIQELAkAgACACSQ0AA0BBgIoBIAEgAhADIAEgAmohASAAIAJrIgAgAk8NAAsLIABFDQBBACECQQAhBQNAIAJByIsBaiABIAJqLQAAOgAAIAAgBUEBaiIFQf8BcSICSw0ACwsLyAoBKH4gACAAKQMAIAEpAwCFIgM3AwAgACAAKQMIIAEpAwiFIgQ3AwggACAAKQMQIAEpAxCFIgU3AxAgACAAKQMYIAEpAxiFIgY3AxggACAAKQMgIAEpAyCFIgc3AyAgACAAKQMoIAEpAyiFIgg3AyggACAAKQMwIAEpAzCFIgk3AzAgACAAKQM4IAEpAziFIgo3AzggACAAKQN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QBCADcDyIsBQQBCADcDwIsBQQBCADcDuIsBQQBCADcDsIsBQQBCADcDqIsBQQBCADcDoIsBQQBCADcDmIsBQQBCADcDkIsBQQBCADcDiIsBQQBCADcDgIsBQQBCADcD+IoBQQBCADcD8IoBQQBCADcD6IoBQQBCADcD4IoBQQBCADcD2IoBQQBCADcD0IoBQQBCADcDyIoBQQBCADcDwIoBQQBCADcDuIoBQQBCADcDsIoBQQBCADcDqIoBQQBCADcDoIoBQQBCADcDmIoBQQBCADcDkIoBQQBCADcDiIoBQQBCADcDgIoBQQBBwAwgAUEBdGtBA3Y2AoyNAUEAQQA2AoiNASAAEAJB5ABBACgCjI0BIgFBAXZrIQMCQEEAKAKIjQEiAEEASA0AIAEhBAJAIAEgAEYNACAAQciLAWohBUEAIQADQCAFIABqQQA6AAAgAEEBaiIAIAFBACgCiI0BIgRrSQ0ACwsgBEHIiwFqIgAgAC0AACACcjoAACABQceLAWoiACAALQAAQYABcjoAAEGAigFByIsBIAEQA0EAQYCAgIB4NgKIjQELAkAgA0ECdiIBRQ0AQQAhAANAIABBgApqIABBgIoBaigCADYCACAAQQRqIQAgAUF/aiIBDQALCwsLzAEBAEGACAvEAQEAAAAAAAAAgoAAAAAAAACKgAAAAAAAgACAAIAAAACAi4AAAAAAAAABAACAAAAAAIGAAIAAAACACYAAAAAAAICKAAAAAAAAAIgAAAAAAAAACYAAgAAAAAAKAACAAAAAAIuAAIAAAAAAiwAAAAAAAICJgAAAAAAAgAOAAAAAAACAAoAAAAAAAICAAAAAAAAAgAqAAAAAAAAACgAAgAAAAICBgACAAAAAgICAAAAAAACAAQAAgAAAAAAIgACAAAAAgJABAAA=";
1081
- var hash$b = "ec266d91";
1082
- var wasmJson$b = {
1083
- name: name$b,
1084
- data: data$b,
1085
- hash: hash$b
1086
- };
1087
-
1088
- new Mutex();
1089
-
1090
- new Mutex();
1091
- function validateBits(bits) {
1092
- if (![224, 256, 384, 512].includes(bits)) {
1093
- return new Error('Invalid variant! Valid values: 224, 256, 384, 512');
1094
- }
1095
- return null;
1096
- }
1097
- /**
1098
- * Creates a new Keccak hash instance
1099
- * @param bits Number of output bits. Valid values: 224, 256, 384, 512
1100
- */
1101
- function createKeccak(bits = 512) {
1102
- if (validateBits(bits)) {
1103
- return Promise.reject(validateBits(bits));
1104
- }
1105
- const outputSize = bits / 8;
1106
- return WASMInterface(wasmJson$b, outputSize).then((wasm) => {
1107
- wasm.init(bits);
1108
- const obj = {
1109
- init: () => { wasm.init(bits); return obj; },
1110
- update: (data) => { wasm.update(data); return obj; },
1111
- digest: (outputType) => wasm.digest(outputType, 0x01),
1112
- save: () => wasm.save(),
1113
- load: (data) => { wasm.load(data); return obj; },
1114
- blockSize: 200 - 2 * outputSize,
1115
- digestSize: outputSize,
1116
- };
1117
- return obj;
1118
- });
1119
- }
1120
-
1121
- new Mutex();
1122
-
1123
- new Mutex();
1124
-
1125
- var name$9 = "sha512";
1126
- var data$9 = "AGFzbQEAAAABEQRgAAF/YAF/AGACf38AYAAAAwgHAAEBAgMAAgQFAXABAQEFBAEBAgIGDgJ/AUHQigULfwBBgAgLB3AIBm1lbW9yeQIADkhhc2hfR2V0QnVmZmVyAAAJSGFzaF9Jbml0AAELSGFzaF9VcGRhdGUAAgpIYXNoX0ZpbmFsAAQNSGFzaF9HZXRTdGF0ZQAFDkhhc2hfQ2FsY3VsYXRlAAYKU1RBVEVfU0laRQMBCvhnBwUAQYAJC5sCAEEAQgA3A4CKAUEAQTBBwAAgAEGAA0YiABs2AsiKAUEAQqSf6ffbg9LaxwBC+cL4m5Gjs/DbACAAGzcDwIoBQQBCp5/mp9bBi4ZbQuv6htq/tfbBHyAAGzcDuIoBQQBCkargwvbQktqOf0Kf2PnZwpHagpt/IAAbNwOwigFBAEKxloD+/8zJmecAQtGFmu/6z5SH0QAgABs3A6iKAUEAQrmyubiPm/uXFULx7fT4paf9p6V/IAAbNwOgigFBAEKXusODo6vArJF/Qqvw0/Sv7ry3PCAAGzcDmIoBQQBCh6rzs6Ol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AlqIAQ6AAAgAyACQQFqIgJB/wFxIgFNDQEgAUGIigFqLQAAIQQMAAsLCwYAQYCJAQuhAgBBAEIANwOAigFBAEEwQcAAIAFBgANGIgEbNgLIigFBAEKkn+n324PS2scAQvnC+JuRo7Pw2wAgARs3A8CKAUEAQqef5qfWwYuGW0Lr+obav7X2wR8gARs3A7iKAUEAQpGq4ML20JLajn9Cn9j52cKR2oKbfyABGzcDsIoBQQBCsZaA/v/MyZnnAELRhZrv+s+Uh9EAIAEbNwOoigFBAEK5srm4j5v7lxVC8e30+KWn/aelfyABGzcDoIoBQQBCl7rDg6OrwKyRf0Kr8NP0r+68tzwgARs3A5iKAUEAQoeq87OjpYrN4gBCu86qptjQ67O7fyABGzcDkIoBQQBC2L2WiNyr591LQoiS853/zPmE6gAgARs3A4iKASAAEAIQBAsLCwEAQYAICwTQAAAA";
1127
- var hash$9 = "a5d1ca7c";
1128
- var wasmJson$9 = {
1129
- name: name$9,
1130
- data: data$9,
1131
- hash: hash$9
1132
- };
1133
-
1134
- new Mutex();
1135
-
1136
- new Mutex();
1137
- /**
1138
- * Creates a new SHA-2 (SHA-512) hash instance
1139
- */
1140
- function createSHA512() {
1141
- return WASMInterface(wasmJson$9, 64).then((wasm) => {
1142
- wasm.init(512);
1143
- const obj = {
1144
- init: () => { wasm.init(512); return obj; },
1145
- update: (data) => { wasm.update(data); return obj; },
1146
- digest: (outputType) => wasm.digest(outputType),
1147
- save: () => wasm.save(),
1148
- load: (data) => { wasm.load(data); return obj; },
1149
- blockSize: 128,
1150
- digestSize: 64,
1151
- };
1152
- return obj;
1153
- });
1154
- }
1155
-
1156
- new Mutex();
1157
-
1158
- new Mutex();
1159
-
1160
- new Mutex();
1161
-
1162
- new Mutex();
1163
-
1164
- var name$4 = "ripemd160";
1165
- var data$4 = "AGFzbQEAAAABEQRgAAF/YAAAYAF/AGACf38AAwkIAAECAwIBAAIEBQFwAQEBBQQBAQICBg4CfwFB4IkFC38AQcAICweDAQkGbWVtb3J5Ag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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABcAAAA";
1166
- var hash$4 = "42f1de39";
1167
- var wasmJson$4 = {
1168
- name: name$4,
1169
- data: data$4,
1170
- hash: hash$4
1171
- };
1172
-
1173
- new Mutex();
1174
- /**
1175
- * Creates a new RIPEMD-160 hash instance
1176
- */
1177
- function createRIPEMD160() {
1178
- return WASMInterface(wasmJson$4, 20).then((wasm) => {
1179
- wasm.init();
1180
- const obj = {
1181
- init: () => { wasm.init(); return obj; },
1182
- update: (data) => { wasm.update(data); return obj; },
1183
- digest: (outputType) => wasm.digest(outputType),
1184
- save: () => wasm.save(),
1185
- load: (data) => { wasm.load(data); return obj; },
1186
- blockSize: 64,
1187
- digestSize: 20,
1188
- };
1189
- return obj;
1190
- });
1191
- }
1192
-
1193
- function calculateKeyBuffer(hasher, key) {
1194
- const { blockSize } = hasher;
1195
- const buf = getUInt8Buffer(key);
1196
- if (buf.length > blockSize) {
1197
- hasher.update(buf);
1198
- const uintArr = hasher.digest('binary');
1199
- hasher.init();
1200
- return uintArr;
1201
- }
1202
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
1203
- }
1204
- function calculateHmac(hasher, key) {
1205
- hasher.init();
1206
- const { blockSize } = hasher;
1207
- const keyBuf = calculateKeyBuffer(hasher, key);
1208
- const keyBuffer = new Uint8Array(blockSize);
1209
- keyBuffer.set(keyBuf);
1210
- const opad = new Uint8Array(blockSize);
1211
- for (let i = 0; i < blockSize; i++) {
1212
- const v = keyBuffer[i];
1213
- opad[i] = v ^ 0x5C;
1214
- keyBuffer[i] = v ^ 0x36;
1215
- }
1216
- hasher.update(keyBuffer);
1217
- const obj = {
1218
- init: () => {
1219
- hasher.init();
1220
- hasher.update(keyBuffer);
1221
- return obj;
1222
- },
1223
- update: (data) => {
1224
- hasher.update(data);
1225
- return obj;
1226
- },
1227
- digest: ((outputType) => {
1228
- const uintArr = hasher.digest('binary');
1229
- hasher.init();
1230
- hasher.update(opad);
1231
- hasher.update(uintArr);
1232
- return hasher.digest(outputType);
1233
- }),
1234
- save: () => {
1235
- throw new Error('save() not supported');
1236
- },
1237
- load: () => {
1238
- throw new Error('load() not supported');
1239
- },
1240
- blockSize: hasher.blockSize,
1241
- digestSize: hasher.digestSize,
1242
- };
1243
- return obj;
1244
- }
1245
- /**
1246
- * Calculates HMAC hash
1247
- * @param hash Hash algorithm to use. It has to be the return value of a function like createSHA1()
1248
- * @param key Key (string, Buffer or TypedArray)
1249
- */
1250
- function createHMAC(hash, key) {
1251
- if (!hash || !hash.then) {
1252
- throw new Error('Invalid hash function is provided! Usage: createHMAC(createMD5(), "key").');
1253
- }
1254
- return hash.then((hasher) => calculateHmac(hasher, key));
1255
- }
1256
-
1257
- new Mutex();
1258
-
1259
- new Mutex();
1260
-
1261
- const blockchainCodecs = [
1262
- {
1263
- name: 'leofcoin-block',
1264
- codec: '0x6c62',
1265
- hashAlg: 'dbl-keccak-512',
1266
- },
1267
- {
1268
- name: 'leofcoin-tx',
1269
- codec: '0x6c74',
1270
- hashAlg: 'dbl-keccak-512',
1271
- },
1272
- {
1273
- name: 'leofcoin-itx',
1274
- codec: '0x6c69',
1275
- hashAlg: 'keccak-512',
1276
- },
1277
- {
1278
- name: 'leofcoin-pr',
1279
- codec: '0x6c70',
1280
- hashAlg: 'keccak-256',
1281
- },
1282
- {
1283
- name: 'contract-message',
1284
- codec: '0x63636d',
1285
- hashAlg: 'keccak-256'
1286
- },
1287
- {
1288
- name: 'transaction-message',
1289
- codec: '0x746d',
1290
- hashAlg: 'keccak-256'
1291
- },
1292
- {
1293
- name: 'block-message',
1294
- codec: '0x626d',
1295
- hashAlg: 'keccak-256'
1296
- },
1297
- {
1298
- name: 'bw-message',
1299
- codec: '0x62776d',
1300
- hashAlg: 'keccak-256'
1301
- },
1302
- {
1303
- name: 'bw-request-message',
1304
- codec: '0x6277726d',
1305
- hashAlg: 'keccak-256'
1306
- },
1307
- {
1308
- name: 'validator-message',
1309
- codec: '0x766d',
1310
- hashAlg: 'keccak-256'
1311
- }
1312
- ];
1313
-
1314
- const internalCodecs = [
1315
- {
1316
- name: 'disco-hash',
1317
- codec: '0x30',
1318
- hashAlg: 'dbl-keccak-256',
1319
- },
1320
- {
1321
- name: 'peernet-peer-response',
1322
- codec: '0x707072',
1323
- hashAlg: 'keccak-256',
1324
- },
1325
- {
1326
- name: 'peernet-peer',
1327
- codec: '0x7070',
1328
- hashAlg: 'keccak-256',
1329
- },
1330
- {
1331
- name: 'peernet-dht',
1332
- codec: '0x706468',
1333
- hashAlg: 'keccak-256',
1334
- },
1335
- {
1336
- name: 'peernet-dht-response',
1337
- codec: '0x706472',
1338
- hashAlg: 'keccak-256',
1339
- },
1340
- {
1341
- name: 'peernet-data',
1342
- codec: '0x706461',
1343
- hashAlg: 'keccak-256',
1344
- },
1345
- {
1346
- name: 'peernet-data-response',
1347
- codec: '0x70646172',
1348
- hashAlg: 'keccak-256',
1349
- },
1350
- {
1351
- name: 'peernet-message',
1352
- codec: '0x706d65',
1353
- hashAlg: 'keccak-256',
1354
- },
1355
- {
1356
- name: 'peernet-ps',
1357
- codec: '707073',
1358
- hashAlg: 'keccak-256',
1359
- },
1360
- {
1361
- name: 'peernet-response',
1362
- codec: '0x7072',
1363
- hashAlg: 'keccak-256',
1364
- },
1365
- {
1366
- name: 'peernet-request',
1367
- codec: '0x707271',
1368
- hashAlg: 'keccak-256',
1369
- },
1370
- {
1371
- name: 'peernet-file',
1372
- codec: '0x7066',
1373
- hashAlg: 'keccak-256',
1374
- },
1375
- {
1376
- name: 'peernet-file-response',
1377
- codec: '0x706672',
1378
- hashAlg: 'keccak-256',
1379
- }
1380
- ];
1381
-
1382
- const codecs = [
1383
- ...internalCodecs,
1384
- ...blockchainCodecs,
1385
- {
1386
- name: 'chat-message',
1387
- codec: '0x70636d',
1388
- hashAlg: 'dbl-keccak-256',
1389
- }
1390
- ];
1391
-
1392
- globalThis.peernetCodecs = globalThis.peernetCodecs || {};
1393
- const addCodec = (codecInput) => {
1394
- let { hashAlg, codec, name } = codecInput;
1395
- if (!globalThis.peernetCodecs[name])
1396
- globalThis.peernetCodecs[name] = {
1397
- hashAlg,
1398
- codec: typeof codec === 'string' ? parseInt(codec, 16) : codec
1399
- };
1400
- };
1401
- const getCodec = (name) => {
1402
- if (typeof name === 'number')
1403
- return name;
1404
- return getCodecByName(name).codec;
1405
- };
1406
- const getCodecName = (codec) => {
1407
- return Object.keys(globalThis.peernetCodecs).reduce((p, c) => {
1408
- const item = globalThis.peernetCodecs[c];
1409
- if (item.codec === codec)
1410
- return c;
1411
- else
1412
- return p;
1413
- }, undefined);
1414
- };
1415
- const getCodecByName = (name) => globalThis.peernetCodecs[name];
1416
- const getHashAlg = (name) => {
1417
- if (typeof name === 'number')
1418
- return getCodecByName(getCodecName(name)).hashAlg;
1419
- return getCodecByName(name).hashAlg;
1420
- };
1421
- const isCodec = (codec) => {
1422
- if (codec.codec !== undefined && codec.hashAlg)
1423
- return true;
1424
- return false;
1425
- };
1426
- const validateCodec = (codec) => {
1427
- if (codec.codec === undefined ||
1428
- codec.hashAlg === undefined ||
1429
- codec.name === undefined)
1430
- throw new Error(`invalid codecInput: ${codec}`);
1431
- };
1432
- for (const codec of codecs) {
1433
- addCodec(codec);
1434
- }
1435
- var utils = {
1436
- isCodec,
1437
- addCodec,
1438
- getCodec,
1439
- getHashAlg,
1440
- getCodecName,
1441
- validateCodec,
1442
- codecs: globalThis.peernetCodecs
1443
- };
1444
-
1445
- /**
1446
- * @param {string}
1447
- */
1448
- var isHex = (function (string) { return /^[A-F0-9]+$/i.test(string); });
1449
-
1450
- let BasicInterface$1 = class BasicInterface {
1451
- encoded;
1452
- decoded;
1453
- keys;
1454
- name;
1455
- #proto;
1456
- set proto(value) {
1457
- this.#proto = value;
1458
- this.keys = Object.keys(value);
1459
- }
1460
- get proto() {
1461
- return this.#proto;
1462
- }
1463
- decode(encoded) {
1464
- encoded = encoded || this.encoded;
1465
- return new Object();
1466
- }
1467
- encode(decoded) {
1468
- decoded = decoded || this.decoded;
1469
- return new Uint8Array();
1470
- }
1471
- // get Codec(): Codec {}
1472
- protoEncode(data) {
1473
- // check schema
1474
- return index.encode(this.proto, data);
1475
- }
1476
- protoDecode(data) {
1477
- // check schema
1478
- return index.decode(this.proto, data);
1479
- }
1480
- isHex(string) {
1481
- return isHex(string);
1482
- }
1483
- isBase32(string) {
1484
- return index$7.isBase32(string);
1485
- }
1486
- isBase58(string) {
1487
- return base58$1.isBase58(string);
1488
- }
1489
- fromBs32(encoded) {
1490
- return this.decode(index$7.decode(encoded));
1491
- }
1492
- fromBs58(encoded) {
1493
- return this.decode(fromBase58(encoded));
1494
- }
1495
- async toArray() {
1496
- const array = [];
1497
- for await (const value of this.encoded.values()) {
1498
- array.push(value);
1499
- }
1500
- return array;
1501
- }
1502
- fromString(string) {
1503
- const array = string.split(',');
1504
- const arrayLike = array.map(string => Number(string));
1505
- return this.decode(Uint8Array.from(arrayLike));
1506
- }
1507
- fromHex(string) {
1508
- return this.decode(fromHex(string));
1509
- }
1510
- fromArray(array) {
1511
- return this.decode(Uint8Array.from([...array]));
1512
- }
1513
- fromEncoded(encoded) {
1514
- return this.decode(encoded);
1515
- }
1516
- toString() {
1517
- if (!this.encoded)
1518
- this.encode();
1519
- return this.encoded.toString();
1520
- }
1521
- toHex() {
1522
- if (!this.encoded)
1523
- this.encode();
1524
- return toHex(this.encoded.toString().split(',').map(number => Number(number)));
1525
- }
1526
- /**
1527
- * @return {String} encoded
1528
- */
1529
- toBs32() {
1530
- if (!this.encoded)
1531
- this.encode();
1532
- return toBase32(this.encoded);
1533
- }
1534
- /**
1535
- * @return {String} encoded
1536
- */
1537
- toBs58() {
1538
- if (!this.encoded)
1539
- this.encode();
1540
- return toBase58(this.encoded);
1541
- }
1542
- };
1543
-
1544
- let Codec$1 = class Codec extends BasicInterface$1 {
1545
- codecBuffer;
1546
- codec;
1547
- hashAlg;
1548
- constructor(buffer) {
1549
- super();
1550
- if (buffer) {
1551
- if (buffer instanceof Uint8Array) {
1552
- const codec = index$6.decode(buffer);
1553
- const name = this.getCodecName(codec);
1554
- if (name) {
1555
- this.name = name;
1556
- this.encoded = buffer;
1557
- this.decode(buffer);
1558
- }
1559
- else {
1560
- this.encode(Number(new TextDecoder().decode(buffer)));
1561
- }
1562
- }
1563
- else if (buffer instanceof ArrayBuffer) {
1564
- const codec = index$6.decode(buffer);
1565
- const name = this.getCodecName(codec);
1566
- if (name) {
1567
- this.name = name;
1568
- this.decode(buffer);
1569
- }
1570
- else {
1571
- this.encode(Number(new TextDecoder().decode(new Uint8Array(buffer))));
1572
- }
1573
- }
1574
- else if (typeof buffer === 'string') {
1575
- if (utils.getCodec(buffer))
1576
- this.fromName(buffer);
1577
- else if (this.isHex(buffer))
1578
- this.fromHex(buffer);
1579
- else if (this.isBase32(buffer))
1580
- this.fromBs32(buffer);
1581
- else if (this.isBase58(buffer))
1582
- this.fromBs58(buffer);
1583
- else
1584
- this.fromString(buffer);
1585
- }
1586
- if (!isNaN(buffer))
1587
- if (utils.getCodec(buffer))
1588
- this.fromCodec(buffer);
1589
- }
1590
- }
1591
- fromEncoded(encoded) {
1592
- const codec = index$6.decode(encoded);
1593
- const name = this.getCodecName(codec);
1594
- this.name = name;
1595
- this.encoded = encoded;
1596
- return this.decode(encoded);
1597
- }
1598
- getCodec(name) {
1599
- return utils.getCodec(name);
1600
- }
1601
- getCodecName(codec) {
1602
- return utils.getCodecName(codec);
1603
- }
1604
- getHashAlg(name) {
1605
- return utils.getHashAlg(name);
1606
- }
1607
- fromCodec(codec) {
1608
- this.name = this.getCodecName(codec);
1609
- this.hashAlg = this.getHashAlg(this.name);
1610
- this.codec = this.getCodec(this.name);
1611
- this.codecBuffer = index$6.encode(this.codec);
1612
- }
1613
- fromName(name) {
1614
- const codec = this.getCodec(name);
1615
- this.name = name;
1616
- this.codec = codec;
1617
- this.hashAlg = this.getHashAlg(name);
1618
- this.codecBuffer = index$6.encode(this.codec);
1619
- }
1620
- decode(encoded) {
1621
- encoded = encoded || this.encoded;
1622
- const codec = index$6.decode(encoded);
1623
- this.fromCodec(codec);
1624
- return this.decoded;
1625
- }
1626
- encode(codec) {
1627
- codec = codec || this.codec;
1628
- this.encoded = index$6.encode(codec);
1629
- return this.encoded;
1630
- }
1631
- };
1632
-
1633
- let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1634
- constructor(buffer, options = {}) {
1635
- super();
1636
- if (options.name)
1637
- this.name = options.name;
1638
- else
1639
- this.name = 'disco-hash';
1640
- if (options.codecs)
1641
- this.codecs = options.codecs;
1642
- return this.init(buffer);
1643
- }
1644
- async init(uint8Array) {
1645
- if (uint8Array) {
1646
- if (uint8Array instanceof Uint8Array) {
1647
- this.discoCodec = new Codec$1(uint8Array, this.codecs);
1648
- const name = this.discoCodec.name;
1649
- if (name) {
1650
- this.name = name;
1651
- this.decode(uint8Array);
1652
- }
1653
- else {
1654
- await this.encode(uint8Array);
1655
- }
1656
- }
1657
- if (typeof uint8Array === 'string') {
1658
- if (this.isHex(uint8Array))
1659
- await this.fromHex(uint8Array);
1660
- if (this.isBase32(uint8Array))
1661
- await this.fromBs32(uint8Array);
1662
- else if (this.isBase58(uint8Array))
1663
- await this.fromBs58(uint8Array);
1664
- else
1665
- throw new Error(`unsupported string ${uint8Array}`);
1666
- }
1667
- else if (typeof uint8Array === 'object')
1668
- await this.fromJSON(uint8Array);
1669
- }
1670
- return this;
1671
- }
1672
- get prefix() {
1673
- const length = this.length;
1674
- const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
1675
- uint8Array.set(length);
1676
- uint8Array.set(this.discoCodec.codecBuffer, length.length);
1677
- return uint8Array;
1678
- }
1679
- get length() {
1680
- return index$6.encode(this.size);
1681
- }
1682
- get buffer() {
1683
- return this.encoded;
1684
- }
1685
- get hash() {
1686
- return this.encoded;
1687
- }
1688
- fromJSON(json) {
1689
- return this.encode(Buffer.from(JSON.stringify(json)));
1690
- }
1691
- async encode(buffer, name) {
1692
- if (!this.name && name)
1693
- this.name = name;
1694
- if (!buffer)
1695
- buffer = this.buffer;
1696
- this.discoCodec = new Codec$1(this.name, this.codecs);
1697
- this.discoCodec.fromName(this.name);
1698
- let hashAlg = this.discoCodec.hashAlg;
1699
- const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
1700
- if (hashAlg.includes('dbl')) {
1701
- hashAlg = hashAlg.replace('dbl-', '');
1702
- const hasher = await createKeccak(hashVariant);
1703
- await hasher.init();
1704
- hasher.update(buffer);
1705
- buffer = hasher.digest('binary');
1706
- }
1707
- const hasher = await createKeccak(hashVariant);
1708
- await hasher.init();
1709
- hasher.update(buffer);
1710
- this.digest = hasher.digest('binary');
1711
- this.size = this.digest.length;
1712
- this.codec = this.discoCodec.encode();
1713
- this.codec = this.discoCodec.codecBuffer;
1714
- const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
1715
- uint8Array.set(this.prefix);
1716
- uint8Array.set(this.digest, this.prefix.length);
1717
- this.encoded = uint8Array;
1718
- return this.encoded;
1719
- }
1720
- async validate(buffer) {
1721
- if (Buffer.isBuffer(buffer)) {
1722
- const codec = index$6.decode(buffer);
1723
- if (this.codecs[codec]) {
1724
- this.decode(buffer);
1725
- }
1726
- else {
1727
- await this.encode(buffer);
1728
- }
1729
- }
1730
- if (typeof buffer === 'string') {
1731
- if (this.isHex(buffer))
1732
- this.fromHex(buffer);
1733
- if (this.isBase32(buffer))
1734
- this.fromBs32(buffer);
1735
- }
1736
- if (typeof buffer === 'object')
1737
- this.fromJSON(buffer);
1738
- }
1739
- decode(buffer) {
1740
- this.encoded = buffer;
1741
- const codec = index$6.decode(buffer);
1742
- this.discoCodec = new Codec$1(codec, this.codecs);
1743
- // TODO: validate codec
1744
- buffer = buffer.slice(index$6.decode.bytes);
1745
- this.size = index$6.decode(buffer);
1746
- this.digest = buffer.slice(index$6.decode.bytes);
1747
- if (this.digest.length !== this.size) {
1748
- throw new Error(`hash length inconsistent: 0x${this.encoded.toString('hex')}`);
1749
- }
1750
- // const discoCodec = new Codec(codec, this.codecs)
1751
- this.name = this.discoCodec.name;
1752
- this.size = this.digest.length;
1753
- return {
1754
- codec: this.codec,
1755
- name: this.name,
1756
- size: this.size,
1757
- length: this.length,
1758
- digest: this.digest,
1759
- };
1760
- }
1761
- };
1762
-
1763
- let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
1764
- hashFormat;
1765
- init(buffer) {
1766
- if (buffer instanceof Uint8Array)
1767
- this.fromUint8Array(buffer);
1768
- else if (buffer instanceof ArrayBuffer)
1769
- this.fromArrayBuffer(buffer);
1770
- else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
1771
- return buffer;
1772
- else if (typeof buffer === 'string') {
1773
- if (this.isHex(buffer))
1774
- this.fromHex(buffer);
1775
- else if (this.isBase58(buffer))
1776
- this.fromBs58(buffer);
1777
- else if (this.isBase32(buffer))
1778
- this.fromBs32(buffer);
1779
- else
1780
- this.fromString(buffer);
1781
- }
1782
- else {
1783
- this.create(buffer);
1784
- }
1785
- return this;
1786
- }
1787
- hasCodec() {
1788
- if (!this.encoded)
1789
- return false;
1790
- const codec = new Codec$1(this.encoded);
1791
- if (codec.name)
1792
- return true;
1793
- }
1794
- decode(encoded) {
1795
- encoded = encoded || this.encoded;
1796
- const codec = new Codec$1(this.encoded);
1797
- if (codec.codecBuffer) {
1798
- encoded = encoded.slice(codec.codecBuffer.length);
1799
- this.name = codec.name;
1800
- this.decoded = this.protoDecode(encoded);
1801
- // try {
1802
- // this.decoded = JSON.parse(this.decoded)
1803
- // } catch {
1804
- // }
1805
- }
1806
- else {
1807
- throw new Error(`no codec found`);
1808
- }
1809
- return this.decoded;
1810
- }
1811
- encode(decoded) {
1812
- let encoded;
1813
- if (!decoded)
1814
- decoded = this.decoded;
1815
- const codec = new Codec$1(this.name);
1816
- if (decoded instanceof Uint8Array)
1817
- encoded = decoded;
1818
- else
1819
- encoded = this.protoEncode(decoded);
1820
- if (codec.codecBuffer) {
1821
- const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
1822
- uint8Array.set(codec.codecBuffer);
1823
- uint8Array.set(encoded, codec.codecBuffer.length);
1824
- this.encoded = uint8Array;
1825
- }
1826
- else {
1827
- throw new Error(`invalid codec`);
1828
- }
1829
- return this.encoded;
1830
- }
1831
- /**
1832
- * @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
1833
- * @param {Object} proto - {protoObject}
1834
- * @param {Object} options - {hashFormat, name}
1835
- */
1836
- constructor(buffer, proto, options) {
1837
- super();
1838
- this.proto = proto;
1839
- this.hashFormat = options?.hashFormat ? options.hashFormat : 'bs32';
1840
- if (options?.name)
1841
- this.name = options.name;
1842
- this.init(buffer);
1843
- }
1844
- /**
1845
- * @return {PeernetHash}
1846
- */
1847
- get peernetHash() {
1848
- return new CodecHash$1(this.decoded, { name: this.name });
1849
- }
1850
- /**
1851
- * @return {peernetHash}
1852
- */
1853
- async hash() {
1854
- const upper = this.hashFormat.charAt(0).toUpperCase();
1855
- const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
1856
- return (await this.peernetHash)[`to${format}`]();
1857
- }
1858
- fromUint8Array(buffer) {
1859
- this.encoded = buffer;
1860
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1861
- }
1862
- fromArrayBuffer(buffer) {
1863
- this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
1864
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1865
- }
1866
- /**
1867
- * @param {Object} data
1868
- */
1869
- create(data) {
1870
- const decoded = {};
1871
- if (this.keys?.length > 0) {
1872
- for (const key of this.keys) {
1873
- Object.defineProperties(decoded, {
1874
- [key]: {
1875
- enumerable: true,
1876
- configurable: true,
1877
- set: (value) => data[key],
1878
- get: () => data[key]
1879
- }
1880
- });
1881
- }
1882
- this.decoded = decoded;
1883
- return this.encode(decoded);
1884
- }
1885
- }
1886
- };
1887
- const FormatInterface = FormatInterface$1;
1888
- const Codec = Codec$1;
1889
-
1890
- const BufferToUint8Array = data => {
1891
- if (data.type === 'Buffer') {
1892
- data = new Uint8Array(data.data);
1893
- }
1894
- return data;
1895
- };
1896
- const protoFor = (message) => {
1897
- const codec = new Codec(message);
1898
- if (!codec.name)
1899
- throw new Error('proto not found');
1900
- const Proto = globalThis.peernet.protos[codec.name];
1901
- if (!Proto)
1902
- throw (new Error(`No proto defined for ${codec.name}`));
1903
- return new Proto(message);
1904
- };
1905
- /**
1906
- * wether or not a peernet daemon is active
1907
- * @return {Boolean}
1908
- */
1909
- const hasDaemon = async () => {
1910
- try {
1911
- let response = await fetch('http://127.0.0.1:1000/api/version');
1912
- response = await response.json();
1913
- return Boolean(response.client === '@peernet/api/http');
1914
- }
1915
- catch (e) {
1916
- return false;
1917
- }
1918
- };
1919
- const https = () => {
1920
- if (!globalThis.location)
1921
- return false;
1922
- return Boolean(globalThis.location.protocol === 'https:');
1923
- };
1924
- /**
1925
- * Get current environment
1926
- * @return {String} current environment [node, electron, browser]
1927
- */
1928
- const environment = () => {
1929
- const _navigator = globalThis.navigator;
1930
- if (!_navigator) {
1931
- return 'node';
1932
- }
1933
- else if (_navigator && /electron/i.test(_navigator.userAgent)) {
1934
- return 'electron';
1935
- }
1936
- else {
1937
- return 'browser';
1938
- }
1939
- };
1940
- /**
1941
- * * Get current environment
1942
- * @return {Object} result
1943
- * @property {Boolean} reult.daemon whether or not daemon is running
1944
- * @property {Boolean} reult.environment Current environment
1945
- */
1946
- const target = async () => {
1947
- let daemon = false;
1948
- if (!https())
1949
- daemon = await hasDaemon();
1950
- return { daemon, environment: environment() };
1951
- };
1952
-
1953
- class PeerDiscovery {
1954
- constructor(id) {
1955
- this.id = id;
1956
- }
1957
- _getPeerId(id) {
1958
- if (!peernet.peerMap || peernet.peerMap && peernet.peerMap.size === 0)
1959
- return false;
1960
- for (const entry of [...peernet.peerMap.entries()]) {
1961
- for (const _id of entry[1]) {
1962
- if (_id === id)
1963
- return entry[0];
1964
- }
1965
- }
1966
- }
1967
- async discover(peer) {
1968
- let id = this._getPeerId(peer.id);
1969
- if (id)
1970
- return id;
1971
- const data = await new peernet.protos['peernet-peer']({ id: this.id });
1972
- const node = await peernet.prepareMessage(peer.id, data.encoded);
1973
- let response = await peer.request(node.encoded);
1974
- response = await protoFor(response);
1975
- response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
1976
- id = response.decoded.id;
1977
- if (id === this.id)
1978
- return;
1979
- if (!peernet.peerMap.has(id))
1980
- peernet.peerMap.set(id, [peer.id]);
1981
- else {
1982
- const connections = peernet.peerMap.get(id);
1983
- if (connections.indexOf(peer.id) === -1) {
1984
- connections.push(peer.id);
1985
- peernet.peerMap.set(peer.id, connections);
1986
- }
1987
- }
1988
- return id;
1989
- }
1990
- async discoverHandler(message, peer) {
1991
- const { id, proto } = message;
1992
- // if (typeof message.data === 'string') message.data = Buffer.from(message.data)
1993
- if (proto.name === 'peernet-peer') {
1994
- const from = proto.decoded.id;
1995
- if (from === this.id)
1996
- return;
1997
- if (!peernet.peerMap.has(from))
1998
- peernet.peerMap.set(from, [peer.id]);
1999
- else {
2000
- const connections = peernet.peerMap.get(from);
2001
- if (connections.indexOf(peer.id) === -1) {
2002
- connections.push(peer.id);
2003
- peernet.peerMap.set(from, connections);
2004
- }
2005
- }
2006
- const data = await new peernet.protos['peernet-peer-response']({ id: this.id });
2007
- const node = await peernet.prepareMessage(from, data.encoded);
2008
- peer.write(Buffer.from(JSON.stringify({ id, data: node.encoded })));
2009
- }
2010
- else if (proto.name === 'peernet-peer-response') {
2011
- const from = proto.decoded.id;
2012
- if (from === this.id)
2013
- return;
2014
- if (!peernet.peerMap.has(from))
2015
- peernet.peerMap.set(from, [peer.id]);
2016
- else {
2017
- const connections = peernet.peerMap.get(from);
2018
- if (connections.indexOf(peer.id) === -1) {
2019
- connections.push(peer.id);
2020
- peernet.peerMap.set(from, connections);
2021
- }
2022
- }
2023
- }
2024
- }
2025
- }
2026
-
2027
- /**
2028
- * Keep history of fetched address and ptr
2029
- * @property {Object} address
2030
- * @property {Object} ptr
2031
- */
2032
- const lastFetched = {
2033
- address: {
2034
- value: undefined,
2035
- timestamp: 0,
2036
- },
2037
- ptr: {
2038
- value: undefined,
2039
- timestamp: 0,
2040
- },
2041
- };
2042
- const getAddress = async () => {
2043
- const { address } = lastFetched;
2044
- const now = Math.round(new Date().getTime() / 1000);
2045
- if (now - address.timestamp > 1200000) {
2046
- address.value = await fetch('https://icanhazip.com/');
2047
- address.value = await address.value.text();
2048
- address.timestamp = Math.round(new Date().getTime() / 1000);
2049
- lastFetched.address = address;
2050
- }
2051
- return address.value;
2052
- };
2053
- const degreesToRadians = (degrees) => {
2054
- return degrees * Math.PI / 180;
2055
- };
2056
- const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
2057
- const earthRadiusKm = 6371;
2058
- const dLat = degreesToRadians(lat2 - lat1);
2059
- const dLon = degreesToRadians(lon2 - lon1);
2060
- lat1 = degreesToRadians(lat1);
2061
- lat2 = degreesToRadians(lat2);
2062
- const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
2063
- Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
2064
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
2065
- return earthRadiusKm * c;
2066
- };
2067
- class DhtEarth {
2068
- /**
2069
- *
2070
- */
2071
- constructor() {
2072
- this.providerMap = new Map();
2073
- }
2074
- /**
2075
- * @param {Object} address
2076
- * @return {Object} {latitude: lat, longitude: lon}
2077
- */
2078
- async getCoordinates(address) {
2079
- // const {address} = parseAddress(provider)
2080
- const request = `https://whereis.leofcoin.org/?ip=${address}`;
2081
- let response = await fetch(request);
2082
- response = await response.json();
2083
- const { lat, lon } = response;
2084
- return { latitude: lat, longitude: lon };
2085
- }
2086
- /**
2087
- * @param {Object} peer
2088
- * @param {Object} provider
2089
- * @return {Object} {provider, distance}
2090
- */
2091
- async getDistance(peer, provider) {
2092
- const { latitude, longitude } = await this.getCoordinates(provider.address);
2093
- return { provider, distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude) };
2094
- }
2095
- /**
2096
- * @param {Array} providers
2097
- * @return {Object} closestPeer
2098
- */
2099
- async closestPeer(providers) {
2100
- let all = [];
2101
- const address = await getAddress();
2102
- const peerLoc = await this.getCoordinates(address);
2103
- for (const provider of providers) {
2104
- if (provider.address === '127.0.0.1')
2105
- all.push({ provider, distance: 0 });
2106
- else
2107
- all.push(this.getDistance(peerLoc, provider));
2108
- }
2109
- all = await Promise.all(all);
2110
- all = all.sort((previous, current) => previous.distance - current.distance);
2111
- return all[0].provider;
2112
- }
2113
- /**
2114
- * @param {String} hash
2115
- * @return {Array} providers
2116
- */
2117
- providersFor(hash) {
2118
- return this.providerMap.get(hash);
2119
- }
2120
- /**
2121
- * @param {String} address
2122
- * @param {String} hash
2123
- * @return {Array} providers
2124
- */
2125
- async addProvider(address, hash) {
2126
- let providers = [];
2127
- if (this.providerMap.has(hash))
2128
- providers = this.providerMap.get(hash);
2129
- providers = new Set([...providers, address]);
2130
- this.providerMap.set(hash, providers);
2131
- return providers;
2132
- }
2133
- }
2134
-
2135
- class MessageHandler {
2136
- constructor(network) {
2137
- this.network = network;
2138
- }
2139
- /**
2140
- * hash and sign message
2141
- *
2142
- * @param {object} message
2143
- * @param {Buffer} message.from peer id
2144
- * @param {Buffer} message.to peer id
2145
- * @param {string} message.data Peernet message
2146
- * (PeernetMessage excluded) encoded as a string
2147
- * @return message
2148
- */
2149
- async hashAndSignMessage(message) {
2150
- let identity = await walletStore.get('identity');
2151
- identity = JSON.parse(identity);
2152
- if (!globalThis.MultiWallet) {
2153
- const importee = await import(/* webpackChunkName: "multi-wallet" */ './index-769b10c7.js');
2154
- globalThis.MultiWallet = importee.default;
2155
- }
2156
- const wallet = new MultiWallet(this.network);
2157
- wallet.recover(identity.mnemonic);
2158
- message.decoded.signature = wallet.sign(Buffer.from(await message.hash).slice(0, 32));
2159
- return message;
2160
- }
2161
- /**
2162
- * @param {String} from - peer id
2163
- * @param {String} to - peer id
2164
- * @param {String|PeernetMessage} data - data encoded message string
2165
- * or the messageNode itself
2166
- */
2167
- async prepareMessage(message) {
2168
- if (message.keys.includes('signature')) {
2169
- message = await this.hashAndSignMessage(message);
2170
- }
2171
- return message;
2172
- }
2173
- }
2174
-
2175
- const dataHandler = async (message) => {
2176
- if (!message)
2177
- return;
2178
- const { data, id, from } = message;
2179
- const proto = await protoFor(data);
2180
- peernet._protoHandler({ id, proto }, peernet.client.connections[from], from);
2181
- };
2182
-
2183
- const dhtError = (proto) => {
2184
- const text = `Received proto ${proto.name} expected peernet-dht-response`;
2185
- return new Error(`Routing error: ${text}`);
2186
- };
2187
- const nothingFoundError = (hash) => {
2188
- return new Error(`nothing found for ${hash}`);
2189
- };
2190
-
2191
- // import base32 from '@vandeurenglenn/base32'
2192
- // import base58 from '@vandeurenglenn/base58'
2193
-
2194
- // export const encodings = {
2195
- // base58,
2196
- // base32
2197
- // }
2198
-
2199
- const encode = (string, encoding = 'utf-8') => {
2200
- if (typeof string === 'string') {
2201
- let encoded;
2202
-
2203
- // if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
2204
- encoded = new TextEncoder().encode(string);
2205
- return encoded
2206
- }
2207
- throw Error(`expected typeof String instead got ${string}`)
2208
- };
2209
-
2210
- const decode = (uint8Array, encoding) => {
2211
- if (uint8Array instanceof Uint8Array) {
2212
- let decoded;
2213
- // if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
2214
- decoded = new TextDecoder().decode(uint8Array);
2215
-
2216
- return decoded
2217
- }
2218
- throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
2219
- };
2220
-
2221
- const pathSepS = '/';
2222
- class KeyPath {
2223
-
2224
- /**
2225
- * @param {string | Uint8Array} input
2226
- */
2227
- constructor(input) {
2228
- if (typeof input === 'string') {
2229
- this.uint8Array = encode(input);
2230
- } else if (input instanceof Uint8Array) {
2231
- this.uint8Array = input;
2232
- } else if (input instanceof KeyPath) {
2233
- this.uint8Array = input.uint8Array;
2234
- } else {
2235
- throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
2236
- }
2237
- }
2238
-
2239
- isKeyPath() {
2240
- return true
2241
- }
2242
-
2243
- /**
2244
- * Convert to the string representation
2245
- *
2246
- * @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
2247
- * @returns {string}
2248
- */
2249
- toString(encoding = 'hex') {
2250
- return decode(this.uint8Array)
2251
- }
2252
-
2253
- /**
2254
- * Returns the `list` representation of this path.
2255
- *
2256
- * @returns string[]
2257
- *
2258
- * @example
2259
- * ```js
2260
- * new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
2261
- * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
2262
- * ```
2263
- */
2264
- list() {
2265
- return this.toString().split(pathSepS).slice(1)
2266
- }
2267
-
2268
- }
2269
-
2270
- class LeofcoinStorage {
2271
-
2272
- constructor(name = 'storage', root = '.leofcoin') {
2273
- this.name = name;
2274
- this.root = root;
2275
- }
2276
-
2277
- async init(name, root) {
2278
- const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
2279
- const Store = importee.default;
2280
- this.db = new Store(this.name, this.root);
2281
- }
2282
-
2283
- async get(key) {
2284
- if (typeof key === 'object') return this.many('get', key);
2285
- return this.db.get(new KeyPath(key))
2286
- }
2287
-
2288
- /**
2289
- *
2290
- * @param {*} key
2291
- * @param {*} value
2292
- * @returns Promise
2293
- */
2294
- put(key, value) {
2295
- if (typeof key === 'object') return this.many('put', key);
2296
- return this.db.put(new KeyPath(key), new KeyValue(value));
2297
- }
2298
-
2299
- async has(key) {
2300
- if (typeof key === 'object') return this.many('has', key);
2301
-
2302
- try {
2303
- const has = await this.db.get(new KeyPath(key));
2304
-
2305
- return Boolean(has);
2306
- } catch (e) {
2307
- return false
2308
- }
2309
- }
2310
-
2311
- async delete(key) {
2312
- return this.db.delete(new KeyPath(key))
2313
- }
2314
-
2315
- keys(limit = -1) {
2316
- return this.db.keys(limit)
2317
- }
2318
-
2319
- async values(limit = -1) {
2320
- return this.db.values(limit)
2321
- }
2322
-
2323
- async many(type, _value) {
2324
- const jobs = [];
2325
-
2326
- for (const key of Object.keys(_value)) {
2327
- jobs.push(this[type](key, _value[key]));
2328
- }
2329
-
2330
- return Promise.all(jobs)
2331
- }
2332
-
2333
- async length() {
2334
- const keys = await this.keys();
2335
- return keys.length
2336
- }
2337
-
2338
- async size() {
2339
- let size = 0;
2340
- const query = await this.db.iterate();
2341
- for await (const item of query) {
2342
- size += item.value ? item.value.length : item[1].length;
2343
- }
2344
- return size
2345
- }
2346
-
2347
- async clear() {
2348
- return this.db.clear()
2349
- }
2350
-
2351
- async iterate() {
2352
- return this.db.iterate()
2353
- }
2354
-
2355
- }
2356
-
2357
- globalThis.LeofcoinStorage = LeofcoinStorage;
2358
- globalThis.leofcoin = globalThis.leofcoin || {};
2359
- globalThis.pubsub = globalThis.pubsub || new LittlePubSub();
2360
- globalThis.globalSub = globalThis.globalSub || new LittlePubSub(true);
2361
- /**
2362
- * @access public
2363
- * @example
2364
- * const peernet = new Peernet();
2365
- */
2366
- class Peernet {
2367
- stores = [];
2368
- /**
2369
- * @type {Object}
2370
- * @property {Object} peer Instance of Peer
2371
- */
2372
- dht = new DhtEarth();
2373
- /** @leofcoin/peernet-swarm/client */
2374
- client;
2375
- network;
2376
- stars;
2377
- networkVersion;
2378
- bw;
2379
- /**
2380
- * @access public
2381
- * @param {Object} options
2382
- * @param {String} options.network - desired network
2383
- * @param {String} options.stars - star list for selected network (these should match, don't mix networks)
2384
- * @param {String} options.root - path to root directory
2385
- * @param {String} options.storePrefix - prefix for datatores (lfc)
2386
- *
2387
- * @return {Promise} instance of Peernet
2388
- *
2389
- * @example
2390
- * const peernet = new Peernet({network: 'leofcoin', root: '.leofcoin'});
2391
- */
2392
- constructor(options) {
2393
- /**
2394
- * @property {String} network - current network
2395
- */
2396
- this.network = options.network || 'leofcoin';
2397
- this.stars = options.stars;
2398
- const parts = this.network.split(':');
2399
- this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet';
2400
- if (!options.storePrefix)
2401
- options.storePrefix = 'lfc';
2402
- if (!options.port)
2403
- options.port = 2000;
2404
- if (!options.root) {
2405
- parts[1] ? options.root = `.${parts[0]}/${parts[1]}` : options.root = `.${this.network}`;
2406
- }
2407
- globalThis.peernet = this;
2408
- this.bw = {
2409
- up: 0,
2410
- down: 0,
2411
- };
2412
- return this._init(options);
2413
- }
2414
- get defaultStores() {
2415
- return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message'];
2416
- }
2417
- addProto(name, proto) {
2418
- if (!globalThis.peernet.protos[name])
2419
- globalThis.peernet.protos[name] = proto;
2420
- }
2421
- addCodec(codec) {
2422
- return utils.addCodec(codec);
2423
- }
2424
- async addStore(name, prefix, root, isPrivate = true) {
2425
- if (name === 'block' || name === 'transaction' || name === 'chain' ||
2426
- name === 'data' || name === 'message')
2427
- isPrivate = false;
2428
- let Storage;
2429
- this.hasDaemon ? Storage = LeofcoinStorageClient : Storage = LeofcoinStorage;
2430
- if (!globalThis[`${name}Store`]) {
2431
- globalThis[`${name}Store`] = new Storage(name, root);
2432
- await globalThis[`${name}Store`].init();
2433
- }
2434
- globalThis[`${name}Store`].private = isPrivate;
2435
- if (!isPrivate)
2436
- this.stores.push(name);
2437
- }
2438
- /**
2439
- * @see MessageHandler
2440
- */
2441
- prepareMessage(data) {
2442
- return this._messageHandler.prepareMessage(data);
2443
- }
2444
- /**
2445
- * @access public
2446
- *
2447
- * @return {Array} peerId
2448
- */
2449
- get peers() {
2450
- return Object.keys(this.client.connections);
2451
- }
2452
- get connections() {
2453
- return Object.values(this.client.connections);
2454
- }
2455
- get peerEntries() {
2456
- return Object.entries(this.client.connections);
2457
- }
2458
- /**
2459
- * @return {String} id - peerId
2460
- */
2461
- getConnection(id) {
2462
- return this.client.connections[id];
2463
- }
2464
- /**
2465
- * @private
2466
- *
2467
- * @param {Object} options
2468
- * @param {String} options.root - path to root directory
2469
- *
2470
- * @return {Promise} instance of Peernet
2471
- */
2472
- async _init(options) {
2473
- this.requestProtos = {};
2474
- this.storePrefix = options.storePrefix;
2475
- this.root = options.root;
2476
- const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
2477
- // FolderMessageResponse
2478
- } = await import(/* webpackChunkName: "messages" */ './messages-1f20bad9.js');
2479
- /**
2480
- * proto Object containing protos
2481
- * @type {Object}
2482
- * @property {PeernetMessage} protos[peernet-message] messageNode
2483
- * @property {DHTMessage} protos[peernet-dht] messageNode
2484
- * @property {DHTMessageResponse} protos[peernet-dht-response] messageNode
2485
- * @property {DataMessage} protos[peernet-data] messageNode
2486
- * @property {DataMessageResponse} protos[peernet-data-response] messageNode
2487
- */
2488
- globalThis.peernet.protos = {
2489
- 'peernet-request': RequestMessage,
2490
- 'peernet-response': ResponseMessage,
2491
- 'peernet-peer': PeerMessage,
2492
- 'peernet-peer-response': PeerMessageResponse,
2493
- 'peernet-message': PeernetMessage,
2494
- 'peernet-dht': DHTMessage,
2495
- 'peernet-dht-response': DHTMessageResponse,
2496
- 'peernet-data': DataMessage,
2497
- 'peernet-data-response': DataMessageResponse,
2498
- 'peernet-ps': PsMessage,
2499
- 'chat-message': ChatMessage,
2500
- 'peernet-file': PeernetFile
2501
- };
2502
- this._messageHandler = new MessageHandler(this.network);
2503
- const { daemon, environment } = await target();
2504
- this.hasDaemon = daemon;
2505
- for (const store of this.defaultStores) {
2506
- await this.addStore(store, options.storePrefix, options.root);
2507
- }
2508
- const accountExists = await accountStore.has('public');
2509
- if (accountExists) {
2510
- const pub = await accountStore.get('public');
2511
- this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
2512
- let accounts = await walletStore.get('accounts');
2513
- accounts = new TextDecoder().decode(accounts);
2514
- const selected = await walletStore.get('selected-account');
2515
- globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
2516
- // fixing account issue (string while needs to be a JSON)
2517
- // TODO: remove when on mainnet
2518
- try {
2519
- this.accounts = JSON.parse(accounts);
2520
- }
2521
- catch {
2522
- this.accounts = [accounts.split(',')];
2523
- }
2524
- }
2525
- else {
2526
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-72471f52.js');
2527
- const generateAccount = importee.default;
2528
- const { identity, accounts, config } = await generateAccount(this.network);
2529
- // await accountStore.put('config', JSON.stringify(config));
2530
- await accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
2531
- await walletStore.put('version', String(1));
2532
- await walletStore.put('accounts', JSON.stringify(accounts));
2533
- await walletStore.put('selected-account', accounts[0][1]);
2534
- await walletStore.put('identity', JSON.stringify(identity));
2535
- globalThis.peernet.selectedAccount = accounts[0][1];
2536
- this.id = identity.walletId;
2537
- }
2538
- this._peerHandler = new PeerDiscovery(this.id);
2539
- this.peerId = this.id;
2540
- pubsub.subscribe('peer:connected', async (peer) => {
2541
- // console.log(peer);
2542
- // console.log({connected: peer.id, as: this._getPeerId(peer.id) });
2543
- // peer.on('peernet.data', async (message) => {
2544
- // const id = message.id
2545
- // message = new PeernetMessage(Buffer.from(message.data.data))
2546
- // const proto = protoFor(message.decoded.data)
2547
- // this._protoHandler({id, proto}, peer)
2548
- // })
2549
- });
2550
- /**
2551
- * converts data -> message -> proto
2552
- * @see DataHandler
2553
- */
2554
- pubsub.subscribe('peer:data', dataHandler);
2555
- const importee = await import('./client-ae251a9c.js');
2556
- /**
2557
- * @access public
2558
- * @type {PeernetClient}
2559
- */
2560
- this.client = new importee.default(this.id, this.networkVersion, this.stars);
2561
- if (globalThis.navigator) {
2562
- globalThis.addEventListener('beforeunload', async () => this.client.close());
2563
- }
2564
- else {
2565
- process.on('SIGTERM', async () => {
2566
- process.stdin.resume();
2567
- await this.client.close();
2568
- process.exit();
2569
- });
2570
- }
2571
- return this;
2572
- }
2573
- addRequestHandler(name, method) {
2574
- this.requestProtos[name] = method;
2575
- }
2576
- sendMessage(peer, id, data) {
2577
- if (peer.readyState === 'open') {
2578
- peer.send(data, id);
2579
- this.bw.up += data.length;
2580
- }
2581
- else if (peer.readyState === 'closed') ;
2582
- }
2583
- async handleDHT(peer, id, proto) {
2584
- let { hash, store } = proto.decoded;
2585
- let has;
2586
- if (store) {
2587
- store = globalThis[`${store}Store`];
2588
- has = store.private ? false : await store.has(hash);
2589
- }
2590
- else {
2591
- has = await this.has(hash);
2592
- }
2593
- const data = await new globalThis.peernet.protos['peernet-dht-response']({ hash, has });
2594
- const node = await this.prepareMessage(data);
2595
- this.sendMessage(peer, id, node.encoded);
2596
- }
2597
- async handleData(peer, id, proto) {
2598
- let { hash, store } = proto.decoded;
2599
- let data;
2600
- store = globalThis[`${store}Store`] || await this.whichStore([...this.stores], hash);
2601
- if (store && !store.private) {
2602
- data = await store.get(hash);
2603
- if (data) {
2604
- data = await new globalThis.peernet.protos['peernet-data-response']({ hash, data });
2605
- const node = await this.prepareMessage(data);
2606
- this.sendMessage(peer, id, node.encoded);
2607
- }
2608
- }
2609
- }
2610
- async handleRequest(peer, id, proto) {
2611
- const method = this.requestProtos[proto.decoded.request];
2612
- if (method) {
2613
- const data = await method();
2614
- const node = await this.prepareMessage(data);
2615
- this.sendMessage(peer, id, node.encoded);
2616
- }
2617
- }
2618
- /**
2619
- * @private
2620
- *
2621
- * @param {Buffer} message - peernet message
2622
- * @param {PeernetPeer} peer - peernet peer
2623
- */
2624
- async _protoHandler(message, peer, from) {
2625
- const { id, proto } = message;
2626
- this.bw.down += proto.encoded.length;
2627
- switch (proto.name) {
2628
- case 'peernet-dht': {
2629
- this.handleDHT(peer, id, proto);
2630
- break;
2631
- }
2632
- case 'peernet-data': {
2633
- this.handleData(peer, id, proto);
2634
- break;
2635
- }
2636
- case 'peernet-request': {
2637
- this.handleRequest(peer, id, proto);
2638
- }
2639
- case 'peernet-ps': {
2640
- if (peer.peerId !== this.id)
2641
- globalSub.publish(proto.decoded.topic, proto.decoded.data);
2642
- }
2643
- }
2644
- }
2645
- /**
2646
- * performs a walk and resolves first encounter
2647
- *
2648
- * @param {String} hash
2649
- */
2650
- async walk(hash) {
2651
- if (!hash)
2652
- throw new Error('hash expected, received undefined');
2653
- const data = await new globalThis.peernet.protos['peernet-dht']({ hash });
2654
- this.client.id;
2655
- const walk = async (peer) => {
2656
- const node = await this.prepareMessage(data);
2657
- let result = await peer.request(node.encoded);
2658
- result = new Uint8Array(Object.values(result));
2659
- const proto = await protoFor(result);
2660
- if (proto.name !== 'peernet-dht-response')
2661
- throw dhtError(proto.name);
2662
- // TODO: give ip and port (just used for location)
2663
- if (!peer.connection.remoteAddress || !peer.connection.localAddress) {
2664
- peer.connection.remoteFamily = 'ipv4';
2665
- peer.connection.remoteAddress = '127.0.0.1';
2666
- peer.connection.remotePort = '0000';
2667
- }
2668
- const peerInfo = {
2669
- family: peer.connection.remoteFamily || peer.connection.localFamily,
2670
- address: peer.connection.remoteAddress || peer.connection.localAddress,
2671
- port: peer.connection.remotePort || peer.connection.localPort,
2672
- id: peer.peerId,
2673
- };
2674
- if (proto.decoded.has)
2675
- this.dht.addProvider(peerInfo, proto.decoded.hash);
2676
- };
2677
- let walks = [];
2678
- for (const peer of this.connections) {
2679
- if (peer.peerId !== this.id) {
2680
- walks.push(walk(peer));
2681
- }
2682
- }
2683
- return Promise.all(walks);
2684
- }
2685
- /**
2686
- * Override DHT behavior, try's finding the content three times
2687
- *
2688
- * @param {String} hash
2689
- */
2690
- async providersFor(hash) {
2691
- let providers = await this.dht.providersFor(hash);
2692
- // walk the network to find a provider
2693
- if (!providers || providers.length === 0) {
2694
- await this.walk(hash);
2695
- providers = await this.dht.providersFor(hash);
2696
- // second walk the network to find a provider
2697
- if (!providers || providers.length === 0) {
2698
- await this.walk(hash);
2699
- providers = await this.dht.providersFor(hash);
2700
- }
2701
- // last walk
2702
- if (!providers || providers.length === 0) {
2703
- await this.walk(hash);
2704
- providers = await this.dht.providersFor(hash);
2705
- }
2706
- }
2707
- // undefined if no providers given
2708
- return providers;
2709
- }
2710
- get block() {
2711
- return {
2712
- get: async (hash) => {
2713
- const data = await blockStore.has(hash);
2714
- if (data)
2715
- return blockStore.get(hash);
2716
- return this.requestData(hash, 'block');
2717
- },
2718
- put: async (hash, data) => {
2719
- if (await blockStore.has(hash))
2720
- return;
2721
- return await blockStore.put(hash, data);
2722
- },
2723
- has: async (hash) => await blockStore.has(hash, 'block'),
2724
- };
2725
- }
2726
- get transaction() {
2727
- return {
2728
- get: async (hash) => {
2729
- const data = await transactionStore.has(hash);
2730
- if (data)
2731
- return await transactionStore.get(hash);
2732
- return this.requestData(hash, 'transaction');
2733
- },
2734
- put: async (hash, data) => {
2735
- if (await transactionStore.has(hash))
2736
- return;
2737
- return await transactionStore.put(hash, data);
2738
- },
2739
- has: async (hash) => await transactionStore.has(hash),
2740
- };
2741
- }
2742
- async requestData(hash, store) {
2743
- const providers = await this.providersFor(hash);
2744
- if (!providers || providers.size === 0)
2745
- throw nothingFoundError(hash);
2746
- debug(`found ${providers.size} provider(s) for ${hash}`);
2747
- // get closest peer on earth
2748
- const closestPeer = await this.dht.closestPeer(providers);
2749
- // get peer instance by id
2750
- if (!closestPeer || !closestPeer.id)
2751
- return this.requestData(hash, store?.name || store);
2752
- const id = closestPeer.id;
2753
- if (this.connections) {
2754
- let closest = this.connections.filter((peer) => {
2755
- if (peer.peerId === id)
2756
- return peer;
2757
- });
2758
- let data = await new globalThis.peernet.protos['peernet-data']({ hash, store: store?.name || store });
2759
- const node = await this.prepareMessage(data);
2760
- if (closest[0])
2761
- data = await closest[0].request(node.encoded);
2762
- else {
2763
- closest = this.connections.filter((peer) => {
2764
- if (peer.peerId === id)
2765
- return peer;
2766
- });
2767
- if (closest[0])
2768
- data = await closest[0].request(node.encoded);
2769
- }
2770
- const proto = await protoFor(data);
2771
- // TODO: store data automaticly or not
2772
- return BufferToUint8Array(proto.decoded.data);
2773
- // this.put(hash, proto.decoded.data)
2774
- }
2775
- return;
2776
- }
2777
- get message() {
2778
- return {
2779
- /**
2780
- * Get content for given message hash
2781
- *
2782
- * @param {String} hash
2783
- */
2784
- get: async (hash) => {
2785
- debug(`get message ${hash}`);
2786
- const message = await messageStore.has(hash);
2787
- if (message)
2788
- return await messageStore.get(hash);
2789
- return this.requestData(hash, 'message');
2790
- },
2791
- /**
2792
- * put message content
2793
- *
2794
- * @param {String} hash
2795
- * @param {Buffer} message
2796
- */
2797
- put: async (hash, message) => await messageStore.put(hash, message),
2798
- /**
2799
- * @param {String} hash
2800
- * @return {Boolean}
2801
- */
2802
- has: async (hash) => await messageStore.has(hash),
2803
- };
2804
- }
2805
- get data() {
2806
- return {
2807
- /**
2808
- * Get content for given data hash
2809
- *
2810
- * @param {String} hash
2811
- */
2812
- get: async (hash) => {
2813
- debug(`get data ${hash}`);
2814
- const data = await dataStore.has(hash);
2815
- if (data)
2816
- return await dataStore.get(hash);
2817
- return this.requestData(hash, 'data');
2818
- },
2819
- /**
2820
- * put data content
2821
- *
2822
- * @param {String} hash
2823
- * @param {Buffer} data
2824
- */
2825
- put: async (hash, data) => await dataStore.put(hash, data),
2826
- /**
2827
- * @param {String} hash
2828
- * @return {Boolean}
2829
- */
2830
- has: async (hash) => await dataStore.has(hash),
2831
- };
2832
- }
2833
- get folder() {
2834
- return {
2835
- /**
2836
- * Get content for given data hash
2837
- *
2838
- * @param {String} hash
2839
- */
2840
- get: async (hash) => {
2841
- debug(`get data ${hash}`);
2842
- const data = await dataStore.has(hash);
2843
- if (data)
2844
- return await dataStore.get(hash);
2845
- return this.requestData(hash, 'data');
2846
- },
2847
- /**
2848
- * put data content
2849
- *
2850
- * @param {String} hash
2851
- * @param {Buffer} data
2852
- */
2853
- put: async (hash, data) => await dataStore.put(hash, data),
2854
- /**
2855
- * @param {String} hash
2856
- * @return {Boolean}
2857
- */
2858
- has: async (hash) => await dataStore.has(hash),
2859
- };
2860
- }
2861
- async addFolder(files) {
2862
- const links = [];
2863
- for (const file of files) {
2864
- const fileNode = await new globalThis.peernet.protos['peernet-file'](file);
2865
- const hash = await fileNode.hash;
2866
- await dataStore.put(hash, fileNode.encoded);
2867
- links.push({ hash, path: file.path });
2868
- }
2869
- const node = await new globalThis.peernet.protos['peernet-file']({ path: '/', links });
2870
- const hash = await node.hash;
2871
- await dataStore.put(hash, node.encoded);
2872
- return hash;
2873
- }
2874
- async ls(hash, options) {
2875
- let data;
2876
- const has = await dataStore.has(hash);
2877
- data = has ? await dataStore.get(hash) : await this.requestData(hash, 'data');
2878
- const node = await new peernet.protos['peernet-file'](data);
2879
- await node.decode();
2880
- console.log(data);
2881
- const paths = [];
2882
- if (node.decoded?.links.length === 0)
2883
- throw new Error(`${hash} is a file`);
2884
- for (const { path, hash } of node.decoded.links) {
2885
- paths.push({ path, hash });
2886
- }
2887
- if (options?.pin)
2888
- await dataStore.put(hash, node.encoded);
2889
- return paths;
2890
- }
2891
- async cat(hash, options) {
2892
- let data;
2893
- const has = await dataStore.has(hash);
2894
- data = has ? await dataStore.get(hash) : await this.requestData(hash, 'data');
2895
- const node = await new peernet.protos['peernet-file'](data);
2896
- if (node.decoded?.links.length > 0)
2897
- throw new Error(`${hash} is a directory`);
2898
- if (options?.pin)
2899
- await dataStore.put(hash, node.encoded);
2900
- return node.decoded.content;
2901
- }
2902
- /**
2903
- * goes trough given stores and tries to find data for given hash
2904
- * @param {Array} stores
2905
- * @param {string} hash
2906
- */
2907
- async whichStore(stores, hash) {
2908
- let store = stores.pop();
2909
- store = globalThis[`${store}Store`];
2910
- if (store) {
2911
- const has = await store.has(hash);
2912
- if (has)
2913
- return store;
2914
- if (stores.length > 0)
2915
- return this.whichStore(stores, hash);
2916
- }
2917
- else
2918
- return;
2919
- }
2920
- /**
2921
- * Get content for given hash
2922
- *
2923
- * @param {String} hash - the hash of the wanted data
2924
- * @param {String} store - storeName to access
2925
- */
2926
- async get(hash, store) {
2927
- debug(`get ${hash}`);
2928
- let data;
2929
- if (store)
2930
- store = globalThis[`${store}Store`];
2931
- if (!store)
2932
- store = await this.whichStore([...this.stores], hash);
2933
- if (store && await store.has(hash))
2934
- data = await store.get(hash);
2935
- if (data)
2936
- return data;
2937
- return this.requestData(hash, store?.name || store);
2938
- }
2939
- /**
2940
- * put content
2941
- *
2942
- * @param {String} hash
2943
- * @param {Buffer} data
2944
- * @param {String} store - storeName to access
2945
- */
2946
- async put(hash, data, store = 'data') {
2947
- store = globalThis[`${store}Store`];
2948
- return store.put(hash, data);
2949
- }
2950
- /**
2951
- * @param {String} hash
2952
- * @return {Boolean}
2953
- */
2954
- async has(hash) {
2955
- const store = await this.whichStore([...this.stores], hash);
2956
- if (store) {
2957
- return store.private ? false : true;
2958
- }
2959
- return false;
2960
- }
2961
- /**
2962
- *
2963
- * @param {String} topic
2964
- * @param {String|Object|Array|Boolean|Buffer} data
2965
- */
2966
- async publish(topic, data) {
2967
- // globalSub.publish(topic, data)
2968
- const id = Math.random().toString(36).slice(-12);
2969
- data = await new globalThis.peernet.protos['peernet-ps']({ data, topic });
2970
- for (const peer of this.connections) {
2971
- if (peer.peerId !== this.peerId) {
2972
- const node = await this.prepareMessage(data);
2973
- this.sendMessage(peer, id, node.encoded);
2974
- }
2975
- // TODO: if peer subscribed
2976
- }
2977
- }
2978
- createHash(data, name) {
2979
- return new CodeHash(data, { name });
2980
- }
2981
- /**
2982
- *
2983
- * @param {String} topic
2984
- * @param {Method} cb
2985
- */
2986
- async subscribe(topic, callback) {
2987
- // TODO: if peer subscribed
2988
- globalSub.subscribe(topic, callback);
2989
- }
2990
- async removePeer(peer) {
2991
- return this.client.removePeer(peer);
2992
- }
2993
- get Buffer() {
2994
- return Buffer;
2995
- }
2996
- }
2997
- globalThis.Peernet = Peernet;
2998
-
2999
- export { FormatInterface as F, LittlePubSub as L, Peernet as P, index$4 as a, base58$1 as b, index$6 as c, index$7 as d, createRIPEMD160 as e, createHMAC as f, createSHA512 as g, createKeccak as h, index$5 as i };