@leofcoin/peernet 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { L as LittlePubSub } from './peernet-1908438f.js';
1
+ import { L as LittlePubSub } from './peernet-e74b2091.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  var clientApi = _pubsub => {
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet } from './peernet-1908438f.js';
1
+ import { M as MultiWallet } from './peernet-e74b2091.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-1908438f.js';
1
+ import { F as FormatInterface } from './peernet-e74b2091.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  var proto$b = {
@@ -225,7 +225,7 @@ const isBase32 = (string, hex = false) => {
225
225
  const isBase32Hex = (string) => {
226
226
  return isBase32(string, true);
227
227
  };
228
- var index$9 = {
228
+ var index$8 = {
229
229
  encode: encode$8,
230
230
  decode: decode$9,
231
231
  encodeHex: encodeHex$2,
@@ -346,16 +346,16 @@ var encodingLength = (value) => (value < N1 ? 1
346
346
  : value < N9 ? 9
347
347
  : 10);
348
348
 
349
- var index$8 = {
349
+ var index$7 = {
350
350
  encode: encode$6,
351
351
  decode: decode$7,
352
352
  encodingLength
353
353
  };
354
354
 
355
- var index$7 = (input, prefix) => {
355
+ var index$6 = (input, prefix) => {
356
356
  const encodedArray = [];
357
357
  const length = input.reduce((total, current) => {
358
- const encoded = index$8.encode(current.length);
358
+ const encoded = index$7.encode(current.length);
359
359
  encodedArray.push(encoded);
360
360
  total += current.length + encoded.length;
361
361
  return total;
@@ -377,14 +377,14 @@ var index$7 = (input, prefix) => {
377
377
  return typedArray;
378
378
  };
379
379
 
380
- var index$6 = (typedArray, prefix) => {
380
+ var index$5 = (typedArray, prefix) => {
381
381
  const set = [];
382
382
  if (prefix)
383
383
  typedArray = typedArray.subarray(prefix.length);
384
384
  const varintAndSub = (typedArray) => {
385
- const length = index$8.decode(typedArray);
385
+ const length = index$7.decode(typedArray);
386
386
  // remove length
387
- typedArray = typedArray.subarray(index$8.decode.bytes);
387
+ typedArray = typedArray.subarray(index$7.decode.bytes);
388
388
  // push value
389
389
  set.push(typedArray.subarray(0, length));
390
390
  // remove value
@@ -409,7 +409,7 @@ const isBase16 = (string) => {
409
409
  return false;
410
410
  }
411
411
  };
412
- var index$5 = {
412
+ var index$4 = {
413
413
  encode: encode$5,
414
414
  decode: decode$6,
415
415
  isBase16
@@ -428,7 +428,7 @@ const isBase64 = (string) => {
428
428
  return false;
429
429
  }
430
430
  };
431
- var index$4 = {
431
+ var index$3 = {
432
432
  encode: encode$4,
433
433
  decode: decode$5,
434
434
  isBase64
@@ -496,25 +496,25 @@ const fromArrayLike = (array) => Uint8Array.from(array);
496
496
  * @returns Uint8Array
497
497
  */
498
498
  const toArrayLike = (uint8Array) => [...uint8Array.values()];
499
- const toBase64 = (uint8Array) => index$4.encode(uint8Array);
500
- const fromBase64 = (string) => index$4.decode(string);
499
+ const toBase64 = (uint8Array) => index$3.encode(uint8Array);
500
+ const fromBase64 = (string) => index$3.decode(string);
501
501
  const toBase58 = (uint8Array) => base58$1.encode(uint8Array);
502
502
  const fromBase58 = (string) => base58$1.decode(string);
503
- const toBase32 = (uint8Array) => index$9.encode(uint8Array);
504
- const fromBase32 = (string) => index$9.decode(string);
505
- const toBase16 = (uint8Array) => index$5.encode(uint8Array);
506
- const fromBase16 = (string) => index$5.decode(string);
503
+ const toBase32 = (uint8Array) => index$8.encode(uint8Array);
504
+ const fromBase32 = (string) => index$8.decode(string);
505
+ const toBase16 = (uint8Array) => index$4.encode(uint8Array);
506
+ const fromBase16 = (string) => index$4.decode(string);
507
507
  let FormatInterface$2 = class FormatInterface {
508
508
  encoded;
509
509
  constructor(input) {
510
510
  if (input) {
511
- if (index$5.isBase16(input))
511
+ if (index$4.isBase16(input))
512
512
  this.encoded = this.fromBase16(input);
513
- else if (index$9.isBase32(input))
513
+ else if (index$8.isBase32(input))
514
514
  this.encoded = this.fromBase32(input);
515
515
  else if (base58$1.isBase58(input))
516
516
  this.encoded = this.fromBase58(input);
517
- else if (index$4.isBase64(input))
517
+ else if (index$3.isBase64(input))
518
518
  this.encoded = this.fromBase64(input);
519
519
  else if (typeof input === 'string') {
520
520
  let isCompatible = isTypedArrayCompatible(input);
@@ -602,10 +602,10 @@ let FormatInterface$2 = class FormatInterface {
602
602
  return JSON.parse(new TextDecoder().decode(uint8Array));
603
603
  }
604
604
  toBase64(uint8Array) {
605
- return index$4.encode(uint8Array);
605
+ return index$3.encode(uint8Array);
606
606
  }
607
607
  fromBase64(string) {
608
- return index$4.decode(string);
608
+ return index$3.decode(string);
609
609
  }
610
610
  toBase58(uint8Array) {
611
611
  return base58$1.encode(uint8Array);
@@ -614,19 +614,19 @@ let FormatInterface$2 = class FormatInterface {
614
614
  return base58$1.decode(string);
615
615
  }
616
616
  toBase32(uint8Array) {
617
- return index$9.encode(uint8Array);
617
+ return index$8.encode(uint8Array);
618
618
  }
619
619
  fromBase32(string) {
620
- return index$9.decode(string);
620
+ return index$8.decode(string);
621
621
  }
622
622
  toBase16(uint8Array) {
623
- return index$5.encode(uint8Array);
623
+ return index$4.encode(uint8Array);
624
624
  }
625
625
  fromBase16(string) {
626
- return index$5.decode(string);
626
+ return index$4.decode(string);
627
627
  }
628
628
  };
629
- var index$3 = {
629
+ var index$2 = {
630
630
  fromString: fromString$1,
631
631
  toString: toString$1,
632
632
  fromHex,
@@ -646,7 +646,7 @@ var index$3 = {
646
646
  FormatInterface: FormatInterface$2
647
647
  };
648
648
 
649
- const { fromString, toString } = index$3;
649
+ const { fromString, toString } = index$2;
650
650
  const isJson = (type) => type === 'object' || 'array';
651
651
  const isString = (type) => type === 'string';
652
652
  const isNumber = (type) => type === 'number';
@@ -695,10 +695,10 @@ const encode$3 = (proto, input) => {
695
695
  // when data is undefined push the default value of the proto
696
696
  set.push(toType(data || values[i]));
697
697
  }
698
- return index$7(set);
698
+ return index$6(set);
699
699
  };
700
700
  const decode$4 = (proto, uint8Array) => {
701
- let deconcated = index$6(uint8Array);
701
+ let deconcated = index$5(uint8Array);
702
702
  const output = {};
703
703
  const keys = Object.keys(proto);
704
704
  const values = Object.values(proto);
@@ -725,7 +725,7 @@ const decode$4 = (proto, uint8Array) => {
725
725
  }
726
726
  return output;
727
727
  };
728
- var index$2 = {
728
+ var index$1 = {
729
729
  encode: encode$3,
730
730
  decode: decode$4
731
731
  };
@@ -1491,23 +1491,23 @@ let BasicInterface$1 = class BasicInterface {
1491
1491
  // get Codec(): Codec {}
1492
1492
  protoEncode(data) {
1493
1493
  // check schema
1494
- return index$2.encode(this.proto, data);
1494
+ return index$1.encode(this.proto, data);
1495
1495
  }
1496
1496
  protoDecode(data) {
1497
1497
  // check schema
1498
- return index$2.decode(this.proto, data);
1498
+ return index$1.decode(this.proto, data);
1499
1499
  }
1500
1500
  isHex(string) {
1501
1501
  return isHex(string);
1502
1502
  }
1503
1503
  isBase32(string) {
1504
- return index$9.isBase32(string);
1504
+ return index$8.isBase32(string);
1505
1505
  }
1506
1506
  isBase58(string) {
1507
1507
  return base58$1.isBase58(string);
1508
1508
  }
1509
1509
  fromBs32(encoded) {
1510
- return this.decode(index$9.decode(encoded));
1510
+ return this.decode(index$8.decode(encoded));
1511
1511
  }
1512
1512
  fromBs58(encoded) {
1513
1513
  return this.decode(fromBase58(encoded));
@@ -1569,7 +1569,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
1569
1569
  super();
1570
1570
  if (buffer) {
1571
1571
  if (buffer instanceof Uint8Array) {
1572
- const codec = index$8.decode(buffer);
1572
+ const codec = index$7.decode(buffer);
1573
1573
  const name = this.getCodecName(codec);
1574
1574
  if (name) {
1575
1575
  this.name = name;
@@ -1581,7 +1581,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
1581
1581
  }
1582
1582
  }
1583
1583
  else if (buffer instanceof ArrayBuffer) {
1584
- const codec = index$8.decode(buffer);
1584
+ const codec = index$7.decode(buffer);
1585
1585
  const name = this.getCodecName(codec);
1586
1586
  if (name) {
1587
1587
  this.name = name;
@@ -1609,7 +1609,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
1609
1609
  }
1610
1610
  }
1611
1611
  fromEncoded(encoded) {
1612
- const codec = index$8.decode(encoded);
1612
+ const codec = index$7.decode(encoded);
1613
1613
  const name = this.getCodecName(codec);
1614
1614
  this.name = name;
1615
1615
  this.encoded = encoded;
@@ -1628,24 +1628,24 @@ let Codec$1 = class Codec extends BasicInterface$1 {
1628
1628
  this.name = this.getCodecName(codec);
1629
1629
  this.hashAlg = this.getHashAlg(this.name);
1630
1630
  this.codec = this.getCodec(this.name);
1631
- this.codecBuffer = index$8.encode(this.codec);
1631
+ this.codecBuffer = index$7.encode(this.codec);
1632
1632
  }
1633
1633
  fromName(name) {
1634
1634
  const codec = this.getCodec(name);
1635
1635
  this.name = name;
1636
1636
  this.codec = codec;
1637
1637
  this.hashAlg = this.getHashAlg(name);
1638
- this.codecBuffer = index$8.encode(this.codec);
1638
+ this.codecBuffer = index$7.encode(this.codec);
1639
1639
  }
1640
1640
  decode(encoded) {
1641
1641
  encoded = encoded || this.encoded;
1642
- const codec = index$8.decode(encoded);
1642
+ const codec = index$7.decode(encoded);
1643
1643
  this.fromCodec(codec);
1644
1644
  return this.decoded;
1645
1645
  }
1646
1646
  encode(codec) {
1647
1647
  codec = codec || this.codec;
1648
- this.encoded = index$8.encode(codec);
1648
+ this.encoded = index$7.encode(codec);
1649
1649
  return this.encoded;
1650
1650
  }
1651
1651
  };
@@ -1697,7 +1697,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1697
1697
  return uint8Array;
1698
1698
  }
1699
1699
  get length() {
1700
- return index$8.encode(this.size);
1700
+ return index$7.encode(this.size);
1701
1701
  }
1702
1702
  get buffer() {
1703
1703
  return this.encoded;
@@ -1739,7 +1739,7 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1739
1739
  }
1740
1740
  async validate(buffer) {
1741
1741
  if (Buffer.isBuffer(buffer)) {
1742
- const codec = index$8.decode(buffer);
1742
+ const codec = index$7.decode(buffer);
1743
1743
  if (this.codecs[codec]) {
1744
1744
  this.decode(buffer);
1745
1745
  }
@@ -1758,12 +1758,12 @@ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1758
1758
  }
1759
1759
  decode(buffer) {
1760
1760
  this.encoded = buffer;
1761
- const codec = index$8.decode(buffer);
1761
+ const codec = index$7.decode(buffer);
1762
1762
  this.discoCodec = new Codec$1(codec, this.codecs);
1763
1763
  // TODO: validate codec
1764
- buffer = buffer.slice(index$8.decode.bytes);
1765
- this.size = index$8.decode(buffer);
1766
- this.digest = buffer.slice(index$8.decode.bytes);
1764
+ buffer = buffer.slice(index$7.decode.bytes);
1765
+ this.size = index$7.decode(buffer);
1766
+ this.digest = buffer.slice(index$7.decode.bytes);
1767
1767
  if (this.digest.length !== this.size) {
1768
1768
  throw new Error(`hash length inconsistent: 0x${this.encoded.toString('hex')}`);
1769
1769
  }
@@ -2167,16 +2167,8 @@ class MessageHandler {
2167
2167
  * @return message
2168
2168
  */
2169
2169
  async hashAndSignMessage(message) {
2170
- let identity = await walletStore.get('identity');
2171
- identity = JSON.parse(identity);
2172
- if (!globalThis.MultiWallet) {
2173
- const importee = await Promise.resolve().then(function () { return index; });
2174
- globalThis.MultiWallet = importee.default;
2175
- }
2176
- const wallet = new MultiWallet(this.network);
2177
- wallet.recover(identity.mnemonic);
2178
- const hash = await message.hash();
2179
- message.decoded.signature = wallet.sign(hash.subarray(0, 32));
2170
+ const hash = await message.peernetHash;
2171
+ message.decoded.signature = globalThis.identity.sign(hash.buffer);
2180
2172
  return message;
2181
2173
  }
2182
2174
  /**
@@ -2567,7 +2559,7 @@ var base58check = { encode: encode$1, decode: decode$2, encodeHex, decodeHex, is
2567
2559
 
2568
2560
  const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
2569
2561
  const decoded = base58$1.decode(multiWif);
2570
- let [version, codec, privateKey] = index$6(decoded);
2562
+ let [version, codec, privateKey] = index$5(decoded);
2571
2563
  version = Number(new TextDecoder().decode(version));
2572
2564
  codec = Number(new TextDecoder().decode(codec));
2573
2565
  if (expectedVersion && version !== expectedVersion)
@@ -2576,9 +2568,9 @@ const decode$1 = (multiWif, expectedVersion, expectedCodec) => {
2576
2568
  throw new Error(`invalid codec: expected ${expectedCodec} but got ${codec}`);
2577
2569
  return { version, codec, privateKey };
2578
2570
  };
2579
- var index$1 = {
2571
+ var index = {
2580
2572
  encode: (version, codec, privateKey) => {
2581
- return base58$1.encode(index$7([
2573
+ return base58$1.encode(index$6([
2582
2574
  new TextEncoder().encode(version.toString()),
2583
2575
  new TextEncoder().encode(codec.toString()),
2584
2576
  privateKey
@@ -12443,7 +12435,7 @@ class HdNode {
12443
12435
  else {
12444
12436
  set.push(new Uint8Array(this.publicKey));
12445
12437
  }
12446
- return base58check.encode(index$7(set));
12438
+ return base58check.encode(index$6(set));
12447
12439
  }
12448
12440
  toWIF() {
12449
12441
  if (!this.#privateKey)
@@ -12459,14 +12451,14 @@ class HdNode {
12459
12451
  if (this.isNeutered)
12460
12452
  throw new TypeError('Missing private key for hardened child key');
12461
12453
  // data = 0x00 || ser256(kpar) || ser32(index)
12462
- data = index$7([
12454
+ data = index$6([
12463
12455
  new TextEncoder().encode('0'),
12464
12456
  this.privateKey,
12465
12457
  new TextEncoder().encode(index.toString())
12466
12458
  ]);
12467
12459
  }
12468
12460
  else {
12469
- data = index$7([
12461
+ data = index$6([
12470
12462
  this.publicKey,
12471
12463
  new TextEncoder().encode(index.toString())
12472
12464
  ]);
@@ -12530,7 +12522,7 @@ class HdNode {
12530
12522
  let buffer = (await base58check.decode(string)).data;
12531
12523
  network = network || networks.leofcoin;
12532
12524
  // 4 bytes: version bytes
12533
- let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$6(buffer);
12525
+ let [version, depth, parentFingerprint, index, chainCode, k, privateKey] = index$5(buffer);
12534
12526
  version = Number(new TextDecoder().decode(version));
12535
12527
  depth = Number(new TextDecoder().decode(depth));
12536
12528
  parentFingerprint = Number(new TextDecoder().decode(parentFingerprint));
@@ -12799,8 +12791,8 @@ class MultiSignature {
12799
12791
  if (!signature)
12800
12792
  throw ReferenceError('signature undefined');
12801
12793
  this.#multiSignature = typedArrayConcat([
12802
- index$8.encode(this.version),
12803
- index$8.encode(this.multiCodec),
12794
+ index$7.encode(this.version),
12795
+ index$7.encode(this.multiCodec),
12804
12796
  signature
12805
12797
  ]);
12806
12798
  return this.multiSignature;
@@ -12816,10 +12808,10 @@ class MultiSignature {
12816
12808
  if (!this.multiSignature)
12817
12809
  throw ReferenceError('multiSignature undefined');
12818
12810
  let buffer = this.multiSignature;
12819
- const version = index$8.decode(buffer);
12820
- buffer = buffer.subarray(index$8.decode.bytes);
12821
- const codec = index$8.decode(buffer);
12822
- buffer = buffer.subarray(index$8.decode.bytes);
12811
+ const version = index$7.decode(buffer);
12812
+ buffer = buffer.subarray(index$7.decode.bytes);
12813
+ const codec = index$7.decode(buffer);
12814
+ buffer = buffer.subarray(index$7.decode.bytes);
12823
12815
  const signature = buffer.subarray(0, buffer.length);
12824
12816
  if (version !== this.version)
12825
12817
  throw TypeError('Invalid version');
@@ -12845,16 +12837,16 @@ class MultiSignature {
12845
12837
  return this.decode(base58$1.decode(string));
12846
12838
  }
12847
12839
  toBs32() {
12848
- return index$9.encode(this.multiSignature);
12840
+ return index$8.encode(this.multiSignature);
12849
12841
  }
12850
12842
  fromBs32(string) {
12851
- return this.decode(index$9.decode(string));
12843
+ return this.decode(index$8.decode(string));
12852
12844
  }
12853
12845
  toBs32Hex() {
12854
- return index$9.encodeHex(this.multiSignature);
12846
+ return index$8.encodeHex(this.multiSignature);
12855
12847
  }
12856
12848
  fromBs32Hex(string) {
12857
- return this.decode(index$9.decodeHex(string));
12849
+ return this.decode(index$8.decodeHex(string));
12858
12850
  }
12859
12851
  toBs58Hex() {
12860
12852
  return base58$1.encodeHex(this.multiSignature);
@@ -12870,7 +12862,7 @@ class MultiHDNode extends HDWallet {
12870
12862
  super(network, hdnode);
12871
12863
  }
12872
12864
  get id() {
12873
- return base58check.encode(index$7([
12865
+ return base58check.encode(index$6([
12874
12866
  new TextEncoder().encode(this.version.toString()),
12875
12867
  this.account(0).hdnode.neutered.publicKey
12876
12868
  ]));
@@ -12880,8 +12872,8 @@ class MultiHDNode extends HDWallet {
12880
12872
  }
12881
12873
  async fromId(id) {
12882
12874
  let buffer = (await base58check.decode(id)).data;
12883
- index$8.decode(buffer);
12884
- buffer = buffer.slice(index$8.decode.bytes);
12875
+ index$7.decode(buffer);
12876
+ buffer = buffer.slice(index$7.decode.bytes);
12885
12877
  this.fromPublicKey(buffer, null, this.networkName);
12886
12878
  }
12887
12879
  async lock(multiWIF) {
@@ -12897,7 +12889,7 @@ class MultiHDNode extends HDWallet {
12897
12889
  this.locked = false;
12898
12890
  }
12899
12891
  fromMultiWif(string) {
12900
- const { version, codec, privateKey } = index$1.decode(string);
12892
+ const { version, codec, privateKey } = index.decode(string);
12901
12893
  this.network = Object.values(networks).reduce((p, c) => {
12902
12894
  if (c.multiCodec === codec)
12903
12895
  return c;
@@ -12911,7 +12903,7 @@ class MultiHDNode extends HDWallet {
12911
12903
  return this.fromPrivateKey(privateKey, undefined, this.network);
12912
12904
  }
12913
12905
  toMultiWif() {
12914
- return index$1.encode(this.network.version, this.network.multiCodec, this.privateKey);
12906
+ return index.encode(this.network.version, this.network.multiCodec, this.privateKey);
12915
12907
  }
12916
12908
  sign(hash) {
12917
12909
  return new MultiSignature(this.version, this.network.multiCodec)
@@ -12950,12 +12942,12 @@ class HDAccount extends MultiHDNode {
12950
12942
  }
12951
12943
  }
12952
12944
 
12953
- let MultiWallet$1 = class MultiWallet extends MultiHDNode {
12945
+ class MultiWallet extends MultiHDNode {
12954
12946
  constructor(network, hdnode) {
12955
12947
  super(network, hdnode);
12956
12948
  }
12957
12949
  get id() {
12958
- return base58check.encode(index$7([
12950
+ return base58check.encode(index$6([
12959
12951
  new TextEncoder().encode(this.version.toString()),
12960
12952
  this.account(0).hdnode.neutered.publicKey
12961
12953
  ]));
@@ -12974,7 +12966,7 @@ let MultiWallet$1 = class MultiWallet extends MultiHDNode {
12974
12966
  return new HDAccount(this.networkName, this, index);
12975
12967
  }
12976
12968
  async fromAccount(privateKey, depth, network) {
12977
- const node = await new MultiWallet$1(network).fromPrivateKey(privateKey);
12969
+ const node = await new MultiWallet(network).fromPrivateKey(privateKey);
12978
12970
  return new HDAccount(node, depth);
12979
12971
  }
12980
12972
  /**
@@ -12983,20 +12975,13 @@ let MultiWallet$1 = class MultiWallet extends MultiHDNode {
12983
12975
  * see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
12984
12976
  */
12985
12977
  async derivePath(path) {
12986
- return new MultiWallet$1(this.networkName, await this.hdnode.derivePath(path));
12978
+ return new MultiWallet(this.networkName, await this.hdnode.derivePath(path));
12987
12979
  }
12988
12980
  async derive(index) {
12989
- return new MultiWallet$1(this.networkName, await this.hdnode.derive(index));
12981
+ return new MultiWallet(this.networkName, await this.hdnode.derive(index));
12990
12982
  }
12991
- };
12992
-
12993
- var index = /*#__PURE__*/Object.freeze({
12994
- __proto__: null,
12995
- default: MultiWallet$1
12996
- });
12983
+ }
12997
12984
 
12998
- const walletStore$1 = globalThis.walletStore;
12999
- const accountStore = globalThis.accountStore;
13000
12985
  class Identity {
13001
12986
  #wallet;
13002
12987
  network;
@@ -13008,57 +12993,50 @@ class Identity {
13008
12993
  return this.getAccounts();
13009
12994
  }
13010
12995
  async getAccounts() {
13011
- let accounts = await walletStore$1.get('accounts');
12996
+ let accounts = await globalThis.walletStore.get('accounts');
13012
12997
  accounts = new TextDecoder().decode(accounts);
13013
12998
  return JSON.parse(accounts);
13014
12999
  }
13015
13000
  async load(password) {
13016
- let importee;
13017
13001
  if (!password) {
13018
- if (globalThis.navigator)
13019
- importee = await import('./browser.js');
13020
- else {
13021
- const path = await import('node:path');
13022
- const { fileURLToPath } = await import('node:url');
13023
- const __filename = fileURLToPath(import.meta.url);
13024
- const __dirname = path.dirname(__filename);
13025
- const url = path.join(__dirname, './prompts/password/node.js');
13026
- importee = await import(url);
13027
- }
13002
+ const importee = await import('./src/prompts/password.js');
13028
13003
  password = await importee.default();
13029
13004
  }
13030
- const accountExists = await accountStore.has('public');
13005
+ const accountExists = await globalThis.accountStore.has('public');
13031
13006
  if (accountExists) {
13032
- const pub = await accountStore.get('public');
13007
+ const pub = await globalThis.accountStore.get('public');
13033
13008
  this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
13034
- const selected = await walletStore$1.get('selected-account');
13009
+ const selected = await globalThis.walletStore.get('selected-account');
13035
13010
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
13036
13011
  }
13037
13012
  else {
13038
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-5a93c9c3.js');
13013
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-3699fac4.js');
13039
13014
  const { identity, accounts } = await importee.default(password, this.network);
13040
- await accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
13041
- await walletStore$1.put('version', String(1));
13042
- await walletStore$1.put('accounts', JSON.stringify(accounts));
13043
- await walletStore$1.put('selected-account', accounts[0][1]);
13044
- await walletStore$1.put('identity', JSON.stringify(identity));
13015
+ await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
13016
+ await globalThis.walletStore.put('version', String(1));
13017
+ await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
13018
+ await globalThis.walletStore.put('selected-account', accounts[0][1]);
13019
+ await globalThis.walletStore.put('identity', JSON.stringify(identity));
13045
13020
  globalThis.peernet.selectedAccount = accounts[0][1];
13046
13021
  this.id = identity.walletId;
13047
13022
  }
13048
- const identity = JSON.parse(new TextDecoder().decode(await walletStore$1.get('identity')));
13049
- this.#wallet = new MultiWallet$1(this.network);
13023
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
13024
+ this.#wallet = new MultiWallet(this.network);
13050
13025
  await this.#wallet.recover(identity.mnemonic, password, this.network);
13051
13026
  }
13027
+ sign(hash) {
13028
+ return this.#wallet.sign(hash.subarray(0, 32));
13029
+ }
13052
13030
  async export(password) {
13053
13031
  if (!password)
13054
13032
  throw new Error('IdentityExportError: password required');
13055
- const identity = JSON.parse(new TextDecoder().decode(await walletStore$1.get('identity')));
13056
- this.#wallet = new MultiWallet$1(this.network);
13033
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
13034
+ this.#wallet = new MultiWallet(this.network);
13057
13035
  await this.#wallet.recover(identity.mnemonic, password, this.network);
13058
13036
  return this.#wallet.toMultiWif();
13059
13037
  }
13060
13038
  async import(multiWIF) {
13061
- this.#wallet = new MultiWallet$1(this.network);
13039
+ this.#wallet = new MultiWallet(this.network);
13062
13040
  await this.#wallet.fromMultiWif(multiWIF);
13063
13041
  }
13064
13042
  async unlock({ key, iv, cipher }) {
@@ -13109,7 +13087,7 @@ class Peernet {
13109
13087
  * @example
13110
13088
  * const peernet = new Peernet({network: 'leofcoin', root: '.leofcoin'});
13111
13089
  */
13112
- constructor(options) {
13090
+ constructor(options, password) {
13113
13091
  /**
13114
13092
  * @property {String} network - current network
13115
13093
  */
@@ -13129,7 +13107,7 @@ class Peernet {
13129
13107
  up: 0,
13130
13108
  down: 0,
13131
13109
  };
13132
- return this._init(options);
13110
+ return this._init(options, password);
13133
13111
  }
13134
13112
  get id() {
13135
13113
  return this.identity.id;
@@ -13195,13 +13173,13 @@ class Peernet {
13195
13173
  *
13196
13174
  * @return {Promise} instance of Peernet
13197
13175
  */
13198
- async _init(options) {
13176
+ async _init(options, password) {
13199
13177
  this.requestProtos = {};
13200
13178
  this.storePrefix = options.storePrefix;
13201
13179
  this.root = options.root;
13202
13180
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
13203
13181
  // FolderMessageResponse
13204
- } = await import(/* webpackChunkName: "messages" */ './messages-c820f513.js');
13182
+ } = await import(/* webpackChunkName: "messages" */ './messages-2214fcbb.js');
13205
13183
  /**
13206
13184
  * proto Object containing protos
13207
13185
  * @type {Object}
@@ -13232,7 +13210,7 @@ class Peernet {
13232
13210
  await this.addStore(store, options.storePrefix, options.root);
13233
13211
  }
13234
13212
  this.identity = new Identity(this.network);
13235
- await this.identity.load();
13213
+ await this.identity.load(password);
13236
13214
  this._peerHandler = new PeerDiscovery(this.id);
13237
13215
  this.peerId = this.id;
13238
13216
  pubsub.subscribe('peer:connected', async (peer) => {
@@ -13250,7 +13228,7 @@ class Peernet {
13250
13228
  * @see DataHandler
13251
13229
  */
13252
13230
  pubsub.subscribe('peer:data', dataHandler);
13253
- const importee = await import('./client-94d84d27.js');
13231
+ const importee = await import('./client-95423644.js');
13254
13232
  /**
13255
13233
  * @access public
13256
13234
  * @type {PeernetClient}
@@ -13694,4 +13672,4 @@ class Peernet {
13694
13672
  }
13695
13673
  globalThis.Peernet = Peernet;
13696
13674
 
13697
- export { FormatInterface as F, LittlePubSub as L, MultiWallet$1 as M, Peernet as P };
13675
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P };
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-1908438f.js';
1
+ export { P as default } from './peernet-e74b2091.js';
2
2
  import './value-157ab062.js';
@@ -3,7 +3,7 @@ import PubSub from '@vandeurenglenn/little-pubsub';
3
3
  import { Codec } from '@leofcoin/codec-format-interface';
4
4
  import LeofcoinStorage from '@leofcoin/storage';
5
5
  import { utils } from '@leofcoin/codecs';
6
- import MultiWallet$1 from '@leofcoin/multi-wallet';
6
+ import MultiWallet from '@leofcoin/multi-wallet';
7
7
 
8
8
  const BufferToUint8Array = data => {
9
9
  if (data.type === 'Buffer') {
@@ -265,16 +265,8 @@ class MessageHandler {
265
265
  * @return message
266
266
  */
267
267
  async hashAndSignMessage(message) {
268
- let identity = await walletStore.get('identity');
269
- identity = JSON.parse(identity);
270
- if (!globalThis.MultiWallet) {
271
- const importee = await import(/* webpackChunkName: "multi-wallet" */ '@leofcoin/multi-wallet');
272
- globalThis.MultiWallet = importee.default;
273
- }
274
- const wallet = new MultiWallet(this.network);
275
- wallet.recover(identity.mnemonic);
276
- const hash = await message.hash();
277
- message.decoded.signature = wallet.sign(hash.subarray(0, 32));
268
+ const hash = await message.peernetHash;
269
+ message.decoded.signature = globalThis.identity.sign(hash.buffer);
278
270
  return message;
279
271
  }
280
272
  /**
@@ -307,8 +299,6 @@ const nothingFoundError = (hash) => {
307
299
  return new Error(`nothing found for ${hash}`);
308
300
  };
309
301
 
310
- const walletStore$1 = globalThis.walletStore;
311
- const accountStore = globalThis.accountStore;
312
302
  class Identity {
313
303
  #wallet;
314
304
  network;
@@ -320,57 +310,50 @@ class Identity {
320
310
  return this.getAccounts();
321
311
  }
322
312
  async getAccounts() {
323
- let accounts = await walletStore$1.get('accounts');
313
+ let accounts = await globalThis.walletStore.get('accounts');
324
314
  accounts = new TextDecoder().decode(accounts);
325
315
  return JSON.parse(accounts);
326
316
  }
327
317
  async load(password) {
328
- let importee;
329
318
  if (!password) {
330
- if (globalThis.navigator)
331
- importee = await import('./src/prompts/password/browser.js');
332
- else {
333
- const path = await import('node:path');
334
- const { fileURLToPath } = await import('node:url');
335
- const __filename = fileURLToPath(import.meta.url);
336
- const __dirname = path.dirname(__filename);
337
- const url = path.join(__dirname, './prompts/password/node.js');
338
- importee = await import(url);
339
- }
319
+ const importee = await import('./src/prompts/password.js');
340
320
  password = await importee.default();
341
321
  }
342
- const accountExists = await accountStore.has('public');
322
+ const accountExists = await globalThis.accountStore.has('public');
343
323
  if (accountExists) {
344
- const pub = await accountStore.get('public');
324
+ const pub = await globalThis.accountStore.get('public');
345
325
  this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
346
- const selected = await walletStore$1.get('selected-account');
326
+ const selected = await globalThis.walletStore.get('selected-account');
347
327
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
348
328
  }
349
329
  else {
350
330
  const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account');
351
331
  const { identity, accounts } = await importee.default(password, this.network);
352
- await accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
353
- await walletStore$1.put('version', String(1));
354
- await walletStore$1.put('accounts', JSON.stringify(accounts));
355
- await walletStore$1.put('selected-account', accounts[0][1]);
356
- await walletStore$1.put('identity', JSON.stringify(identity));
332
+ await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
333
+ await globalThis.walletStore.put('version', String(1));
334
+ await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
335
+ await globalThis.walletStore.put('selected-account', accounts[0][1]);
336
+ await globalThis.walletStore.put('identity', JSON.stringify(identity));
357
337
  globalThis.peernet.selectedAccount = accounts[0][1];
358
338
  this.id = identity.walletId;
359
339
  }
360
- const identity = JSON.parse(new TextDecoder().decode(await walletStore$1.get('identity')));
361
- this.#wallet = new MultiWallet$1(this.network);
340
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
341
+ this.#wallet = new MultiWallet(this.network);
362
342
  await this.#wallet.recover(identity.mnemonic, password, this.network);
363
343
  }
344
+ sign(hash) {
345
+ return this.#wallet.sign(hash.subarray(0, 32));
346
+ }
364
347
  async export(password) {
365
348
  if (!password)
366
349
  throw new Error('IdentityExportError: password required');
367
- const identity = JSON.parse(new TextDecoder().decode(await walletStore$1.get('identity')));
368
- this.#wallet = new MultiWallet$1(this.network);
350
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
351
+ this.#wallet = new MultiWallet(this.network);
369
352
  await this.#wallet.recover(identity.mnemonic, password, this.network);
370
353
  return this.#wallet.toMultiWif();
371
354
  }
372
355
  async import(multiWIF) {
373
- this.#wallet = new MultiWallet$1(this.network);
356
+ this.#wallet = new MultiWallet(this.network);
374
357
  await this.#wallet.fromMultiWif(multiWIF);
375
358
  }
376
359
  async unlock({ key, iv, cipher }) {
@@ -421,7 +404,7 @@ class Peernet {
421
404
  * @example
422
405
  * const peernet = new Peernet({network: 'leofcoin', root: '.leofcoin'});
423
406
  */
424
- constructor(options) {
407
+ constructor(options, password) {
425
408
  /**
426
409
  * @property {String} network - current network
427
410
  */
@@ -441,7 +424,7 @@ class Peernet {
441
424
  up: 0,
442
425
  down: 0,
443
426
  };
444
- return this._init(options);
427
+ return this._init(options, password);
445
428
  }
446
429
  get id() {
447
430
  return this.identity.id;
@@ -507,7 +490,7 @@ class Peernet {
507
490
  *
508
491
  * @return {Promise} instance of Peernet
509
492
  */
510
- async _init(options) {
493
+ async _init(options, password) {
511
494
  this.requestProtos = {};
512
495
  this.storePrefix = options.storePrefix;
513
496
  this.root = options.root;
@@ -544,7 +527,7 @@ class Peernet {
544
527
  await this.addStore(store, options.storePrefix, options.root);
545
528
  }
546
529
  this.identity = new Identity(this.network);
547
- await this.identity.load();
530
+ await this.identity.load(password);
548
531
  this._peerHandler = new PeerDiscovery(this.id);
549
532
  this.peerId = this.id;
550
533
  pubsub.subscribe('peer:connected', async (peer) => {
@@ -0,0 +1,8 @@
1
+ import inquirer from 'inquirer';
2
+
3
+ var node = async () => {
4
+ const answers = await inquirer.prompt({type: 'password', name: 'password', message: 'Enter password'});
5
+ return answers.password
6
+ };
7
+
8
+ export { node as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "src/peernet.js",
6
6
  "exports": {
package/rollup.config.js CHANGED
@@ -10,7 +10,7 @@ rimraf.sync('./exports/**')
10
10
 
11
11
 
12
12
  export default [{
13
- input: ['./src/peernet.ts', './src/prompts/password/browser.js', './node_modules/@leofcoin/storage/exports/browser-store.js'],
13
+ input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/browser-store.js'],
14
14
  output: {
15
15
  format: 'es',
16
16
  dir: './exports/browser'
@@ -25,10 +25,10 @@ export default [{
25
25
  typescript({...tsconfig, outDir: './exports/browser'})
26
26
  ],
27
27
  external: [
28
- './prompts/password/node.js'
28
+ './prompts/password.js'
29
29
  ]
30
30
  }, {
31
- input: ['./src/peernet.ts', './src/prompts/password/node.js', './node_modules/@leofcoin/storage/exports/store.js'],
31
+ input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/store.js'],
32
32
  output: {
33
33
  format: 'es',
34
34
  dir: './exports'
@@ -37,6 +37,18 @@ export default [{
37
37
  typescript({...tsconfig, outDir: './exports'})
38
38
  ],
39
39
  external: [
40
- './prompts/password/browser.js'
40
+ './prompts/password.js'
41
41
  ]
42
+ }, {
43
+ input: ['./src/prompts/password/browser.js'],
44
+ output: {
45
+ format: 'es',
46
+ file: './exports/browser/src/prompts/password.js'
47
+ }
48
+ }, {
49
+ input: ['./src/prompts/password/node.js'],
50
+ output: {
51
+ format: 'es',
52
+ file: './exports/src/prompts/password.js'
53
+ }
42
54
  }]
package/src/identity.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import MultiWallet from '@leofcoin/multi-wallet'
2
2
 
3
- const walletStore = globalThis.walletStore
4
- const accountStore = globalThis.accountStore
5
-
6
3
  export default class Identity {
7
4
  #wallet: MultiWallet
8
5
  network: MultiWallet.network
@@ -17,46 +14,37 @@ export default class Identity {
17
14
  }
18
15
 
19
16
  async getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]> {
20
- let accounts = await walletStore.get('accounts')
17
+ let accounts = await globalThis.walletStore.get('accounts')
21
18
  accounts = new TextDecoder().decode(accounts)
22
19
  return JSON.parse(accounts)
23
20
  }
24
21
 
25
- async load(password?: string): Promise<void> {
26
- let importee: { default: () => Promise<string> }
22
+ async load(password?: string): Promise<void> {
27
23
  if (!password) {
28
- if (globalThis.navigator) importee = await import('./prompts/password/browser.js')
29
- else {
30
- const path = await import('node:path');
31
- const { fileURLToPath } = await import('node:url');
32
- const __filename = fileURLToPath(import.meta.url);
33
- const __dirname = path.dirname(__filename);
34
- const url = path.join(__dirname, './prompts/password/node.js')
35
- importee = await import(url)
36
- }
24
+ const importee: { default: () => Promise<string> } = await import('./prompts/password.js')
37
25
  password = await importee.default()
38
26
  }
39
27
 
40
- const accountExists = await accountStore.has('public')
28
+ const accountExists = await globalThis.accountStore.has('public')
41
29
  if (accountExists) {
42
- const pub = await accountStore.get('public')
30
+ const pub = await globalThis.accountStore.get('public')
43
31
  this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
44
- const selected = await walletStore.get('selected-account')
32
+ const selected = await globalThis.walletStore.get('selected-account')
45
33
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected)
46
34
  } else {
47
35
  const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
48
36
  const {identity, accounts} = await importee.default(password, this.network)
49
- await accountStore.put('public', JSON.stringify({walletId: identity.walletId}));
37
+ await globalThis.accountStore.put('public', JSON.stringify({walletId: identity.walletId}));
50
38
 
51
- await walletStore.put('version', String(1))
52
- await walletStore.put('accounts', JSON.stringify(accounts))
53
- await walletStore.put('selected-account', accounts[0][1])
54
- await walletStore.put('identity', JSON.stringify(identity))
39
+ await globalThis.walletStore.put('version', String(1))
40
+ await globalThis.walletStore.put('accounts', JSON.stringify(accounts))
41
+ await globalThis.walletStore.put('selected-account', accounts[0][1])
42
+ await globalThis.walletStore.put('identity', JSON.stringify(identity))
55
43
 
56
44
  globalThis.peernet.selectedAccount = accounts[0][1]
57
45
  this.id = identity.walletId
58
46
  }
59
- const identity = JSON.parse(new TextDecoder().decode(await walletStore.get('identity')))
47
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')))
60
48
  this.#wallet = new MultiWallet(this.network)
61
49
  await this.#wallet.recover(identity.mnemonic, password, this.network)
62
50
  }
@@ -67,7 +55,7 @@ export default class Identity {
67
55
 
68
56
  async export(password: string) {
69
57
  if (!password) throw new Error('IdentityExportError: password required')
70
- const identity = JSON.parse(new TextDecoder().decode(await walletStore.get('identity')))
58
+ const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')))
71
59
  this.#wallet = new MultiWallet(this.network)
72
60
  await this.#wallet.recover(identity.mnemonic, password, this.network)
73
61
  return this.#wallet.toMultiWif()
package/exports/node.js DELETED
@@ -1,8 +0,0 @@
1
- import inquirer from 'inquirer';
2
-
3
- var node = async () => {
4
- const answers = await inquirer.prompt({ type: 'password', name: 'password', message: 'Enter password' });
5
- return answers.password;
6
- };
7
-
8
- export { node as default };