@leofcoin/chain 1.4.82 → 1.4.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/browser/chain.js +72 -52
- package/exports/browser/client-c8558012-c8558012.js +10727 -0
- package/exports/browser/{index-6311966e-b5f647d8.js → index-ed6cbdf7-eb75dc7a.js} +2 -2
- package/exports/browser/{index-c3f4012c.js → index-f4429da1.js} +200 -210
- package/exports/browser/{messages-54aa3cad-5309745b.js → messages-35d069e1-9413ac70.js} +2 -2
- package/exports/browser/{node-browser-3cbee72b.js → node-browser-504c804a.js} +509 -600
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +200 -210
- package/exports/browser/workers/machine-worker.js +219 -212
- package/exports/chain.js +49 -35
- package/exports/types/config/main.d.ts +5 -0
- package/exports/{typings → types}/config/protocol.d.ts +1 -1
- package/exports/{typings → types}/contract.d.ts +1 -1
- package/exports/{typings → types}/fee/config.d.ts +1 -1
- package/exports/{typings → types}/machine.d.ts +8 -7
- package/exports/{typings → types}/node-browser.d.ts +1 -1
- package/exports/{typings → types}/node.d.ts +3 -3
- package/exports/workers/block-worker.js +6035 -0
- package/exports/workers/machine-worker.js +6298 -0
- package/package.json +18 -10
- package/exports/browser/client-6072af1a-6072af1a.js +0 -41092
- package/exports/typings/config/main.d.ts +0 -5
- /package/exports/{typings → types}/config/config.d.ts +0 -0
- /package/exports/{typings → types}/jobs/jobber.d.ts +0 -0
- /package/exports/{typings → types}/machine-state.d.ts +0 -0
- /package/exports/{typings → types}/protocol.d.ts +0 -0
- /package/exports/{typings → types}/sync-controller.d.ts +0 -0
- /package/exports/{typings → types}/transaction.d.ts +0 -0
- /package/exports/{typings → types}/typer.d.ts +0 -0
- /package/exports/{typings → types}/types.d.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-
|
|
1
|
+
import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-f4429da1.js';
|
|
2
2
|
|
|
3
3
|
var nodeConfig = async (config = {
|
|
4
4
|
network: 'leofcoin:peach',
|
|
@@ -20,67 +20,76 @@ var nodeConfig = async (config = {
|
|
|
20
20
|
await globalThis.peernet.addStore('transactionPool', 'lfc', name, false);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// base58,
|
|
28
|
-
// base32
|
|
29
|
-
// }
|
|
30
|
-
|
|
31
|
-
const encode$9 = (string, encoding = 'utf-8') => {
|
|
32
|
-
if (typeof string === 'string') {
|
|
33
|
-
let encoded;
|
|
34
|
-
|
|
35
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
36
|
-
encoded = new TextEncoder().encode(string);
|
|
37
|
-
return encoded
|
|
38
|
-
}
|
|
39
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
23
|
+
const encode$8 = (string) => {
|
|
24
|
+
if (typeof string === 'string')
|
|
25
|
+
return new TextEncoder().encode(string);
|
|
26
|
+
throw Error(`expected typeof String instead got ${string}`);
|
|
40
27
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
46
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
47
|
-
|
|
48
|
-
return decoded
|
|
49
|
-
}
|
|
50
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
28
|
+
const decode$9 = (uint8Array) => {
|
|
29
|
+
if (uint8Array instanceof Uint8Array)
|
|
30
|
+
return new TextDecoder().decode(uint8Array);
|
|
31
|
+
throw Error(`expected typeof uint8Array instead got ${uint8Array}`);
|
|
51
32
|
};
|
|
52
33
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
const pathSepS = '/';
|
|
35
|
+
class KeyPath {
|
|
36
|
+
uint8Array;
|
|
37
|
+
constructor(input) {
|
|
38
|
+
if (typeof input === 'string') {
|
|
39
|
+
this.uint8Array = encode$8(input);
|
|
40
|
+
}
|
|
41
|
+
else if (input instanceof Uint8Array) {
|
|
42
|
+
this.uint8Array = input;
|
|
43
|
+
}
|
|
44
|
+
else if (input instanceof KeyPath) {
|
|
45
|
+
this.uint8Array = input.uint8Array;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath');
|
|
49
|
+
}
|
|
67
50
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
51
|
+
isKeyPath() {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
toString() {
|
|
55
|
+
return decode$9(this.uint8Array);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns the `list` representation of this path.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
63
|
+
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
list() {
|
|
67
|
+
return this.toString().split(pathSepS).slice(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
83
70
|
|
|
71
|
+
class KeyValue {
|
|
72
|
+
uint8Array;
|
|
73
|
+
constructor(input) {
|
|
74
|
+
if (typeof input === 'string') {
|
|
75
|
+
this.uint8Array = encode$8(input);
|
|
76
|
+
}
|
|
77
|
+
else if (input instanceof Uint8Array) {
|
|
78
|
+
this.uint8Array = input;
|
|
79
|
+
}
|
|
80
|
+
else if (input instanceof KeyValue) {
|
|
81
|
+
this.uint8Array = input.uint8Array;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
isKeyValue() {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
toString() {
|
|
91
|
+
return decode$9(this.uint8Array);
|
|
92
|
+
}
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
if (!globalThis.DEBUG) {
|
|
@@ -289,16 +298,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
|
289
298
|
const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
|
|
290
299
|
const base32 = base$1(ALPHABET$3);
|
|
291
300
|
const base32Hex = base$1(ALPHABET_HEX$1);
|
|
292
|
-
const decode$
|
|
301
|
+
const decode$8 = base32.decode;
|
|
293
302
|
const decodeHex$2 = base32Hex.decode;
|
|
294
|
-
const encode$
|
|
303
|
+
const encode$7 = base32.encode;
|
|
295
304
|
const encodeHex$2 = base32Hex.encode;
|
|
296
305
|
const isBase32 = (string, hex = false) => {
|
|
297
306
|
try {
|
|
298
307
|
if (hex)
|
|
299
308
|
decodeHex$2(string);
|
|
300
309
|
else
|
|
301
|
-
decode$
|
|
310
|
+
decode$8(string);
|
|
302
311
|
return true;
|
|
303
312
|
}
|
|
304
313
|
catch (e) {
|
|
@@ -309,8 +318,8 @@ const isBase32Hex = (string) => {
|
|
|
309
318
|
return isBase32(string, true);
|
|
310
319
|
};
|
|
311
320
|
var index$8 = {
|
|
312
|
-
encode: encode$
|
|
313
|
-
decode: decode$
|
|
321
|
+
encode: encode$7,
|
|
322
|
+
decode: decode$8,
|
|
314
323
|
encodeHex: encodeHex$2,
|
|
315
324
|
decodeHex: decodeHex$2,
|
|
316
325
|
isBase32,
|
|
@@ -321,13 +330,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
|
321
330
|
var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
|
|
322
331
|
var base58 = base$1(ALPHABET$2);
|
|
323
332
|
var base58Hex = base$1(ALPHABET_HEX);
|
|
324
|
-
var encode$
|
|
325
|
-
var decode$
|
|
333
|
+
var encode$6 = base58.encode;
|
|
334
|
+
var decode$7 = base58.decode;
|
|
326
335
|
var encodeHex$1 = base58Hex.encode;
|
|
327
336
|
var decodeHex$1 = base58Hex.decode;
|
|
328
337
|
var isBase58 = function (string) {
|
|
329
338
|
try {
|
|
330
|
-
decode$
|
|
339
|
+
decode$7(string);
|
|
331
340
|
return true;
|
|
332
341
|
}
|
|
333
342
|
catch (e) {
|
|
@@ -345,7 +354,7 @@ var isBase58Hex = function (string) {
|
|
|
345
354
|
};
|
|
346
355
|
var whatType = function (string) {
|
|
347
356
|
try {
|
|
348
|
-
decode$
|
|
357
|
+
decode$7(string);
|
|
349
358
|
return 'base58';
|
|
350
359
|
}
|
|
351
360
|
catch (e) {
|
|
@@ -358,15 +367,15 @@ var whatType = function (string) {
|
|
|
358
367
|
}
|
|
359
368
|
}
|
|
360
369
|
};
|
|
361
|
-
var base58$1 = { encode: encode$
|
|
370
|
+
var base58$1 = { encode: encode$6, decode: decode$7, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
|
|
362
371
|
|
|
363
372
|
const MSB$1 = 0x80;
|
|
364
373
|
const REST$1 = 0x7F;
|
|
365
374
|
const MSBALL = ~REST$1;
|
|
366
375
|
const INT = Math.pow(2, 31);
|
|
367
|
-
const encode$
|
|
376
|
+
const encode$5 = (num, out, offset) => {
|
|
368
377
|
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
369
|
-
encode$
|
|
378
|
+
encode$5.bytes = 0;
|
|
370
379
|
throw new RangeError('Could not encode varint');
|
|
371
380
|
}
|
|
372
381
|
out = out || [];
|
|
@@ -381,13 +390,13 @@ const encode$6 = (num, out, offset) => {
|
|
|
381
390
|
num >>>= 7;
|
|
382
391
|
}
|
|
383
392
|
out[offset] = num | 0;
|
|
384
|
-
encode$
|
|
393
|
+
encode$5.bytes = offset - oldOffset + 1;
|
|
385
394
|
return out;
|
|
386
395
|
};
|
|
387
396
|
|
|
388
397
|
const MSB = 0x80;
|
|
389
398
|
const REST = 0x7F;
|
|
390
|
-
const decode$
|
|
399
|
+
const decode$6 = (buf, offset) => {
|
|
391
400
|
offset = offset || 0;
|
|
392
401
|
const l = buf.length;
|
|
393
402
|
let counter = offset;
|
|
@@ -396,7 +405,7 @@ const decode$7 = (buf, offset) => {
|
|
|
396
405
|
let b;
|
|
397
406
|
do {
|
|
398
407
|
if (counter >= l || shift > 49) {
|
|
399
|
-
decode$
|
|
408
|
+
decode$6.bytes = 0;
|
|
400
409
|
throw new RangeError('Could not decode varint');
|
|
401
410
|
}
|
|
402
411
|
b = buf[counter++];
|
|
@@ -405,7 +414,7 @@ const decode$7 = (buf, offset) => {
|
|
|
405
414
|
: (b & REST) * Math.pow(2, shift);
|
|
406
415
|
shift += 7;
|
|
407
416
|
} while (b >= MSB);
|
|
408
|
-
decode$
|
|
417
|
+
decode$6.bytes = counter - offset;
|
|
409
418
|
return result;
|
|
410
419
|
};
|
|
411
420
|
|
|
@@ -430,8 +439,8 @@ var encodingLength = (value) => (value < N1 ? 1
|
|
|
430
439
|
: 10);
|
|
431
440
|
|
|
432
441
|
var index$7 = {
|
|
433
|
-
encode: encode$
|
|
434
|
-
decode: decode$
|
|
442
|
+
encode: encode$5,
|
|
443
|
+
decode: decode$6,
|
|
435
444
|
encodingLength
|
|
436
445
|
};
|
|
437
446
|
|
|
@@ -481,11 +490,11 @@ var index$5 = (typedArray, prefix) => {
|
|
|
481
490
|
|
|
482
491
|
const ALPHABET$1 = '0123456789ABCDEF';
|
|
483
492
|
const base16 = base$1(ALPHABET$1);
|
|
484
|
-
const decode$
|
|
485
|
-
const encode$
|
|
493
|
+
const decode$5 = base16.decode;
|
|
494
|
+
const encode$4 = base16.encode;
|
|
486
495
|
const isBase16 = (string) => {
|
|
487
496
|
try {
|
|
488
|
-
decode$
|
|
497
|
+
decode$5(string);
|
|
489
498
|
return true;
|
|
490
499
|
}
|
|
491
500
|
catch (e) {
|
|
@@ -493,18 +502,18 @@ const isBase16 = (string) => {
|
|
|
493
502
|
}
|
|
494
503
|
};
|
|
495
504
|
var index$4 = {
|
|
496
|
-
encode: encode$
|
|
497
|
-
decode: decode$
|
|
505
|
+
encode: encode$4,
|
|
506
|
+
decode: decode$5,
|
|
498
507
|
isBase16
|
|
499
508
|
};
|
|
500
509
|
|
|
501
510
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
502
511
|
const base64 = base$1(ALPHABET);
|
|
503
|
-
const decode$
|
|
504
|
-
const encode$
|
|
512
|
+
const decode$4 = base64.decode;
|
|
513
|
+
const encode$3 = base64.encode;
|
|
505
514
|
const isBase64 = (string) => {
|
|
506
515
|
try {
|
|
507
|
-
decode$
|
|
516
|
+
decode$4(string);
|
|
508
517
|
return true;
|
|
509
518
|
}
|
|
510
519
|
catch (e) {
|
|
@@ -512,221 +521,211 @@ const isBase64 = (string) => {
|
|
|
512
521
|
}
|
|
513
522
|
};
|
|
514
523
|
var index$3 = {
|
|
515
|
-
encode: encode$
|
|
516
|
-
decode: decode$
|
|
524
|
+
encode: encode$3,
|
|
525
|
+
decode: decode$4,
|
|
517
526
|
isBase64
|
|
518
527
|
};
|
|
519
528
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Returns a
|
|
542
|
-
* @param
|
|
543
|
-
* @returns
|
|
544
|
-
*/
|
|
545
|
-
const
|
|
546
|
-
/**
|
|
547
|
-
* Returns a
|
|
548
|
-
* @param
|
|
549
|
-
* @returns
|
|
550
|
-
*/
|
|
551
|
-
const
|
|
552
|
-
/**
|
|
553
|
-
* Returns a
|
|
554
|
-
* @param
|
|
555
|
-
* @returns
|
|
556
|
-
*/
|
|
557
|
-
const
|
|
558
|
-
/**
|
|
559
|
-
*
|
|
560
|
-
* @param
|
|
561
|
-
* @returns
|
|
562
|
-
*/
|
|
563
|
-
const
|
|
564
|
-
/**
|
|
565
|
-
*
|
|
566
|
-
* @param
|
|
567
|
-
* @returns
|
|
568
|
-
*/
|
|
569
|
-
const
|
|
570
|
-
/**
|
|
571
|
-
*
|
|
572
|
-
* @param
|
|
573
|
-
* @returns
|
|
574
|
-
*/
|
|
575
|
-
const
|
|
576
|
-
/**
|
|
577
|
-
*
|
|
578
|
-
* @param
|
|
579
|
-
* @returns Uint8Array
|
|
580
|
-
*/
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
*
|
|
652
|
-
* @
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
* uint8Array
|
|
659
|
-
* @
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
*
|
|
676
|
-
* @
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
toUintArrayString,
|
|
721
|
-
toBase64,
|
|
722
|
-
fromBase64,
|
|
723
|
-
toBase58,
|
|
724
|
-
fromBase58,
|
|
725
|
-
toBase32,
|
|
726
|
-
fromBase32,
|
|
727
|
-
toBase16,
|
|
728
|
-
fromBase16,
|
|
729
|
-
FormatInterface: FormatInterface$2
|
|
529
|
+
/**
|
|
530
|
+
* Returns a hex string as Binary string
|
|
531
|
+
* @param string string to encode to binary
|
|
532
|
+
* @returns binaryString
|
|
533
|
+
*/
|
|
534
|
+
const hexToBinary = (hex) => (parseInt(hex, 16).toString(2)).padStart(8, '0');
|
|
535
|
+
const isTypedArrayCompatible = (possibleUint8Array) => {
|
|
536
|
+
if (typeof possibleUint8Array === 'string') {
|
|
537
|
+
possibleUint8Array = possibleUint8Array.split(',').map(number => Number(number));
|
|
538
|
+
for (const number of possibleUint8Array) {
|
|
539
|
+
if (isNaN(number))
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
for (const number of possibleUint8Array) {
|
|
544
|
+
if (isNaN(number))
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
return true;
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Returns a String as Uint8Array
|
|
551
|
+
* @param string string to encode to Uint8Array
|
|
552
|
+
* @returns Uint8Array
|
|
553
|
+
*/
|
|
554
|
+
const fromString$1 = (string) => new TextEncoder().encode(string);
|
|
555
|
+
/**
|
|
556
|
+
* Returns a Uint8Array as String
|
|
557
|
+
* @param uint8Array Uint8Array to encode to String
|
|
558
|
+
* @returns String
|
|
559
|
+
*/
|
|
560
|
+
const toString$1 = (uint8Array) => new TextDecoder().decode(uint8Array);
|
|
561
|
+
/**
|
|
562
|
+
* Returns a String as Uint8Array
|
|
563
|
+
* @param string string to encode to Uint8Array
|
|
564
|
+
* @returns Uint8Array
|
|
565
|
+
*/
|
|
566
|
+
const fromUintArrayString = (string) => Uint8Array.from(string.split(',').map(string => Number(string)));
|
|
567
|
+
/**
|
|
568
|
+
* Returns a Uint8Array as String
|
|
569
|
+
* @param uint8Array Uint8Array to encode to String
|
|
570
|
+
* @returns String
|
|
571
|
+
*/
|
|
572
|
+
const toUintArrayString = (uint8Array) => uint8Array.toString();
|
|
573
|
+
/**
|
|
574
|
+
* hexString -> uint8Array
|
|
575
|
+
* @param string hex encoded string
|
|
576
|
+
* @returns UintArray
|
|
577
|
+
*/
|
|
578
|
+
const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
579
|
+
/**
|
|
580
|
+
* uint8Array -> hexString
|
|
581
|
+
* @param bytes number[]
|
|
582
|
+
* @returns hexString
|
|
583
|
+
*/
|
|
584
|
+
const toHex$2 = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
|
|
585
|
+
/**
|
|
586
|
+
* number[] -> Uint8Array
|
|
587
|
+
* @param array number[]
|
|
588
|
+
* @returns Uint8Array
|
|
589
|
+
*/
|
|
590
|
+
const fromArrayLike = (array) => Uint8Array.from(array);
|
|
591
|
+
/**
|
|
592
|
+
* Uint8Array -> number[]
|
|
593
|
+
* @param uint8Array Uint8Array
|
|
594
|
+
* @returns Uint8Array
|
|
595
|
+
*/
|
|
596
|
+
const toArrayLike = (uint8Array) => [...uint8Array.values()];
|
|
597
|
+
/**
|
|
598
|
+
* object -> Uint8Array
|
|
599
|
+
* @param object any
|
|
600
|
+
* @returns Uint8Array
|
|
601
|
+
*/
|
|
602
|
+
const fromObject = (object) => new TextEncoder().encode(JSON.stringify(object));
|
|
603
|
+
/**
|
|
604
|
+
* Uint8Array -> Object
|
|
605
|
+
* @param uint8Array Uint8Array
|
|
606
|
+
* @returns Object
|
|
607
|
+
*/
|
|
608
|
+
const toObject = (uint8Array) => JSON.parse(new TextDecoder().decode(uint8Array));
|
|
609
|
+
const fromBinary = (string) => fromHex(parseInt(string, 2).toString(16).toUpperCase());
|
|
610
|
+
const toBinary = (uint8Array) => hexToBinary(toHex$2(uint8Array));
|
|
611
|
+
const toBase64 = (uint8Array) => index$3.encode(uint8Array);
|
|
612
|
+
const fromBase64 = (string) => index$3.decode(string);
|
|
613
|
+
const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
|
|
614
|
+
const fromBase58 = (string) => base58$1.decode(string);
|
|
615
|
+
const toBase32 = (uint8Array) => index$8.encode(uint8Array);
|
|
616
|
+
const fromBase32 = (string) => index$8.decode(string);
|
|
617
|
+
const toBase16 = (uint8Array) => index$4.encode(uint8Array);
|
|
618
|
+
const fromBase16 = (string) => index$4.decode(string);
|
|
619
|
+
let FormatInterface$2 = class FormatInterface {
|
|
620
|
+
encoded;
|
|
621
|
+
decoded;
|
|
622
|
+
constructor(input) {
|
|
623
|
+
if (input) {
|
|
624
|
+
if (index$4.isBase16(input))
|
|
625
|
+
this.encoded = this.fromBase16(input);
|
|
626
|
+
else if (index$8.isBase32(input))
|
|
627
|
+
this.encoded = this.fromBase32(input);
|
|
628
|
+
else if (base58$1.isBase58(input))
|
|
629
|
+
this.encoded = this.fromBase58(input);
|
|
630
|
+
else if (index$3.isBase64(input))
|
|
631
|
+
this.encoded = this.fromBase64(input);
|
|
632
|
+
else if (typeof input === 'string') {
|
|
633
|
+
let isCompatible = isTypedArrayCompatible(input);
|
|
634
|
+
if (isCompatible)
|
|
635
|
+
this.encoded = fromUintArrayString(input);
|
|
636
|
+
else
|
|
637
|
+
this.encoded = this.fromString(input); // normal string
|
|
638
|
+
}
|
|
639
|
+
else if (typeof input === 'object')
|
|
640
|
+
this.encoded = this.fromObject(input);
|
|
641
|
+
else if (input instanceof Uint8Array)
|
|
642
|
+
this.encoded = input;
|
|
643
|
+
else if (Array.isArray(input) && isTypedArrayCompatible(input))
|
|
644
|
+
this.encoded = this.fromArrayLike(input);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Returns a String as Uint8Array
|
|
649
|
+
* @param string string to encode to Uint8Array
|
|
650
|
+
* @returns Uint8Array
|
|
651
|
+
*/
|
|
652
|
+
fromString = (string) => this.encoded = fromString$1(string);
|
|
653
|
+
/**
|
|
654
|
+
* Returns a Uint8Array as String
|
|
655
|
+
* @param uint8Array Uint8Array to encode to String
|
|
656
|
+
* @returns String
|
|
657
|
+
*/
|
|
658
|
+
toString = (uint8Array) => this.decoded = toString$1(uint8Array);
|
|
659
|
+
/**
|
|
660
|
+
* Returns a String as Uint8Array
|
|
661
|
+
* @param string string to encode to Uint8Array
|
|
662
|
+
* @returns Uint8Array
|
|
663
|
+
*/
|
|
664
|
+
fromUintArrayString = (string) => this.encoded = fromUintArrayString(string);
|
|
665
|
+
/**
|
|
666
|
+
* Returns a Uint8Array as String
|
|
667
|
+
* @param uint8Array Uint8Array to encode to String
|
|
668
|
+
* @returns String
|
|
669
|
+
*/
|
|
670
|
+
toUintArrayString = (uint8Array) => this.decoded = uint8Array.toString();
|
|
671
|
+
/**
|
|
672
|
+
* hexString -> uint8Array
|
|
673
|
+
* @param string hex encoded string
|
|
674
|
+
* @returns UintArray
|
|
675
|
+
*/
|
|
676
|
+
fromHex = (string) => this.encoded = fromHex(string);
|
|
677
|
+
/**
|
|
678
|
+
* uint8Array -> hexString
|
|
679
|
+
* @param bytes ArrayLike
|
|
680
|
+
* @returns hexString
|
|
681
|
+
*/
|
|
682
|
+
toHex = (arrayLike) => this.decoded = toHex$2(arrayLike);
|
|
683
|
+
/**
|
|
684
|
+
* number[] -> Uint8Array
|
|
685
|
+
* @param array number[]
|
|
686
|
+
* @returns Uint8Array
|
|
687
|
+
*/
|
|
688
|
+
fromArrayLike = (array) => this.encoded = Uint8Array.from(array);
|
|
689
|
+
/**
|
|
690
|
+
* Uint8Array -> number[]
|
|
691
|
+
* @param uint8Array Uint8Array
|
|
692
|
+
* @returns Uint8Array
|
|
693
|
+
*/
|
|
694
|
+
toArrayLike = (uint8Array) => this.decoded = [...uint8Array.values()];
|
|
695
|
+
fromObject = (object) => this.encoded = fromObject(object);
|
|
696
|
+
toBinary = (uint8Array) => this.decoded = hexToBinary(toHex$2(uint8Array));
|
|
697
|
+
fromBinary = (binary) => this.encoded = fromBinary(binary);
|
|
698
|
+
toObject = (uint8Array) => this.decoded = toObject(uint8Array);
|
|
699
|
+
toBase64 = (uint8Array) => this.decoded = index$3.encode(uint8Array);
|
|
700
|
+
fromBase64 = (string) => this.encoded = index$3.decode(string);
|
|
701
|
+
toBase58 = (uint8Array) => this.decoded = base58$1.encode(uint8Array);
|
|
702
|
+
fromBase58 = (string) => this.encoded = base58$1.decode(string);
|
|
703
|
+
toBase32 = (uint8Array) => this.decoded = index$8.encode(uint8Array);
|
|
704
|
+
fromBase32 = (string) => this.encoded = index$8.decode(string);
|
|
705
|
+
toBase16 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
|
|
706
|
+
fromBase16 = (string) => this.decoded = index$4.decode(string);
|
|
707
|
+
};
|
|
708
|
+
var index$2 = {
|
|
709
|
+
fromString: fromString$1,
|
|
710
|
+
toString: toString$1,
|
|
711
|
+
fromHex,
|
|
712
|
+
toHex: toHex$2,
|
|
713
|
+
fromArrayLike,
|
|
714
|
+
toArrayLike,
|
|
715
|
+
fromUintArrayString,
|
|
716
|
+
toUintArrayString,
|
|
717
|
+
toObject,
|
|
718
|
+
toBinary,
|
|
719
|
+
fromBinary,
|
|
720
|
+
toBase64,
|
|
721
|
+
fromBase64,
|
|
722
|
+
toBase58,
|
|
723
|
+
fromBase58,
|
|
724
|
+
toBase32,
|
|
725
|
+
fromBase32,
|
|
726
|
+
toBase16,
|
|
727
|
+
fromBase16,
|
|
728
|
+
FormatInterface: FormatInterface$2
|
|
730
729
|
};
|
|
731
730
|
|
|
732
731
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -4897,7 +4896,7 @@ const toType = (data) => {
|
|
|
4897
4896
|
return new TextEncoder().encode(data.toString());
|
|
4898
4897
|
throw new Error(`unsuported type ${typeof data || data}`);
|
|
4899
4898
|
};
|
|
4900
|
-
const encode$
|
|
4899
|
+
const encode$2 = (proto, input, compress) => {
|
|
4901
4900
|
const keys = Object.keys(proto);
|
|
4902
4901
|
const values = Object.values(proto);
|
|
4903
4902
|
const set = [];
|
|
@@ -4914,7 +4913,7 @@ const encode$3 = (proto, input, compress) => {
|
|
|
4914
4913
|
}
|
|
4915
4914
|
return index$6(set);
|
|
4916
4915
|
};
|
|
4917
|
-
const decode$
|
|
4916
|
+
const decode$3 = (proto, uint8Array, compressed) => {
|
|
4918
4917
|
let deconcated = index$5(uint8Array);
|
|
4919
4918
|
const output = {};
|
|
4920
4919
|
const keys = Object.keys(proto);
|
|
@@ -4945,8 +4944,8 @@ const decode$4 = (proto, uint8Array, compressed) => {
|
|
|
4945
4944
|
return output;
|
|
4946
4945
|
};
|
|
4947
4946
|
var index$1 = {
|
|
4948
|
-
encode: encode$
|
|
4949
|
-
decode: decode$
|
|
4947
|
+
encode: encode$2,
|
|
4948
|
+
decode: decode$3
|
|
4950
4949
|
};
|
|
4951
4950
|
|
|
4952
4951
|
/*!
|
|
@@ -6316,8 +6315,7 @@ class DhtEarth {
|
|
|
6316
6315
|
if (!fetchedCoordinates[address]) {
|
|
6317
6316
|
const request = `https://whereis.leofcoin.org/?ip=${address}`;
|
|
6318
6317
|
let response = await fetch(request);
|
|
6319
|
-
|
|
6320
|
-
const { lat, lon } = response;
|
|
6318
|
+
const { lat, lon } = await response.json();
|
|
6321
6319
|
fetchedCoordinates[address] = { latitude: lat, longitude: lon };
|
|
6322
6320
|
}
|
|
6323
6321
|
return fetchedCoordinates[address];
|
|
@@ -6341,6 +6339,7 @@ class DhtEarth {
|
|
|
6341
6339
|
else
|
|
6342
6340
|
all.push(this.getDistance(peerLoc, provider));
|
|
6343
6341
|
}
|
|
6342
|
+
// todo queue
|
|
6344
6343
|
all = await Promise.all(all);
|
|
6345
6344
|
all = all.sort((previous, current) => previous.distance - current.distance);
|
|
6346
6345
|
return all[0].provider;
|
|
@@ -6354,22 +6353,20 @@ class DhtEarth {
|
|
|
6354
6353
|
providers = this.providerMap.get(hash);
|
|
6355
6354
|
return providers;
|
|
6356
6355
|
}
|
|
6357
|
-
addProvider(
|
|
6358
|
-
let providers =
|
|
6356
|
+
addProvider(provider, hash) {
|
|
6357
|
+
let providers = {};
|
|
6359
6358
|
if (this.providerMap.has(hash)) {
|
|
6360
6359
|
providers = this.providerMap.get(hash);
|
|
6361
6360
|
}
|
|
6362
|
-
providers.
|
|
6361
|
+
providers[provider.address] = provider;
|
|
6363
6362
|
this.providerMap.set(hash, providers);
|
|
6364
6363
|
}
|
|
6365
6364
|
removeProvider(address, hash) {
|
|
6366
|
-
let deleted = undefined;
|
|
6367
6365
|
if (this.providerMap.has(hash)) {
|
|
6368
6366
|
const providers = this.providerMap.get(hash);
|
|
6369
|
-
|
|
6370
|
-
|
|
6367
|
+
delete providers[address];
|
|
6368
|
+
this.providerMap.set(hash, providers);
|
|
6371
6369
|
}
|
|
6372
|
-
return deleted;
|
|
6373
6370
|
}
|
|
6374
6371
|
}
|
|
6375
6372
|
|
|
@@ -6425,278 +6422,188 @@ const nothingFoundError = (hash) => {
|
|
|
6425
6422
|
return new Error(`nothing found for ${hash}`)
|
|
6426
6423
|
};
|
|
6427
6424
|
|
|
6428
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
6429
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
6430
|
-
|
|
6431
|
-
// export const encodings = {
|
|
6432
|
-
// base58,
|
|
6433
|
-
// base32
|
|
6434
|
-
// }
|
|
6435
|
-
|
|
6436
|
-
const encode$2 = (string, encoding = 'utf-8') => {
|
|
6437
|
-
if (typeof string === 'string') {
|
|
6438
|
-
let encoded;
|
|
6439
|
-
|
|
6440
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
6441
|
-
encoded = new TextEncoder().encode(string);
|
|
6442
|
-
return encoded
|
|
6443
|
-
}
|
|
6444
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
6445
|
-
};
|
|
6446
|
-
|
|
6447
|
-
const decode$3 = (uint8Array, encoding) => {
|
|
6448
|
-
if (uint8Array instanceof Uint8Array) {
|
|
6449
|
-
let decoded;
|
|
6450
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
6451
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
6452
|
-
|
|
6453
|
-
return decoded
|
|
6454
|
-
}
|
|
6455
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
6456
|
-
};
|
|
6457
|
-
|
|
6458
|
-
const pathSepS = '/';
|
|
6459
|
-
class KeyPath {
|
|
6460
|
-
|
|
6461
|
-
/**
|
|
6462
|
-
* @param {string | Uint8Array} input
|
|
6463
|
-
*/
|
|
6464
|
-
constructor(input) {
|
|
6465
|
-
if (typeof input === 'string') {
|
|
6466
|
-
this.uint8Array = encode$2(input);
|
|
6467
|
-
} else if (input instanceof Uint8Array) {
|
|
6468
|
-
this.uint8Array = input;
|
|
6469
|
-
} else if (input instanceof KeyPath) {
|
|
6470
|
-
this.uint8Array = input.uint8Array;
|
|
6471
|
-
} else {
|
|
6472
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
6473
|
-
}
|
|
6474
|
-
}
|
|
6475
|
-
|
|
6476
|
-
isKeyPath() {
|
|
6477
|
-
return true
|
|
6478
|
-
}
|
|
6479
|
-
|
|
6480
|
-
/**
|
|
6481
|
-
* Convert to the string representation
|
|
6482
|
-
*
|
|
6483
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
6484
|
-
* @returns {string}
|
|
6485
|
-
*/
|
|
6486
|
-
toString(encoding = 'hex') {
|
|
6487
|
-
return decode$3(this.uint8Array)
|
|
6488
|
-
}
|
|
6489
|
-
|
|
6490
|
-
/**
|
|
6491
|
-
* Returns the `list` representation of this path.
|
|
6492
|
-
*
|
|
6493
|
-
* @returns string[]
|
|
6494
|
-
*
|
|
6495
|
-
* @example
|
|
6496
|
-
* ```js
|
|
6497
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
6498
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
6499
|
-
* ```
|
|
6500
|
-
*/
|
|
6501
|
-
list() {
|
|
6502
|
-
return this.toString().split(pathSepS).slice(1)
|
|
6503
|
-
}
|
|
6504
|
-
|
|
6505
|
-
}
|
|
6506
|
-
|
|
6507
6425
|
let LeofcoinStorage$1 = class LeofcoinStorage {
|
|
6426
|
+
name;
|
|
6427
|
+
root;
|
|
6428
|
+
db;
|
|
6429
|
+
constructor(name = 'storage', root = '.leofcoin') {
|
|
6430
|
+
this.name = name;
|
|
6431
|
+
this.root = root;
|
|
6432
|
+
}
|
|
6433
|
+
async init(name, root) {
|
|
6434
|
+
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6435
|
+
const Store = importee.default;
|
|
6436
|
+
this.db = new Store(this.name, this.root);
|
|
6437
|
+
}
|
|
6438
|
+
async get(key) {
|
|
6439
|
+
if (typeof key === 'object')
|
|
6440
|
+
return this.many('get', key);
|
|
6441
|
+
return this.db.get(new KeyPath(key));
|
|
6442
|
+
}
|
|
6443
|
+
/**
|
|
6444
|
+
*
|
|
6445
|
+
* @param {*} key
|
|
6446
|
+
* @param {*} value
|
|
6447
|
+
* @returns Promise
|
|
6448
|
+
*/
|
|
6449
|
+
put(key, value) {
|
|
6450
|
+
if (typeof key === 'object')
|
|
6451
|
+
return this.many('put', key);
|
|
6452
|
+
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6453
|
+
}
|
|
6454
|
+
async has(key) {
|
|
6455
|
+
if (typeof key === 'object')
|
|
6456
|
+
return this.many('has', key);
|
|
6457
|
+
try {
|
|
6458
|
+
const has = await this.db.get(new KeyPath(key));
|
|
6459
|
+
return Boolean(has);
|
|
6460
|
+
}
|
|
6461
|
+
catch (e) {
|
|
6462
|
+
return false;
|
|
6463
|
+
}
|
|
6464
|
+
}
|
|
6465
|
+
async delete(key) {
|
|
6466
|
+
return this.db.delete(new KeyPath(key));
|
|
6467
|
+
}
|
|
6468
|
+
keys(limit = -1) {
|
|
6469
|
+
return this.db.keys(limit);
|
|
6470
|
+
}
|
|
6471
|
+
async values(limit = -1) {
|
|
6472
|
+
return this.db.values(limit);
|
|
6473
|
+
}
|
|
6474
|
+
async many(type, _value) {
|
|
6475
|
+
const jobs = [];
|
|
6476
|
+
for (const key of Object.keys(_value)) {
|
|
6477
|
+
jobs.push(this[type](key, _value[key]));
|
|
6478
|
+
}
|
|
6479
|
+
return Promise.all(jobs);
|
|
6480
|
+
}
|
|
6481
|
+
async length() {
|
|
6482
|
+
const keys = await this.keys();
|
|
6483
|
+
return keys.length;
|
|
6484
|
+
}
|
|
6485
|
+
async size() {
|
|
6486
|
+
let size = 0;
|
|
6487
|
+
const query = await this.db.iterate();
|
|
6488
|
+
for await (const item of query) {
|
|
6489
|
+
size += item.value ? item.value.length : item[1].length;
|
|
6490
|
+
}
|
|
6491
|
+
return size;
|
|
6492
|
+
}
|
|
6493
|
+
async clear() {
|
|
6494
|
+
return this.db.clear();
|
|
6495
|
+
}
|
|
6496
|
+
async iterate() {
|
|
6497
|
+
return this.db.iterate();
|
|
6498
|
+
}
|
|
6499
|
+
};
|
|
6508
6500
|
|
|
6509
|
-
|
|
6510
|
-
this.name = name;
|
|
6511
|
-
this.root = root;
|
|
6512
|
-
}
|
|
6501
|
+
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
6513
6502
|
|
|
6514
|
-
|
|
6515
|
-
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6516
|
-
const Store = importee.default;
|
|
6517
|
-
this.db = new Store(this.name, this.root);
|
|
6518
|
-
}
|
|
6503
|
+
const {subtle} = crypto;
|
|
6519
6504
|
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
*/
|
|
6531
|
-
put(key, value) {
|
|
6532
|
-
if (typeof key === 'object') return this.many('put', key);
|
|
6533
|
-
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6534
|
-
}
|
|
6505
|
+
/**
|
|
6506
|
+
* ```js
|
|
6507
|
+
* const {createHash} = await import('@leofcoin/crypto')
|
|
6508
|
+
* createHash(data, algorithm)
|
|
6509
|
+
* ```
|
|
6510
|
+
* @param {Uint8Array} data
|
|
6511
|
+
* @param {string} algorithm
|
|
6512
|
+
* @returns Uint8Array
|
|
6513
|
+
*/
|
|
6514
|
+
const createHash = (data, algorithm = 'SHA-512') => subtle.digest(algorithm, data);
|
|
6535
6515
|
|
|
6536
|
-
|
|
6537
|
-
|
|
6516
|
+
/**
|
|
6517
|
+
* Hashes the created hash again
|
|
6518
|
+
* ```js
|
|
6519
|
+
* const {createDoubleHash} = await import('@leofcoin/crypto')
|
|
6520
|
+
* createDoubleHash(data, algorithm)
|
|
6521
|
+
* ```
|
|
6522
|
+
* @param {Uint8Array} data
|
|
6523
|
+
* @param {string} algorithm
|
|
6524
|
+
* @returns Uint8Array
|
|
6525
|
+
*/
|
|
6526
|
+
const createDoubleHash = async (data, algorithm = 'SHA-512') =>
|
|
6527
|
+
subtle.digest(algorithm, await subtle.digest(algorithm, data));
|
|
6538
6528
|
|
|
6539
|
-
|
|
6540
|
-
|
|
6529
|
+
const generatePbkdf2 = async (password) => {
|
|
6530
|
+
return subtle.importKey(
|
|
6531
|
+
'raw',
|
|
6532
|
+
password,
|
|
6533
|
+
'PBKDF2',
|
|
6534
|
+
false,
|
|
6535
|
+
['deriveBits']
|
|
6536
|
+
)
|
|
6537
|
+
};
|
|
6541
6538
|
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6539
|
+
const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SHA-512') => {
|
|
6540
|
+
const key = await generatePbkdf2(password);
|
|
6541
|
+
return subtle.deriveBits({
|
|
6542
|
+
name: 'PBKDF2',
|
|
6543
|
+
hash,
|
|
6544
|
+
salt,
|
|
6545
|
+
iterations,
|
|
6546
|
+
}, key, length)
|
|
6547
|
+
};
|
|
6547
6548
|
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6549
|
+
const generateAesKey = async (length = 256) => {
|
|
6550
|
+
const key = await subtle.generateKey({
|
|
6551
|
+
name: 'AES-CBC',
|
|
6552
|
+
length
|
|
6553
|
+
}, true, ['encrypt', 'decrypt']);
|
|
6551
6554
|
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
}
|
|
6555
|
+
return key;
|
|
6556
|
+
};
|
|
6555
6557
|
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6558
|
+
const importAesKey = async (exported, format = 'raw', length = 256) => {
|
|
6559
|
+
return await subtle.importKey(format, exported, {
|
|
6560
|
+
name: 'AES-CBC',
|
|
6561
|
+
length
|
|
6562
|
+
}, true, ['encrypt', 'decrypt'])
|
|
6563
|
+
};
|
|
6559
6564
|
|
|
6560
|
-
|
|
6561
|
-
|
|
6565
|
+
const exportAesKey = async (key, format = 'raw') => {
|
|
6566
|
+
return await subtle.exportKey(format, key)
|
|
6567
|
+
};
|
|
6562
6568
|
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6569
|
+
const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
|
|
6570
|
+
name: 'AES-CBC',
|
|
6571
|
+
iv,
|
|
6572
|
+
}, key, uint8Array);
|
|
6566
6573
|
|
|
6567
|
-
|
|
6568
|
-
|
|
6574
|
+
const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
|
|
6575
|
+
name: 'AES-CBC',
|
|
6576
|
+
iv,
|
|
6577
|
+
}, key, uint8Array);
|
|
6569
6578
|
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
return keys.length
|
|
6573
|
-
}
|
|
6579
|
+
const uint8ArrayToHex = uint8Array =>
|
|
6580
|
+
[...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
6574
6581
|
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
const query = await this.db.iterate();
|
|
6578
|
-
for await (const item of query) {
|
|
6579
|
-
size += item.value ? item.value.length : item[1].length;
|
|
6580
|
-
}
|
|
6581
|
-
return size
|
|
6582
|
-
}
|
|
6582
|
+
const arrayBufferToHex = arrayBuffer =>
|
|
6583
|
+
uint8ArrayToHex(new Uint8Array(arrayBuffer));
|
|
6583
6584
|
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
}
|
|
6585
|
+
const hexToUint8Array = hex =>
|
|
6586
|
+
new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
|
|
6587
6587
|
|
|
6588
|
-
|
|
6589
|
-
|
|
6588
|
+
const encrypt$1 = async string => {
|
|
6589
|
+
const key = await generateAesKey();
|
|
6590
|
+
const iv = randombytes(16);
|
|
6591
|
+
const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
|
|
6592
|
+
const exported = await exportAesKey(key);
|
|
6593
|
+
return {
|
|
6594
|
+
key: arrayBufferToHex(exported),
|
|
6595
|
+
iv: uint8ArrayToHex(iv),
|
|
6596
|
+
cipher: arrayBufferToHex(ciphertext)
|
|
6590
6597
|
}
|
|
6591
|
-
|
|
6592
6598
|
};
|
|
6593
6599
|
|
|
6594
|
-
const
|
|
6600
|
+
const decrypt$1 = async ({cipher, key, iv}) => {
|
|
6601
|
+
if (!key.type) key = await importAesKey(hexToUint8Array(key));
|
|
6602
|
+
cipher = new Uint8Array(hexToUint8Array(cipher));
|
|
6603
|
+
iv = new Uint8Array(hexToUint8Array(iv));
|
|
6595
6604
|
|
|
6596
|
-
const
|
|
6597
|
-
|
|
6598
|
-
/**
|
|
6599
|
-
* ```js
|
|
6600
|
-
* const {createHash} = await import('@leofcoin/crypto')
|
|
6601
|
-
* createHash(data, algorithm)
|
|
6602
|
-
* ```
|
|
6603
|
-
* @param {Uint8Array} data
|
|
6604
|
-
* @param {string} algorithm
|
|
6605
|
-
* @returns Uint8Array
|
|
6606
|
-
*/
|
|
6607
|
-
const createHash = (data, algorithm = 'SHA-512') => subtle.digest(algorithm, data);
|
|
6608
|
-
|
|
6609
|
-
/**
|
|
6610
|
-
* Hashes the created hash again
|
|
6611
|
-
* ```js
|
|
6612
|
-
* const {createDoubleHash} = await import('@leofcoin/crypto')
|
|
6613
|
-
* createDoubleHash(data, algorithm)
|
|
6614
|
-
* ```
|
|
6615
|
-
* @param {Uint8Array} data
|
|
6616
|
-
* @param {string} algorithm
|
|
6617
|
-
* @returns Uint8Array
|
|
6618
|
-
*/
|
|
6619
|
-
const createDoubleHash = async (data, algorithm = 'SHA-512') =>
|
|
6620
|
-
subtle.digest(algorithm, await subtle.digest(algorithm, data));
|
|
6621
|
-
|
|
6622
|
-
const generatePbkdf2 = async (password) => {
|
|
6623
|
-
return subtle.importKey(
|
|
6624
|
-
'raw',
|
|
6625
|
-
password,
|
|
6626
|
-
'PBKDF2',
|
|
6627
|
-
false,
|
|
6628
|
-
['deriveBits']
|
|
6629
|
-
)
|
|
6630
|
-
};
|
|
6631
|
-
|
|
6632
|
-
const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SHA-512') => {
|
|
6633
|
-
const key = await generatePbkdf2(password);
|
|
6634
|
-
return subtle.deriveBits({
|
|
6635
|
-
name: 'PBKDF2',
|
|
6636
|
-
hash,
|
|
6637
|
-
salt,
|
|
6638
|
-
iterations,
|
|
6639
|
-
}, key, length)
|
|
6640
|
-
};
|
|
6641
|
-
|
|
6642
|
-
const generateAesKey = async (length = 256) => {
|
|
6643
|
-
const key = await subtle.generateKey({
|
|
6644
|
-
name: 'AES-CBC',
|
|
6645
|
-
length
|
|
6646
|
-
}, true, ['encrypt', 'decrypt']);
|
|
6647
|
-
|
|
6648
|
-
return key;
|
|
6649
|
-
};
|
|
6650
|
-
|
|
6651
|
-
const importAesKey = async (exported, format = 'raw', length = 256) => {
|
|
6652
|
-
return await subtle.importKey(format, exported, {
|
|
6653
|
-
name: 'AES-CBC',
|
|
6654
|
-
length
|
|
6655
|
-
}, true, ['encrypt', 'decrypt'])
|
|
6656
|
-
};
|
|
6657
|
-
|
|
6658
|
-
const exportAesKey = async (key, format = 'raw') => {
|
|
6659
|
-
return await subtle.exportKey(format, key)
|
|
6660
|
-
};
|
|
6661
|
-
|
|
6662
|
-
const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
|
|
6663
|
-
name: 'AES-CBC',
|
|
6664
|
-
iv,
|
|
6665
|
-
}, key, uint8Array);
|
|
6666
|
-
|
|
6667
|
-
const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
|
|
6668
|
-
name: 'AES-CBC',
|
|
6669
|
-
iv,
|
|
6670
|
-
}, key, uint8Array);
|
|
6671
|
-
|
|
6672
|
-
const uint8ArrayToHex = uint8Array =>
|
|
6673
|
-
[...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
6674
|
-
|
|
6675
|
-
const arrayBufferToHex = arrayBuffer =>
|
|
6676
|
-
uint8ArrayToHex(new Uint8Array(arrayBuffer));
|
|
6677
|
-
|
|
6678
|
-
const hexToUint8Array = hex =>
|
|
6679
|
-
new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
|
|
6680
|
-
|
|
6681
|
-
const encrypt$1 = async string => {
|
|
6682
|
-
const key = await generateAesKey();
|
|
6683
|
-
const iv = randombytes(16);
|
|
6684
|
-
const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
|
|
6685
|
-
const exported = await exportAesKey(key);
|
|
6686
|
-
return {
|
|
6687
|
-
key: arrayBufferToHex(exported),
|
|
6688
|
-
iv: uint8ArrayToHex(iv),
|
|
6689
|
-
cipher: arrayBufferToHex(ciphertext)
|
|
6690
|
-
}
|
|
6691
|
-
};
|
|
6692
|
-
|
|
6693
|
-
const decrypt$1 = async ({cipher, key, iv}) => {
|
|
6694
|
-
if (!key.type) key = await importAesKey(hexToUint8Array(key));
|
|
6695
|
-
cipher = new Uint8Array(hexToUint8Array(cipher));
|
|
6696
|
-
iv = new Uint8Array(hexToUint8Array(iv));
|
|
6697
|
-
|
|
6698
|
-
const plaintext = await decryptAes(cipher, key, iv);
|
|
6699
|
-
return new TextDecoder().decode(plaintext);
|
|
6605
|
+
const plaintext = await decryptAes(cipher, key, iv);
|
|
6606
|
+
return new TextDecoder().decode(plaintext);
|
|
6700
6607
|
};
|
|
6701
6608
|
|
|
6702
6609
|
var typedArrayConcat = (input, options = {length: undefined, seperator: undefined}) => {
|
|
@@ -20259,7 +20166,7 @@ class Identity {
|
|
|
20259
20166
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20260
20167
|
}
|
|
20261
20168
|
else {
|
|
20262
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
20169
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-ed6cbdf7-eb75dc7a.js');
|
|
20263
20170
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20264
20171
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20265
20172
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20307,8 +20214,11 @@ globalThis.globalSub = globalThis.globalSub || new LittlePubSub();
|
|
|
20307
20214
|
* const peernet = new Peernet();
|
|
20308
20215
|
*/
|
|
20309
20216
|
class Peernet {
|
|
20217
|
+
storePrefix;
|
|
20218
|
+
root;
|
|
20310
20219
|
identity;
|
|
20311
20220
|
stores = [];
|
|
20221
|
+
peerId;
|
|
20312
20222
|
/**
|
|
20313
20223
|
* @type {Object}
|
|
20314
20224
|
* @property {Object} peer Instance of Peer
|
|
@@ -20327,6 +20237,7 @@ class Peernet {
|
|
|
20327
20237
|
#connections = {};
|
|
20328
20238
|
requestProtos = {};
|
|
20329
20239
|
_messageHandler;
|
|
20240
|
+
_peerHandler;
|
|
20330
20241
|
protos;
|
|
20331
20242
|
/**
|
|
20332
20243
|
* @access public
|
|
@@ -20362,6 +20273,7 @@ class Peernet {
|
|
|
20362
20273
|
up: 0,
|
|
20363
20274
|
down: 0,
|
|
20364
20275
|
};
|
|
20276
|
+
// @ts-ignore
|
|
20365
20277
|
return this._init(options, password);
|
|
20366
20278
|
}
|
|
20367
20279
|
get id() {
|
|
@@ -20433,7 +20345,7 @@ class Peernet {
|
|
|
20433
20345
|
this.root = options.root;
|
|
20434
20346
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20435
20347
|
// FolderMessageResponse
|
|
20436
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
20348
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-35d069e1-9413ac70.js');
|
|
20437
20349
|
/**
|
|
20438
20350
|
* proto Object containing protos
|
|
20439
20351
|
* @type {Object}
|
|
@@ -20500,7 +20412,13 @@ class Peernet {
|
|
|
20500
20412
|
else {
|
|
20501
20413
|
process.on('SIGTERM', async () => {
|
|
20502
20414
|
process.stdin.resume();
|
|
20503
|
-
|
|
20415
|
+
try {
|
|
20416
|
+
await this.client.destroy();
|
|
20417
|
+
}
|
|
20418
|
+
catch (error) {
|
|
20419
|
+
// @ts-ignore
|
|
20420
|
+
await this.client.close();
|
|
20421
|
+
}
|
|
20504
20422
|
process.exit();
|
|
20505
20423
|
});
|
|
20506
20424
|
}
|
|
@@ -20512,7 +20430,7 @@ class Peernet {
|
|
|
20512
20430
|
if (this.#starting || this.#started)
|
|
20513
20431
|
return;
|
|
20514
20432
|
this.#starting = true;
|
|
20515
|
-
const importee = await import('./client-
|
|
20433
|
+
const importee = await import('./client-c8558012-c8558012.js');
|
|
20516
20434
|
/**
|
|
20517
20435
|
* @access public
|
|
20518
20436
|
* @type {PeernetClient}
|
|
@@ -20640,21 +20558,13 @@ class Peernet {
|
|
|
20640
20558
|
* @param {String} hash
|
|
20641
20559
|
*/
|
|
20642
20560
|
async providersFor(hash, store) {
|
|
20643
|
-
let providers =
|
|
20561
|
+
let providers = this.dht.providersFor(hash);
|
|
20644
20562
|
// walk the network to find a provider
|
|
20645
|
-
|
|
20563
|
+
let tries = 0;
|
|
20564
|
+
while (!providers && tries < 3 || Object.keys(providers).length === 0 && tries < 3) {
|
|
20565
|
+
tries += 1;
|
|
20646
20566
|
await this.walk(hash);
|
|
20647
|
-
providers =
|
|
20648
|
-
// second walk the network to find a provider
|
|
20649
|
-
if (!providers || providers.length === 0) {
|
|
20650
|
-
await this.walk(hash);
|
|
20651
|
-
providers = await this.dht.providersFor(hash);
|
|
20652
|
-
}
|
|
20653
|
-
// last walk
|
|
20654
|
-
if (!providers || providers.length === 0) {
|
|
20655
|
-
await this.walk(hash);
|
|
20656
|
-
providers = await this.dht.providersFor(hash);
|
|
20657
|
-
}
|
|
20567
|
+
providers = this.dht.providersFor(hash);
|
|
20658
20568
|
}
|
|
20659
20569
|
// undefined if no providers given
|
|
20660
20570
|
return providers;
|
|
@@ -20693,11 +20603,11 @@ class Peernet {
|
|
|
20693
20603
|
}
|
|
20694
20604
|
async requestData(hash, store) {
|
|
20695
20605
|
const providers = await this.providersFor(hash);
|
|
20696
|
-
if (!providers || providers.
|
|
20606
|
+
if (!providers || Object.keys(providers).length === 0)
|
|
20697
20607
|
throw nothingFoundError(hash);
|
|
20698
|
-
debug(`found ${providers.
|
|
20608
|
+
debug(`found ${Object.keys(providers).length} provider(s) for ${hash}`);
|
|
20699
20609
|
// get closest peer on earth
|
|
20700
|
-
const closestPeer =
|
|
20610
|
+
const closestPeer = Object.values(providers)[0];
|
|
20701
20611
|
// get peer instance by id
|
|
20702
20612
|
if (!closestPeer || !closestPeer.id)
|
|
20703
20613
|
return this.requestData(hash, store?.name || store);
|
|
@@ -20712,7 +20622,7 @@ class Peernet {
|
|
|
20712
20622
|
// fallback and try every provider found
|
|
20713
20623
|
const promises = [];
|
|
20714
20624
|
const providers = await this.providersFor(hash, store);
|
|
20715
|
-
for (const provider of providers) {
|
|
20625
|
+
for (const provider of Object.values(providers)) {
|
|
20716
20626
|
const peer = this.#connections[provider.id];
|
|
20717
20627
|
if (peer)
|
|
20718
20628
|
promises.push(peer.request(node.encoded));
|
|
@@ -20898,10 +20808,10 @@ class Peernet {
|
|
|
20898
20808
|
*
|
|
20899
20809
|
* @param {String} hash
|
|
20900
20810
|
* @param {Buffer} data
|
|
20901
|
-
* @param {String}
|
|
20811
|
+
* @param {String} storeName - storeName to access
|
|
20902
20812
|
*/
|
|
20903
|
-
async put(hash, data,
|
|
20904
|
-
store = globalThis[`${
|
|
20813
|
+
async put(hash, data, storeName = 'data') {
|
|
20814
|
+
const store = globalThis[`${storeName}Store`];
|
|
20905
20815
|
return store.put(hash, data);
|
|
20906
20816
|
}
|
|
20907
20817
|
/**
|
|
@@ -20932,9 +20842,9 @@ class Peernet {
|
|
|
20932
20842
|
// TODO: if peer subscribed
|
|
20933
20843
|
}
|
|
20934
20844
|
}
|
|
20935
|
-
createHash(data, name) {
|
|
20936
|
-
|
|
20937
|
-
}
|
|
20845
|
+
// createHash(data, name) {
|
|
20846
|
+
// return new CodeHash(data, {name})
|
|
20847
|
+
// }
|
|
20938
20848
|
/**
|
|
20939
20849
|
*
|
|
20940
20850
|
* @param {String} topic
|
|
@@ -20948,10 +20858,10 @@ class Peernet {
|
|
|
20948
20858
|
console.log('removepeer', peer.id);
|
|
20949
20859
|
const id = peer.id;
|
|
20950
20860
|
await this.client._removePeer(peer);
|
|
20951
|
-
console.log(this.client.peers[id]);
|
|
20952
20861
|
if (this.client.peers[id]) {
|
|
20953
20862
|
for (const connection of Object.keys(this.client.peers[id])) {
|
|
20954
|
-
// if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
20863
|
+
// if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
20864
|
+
// @ts-ignore
|
|
20955
20865
|
if (this.client.peers[id][connection].connected)
|
|
20956
20866
|
return this.client.emit('peerconnect', connection);
|
|
20957
20867
|
}
|
|
@@ -20963,18 +20873,17 @@ class Peernet {
|
|
|
20963
20873
|
}
|
|
20964
20874
|
globalThis.Peernet = Peernet;
|
|
20965
20875
|
|
|
20966
|
-
var networks = {
|
|
20967
|
-
|
|
20968
|
-
|
|
20969
|
-
|
|
20970
|
-
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
20974
|
-
|
|
20975
|
-
|
|
20976
|
-
}
|
|
20977
|
-
}
|
|
20876
|
+
var networks = {
|
|
20877
|
+
leofcoin: {
|
|
20878
|
+
mainnet: {
|
|
20879
|
+
port: 33333,
|
|
20880
|
+
stars: ['wss://mainnet.leofcoin.org'] // todo webrtc and bittorent stars
|
|
20881
|
+
},
|
|
20882
|
+
peach: {
|
|
20883
|
+
port: 44444,
|
|
20884
|
+
stars: ['wss://peach.leofcoin.org'] // todo webrtc and bittorent stars
|
|
20885
|
+
}
|
|
20886
|
+
}
|
|
20978
20887
|
};
|
|
20979
20888
|
|
|
20980
20889
|
// import config from './config/config'
|