@leofcoin/peernet 1.1.54 → 1.1.56

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.
@@ -209,16 +209,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
209
209
  const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
210
210
  const base32 = base$1(ALPHABET$3);
211
211
  const base32Hex = base$1(ALPHABET_HEX$1);
212
- const decode$8 = base32.decode;
213
- const decodeHex$2 = base32Hex.decode;
214
- const encode$7 = base32.encode;
215
- const encodeHex$2 = base32Hex.encode;
212
+ const decode$a = base32.decode;
213
+ const decodeHex$3 = base32Hex.decode;
214
+ const encode$9 = base32.encode;
215
+ const encodeHex$3 = base32Hex.encode;
216
216
  const isBase32 = (string, hex = false) => {
217
217
  try {
218
218
  if (hex)
219
- decodeHex$2(string);
219
+ decodeHex$3(string);
220
220
  else
221
- decode$8(string);
221
+ decode$a(string);
222
222
  return true;
223
223
  }
224
224
  catch (e) {
@@ -228,11 +228,11 @@ const isBase32 = (string, hex = false) => {
228
228
  const isBase32Hex = (string) => {
229
229
  return isBase32(string, true);
230
230
  };
231
- var index$8 = {
232
- encode: encode$7,
233
- decode: decode$8,
234
- encodeHex: encodeHex$2,
235
- decodeHex: decodeHex$2,
231
+ var index$9 = {
232
+ encode: encode$9,
233
+ decode: decode$a,
234
+ encodeHex: encodeHex$3,
235
+ decodeHex: decodeHex$3,
236
236
  isBase32,
237
237
  isBase32Hex
238
238
  };
@@ -241,13 +241,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
241
241
  var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
242
242
  var base58 = base$1(ALPHABET$2);
243
243
  var base58Hex = base$1(ALPHABET_HEX);
244
- var encode$6 = base58.encode;
245
- var decode$7 = base58.decode;
246
- var encodeHex$1 = base58Hex.encode;
247
- var decodeHex$1 = base58Hex.decode;
244
+ var encode$8 = base58.encode;
245
+ var decode$9 = base58.decode;
246
+ var encodeHex$2 = base58Hex.encode;
247
+ var decodeHex$2 = base58Hex.decode;
248
248
  var isBase58 = function (string) {
249
249
  try {
250
- decode$7(string);
250
+ decode$9(string);
251
251
  return true;
252
252
  }
253
253
  catch (e) {
@@ -256,7 +256,7 @@ var isBase58 = function (string) {
256
256
  };
257
257
  var isBase58Hex = function (string) {
258
258
  try {
259
- decodeHex$1(string);
259
+ decodeHex$2(string);
260
260
  return true;
261
261
  }
262
262
  catch (e) {
@@ -265,12 +265,12 @@ var isBase58Hex = function (string) {
265
265
  };
266
266
  var whatType = function (string) {
267
267
  try {
268
- decode$7(string);
268
+ decode$9(string);
269
269
  return 'base58';
270
270
  }
271
271
  catch (e) {
272
272
  try {
273
- decodeHex$1(string);
273
+ decodeHex$2(string);
274
274
  return 'base58Hex';
275
275
  }
276
276
  catch (_a) {
@@ -278,36 +278,36 @@ var whatType = function (string) {
278
278
  }
279
279
  }
280
280
  };
281
- var base58$1 = { encode: encode$6, decode: decode$7, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
281
+ var base58$1 = { encode: encode$8, decode: decode$9, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$2, decodeHex: decodeHex$2, whatType: whatType };
282
282
 
283
- const MSB$1 = 0x80;
284
- const REST$1 = 0x7F;
285
- const MSBALL = ~REST$1;
286
- const INT = Math.pow(2, 31);
287
- const encode$5 = (num, out, offset) => {
283
+ const MSB$3 = 0x80;
284
+ const REST$3 = 0x7F;
285
+ const MSBALL$1 = ~REST$3;
286
+ const INT$1 = Math.pow(2, 31);
287
+ const encode$7 = (num, out, offset) => {
288
288
  if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
289
- encode$5.bytes = 0;
289
+ encode$7.bytes = 0;
290
290
  throw new RangeError('Could not encode varint');
291
291
  }
292
292
  out = out || [];
293
293
  offset = offset || 0;
294
294
  const oldOffset = offset;
295
- while (num >= INT) {
296
- out[offset++] = (num & 0xFF) | MSB$1;
295
+ while (num >= INT$1) {
296
+ out[offset++] = (num & 0xFF) | MSB$3;
297
297
  num /= 128;
298
298
  }
299
- while (num & MSBALL) {
300
- out[offset++] = (num & 0xFF) | MSB$1;
299
+ while (num & MSBALL$1) {
300
+ out[offset++] = (num & 0xFF) | MSB$3;
301
301
  num >>>= 7;
302
302
  }
303
303
  out[offset] = num | 0;
304
- encode$5.bytes = offset - oldOffset + 1;
304
+ encode$7.bytes = offset - oldOffset + 1;
305
305
  return out;
306
306
  };
307
307
 
308
- const MSB = 0x80;
309
- const REST = 0x7F;
310
- const decode$6 = (buf, offset) => {
308
+ const MSB$2 = 0x80;
309
+ const REST$2 = 0x7F;
310
+ const decode$8 = (buf, offset) => {
311
311
  offset = offset || 0;
312
312
  const l = buf.length;
313
313
  let counter = offset;
@@ -316,49 +316,49 @@ const decode$6 = (buf, offset) => {
316
316
  let b;
317
317
  do {
318
318
  if (counter >= l || shift > 49) {
319
- decode$6.bytes = 0;
319
+ decode$8.bytes = 0;
320
320
  throw new RangeError('Could not decode varint');
321
321
  }
322
322
  b = buf[counter++];
323
323
  result += shift < 28
324
- ? (b & REST) << shift
325
- : (b & REST) * Math.pow(2, shift);
324
+ ? (b & REST$2) << shift
325
+ : (b & REST$2) * Math.pow(2, shift);
326
326
  shift += 7;
327
- } while (b >= MSB);
328
- decode$6.bytes = counter - offset;
327
+ } while (b >= MSB$2);
328
+ decode$8.bytes = counter - offset;
329
329
  return result;
330
330
  };
331
331
 
332
- const N1 = Math.pow(2, 7);
333
- const N2 = Math.pow(2, 14);
334
- const N3 = Math.pow(2, 21);
335
- const N4 = Math.pow(2, 28);
336
- const N5 = Math.pow(2, 35);
337
- const N6 = Math.pow(2, 42);
338
- const N7 = Math.pow(2, 49);
339
- const N8 = Math.pow(2, 56);
340
- const N9 = Math.pow(2, 63);
341
- var encodingLength = (value) => (value < N1 ? 1
342
- : value < N2 ? 2
343
- : value < N3 ? 3
344
- : value < N4 ? 4
345
- : value < N5 ? 5
346
- : value < N6 ? 6
347
- : value < N7 ? 7
348
- : value < N8 ? 8
349
- : value < N9 ? 9
332
+ const N1$1 = Math.pow(2, 7);
333
+ const N2$1 = Math.pow(2, 14);
334
+ const N3$1 = Math.pow(2, 21);
335
+ const N4$1 = Math.pow(2, 28);
336
+ const N5$1 = Math.pow(2, 35);
337
+ const N6$1 = Math.pow(2, 42);
338
+ const N7$1 = Math.pow(2, 49);
339
+ const N8$1 = Math.pow(2, 56);
340
+ const N9$1 = Math.pow(2, 63);
341
+ var encodingLength$1 = (value) => (value < N1$1 ? 1
342
+ : value < N2$1 ? 2
343
+ : value < N3$1 ? 3
344
+ : value < N4$1 ? 4
345
+ : value < N5$1 ? 5
346
+ : value < N6$1 ? 6
347
+ : value < N7$1 ? 7
348
+ : value < N8$1 ? 8
349
+ : value < N9$1 ? 9
350
350
  : 10);
351
351
 
352
- var index$7 = {
353
- encode: encode$5,
354
- decode: decode$6,
355
- encodingLength
352
+ var index$8 = {
353
+ encode: encode$7,
354
+ decode: decode$8,
355
+ encodingLength: encodingLength$1
356
356
  };
357
357
 
358
- var index$6 = (input, prefix) => {
358
+ var index$7 = (input, prefix) => {
359
359
  const encodedArray = [];
360
360
  const length = input.reduce((total, current) => {
361
- const encoded = index$7.encode(current.length);
361
+ const encoded = index$8.encode(current.length);
362
362
  encodedArray.push(encoded);
363
363
  total += current.length + encoded.length;
364
364
  return total;
@@ -380,14 +380,14 @@ var index$6 = (input, prefix) => {
380
380
  return typedArray;
381
381
  };
382
382
 
383
- var index$5 = (typedArray, prefix) => {
383
+ var index$6 = (typedArray, prefix) => {
384
384
  const set = [];
385
385
  if (prefix)
386
386
  typedArray = typedArray.subarray(prefix.length);
387
387
  const varintAndSub = (typedArray) => {
388
- const length = index$7.decode(typedArray);
388
+ const length = index$8.decode(typedArray);
389
389
  // remove length
390
- typedArray = typedArray.subarray(index$7.decode.bytes);
390
+ typedArray = typedArray.subarray(index$8.decode.bytes);
391
391
  // push value
392
392
  set.push(typedArray.subarray(0, length));
393
393
  // remove value
@@ -401,39 +401,39 @@ var index$5 = (typedArray, prefix) => {
401
401
 
402
402
  const ALPHABET$1 = '0123456789ABCDEF';
403
403
  const base16 = base$1(ALPHABET$1);
404
- const decode$5 = base16.decode;
405
- const encode$4 = base16.encode;
404
+ const decode$7 = base16.decode;
405
+ const encode$6 = base16.encode;
406
406
  const isBase16 = (string) => {
407
407
  try {
408
- decode$5(string);
408
+ decode$7(string);
409
409
  return true;
410
410
  }
411
411
  catch (e) {
412
412
  return false;
413
413
  }
414
414
  };
415
- var index$4 = {
416
- encode: encode$4,
417
- decode: decode$5,
415
+ var index$5 = {
416
+ encode: encode$6,
417
+ decode: decode$7,
418
418
  isBase16
419
419
  };
420
420
 
421
421
  const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
422
422
  const base64 = base$1(ALPHABET);
423
- const decode$4 = base64.decode;
424
- const encode$3 = base64.encode;
423
+ const decode$6 = base64.decode;
424
+ const encode$5 = base64.encode;
425
425
  const isBase64 = (string) => {
426
426
  try {
427
- decode$4(string);
427
+ decode$6(string);
428
428
  return true;
429
429
  }
430
430
  catch (e) {
431
431
  return false;
432
432
  }
433
433
  };
434
- var index$3 = {
435
- encode: encode$3,
436
- decode: decode$4,
434
+ var index$4 = {
435
+ encode: encode$5,
436
+ decode: decode$6,
437
437
  isBase64
438
438
  };
439
439
 
@@ -519,26 +519,26 @@ const fromObject = (object) => new TextEncoder().encode(JSON.stringify(object));
519
519
  const toObject = (uint8Array) => JSON.parse(new TextDecoder().decode(uint8Array));
520
520
  const fromBinary = (string) => fromHex(parseInt(string, 2).toString(16).toUpperCase());
521
521
  const toBinary = (uint8Array) => hexToBinary(toHex$2(uint8Array));
522
- const toBase64 = (uint8Array) => index$3.encode(uint8Array);
523
- const fromBase64 = (string) => index$3.decode(string);
522
+ const toBase64 = (uint8Array) => index$4.encode(uint8Array);
523
+ const fromBase64 = (string) => index$4.decode(string);
524
524
  const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
525
525
  const fromBase58 = (string) => base58$1.decode(string);
526
- const toBase32 = (uint8Array) => index$8.encode(uint8Array);
527
- const fromBase32 = (string) => index$8.decode(string);
528
- const toBase16 = (uint8Array) => index$4.encode(uint8Array);
529
- const fromBase16 = (string) => index$4.decode(string);
526
+ const toBase32 = (uint8Array) => index$9.encode(uint8Array);
527
+ const fromBase32 = (string) => index$9.decode(string);
528
+ const toBase16 = (uint8Array) => index$5.encode(uint8Array);
529
+ const fromBase16 = (string) => index$5.decode(string);
530
530
  let FormatInterface$2 = class FormatInterface {
531
531
  encoded;
532
532
  decoded;
533
533
  constructor(input) {
534
534
  if (input) {
535
- if (index$4.isBase16(input))
535
+ if (index$5.isBase16(input))
536
536
  this.encoded = this.fromBase16(input);
537
- else if (index$8.isBase32(input))
537
+ else if (index$9.isBase32(input))
538
538
  this.encoded = this.fromBase32(input);
539
539
  else if (base58$1.isBase58(input))
540
540
  this.encoded = this.fromBase58(input);
541
- else if (index$3.isBase64(input))
541
+ else if (index$4.isBase64(input))
542
542
  this.encoded = this.fromBase64(input);
543
543
  else if (typeof input === 'string') {
544
544
  let isCompatible = isTypedArrayCompatible(input);
@@ -607,16 +607,16 @@ let FormatInterface$2 = class FormatInterface {
607
607
  toBinary = (uint8Array) => this.decoded = hexToBinary(toHex$2(uint8Array));
608
608
  fromBinary = (binary) => this.encoded = fromBinary(binary);
609
609
  toObject = (uint8Array) => this.decoded = toObject(uint8Array);
610
- toBase64 = (uint8Array) => this.decoded = index$3.encode(uint8Array);
611
- fromBase64 = (string) => this.encoded = index$3.decode(string);
610
+ toBase64 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
611
+ fromBase64 = (string) => this.encoded = index$4.decode(string);
612
612
  toBase58 = (uint8Array) => this.decoded = base58$1.encode(uint8Array);
613
613
  fromBase58 = (string) => this.encoded = base58$1.decode(string);
614
- toBase32 = (uint8Array) => this.decoded = index$8.encode(uint8Array);
615
- fromBase32 = (string) => this.encoded = index$8.decode(string);
616
- toBase16 = (uint8Array) => this.decoded = index$4.encode(uint8Array);
617
- fromBase16 = (string) => this.decoded = index$4.decode(string);
614
+ toBase32 = (uint8Array) => this.decoded = index$9.encode(uint8Array);
615
+ fromBase32 = (string) => this.encoded = index$9.decode(string);
616
+ toBase16 = (uint8Array) => this.decoded = index$5.encode(uint8Array);
617
+ fromBase16 = (string) => this.decoded = index$5.decode(string);
618
618
  };
619
- var index$2 = {
619
+ var index$3 = {
620
620
  fromString: fromString$1,
621
621
  toString: toString$1,
622
622
  fromHex,
@@ -4768,7 +4768,7 @@ function throwFault(fault, operation, value) {
4768
4768
  return logger.throwError(fault, Logger.errors.NUMERIC_FAULT, params);
4769
4769
  }
4770
4770
 
4771
- const { fromString, toString } = index$2;
4771
+ const { fromString, toString } = index$3;
4772
4772
  const isJson = (type) => type === 'object' || 'array';
4773
4773
  const isString = (type) => type === 'string';
4774
4774
  const isNumber = (type) => type === 'number';
@@ -4809,7 +4809,7 @@ const toType = (data) => {
4809
4809
  return new TextEncoder().encode(data.toString());
4810
4810
  throw new Error(`unsuported type ${typeof data || data}`);
4811
4811
  };
4812
- const encode$2 = (proto, input, compress) => {
4812
+ const encode$4 = (proto, input, compress) => {
4813
4813
  const keys = Object.keys(proto);
4814
4814
  const values = Object.values(proto);
4815
4815
  const set = [];
@@ -4824,10 +4824,10 @@ const encode$2 = (proto, input, compress) => {
4824
4824
  // when data is undefined push the default value of the proto
4825
4825
  set.push(toType(data || values[i]));
4826
4826
  }
4827
- return index$6(set);
4827
+ return index$7(set);
4828
4828
  };
4829
- const decode$3 = (proto, uint8Array, compressed) => {
4830
- let deconcated = index$5(uint8Array);
4829
+ const decode$5 = (proto, uint8Array, compressed) => {
4830
+ let deconcated = index$6(uint8Array);
4831
4831
  const output = {};
4832
4832
  const keys = Object.keys(proto);
4833
4833
  const values = Object.values(proto);
@@ -4856,9 +4856,9 @@ const decode$3 = (proto, uint8Array, compressed) => {
4856
4856
  }
4857
4857
  return output;
4858
4858
  };
4859
- var index$1 = {
4860
- encode: encode$2,
4861
- decode: decode$3
4859
+ var index$2 = {
4860
+ encode: encode$4,
4861
+ decode: decode$5
4862
4862
  };
4863
4863
 
4864
4864
  /*!
@@ -5629,23 +5629,23 @@ let BasicInterface$1 = class BasicInterface {
5629
5629
  // get Codec(): Codec {}
5630
5630
  protoEncode(data) {
5631
5631
  // check schema
5632
- return index$1.encode(this.proto, data, false);
5632
+ return index$2.encode(this.proto, data, false);
5633
5633
  }
5634
5634
  protoDecode(data) {
5635
5635
  // check schema
5636
- return index$1.decode(this.proto, data, false);
5636
+ return index$2.decode(this.proto, data, false);
5637
5637
  }
5638
5638
  isHex(string) {
5639
5639
  return isHex(string);
5640
5640
  }
5641
5641
  isBase32(string) {
5642
- return index$8.isBase32(string);
5642
+ return index$9.isBase32(string);
5643
5643
  }
5644
5644
  isBase58(string) {
5645
5645
  return base58$1.isBase58(string);
5646
5646
  }
5647
5647
  fromBs32(encoded) {
5648
- return this.decode(index$8.decode(encoded));
5648
+ return this.decode(index$9.decode(encoded));
5649
5649
  }
5650
5650
  fromBs58(encoded) {
5651
5651
  return this.decode(fromBase58(encoded));
@@ -5707,7 +5707,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5707
5707
  super();
5708
5708
  if (buffer) {
5709
5709
  if (buffer instanceof Uint8Array) {
5710
- const codec = index$7.decode(buffer);
5710
+ const codec = index$8.decode(buffer);
5711
5711
  const name = this.getCodecName(codec);
5712
5712
  if (name) {
5713
5713
  this.name = name;
@@ -5719,7 +5719,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5719
5719
  }
5720
5720
  }
5721
5721
  else if (buffer instanceof ArrayBuffer) {
5722
- const codec = index$7.decode(new Uint8Array(buffer));
5722
+ const codec = index$8.decode(new Uint8Array(buffer));
5723
5723
  const name = this.getCodecName(codec);
5724
5724
  if (name) {
5725
5725
  this.name = name;
@@ -5747,7 +5747,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5747
5747
  }
5748
5748
  }
5749
5749
  fromEncoded(encoded) {
5750
- const codec = index$7.decode(encoded);
5750
+ const codec = index$8.decode(encoded);
5751
5751
  const name = this.getCodecName(codec);
5752
5752
  this.name = name;
5753
5753
  this.encoded = encoded;
@@ -5766,24 +5766,24 @@ let Codec$1 = class Codec extends BasicInterface$1 {
5766
5766
  this.name = this.getCodecName(codec);
5767
5767
  this.hashAlg = this.getHashAlg(this.name);
5768
5768
  this.codec = this.getCodec(this.name);
5769
- this.codecBuffer = index$7.encode(this.codec);
5769
+ this.codecBuffer = index$8.encode(this.codec);
5770
5770
  }
5771
5771
  fromName(name) {
5772
5772
  const codec = this.getCodec(name);
5773
5773
  this.name = name;
5774
5774
  this.codec = codec;
5775
5775
  this.hashAlg = this.getHashAlg(name);
5776
- this.codecBuffer = index$7.encode(this.codec);
5776
+ this.codecBuffer = index$8.encode(this.codec);
5777
5777
  }
5778
5778
  decode(encoded) {
5779
5779
  encoded = encoded || this.encoded;
5780
- const codec = index$7.decode(encoded);
5780
+ const codec = index$8.decode(encoded);
5781
5781
  this.fromCodec(codec);
5782
5782
  return this.decoded;
5783
5783
  }
5784
5784
  encode(codec) {
5785
5785
  codec = codec || this.codec;
5786
- this.encoded = index$7.encode(codec);
5786
+ this.encoded = index$8.encode(codec);
5787
5787
  return this.encoded;
5788
5788
  }
5789
5789
  };
@@ -5839,7 +5839,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5839
5839
  return uint8Array;
5840
5840
  }
5841
5841
  get length() {
5842
- return index$7.encode(this.size);
5842
+ return index$8.encode(this.size);
5843
5843
  }
5844
5844
  get buffer() {
5845
5845
  return this.encoded;
@@ -5879,7 +5879,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5879
5879
  }
5880
5880
  async validate(buffer) {
5881
5881
  if (Buffer.isBuffer(buffer)) {
5882
- const codec = index$7.decode(buffer);
5882
+ const codec = index$8.decode(buffer);
5883
5883
  if (this.codecs[codec]) {
5884
5884
  this.decode(buffer);
5885
5885
  }
@@ -5898,12 +5898,12 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
5898
5898
  }
5899
5899
  decode(buffer) {
5900
5900
  this.encoded = buffer;
5901
- const codec = index$7.decode(buffer);
5901
+ const codec = index$8.decode(buffer);
5902
5902
  this.codec = new Codec$1(codec);
5903
5903
  // TODO: validate codec
5904
- buffer = buffer.slice(index$7.decode.bytes);
5905
- this.size = index$7.decode(buffer);
5906
- this.digest = buffer.slice(index$7.decode.bytes);
5904
+ buffer = buffer.slice(index$8.decode.bytes);
5905
+ this.size = index$8.decode(buffer);
5906
+ this.digest = buffer.slice(index$8.decode.bytes);
5907
5907
  if (this.digest.length !== this.size) {
5908
5908
  throw new Error(`hash length inconsistent: ${this.encoded.toString()}`);
5909
5909
  }
@@ -6459,66 +6459,6 @@ const pbkdf2 = async (password, salt, iterations = 4096, length = 64, hash = 'SH
6459
6459
  }, key, length)
6460
6460
  };
6461
6461
 
6462
- const generateAesKey = async (length = 256) => {
6463
- const key = await subtle.generateKey({
6464
- name: 'AES-CBC',
6465
- length
6466
- }, true, ['encrypt', 'decrypt']);
6467
-
6468
- return key;
6469
- };
6470
-
6471
- const importAesKey = async (exported, format = 'raw', length = 256) => {
6472
- return await subtle.importKey(format, exported, {
6473
- name: 'AES-CBC',
6474
- length
6475
- }, true, ['encrypt', 'decrypt'])
6476
- };
6477
-
6478
- const exportAesKey = async (key, format = 'raw') => {
6479
- return await subtle.exportKey(format, key)
6480
- };
6481
-
6482
- const encryptAes = async (uint8Array, key, iv) => subtle.encrypt({
6483
- name: 'AES-CBC',
6484
- iv,
6485
- }, key, uint8Array);
6486
-
6487
- const decryptAes = async (uint8Array, key, iv) => subtle.decrypt({
6488
- name: 'AES-CBC',
6489
- iv,
6490
- }, key, uint8Array);
6491
-
6492
- const uint8ArrayToHex = uint8Array =>
6493
- [...uint8Array].map(x => x.toString(16).padStart(2, '0')).join('');
6494
-
6495
- const arrayBufferToHex = arrayBuffer =>
6496
- uint8ArrayToHex(new Uint8Array(arrayBuffer));
6497
-
6498
- const hexToUint8Array = hex =>
6499
- new Uint8Array(hex.match(/[\da-f]{2}/gi).map(x => parseInt(x, 16)));
6500
-
6501
- const encrypt$1 = async string => {
6502
- const key = await generateAesKey();
6503
- const iv = randombytes(16);
6504
- const ciphertext = await encryptAes(new TextEncoder().encode(string), key, iv);
6505
- const exported = await exportAesKey(key);
6506
- return {
6507
- key: arrayBufferToHex(exported),
6508
- iv: uint8ArrayToHex(iv),
6509
- cipher: arrayBufferToHex(ciphertext)
6510
- }
6511
- };
6512
-
6513
- const decrypt$1 = async ({cipher, key, iv}) => {
6514
- if (!key.type) key = await importAesKey(hexToUint8Array(key));
6515
- cipher = new Uint8Array(hexToUint8Array(cipher));
6516
- iv = new Uint8Array(hexToUint8Array(iv));
6517
-
6518
- const plaintext = await decryptAes(cipher, key, iv);
6519
- return new TextDecoder().decode(plaintext);
6520
- };
6521
-
6522
6462
  var typedArrayConcat = (input, options = {length: undefined, seperator: undefined}) => {
6523
6463
  if (!options) options = {};
6524
6464
 
@@ -6548,15 +6488,15 @@ var typedArrayConcat = (input, options = {length: undefined, seperator: undefine
6548
6488
  return typedArray
6549
6489
  };
6550
6490
 
6551
- const concatAndDoubleHash = async (input) => {
6491
+ const concatAndDoubleHash$1 = async (input) => {
6552
6492
  return new Uint8Array(await createDoubleHash(typedArrayConcat(input), 'SHA-256'));
6553
6493
  };
6554
6494
 
6555
- const encode$1 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
6495
+ const encode$3 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
6556
6496
  if (!(source instanceof Uint8Array) || !(prefix instanceof Uint8Array)) {
6557
6497
  throw new TypeError('Expected Uint8Array');
6558
6498
  }
6559
- const hash = await concatAndDoubleHash([
6499
+ const hash = await concatAndDoubleHash$1([
6560
6500
  prefix,
6561
6501
  source
6562
6502
  ]);
@@ -6569,11 +6509,11 @@ const encode$1 = async (source, prefix = new TextEncoder().encode('00'), hex) =>
6569
6509
  return base58$1.encodeHex(uint8Array);
6570
6510
  return base58$1.encode(uint8Array);
6571
6511
  };
6572
- const decode$2 = async (string, hex) => {
6512
+ const decode$4 = async (string, hex) => {
6573
6513
  let uint8Array = hex ? base58$1.decodeHex(string) : base58$1.decode(string);
6574
6514
  const prefix = uint8Array.subarray(0, 2);
6575
6515
  const source = uint8Array.subarray(2, -4);
6576
- const hash = await concatAndDoubleHash([
6516
+ const hash = await concatAndDoubleHash$1([
6577
6517
  prefix,
6578
6518
  source
6579
6519
  ]);
@@ -6587,23 +6527,23 @@ const decode$2 = async (string, hex) => {
6587
6527
  }
6588
6528
  return { prefix, data: source };
6589
6529
  };
6590
- const isBase58check = (string, hex) => {
6530
+ const isBase58check$1 = (string, hex) => {
6591
6531
  try {
6592
- hex ? decode$2(string, true) : decode$2(string);
6532
+ hex ? decode$4(string, true) : decode$4(string);
6593
6533
  return true;
6594
6534
  }
6595
6535
  catch (e) {
6596
6536
  return false;
6597
6537
  }
6598
6538
  };
6599
- const encodeHex = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$1(uint8Array, prefix, true);
6600
- const decodeHex = (string) => decode$2(string, true);
6601
- const isBase58checkHex = (string) => isBase58check(string, true);
6602
- var base58check = { encode: encode$1, decode: decode$2, encodeHex, decodeHex, isBase58check, isBase58checkHex };
6539
+ const encodeHex$1 = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$3(uint8Array, prefix, true);
6540
+ const decodeHex$1 = (string) => decode$4(string, true);
6541
+ const isBase58checkHex$1 = (string) => isBase58check$1(string, true);
6542
+ var base58check$1 = { encode: encode$3, decode: decode$4, encodeHex: encodeHex$1, decodeHex: decodeHex$1, isBase58check: isBase58check$1, isBase58checkHex: isBase58checkHex$1 };
6603
6543
 
6604
- const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
6544
+ const decode$3 = (multiWif, expectedVersion, expectedCodec) => {
6605
6545
  const decoded = base58$1.decode(multiWif);
6606
- let [version, codec, privateKey] = index$5(decoded);
6546
+ let [version, codec, privateKey] = index$6(decoded);
6607
6547
  version = Number(new TextDecoder().decode(version));
6608
6548
  codec = Number(new TextDecoder().decode(codec));
6609
6549
  if (expectedVersion && version !== expectedVersion)
@@ -6612,18 +6552,18 @@ const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
6612
6552
  throw new Error(`invalid codec: expected ${expectedCodec} but got ${codec}`);
6613
6553
  return { version, codec, privateKey };
6614
6554
  };
6615
- var index = {
6555
+ var index$1 = {
6616
6556
  encode: (version, codec, privateKey) => {
6617
- return base58$1.encode(index$6([
6557
+ return base58$1.encode(index$7([
6618
6558
  new TextEncoder().encode(version.toString()),
6619
6559
  new TextEncoder().encode(codec.toString()),
6620
6560
  privateKey
6621
6561
  ]));
6622
6562
  },
6623
- decode: decode$1,
6563
+ decode: decode$3,
6624
6564
  isMultiWif: (multiWif) => {
6625
6565
  try {
6626
- const { version, codec, privateKey } = decode$1(multiWif);
6566
+ const { version, codec, privateKey } = decode$3(multiWif);
6627
6567
  if (version === undefined)
6628
6568
  return false;
6629
6569
  if (codec === undefined)
@@ -16285,110 +16225,166 @@ var elliptic = lib(elliptic$1);
16285
16225
 
16286
16226
  var secp256k1 = /*@__PURE__*/getDefaultExportFromCjs(elliptic);
16287
16227
 
16288
- const leofcoinOlivia = {
16289
- messagePrefix: '\u0019Leofcoin Signed Message:',
16290
- version: 1,
16291
- pubKeyHash: 0x73,
16292
- scriptHash: 0x76,
16293
- multiTxHash: 0x8b4125,
16294
- payments: {
16295
- version: 0,
16296
- unspent: 0x1fa443d7 // ounsp
16297
- },
16298
- wif: 0x7D,
16299
- multiCodec: 0x7c4,
16300
- bip32: { public: 0x13BBF2D5, private: 0x13BBCBC5 }
16301
- };
16302
- const bitcoinTestnet = {
16303
- messagePrefix: '\x18Bitcoin Signed Message:\n',
16304
- version: 1,
16305
- bech32: 'tb',
16306
- pubKeyHash: 0x6f,
16307
- scriptHash: 0xc4,
16308
- wif: 0xef,
16309
- bip32: {
16310
- public: 0x043587cf,
16311
- private: 0x04358394
16312
- },
16313
- multiCodec: 0
16314
- };
16315
- var testnets = {
16316
- 'leofcoin:olivia': leofcoinOlivia,
16317
- 'bitcoin:testnet': bitcoinTestnet
16228
+ const leofcoinOlivia = {
16229
+ messagePrefix: '\u0019Leofcoin Signed Message:',
16230
+ version: 1,
16231
+ pubKeyHash: 0x73,
16232
+ scriptHash: 0x76,
16233
+ multiTxHash: 0x8b4125,
16234
+ payments: {
16235
+ version: 0,
16236
+ unspent: 0x1fa443d7 // ounsp
16237
+ },
16238
+ wif: 0x7D,
16239
+ multiCodec: 0x7c4,
16240
+ bip32: { public: 0x13BBF2D5, private: 0x13BBCBC5 }
16241
+ };
16242
+ const bitcoinTestnet = {
16243
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
16244
+ version: 1,
16245
+ bech32: 'tb',
16246
+ pubKeyHash: 0x6f,
16247
+ scriptHash: 0xc4,
16248
+ wif: 0xef,
16249
+ bip32: {
16250
+ public: 0x043587cf,
16251
+ private: 0x04358394
16252
+ },
16253
+ multiCodec: 0
16254
+ };
16255
+ var testnets = {
16256
+ 'leofcoin:olivia': leofcoinOlivia,
16257
+ 'bitcoin:testnet': bitcoinTestnet
16318
16258
  };
16319
16259
 
16320
- // https://en.bitcoin.it/wiki/List_of_address_prefixes
16321
- /**
16322
- * Main network
16323
- * @return {messagePrefix, pubKeyHash, scriptHash, wif, bip32}
16324
- */
16325
- const leofcoin = {
16326
- messagePrefix: '\u0019Leofcoin Signed Message:',
16327
- version: 1,
16328
- pubKeyHash: 0x30,
16329
- scriptHash: 0x37,
16330
- multiTxHash: 0x3adeed,
16331
- payments: {
16332
- version: 0,
16333
- unspent: 0x0d6e0327 // Lunsp
16334
- },
16335
- coin_type: 640,
16336
- wif: 0x3F,
16337
- multiCodec: 0x3c4,
16338
- bip32: { public: 0x13BBF2D4, private: 0x13BBCBC4 },
16339
- testnet: testnets['leofcoin:olivia']
16260
+ // https://en.bitcoin.it/wiki/List_of_address_prefixes
16261
+ // usage:
16262
+ // networks['bitcoin']['testnet']
16263
+ // networks.bitcoin.testnet
16264
+ /**
16265
+ * Main network
16266
+ * @return {messagePrefix, pubKeyHash, scriptHash, wif, bip32}
16267
+ */
16268
+ const leofcoin = {
16269
+ messagePrefix: '\u0019Leofcoin Signed Message:',
16270
+ version: 1,
16271
+ pubKeyHash: 0x30,
16272
+ scriptHash: 0x37,
16273
+ multiTxHash: 0x3adeed,
16274
+ payments: {
16275
+ version: 0,
16276
+ unspent: 0x0d6e0327 // Lunsp
16277
+ },
16278
+ coin_type: 640,
16279
+ wif: 0x3F,
16280
+ multiCodec: 0x3c4,
16281
+ bip32: { public: 0x13BBF2D4, private: 0x13BBCBC4 },
16282
+ testnet: testnets['leofcoin:olivia']
16283
+ };
16284
+ const bitcoin = {
16285
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
16286
+ version: 1,
16287
+ bech32: 'bc',
16288
+ pubKeyHash: 0x00,
16289
+ multiCodec: 0x00,
16290
+ scriptHash: 0x05,
16291
+ wif: 0x80,
16292
+ coin_type: 0,
16293
+ bip32: {
16294
+ public: 0x0488b21e, private: 0x0488ade4
16295
+ },
16296
+ testnet: testnets['bitcoin:testnet']
16297
+ };
16298
+ const litecoin = {
16299
+ messagePrefix: '\x19Litecoin Signed Message:\n',
16300
+ version: 1,
16301
+ pubKeyHash: 0x30,
16302
+ scriptHash: 0x32,
16303
+ wif: 0xb0,
16304
+ bip32: {
16305
+ public: 0x019da462,
16306
+ private: 0x019d9cfe
16307
+ },
16308
+ bech32: '',
16309
+ multiCodec: 0
16310
+ };
16311
+ const ethereum = {
16312
+ messagePrefix: '\x19Ethereum Signed Message:\n',
16313
+ version: 1,
16314
+ pubKeyHash: 0x30,
16315
+ scriptHash: 0x32,
16316
+ bip32: {
16317
+ private: 0x0488ADE4, public: 0x0488B21E
16318
+ },
16319
+ coin_type: 60,
16320
+ wif: 0x45,
16321
+ multiCodec: 0x3c5
16322
+ };
16323
+ /**
16324
+ * Our & supported networks
16325
+ * @return {leofcoin, olivia}
16326
+ */
16327
+ var networks = {
16328
+ leofcoin,
16329
+ bitcoin,
16330
+ litecoin,
16331
+ ethereum
16332
+ };
16333
+
16334
+ const concatAndDoubleHash = async (input) => {
16335
+ return new Uint8Array(await createDoubleHash(typedArrayConcat(input), 'SHA-256'));
16340
16336
  };
16341
- const bitcoin = {
16342
- messagePrefix: '\x18Bitcoin Signed Message:\n',
16343
- version: 1,
16344
- bech32: 'bc',
16345
- pubKeyHash: 0x00,
16346
- multiCodec: 0x00,
16347
- scriptHash: 0x05,
16348
- wif: 0x80,
16349
- coin_type: 0,
16350
- bip32: {
16351
- public: 0x0488b21e, private: 0x0488ade4
16352
- },
16353
- testnet: testnets['bitcoin:testnet']
16337
+
16338
+ const encode$2 = async (source, prefix = new TextEncoder().encode('00'), hex) => {
16339
+ if (!(source instanceof Uint8Array) || !(prefix instanceof Uint8Array)) {
16340
+ throw new TypeError('Expected Uint8Array');
16341
+ }
16342
+ const hash = await concatAndDoubleHash([
16343
+ prefix,
16344
+ source
16345
+ ]);
16346
+ const uint8Array = typedArrayConcat([
16347
+ prefix,
16348
+ source,
16349
+ hash.subarray(0, 4)
16350
+ ]);
16351
+ if (hex)
16352
+ return base58$1.encodeHex(uint8Array);
16353
+ return base58$1.encode(uint8Array);
16354
16354
  };
16355
- const litecoin = {
16356
- messagePrefix: '\x19Litecoin Signed Message:\n',
16357
- version: 1,
16358
- pubKeyHash: 0x30,
16359
- scriptHash: 0x32,
16360
- wif: 0xb0,
16361
- bip32: {
16362
- public: 0x019da462,
16363
- private: 0x019d9cfe
16364
- },
16365
- bech32: '',
16366
- multiCodec: 0
16355
+ const decode$2 = async (string, hex) => {
16356
+ let uint8Array = hex ? base58$1.decodeHex(string) : base58$1.decode(string);
16357
+ const prefix = uint8Array.subarray(0, 2);
16358
+ const source = uint8Array.subarray(2, -4);
16359
+ const hash = await concatAndDoubleHash([
16360
+ prefix,
16361
+ source
16362
+ ]);
16363
+ let index = 0;
16364
+ const slice = uint8Array.subarray(-4);
16365
+ for (const check of slice) {
16366
+ if (check !== hash[index]) {
16367
+ throw new Error('Invalid checksum');
16368
+ }
16369
+ index++;
16370
+ }
16371
+ return { prefix, data: source };
16367
16372
  };
16368
- const ethereum = {
16369
- messagePrefix: '\x19Ethereum Signed Message:\n',
16370
- version: 1,
16371
- pubKeyHash: 0x30,
16372
- scriptHash: 0x32,
16373
- bip32: {
16374
- private: 0x0488ADE4, public: 0x0488B21E
16375
- },
16376
- coin_type: 60,
16377
- wif: 0x45,
16378
- multiCodec: 0x3c5
16373
+ const isBase58check = (string, hex) => {
16374
+ try {
16375
+ hex ? decode$2(string, true) : decode$2(string);
16376
+ return true;
16377
+ }
16378
+ catch (e) {
16379
+ return false;
16380
+ }
16379
16381
  };
16380
- /**
16381
- * Our & supported networks
16382
- * @return {leofcoin, olivia}
16383
- */
16384
- var networks = {
16385
- leofcoin,
16386
- bitcoin,
16387
- litecoin,
16388
- ethereum
16389
- };
16382
+ const encodeHex = (uint8Array, prefix = new TextEncoder().encode('00')) => encode$2(uint8Array, prefix, true);
16383
+ const decodeHex = (string) => decode$2(string, true);
16384
+ const isBase58checkHex = (string) => isBase58check(string, true);
16385
+ var base58check = { encode: encode$2, decode: decode$2, encodeHex, decodeHex, isBase58check, isBase58checkHex };
16390
16386
 
16391
- const encode = (version, privateKey, compressed) => {
16387
+ const encode$1 = (version, privateKey, compressed) => {
16392
16388
  if (privateKey.length !== 32)
16393
16389
  throw new TypeError(`Invalid privateKey length: expected 32 got ${privateKey.length}`);
16394
16390
  const uint8Array = new Uint8Array(compressed ? 34 : 33);
@@ -16399,7 +16395,7 @@ const encode = (version, privateKey, compressed) => {
16399
16395
  }
16400
16396
  return base58check.encode(uint8Array);
16401
16397
  };
16402
- const decode = async (wif, version) => {
16398
+ const decode$1 = async (wif, version) => {
16403
16399
  wif = (await base58check.decode(wif)).data;
16404
16400
  if (version && wif[0] !== version)
16405
16401
  throw new Error('Invalid network version');
@@ -16414,207 +16410,208 @@ const decode = async (wif, version) => {
16414
16410
  compressed: wif.length === 33 ? false : true
16415
16411
  };
16416
16412
  };
16417
- var wif = { encode, decode };
16418
-
16419
- const HIGHEST_BIT = 0x80000000;
16420
- const { publicKeyCreate, publicKeyVerify, privateKeyVerify, privateKeyTweakAdd, ecdh } = secp256k1;
16421
- class HdNode {
16422
- #privateKey;
16423
- #publicKey;
16424
- #chainCode;
16425
- #network;
16426
- #depth;
16427
- #index;
16428
- #parentFingerprint;
16429
- constructor(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16430
- this.init(privateKey, publicKey, chainCode, network, depth, index, parentFingerprint);
16431
- }
16432
- init(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16433
- this.#privateKey = privateKey;
16434
- this.#publicKey = publicKey;
16435
- this.#chainCode = chainCode;
16436
- this.#network = network || networks.leofcoin;
16437
- this.#depth = depth;
16438
- this.#index = index;
16439
- this.#parentFingerprint = parentFingerprint;
16440
- }
16441
- get network() {
16442
- return this.#network;
16443
- }
16444
- get publicKey() {
16445
- this.#publicKey = this.#publicKey || publicKeyCreate(this.#privateKey, true);
16446
- return this.#publicKey;
16447
- }
16448
- get privateKey() {
16449
- return this.#privateKey;
16450
- }
16451
- get identifier() {
16452
- return this.hash160(this.publicKey);
16453
- }
16454
- get fingerprint() {
16455
- return (async () => (await this.identifier).subarray(0, 4))();
16456
- }
16457
- async hash160(data) {
16458
- const hash = await createHash(data, 'SHA-256');
16459
- return (await createRIPEMD160()).update(new Uint8Array(hash)).digest('binary');
16460
- }
16461
- get isNeutered() {
16462
- return this.#privateKey === undefined;
16463
- }
16464
- get neutered() {
16465
- return new HdNode(undefined, this.#publicKey, this.#chainCode, this.#network, this.#depth, this.#index, this.#parentFingerprint);
16466
- }
16467
- fromPrivateKey(privateKey, chainCode, network) {
16468
- if (!privateKeyVerify(privateKey))
16469
- throw new TypeError('Private key not in range [1, n)');
16470
- return new HdNode(privateKey, publicKeyCreate(privateKey, true), chainCode, network);
16471
- }
16472
- fromPublicKey(publicKey, chainCode, network) {
16473
- // verify the X coordinate is a point on the curve
16474
- if (!publicKeyVerify(publicKey))
16475
- throw new TypeError('Point is not on the curve');
16476
- return new HdNode(undefined, publicKey, chainCode, network);
16477
- }
16478
- async fromSeed(seed, network) {
16479
- if (seed.length < 16)
16480
- throw new TypeError('Seed should be at least 128 bits');
16481
- if (seed.length > 64)
16482
- throw new TypeError('Seed should be at most 512 bits');
16483
- let hash = (await createHMAC(createSHA512(), new TextEncoder().encode('Bitcoin seed')))
16484
- .update(seed)
16485
- .digest('binary');
16486
- const privateKey = hash.subarray(0, 32);
16487
- const chainCode = hash.subarray(32);
16488
- return this.fromPrivateKey(privateKey, chainCode, network);
16489
- }
16490
- async toBase58() {
16491
- const network = this.#network || networks.leofcoin;
16492
- let version = !this.isNeutered
16493
- ? network.bip32.private
16494
- : network.bip32.public;
16495
- const set = [
16496
- new TextEncoder().encode(version.toString()),
16497
- new TextEncoder().encode(this.#depth.toString()),
16498
- new TextEncoder().encode(this.#parentFingerprint.toString()),
16499
- new TextEncoder().encode(this.#index.toString()),
16500
- this.#chainCode
16501
- ];
16502
- if (!this.isNeutered) {
16503
- set.push(new TextEncoder().encode('0'));
16504
- set.push(new Uint8Array(this.privateKey));
16505
- }
16506
- else {
16507
- set.push(new Uint8Array(this.publicKey));
16508
- }
16509
- return base58check.encode(index$6(set));
16510
- }
16511
- toWIF() {
16512
- if (!this.#privateKey)
16513
- throw new TypeError('Missing private key');
16514
- return wif.encode(this.#network.wif, this.#privateKey, true);
16515
- }
16516
- // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
16517
- async derive(index) {
16518
- const isHardened = index >= HIGHEST_BIT;
16519
- let data;
16520
- // Hardened child
16521
- if (isHardened) {
16522
- if (this.isNeutered)
16523
- throw new TypeError('Missing private key for hardened child key');
16524
- // data = 0x00 || ser256(kpar) || ser32(index)
16525
- data = index$6([
16526
- new TextEncoder().encode('0'),
16527
- this.privateKey,
16528
- new TextEncoder().encode(index.toString())
16529
- ]);
16530
- }
16531
- else {
16532
- data = index$6([
16533
- this.publicKey,
16534
- new TextEncoder().encode(index.toString())
16535
- ]);
16536
- }
16537
- const hash = (await createHMAC(createSHA512(), this.#chainCode))
16538
- .update(data)
16539
- .digest('binary');
16540
- const privateKey = hash.subarray(0, 32);
16541
- const chainCode = hash.subarray(32);
16542
- // if parse256(privateKey) >= n, proceed with the next value for i
16543
- if (!privateKeyVerify(privateKey))
16544
- return this.derive(index + 1);
16545
- // Private parent key -> private child key
16546
- if (!this.isNeutered) {
16547
- // ki = parse256(privateKey) + kpar (mod n)
16548
- const ki = privateKeyTweakAdd(this.privateKey, privateKey);
16549
- // In case ki == 0, proceed with the next value for i
16550
- if (ki == null)
16551
- return this.derive(index + 1);
16552
- return new HdNode(ki, null, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16553
- }
16554
- function hashfn(x, y) {
16555
- const pubKey = new Uint8Array(33);
16556
- pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03;
16557
- pubKey.set(x, 1);
16558
- return pubKey;
16559
- }
16560
- const Ki = ecdh(this.publicKey, chainCode, { hashfn }, new Uint8Array(33));
16561
- // const Ki = new Uint8Array(ecc.pointAddScalar(this.publicKey, IL, true));
16562
- // In case Ki is the point at infinity, proceed with the next value for i
16563
- if (Ki === null)
16564
- return this.derive(index + 1);
16565
- return new HdNode(undefined, Ki, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16566
- }
16567
- deriveHardened(index) {
16568
- // Only derives hardened private keys by default
16569
- return this.derive(index + HIGHEST_BIT);
16570
- }
16571
- async derivePath(path) {
16572
- let splitPath = path.split('/');
16573
- if (splitPath[0] === 'm') {
16574
- if (this.#parentFingerprint)
16575
- throw new TypeError('Expected master, got child');
16576
- splitPath = splitPath.slice(1);
16577
- }
16578
- let prevHd = this;
16579
- for (const indexString of splitPath) {
16580
- let index;
16581
- if (indexString.slice(-1) === `'`) {
16582
- index = parseInt(indexString.slice(0, -1), 10);
16583
- prevHd = await prevHd.deriveHardened(index);
16584
- }
16585
- else {
16586
- index = parseInt(indexString, 10);
16587
- prevHd = await prevHd.derive(index);
16588
- }
16589
- }
16590
- return prevHd;
16591
- }
16592
- async fromBase58(string, network) {
16593
- let buffer = (await base58check.decode(string)).data;
16594
- network = network || networks.leofcoin;
16595
- // 4 bytes: version bytes
16596
- let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$5(buffer);
16597
- version = Number(new TextDecoder().decode(version));
16598
- depth = Number(new TextDecoder().decode(depth));
16599
- parentFingerprint = Number(new TextDecoder().decode(parentFingerprint));
16600
- index = Number(new TextDecoder().decode(index));
16601
- k = privateKey ? 0 : k;
16602
- if (version !== network.bip32.private && version !== network.bip32.public)
16603
- throw new TypeError('Invalid network version');
16604
- if (depth === 0) {
16605
- if (parentFingerprint !== 0)
16606
- throw new TypeError('Invalid parent fingerprint');
16607
- }
16608
- if (depth === 0 && index !== 0)
16609
- throw new TypeError('Invalid index');
16610
- if (version === network.bip32.private) {
16611
- if (k !== 0x00)
16612
- throw new TypeError('Invalid private key');
16613
- return new HdNode(privateKey, undefined, chainCode, network, depth, index, parentFingerprint);
16614
- }
16615
- this.init(undefined, k, chainCode, network, depth, index, parentFingerprint);
16616
- return new HdNode(undefined, k, chainCode, network, depth, index, parentFingerprint);
16617
- }
16413
+ var wif = { encode: encode$1, decode: decode$1 };
16414
+
16415
+ const HIGHEST_BIT = 0x80000000;
16416
+ const { publicKeyCreate, publicKeyVerify, privateKeyVerify, privateKeyTweakAdd, ecdh } = secp256k1;
16417
+ class HdNode {
16418
+ #privateKey;
16419
+ #publicKey;
16420
+ #chainCode;
16421
+ #network;
16422
+ #depth;
16423
+ #index;
16424
+ #parentFingerprint;
16425
+ constructor(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16426
+ this.init(privateKey, publicKey, chainCode, network, depth, index, parentFingerprint);
16427
+ }
16428
+ init(privateKey, publicKey, chainCode, network, depth = 0, index = 0, parentFingerprint = 0x00000000) {
16429
+ this.#privateKey = privateKey;
16430
+ this.#publicKey = publicKey;
16431
+ this.#chainCode = chainCode;
16432
+ this.#network = network || networks.leofcoin;
16433
+ this.#depth = depth;
16434
+ this.#index = index;
16435
+ this.#parentFingerprint = parentFingerprint;
16436
+ }
16437
+ get network() {
16438
+ return this.#network;
16439
+ }
16440
+ get publicKey() {
16441
+ this.#publicKey = this.#publicKey || publicKeyCreate(this.#privateKey, true);
16442
+ return this.#publicKey;
16443
+ }
16444
+ get privateKey() {
16445
+ return this.#privateKey;
16446
+ }
16447
+ get identifier() {
16448
+ return this.hash160(this.publicKey);
16449
+ }
16450
+ get fingerprint() {
16451
+ return (async () => (await this.identifier).subarray(0, 4))();
16452
+ }
16453
+ async hash160(data) {
16454
+ const hash = await createHash(data, 'SHA-256');
16455
+ return (await createRIPEMD160()).update(new Uint8Array(hash)).digest('binary');
16456
+ }
16457
+ get isNeutered() {
16458
+ return this.#privateKey === undefined;
16459
+ }
16460
+ get neutered() {
16461
+ return new HdNode(undefined, this.#publicKey, this.#chainCode, this.#network, this.#depth, this.#index, this.#parentFingerprint);
16462
+ }
16463
+ fromPrivateKey(privateKey, chainCode, network) {
16464
+ if (!privateKeyVerify(privateKey))
16465
+ throw new TypeError('Private key not in range [1, n)');
16466
+ const publicKey = publicKeyCreate(privateKey, true);
16467
+ return new HdNode(privateKey, publicKey, publicKey.slice(1), network);
16468
+ }
16469
+ fromPublicKey(publicKey, chainCode, network) {
16470
+ // verify the X coordinate is a point on the curve
16471
+ if (!publicKeyVerify(publicKey))
16472
+ throw new TypeError('Point is not on the curve');
16473
+ return new HdNode(undefined, publicKey, chainCode, network);
16474
+ }
16475
+ async fromSeed(seed, network) {
16476
+ if (seed.length < 16)
16477
+ throw new TypeError('Seed should be at least 128 bits');
16478
+ if (seed.length > 64)
16479
+ throw new TypeError('Seed should be at most 512 bits');
16480
+ let hash = (await createHMAC(createSHA512(), new TextEncoder().encode('Bitcoin seed')))
16481
+ .update(seed)
16482
+ .digest('binary');
16483
+ const privateKey = hash.subarray(0, 32);
16484
+ const chainCode = hash.subarray(32);
16485
+ return this.fromPrivateKey(privateKey, chainCode, network);
16486
+ }
16487
+ async toBase58() {
16488
+ const network = this.#network || networks.leofcoin;
16489
+ let version = !this.isNeutered
16490
+ ? network.bip32.private
16491
+ : network.bip32.public;
16492
+ const set = [
16493
+ new TextEncoder().encode(version.toString()),
16494
+ new TextEncoder().encode(this.#depth.toString()),
16495
+ new TextEncoder().encode(this.#parentFingerprint.toString()),
16496
+ new TextEncoder().encode(this.#index.toString()),
16497
+ this.#chainCode
16498
+ ];
16499
+ if (!this.isNeutered) {
16500
+ set.push(new TextEncoder().encode('0'));
16501
+ set.push(new Uint8Array(this.privateKey));
16502
+ }
16503
+ else {
16504
+ set.push(new Uint8Array(this.publicKey));
16505
+ }
16506
+ return base58check$1.encode(index$7(set));
16507
+ }
16508
+ toWIF() {
16509
+ if (!this.#privateKey)
16510
+ throw new TypeError('Missing private key');
16511
+ return wif.encode(this.#network.wif, this.#privateKey, true);
16512
+ }
16513
+ // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
16514
+ async derive(index) {
16515
+ const isHardened = index >= HIGHEST_BIT;
16516
+ let data;
16517
+ // Hardened child
16518
+ if (isHardened) {
16519
+ if (this.isNeutered)
16520
+ throw new TypeError('Missing private key for hardened child key');
16521
+ // data = 0x00 || ser256(kpar) || ser32(index)
16522
+ data = index$7([
16523
+ new TextEncoder().encode('0'),
16524
+ this.privateKey,
16525
+ new TextEncoder().encode(index.toString())
16526
+ ]);
16527
+ }
16528
+ else {
16529
+ data = index$7([
16530
+ this.publicKey,
16531
+ new TextEncoder().encode(index.toString())
16532
+ ]);
16533
+ }
16534
+ const hash = (await createHMAC(createSHA512(), this.#chainCode))
16535
+ .update(data)
16536
+ .digest('binary');
16537
+ const privateKey = hash.subarray(0, 32);
16538
+ const chainCode = hash.subarray(32);
16539
+ // if parse256(privateKey) >= n, proceed with the next value for i
16540
+ if (!privateKeyVerify(privateKey))
16541
+ return this.derive(index + 1);
16542
+ // Private parent key -> private child key
16543
+ if (!this.isNeutered) {
16544
+ // ki = parse256(privateKey) + kpar (mod n)
16545
+ const ki = privateKeyTweakAdd(this.privateKey, privateKey);
16546
+ // In case ki == 0, proceed with the next value for i
16547
+ if (ki == null)
16548
+ return this.derive(index + 1);
16549
+ return new HdNode(ki, null, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16550
+ }
16551
+ function hashfn(x, y) {
16552
+ const pubKey = new Uint8Array(33);
16553
+ pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03;
16554
+ pubKey.set(x, 1);
16555
+ return pubKey;
16556
+ }
16557
+ const Ki = ecdh(this.publicKey, chainCode, { hashfn }, new Uint8Array(33));
16558
+ // const Ki = new Uint8Array(ecc.pointAddScalar(this.publicKey, IL, true));
16559
+ // In case Ki is the point at infinity, proceed with the next value for i
16560
+ if (Ki === null)
16561
+ return this.derive(index + 1);
16562
+ return new HdNode(undefined, Ki, chainCode, this.#network, this.#depth + 1, index, (await this.fingerprint)[0]);
16563
+ }
16564
+ deriveHardened(index) {
16565
+ // Only derives hardened private keys by default
16566
+ return this.derive(index + HIGHEST_BIT);
16567
+ }
16568
+ async derivePath(path) {
16569
+ let splitPath = path.split('/');
16570
+ if (splitPath[0] === 'm') {
16571
+ if (this.#parentFingerprint)
16572
+ throw new TypeError('Expected master, got child');
16573
+ splitPath = splitPath.slice(1);
16574
+ }
16575
+ let prevHd = this;
16576
+ for (const indexString of splitPath) {
16577
+ let index;
16578
+ if (indexString.slice(-1) === `'`) {
16579
+ index = parseInt(indexString.slice(0, -1), 10);
16580
+ prevHd = await prevHd.deriveHardened(index);
16581
+ }
16582
+ else {
16583
+ index = parseInt(indexString, 10);
16584
+ prevHd = await prevHd.derive(index);
16585
+ }
16586
+ }
16587
+ return prevHd;
16588
+ }
16589
+ async fromBase58(string, network) {
16590
+ let buffer = (await base58check$1.decode(string)).data;
16591
+ network = network || networks.leofcoin;
16592
+ // 4 bytes: version bytes
16593
+ let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$6(buffer);
16594
+ version = Number(new TextDecoder().decode(version));
16595
+ depth = Number(new TextDecoder().decode(depth));
16596
+ parentFingerprint = Number(new TextDecoder().decode(parentFingerprint));
16597
+ index = Number(new TextDecoder().decode(index));
16598
+ k = privateKey ? 0 : k;
16599
+ if (version !== network.bip32.private && version !== network.bip32.public)
16600
+ throw new TypeError('Invalid network version');
16601
+ if (depth === 0) {
16602
+ if (parentFingerprint !== 0)
16603
+ throw new TypeError('Invalid parent fingerprint');
16604
+ }
16605
+ if (depth === 0 && index !== 0)
16606
+ throw new TypeError('Invalid index');
16607
+ if (version === network.bip32.private) {
16608
+ if (k !== 0x00)
16609
+ throw new TypeError('Invalid private key');
16610
+ return new HdNode(privateKey, undefined, chainCode, network, depth, index, parentFingerprint);
16611
+ }
16612
+ this.init(undefined, k, chainCode, network, depth, index, parentFingerprint);
16613
+ return new HdNode(undefined, k, chainCode, network, depth, index, parentFingerprint);
16614
+ }
16618
16615
  }
16619
16616
 
16620
16617
  // see https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
@@ -16667,144 +16664,145 @@ class Mnemonic {
16667
16664
  }
16668
16665
  }
16669
16666
 
16670
- const fromNetworkString = network => {
16671
- const parts = network.split(':');
16672
- network = networks[parts[0]];
16673
- if (parts[1]) {
16674
- if (network[parts[1]])
16675
- network = network[parts[1]];
16676
- network.coin_type = 1;
16677
- }
16678
- return network;
16679
- };
16680
- const publicKeyToEthereumAddress = async (publicKeyBuffer) => {
16681
- const hasher = await createKeccak(256);
16682
- hasher.update(publicKeyBuffer);
16683
- const hash = hasher.digest();
16684
- return `0x${hash.slice(-40).toString()}`;
16685
- };
16686
- class HDWallet {
16687
- hdnode;
16688
- networkName;
16689
- version;
16690
- locked;
16691
- network;
16692
- multiCodec;
16693
- get privateKey() {
16694
- return this.ifNotLocked(() => this.hdnode.privateKey);
16695
- }
16696
- get publicKey() {
16697
- return this.hdnode.publicKey;
16698
- }
16699
- async ethereumAddress() {
16700
- const address = await publicKeyToEthereumAddress(this.publicKey);
16701
- return address;
16702
- }
16703
- leofcoinAddress() {
16704
- return base58check.encode(this.publicKey);
16705
- }
16706
- get address() {
16707
- return this.getAddressForCoin();
16708
- }
16709
- async getAddressForCoin(coin_type) {
16710
- if (!coin_type)
16711
- coin_type = this.network.coin_type;
16712
- if (coin_type === 1) {
16713
- if (this.networkName?.split(':')[0] === 'ethereum')
16714
- coin_type = 60;
16715
- if (this.networkName?.split(':')[0] === 'leofcoin')
16716
- coin_type = 640;
16717
- }
16718
- // if (coin_type === 0) return this.bitcoinAddress
16719
- if (coin_type === 60)
16720
- return this.ethereumAddress();
16721
- if (coin_type === 640)
16722
- return this.leofcoinAddress();
16723
- }
16724
- get accountAddress() {
16725
- return this.ifNotLocked(async () => base58check.encode(this.hdnode.publicKey));
16726
- }
16727
- get isTestnet() {
16728
- return this.network.coin_type === 1;
16729
- }
16730
- constructor(network, hdnode) {
16731
- if (typeof network === 'string') {
16732
- this.networkName = network;
16733
- this.network = fromNetworkString(network);
16734
- }
16735
- else if (typeof network === 'object')
16736
- this.network = network;
16737
- this.multiCodec = this.network.multiCodec;
16738
- this.version = 0x00;
16739
- if (hdnode)
16740
- this.defineHDNode(hdnode);
16741
- }
16742
- ifNotLocked(fn, params) {
16743
- if (this.locked)
16744
- return;
16745
- return params ? fn(...params) : fn();
16746
- }
16747
- async defineHDNode(value) {
16748
- Object.defineProperty(this, 'hdnode', {
16749
- configurable: false,
16750
- writable: false,
16751
- value: await value
16752
- });
16753
- }
16754
- validateNetwork(network) {
16755
- if (!network && !this.network)
16756
- return console.error(`expected network to be defined`);
16757
- if (!network && this.network)
16758
- network = this.network;
16759
- if (typeof network === 'string')
16760
- network = fromNetworkString(network);
16761
- if (typeof network !== 'object')
16762
- return console.error('network not found');
16763
- return network;
16764
- }
16765
- async generate(password, network) {
16766
- network = this.validateNetwork(network);
16767
- const mnemonic = await new Mnemonic().generate(512);
16768
- const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16769
- await this.defineHDNode(await (new HdNode()).fromSeed(new Uint8Array(seed), network));
16770
- return mnemonic;
16771
- }
16772
- /**
16773
- * recover using mnemonic (recovery word list)
16774
- */
16775
- async recover(mnemonic, password, network) {
16776
- network = this.validateNetwork(network || password);
16777
- const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16778
- let node = new HdNode();
16779
- node = await node.fromSeed(new Uint8Array(seed), network);
16780
- await this.defineHDNode(await node.fromSeed(new Uint8Array(seed), network));
16781
- }
16782
- async load(base58, network) {
16783
- network = this.validateNetwork(network);
16784
- await this.defineHDNode(await (new HdNode()).fromBase58(base58, network));
16785
- }
16786
- save() {
16787
- return this.hdnode.toBase58();
16788
- }
16789
- async fromAddress(address, chainCode, network) {
16790
- network = this.validateNetwork(network);
16791
- address = (await base58check.decode(address)).data;
16792
- if (!chainCode || chainCode && !Buffer.isBuffer(chainCode))
16793
- chainCode = address.slice(1);
16794
- await this.defineHDNode(await (new HdNode()).fromPublicKey(address, chainCode, network));
16795
- }
16796
- async fromPublicKey(hex, chainCode, network) {
16797
- network = this.validateNetwork(network);
16798
- if (!chainCode || chainCode)
16799
- chainCode = hex.slice(1);
16800
- let node = new HdNode();
16801
- node = await node.fromPublicKey(hex, chainCode, network);
16802
- await this.defineHDNode(node);
16803
- return this;
16804
- }
16805
- async fromPrivateKey(privateKey, chainCode, network) {
16806
- await this.defineHDNode(await (new HdNode()).fromPrivateKey(privateKey, chainCode, network));
16807
- }
16667
+ const fromNetworkString = network => {
16668
+ const parts = network.split(':');
16669
+ network = networks[parts[0]];
16670
+ if (parts[1]) {
16671
+ if (network[parts[1]])
16672
+ network = network[parts[1]];
16673
+ network.coin_type = 1;
16674
+ }
16675
+ return network;
16676
+ };
16677
+ const publicKeyToEthereumAddress = async (publicKeyBuffer) => {
16678
+ const hasher = await createKeccak(256);
16679
+ hasher.update(publicKeyBuffer);
16680
+ const hash = hasher.digest();
16681
+ return `0x${hash.slice(-40).toString()}`;
16682
+ };
16683
+ class HDWallet {
16684
+ hdnode;
16685
+ networkName;
16686
+ version;
16687
+ locked;
16688
+ network;
16689
+ multiCodec;
16690
+ get privateKey() {
16691
+ return this.ifNotLocked(() => this.hdnode.privateKey);
16692
+ }
16693
+ get publicKey() {
16694
+ return this.hdnode.publicKey;
16695
+ }
16696
+ async ethereumAddress() {
16697
+ const address = await publicKeyToEthereumAddress(this.publicKey);
16698
+ return address;
16699
+ }
16700
+ leofcoinAddress() {
16701
+ return base58check$1.encode(this.publicKey);
16702
+ }
16703
+ get address() {
16704
+ return this.getAddressForCoin();
16705
+ }
16706
+ async getAddressForCoin(coin_type) {
16707
+ if (!coin_type)
16708
+ coin_type = this.network.coin_type;
16709
+ if (coin_type === 1) {
16710
+ if (this.networkName?.split(':')[0] === 'ethereum')
16711
+ coin_type = 60;
16712
+ if (this.networkName?.split(':')[0] === 'leofcoin')
16713
+ coin_type = 640;
16714
+ }
16715
+ // if (coin_type === 0) return this.bitcoinAddress
16716
+ if (coin_type === 60)
16717
+ return this.ethereumAddress();
16718
+ if (coin_type === 640)
16719
+ return this.leofcoinAddress();
16720
+ // if (coin_type === 0) return this.bitcoinAddress()
16721
+ }
16722
+ get accountAddress() {
16723
+ return this.ifNotLocked(async () => base58check$1.encode(this.hdnode.publicKey));
16724
+ }
16725
+ get isTestnet() {
16726
+ return this.network.coin_type === 1;
16727
+ }
16728
+ constructor(network, hdnode) {
16729
+ if (typeof network === 'string') {
16730
+ this.networkName = network;
16731
+ this.network = fromNetworkString(network);
16732
+ }
16733
+ else if (typeof network === 'object')
16734
+ this.network = network;
16735
+ this.multiCodec = this.network.multiCodec;
16736
+ this.version = 0x00;
16737
+ if (hdnode)
16738
+ this.defineHDNode(hdnode);
16739
+ }
16740
+ ifNotLocked(fn, params) {
16741
+ if (this.locked)
16742
+ return;
16743
+ return params ? fn(...params) : fn();
16744
+ }
16745
+ async defineHDNode(value) {
16746
+ Object.defineProperty(this, 'hdnode', {
16747
+ configurable: false,
16748
+ writable: false,
16749
+ value: await value
16750
+ });
16751
+ }
16752
+ validateNetwork(network) {
16753
+ if (!network && !this.network)
16754
+ return console.error(`expected network to be defined`);
16755
+ if (!network && this.network)
16756
+ network = this.network;
16757
+ if (typeof network === 'string')
16758
+ network = fromNetworkString(network);
16759
+ if (typeof network !== 'object')
16760
+ return console.error('network not found');
16761
+ return network;
16762
+ }
16763
+ async generate(password, network) {
16764
+ network = this.validateNetwork(network);
16765
+ const mnemonic = await new Mnemonic().generate(512);
16766
+ const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16767
+ await this.defineHDNode(await (new HdNode()).fromSeed(new Uint8Array(seed), network));
16768
+ return mnemonic;
16769
+ }
16770
+ /**
16771
+ * recover using mnemonic (recovery word list)
16772
+ */
16773
+ async recover(mnemonic, password, network) {
16774
+ network = this.validateNetwork(network || password);
16775
+ const seed = await new Mnemonic().seedFromMnemonic(mnemonic, password, 512);
16776
+ let node = new HdNode();
16777
+ node = await node.fromSeed(new Uint8Array(seed), network);
16778
+ await this.defineHDNode(await node.fromSeed(new Uint8Array(seed), network));
16779
+ }
16780
+ async load(base58, network) {
16781
+ network = this.validateNetwork(network);
16782
+ await this.defineHDNode(await (new HdNode()).fromBase58(base58, network));
16783
+ }
16784
+ save() {
16785
+ return this.hdnode.toBase58();
16786
+ }
16787
+ async fromAddress(address, chainCode, network) {
16788
+ network = this.validateNetwork(network);
16789
+ address = (await base58check$1.decode(address)).data;
16790
+ if (!chainCode || chainCode && !Buffer.isBuffer(chainCode))
16791
+ chainCode = address.slice(1);
16792
+ await this.defineHDNode(await (new HdNode()).fromPublicKey(address, chainCode, network));
16793
+ }
16794
+ async fromPublicKey(hex, chainCode, network) {
16795
+ network = this.validateNetwork(network);
16796
+ if (!chainCode || chainCode)
16797
+ chainCode = hex.slice(1);
16798
+ let node = new HdNode();
16799
+ node = await node.fromPublicKey(hex, chainCode, network);
16800
+ await this.defineHDNode(node);
16801
+ return this;
16802
+ }
16803
+ async fromPrivateKey(privateKey, chainCode, network) {
16804
+ await this.defineHDNode(await (new HdNode()).fromPrivateKey(privateKey, chainCode, network));
16805
+ }
16808
16806
  }
16809
16807
 
16810
16808
  class MultiSignature {
@@ -16862,8 +16860,8 @@ class MultiSignature {
16862
16860
  if (!signature)
16863
16861
  throw ReferenceError('signature undefined');
16864
16862
  this.#multiSignature = typedArrayConcat([
16865
- index$7.encode(this.version),
16866
- index$7.encode(this.multiCodec),
16863
+ index$8.encode(this.version),
16864
+ index$8.encode(this.multiCodec),
16867
16865
  signature
16868
16866
  ]);
16869
16867
  return this.multiSignature;
@@ -16879,10 +16877,10 @@ class MultiSignature {
16879
16877
  if (!this.multiSignature)
16880
16878
  throw ReferenceError('multiSignature undefined');
16881
16879
  let buffer = this.multiSignature;
16882
- const version = index$7.decode(buffer);
16883
- buffer = buffer.subarray(index$7.decode.bytes);
16884
- const codec = index$7.decode(buffer);
16885
- buffer = buffer.subarray(index$7.decode.bytes);
16880
+ const version = index$8.decode(buffer);
16881
+ buffer = buffer.subarray(index$8.decode.bytes);
16882
+ const codec = index$8.decode(buffer);
16883
+ buffer = buffer.subarray(index$8.decode.bytes);
16886
16884
  const signature = buffer.subarray(0, buffer.length);
16887
16885
  if (version !== this.version)
16888
16886
  throw TypeError('Invalid version');
@@ -16908,16 +16906,16 @@ class MultiSignature {
16908
16906
  return this.decode(base58$1.decode(string));
16909
16907
  }
16910
16908
  toBs32() {
16911
- return index$8.encode(this.multiSignature);
16909
+ return index$9.encode(this.multiSignature);
16912
16910
  }
16913
16911
  fromBs32(string) {
16914
- return this.decode(index$8.decode(string));
16912
+ return this.decode(index$9.decode(string));
16915
16913
  }
16916
16914
  toBs32Hex() {
16917
- return index$8.encodeHex(this.multiSignature);
16915
+ return index$9.encodeHex(this.multiSignature);
16918
16916
  }
16919
16917
  fromBs32Hex(string) {
16920
- return this.decode(index$8.decodeHex(string));
16918
+ return this.decode(index$9.decodeHex(string));
16921
16919
  }
16922
16920
  toBs58Hex() {
16923
16921
  return base58$1.encodeHex(this.multiSignature);
@@ -16927,132 +16925,6 @@ class MultiSignature {
16927
16925
  }
16928
16926
  }
16929
16927
 
16930
- class MultiHDNode extends HDWallet {
16931
- #encrypted;
16932
- constructor(network, hdnode) {
16933
- super(network, hdnode);
16934
- }
16935
- get id() {
16936
- return base58check.encode(index$6([
16937
- new TextEncoder().encode(this.version.toString()),
16938
- this.account(0).hdnode.neutered.publicKey
16939
- ]));
16940
- }
16941
- get multiWIF() {
16942
- return this.toMultiWif();
16943
- }
16944
- async fromId(id) {
16945
- let buffer = (await base58check.decode(id)).data;
16946
- index$7.decode(buffer);
16947
- buffer = buffer.slice(index$7.decode.bytes);
16948
- this.fromPublicKey(buffer, null, this.networkName);
16949
- }
16950
- async lock(multiWIF) {
16951
- if (!multiWIF)
16952
- multiWIF = this.multiWIF;
16953
- this.#encrypted = await encrypt$1(multiWIF);
16954
- this.locked = true;
16955
- return this.#encrypted;
16956
- }
16957
- async unlock({ key, iv, cipher }) {
16958
- const decrypted = await decrypt$1({ cipher, key, iv });
16959
- await this.fromMultiWif(new TextDecoder().decode(decrypted));
16960
- this.locked = false;
16961
- }
16962
- fromMultiWif(string) {
16963
- const { version, codec, privateKey } = index.decode(string);
16964
- this.network = Object.values(networks).reduce((p, c) => {
16965
- if (c.multiCodec === codec)
16966
- return c;
16967
- else if (c.testnet && c.testnet.multiCodec === codec)
16968
- return c.testnet;
16969
- else
16970
- return p;
16971
- }, networks['leofcoin']);
16972
- if (version !== this.network.version)
16973
- throw new Error('invalid version');
16974
- return this.fromPrivateKey(privateKey, undefined, this.network);
16975
- }
16976
- toMultiWif() {
16977
- return index.encode(this.network.version, this.network.multiCodec, this.privateKey);
16978
- }
16979
- sign(hash) {
16980
- return new MultiSignature(this.version, this.network.multiCodec)
16981
- .sign(hash, this.privateKey);
16982
- }
16983
- verify(multiSignature, hash) {
16984
- return new MultiSignature(this.version, this.network.multiCodec)
16985
- .verify(multiSignature, hash, this.publicKey);
16986
- }
16987
- }
16988
-
16989
- class HDAccount extends MultiHDNode {
16990
- /**
16991
- * @param {number} depth - acount depth
16992
- */
16993
- constructor(network, hdnode, depth = 0) {
16994
- super(network, hdnode);
16995
- this.hdnode = hdnode;
16996
- this.depth = depth;
16997
- this._prefix = `m/44'/${hdnode.network.coin_type}'/${depth}'/`;
16998
- }
16999
- get neutered() {
17000
- return this.hdnode.neutered;
17001
- }
17002
- /**
17003
- * @param {number} index - address index
17004
- */
17005
- async internal(index = 0) {
17006
- return this.hdnode.derivePath(`${this._prefix}1/${index}`);
17007
- }
17008
- /**
17009
- * @param {number} index - address index
17010
- */
17011
- async external(index = 0) {
17012
- return this.hdnode.derivePath(`${this._prefix}0/${index}`);
17013
- }
17014
- }
17015
-
17016
- class MultiWallet extends MultiHDNode {
17017
- constructor(network, hdnode) {
17018
- super(network, hdnode);
17019
- }
17020
- get id() {
17021
- return base58check.encode(index$6([
17022
- new TextEncoder().encode(this.version.toString()),
17023
- this.account(0).hdnode.neutered.publicKey
17024
- ]));
17025
- }
17026
- get multiWIF() {
17027
- return this.toMultiWif();
17028
- }
17029
- get neutered() {
17030
- return new HDAccount(this.networkName, this, this.hdnode.depth);
17031
- }
17032
- /**
17033
- * @param {number} account - account to return chain for
17034
- * @return internal(addressIndex), external(addressIndex)
17035
- */
17036
- account(index) {
17037
- return new HDAccount(this.networkName, this, index);
17038
- }
17039
- async fromAccount(privateKey, depth, network) {
17040
- const node = await new MultiWallet(network).fromPrivateKey(privateKey);
17041
- return new HDAccount(node, depth);
17042
- }
17043
- /**
17044
- * m / purpose' / coin_type' / account' / change / aadress_index
17045
- *
17046
- * see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
17047
- */
17048
- async derivePath(path) {
17049
- return new MultiWallet(this.networkName, await this.hdnode.derivePath(path));
17050
- }
17051
- async derive(index) {
17052
- return new MultiWallet(this.networkName, await this.hdnode.derive(index));
17053
- }
17054
- }
17055
-
17056
16928
  var passwordToKey = (password) => globalThis.crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, ['deriveKey']);
17057
16929
 
17058
16930
  var deriveKey = (key, salt, iterations = 250000, hashAlgorithm = 'SHA-512') => globalThis.crypto.subtle.deriveKey({
@@ -17074,11 +16946,11 @@ var encrypt = async (password, data, version = new TextEncoder().encode('1')) =>
17074
16946
  name: 'AES-GCM',
17075
16947
  iv
17076
16948
  }, key, new TextEncoder().encode(data));
17077
- return index$6([version, salt, iv, new Uint8Array(encrypted)]);
16949
+ return index$7([version, salt, iv, new Uint8Array(encrypted)]);
17078
16950
  };
17079
16951
 
17080
16952
  var decrypt = async (password, concatecated) => {
17081
- const [version, salt, iv, cipher] = index$5(concatecated);
16953
+ const [version, salt, iv, cipher] = index$6(concatecated);
17082
16954
  let iterations;
17083
16955
  if (new TextDecoder().decode(version) === '1') {
17084
16956
  iterations = 250000;
@@ -17092,6 +16964,213 @@ var decrypt = async (password, concatecated) => {
17092
16964
  return new TextDecoder().decode(decrypted);
17093
16965
  };
17094
16966
 
16967
+ const MSB$1 = 0x80;
16968
+ const REST$1 = 0x7F;
16969
+ const MSBALL = ~REST$1;
16970
+ const INT = Math.pow(2, 31);
16971
+ const encode = (num, out, offset) => {
16972
+ if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
16973
+ encode.bytes = 0;
16974
+ throw new RangeError('Could not encode varint');
16975
+ }
16976
+ out = out || [];
16977
+ offset = offset || 0;
16978
+ const oldOffset = offset;
16979
+ while (num >= INT) {
16980
+ out[offset++] = (num & 0xFF) | MSB$1;
16981
+ num /= 128;
16982
+ }
16983
+ while (num & MSBALL) {
16984
+ out[offset++] = (num & 0xFF) | MSB$1;
16985
+ num >>>= 7;
16986
+ }
16987
+ out[offset] = num | 0;
16988
+ encode.bytes = offset - oldOffset + 1;
16989
+ return out;
16990
+ };
16991
+
16992
+ const MSB = 0x80;
16993
+ const REST = 0x7F;
16994
+ const decode = (buf, offset) => {
16995
+ offset = offset || 0;
16996
+ const l = buf.length;
16997
+ let counter = offset;
16998
+ let result = 0;
16999
+ let shift = 0;
17000
+ let b;
17001
+ do {
17002
+ if (counter >= l || shift > 49) {
17003
+ decode.bytes = 0;
17004
+ throw new RangeError('Could not decode varint');
17005
+ }
17006
+ b = buf[counter++];
17007
+ result += shift < 28
17008
+ ? (b & REST) << shift
17009
+ : (b & REST) * Math.pow(2, shift);
17010
+ shift += 7;
17011
+ } while (b >= MSB);
17012
+ decode.bytes = counter - offset;
17013
+ return result;
17014
+ };
17015
+
17016
+ const N1 = Math.pow(2, 7);
17017
+ const N2 = Math.pow(2, 14);
17018
+ const N3 = Math.pow(2, 21);
17019
+ const N4 = Math.pow(2, 28);
17020
+ const N5 = Math.pow(2, 35);
17021
+ const N6 = Math.pow(2, 42);
17022
+ const N7 = Math.pow(2, 49);
17023
+ const N8 = Math.pow(2, 56);
17024
+ const N9 = Math.pow(2, 63);
17025
+ var encodingLength = (value) => (value < N1 ? 1
17026
+ : value < N2 ? 2
17027
+ : value < N3 ? 3
17028
+ : value < N4 ? 4
17029
+ : value < N5 ? 5
17030
+ : value < N6 ? 6
17031
+ : value < N7 ? 7
17032
+ : value < N8 ? 8
17033
+ : value < N9 ? 9
17034
+ : 10);
17035
+
17036
+ var index = {
17037
+ encode,
17038
+ decode,
17039
+ encodingLength
17040
+ };
17041
+
17042
+ class MultiHDNode extends HDWallet {
17043
+ #encrypted;
17044
+ constructor(network, hdnode) {
17045
+ super(network, hdnode);
17046
+ }
17047
+ get id() {
17048
+ return base58check$1.encode(index$7([
17049
+ new TextEncoder().encode(this.version.toString()),
17050
+ this.account(0).hdnode.neutered.publicKey
17051
+ ]));
17052
+ }
17053
+ get multiWIF() {
17054
+ return this.toMultiWif();
17055
+ }
17056
+ async fromId(id) {
17057
+ let buffer = (await base58check$1.decode(id)).data;
17058
+ index.decode(buffer);
17059
+ buffer = buffer.slice(index.decode.bytes);
17060
+ this.fromPublicKey(buffer, null, this.networkName);
17061
+ }
17062
+ async import(password, encrypted) {
17063
+ const { prefix, data } = await base58check$1.decode(encrypted);
17064
+ const decrypted = await decrypt(password, data);
17065
+ await this.fromMultiWif(decrypted);
17066
+ }
17067
+ async export(password) {
17068
+ return base58check$1.encode(await encrypt(password, await this.toMultiWif()));
17069
+ }
17070
+ async lock(password) {
17071
+ // todo redefine hdnode
17072
+ this.#encrypted = await this.export(password);
17073
+ this.locked = true;
17074
+ }
17075
+ async unlock(password) {
17076
+ const { prefix, data } = await base58check$1.decode(this.#encrypted);
17077
+ await decrypt(password, data);
17078
+ this.locked = false;
17079
+ }
17080
+ fromMultiWif(string) {
17081
+ const { version, codec, privateKey } = index$1.decode(string);
17082
+ this.network = Object.values(networks).reduce((p, c) => {
17083
+ if (c.multiCodec === codec)
17084
+ return c;
17085
+ else if (c.testnet && c.testnet.multiCodec === codec)
17086
+ return c.testnet;
17087
+ else
17088
+ return p;
17089
+ }, networks['leofcoin']);
17090
+ if (version !== this.network.version)
17091
+ throw new Error('invalid version');
17092
+ return this.fromPrivateKey(privateKey, undefined, this.network);
17093
+ }
17094
+ toMultiWif() {
17095
+ return index$1.encode(this.network.version, this.network.multiCodec, this.privateKey);
17096
+ }
17097
+ sign(hash) {
17098
+ return new MultiSignature(this.version, this.network.multiCodec)
17099
+ .sign(hash, this.privateKey);
17100
+ }
17101
+ verify(multiSignature, hash) {
17102
+ return new MultiSignature(this.version, this.network.multiCodec)
17103
+ .verify(multiSignature, hash, this.publicKey);
17104
+ }
17105
+ }
17106
+
17107
+ class HDAccount extends MultiHDNode {
17108
+ /**
17109
+ * @param {number} depth - acount depth
17110
+ */
17111
+ constructor(network, hdnode, depth = 0) {
17112
+ super(network, hdnode);
17113
+ this.hdnode = hdnode;
17114
+ this.depth = depth;
17115
+ this._prefix = `m/44'/${hdnode.network.coin_type}'/${depth}'/`;
17116
+ }
17117
+ get neutered() {
17118
+ return this.hdnode.neutered;
17119
+ }
17120
+ /**
17121
+ * @param {number} index - address index
17122
+ */
17123
+ async internal(index = 0) {
17124
+ return this.hdnode.derivePath(`${this._prefix}1/${index}`);
17125
+ }
17126
+ /**
17127
+ * @param {number} index - address index
17128
+ */
17129
+ async external(index = 0) {
17130
+ return this.hdnode.derivePath(`${this._prefix}0/${index}`);
17131
+ }
17132
+ }
17133
+
17134
+ class MultiWallet extends MultiHDNode {
17135
+ constructor(network, hdnode) {
17136
+ super(network, hdnode);
17137
+ }
17138
+ get id() {
17139
+ return base58check$1.encode(index$7([
17140
+ new TextEncoder().encode(this.version.toString()),
17141
+ this.account(0).hdnode.neutered.publicKey
17142
+ ]));
17143
+ }
17144
+ get multiWIF() {
17145
+ return this.toMultiWif();
17146
+ }
17147
+ get neutered() {
17148
+ return new HDAccount(this.networkName, this, this.hdnode.depth);
17149
+ }
17150
+ /**
17151
+ * @param {number} account - account to return chain for
17152
+ * @return internal(addressIndex), external(addressIndex)
17153
+ */
17154
+ account(index) {
17155
+ return new HDAccount(this.networkName, this, index);
17156
+ }
17157
+ async fromAccount(privateKey, depth, network) {
17158
+ const node = await new MultiWallet(network).fromPrivateKey(privateKey);
17159
+ return new HDAccount(node, depth);
17160
+ }
17161
+ /**
17162
+ * m / purpose' / coin_type' / account' / change / aadress_index
17163
+ *
17164
+ * see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
17165
+ */
17166
+ async derivePath(path) {
17167
+ return new MultiWallet(this.networkName, await this.hdnode.derivePath(path));
17168
+ }
17169
+ async derive(index) {
17170
+ return new MultiWallet(this.networkName, await this.hdnode.derive(index));
17171
+ }
17172
+ }
17173
+
17095
17174
  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."),
17096
17175
  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=
17097
17176
  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";
@@ -20081,7 +20160,7 @@ class Identity {
20081
20160
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20082
20161
  }
20083
20162
  else {
20084
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-ff6a68c3.js');
20163
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-9c85cd32.js');
20085
20164
  const { identity, accounts } = await importee.default(password, this.network);
20086
20165
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20087
20166
  await globalThis.walletStore.put('version', String(1));
@@ -20099,15 +20178,17 @@ class Identity {
20099
20178
  sign(hash) {
20100
20179
  return this.#wallet.sign(hash.subarray(0, 32));
20101
20180
  }
20181
+ lock(password) {
20182
+ this.#wallet.lock(password);
20183
+ }
20184
+ unlock(password) {
20185
+ this.#wallet.unlock(password);
20186
+ }
20102
20187
  async export(password) {
20103
- const multiWIF = this.#wallet.toMultiWif();
20104
- const encypted = await encrypt(password, multiWIF);
20105
- return base58$1.encode(encypted);
20188
+ return this.#wallet.export(password);
20106
20189
  }
20107
20190
  async import(password, encrypted) {
20108
- this.#wallet = new MultiWallet(this.network);
20109
- const decrypted = await decrypt(password, base58$1.decode(encrypted));
20110
- await this.#wallet.fromMultiWif(decrypted);
20191
+ await this.#wallet.import(password, encrypted);
20111
20192
  }
20112
20193
  async exportQR(password) {
20113
20194
  const exported = await this.export(password);
@@ -20260,7 +20341,7 @@ class Peernet {
20260
20341
  this.root = options.root;
20261
20342
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20262
20343
  // FolderMessageResponse
20263
- } = await import(/* webpackChunkName: "messages" */ './messages-7a0e14b4.js');
20344
+ } = await import(/* webpackChunkName: "messages" */ './messages-b66f5393.js');
20264
20345
  /**
20265
20346
  * proto Object containing protos
20266
20347
  * @type {Object}
@@ -20518,7 +20599,7 @@ class Peernet {
20518
20599
  }
20519
20600
  async requestData(hash, store) {
20520
20601
  const providers = await this.providersFor(hash);
20521
- if (!providers || Object.keys(providers).length === 0)
20602
+ if (!providers || providers && Object.keys(providers).length === 0)
20522
20603
  throw nothingFoundError(hash);
20523
20604
  debug(`found ${Object.keys(providers).length} provider(s) for ${hash}`);
20524
20605
  // get closest peer on earth