@leofcoin/chain 1.5.5 → 1.5.7

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.
@@ -20,12 +20,12 @@ var nodeConfig = async (config = {
20
20
  await globalThis.peernet.addStore('transactionPool', 'lfc', name, false);
21
21
  };
22
22
 
23
- const encode$8 = (string) => {
23
+ const encode$a = (string) => {
24
24
  if (typeof string === 'string')
25
25
  return new TextEncoder().encode(string);
26
26
  throw Error(`expected typeof String instead got ${string}`);
27
27
  };
28
- const decode$9 = (uint8Array) => {
28
+ const decode$b = (uint8Array) => {
29
29
  if (uint8Array instanceof Uint8Array)
30
30
  return new TextDecoder().decode(uint8Array);
31
31
  throw Error(`expected typeof uint8Array instead got ${uint8Array}`);
@@ -36,7 +36,7 @@ class KeyPath {
36
36
  uint8Array;
37
37
  constructor(input) {
38
38
  if (typeof input === 'string') {
39
- this.uint8Array = encode$8(input);
39
+ this.uint8Array = encode$a(input);
40
40
  }
41
41
  else if (input instanceof Uint8Array) {
42
42
  this.uint8Array = input;
@@ -52,7 +52,7 @@ class KeyPath {
52
52
  return true;
53
53
  }
54
54
  toString() {
55
- return decode$9(this.uint8Array);
55
+ return decode$b(this.uint8Array);
56
56
  }
57
57
  /**
58
58
  * Returns the `list` representation of this path.
@@ -72,7 +72,7 @@ class KeyValue {
72
72
  uint8Array;
73
73
  constructor(input) {
74
74
  if (typeof input === 'string') {
75
- this.uint8Array = encode$8(input);
75
+ this.uint8Array = encode$a(input);
76
76
  }
77
77
  else if (input instanceof Uint8Array) {
78
78
  this.uint8Array = input;
@@ -88,7 +88,7 @@ class KeyValue {
88
88
  return true;
89
89
  }
90
90
  toString() {
91
- return decode$9(this.uint8Array);
91
+ return decode$b(this.uint8Array);
92
92
  }
93
93
  }
94
94
 
@@ -301,16 +301,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
301
301
  const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
302
302
  const base32 = base$1(ALPHABET$3);
303
303
  const base32Hex = base$1(ALPHABET_HEX$1);
304
- const decode$8 = base32.decode;
305
- const decodeHex$2 = base32Hex.decode;
306
- const encode$7 = base32.encode;
307
- const encodeHex$2 = base32Hex.encode;
304
+ const decode$a = base32.decode;
305
+ const decodeHex$3 = base32Hex.decode;
306
+ const encode$9 = base32.encode;
307
+ const encodeHex$3 = base32Hex.encode;
308
308
  const isBase32 = (string, hex = false) => {
309
309
  try {
310
310
  if (hex)
311
- decodeHex$2(string);
311
+ decodeHex$3(string);
312
312
  else
313
- decode$8(string);
313
+ decode$a(string);
314
314
  return true;
315
315
  }
316
316
  catch (e) {
@@ -320,11 +320,11 @@ const isBase32 = (string, hex = false) => {
320
320
  const isBase32Hex = (string) => {
321
321
  return isBase32(string, true);
322
322
  };
323
- var index$8 = {
324
- encode: encode$7,
325
- decode: decode$8,
326
- encodeHex: encodeHex$2,
327
- decodeHex: decodeHex$2,
323
+ var index$9 = {
324
+ encode: encode$9,
325
+ decode: decode$a,
326
+ encodeHex: encodeHex$3,
327
+ decodeHex: decodeHex$3,
328
328
  isBase32,
329
329
  isBase32Hex
330
330
  };
@@ -333,13 +333,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
333
333
  var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
334
334
  var base58 = base$1(ALPHABET$2);
335
335
  var base58Hex = base$1(ALPHABET_HEX);
336
- var encode$6 = base58.encode;
337
- var decode$7 = base58.decode;
338
- var encodeHex$1 = base58Hex.encode;
339
- var decodeHex$1 = base58Hex.decode;
336
+ var encode$8 = base58.encode;
337
+ var decode$9 = base58.decode;
338
+ var encodeHex$2 = base58Hex.encode;
339
+ var decodeHex$2 = base58Hex.decode;
340
340
  var isBase58 = function (string) {
341
341
  try {
342
- decode$7(string);
342
+ decode$9(string);
343
343
  return true;
344
344
  }
345
345
  catch (e) {
@@ -348,7 +348,7 @@ var isBase58 = function (string) {
348
348
  };
349
349
  var isBase58Hex = function (string) {
350
350
  try {
351
- decodeHex$1(string);
351
+ decodeHex$2(string);
352
352
  return true;
353
353
  }
354
354
  catch (e) {
@@ -357,12 +357,12 @@ var isBase58Hex = function (string) {
357
357
  };
358
358
  var whatType = function (string) {
359
359
  try {
360
- decode$7(string);
360
+ decode$9(string);
361
361
  return 'base58';
362
362
  }
363
363
  catch (e) {
364
364
  try {
365
- decodeHex$1(string);
365
+ decodeHex$2(string);
366
366
  return 'base58Hex';
367
367
  }
368
368
  catch (_a) {
@@ -370,36 +370,36 @@ var whatType = function (string) {
370
370
  }
371
371
  }
372
372
  };
373
- var base58$1 = { encode: encode$6, decode: decode$7, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
373
+ var base58$1 = { encode: encode$8, decode: decode$9, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$2, decodeHex: decodeHex$2, whatType: whatType };
374
374
 
375
- const MSB$1 = 0x80;
376
- const REST$1 = 0x7F;
377
- const MSBALL = ~REST$1;
378
- const INT = Math.pow(2, 31);
379
- const encode$5 = (num, out, offset) => {
375
+ const MSB$3 = 0x80;
376
+ const REST$3 = 0x7F;
377
+ const MSBALL$1 = ~REST$3;
378
+ const INT$1 = Math.pow(2, 31);
379
+ const encode$7 = (num, out, offset) => {
380
380
  if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
381
- encode$5.bytes = 0;
381
+ encode$7.bytes = 0;
382
382
  throw new RangeError('Could not encode varint');
383
383
  }
384
384
  out = out || [];
385
385
  offset = offset || 0;
386
386
  const oldOffset = offset;
387
- while (num >= INT) {
388
- out[offset++] = (num & 0xFF) | MSB$1;
387
+ while (num >= INT$1) {
388
+ out[offset++] = (num & 0xFF) | MSB$3;
389
389
  num /= 128;
390
390
  }
391
- while (num & MSBALL) {
392
- out[offset++] = (num & 0xFF) | MSB$1;
391
+ while (num & MSBALL$1) {
392
+ out[offset++] = (num & 0xFF) | MSB$3;
393
393
  num >>>= 7;
394
394
  }
395
395
  out[offset] = num | 0;
396
- encode$5.bytes = offset - oldOffset + 1;
396
+ encode$7.bytes = offset - oldOffset + 1;
397
397
  return out;
398
398
  };
399
399
 
400
- const MSB = 0x80;
401
- const REST = 0x7F;
402
- const decode$6 = (buf, offset) => {
400
+ const MSB$2 = 0x80;
401
+ const REST$2 = 0x7F;
402
+ const decode$8 = (buf, offset) => {
403
403
  offset = offset || 0;
404
404
  const l = buf.length;
405
405
  let counter = offset;
@@ -408,49 +408,49 @@ const decode$6 = (buf, offset) => {
408
408
  let b;
409
409
  do {
410
410
  if (counter >= l || shift > 49) {
411
- decode$6.bytes = 0;
411
+ decode$8.bytes = 0;
412
412
  throw new RangeError('Could not decode varint');
413
413
  }
414
414
  b = buf[counter++];
415
415
  result += shift < 28
416
- ? (b & REST) << shift
417
- : (b & REST) * Math.pow(2, shift);
416
+ ? (b & REST$2) << shift
417
+ : (b & REST$2) * Math.pow(2, shift);
418
418
  shift += 7;
419
- } while (b >= MSB);
420
- decode$6.bytes = counter - offset;
419
+ } while (b >= MSB$2);
420
+ decode$8.bytes = counter - offset;
421
421
  return result;
422
422
  };
423
423
 
424
- const N1 = Math.pow(2, 7);
425
- const N2 = Math.pow(2, 14);
426
- const N3 = Math.pow(2, 21);
427
- const N4 = Math.pow(2, 28);
428
- const N5 = Math.pow(2, 35);
429
- const N6 = Math.pow(2, 42);
430
- const N7 = Math.pow(2, 49);
431
- const N8 = Math.pow(2, 56);
432
- const N9 = Math.pow(2, 63);
433
- var encodingLength = (value) => (value < N1 ? 1
434
- : value < N2 ? 2
435
- : value < N3 ? 3
436
- : value < N4 ? 4
437
- : value < N5 ? 5
438
- : value < N6 ? 6
439
- : value < N7 ? 7
440
- : value < N8 ? 8
441
- : value < N9 ? 9
424
+ const N1$1 = Math.pow(2, 7);
425
+ const N2$1 = Math.pow(2, 14);
426
+ const N3$1 = Math.pow(2, 21);
427
+ const N4$1 = Math.pow(2, 28);
428
+ const N5$1 = Math.pow(2, 35);
429
+ const N6$1 = Math.pow(2, 42);
430
+ const N7$1 = Math.pow(2, 49);
431
+ const N8$1 = Math.pow(2, 56);
432
+ const N9$1 = Math.pow(2, 63);
433
+ var encodingLength$1 = (value) => (value < N1$1 ? 1
434
+ : value < N2$1 ? 2
435
+ : value < N3$1 ? 3
436
+ : value < N4$1 ? 4
437
+ : value < N5$1 ? 5
438
+ : value < N6$1 ? 6
439
+ : value < N7$1 ? 7
440
+ : value < N8$1 ? 8
441
+ : value < N9$1 ? 9
442
442
  : 10);
443
443
 
444
- var index$7 = {
445
- encode: encode$5,
446
- decode: decode$6,
447
- encodingLength
444
+ var index$8 = {
445
+ encode: encode$7,
446
+ decode: decode$8,
447
+ encodingLength: encodingLength$1
448
448
  };
449
449
 
450
- var index$6 = (input, prefix) => {
450
+ var index$7 = (input, prefix) => {
451
451
  const encodedArray = [];
452
452
  const length = input.reduce((total, current) => {
453
- const encoded = index$7.encode(current.length);
453
+ const encoded = index$8.encode(current.length);
454
454
  encodedArray.push(encoded);
455
455
  total += current.length + encoded.length;
456
456
  return total;
@@ -472,14 +472,14 @@ var index$6 = (input, prefix) => {
472
472
  return typedArray;
473
473
  };
474
474
 
475
- var index$5 = (typedArray, prefix) => {
475
+ var index$6 = (typedArray, prefix) => {
476
476
  const set = [];
477
477
  if (prefix)
478
478
  typedArray = typedArray.subarray(prefix.length);
479
479
  const varintAndSub = (typedArray) => {
480
- const length = index$7.decode(typedArray);
480
+ const length = index$8.decode(typedArray);
481
481
  // remove length
482
- typedArray = typedArray.subarray(index$7.decode.bytes);
482
+ typedArray = typedArray.subarray(index$8.decode.bytes);
483
483
  // push value
484
484
  set.push(typedArray.subarray(0, length));
485
485
  // remove value
@@ -493,39 +493,39 @@ var index$5 = (typedArray, prefix) => {
493
493
 
494
494
  const ALPHABET$1 = '0123456789ABCDEF';
495
495
  const base16 = base$1(ALPHABET$1);
496
- const decode$5 = base16.decode;
497
- const encode$4 = base16.encode;
496
+ const decode$7 = base16.decode;
497
+ const encode$6 = base16.encode;
498
498
  const isBase16 = (string) => {
499
499
  try {
500
- decode$5(string);
500
+ decode$7(string);
501
501
  return true;
502
502
  }
503
503
  catch (e) {
504
504
  return false;
505
505
  }
506
506
  };
507
- var index$4 = {
508
- encode: encode$4,
509
- decode: decode$5,
507
+ var index$5 = {
508
+ encode: encode$6,
509
+ decode: decode$7,
510
510
  isBase16
511
511
  };
512
512
 
513
513
  const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
514
514
  const base64 = base$1(ALPHABET);
515
- const decode$4 = base64.decode;
516
- const encode$3 = base64.encode;
515
+ const decode$6 = base64.decode;
516
+ const encode$5 = base64.encode;
517
517
  const isBase64 = (string) => {
518
518
  try {
519
- decode$4(string);
519
+ decode$6(string);
520
520
  return true;
521
521
  }
522
522
  catch (e) {
523
523
  return false;
524
524
  }
525
525
  };
526
- var index$3 = {
527
- encode: encode$3,
528
- decode: decode$4,
526
+ var index$4 = {
527
+ encode: encode$5,
528
+ decode: decode$6,
529
529
  isBase64
530
530
  };
531
531
 
@@ -611,26 +611,26 @@ const fromObject = (object) => new TextEncoder().encode(JSON.stringify(object));
611
611
  const toObject = (uint8Array) => JSON.parse(new TextDecoder().decode(uint8Array));
612
612
  const fromBinary = (string) => fromHex(parseInt(string, 2).toString(16).toUpperCase());
613
613
  const toBinary = (uint8Array) => hexToBinary(toHex$2(uint8Array));
614
- const toBase64 = (uint8Array) => index$3.encode(uint8Array);
615
- const fromBase64 = (string) => index$3.decode(string);
614
+ const toBase64 = (uint8Array) => index$4.encode(uint8Array);
615
+ const fromBase64 = (string) => index$4.decode(string);
616
616
  const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
617
617
  const fromBase58 = (string) => base58$1.decode(string);
618
- const toBase32 = (uint8Array) => index$8.encode(uint8Array);
619
- const fromBase32 = (string) => index$8.decode(string);
620
- const toBase16 = (uint8Array) => index$4.encode(uint8Array);
621
- const fromBase16 = (string) => index$4.decode(string);
618
+ const toBase32 = (uint8Array) => index$9.encode(uint8Array);
619
+ const fromBase32 = (string) => index$9.decode(string);
620
+ const toBase16 = (uint8Array) => index$5.encode(uint8Array);
621
+ const fromBase16 = (string) => index$5.decode(string);
622
622
  let FormatInterface$2 = class FormatInterface {
623
623
  encoded;
624
624
  decoded;
625
625
  constructor(input) {
626
626
  if (input) {
627
- if (index$4.isBase16(input))
627
+ if (index$5.isBase16(input))
628
628
  this.encoded = this.fromBase16(input);
629
- else if (index$8.isBase32(input))
629
+ else if (index$9.isBase32(input))
630
630
  this.encoded = this.fromBase32(input);
631
631
  else if (base58$1.isBase58(input))
632
632
  this.encoded = this.fromBase58(input);
633
- else if (index$3.isBase64(input))
633
+ else if (index$4.isBase64(input))
634
634
  this.encoded = this.fromBase64(input);
635
635
  else if (typeof input === 'string') {
636
636
  let isCompatible = isTypedArrayCompatible(input);
@@ -699,16 +699,16 @@ let FormatInterface$2 = class FormatInterface {
699
699
  toBinary = (uint8Array) => this.decoded = hexToBinary(toHex$2(uint8Array));
700
700
  fromBinary = (binary) => this.encoded = fromBinary(binary);
701
701
  toObject = (uint8Array) => this.decoded = toObject(uint8Array);
702
- toBase64 = (uint8Array) => this.decoded = index$3.encode(uint8Array);
703
- fromBase64 = (string) => this.encoded = index$3.decode(string);
702
+ toBase64 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
703
+ fromBase64 = (string) => this.encoded = index$4.decode(string);
704
704
  toBase58 = (uint8Array) => this.decoded = base58$1.encode(uint8Array);
705
705
  fromBase58 = (string) => this.encoded = base58$1.decode(string);
706
- toBase32 = (uint8Array) => this.decoded = index$8.encode(uint8Array);
707
- fromBase32 = (string) => this.encoded = index$8.decode(string);
708
- toBase16 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
709
- fromBase16 = (string) => this.decoded = index$4.decode(string);
706
+ toBase32 = (uint8Array) => this.decoded = index$9.encode(uint8Array);
707
+ fromBase32 = (string) => this.encoded = index$9.decode(string);
708
+ toBase16 = (uint8Array) => this.decoded = index$5.encode(uint8Array);
709
+ fromBase16 = (string) => this.decoded = index$5.decode(string);
710
710
  };
711
- var index$2 = {
711
+ var index$3 = {
712
712
  fromString: fromString$1,
713
713
  toString: toString$1,
714
714
  fromHex,
@@ -4858,7 +4858,7 @@ function throwFault(fault, operation, value) {
4858
4858
  return logger.throwError(fault, Logger.errors.NUMERIC_FAULT, params);
4859
4859
  }
4860
4860
 
4861
- const { fromString, toString } = index$2;
4861
+ const { fromString, toString } = index$3;
4862
4862
  const isJson = (type) => type === 'object' || 'array';
4863
4863
  const isString = (type) => type === 'string';
4864
4864
  const isNumber = (type) => type === 'number';
@@ -4899,7 +4899,7 @@ const toType = (data) => {
4899
4899
  return new TextEncoder().encode(data.toString());
4900
4900
  throw new Error(`unsuported type ${typeof data || data}`);
4901
4901
  };
4902
- const encode$2 = (proto, input, compress) => {
4902
+ const encode$4 = (proto, input, compress) => {
4903
4903
  const keys = Object.keys(proto);
4904
4904
  const values = Object.values(proto);
4905
4905
  const set = [];
@@ -4914,10 +4914,10 @@ const encode$2 = (proto, input, compress) => {
4914
4914
  // when data is undefined push the default value of the proto
4915
4915
  set.push(toType(data || values[i]));
4916
4916
  }
4917
- return index$6(set);
4917
+ return index$7(set);
4918
4918
  };
4919
- const decode$3 = (proto, uint8Array, compressed) => {
4920
- let deconcated = index$5(uint8Array);
4919
+ const decode$5 = (proto, uint8Array, compressed) => {
4920
+ let deconcated = index$6(uint8Array);
4921
4921
  const output = {};
4922
4922
  const keys = Object.keys(proto);
4923
4923
  const values = Object.values(proto);
@@ -4946,9 +4946,9 @@ const decode$3 = (proto, uint8Array, compressed) => {
4946
4946
  }
4947
4947
  return output;
4948
4948
  };
4949
- var index$1 = {
4950
- encode: encode$2,
4951
- decode: decode$3
4949
+ var index$2 = {
4950
+ encode: encode$4,
4951
+ decode: decode$5
4952
4952
  };
4953
4953
 
4954
4954
  /*!
@@ -5719,23 +5719,23 @@ let BasicInterface$1 = class BasicInterface {
5719
5719
  // get Codec(): Codec {}
5720
5720
  protoEncode(data) {
5721
5721
  // check schema
5722
- return index$1.encode(this.proto, data, false);
5722
+ return index$2.encode(this.proto, data, false);
5723
5723
  }
5724
5724
  protoDecode(data) {
5725
5725
  // check schema
5726
- return index$1.decode(this.proto, data, false);
5726
+ return index$2.decode(this.proto, data, false);
5727
5727
  }
5728
5728
  isHex(string) {
5729
5729
  return isHex(string);
5730
5730
  }
5731
5731
  isBase32(string) {
5732
- return index$8.isBase32(string);
5732
+ return index$9.isBase32(string);
5733
5733
  }
5734
5734
  isBase58(string) {
5735
5735
  return base58$1.isBase58(string);
5736
5736
  }
5737
5737
  fromBs32(encoded) {
5738
- return this.decode(index$8.decode(encoded));
5738
+ return this.decode(index$9.decode(encoded));
5739
5739
  }
5740
5740
  fromBs58(encoded) {
5741
5741
  return this.decode(fromBase58(encoded));
@@ -5797,7 +5797,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5797
5797
  super();
5798
5798
  if (buffer) {
5799
5799
  if (buffer instanceof Uint8Array) {
5800
- const codec = index$7.decode(buffer);
5800
+ const codec = index$8.decode(buffer);
5801
5801
  const name = this.getCodecName(codec);
5802
5802
  if (name) {
5803
5803
  this.name = name;
@@ -5809,7 +5809,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5809
5809
  }
5810
5810
  }
5811
5811
  else if (buffer instanceof ArrayBuffer) {
5812
- const codec = index$7.decode(new Uint8Array(buffer));
5812
+ const codec = index$8.decode(new Uint8Array(buffer));
5813
5813
  const name = this.getCodecName(codec);
5814
5814
  if (name) {
5815
5815
  this.name = name;
@@ -5837,7 +5837,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5837
5837
  }
5838
5838
  }
5839
5839
  fromEncoded(encoded) {
5840
- const codec = index$7.decode(encoded);
5840
+ const codec = index$8.decode(encoded);
5841
5841
  const name = this.getCodecName(codec);
5842
5842
  this.name = name;
5843
5843
  this.encoded = encoded;
@@ -5856,24 +5856,24 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5856
5856
  this.name = this.getCodecName(codec);
5857
5857
  this.hashAlg = this.getHashAlg(this.name);
5858
5858
  this.codec = this.getCodec(this.name);
5859
- this.codecBuffer = index$7.encode(this.codec);
5859
+ this.codecBuffer = index$8.encode(this.codec);
5860
5860
  }
5861
5861
  fromName(name) {
5862
5862
  const codec = this.getCodec(name);
5863
5863
  this.name = name;
5864
5864
  this.codec = codec;
5865
5865
  this.hashAlg = this.getHashAlg(name);
5866
- this.codecBuffer = index$7.encode(this.codec);
5866
+ this.codecBuffer = index$8.encode(this.codec);
5867
5867
  }
5868
5868
  decode(encoded) {
5869
5869
  encoded = encoded || this.encoded;
5870
- const codec = index$7.decode(encoded);
5870
+ const codec = index$8.decode(encoded);
5871
5871
  this.fromCodec(codec);
5872
5872
  return this.decoded;
5873
5873
  }
5874
5874
  encode(codec) {
5875
5875
  codec = codec || this.codec;
5876
- this.encoded = index$7.encode(codec);
5876
+ this.encoded = index$8.encode(codec);
5877
5877
  return this.encoded;
5878
5878
  }
5879
5879
  };
@@ -5929,7 +5929,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5929
5929
  return uint8Array;
5930
5930
  }
5931
5931
  get length() {
5932
- return index$7.encode(this.size);
5932
+ return index$8.encode(this.size);
5933
5933
  }
5934
5934
  get buffer() {
5935
5935
  return this.encoded;
@@ -5969,7 +5969,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5969
5969
  }
5970
5970
  async validate(buffer) {
5971
5971
  if (Buffer.isBuffer(buffer)) {
5972
- const codec = index$7.decode(buffer);
5972
+ const codec = index$8.decode(buffer);
5973
5973
  if (this.codecs[codec]) {
5974
5974
  this.decode(buffer);
5975
5975
  }
@@ -5988,12 +5988,12 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5988
5988
  }
5989
5989
  decode(buffer) {
5990
5990
  this.encoded = buffer;
5991
- const codec = index$7.decode(buffer);
5991
+ const codec = index$8.decode(buffer);
5992
5992
  this.codec = new Codec$1(codec);
5993
5993
  // TODO: validate codec
5994
- buffer = buffer.slice(index$7.decode.bytes);
5995
- this.size = index$7.decode(buffer);
5996
- this.digest = buffer.slice(index$7.decode.bytes);
5994
+ buffer = buffer.slice(index$8.decode.bytes);
5995
+ this.size = index$8.decode(buffer);
5996
+ this.digest = buffer.slice(index$8.decode.bytes);
5997
5997
  if (this.digest.length !== this.size) {
5998
5998
  throw new Error(`hash length inconsistent: ${this.encoded.toString()}`);
5999
5999
  }
@@ -6549,66 +6549,6 @@ const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SH
6549
6549
  }, key, length)
6550
6550
  };
6551
6551
 
6552
- const generateAesKey = async (length = 256) => {
6553
- const key = await subtle.generateKey({
6554
- name: 'AES-CBC',
6555
- length
6556
- }, true, ['encrypt', 'decrypt']);
6557
-
6558
- return key;
6559
- };
6560
-
6561
- const importAesKey = async (exported, format = 'raw', length = 256) => {
6562
- return await subtle.importKey(format, exported, {
6563
- name: 'AES-CBC',
6564
- length
6565
- }, true, ['encrypt', 'decrypt'])
6566
- };
6567
-
6568
- const exportAesKey = async (key, format = 'raw') => {
6569
- return await subtle.exportKey(format, key)
6570
- };
6571
-
6572
- const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
6573
- name: 'AES-CBC',
6574
- iv,
6575
- }, key, uint8Array);
6576
-
6577
- const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
6578
- name: 'AES-CBC',
6579
- iv,
6580
- }, key, uint8Array);
6581
-
6582
- const uint8ArrayToHex = uint8Array =>
6583
- [...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
6584
-
6585
- const arrayBufferToHex = arrayBuffer =>
6586
- uint8ArrayToHex(new Uint8Array(arrayBuffer));
6587
-
6588
- const hexToUint8Array = hex =>
6589
- new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
6590
-
6591
- const encrypt$1 = async string => {
6592
- const key = await generateAesKey();
6593
- const iv = randombytes(16);
6594
- const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
6595
- const exported = await exportAesKey(key);
6596
- return {
6597
- key: arrayBufferToHex(exported),
6598
- iv: uint8ArrayToHex(iv),
6599
- cipher: arrayBufferToHex(ciphertext)
6600
- }
6601
- };
6602
-
6603
- const decrypt$1 = async ({cipher, key, iv}) => {
6604
- if (!key.type) key = await importAesKey(hexToUint8Array(key));
6605
- cipher = new Uint8Array(hexToUint8Array(cipher));
6606
- iv = new Uint8Array(hexToUint8Array(iv));
6607
-
6608
- const plaintext = await decryptAes(cipher, key, iv);
6609
- return new TextDecoder().decode(plaintext);
6610
- };
6611
-
6612
6552
  var typedArrayConcat = (input, options = {length: undefined, seperator: undefined}) => {
6613
6553
  if (!options) options = {};
6614
6554
 
@@ -6638,15 +6578,15 @@ var typedArrayConcat = (input, options = {length: undefined, seperator: undefine
6638
6578
  return typedArray
6639
6579
  };
6640
6580
 
6641
- const concatAndDoubleHash = async (input) => {
6581
+ const concatAndDoubleHash$1 = async (input) => {
6642
6582
  return new Uint8Array(await createDoubleHash(typedArrayConcat(input), 'SHA-256'));
6643
6583
  };
6644
6584
 
6645
- const encode$1 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
6585
+ const encode$3 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
6646
6586
  if (!(source instanceof Uint8Array) || !(prefix instanceof Uint8Array)) {
6647
6587
  throw new TypeError('Expected Uint8Array');
6648
6588
  }
6649
- const hash = await concatAndDoubleHash([
6589
+ const hash = await concatAndDoubleHash$1([
6650
6590
  prefix,
6651
6591
  source
6652
6592
  ]);
@@ -6659,11 +6599,11 @@ const encode$1 = async (source, prefix = new TextEncoder().encode('00'), hex) =>
6659
6599
  return base58$1.encodeHex(uint8Array);
6660
6600
  return base58$1.encode(uint8Array);
6661
6601
  };
6662
- const decode$2 = async (string, hex) => {
6602
+ const decode$4 = async (string, hex) => {
6663
6603
  let uint8Array = hex ? base58$1.decodeHex(string) : base58$1.decode(string);
6664
6604
  const prefix = uint8Array.subarray(0, 2);
6665
6605
  const source = uint8Array.subarray(2, -4);
6666
- const hash = await concatAndDoubleHash([
6606
+ const hash = await concatAndDoubleHash$1([
6667
6607
  prefix,
6668
6608
  source
6669
6609
  ]);
@@ -6677,23 +6617,23 @@ const decode$2 = async (string, hex) => {
6677
6617
  }
6678
6618
  return { prefix, data: source };
6679
6619
  };
6680
- const isBase58check = (string, hex) => {
6620
+ const isBase58check$1 = (string, hex) => {
6681
6621
  try {
6682
- hex ? decode$2(string, true) : decode$2(string);
6622
+ hex ? decode$4(string, true) : decode$4(string);
6683
6623
  return true;
6684
6624
  }
6685
6625
  catch (e) {
6686
6626
  return false;
6687
6627
  }
6688
6628
  };
6689
- const encodeHex = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$1(uint8Array, prefix, true);
6690
- const decodeHex = (string) => decode$2(string, true);
6691
- const isBase58checkHex = (string) => isBase58check(string, true);
6692
- var base58check = { encode: encode$1, decode: decode$2, encodeHex, decodeHex, isBase58check, isBase58checkHex };
6629
+ const encodeHex$1 = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$3(uint8Array, prefix, true);
6630
+ const decodeHex$1 = (string) => decode$4(string, true);
6631
+ const isBase58checkHex$1 = (string) => isBase58check$1(string, true);
6632
+ var base58check$1 = { encode: encode$3, decode: decode$4, encodeHex: encodeHex$1, decodeHex: decodeHex$1, isBase58check: isBase58check$1, isBase58checkHex: isBase58checkHex$1 };
6693
6633
 
6694
- const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
6634
+ const decode$3 = (multiWif, expectedVersion, expectedCodec) => {
6695
6635
  const decoded = base58$1.decode(multiWif);
6696
- let [version, codec, privateKey] = index$5(decoded);
6636
+ let [version, codec, privateKey] = index$6(decoded);
6697
6637
  version = Number(new TextDecoder().decode(version));
6698
6638
  codec = Number(new TextDecoder().decode(codec));
6699
6639
  if (expectedVersion && version !== expectedVersion)
@@ -6702,18 +6642,18 @@ const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
6702
6642
  throw new Error(`invalid codec: expected ${expectedCodec} but got ${codec}`);
6703
6643
  return { version, codec, privateKey };
6704
6644
  };
6705
- var index = {
6645
+ var index$1 = {
6706
6646
  encode: (version, codec, privateKey) => {
6707
- return base58$1.encode(index$6([
6647
+ return base58$1.encode(index$7([
6708
6648
  new TextEncoder().encode(version.toString()),
6709
6649
  new TextEncoder().encode(codec.toString()),
6710
6650
  privateKey
6711
6651
  ]));
6712
6652
  },
6713
- decode: decode$1,
6653
+ decode: decode$3,
6714
6654
  isMultiWif: (multiWif) => {
6715
6655
  try {
6716
- const { version, codec, privateKey } = decode$1(multiWif);
6656
+ const { version, codec, privateKey } = decode$3(multiWif);
6717
6657
  if (version === undefined)
6718
6658
  return false;
6719
6659
  if (codec === undefined)
@@ -16373,110 +16313,166 @@ var elliptic = lib(elliptic$1);
16373
16313
 
16374
16314
  var secp256k1 = /*@__PURE__*/getDefaultExportFromCjs(elliptic);
16375
16315
 
16376
- const leofcoinOlivia = {
16377
- messagePrefix: '\u0019Leofcoin Signed Message:',
16378
- version: 1,
16379
- pubKeyHash: 0x73,
16380
- scriptHash: 0x76,
16381
- multiTxHash: 0x8b4125,
16382
- payments: {
16383
- version: 0,
16384
- unspent: 0x1fa443d7 // ounsp
16385
- },
16386
- wif: 0x7D,
16387
- multiCodec: 0x7c4,
16388
- bip32: { public: 0x13BBF2D5, private: 0x13BBCBC5 }
16389
- };
16390
- const bitcoinTestnet = {
16391
- messagePrefix: '\x18Bitcoin Signed Message:\n',
16392
- version: 1,
16393
- bech32: 'tb',
16394
- pubKeyHash: 0x6f,
16395
- scriptHash: 0xc4,
16396
- wif: 0xef,
16397
- bip32: {
16398
- public: 0x043587cf,
16399
- private: 0x04358394
16400
- },
16401
- multiCodec: 0
16402
- };
16403
- var testnets = {
16404
- 'leofcoin:olivia': leofcoinOlivia,
16405
- 'bitcoin:testnet': bitcoinTestnet
16316
+ const leofcoinOlivia = {
16317
+ messagePrefix: '\u0019Leofcoin Signed Message:',
16318
+ version: 1,
16319
+ pubKeyHash: 0x73,
16320
+ scriptHash: 0x76,
16321
+ multiTxHash: 0x8b4125,
16322
+ payments: {
16323
+ version: 0,
16324
+ unspent: 0x1fa443d7 // ounsp
16325
+ },
16326
+ wif: 0x7D,
16327
+ multiCodec: 0x7c4,
16328
+ bip32: { public: 0x13BBF2D5, private: 0x13BBCBC5 }
16329
+ };
16330
+ const bitcoinTestnet = {
16331
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
16332
+ version: 1,
16333
+ bech32: 'tb',
16334
+ pubKeyHash: 0x6f,
16335
+ scriptHash: 0xc4,
16336
+ wif: 0xef,
16337
+ bip32: {
16338
+ public: 0x043587cf,
16339
+ private: 0x04358394
16340
+ },
16341
+ multiCodec: 0
16342
+ };
16343
+ var testnets = {
16344
+ 'leofcoin:olivia': leofcoinOlivia,
16345
+ 'bitcoin:testnet': bitcoinTestnet
16406
16346
  };
16407
16347
 
16408
- // https://en.bitcoin.it/wiki/List_of_address_prefixes
16409
- /**
16410
- * Main network
16411
- * @return {messagePrefix, pubKeyHash, scriptHash, wif, bip32}
16412
- */
16413
- const leofcoin = {
16414
- messagePrefix: '\u0019Leofcoin Signed Message:',
16415
- version: 1,
16416
- pubKeyHash: 0x30,
16417
- scriptHash: 0x37,
16418
- multiTxHash: 0x3adeed,
16419
- payments: {
16420
- version: 0,
16421
- unspent: 0x0d6e0327 // Lunsp
16422
- },
16423
- coin_type: 640,
16424
- wif: 0x3F,
16425
- multiCodec: 0x3c4,
16426
- bip32: { public: 0x13BBF2D4, private: 0x13BBCBC4 },
16427
- testnet: testnets['leofcoin:olivia']
16348
+ // https://en.bitcoin.it/wiki/List_of_address_prefixes
16349
+ // usage:
16350
+ // networks['bitcoin']['testnet']
16351
+ // networks.bitcoin.testnet
16352
+ /**
16353
+ * Main network
16354
+ * @return {messagePrefix, pubKeyHash, scriptHash, wif, bip32}
16355
+ */
16356
+ const leofcoin = {
16357
+ messagePrefix: '\u0019Leofcoin Signed Message:',
16358
+ version: 1,
16359
+ pubKeyHash: 0x30,
16360
+ scriptHash: 0x37,
16361
+ multiTxHash: 0x3adeed,
16362
+ payments: {
16363
+ version: 0,
16364
+ unspent: 0x0d6e0327 // Lunsp
16365
+ },
16366
+ coin_type: 640,
16367
+ wif: 0x3F,
16368
+ multiCodec: 0x3c4,
16369
+ bip32: { public: 0x13BBF2D4, private: 0x13BBCBC4 },
16370
+ testnet: testnets['leofcoin:olivia']
16371
+ };
16372
+ const bitcoin = {
16373
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
16374
+ version: 1,
16375
+ bech32: 'bc',
16376
+ pubKeyHash: 0x00,
16377
+ multiCodec: 0x00,
16378
+ scriptHash: 0x05,
16379
+ wif: 0x80,
16380
+ coin_type: 0,
16381
+ bip32: {
16382
+ public: 0x0488b21e, private: 0x0488ade4
16383
+ },
16384
+ testnet: testnets['bitcoin:testnet']
16385
+ };
16386
+ const litecoin = {
16387
+ messagePrefix: '\x19Litecoin Signed Message:\n',
16388
+ version: 1,
16389
+ pubKeyHash: 0x30,
16390
+ scriptHash: 0x32,
16391
+ wif: 0xb0,
16392
+ bip32: {
16393
+ public: 0x019da462,
16394
+ private: 0x019d9cfe
16395
+ },
16396
+ bech32: '',
16397
+ multiCodec: 0
16398
+ };
16399
+ const ethereum = {
16400
+ messagePrefix: '\x19Ethereum Signed Message:\n',
16401
+ version: 1,
16402
+ pubKeyHash: 0x30,
16403
+ scriptHash: 0x32,
16404
+ bip32: {
16405
+ private: 0x0488ADE4, public: 0x0488B21E
16406
+ },
16407
+ coin_type: 60,
16408
+ wif: 0x45,
16409
+ multiCodec: 0x3c5
16410
+ };
16411
+ /**
16412
+ * Our & supported networks
16413
+ * @return {leofcoin, olivia}
16414
+ */
16415
+ var networks$1 = {
16416
+ leofcoin,
16417
+ bitcoin,
16418
+ litecoin,
16419
+ ethereum
16420
+ };
16421
+
16422
+ const concatAndDoubleHash = async (input) => {
16423
+ return new Uint8Array(await createDoubleHash(typedArrayConcat(input), 'SHA-256'));
16428
16424
  };
16429
- const bitcoin = {
16430
- messagePrefix: '\x18Bitcoin Signed Message:\n',
16431
- version: 1,
16432
- bech32: 'bc',
16433
- pubKeyHash: 0x00,
16434
- multiCodec: 0x00,
16435
- scriptHash: 0x05,
16436
- wif: 0x80,
16437
- coin_type: 0,
16438
- bip32: {
16439
- public: 0x0488b21e, private: 0x0488ade4
16440
- },
16441
- testnet: testnets['bitcoin:testnet']
16425
+
16426
+ const encode$2 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
16427
+ if (!(source instanceof Uint8Array) || !(prefix instanceof Uint8Array)) {
16428
+ throw new TypeError('Expected Uint8Array');
16429
+ }
16430
+ const hash = await concatAndDoubleHash([
16431
+ prefix,
16432
+ source
16433
+ ]);
16434
+ const uint8Array = typedArrayConcat([
16435
+ prefix,
16436
+ source,
16437
+ hash.subarray(0, 4)
16438
+ ]);
16439
+ if (hex)
16440
+ return base58$1.encodeHex(uint8Array);
16441
+ return base58$1.encode(uint8Array);
16442
16442
  };
16443
- const litecoin = {
16444
- messagePrefix: '\x19Litecoin Signed Message:\n',
16445
- version: 1,
16446
- pubKeyHash: 0x30,
16447
- scriptHash: 0x32,
16448
- wif: 0xb0,
16449
- bip32: {
16450
- public: 0x019da462,
16451
- private: 0x019d9cfe
16452
- },
16453
- bech32: '',
16454
- multiCodec: 0
16443
+ const decode$2 = async (string, hex) => {
16444
+ let uint8Array = hex ? base58$1.decodeHex(string) : base58$1.decode(string);
16445
+ const prefix = uint8Array.subarray(0, 2);
16446
+ const source = uint8Array.subarray(2, -4);
16447
+ const hash = await concatAndDoubleHash([
16448
+ prefix,
16449
+ source
16450
+ ]);
16451
+ let index = 0;
16452
+ const slice = uint8Array.subarray(-4);
16453
+ for (const check of slice) {
16454
+ if (check !== hash[index]) {
16455
+ throw new Error('Invalid checksum');
16456
+ }
16457
+ index++;
16458
+ }
16459
+ return { prefix, data: source };
16455
16460
  };
16456
- const ethereum = {
16457
- messagePrefix: '\x19Ethereum Signed Message:\n',
16458
- version: 1,
16459
- pubKeyHash: 0x30,
16460
- scriptHash: 0x32,
16461
- bip32: {
16462
- private: 0x0488ADE4, public: 0x0488B21E
16463
- },
16464
- coin_type: 60,
16465
- wif: 0x45,
16466
- multiCodec: 0x3c5
16461
+ const isBase58check = (string, hex) => {
16462
+ try {
16463
+ hex ? decode$2(string, true) : decode$2(string);
16464
+ return true;
16465
+ }
16466
+ catch (e) {
16467
+ return false;
16468
+ }
16467
16469
  };
16468
- /**
16469
- * Our & supported networks
16470
- * @return {leofcoin, olivia}
16471
- */
16472
- var networks$1 = {
16473
- leofcoin,
16474
- bitcoin,
16475
- litecoin,
16476
- ethereum
16477
- };
16470
+ const encodeHex = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$2(uint8Array, prefix, true);
16471
+ const decodeHex = (string) => decode$2(string, true);
16472
+ const isBase58checkHex = (string) => isBase58check(string, true);
16473
+ var base58check = { encode: encode$2, decode: decode$2, encodeHex, decodeHex, isBase58check, isBase58checkHex };
16478
16474
 
16479
- const encode = (version, privateKey, compressed) => {
16475
+ const encode$1 = (version, privateKey, compressed) => {
16480
16476
  if (privateKey.length !== 32)
16481
16477
  throw new TypeError(`Invalid privateKey length: expected 32 got ${privateKey.length}`);
16482
16478
  const uint8Array = new Uint8Array(compressed ? 34 : 33);
@@ -16487,7 +16483,7 @@ const encode = (version, privateKey, compressed) => {
16487
16483
  }
16488
16484
  return base58check.encode(uint8Array);
16489
16485
  };
16490
- const decode = async (wif, version) => {
16486
+ const decode$1 = async (wif, version) => {
16491
16487
  wif = (await base58check.decode(wif)).data;
16492
16488
  if (version && wif[0] !== version)
16493
16489
  throw new Error('Invalid network version');
@@ -16502,207 +16498,208 @@ const decode = async (wif, version) => {
16502
16498
  compressed: wif.length === 33 ? false : true
16503
16499
  };
16504
16500
  };
16505
- var wif = { encode, decode };
16506
-
16507
- const HIGHEST_BIT = 0x80000000;
16508
- const { publicKeyCreate, publicKeyVerify, privateKeyVerify, privateKeyTweakAdd, ecdh } = secp256k1;
16509
- class HdNode {
16510
- #privateKey;
16511
- #publicKey;
16512
- #chainCode;
16513
- #network;
16514
- #depth;
16515
- #index;
16516
- #parentFingerprint;
16517
- constructor(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16518
- this.init(privateKey, publicKey, chainCode, network, depth, index, parentFingerprint);
16519
- }
16520
- init(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16521
- this.#privateKey = privateKey;
16522
- this.#publicKey = publicKey;
16523
- this.#chainCode = chainCode;
16524
- this.#network = network || networks$1.leofcoin;
16525
- this.#depth = depth;
16526
- this.#index = index;
16527
- this.#parentFingerprint = parentFingerprint;
16528
- }
16529
- get network() {
16530
- return this.#network;
16531
- }
16532
- get publicKey() {
16533
- this.#publicKey = this.#publicKey || publicKeyCreate(this.#privateKey, true);
16534
- return this.#publicKey;
16535
- }
16536
- get privateKey() {
16537
- return this.#privateKey;
16538
- }
16539
- get identifier() {
16540
- return this.hash160(this.publicKey);
16541
- }
16542
- get fingerprint() {
16543
- return (async () => (await this.identifier).subarray(0, 4))();
16544
- }
16545
- async hash160(data) {
16546
- const hash = await createHash(data, 'SHA-256');
16547
- return (await createRIPEMD160()).update(new Uint8Array(hash)).digest('binary');
16548
- }
16549
- get isNeutered() {
16550
- return this.#privateKey === undefined;
16551
- }
16552
- get neutered() {
16553
- return new HdNode(undefined, this.#publicKey, this.#chainCode, this.#network, this.#depth, this.#index, this.#parentFingerprint);
16554
- }
16555
- fromPrivateKey(privateKey, chainCode, network) {
16556
- if (!privateKeyVerify(privateKey))
16557
- throw new TypeError('Private key not in range [1, n)');
16558
- return new HdNode(privateKey, publicKeyCreate(privateKey, true), chainCode, network);
16559
- }
16560
- fromPublicKey(publicKey, chainCode, network) {
16561
- // verify the X coordinate is a point on the curve
16562
- if (!publicKeyVerify(publicKey))
16563
- throw new TypeError('Point is not on the curve');
16564
- return new HdNode(undefined, publicKey, chainCode, network);
16565
- }
16566
- async fromSeed(seed, network) {
16567
- if (seed.length < 16)
16568
- throw new TypeError('Seed should be at least 128 bits');
16569
- if (seed.length > 64)
16570
- throw new TypeError('Seed should be at most 512 bits');
16571
- let hash = (await createHMAC(createSHA512(), new TextEncoder().encode('Bitcoin seed')))
16572
- .update(seed)
16573
- .digest('binary');
16574
- const privateKey = hash.subarray(0, 32);
16575
- const chainCode = hash.subarray(32);
16576
- return this.fromPrivateKey(privateKey, chainCode, network);
16577
- }
16578
- async toBase58() {
16579
- const network = this.#network || networks$1.leofcoin;
16580
- let version = !this.isNeutered
16581
- ? network.bip32.private
16582
- : network.bip32.public;
16583
- const set = [
16584
- new TextEncoder().encode(version.toString()),
16585
- new TextEncoder().encode(this.#depth.toString()),
16586
- new TextEncoder().encode(this.#parentFingerprint.toString()),
16587
- new TextEncoder().encode(this.#index.toString()),
16588
- this.#chainCode
16589
- ];
16590
- if (!this.isNeutered) {
16591
- set.push(new TextEncoder().encode('0'));
16592
- set.push(new Uint8Array(this.privateKey));
16593
- }
16594
- else {
16595
- set.push(new Uint8Array(this.publicKey));
16596
- }
16597
- return base58check.encode(index$6(set));
16598
- }
16599
- toWIF() {
16600
- if (!this.#privateKey)
16601
- throw new TypeError('Missing private key');
16602
- return wif.encode(this.#network.wif, this.#privateKey, true);
16603
- }
16604
- // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
16605
- async derive(index) {
16606
- const isHardened = index >= HIGHEST_BIT;
16607
- let data;
16608
- // Hardened child
16609
- if (isHardened) {
16610
- if (this.isNeutered)
16611
- throw new TypeError('Missing private key for hardened child key');
16612
- // data = 0x00 || ser256(kpar) || ser32(index)
16613
- data = index$6([
16614
- new TextEncoder().encode('0'),
16615
- this.privateKey,
16616
- new TextEncoder().encode(index.toString())
16617
- ]);
16618
- }
16619
- else {
16620
- data = index$6([
16621
- this.publicKey,
16622
- new TextEncoder().encode(index.toString())
16623
- ]);
16624
- }
16625
- const hash = (await createHMAC(createSHA512(), this.#chainCode))
16626
- .update(data)
16627
- .digest('binary');
16628
- const privateKey = hash.subarray(0, 32);
16629
- const chainCode = hash.subarray(32);
16630
- // if parse256(privateKey) >= n, proceed with the next value for i
16631
- if (!privateKeyVerify(privateKey))
16632
- return this.derive(index + 1);
16633
- // Private parent key -> private child key
16634
- if (!this.isNeutered) {
16635
- // ki = parse256(privateKey) + kpar (mod n)
16636
- const ki = privateKeyTweakAdd(this.privateKey, privateKey);
16637
- // In case ki == 0, proceed with the next value for i
16638
- if (ki == null)
16639
- return this.derive(index + 1);
16640
- return new HdNode(ki, null, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16641
- }
16642
- function hashfn(x, y) {
16643
- const pubKey = new Uint8Array(33);
16644
- pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03;
16645
- pubKey.set(x, 1);
16646
- return pubKey;
16647
- }
16648
- const Ki = ecdh(this.publicKey, chainCode, { hashfn }, new Uint8Array(33));
16649
- // const Ki = new Uint8Array(ecc.pointAddScalar(this.publicKey, IL, true));
16650
- // In case Ki is the point at infinity, proceed with the next value for i
16651
- if (Ki === null)
16652
- return this.derive(index + 1);
16653
- return new HdNode(undefined, Ki, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16654
- }
16655
- deriveHardened(index) {
16656
- // Only derives hardened private keys by default
16657
- return this.derive(index + HIGHEST_BIT);
16658
- }
16659
- async derivePath(path) {
16660
- let splitPath = path.split('/');
16661
- if (splitPath[0] === 'm') {
16662
- if (this.#parentFingerprint)
16663
- throw new TypeError('Expected master, got child');
16664
- splitPath = splitPath.slice(1);
16665
- }
16666
- let prevHd = this;
16667
- for (const indexString of splitPath) {
16668
- let index;
16669
- if (indexString.slice(-1) === `'`) {
16670
- index = parseInt(indexString.slice(0, -1), 10);
16671
- prevHd = await prevHd.deriveHardened(index);
16672
- }
16673
- else {
16674
- index = parseInt(indexString, 10);
16675
- prevHd = await prevHd.derive(index);
16676
- }
16677
- }
16678
- return prevHd;
16679
- }
16680
- async fromBase58(string, network) {
16681
- let buffer = (await base58check.decode(string)).data;
16682
- network = network || networks$1.leofcoin;
16683
- // 4 bytes: version bytes
16684
- let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$5(buffer);
16685
- version = Number(new TextDecoder().decode(version));
16686
- depth = Number(new TextDecoder().decode(depth));
16687
- parentFingerprint = Number(new TextDecoder().decode(parentFingerprint));
16688
- index = Number(new TextDecoder().decode(index));
16689
- k = privateKey ? 0 : k;
16690
- if (version !== network.bip32.private && version !== network.bip32.public)
16691
- throw new TypeError('Invalid network version');
16692
- if (depth === 0) {
16693
- if (parentFingerprint !== 0)
16694
- throw new TypeError('Invalid parent fingerprint');
16695
- }
16696
- if (depth === 0 && index !== 0)
16697
- throw new TypeError('Invalid index');
16698
- if (version === network.bip32.private) {
16699
- if (k !== 0x00)
16700
- throw new TypeError('Invalid private key');
16701
- return new HdNode(privateKey, undefined, chainCode, network, depth, index, parentFingerprint);
16702
- }
16703
- this.init(undefined, k, chainCode, network, depth, index, parentFingerprint);
16704
- return new HdNode(undefined, k, chainCode, network, depth, index, parentFingerprint);
16705
- }
16501
+ var wif = { encode: encode$1, decode: decode$1 };
16502
+
16503
+ const HIGHEST_BIT = 0x80000000;
16504
+ const { publicKeyCreate, publicKeyVerify, privateKeyVerify, privateKeyTweakAdd, ecdh } = secp256k1;
16505
+ class HdNode {
16506
+ #privateKey;
16507
+ #publicKey;
16508
+ #chainCode;
16509
+ #network;
16510
+ #depth;
16511
+ #index;
16512
+ #parentFingerprint;
16513
+ constructor(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16514
+ this.init(privateKey, publicKey, chainCode, network, depth, index, parentFingerprint);
16515
+ }
16516
+ init(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16517
+ this.#privateKey = privateKey;
16518
+ this.#publicKey = publicKey;
16519
+ this.#chainCode = chainCode;
16520
+ this.#network = network || networks$1.leofcoin;
16521
+ this.#depth = depth;
16522
+ this.#index = index;
16523
+ this.#parentFingerprint = parentFingerprint;
16524
+ }
16525
+ get network() {
16526
+ return this.#network;
16527
+ }
16528
+ get publicKey() {
16529
+ this.#publicKey = this.#publicKey || publicKeyCreate(this.#privateKey, true);
16530
+ return this.#publicKey;
16531
+ }
16532
+ get privateKey() {
16533
+ return this.#privateKey;
16534
+ }
16535
+ get identifier() {
16536
+ return this.hash160(this.publicKey);
16537
+ }
16538
+ get fingerprint() {
16539
+ return (async () => (await this.identifier).subarray(0, 4))();
16540
+ }
16541
+ async hash160(data) {
16542
+ const hash = await createHash(data, 'SHA-256');
16543
+ return (await createRIPEMD160()).update(new Uint8Array(hash)).digest('binary');
16544
+ }
16545
+ get isNeutered() {
16546
+ return this.#privateKey === undefined;
16547
+ }
16548
+ get neutered() {
16549
+ return new HdNode(undefined, this.#publicKey, this.#chainCode, this.#network, this.#depth, this.#index, this.#parentFingerprint);
16550
+ }
16551
+ fromPrivateKey(privateKey, chainCode, network) {
16552
+ if (!privateKeyVerify(privateKey))
16553
+ throw new TypeError('Private key not in range [1, n)');
16554
+ const publicKey = publicKeyCreate(privateKey, true);
16555
+ return new HdNode(privateKey, publicKey, publicKey.slice(1), network);
16556
+ }
16557
+ fromPublicKey(publicKey, chainCode, network) {
16558
+ // verify the X coordinate is a point on the curve
16559
+ if (!publicKeyVerify(publicKey))
16560
+ throw new TypeError('Point is not on the curve');
16561
+ return new HdNode(undefined, publicKey, chainCode, network);
16562
+ }
16563
+ async fromSeed(seed, network) {
16564
+ if (seed.length < 16)
16565
+ throw new TypeError('Seed should be at least 128 bits');
16566
+ if (seed.length > 64)
16567
+ throw new TypeError('Seed should be at most 512 bits');
16568
+ let hash = (await createHMAC(createSHA512(), new TextEncoder().encode('Bitcoin seed')))
16569
+ .update(seed)
16570
+ .digest('binary');
16571
+ const privateKey = hash.subarray(0, 32);
16572
+ const chainCode = hash.subarray(32);
16573
+ return this.fromPrivateKey(privateKey, chainCode, network);
16574
+ }
16575
+ async toBase58() {
16576
+ const network = this.#network || networks$1.leofcoin;
16577
+ let version = !this.isNeutered
16578
+ ? network.bip32.private
16579
+ : network.bip32.public;
16580
+ const set = [
16581
+ new TextEncoder().encode(version.toString()),
16582
+ new TextEncoder().encode(this.#depth.toString()),
16583
+ new TextEncoder().encode(this.#parentFingerprint.toString()),
16584
+ new TextEncoder().encode(this.#index.toString()),
16585
+ this.#chainCode
16586
+ ];
16587
+ if (!this.isNeutered) {
16588
+ set.push(new TextEncoder().encode('0'));
16589
+ set.push(new Uint8Array(this.privateKey));
16590
+ }
16591
+ else {
16592
+ set.push(new Uint8Array(this.publicKey));
16593
+ }
16594
+ return base58check$1.encode(index$7(set));
16595
+ }
16596
+ toWIF() {
16597
+ if (!this.#privateKey)
16598
+ throw new TypeError('Missing private key');
16599
+ return wif.encode(this.#network.wif, this.#privateKey, true);
16600
+ }
16601
+ // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
16602
+ async derive(index) {
16603
+ const isHardened = index >= HIGHEST_BIT;
16604
+ let data;
16605
+ // Hardened child
16606
+ if (isHardened) {
16607
+ if (this.isNeutered)
16608
+ throw new TypeError('Missing private key for hardened child key');
16609
+ // data = 0x00 || ser256(kpar) || ser32(index)
16610
+ data = index$7([
16611
+ new TextEncoder().encode('0'),
16612
+ this.privateKey,
16613
+ new TextEncoder().encode(index.toString())
16614
+ ]);
16615
+ }
16616
+ else {
16617
+ data = index$7([
16618
+ this.publicKey,
16619
+ new TextEncoder().encode(index.toString())
16620
+ ]);
16621
+ }
16622
+ const hash = (await createHMAC(createSHA512(), this.#chainCode))
16623
+ .update(data)
16624
+ .digest('binary');
16625
+ const privateKey = hash.subarray(0, 32);
16626
+ const chainCode = hash.subarray(32);
16627
+ // if parse256(privateKey) >= n, proceed with the next value for i
16628
+ if (!privateKeyVerify(privateKey))
16629
+ return this.derive(index + 1);
16630
+ // Private parent key -> private child key
16631
+ if (!this.isNeutered) {
16632
+ // ki = parse256(privateKey) + kpar (mod n)
16633
+ const ki = privateKeyTweakAdd(this.privateKey, privateKey);
16634
+ // In case ki == 0, proceed with the next value for i
16635
+ if (ki == null)
16636
+ return this.derive(index + 1);
16637
+ return new HdNode(ki, null, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16638
+ }
16639
+ function hashfn(x, y) {
16640
+ const pubKey = new Uint8Array(33);
16641
+ pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03;
16642
+ pubKey.set(x, 1);
16643
+ return pubKey;
16644
+ }
16645
+ const Ki = ecdh(this.publicKey, chainCode, { hashfn }, new Uint8Array(33));
16646
+ // const Ki = new Uint8Array(ecc.pointAddScalar(this.publicKey, IL, true));
16647
+ // In case Ki is the point at infinity, proceed with the next value for i
16648
+ if (Ki === null)
16649
+ return this.derive(index + 1);
16650
+ return new HdNode(undefined, Ki, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16651
+ }
16652
+ deriveHardened(index) {
16653
+ // Only derives hardened private keys by default
16654
+ return this.derive(index + HIGHEST_BIT);
16655
+ }
16656
+ async derivePath(path) {
16657
+ let splitPath = path.split('/');
16658
+ if (splitPath[0] === 'm') {
16659
+ if (this.#parentFingerprint)
16660
+ throw new TypeError('Expected master, got child');
16661
+ splitPath = splitPath.slice(1);
16662
+ }
16663
+ let prevHd = this;
16664
+ for (const indexString of splitPath) {
16665
+ let index;
16666
+ if (indexString.slice(-1) === `'`) {
16667
+ index = parseInt(indexString.slice(0, -1), 10);
16668
+ prevHd = await prevHd.deriveHardened(index);
16669
+ }
16670
+ else {
16671
+ index = parseInt(indexString, 10);
16672
+ prevHd = await prevHd.derive(index);
16673
+ }
16674
+ }
16675
+ return prevHd;
16676
+ }
16677
+ async fromBase58(string, network) {
16678
+ let buffer = (await base58check$1.decode(string)).data;
16679
+ network = network || networks$1.leofcoin;
16680
+ // 4 bytes: version bytes
16681
+ let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$6(buffer);
16682
+ version = Number(new TextDecoder().decode(version));
16683
+ depth = Number(new TextDecoder().decode(depth));
16684
+ parentFingerprint = Number(new TextDecoder().decode(parentFingerprint));
16685
+ index = Number(new TextDecoder().decode(index));
16686
+ k = privateKey ? 0 : k;
16687
+ if (version !== network.bip32.private && version !== network.bip32.public)
16688
+ throw new TypeError('Invalid network version');
16689
+ if (depth === 0) {
16690
+ if (parentFingerprint !== 0)
16691
+ throw new TypeError('Invalid parent fingerprint');
16692
+ }
16693
+ if (depth === 0 && index !== 0)
16694
+ throw new TypeError('Invalid index');
16695
+ if (version === network.bip32.private) {
16696
+ if (k !== 0x00)
16697
+ throw new TypeError('Invalid private key');
16698
+ return new HdNode(privateKey, undefined, chainCode, network, depth, index, parentFingerprint);
16699
+ }
16700
+ this.init(undefined, k, chainCode, network, depth, index, parentFingerprint);
16701
+ return new HdNode(undefined, k, chainCode, network, depth, index, parentFingerprint);
16702
+ }
16706
16703
  }
16707
16704
 
16708
16705
  // see https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
@@ -16755,144 +16752,145 @@ class Mnemonic {
16755
16752
  }
16756
16753
  }
16757
16754
 
16758
- const fromNetworkString = network => {
16759
- const parts = network.split(':');
16760
- network = networks$1[parts[0]];
16761
- if (parts[1]) {
16762
- if (network[parts[1]])
16763
- network = network[parts[1]];
16764
- network.coin_type = 1;
16765
- }
16766
- return network;
16767
- };
16768
- const publicKeyToEthereumAddress = async (publicKeyBuffer) => {
16769
- const hasher = await createKeccak(256);
16770
- hasher.update(publicKeyBuffer);
16771
- const hash = hasher.digest();
16772
- return `0x${hash.slice(-40).toString()}`;
16773
- };
16774
- class HDWallet {
16775
- hdnode;
16776
- networkName;
16777
- version;
16778
- locked;
16779
- network;
16780
- multiCodec;
16781
- get privateKey() {
16782
- return this.ifNotLocked(() => this.hdnode.privateKey);
16783
- }
16784
- get publicKey() {
16785
- return this.hdnode.publicKey;
16786
- }
16787
- async ethereumAddress() {
16788
- const address = await publicKeyToEthereumAddress(this.publicKey);
16789
- return address;
16790
- }
16791
- leofcoinAddress() {
16792
- return base58check.encode(this.publicKey);
16793
- }
16794
- get address() {
16795
- return this.getAddressForCoin();
16796
- }
16797
- async getAddressForCoin(coin_type) {
16798
- if (!coin_type)
16799
- coin_type = this.network.coin_type;
16800
- if (coin_type === 1) {
16801
- if (this.networkName?.split(':')[0] === 'ethereum')
16802
- coin_type = 60;
16803
- if (this.networkName?.split(':')[0] === 'leofcoin')
16804
- coin_type = 640;
16805
- }
16806
- // if (coin_type === 0) return this.bitcoinAddress
16807
- if (coin_type === 60)
16808
- return this.ethereumAddress();
16809
- if (coin_type === 640)
16810
- return this.leofcoinAddress();
16811
- }
16812
- get accountAddress() {
16813
- return this.ifNotLocked(async () => base58check.encode(this.hdnode.publicKey));
16814
- }
16815
- get isTestnet() {
16816
- return this.network.coin_type === 1;
16817
- }
16818
- constructor(network, hdnode) {
16819
- if (typeof network === 'string') {
16820
- this.networkName = network;
16821
- this.network = fromNetworkString(network);
16822
- }
16823
- else if (typeof network === 'object')
16824
- this.network = network;
16825
- this.multiCodec = this.network.multiCodec;
16826
- this.version = 0x00;
16827
- if (hdnode)
16828
- this.defineHDNode(hdnode);
16829
- }
16830
- ifNotLocked(fn, params) {
16831
- if (this.locked)
16832
- return;
16833
- return params ? fn(...params) : fn();
16834
- }
16835
- async defineHDNode(value) {
16836
- Object.defineProperty(this, 'hdnode', {
16837
- configurable: false,
16838
- writable: false,
16839
- value: await value
16840
- });
16841
- }
16842
- validateNetwork(network) {
16843
- if (!network && !this.network)
16844
- return console.error(`expected network to be defined`);
16845
- if (!network && this.network)
16846
- network = this.network;
16847
- if (typeof network === 'string')
16848
- network = fromNetworkString(network);
16849
- if (typeof network !== 'object')
16850
- return console.error('network not found');
16851
- return network;
16852
- }
16853
- async generate(password, network) {
16854
- network = this.validateNetwork(network);
16855
- const mnemonic = await new Mnemonic().generate(512);
16856
- const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16857
- await this.defineHDNode(await (new HdNode()).fromSeed(new Uint8Array(seed), network));
16858
- return mnemonic;
16859
- }
16860
- /**
16861
- * recover using mnemonic (recovery word list)
16862
- */
16863
- async recover(mnemonic, password, network) {
16864
- network = this.validateNetwork(network || password);
16865
- const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16866
- let node = new HdNode();
16867
- node = await node.fromSeed(new Uint8Array(seed), network);
16868
- await this.defineHDNode(await node.fromSeed(new Uint8Array(seed), network));
16869
- }
16870
- async load(base58, network) {
16871
- network = this.validateNetwork(network);
16872
- await this.defineHDNode(await (new HdNode()).fromBase58(base58, network));
16873
- }
16874
- save() {
16875
- return this.hdnode.toBase58();
16876
- }
16877
- async fromAddress(address, chainCode, network) {
16878
- network = this.validateNetwork(network);
16879
- address = (await base58check.decode(address)).data;
16880
- if (!chainCode || chainCode && !Buffer.isBuffer(chainCode))
16881
- chainCode = address.slice(1);
16882
- await this.defineHDNode(await (new HdNode()).fromPublicKey(address, chainCode, network));
16883
- }
16884
- async fromPublicKey(hex, chainCode, network) {
16885
- network = this.validateNetwork(network);
16886
- if (!chainCode || chainCode)
16887
- chainCode = hex.slice(1);
16888
- let node = new HdNode();
16889
- node = await node.fromPublicKey(hex, chainCode, network);
16890
- await this.defineHDNode(node);
16891
- return this;
16892
- }
16893
- async fromPrivateKey(privateKey, chainCode, network) {
16894
- await this.defineHDNode(await (new HdNode()).fromPrivateKey(privateKey, chainCode, network));
16895
- }
16755
+ const fromNetworkString = network => {
16756
+ const parts = network.split(':');
16757
+ network = networks$1[parts[0]];
16758
+ if (parts[1]) {
16759
+ if (network[parts[1]])
16760
+ network = network[parts[1]];
16761
+ network.coin_type = 1;
16762
+ }
16763
+ return network;
16764
+ };
16765
+ const publicKeyToEthereumAddress = async (publicKeyBuffer) => {
16766
+ const hasher = await createKeccak(256);
16767
+ hasher.update(publicKeyBuffer);
16768
+ const hash = hasher.digest();
16769
+ return `0x${hash.slice(-40).toString()}`;
16770
+ };
16771
+ class HDWallet {
16772
+ hdnode;
16773
+ networkName;
16774
+ version;
16775
+ locked;
16776
+ network;
16777
+ multiCodec;
16778
+ get privateKey() {
16779
+ return this.ifNotLocked(() => this.hdnode.privateKey);
16780
+ }
16781
+ get publicKey() {
16782
+ return this.hdnode.publicKey;
16783
+ }
16784
+ async ethereumAddress() {
16785
+ const address = await publicKeyToEthereumAddress(this.publicKey);
16786
+ return address;
16787
+ }
16788
+ leofcoinAddress() {
16789
+ return base58check$1.encode(this.publicKey);
16790
+ }
16791
+ get address() {
16792
+ return this.getAddressForCoin();
16793
+ }
16794
+ async getAddressForCoin(coin_type) {
16795
+ if (!coin_type)
16796
+ coin_type = this.network.coin_type;
16797
+ if (coin_type === 1) {
16798
+ if (this.networkName?.split(':')[0] === 'ethereum')
16799
+ coin_type = 60;
16800
+ if (this.networkName?.split(':')[0] === 'leofcoin')
16801
+ coin_type = 640;
16802
+ }
16803
+ // if (coin_type === 0) return this.bitcoinAddress
16804
+ if (coin_type === 60)
16805
+ return this.ethereumAddress();
16806
+ if (coin_type === 640)
16807
+ return this.leofcoinAddress();
16808
+ // if (coin_type === 0) return this.bitcoinAddress()
16809
+ }
16810
+ get accountAddress() {
16811
+ return this.ifNotLocked(async () => base58check$1.encode(this.hdnode.publicKey));
16812
+ }
16813
+ get isTestnet() {
16814
+ return this.network.coin_type === 1;
16815
+ }
16816
+ constructor(network, hdnode) {
16817
+ if (typeof network === 'string') {
16818
+ this.networkName = network;
16819
+ this.network = fromNetworkString(network);
16820
+ }
16821
+ else if (typeof network === 'object')
16822
+ this.network = network;
16823
+ this.multiCodec = this.network.multiCodec;
16824
+ this.version = 0x00;
16825
+ if (hdnode)
16826
+ this.defineHDNode(hdnode);
16827
+ }
16828
+ ifNotLocked(fn, params) {
16829
+ if (this.locked)
16830
+ return;
16831
+ return params ? fn(...params) : fn();
16832
+ }
16833
+ async defineHDNode(value) {
16834
+ Object.defineProperty(this, 'hdnode', {
16835
+ configurable: false,
16836
+ writable: false,
16837
+ value: await value
16838
+ });
16839
+ }
16840
+ validateNetwork(network) {
16841
+ if (!network && !this.network)
16842
+ return console.error(`expected network to be defined`);
16843
+ if (!network && this.network)
16844
+ network = this.network;
16845
+ if (typeof network === 'string')
16846
+ network = fromNetworkString(network);
16847
+ if (typeof network !== 'object')
16848
+ return console.error('network not found');
16849
+ return network;
16850
+ }
16851
+ async generate(password, network) {
16852
+ network = this.validateNetwork(network);
16853
+ const mnemonic = await new Mnemonic().generate(512);
16854
+ const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16855
+ await this.defineHDNode(await (new HdNode()).fromSeed(new Uint8Array(seed), network));
16856
+ return mnemonic;
16857
+ }
16858
+ /**
16859
+ * recover using mnemonic (recovery word list)
16860
+ */
16861
+ async recover(mnemonic, password, network) {
16862
+ network = this.validateNetwork(network || password);
16863
+ const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16864
+ let node = new HdNode();
16865
+ node = await node.fromSeed(new Uint8Array(seed), network);
16866
+ await this.defineHDNode(await node.fromSeed(new Uint8Array(seed), network));
16867
+ }
16868
+ async load(base58, network) {
16869
+ network = this.validateNetwork(network);
16870
+ await this.defineHDNode(await (new HdNode()).fromBase58(base58, network));
16871
+ }
16872
+ save() {
16873
+ return this.hdnode.toBase58();
16874
+ }
16875
+ async fromAddress(address, chainCode, network) {
16876
+ network = this.validateNetwork(network);
16877
+ address = (await base58check$1.decode(address)).data;
16878
+ if (!chainCode || chainCode && !Buffer.isBuffer(chainCode))
16879
+ chainCode = address.slice(1);
16880
+ await this.defineHDNode(await (new HdNode()).fromPublicKey(address, chainCode, network));
16881
+ }
16882
+ async fromPublicKey(hex, chainCode, network) {
16883
+ network = this.validateNetwork(network);
16884
+ if (!chainCode || chainCode)
16885
+ chainCode = hex.slice(1);
16886
+ let node = new HdNode();
16887
+ node = await node.fromPublicKey(hex, chainCode, network);
16888
+ await this.defineHDNode(node);
16889
+ return this;
16890
+ }
16891
+ async fromPrivateKey(privateKey, chainCode, network) {
16892
+ await this.defineHDNode(await (new HdNode()).fromPrivateKey(privateKey, chainCode, network));
16893
+ }
16896
16894
  }
16897
16895
 
16898
16896
  class MultiSignature {
@@ -16950,8 +16948,8 @@ class MultiSignature {
16950
16948
  if (!signature)
16951
16949
  throw ReferenceError('signature undefined');
16952
16950
  this.#multiSignature = typedArrayConcat([
16953
- index$7.encode(this.version),
16954
- index$7.encode(this.multiCodec),
16951
+ index$8.encode(this.version),
16952
+ index$8.encode(this.multiCodec),
16955
16953
  signature
16956
16954
  ]);
16957
16955
  return this.multiSignature;
@@ -16967,10 +16965,10 @@ class MultiSignature {
16967
16965
  if (!this.multiSignature)
16968
16966
  throw ReferenceError('multiSignature undefined');
16969
16967
  let buffer = this.multiSignature;
16970
- const version = index$7.decode(buffer);
16971
- buffer = buffer.subarray(index$7.decode.bytes);
16972
- const codec = index$7.decode(buffer);
16973
- buffer = buffer.subarray(index$7.decode.bytes);
16968
+ const version = index$8.decode(buffer);
16969
+ buffer = buffer.subarray(index$8.decode.bytes);
16970
+ const codec = index$8.decode(buffer);
16971
+ buffer = buffer.subarray(index$8.decode.bytes);
16974
16972
  const signature = buffer.subarray(0, buffer.length);
16975
16973
  if (version !== this.version)
16976
16974
  throw TypeError('Invalid version');
@@ -16996,16 +16994,16 @@ class MultiSignature {
16996
16994
  return this.decode(base58$1.decode(string));
16997
16995
  }
16998
16996
  toBs32() {
16999
- return index$8.encode(this.multiSignature);
16997
+ return index$9.encode(this.multiSignature);
17000
16998
  }
17001
16999
  fromBs32(string) {
17002
- return this.decode(index$8.decode(string));
17000
+ return this.decode(index$9.decode(string));
17003
17001
  }
17004
17002
  toBs32Hex() {
17005
- return index$8.encodeHex(this.multiSignature);
17003
+ return index$9.encodeHex(this.multiSignature);
17006
17004
  }
17007
17005
  fromBs32Hex(string) {
17008
- return this.decode(index$8.decodeHex(string));
17006
+ return this.decode(index$9.decodeHex(string));
17009
17007
  }
17010
17008
  toBs58Hex() {
17011
17009
  return base58$1.encodeHex(this.multiSignature);
@@ -17015,132 +17013,6 @@ class MultiSignature {
17015
17013
  }
17016
17014
  }
17017
17015
 
17018
- class MultiHDNode extends HDWallet {
17019
- #encrypted;
17020
- constructor(network, hdnode) {
17021
- super(network, hdnode);
17022
- }
17023
- get id() {
17024
- return base58check.encode(index$6([
17025
- new TextEncoder().encode(this.version.toString()),
17026
- this.account(0).hdnode.neutered.publicKey
17027
- ]));
17028
- }
17029
- get multiWIF() {
17030
- return this.toMultiWif();
17031
- }
17032
- async fromId(id) {
17033
- let buffer = (await base58check.decode(id)).data;
17034
- index$7.decode(buffer);
17035
- buffer = buffer.slice(index$7.decode.bytes);
17036
- this.fromPublicKey(buffer, null, this.networkName);
17037
- }
17038
- async lock(multiWIF) {
17039
- if (!multiWIF)
17040
- multiWIF = this.multiWIF;
17041
- this.#encrypted = await encrypt$1(multiWIF);
17042
- this.locked = true;
17043
- return this.#encrypted;
17044
- }
17045
- async unlock({ key, iv, cipher }) {
17046
- const decrypted = await decrypt$1({ cipher, key, iv });
17047
- await this.fromMultiWif(new TextDecoder().decode(decrypted));
17048
- this.locked = false;
17049
- }
17050
- fromMultiWif(string) {
17051
- const { version, codec, privateKey } = index.decode(string);
17052
- this.network = Object.values(networks$1).reduce((p, c) => {
17053
- if (c.multiCodec === codec)
17054
- return c;
17055
- else if (c.testnet && c.testnet.multiCodec === codec)
17056
- return c.testnet;
17057
- else
17058
- return p;
17059
- }, networks$1['leofcoin']);
17060
- if (version !== this.network.version)
17061
- throw new Error('invalid version');
17062
- return this.fromPrivateKey(privateKey, undefined, this.network);
17063
- }
17064
- toMultiWif() {
17065
- return index.encode(this.network.version, this.network.multiCodec, this.privateKey);
17066
- }
17067
- sign(hash) {
17068
- return new MultiSignature(this.version, this.network.multiCodec)
17069
- .sign(hash, this.privateKey);
17070
- }
17071
- verify(multiSignature, hash) {
17072
- return new MultiSignature(this.version, this.network.multiCodec)
17073
- .verify(multiSignature, hash, this.publicKey);
17074
- }
17075
- }
17076
-
17077
- class HDAccount extends MultiHDNode {
17078
- /**
17079
- * @param {number} depth - acount depth
17080
- */
17081
- constructor(network, hdnode, depth = 0) {
17082
- super(network, hdnode);
17083
- this.hdnode = hdnode;
17084
- this.depth = depth;
17085
- this._prefix = `m/44'/${hdnode.network.coin_type}'/${depth}'/`;
17086
- }
17087
- get neutered() {
17088
- return this.hdnode.neutered;
17089
- }
17090
- /**
17091
- * @param {number} index - address index
17092
- */
17093
- async internal(index = 0) {
17094
- return this.hdnode.derivePath(`${this._prefix}1/${index}`);
17095
- }
17096
- /**
17097
- * @param {number} index - address index
17098
- */
17099
- async external(index = 0) {
17100
- return this.hdnode.derivePath(`${this._prefix}0/${index}`);
17101
- }
17102
- }
17103
-
17104
- class MultiWallet extends MultiHDNode {
17105
- constructor(network, hdnode) {
17106
- super(network, hdnode);
17107
- }
17108
- get id() {
17109
- return base58check.encode(index$6([
17110
- new TextEncoder().encode(this.version.toString()),
17111
- this.account(0).hdnode.neutered.publicKey
17112
- ]));
17113
- }
17114
- get multiWIF() {
17115
- return this.toMultiWif();
17116
- }
17117
- get neutered() {
17118
- return new HDAccount(this.networkName, this, this.hdnode.depth);
17119
- }
17120
- /**
17121
- * @param {number} account - account to return chain for
17122
- * @return internal(addressIndex), external(addressIndex)
17123
- */
17124
- account(index) {
17125
- return new HDAccount(this.networkName, this, index);
17126
- }
17127
- async fromAccount(privateKey, depth, network) {
17128
- const node = await new MultiWallet(network).fromPrivateKey(privateKey);
17129
- return new HDAccount(node, depth);
17130
- }
17131
- /**
17132
- * m / purpose' / coin_type' / account' / change / aadress_index
17133
- *
17134
- * see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
17135
- */
17136
- async derivePath(path) {
17137
- return new MultiWallet(this.networkName, await this.hdnode.derivePath(path));
17138
- }
17139
- async derive(index) {
17140
- return new MultiWallet(this.networkName, await this.hdnode.derive(index));
17141
- }
17142
- }
17143
-
17144
17016
  var passwordToKey = (password) => globalThis.crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, ['deriveKey']);
17145
17017
 
17146
17018
  var deriveKey = (key, salt, iterations = 250000, hashAlgorithm = 'SHA-512') => globalThis.crypto.subtle.deriveKey({
@@ -17162,11 +17034,11 @@ var encrypt = async (password, data, version = new TextEncoder().encode('1')) =>
17162
17034
  name: 'AES-GCM',
17163
17035
  iv
17164
17036
  }, key, new TextEncoder().encode(data));
17165
- return index$6([version, salt, iv, new Uint8Array(encrypted)]);
17037
+ return index$7([version, salt, iv, new Uint8Array(encrypted)]);
17166
17038
  };
17167
17039
 
17168
17040
  var decrypt = async (password, concatecated) => {
17169
- const [version, salt, iv, cipher] = index$5(concatecated);
17041
+ const [version, salt, iv, cipher] = index$6(concatecated);
17170
17042
  let iterations;
17171
17043
  if (new TextDecoder().decode(version) === '1') {
17172
17044
  iterations = 250000;
@@ -17180,6 +17052,213 @@ var decrypt = async (password, concatecated) => {
17180
17052
  return new TextDecoder().decode(decrypted);
17181
17053
  };
17182
17054
 
17055
+ const MSB$1 = 0x80;
17056
+ const REST$1 = 0x7F;
17057
+ const MSBALL = ~REST$1;
17058
+ const INT = Math.pow(2, 31);
17059
+ const encode = (num, out, offset) => {
17060
+ if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
17061
+ encode.bytes = 0;
17062
+ throw new RangeError('Could not encode varint');
17063
+ }
17064
+ out = out || [];
17065
+ offset = offset || 0;
17066
+ const oldOffset = offset;
17067
+ while (num >= INT) {
17068
+ out[offset++] = (num & 0xFF) | MSB$1;
17069
+ num /= 128;
17070
+ }
17071
+ while (num & MSBALL) {
17072
+ out[offset++] = (num & 0xFF) | MSB$1;
17073
+ num >>>= 7;
17074
+ }
17075
+ out[offset] = num | 0;
17076
+ encode.bytes = offset - oldOffset + 1;
17077
+ return out;
17078
+ };
17079
+
17080
+ const MSB = 0x80;
17081
+ const REST = 0x7F;
17082
+ const decode = (buf, offset) => {
17083
+ offset = offset || 0;
17084
+ const l = buf.length;
17085
+ let counter = offset;
17086
+ let result = 0;
17087
+ let shift = 0;
17088
+ let b;
17089
+ do {
17090
+ if (counter >= l || shift > 49) {
17091
+ decode.bytes = 0;
17092
+ throw new RangeError('Could not decode varint');
17093
+ }
17094
+ b = buf[counter++];
17095
+ result += shift < 28
17096
+ ? (b & REST) << shift
17097
+ : (b & REST) * Math.pow(2, shift);
17098
+ shift += 7;
17099
+ } while (b >= MSB);
17100
+ decode.bytes = counter - offset;
17101
+ return result;
17102
+ };
17103
+
17104
+ const N1 = Math.pow(2, 7);
17105
+ const N2 = Math.pow(2, 14);
17106
+ const N3 = Math.pow(2, 21);
17107
+ const N4 = Math.pow(2, 28);
17108
+ const N5 = Math.pow(2, 35);
17109
+ const N6 = Math.pow(2, 42);
17110
+ const N7 = Math.pow(2, 49);
17111
+ const N8 = Math.pow(2, 56);
17112
+ const N9 = Math.pow(2, 63);
17113
+ var encodingLength = (value) => (value < N1 ? 1
17114
+ : value < N2 ? 2
17115
+ : value < N3 ? 3
17116
+ : value < N4 ? 4
17117
+ : value < N5 ? 5
17118
+ : value < N6 ? 6
17119
+ : value < N7 ? 7
17120
+ : value < N8 ? 8
17121
+ : value < N9 ? 9
17122
+ : 10);
17123
+
17124
+ var index = {
17125
+ encode,
17126
+ decode,
17127
+ encodingLength
17128
+ };
17129
+
17130
+ class MultiHDNode extends HDWallet {
17131
+ #encrypted;
17132
+ constructor(network, hdnode) {
17133
+ super(network, hdnode);
17134
+ }
17135
+ get id() {
17136
+ return base58check$1.encode(index$7([
17137
+ new TextEncoder().encode(this.version.toString()),
17138
+ this.account(0).hdnode.neutered.publicKey
17139
+ ]));
17140
+ }
17141
+ get multiWIF() {
17142
+ return this.toMultiWif();
17143
+ }
17144
+ async fromId(id) {
17145
+ let buffer = (await base58check$1.decode(id)).data;
17146
+ index.decode(buffer);
17147
+ buffer = buffer.slice(index.decode.bytes);
17148
+ this.fromPublicKey(buffer, null, this.networkName);
17149
+ }
17150
+ async import(password, encrypted) {
17151
+ const { prefix, data } = await base58check$1.decode(encrypted);
17152
+ const decrypted = await decrypt(password, data);
17153
+ await this.fromMultiWif(decrypted);
17154
+ }
17155
+ async export(password) {
17156
+ return base58check$1.encode(await encrypt(password, await this.toMultiWif()));
17157
+ }
17158
+ async lock(password) {
17159
+ // todo redefine hdnode
17160
+ this.#encrypted = await this.export(password);
17161
+ this.locked = true;
17162
+ }
17163
+ async unlock(password) {
17164
+ const { prefix, data } = await base58check$1.decode(this.#encrypted);
17165
+ await decrypt(password, data);
17166
+ this.locked = false;
17167
+ }
17168
+ fromMultiWif(string) {
17169
+ const { version, codec, privateKey } = index$1.decode(string);
17170
+ this.network = Object.values(networks$1).reduce((p, c) => {
17171
+ if (c.multiCodec === codec)
17172
+ return c;
17173
+ else if (c.testnet && c.testnet.multiCodec === codec)
17174
+ return c.testnet;
17175
+ else
17176
+ return p;
17177
+ }, networks$1['leofcoin']);
17178
+ if (version !== this.network.version)
17179
+ throw new Error('invalid version');
17180
+ return this.fromPrivateKey(privateKey, undefined, this.network);
17181
+ }
17182
+ toMultiWif() {
17183
+ return index$1.encode(this.network.version, this.network.multiCodec, this.privateKey);
17184
+ }
17185
+ sign(hash) {
17186
+ return new MultiSignature(this.version, this.network.multiCodec)
17187
+ .sign(hash, this.privateKey);
17188
+ }
17189
+ verify(multiSignature, hash) {
17190
+ return new MultiSignature(this.version, this.network.multiCodec)
17191
+ .verify(multiSignature, hash, this.publicKey);
17192
+ }
17193
+ }
17194
+
17195
+ class HDAccount extends MultiHDNode {
17196
+ /**
17197
+ * @param {number} depth - acount depth
17198
+ */
17199
+ constructor(network, hdnode, depth = 0) {
17200
+ super(network, hdnode);
17201
+ this.hdnode = hdnode;
17202
+ this.depth = depth;
17203
+ this._prefix = `m/44'/${hdnode.network.coin_type}'/${depth}'/`;
17204
+ }
17205
+ get neutered() {
17206
+ return this.hdnode.neutered;
17207
+ }
17208
+ /**
17209
+ * @param {number} index - address index
17210
+ */
17211
+ async internal(index = 0) {
17212
+ return this.hdnode.derivePath(`${this._prefix}1/${index}`);
17213
+ }
17214
+ /**
17215
+ * @param {number} index - address index
17216
+ */
17217
+ async external(index = 0) {
17218
+ return this.hdnode.derivePath(`${this._prefix}0/${index}`);
17219
+ }
17220
+ }
17221
+
17222
+ class MultiWallet extends MultiHDNode {
17223
+ constructor(network, hdnode) {
17224
+ super(network, hdnode);
17225
+ }
17226
+ get id() {
17227
+ return base58check$1.encode(index$7([
17228
+ new TextEncoder().encode(this.version.toString()),
17229
+ this.account(0).hdnode.neutered.publicKey
17230
+ ]));
17231
+ }
17232
+ get multiWIF() {
17233
+ return this.toMultiWif();
17234
+ }
17235
+ get neutered() {
17236
+ return new HDAccount(this.networkName, this, this.hdnode.depth);
17237
+ }
17238
+ /**
17239
+ * @param {number} account - account to return chain for
17240
+ * @return internal(addressIndex), external(addressIndex)
17241
+ */
17242
+ account(index) {
17243
+ return new HDAccount(this.networkName, this, index);
17244
+ }
17245
+ async fromAccount(privateKey, depth, network) {
17246
+ const node = await new MultiWallet(network).fromPrivateKey(privateKey);
17247
+ return new HDAccount(node, depth);
17248
+ }
17249
+ /**
17250
+ * m / purpose' / coin_type' / account' / change / aadress_index
17251
+ *
17252
+ * see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
17253
+ */
17254
+ async derivePath(path) {
17255
+ return new MultiWallet(this.networkName, await this.hdnode.derivePath(path));
17256
+ }
17257
+ async derive(index) {
17258
+ return new MultiWallet(this.networkName, await this.hdnode.derive(index));
17259
+ }
17260
+ }
17261
+
17183
17262
  class e{constructor(a,b,c,d,f){this._legacyCanvasSize=e.DEFAULT_CANVAS_SIZE;this._preferredCamera="environment";this._maxScansPerSecond=25;this._lastScanTimestamp=-1;this._destroyed=this._flashOn=this._paused=this._active=!1;this.$video=a;this.$canvas=document.createElement("canvas");c&&"object"===typeof c?this._onDecode=b:(c||d||f?console.warn("You're using a deprecated version of the QrScanner constructor which will be removed in the future"):console.warn("Note that the type of the scan result passed to onDecode will change in the future. To already switch to the new api today, you can pass returnDetailedScanResult: true."),
17184
17263
  this._legacyOnDecode=b);b="object"===typeof c?c:{};this._onDecodeError=b.onDecodeError||("function"===typeof c?c:this._onDecodeError);this._calculateScanRegion=b.calculateScanRegion||("function"===typeof d?d:this._calculateScanRegion);this._preferredCamera=b.preferredCamera||f||this._preferredCamera;this._legacyCanvasSize="number"===typeof c?c:"number"===typeof d?d:this._legacyCanvasSize;this._maxScansPerSecond=b.maxScansPerSecond||this._maxScansPerSecond;this._onPlay=this._onPlay.bind(this);this._onLoadedMetaData=
17185
17264
  this._onLoadedMetaData.bind(this);this._onVisibilityChange=this._onVisibilityChange.bind(this);this._updateOverlay=this._updateOverlay.bind(this);a.disablePictureInPicture=!0;a.playsInline=!0;a.muted=!0;let h=!1;a.hidden&&(a.hidden=!1,h=!0);document.body.contains(a)||(document.body.appendChild(a),h=!0);c=a.parentElement;if(b.highlightScanRegion||b.highlightCodeOutline){d=!!b.overlay;this.$overlay=b.overlay||document.createElement("div");f=this.$overlay.style;f.position="absolute";f.display="none";
@@ -20169,7 +20248,7 @@ class Identity {
20169
20248
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20170
20249
  }
20171
20250
  else {
20172
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-ba1b3977-4c483021.js');
20251
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-9c85cd32-ab3cf058.js');
20173
20252
  const { identity, accounts } = await importee.default(password, this.network);
20174
20253
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20175
20254
  await globalThis.walletStore.put('version', String(1));
@@ -20187,15 +20266,17 @@ class Identity {
20187
20266
  sign(hash) {
20188
20267
  return this.#wallet.sign(hash.subarray(0, 32));
20189
20268
  }
20269
+ lock(password) {
20270
+ this.#wallet.lock(password);
20271
+ }
20272
+ unlock(password) {
20273
+ this.#wallet.unlock(password);
20274
+ }
20190
20275
  async export(password) {
20191
- const multiWIF = this.#wallet.toMultiWif();
20192
- const encypted = await encrypt(password, multiWIF);
20193
- return base58$1.encode(encypted);
20276
+ return this.#wallet.export(password);
20194
20277
  }
20195
20278
  async import(password, encrypted) {
20196
- this.#wallet = new MultiWallet(this.network);
20197
- const decrypted = await decrypt(password, base58$1.decode(encrypted));
20198
- await this.#wallet.fromMultiWif(decrypted);
20279
+ await this.#wallet.import(password, encrypted);
20199
20280
  }
20200
20281
  async exportQR(password) {
20201
20282
  const exported = await this.export(password);
@@ -20348,7 +20429,7 @@ class Peernet {
20348
20429
  this.root = options.root;
20349
20430
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20350
20431
  // FolderMessageResponse
20351
- } = await import(/* webpackChunkName: "messages" */ './messages-dd1ad11c-8c747755.js');
20432
+ } = await import(/* webpackChunkName: "messages" */ './messages-b66f5393-8ba2fe1a.js');
20352
20433
  /**
20353
20434
  * proto Object containing protos
20354
20435
  * @type {Object}