@leofcoin/peernet 1.1.50 → 1.1.52
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/browser-store.js +58 -141
- package/exports/browser/client-3221a5d7.js +17580 -0
- package/exports/browser/dht/dht.d.ts +29 -7
- package/exports/browser/identity.d.ts +15 -0
- package/exports/browser/{index-6311966e.js → index-5f552dff.js} +2 -2
- package/exports/browser/{messages-54aa3cad.js → messages-0591b744.js} +2 -2
- package/exports/browser/{peernet-a4156bfd.js → peernet-bc021698.js} +432 -531
- package/exports/browser/peernet.d.ts +25 -32
- package/exports/browser/peernet.js +2 -2
- package/exports/browser/types.d.ts +16 -0
- package/exports/browser/value-4e80eeeb.js +73 -0
- package/exports/peernet.js +35 -34
- package/exports/store.js +117 -193
- package/exports/types/dht/dht.d.ts +29 -7
- package/exports/types/identity.d.ts +15 -0
- package/exports/types/peernet.d.ts +25 -32
- package/exports/types/types.d.ts +16 -0
- package/package.json +2 -2
- package/src/dht/dht.ts +36 -16
- package/src/peernet.ts +48 -61
- package/src/types.ts +28 -0
- package/exports/browser/client-6072af1a.js +0 -41092
- package/exports/browser/value-157ab062.js +0 -64
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyValue } from './value-
|
|
1
|
+
import { K as KeyPath, a as KeyValue } from './value-4e80eeeb.js';
|
|
2
2
|
|
|
3
3
|
if (!globalThis.DEBUG) {
|
|
4
4
|
if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
|
|
@@ -206,16 +206,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
|
206
206
|
const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
|
|
207
207
|
const base32 = base$1(ALPHABET$3);
|
|
208
208
|
const base32Hex = base$1(ALPHABET_HEX$1);
|
|
209
|
-
const decode$
|
|
209
|
+
const decode$8 = base32.decode;
|
|
210
210
|
const decodeHex$2 = base32Hex.decode;
|
|
211
|
-
const encode$
|
|
211
|
+
const encode$7 = base32.encode;
|
|
212
212
|
const encodeHex$2 = base32Hex.encode;
|
|
213
213
|
const isBase32 = (string, hex = false) => {
|
|
214
214
|
try {
|
|
215
215
|
if (hex)
|
|
216
216
|
decodeHex$2(string);
|
|
217
217
|
else
|
|
218
|
-
decode$
|
|
218
|
+
decode$8(string);
|
|
219
219
|
return true;
|
|
220
220
|
}
|
|
221
221
|
catch (e) {
|
|
@@ -226,8 +226,8 @@ const isBase32Hex = (string) => {
|
|
|
226
226
|
return isBase32(string, true);
|
|
227
227
|
};
|
|
228
228
|
var index$8 = {
|
|
229
|
-
encode: encode$
|
|
230
|
-
decode: decode$
|
|
229
|
+
encode: encode$7,
|
|
230
|
+
decode: decode$8,
|
|
231
231
|
encodeHex: encodeHex$2,
|
|
232
232
|
decodeHex: decodeHex$2,
|
|
233
233
|
isBase32,
|
|
@@ -238,13 +238,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
|
238
238
|
var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
|
|
239
239
|
var base58 = base$1(ALPHABET$2);
|
|
240
240
|
var base58Hex = base$1(ALPHABET_HEX);
|
|
241
|
-
var encode$
|
|
242
|
-
var decode$
|
|
241
|
+
var encode$6 = base58.encode;
|
|
242
|
+
var decode$7 = base58.decode;
|
|
243
243
|
var encodeHex$1 = base58Hex.encode;
|
|
244
244
|
var decodeHex$1 = base58Hex.decode;
|
|
245
245
|
var isBase58 = function (string) {
|
|
246
246
|
try {
|
|
247
|
-
decode$
|
|
247
|
+
decode$7(string);
|
|
248
248
|
return true;
|
|
249
249
|
}
|
|
250
250
|
catch (e) {
|
|
@@ -262,7 +262,7 @@ var isBase58Hex = function (string) {
|
|
|
262
262
|
};
|
|
263
263
|
var whatType = function (string) {
|
|
264
264
|
try {
|
|
265
|
-
decode$
|
|
265
|
+
decode$7(string);
|
|
266
266
|
return 'base58';
|
|
267
267
|
}
|
|
268
268
|
catch (e) {
|
|
@@ -275,15 +275,15 @@ var whatType = function (string) {
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
};
|
|
278
|
-
var base58$1 = { encode: encode$
|
|
278
|
+
var base58$1 = { encode: encode$6, decode: decode$7, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
|
|
279
279
|
|
|
280
280
|
const MSB$1 = 0x80;
|
|
281
281
|
const REST$1 = 0x7F;
|
|
282
282
|
const MSBALL = ~REST$1;
|
|
283
283
|
const INT = Math.pow(2, 31);
|
|
284
|
-
const encode$
|
|
284
|
+
const encode$5 = (num, out, offset) => {
|
|
285
285
|
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
286
|
-
encode$
|
|
286
|
+
encode$5.bytes = 0;
|
|
287
287
|
throw new RangeError('Could not encode varint');
|
|
288
288
|
}
|
|
289
289
|
out = out || [];
|
|
@@ -298,13 +298,13 @@ const encode$6 = (num, out, offset) => {
|
|
|
298
298
|
num >>>= 7;
|
|
299
299
|
}
|
|
300
300
|
out[offset] = num | 0;
|
|
301
|
-
encode$
|
|
301
|
+
encode$5.bytes = offset - oldOffset + 1;
|
|
302
302
|
return out;
|
|
303
303
|
};
|
|
304
304
|
|
|
305
305
|
const MSB = 0x80;
|
|
306
306
|
const REST = 0x7F;
|
|
307
|
-
const decode$
|
|
307
|
+
const decode$6 = (buf, offset) => {
|
|
308
308
|
offset = offset || 0;
|
|
309
309
|
const l = buf.length;
|
|
310
310
|
let counter = offset;
|
|
@@ -313,7 +313,7 @@ const decode$7 = (buf, offset) => {
|
|
|
313
313
|
let b;
|
|
314
314
|
do {
|
|
315
315
|
if (counter >= l || shift > 49) {
|
|
316
|
-
decode$
|
|
316
|
+
decode$6.bytes = 0;
|
|
317
317
|
throw new RangeError('Could not decode varint');
|
|
318
318
|
}
|
|
319
319
|
b = buf[counter++];
|
|
@@ -322,7 +322,7 @@ const decode$7 = (buf, offset) => {
|
|
|
322
322
|
: (b & REST) * Math.pow(2, shift);
|
|
323
323
|
shift += 7;
|
|
324
324
|
} while (b >= MSB);
|
|
325
|
-
decode$
|
|
325
|
+
decode$6.bytes = counter - offset;
|
|
326
326
|
return result;
|
|
327
327
|
};
|
|
328
328
|
|
|
@@ -347,8 +347,8 @@ var encodingLength = (value) => (value < N1 ? 1
|
|
|
347
347
|
: 10);
|
|
348
348
|
|
|
349
349
|
var index$7 = {
|
|
350
|
-
encode: encode$
|
|
351
|
-
decode: decode$
|
|
350
|
+
encode: encode$5,
|
|
351
|
+
decode: decode$6,
|
|
352
352
|
encodingLength
|
|
353
353
|
};
|
|
354
354
|
|
|
@@ -398,11 +398,11 @@ var index$5 = (typedArray, prefix) => {
|
|
|
398
398
|
|
|
399
399
|
const ALPHABET$1 = '0123456789ABCDEF';
|
|
400
400
|
const base16 = base$1(ALPHABET$1);
|
|
401
|
-
const decode$
|
|
402
|
-
const encode$
|
|
401
|
+
const decode$5 = base16.decode;
|
|
402
|
+
const encode$4 = base16.encode;
|
|
403
403
|
const isBase16 = (string) => {
|
|
404
404
|
try {
|
|
405
|
-
decode$
|
|
405
|
+
decode$5(string);
|
|
406
406
|
return true;
|
|
407
407
|
}
|
|
408
408
|
catch (e) {
|
|
@@ -410,18 +410,18 @@ const isBase16 = (string) => {
|
|
|
410
410
|
}
|
|
411
411
|
};
|
|
412
412
|
var index$4 = {
|
|
413
|
-
encode: encode$
|
|
414
|
-
decode: decode$
|
|
413
|
+
encode: encode$4,
|
|
414
|
+
decode: decode$5,
|
|
415
415
|
isBase16
|
|
416
416
|
};
|
|
417
417
|
|
|
418
418
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
419
419
|
const base64 = base$1(ALPHABET);
|
|
420
|
-
const decode$
|
|
421
|
-
const encode$
|
|
420
|
+
const decode$4 = base64.decode;
|
|
421
|
+
const encode$3 = base64.encode;
|
|
422
422
|
const isBase64 = (string) => {
|
|
423
423
|
try {
|
|
424
|
-
decode$
|
|
424
|
+
decode$4(string);
|
|
425
425
|
return true;
|
|
426
426
|
}
|
|
427
427
|
catch (e) {
|
|
@@ -429,221 +429,211 @@ const isBase64 = (string) => {
|
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
var index$3 = {
|
|
432
|
-
encode: encode$
|
|
433
|
-
decode: decode$
|
|
432
|
+
encode: encode$3,
|
|
433
|
+
decode: decode$4,
|
|
434
434
|
isBase64
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Returns a
|
|
459
|
-
* @param
|
|
460
|
-
* @returns
|
|
461
|
-
*/
|
|
462
|
-
const
|
|
463
|
-
/**
|
|
464
|
-
* Returns a
|
|
465
|
-
* @param
|
|
466
|
-
* @returns
|
|
467
|
-
*/
|
|
468
|
-
const
|
|
469
|
-
/**
|
|
470
|
-
* Returns a
|
|
471
|
-
* @param
|
|
472
|
-
* @returns
|
|
473
|
-
*/
|
|
474
|
-
const
|
|
475
|
-
/**
|
|
476
|
-
*
|
|
477
|
-
* @param
|
|
478
|
-
* @returns
|
|
479
|
-
*/
|
|
480
|
-
const
|
|
481
|
-
/**
|
|
482
|
-
*
|
|
483
|
-
* @param
|
|
484
|
-
* @returns
|
|
485
|
-
*/
|
|
486
|
-
const
|
|
487
|
-
/**
|
|
488
|
-
*
|
|
489
|
-
* @param
|
|
490
|
-
* @returns
|
|
491
|
-
*/
|
|
492
|
-
const
|
|
493
|
-
/**
|
|
494
|
-
*
|
|
495
|
-
* @param
|
|
496
|
-
* @returns Uint8Array
|
|
497
|
-
*/
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
*
|
|
569
|
-
* @
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
* uint8Array
|
|
576
|
-
* @
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
*
|
|
593
|
-
* @
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
toUintArrayString,
|
|
638
|
-
toBase64,
|
|
639
|
-
fromBase64,
|
|
640
|
-
toBase58,
|
|
641
|
-
fromBase58,
|
|
642
|
-
toBase32,
|
|
643
|
-
fromBase32,
|
|
644
|
-
toBase16,
|
|
645
|
-
fromBase16,
|
|
646
|
-
FormatInterface: FormatInterface$2
|
|
437
|
+
/**
|
|
438
|
+
* Returns a hex string as Binary string
|
|
439
|
+
* @param string string to encode to binary
|
|
440
|
+
* @returns binaryString
|
|
441
|
+
*/
|
|
442
|
+
const hexToBinary = (hex) => (parseInt(hex, 16).toString(2)).padStart(8, '0');
|
|
443
|
+
const isTypedArrayCompatible = (possibleUint8Array) => {
|
|
444
|
+
if (typeof possibleUint8Array === 'string') {
|
|
445
|
+
possibleUint8Array = possibleUint8Array.split(',').map(number => Number(number));
|
|
446
|
+
for (const number of possibleUint8Array) {
|
|
447
|
+
if (isNaN(number))
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
for (const number of possibleUint8Array) {
|
|
452
|
+
if (isNaN(number))
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
return true;
|
|
456
|
+
};
|
|
457
|
+
/**
|
|
458
|
+
* Returns a String as Uint8Array
|
|
459
|
+
* @param string string to encode to Uint8Array
|
|
460
|
+
* @returns Uint8Array
|
|
461
|
+
*/
|
|
462
|
+
const fromString$1 = (string) => new TextEncoder().encode(string);
|
|
463
|
+
/**
|
|
464
|
+
* Returns a Uint8Array as String
|
|
465
|
+
* @param uint8Array Uint8Array to encode to String
|
|
466
|
+
* @returns String
|
|
467
|
+
*/
|
|
468
|
+
const toString$1 = (uint8Array) => new TextDecoder().decode(uint8Array);
|
|
469
|
+
/**
|
|
470
|
+
* Returns a String as Uint8Array
|
|
471
|
+
* @param string string to encode to Uint8Array
|
|
472
|
+
* @returns Uint8Array
|
|
473
|
+
*/
|
|
474
|
+
const fromUintArrayString = (string) => Uint8Array.from(string.split(',').map(string => Number(string)));
|
|
475
|
+
/**
|
|
476
|
+
* Returns a Uint8Array as String
|
|
477
|
+
* @param uint8Array Uint8Array to encode to String
|
|
478
|
+
* @returns String
|
|
479
|
+
*/
|
|
480
|
+
const toUintArrayString = (uint8Array) => uint8Array.toString();
|
|
481
|
+
/**
|
|
482
|
+
* hexString -> uint8Array
|
|
483
|
+
* @param string hex encoded string
|
|
484
|
+
* @returns UintArray
|
|
485
|
+
*/
|
|
486
|
+
const fromHex = (string) => Uint8Array.from(string.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
487
|
+
/**
|
|
488
|
+
* uint8Array -> hexString
|
|
489
|
+
* @param bytes number[]
|
|
490
|
+
* @returns hexString
|
|
491
|
+
*/
|
|
492
|
+
const toHex$2 = (bytes) => bytes.reduce((string, byte) => string + byte.toString(16).padStart(2, '0'), '');
|
|
493
|
+
/**
|
|
494
|
+
* number[] -> Uint8Array
|
|
495
|
+
* @param array number[]
|
|
496
|
+
* @returns Uint8Array
|
|
497
|
+
*/
|
|
498
|
+
const fromArrayLike = (array) => Uint8Array.from(array);
|
|
499
|
+
/**
|
|
500
|
+
* Uint8Array -> number[]
|
|
501
|
+
* @param uint8Array Uint8Array
|
|
502
|
+
* @returns Uint8Array
|
|
503
|
+
*/
|
|
504
|
+
const toArrayLike = (uint8Array) => [...uint8Array.values()];
|
|
505
|
+
/**
|
|
506
|
+
* object -> Uint8Array
|
|
507
|
+
* @param object any
|
|
508
|
+
* @returns Uint8Array
|
|
509
|
+
*/
|
|
510
|
+
const fromObject = (object) => new TextEncoder().encode(JSON.stringify(object));
|
|
511
|
+
/**
|
|
512
|
+
* Uint8Array -> Object
|
|
513
|
+
* @param uint8Array Uint8Array
|
|
514
|
+
* @returns Object
|
|
515
|
+
*/
|
|
516
|
+
const toObject = (uint8Array) => JSON.parse(new TextDecoder().decode(uint8Array));
|
|
517
|
+
const fromBinary = (string) => fromHex(parseInt(string, 2).toString(16).toUpperCase());
|
|
518
|
+
const toBinary = (uint8Array) => hexToBinary(toHex$2(uint8Array));
|
|
519
|
+
const toBase64 = (uint8Array) => index$3.encode(uint8Array);
|
|
520
|
+
const fromBase64 = (string) => index$3.decode(string);
|
|
521
|
+
const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
|
|
522
|
+
const fromBase58 = (string) => base58$1.decode(string);
|
|
523
|
+
const toBase32 = (uint8Array) => index$8.encode(uint8Array);
|
|
524
|
+
const fromBase32 = (string) => index$8.decode(string);
|
|
525
|
+
const toBase16 = (uint8Array) => index$4.encode(uint8Array);
|
|
526
|
+
const fromBase16 = (string) => index$4.decode(string);
|
|
527
|
+
let FormatInterface$2 = class FormatInterface {
|
|
528
|
+
encoded;
|
|
529
|
+
decoded;
|
|
530
|
+
constructor(input) {
|
|
531
|
+
if (input) {
|
|
532
|
+
if (index$4.isBase16(input))
|
|
533
|
+
this.encoded = this.fromBase16(input);
|
|
534
|
+
else if (index$8.isBase32(input))
|
|
535
|
+
this.encoded = this.fromBase32(input);
|
|
536
|
+
else if (base58$1.isBase58(input))
|
|
537
|
+
this.encoded = this.fromBase58(input);
|
|
538
|
+
else if (index$3.isBase64(input))
|
|
539
|
+
this.encoded = this.fromBase64(input);
|
|
540
|
+
else if (typeof input === 'string') {
|
|
541
|
+
let isCompatible = isTypedArrayCompatible(input);
|
|
542
|
+
if (isCompatible)
|
|
543
|
+
this.encoded = fromUintArrayString(input);
|
|
544
|
+
else
|
|
545
|
+
this.encoded = this.fromString(input); // normal string
|
|
546
|
+
}
|
|
547
|
+
else if (typeof input === 'object')
|
|
548
|
+
this.encoded = this.fromObject(input);
|
|
549
|
+
else if (input instanceof Uint8Array)
|
|
550
|
+
this.encoded = input;
|
|
551
|
+
else if (Array.isArray(input) && isTypedArrayCompatible(input))
|
|
552
|
+
this.encoded = this.fromArrayLike(input);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Returns a String as Uint8Array
|
|
557
|
+
* @param string string to encode to Uint8Array
|
|
558
|
+
* @returns Uint8Array
|
|
559
|
+
*/
|
|
560
|
+
fromString = (string) => this.encoded = fromString$1(string);
|
|
561
|
+
/**
|
|
562
|
+
* Returns a Uint8Array as String
|
|
563
|
+
* @param uint8Array Uint8Array to encode to String
|
|
564
|
+
* @returns String
|
|
565
|
+
*/
|
|
566
|
+
toString = (uint8Array) => this.decoded = toString$1(uint8Array);
|
|
567
|
+
/**
|
|
568
|
+
* Returns a String as Uint8Array
|
|
569
|
+
* @param string string to encode to Uint8Array
|
|
570
|
+
* @returns Uint8Array
|
|
571
|
+
*/
|
|
572
|
+
fromUintArrayString = (string) => this.encoded = fromUintArrayString(string);
|
|
573
|
+
/**
|
|
574
|
+
* Returns a Uint8Array as String
|
|
575
|
+
* @param uint8Array Uint8Array to encode to String
|
|
576
|
+
* @returns String
|
|
577
|
+
*/
|
|
578
|
+
toUintArrayString = (uint8Array) => this.decoded = uint8Array.toString();
|
|
579
|
+
/**
|
|
580
|
+
* hexString -> uint8Array
|
|
581
|
+
* @param string hex encoded string
|
|
582
|
+
* @returns UintArray
|
|
583
|
+
*/
|
|
584
|
+
fromHex = (string) => this.encoded = fromHex(string);
|
|
585
|
+
/**
|
|
586
|
+
* uint8Array -> hexString
|
|
587
|
+
* @param bytes ArrayLike
|
|
588
|
+
* @returns hexString
|
|
589
|
+
*/
|
|
590
|
+
toHex = (arrayLike) => this.decoded = toHex$2(arrayLike);
|
|
591
|
+
/**
|
|
592
|
+
* number[] -> Uint8Array
|
|
593
|
+
* @param array number[]
|
|
594
|
+
* @returns Uint8Array
|
|
595
|
+
*/
|
|
596
|
+
fromArrayLike = (array) => this.encoded = Uint8Array.from(array);
|
|
597
|
+
/**
|
|
598
|
+
* Uint8Array -> number[]
|
|
599
|
+
* @param uint8Array Uint8Array
|
|
600
|
+
* @returns Uint8Array
|
|
601
|
+
*/
|
|
602
|
+
toArrayLike = (uint8Array) => this.decoded = [...uint8Array.values()];
|
|
603
|
+
fromObject = (object) => this.encoded = fromObject(object);
|
|
604
|
+
toBinary = (uint8Array) => this.decoded = hexToBinary(toHex$2(uint8Array));
|
|
605
|
+
fromBinary = (binary) => this.encoded = fromBinary(binary);
|
|
606
|
+
toObject = (uint8Array) => this.decoded = toObject(uint8Array);
|
|
607
|
+
toBase64 = (uint8Array) => this.decoded = index$3.encode(uint8Array);
|
|
608
|
+
fromBase64 = (string) => this.encoded = index$3.decode(string);
|
|
609
|
+
toBase58 = (uint8Array) => this.decoded = base58$1.encode(uint8Array);
|
|
610
|
+
fromBase58 = (string) => this.encoded = base58$1.decode(string);
|
|
611
|
+
toBase32 = (uint8Array) => this.decoded = index$8.encode(uint8Array);
|
|
612
|
+
fromBase32 = (string) => this.encoded = index$8.decode(string);
|
|
613
|
+
toBase16 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
|
|
614
|
+
fromBase16 = (string) => this.decoded = index$4.decode(string);
|
|
615
|
+
};
|
|
616
|
+
var index$2 = {
|
|
617
|
+
fromString: fromString$1,
|
|
618
|
+
toString: toString$1,
|
|
619
|
+
fromHex,
|
|
620
|
+
toHex: toHex$2,
|
|
621
|
+
fromArrayLike,
|
|
622
|
+
toArrayLike,
|
|
623
|
+
fromUintArrayString,
|
|
624
|
+
toUintArrayString,
|
|
625
|
+
toObject,
|
|
626
|
+
toBinary,
|
|
627
|
+
fromBinary,
|
|
628
|
+
toBase64,
|
|
629
|
+
fromBase64,
|
|
630
|
+
toBase58,
|
|
631
|
+
fromBase58,
|
|
632
|
+
toBase32,
|
|
633
|
+
fromBase32,
|
|
634
|
+
toBase16,
|
|
635
|
+
fromBase16,
|
|
636
|
+
FormatInterface: FormatInterface$2
|
|
647
637
|
};
|
|
648
638
|
|
|
649
639
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -4816,7 +4806,7 @@ const toType = (data) => {
|
|
|
4816
4806
|
return new TextEncoder().encode(data.toString());
|
|
4817
4807
|
throw new Error(`unsuported type ${typeof data || data}`);
|
|
4818
4808
|
};
|
|
4819
|
-
const encode$
|
|
4809
|
+
const encode$2 = (proto, input, compress) => {
|
|
4820
4810
|
const keys = Object.keys(proto);
|
|
4821
4811
|
const values = Object.values(proto);
|
|
4822
4812
|
const set = [];
|
|
@@ -4833,7 +4823,7 @@ const encode$3 = (proto, input, compress) => {
|
|
|
4833
4823
|
}
|
|
4834
4824
|
return index$6(set);
|
|
4835
4825
|
};
|
|
4836
|
-
const decode$
|
|
4826
|
+
const decode$3 = (proto, uint8Array, compressed) => {
|
|
4837
4827
|
let deconcated = index$5(uint8Array);
|
|
4838
4828
|
const output = {};
|
|
4839
4829
|
const keys = Object.keys(proto);
|
|
@@ -4864,8 +4854,8 @@ const decode$4 = (proto, uint8Array, compressed) => {
|
|
|
4864
4854
|
return output;
|
|
4865
4855
|
};
|
|
4866
4856
|
var index$1 = {
|
|
4867
|
-
encode: encode$
|
|
4868
|
-
decode: decode$
|
|
4857
|
+
encode: encode$2,
|
|
4858
|
+
decode: decode$3
|
|
4869
4859
|
};
|
|
4870
4860
|
|
|
4871
4861
|
/*!
|
|
@@ -6235,8 +6225,7 @@ class DhtEarth {
|
|
|
6235
6225
|
if (!fetchedCoordinates[address]) {
|
|
6236
6226
|
const request = `https://whereis.leofcoin.org/?ip=${address}`;
|
|
6237
6227
|
let response = await fetch(request);
|
|
6238
|
-
|
|
6239
|
-
const { lat, lon } = response;
|
|
6228
|
+
const { lat, lon } = await response.json();
|
|
6240
6229
|
fetchedCoordinates[address] = { latitude: lat, longitude: lon };
|
|
6241
6230
|
}
|
|
6242
6231
|
return fetchedCoordinates[address];
|
|
@@ -6260,6 +6249,7 @@ class DhtEarth {
|
|
|
6260
6249
|
else
|
|
6261
6250
|
all.push(this.getDistance(peerLoc, provider));
|
|
6262
6251
|
}
|
|
6252
|
+
// todo queue
|
|
6263
6253
|
all = await Promise.all(all);
|
|
6264
6254
|
all = all.sort((previous, current) => previous.distance - current.distance);
|
|
6265
6255
|
return all[0].provider;
|
|
@@ -6273,22 +6263,20 @@ class DhtEarth {
|
|
|
6273
6263
|
providers = this.providerMap.get(hash);
|
|
6274
6264
|
return providers;
|
|
6275
6265
|
}
|
|
6276
|
-
addProvider(
|
|
6277
|
-
let providers =
|
|
6266
|
+
addProvider(provider, hash) {
|
|
6267
|
+
let providers = {};
|
|
6278
6268
|
if (this.providerMap.has(hash)) {
|
|
6279
6269
|
providers = this.providerMap.get(hash);
|
|
6280
6270
|
}
|
|
6281
|
-
providers.
|
|
6271
|
+
providers[provider.address] = provider;
|
|
6282
6272
|
this.providerMap.set(hash, providers);
|
|
6283
6273
|
}
|
|
6284
6274
|
removeProvider(address, hash) {
|
|
6285
|
-
let deleted = undefined;
|
|
6286
6275
|
if (this.providerMap.has(hash)) {
|
|
6287
6276
|
const providers = this.providerMap.get(hash);
|
|
6288
|
-
|
|
6289
|
-
|
|
6277
|
+
delete providers[address];
|
|
6278
|
+
this.providerMap.set(hash, providers);
|
|
6290
6279
|
}
|
|
6291
|
-
return deleted;
|
|
6292
6280
|
}
|
|
6293
6281
|
}
|
|
6294
6282
|
|
|
@@ -6344,278 +6332,188 @@ const nothingFoundError = (hash) => {
|
|
|
6344
6332
|
return new Error(`nothing found for ${hash}`)
|
|
6345
6333
|
};
|
|
6346
6334
|
|
|
6347
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
6348
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
6349
|
-
|
|
6350
|
-
// export const encodings = {
|
|
6351
|
-
// base58,
|
|
6352
|
-
// base32
|
|
6353
|
-
// }
|
|
6354
|
-
|
|
6355
|
-
const encode$2 = (string, encoding = 'utf-8') => {
|
|
6356
|
-
if (typeof string === 'string') {
|
|
6357
|
-
let encoded;
|
|
6358
|
-
|
|
6359
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
6360
|
-
encoded = new TextEncoder().encode(string);
|
|
6361
|
-
return encoded
|
|
6362
|
-
}
|
|
6363
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
6364
|
-
};
|
|
6365
|
-
|
|
6366
|
-
const decode$3 = (uint8Array, encoding) => {
|
|
6367
|
-
if (uint8Array instanceof Uint8Array) {
|
|
6368
|
-
let decoded;
|
|
6369
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
6370
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
6371
|
-
|
|
6372
|
-
return decoded
|
|
6373
|
-
}
|
|
6374
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
6375
|
-
};
|
|
6376
|
-
|
|
6377
|
-
const pathSepS = '/';
|
|
6378
|
-
class KeyPath {
|
|
6379
|
-
|
|
6380
|
-
/**
|
|
6381
|
-
* @param {string | Uint8Array} input
|
|
6382
|
-
*/
|
|
6383
|
-
constructor(input) {
|
|
6384
|
-
if (typeof input === 'string') {
|
|
6385
|
-
this.uint8Array = encode$2(input);
|
|
6386
|
-
} else if (input instanceof Uint8Array) {
|
|
6387
|
-
this.uint8Array = input;
|
|
6388
|
-
} else if (input instanceof KeyPath) {
|
|
6389
|
-
this.uint8Array = input.uint8Array;
|
|
6390
|
-
} else {
|
|
6391
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
6392
|
-
}
|
|
6393
|
-
}
|
|
6394
|
-
|
|
6395
|
-
isKeyPath() {
|
|
6396
|
-
return true
|
|
6397
|
-
}
|
|
6398
|
-
|
|
6399
|
-
/**
|
|
6400
|
-
* Convert to the string representation
|
|
6401
|
-
*
|
|
6402
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
6403
|
-
* @returns {string}
|
|
6404
|
-
*/
|
|
6405
|
-
toString(encoding = 'hex') {
|
|
6406
|
-
return decode$3(this.uint8Array)
|
|
6407
|
-
}
|
|
6408
|
-
|
|
6409
|
-
/**
|
|
6410
|
-
* Returns the `list` representation of this path.
|
|
6411
|
-
*
|
|
6412
|
-
* @returns string[]
|
|
6413
|
-
*
|
|
6414
|
-
* @example
|
|
6415
|
-
* ```js
|
|
6416
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
6417
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
6418
|
-
* ```
|
|
6419
|
-
*/
|
|
6420
|
-
list() {
|
|
6421
|
-
return this.toString().split(pathSepS).slice(1)
|
|
6422
|
-
}
|
|
6423
|
-
|
|
6424
|
-
}
|
|
6425
|
-
|
|
6426
6335
|
let LeofcoinStorage$1 = class LeofcoinStorage {
|
|
6336
|
+
name;
|
|
6337
|
+
root;
|
|
6338
|
+
db;
|
|
6339
|
+
constructor(name = 'storage', root = '.leofcoin') {
|
|
6340
|
+
this.name = name;
|
|
6341
|
+
this.root = root;
|
|
6342
|
+
}
|
|
6343
|
+
async init(name, root) {
|
|
6344
|
+
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6345
|
+
const Store = importee.default;
|
|
6346
|
+
this.db = new Store(this.name, this.root);
|
|
6347
|
+
}
|
|
6348
|
+
async get(key) {
|
|
6349
|
+
if (typeof key === 'object')
|
|
6350
|
+
return this.many('get', key);
|
|
6351
|
+
return this.db.get(new KeyPath(key));
|
|
6352
|
+
}
|
|
6353
|
+
/**
|
|
6354
|
+
*
|
|
6355
|
+
* @param {*} key
|
|
6356
|
+
* @param {*} value
|
|
6357
|
+
* @returns Promise
|
|
6358
|
+
*/
|
|
6359
|
+
put(key, value) {
|
|
6360
|
+
if (typeof key === 'object')
|
|
6361
|
+
return this.many('put', key);
|
|
6362
|
+
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6363
|
+
}
|
|
6364
|
+
async has(key) {
|
|
6365
|
+
if (typeof key === 'object')
|
|
6366
|
+
return this.many('has', key);
|
|
6367
|
+
try {
|
|
6368
|
+
const has = await this.db.get(new KeyPath(key));
|
|
6369
|
+
return Boolean(has);
|
|
6370
|
+
}
|
|
6371
|
+
catch (e) {
|
|
6372
|
+
return false;
|
|
6373
|
+
}
|
|
6374
|
+
}
|
|
6375
|
+
async delete(key) {
|
|
6376
|
+
return this.db.delete(new KeyPath(key));
|
|
6377
|
+
}
|
|
6378
|
+
keys(limit = -1) {
|
|
6379
|
+
return this.db.keys(limit);
|
|
6380
|
+
}
|
|
6381
|
+
async values(limit = -1) {
|
|
6382
|
+
return this.db.values(limit);
|
|
6383
|
+
}
|
|
6384
|
+
async many(type, _value) {
|
|
6385
|
+
const jobs = [];
|
|
6386
|
+
for (const key of Object.keys(_value)) {
|
|
6387
|
+
jobs.push(this[type](key, _value[key]));
|
|
6388
|
+
}
|
|
6389
|
+
return Promise.all(jobs);
|
|
6390
|
+
}
|
|
6391
|
+
async length() {
|
|
6392
|
+
const keys = await this.keys();
|
|
6393
|
+
return keys.length;
|
|
6394
|
+
}
|
|
6395
|
+
async size() {
|
|
6396
|
+
let size = 0;
|
|
6397
|
+
const query = await this.db.iterate();
|
|
6398
|
+
for await (const item of query) {
|
|
6399
|
+
size += item.value ? item.value.length : item[1].length;
|
|
6400
|
+
}
|
|
6401
|
+
return size;
|
|
6402
|
+
}
|
|
6403
|
+
async clear() {
|
|
6404
|
+
return this.db.clear();
|
|
6405
|
+
}
|
|
6406
|
+
async iterate() {
|
|
6407
|
+
return this.db.iterate();
|
|
6408
|
+
}
|
|
6409
|
+
};
|
|
6427
6410
|
|
|
6428
|
-
|
|
6429
|
-
this.name = name;
|
|
6430
|
-
this.root = root;
|
|
6431
|
-
}
|
|
6411
|
+
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
6432
6412
|
|
|
6433
|
-
|
|
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
|
-
}
|
|
6413
|
+
const {subtle} = crypto;
|
|
6438
6414
|
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
*/
|
|
6450
|
-
put(key, value) {
|
|
6451
|
-
if (typeof key === 'object') return this.many('put', key);
|
|
6452
|
-
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6453
|
-
}
|
|
6415
|
+
/**
|
|
6416
|
+
* ```js
|
|
6417
|
+
* const {createHash} = await import('@leofcoin/crypto')
|
|
6418
|
+
* createHash(data, algorithm)
|
|
6419
|
+
* ```
|
|
6420
|
+
* @param {Uint8Array} data
|
|
6421
|
+
* @param {string} algorithm
|
|
6422
|
+
* @returns Uint8Array
|
|
6423
|
+
*/
|
|
6424
|
+
const createHash = (data, algorithm = 'SHA-512') => subtle.digest(algorithm, data);
|
|
6454
6425
|
|
|
6455
|
-
|
|
6456
|
-
|
|
6426
|
+
/**
|
|
6427
|
+
* Hashes the created hash again
|
|
6428
|
+
* ```js
|
|
6429
|
+
* const {createDoubleHash} = await import('@leofcoin/crypto')
|
|
6430
|
+
* createDoubleHash(data, algorithm)
|
|
6431
|
+
* ```
|
|
6432
|
+
* @param {Uint8Array} data
|
|
6433
|
+
* @param {string} algorithm
|
|
6434
|
+
* @returns Uint8Array
|
|
6435
|
+
*/
|
|
6436
|
+
const createDoubleHash = async (data, algorithm = 'SHA-512') =>
|
|
6437
|
+
subtle.digest(algorithm, await subtle.digest(algorithm, data));
|
|
6457
6438
|
|
|
6458
|
-
|
|
6459
|
-
|
|
6439
|
+
const generatePbkdf2 = async (password) => {
|
|
6440
|
+
return subtle.importKey(
|
|
6441
|
+
'raw',
|
|
6442
|
+
password,
|
|
6443
|
+
'PBKDF2',
|
|
6444
|
+
false,
|
|
6445
|
+
['deriveBits']
|
|
6446
|
+
)
|
|
6447
|
+
};
|
|
6460
6448
|
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6449
|
+
const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SHA-512') => {
|
|
6450
|
+
const key = await generatePbkdf2(password);
|
|
6451
|
+
return subtle.deriveBits({
|
|
6452
|
+
name: 'PBKDF2',
|
|
6453
|
+
hash,
|
|
6454
|
+
salt,
|
|
6455
|
+
iterations,
|
|
6456
|
+
}, key, length)
|
|
6457
|
+
};
|
|
6466
6458
|
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6459
|
+
const generateAesKey = async (length = 256) => {
|
|
6460
|
+
const key = await subtle.generateKey({
|
|
6461
|
+
name: 'AES-CBC',
|
|
6462
|
+
length
|
|
6463
|
+
}, true, ['encrypt', 'decrypt']);
|
|
6470
6464
|
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
}
|
|
6465
|
+
return key;
|
|
6466
|
+
};
|
|
6474
6467
|
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6468
|
+
const importAesKey = async (exported, format = 'raw', length = 256) => {
|
|
6469
|
+
return await subtle.importKey(format, exported, {
|
|
6470
|
+
name: 'AES-CBC',
|
|
6471
|
+
length
|
|
6472
|
+
}, true, ['encrypt', 'decrypt'])
|
|
6473
|
+
};
|
|
6478
6474
|
|
|
6479
|
-
|
|
6480
|
-
|
|
6475
|
+
const exportAesKey = async (key, format = 'raw') => {
|
|
6476
|
+
return await subtle.exportKey(format, key)
|
|
6477
|
+
};
|
|
6481
6478
|
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6479
|
+
const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
|
|
6480
|
+
name: 'AES-CBC',
|
|
6481
|
+
iv,
|
|
6482
|
+
}, key, uint8Array);
|
|
6485
6483
|
|
|
6486
|
-
|
|
6487
|
-
|
|
6484
|
+
const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
|
|
6485
|
+
name: 'AES-CBC',
|
|
6486
|
+
iv,
|
|
6487
|
+
}, key, uint8Array);
|
|
6488
6488
|
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
return keys.length
|
|
6492
|
-
}
|
|
6489
|
+
const uint8ArrayToHex = uint8Array =>
|
|
6490
|
+
[...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
6493
6491
|
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
const query = await this.db.iterate();
|
|
6497
|
-
for await (const item of query) {
|
|
6498
|
-
size += item.value ? item.value.length : item[1].length;
|
|
6499
|
-
}
|
|
6500
|
-
return size
|
|
6501
|
-
}
|
|
6492
|
+
const arrayBufferToHex = arrayBuffer =>
|
|
6493
|
+
uint8ArrayToHex(new Uint8Array(arrayBuffer));
|
|
6502
6494
|
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
}
|
|
6495
|
+
const hexToUint8Array = hex =>
|
|
6496
|
+
new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
|
|
6506
6497
|
|
|
6507
|
-
|
|
6508
|
-
|
|
6498
|
+
const encrypt$1 = async string => {
|
|
6499
|
+
const key = await generateAesKey();
|
|
6500
|
+
const iv = randombytes(16);
|
|
6501
|
+
const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
|
|
6502
|
+
const exported = await exportAesKey(key);
|
|
6503
|
+
return {
|
|
6504
|
+
key: arrayBufferToHex(exported),
|
|
6505
|
+
iv: uint8ArrayToHex(iv),
|
|
6506
|
+
cipher: arrayBufferToHex(ciphertext)
|
|
6509
6507
|
}
|
|
6510
|
-
|
|
6511
6508
|
};
|
|
6512
6509
|
|
|
6513
|
-
const
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
/**
|
|
6518
|
-
* ```js
|
|
6519
|
-
* const {createHash} = await import('@leofcoin/crypto')
|
|
6520
|
-
* createHash(data, algorithm)
|
|
6521
|
-
* ```
|
|
6522
|
-
* @param {Uint8Array} data
|
|
6523
|
-
* @param {string} algorithm
|
|
6524
|
-
* @returns Uint8Array
|
|
6525
|
-
*/
|
|
6526
|
-
const createHash = (data, algorithm = 'SHA-512') => subtle.digest(algorithm, data);
|
|
6510
|
+
const decrypt$1 = async ({cipher, key, iv}) => {
|
|
6511
|
+
if (!key.type) key = await importAesKey(hexToUint8Array(key));
|
|
6512
|
+
cipher = new Uint8Array(hexToUint8Array(cipher));
|
|
6513
|
+
iv = new Uint8Array(hexToUint8Array(iv));
|
|
6527
6514
|
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
* ```js
|
|
6531
|
-
* const {createDoubleHash} = await import('@leofcoin/crypto')
|
|
6532
|
-
* createDoubleHash(data, algorithm)
|
|
6533
|
-
* ```
|
|
6534
|
-
* @param {Uint8Array} data
|
|
6535
|
-
* @param {string} algorithm
|
|
6536
|
-
* @returns Uint8Array
|
|
6537
|
-
*/
|
|
6538
|
-
const createDoubleHash = async (data, algorithm = 'SHA-512') =>
|
|
6539
|
-
subtle.digest(algorithm, await subtle.digest(algorithm, data));
|
|
6540
|
-
|
|
6541
|
-
const generatePbkdf2 = async (password) => {
|
|
6542
|
-
return subtle.importKey(
|
|
6543
|
-
'raw',
|
|
6544
|
-
password,
|
|
6545
|
-
'PBKDF2',
|
|
6546
|
-
false,
|
|
6547
|
-
['deriveBits']
|
|
6548
|
-
)
|
|
6549
|
-
};
|
|
6550
|
-
|
|
6551
|
-
const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SHA-512') => {
|
|
6552
|
-
const key = await generatePbkdf2(password);
|
|
6553
|
-
return subtle.deriveBits({
|
|
6554
|
-
name: 'PBKDF2',
|
|
6555
|
-
hash,
|
|
6556
|
-
salt,
|
|
6557
|
-
iterations,
|
|
6558
|
-
}, key, length)
|
|
6559
|
-
};
|
|
6560
|
-
|
|
6561
|
-
const generateAesKey = async (length = 256) => {
|
|
6562
|
-
const key = await subtle.generateKey({
|
|
6563
|
-
name: 'AES-CBC',
|
|
6564
|
-
length
|
|
6565
|
-
}, true, ['encrypt', 'decrypt']);
|
|
6566
|
-
|
|
6567
|
-
return key;
|
|
6568
|
-
};
|
|
6569
|
-
|
|
6570
|
-
const importAesKey = async (exported, format = 'raw', length = 256) => {
|
|
6571
|
-
return await subtle.importKey(format, exported, {
|
|
6572
|
-
name: 'AES-CBC',
|
|
6573
|
-
length
|
|
6574
|
-
}, true, ['encrypt', 'decrypt'])
|
|
6575
|
-
};
|
|
6576
|
-
|
|
6577
|
-
const exportAesKey = async (key, format = 'raw') => {
|
|
6578
|
-
return await subtle.exportKey(format, key)
|
|
6579
|
-
};
|
|
6580
|
-
|
|
6581
|
-
const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
|
|
6582
|
-
name: 'AES-CBC',
|
|
6583
|
-
iv,
|
|
6584
|
-
}, key, uint8Array);
|
|
6585
|
-
|
|
6586
|
-
const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
|
|
6587
|
-
name: 'AES-CBC',
|
|
6588
|
-
iv,
|
|
6589
|
-
}, key, uint8Array);
|
|
6590
|
-
|
|
6591
|
-
const uint8ArrayToHex = uint8Array =>
|
|
6592
|
-
[...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
6593
|
-
|
|
6594
|
-
const arrayBufferToHex = arrayBuffer =>
|
|
6595
|
-
uint8ArrayToHex(new Uint8Array(arrayBuffer));
|
|
6596
|
-
|
|
6597
|
-
const hexToUint8Array = hex =>
|
|
6598
|
-
new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
|
|
6599
|
-
|
|
6600
|
-
const encrypt$1 = async string => {
|
|
6601
|
-
const key = await generateAesKey();
|
|
6602
|
-
const iv = randombytes(16);
|
|
6603
|
-
const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
|
|
6604
|
-
const exported = await exportAesKey(key);
|
|
6605
|
-
return {
|
|
6606
|
-
key: arrayBufferToHex(exported),
|
|
6607
|
-
iv: uint8ArrayToHex(iv),
|
|
6608
|
-
cipher: arrayBufferToHex(ciphertext)
|
|
6609
|
-
}
|
|
6610
|
-
};
|
|
6611
|
-
|
|
6612
|
-
const decrypt$1 = async ({cipher, key, iv}) => {
|
|
6613
|
-
if (!key.type) key = await importAesKey(hexToUint8Array(key));
|
|
6614
|
-
cipher = new Uint8Array(hexToUint8Array(cipher));
|
|
6615
|
-
iv = new Uint8Array(hexToUint8Array(iv));
|
|
6616
|
-
|
|
6617
|
-
const plaintext = await decryptAes(cipher, key, iv);
|
|
6618
|
-
return new TextDecoder().decode(plaintext);
|
|
6515
|
+
const plaintext = await decryptAes(cipher, key, iv);
|
|
6516
|
+
return new TextDecoder().decode(plaintext);
|
|
6619
6517
|
};
|
|
6620
6518
|
|
|
6621
6519
|
var typedArrayConcat = (input, options = {length: undefined, seperator: undefined}) => {
|
|
@@ -20180,7 +20078,7 @@ class Identity {
|
|
|
20180
20078
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20181
20079
|
}
|
|
20182
20080
|
else {
|
|
20183
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
20081
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-5f552dff.js');
|
|
20184
20082
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20185
20083
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20186
20084
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20228,8 +20126,11 @@ globalThis.globalSub = globalThis.globalSub || new LittlePubSub();
|
|
|
20228
20126
|
* const peernet = new Peernet();
|
|
20229
20127
|
*/
|
|
20230
20128
|
class Peernet {
|
|
20129
|
+
storePrefix;
|
|
20130
|
+
root;
|
|
20231
20131
|
identity;
|
|
20232
20132
|
stores = [];
|
|
20133
|
+
peerId;
|
|
20233
20134
|
/**
|
|
20234
20135
|
* @type {Object}
|
|
20235
20136
|
* @property {Object} peer Instance of Peer
|
|
@@ -20248,6 +20149,7 @@ class Peernet {
|
|
|
20248
20149
|
#connections = {};
|
|
20249
20150
|
requestProtos = {};
|
|
20250
20151
|
_messageHandler;
|
|
20152
|
+
_peerHandler;
|
|
20251
20153
|
protos;
|
|
20252
20154
|
/**
|
|
20253
20155
|
* @access public
|
|
@@ -20283,6 +20185,7 @@ class Peernet {
|
|
|
20283
20185
|
up: 0,
|
|
20284
20186
|
down: 0,
|
|
20285
20187
|
};
|
|
20188
|
+
// @ts-ignore
|
|
20286
20189
|
return this._init(options, password);
|
|
20287
20190
|
}
|
|
20288
20191
|
get id() {
|
|
@@ -20354,7 +20257,7 @@ class Peernet {
|
|
|
20354
20257
|
this.root = options.root;
|
|
20355
20258
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20356
20259
|
// FolderMessageResponse
|
|
20357
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
20260
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-0591b744.js');
|
|
20358
20261
|
/**
|
|
20359
20262
|
* proto Object containing protos
|
|
20360
20263
|
* @type {Object}
|
|
@@ -20421,7 +20324,13 @@ class Peernet {
|
|
|
20421
20324
|
else {
|
|
20422
20325
|
process.on('SIGTERM', async () => {
|
|
20423
20326
|
process.stdin.resume();
|
|
20424
|
-
|
|
20327
|
+
try {
|
|
20328
|
+
await this.client.destroy();
|
|
20329
|
+
}
|
|
20330
|
+
catch (error) {
|
|
20331
|
+
// @ts-ignore
|
|
20332
|
+
await this.client.close();
|
|
20333
|
+
}
|
|
20425
20334
|
process.exit();
|
|
20426
20335
|
});
|
|
20427
20336
|
}
|
|
@@ -20433,7 +20342,7 @@ class Peernet {
|
|
|
20433
20342
|
if (this.#starting || this.#started)
|
|
20434
20343
|
return;
|
|
20435
20344
|
this.#starting = true;
|
|
20436
|
-
const importee = await import('./client-
|
|
20345
|
+
const importee = await import('./client-3221a5d7.js');
|
|
20437
20346
|
/**
|
|
20438
20347
|
* @access public
|
|
20439
20348
|
* @type {PeernetClient}
|
|
@@ -20561,21 +20470,13 @@ class Peernet {
|
|
|
20561
20470
|
* @param {String} hash
|
|
20562
20471
|
*/
|
|
20563
20472
|
async providersFor(hash, store) {
|
|
20564
|
-
let providers =
|
|
20473
|
+
let providers = this.dht.providersFor(hash);
|
|
20565
20474
|
// walk the network to find a provider
|
|
20566
|
-
|
|
20475
|
+
let tries = 0;
|
|
20476
|
+
while (!providers && tries < 3 || Object.keys(providers).length === 0 && tries < 3) {
|
|
20477
|
+
tries += 1;
|
|
20567
20478
|
await this.walk(hash);
|
|
20568
|
-
providers =
|
|
20569
|
-
// second walk the network to find a provider
|
|
20570
|
-
if (!providers || providers.length === 0) {
|
|
20571
|
-
await this.walk(hash);
|
|
20572
|
-
providers = await this.dht.providersFor(hash);
|
|
20573
|
-
}
|
|
20574
|
-
// last walk
|
|
20575
|
-
if (!providers || providers.length === 0) {
|
|
20576
|
-
await this.walk(hash);
|
|
20577
|
-
providers = await this.dht.providersFor(hash);
|
|
20578
|
-
}
|
|
20479
|
+
providers = this.dht.providersFor(hash);
|
|
20579
20480
|
}
|
|
20580
20481
|
// undefined if no providers given
|
|
20581
20482
|
return providers;
|
|
@@ -20614,11 +20515,11 @@ class Peernet {
|
|
|
20614
20515
|
}
|
|
20615
20516
|
async requestData(hash, store) {
|
|
20616
20517
|
const providers = await this.providersFor(hash);
|
|
20617
|
-
if (!providers || providers.
|
|
20518
|
+
if (!providers || Object.keys(providers).length === 0)
|
|
20618
20519
|
throw nothingFoundError(hash);
|
|
20619
20520
|
debug(`found ${providers.size} provider(s) for ${hash}`);
|
|
20620
20521
|
// get closest peer on earth
|
|
20621
|
-
const closestPeer =
|
|
20522
|
+
const closestPeer = Object.values(providers)[0];
|
|
20622
20523
|
// get peer instance by id
|
|
20623
20524
|
if (!closestPeer || !closestPeer.id)
|
|
20624
20525
|
return this.requestData(hash, store?.name || store);
|
|
@@ -20633,7 +20534,7 @@ class Peernet {
|
|
|
20633
20534
|
// fallback and try every provider found
|
|
20634
20535
|
const promises = [];
|
|
20635
20536
|
const providers = await this.providersFor(hash, store);
|
|
20636
|
-
for (const provider of providers) {
|
|
20537
|
+
for (const provider of Object.values(providers)) {
|
|
20637
20538
|
const peer = this.#connections[provider.id];
|
|
20638
20539
|
if (peer)
|
|
20639
20540
|
promises.push(peer.request(node.encoded));
|
|
@@ -20819,10 +20720,10 @@ class Peernet {
|
|
|
20819
20720
|
*
|
|
20820
20721
|
* @param {String} hash
|
|
20821
20722
|
* @param {Buffer} data
|
|
20822
|
-
* @param {String}
|
|
20723
|
+
* @param {String} storeName - storeName to access
|
|
20823
20724
|
*/
|
|
20824
|
-
async put(hash, data,
|
|
20825
|
-
store = globalThis[`${
|
|
20725
|
+
async put(hash, data, storeName = 'data') {
|
|
20726
|
+
const store = globalThis[`${storeName}Store`];
|
|
20826
20727
|
return store.put(hash, data);
|
|
20827
20728
|
}
|
|
20828
20729
|
/**
|
|
@@ -20853,9 +20754,9 @@ class Peernet {
|
|
|
20853
20754
|
// TODO: if peer subscribed
|
|
20854
20755
|
}
|
|
20855
20756
|
}
|
|
20856
|
-
createHash(data, name) {
|
|
20857
|
-
|
|
20858
|
-
}
|
|
20757
|
+
// createHash(data, name) {
|
|
20758
|
+
// return new CodeHash(data, {name})
|
|
20759
|
+
// }
|
|
20859
20760
|
/**
|
|
20860
20761
|
*
|
|
20861
20762
|
* @param {String} topic
|
|
@@ -20869,10 +20770,10 @@ class Peernet {
|
|
|
20869
20770
|
console.log('removepeer', peer.id);
|
|
20870
20771
|
const id = peer.id;
|
|
20871
20772
|
await this.client._removePeer(peer);
|
|
20872
|
-
console.log(this.client.peers[id]);
|
|
20873
20773
|
if (this.client.peers[id]) {
|
|
20874
20774
|
for (const connection of Object.keys(this.client.peers[id])) {
|
|
20875
|
-
// if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
20775
|
+
// if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
20776
|
+
// @ts-ignore
|
|
20876
20777
|
if (this.client.peers[id][connection].connected)
|
|
20877
20778
|
return this.client.emit('peerconnect', connection);
|
|
20878
20779
|
}
|