@leofcoin/peernet 1.0.3 → 1.0.5

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,5 +1,6 @@
1
- import { L as LittlePubSub } from './peernet-e1e0a046.js';
1
+ import { L as LittlePubSub } from './peernet-76472a7f.js';
2
2
  import './value-157ab062.js';
3
+ import 'fs/promises';
3
4
 
4
5
  var clientApi = _pubsub => {
5
6
 
@@ -1,27 +1,7 @@
1
- import { M as MultiWallet, b as base58$1, r as randombytes, i as index$1 } from './peernet-e1e0a046.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './peernet-76472a7f.js';
2
2
  import './value-157ab062.js';
3
+ import 'fs/promises';
3
4
 
4
- const passwordToKey = (password) => globalThis.crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveKey']);
5
- const deriveKey = (key, salt, iterations = 250000, hashAlgorithm = 'SHA-512') => globalThis.crypto.subtle.deriveKey({
6
- name: 'PBKDF2',
7
- salt,
8
- iterations,
9
- hash: hashAlgorithm
10
- }, key, {
11
- name: 'AES-GCM',
12
- length: 256
13
- }, false, ['encrypt', 'decrypt']);
14
- const encrypt = async (password, data, version = new TextEncoder().encode('1')) => {
15
- const passwordKey = await passwordToKey(new TextEncoder().encode(password));
16
- const salt = randombytes(16);
17
- const iv = randombytes(16);
18
- const key = await deriveKey(passwordKey, salt);
19
- const encrypted = await globalThis.crypto.subtle.encrypt({
20
- name: 'AES-GCM',
21
- iv
22
- }, key, new TextEncoder().encode(data));
23
- return index$1([version, salt, iv, new Uint8Array(encrypted)]);
24
- };
25
5
  /**
26
6
  * @params {String} network
27
7
  * @return {object} { identity, accounts, config }
@@ -1,5 +1,6 @@
1
- import { F as FormatInterface } from './peernet-e1e0a046.js';
1
+ import { F as FormatInterface } from './peernet-76472a7f.js';
2
2
  import './value-157ab062.js';
3
+ import 'fs/promises';
3
4
 
4
5
  var proto$b = {
5
6
  data: new Uint8Array(),
@@ -1,4 +1,5 @@
1
1
  import { K as KeyValue } from './value-157ab062.js';
2
+ import { readFile } from 'fs/promises';
2
3
 
3
4
  if (!globalThis.DEBUG) {
4
5
  if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
@@ -1467,444 +1468,446 @@ var utils$p = {
1467
1468
  */
1468
1469
  var isHex = (function (string) { return /^[A-F0-9]+$/i.test(string); });
1469
1470
 
1470
- let BasicInterface$1 = class BasicInterface {
1471
- encoded;
1472
- decoded;
1473
- keys;
1474
- name;
1475
- #proto;
1476
- set proto(value) {
1477
- this.#proto = value;
1478
- this.keys = Object.keys(value);
1479
- }
1480
- get proto() {
1481
- return this.#proto;
1482
- }
1483
- decode(encoded) {
1484
- encoded = encoded || this.encoded;
1485
- return new Object();
1486
- }
1487
- encode(decoded) {
1488
- decoded = decoded || this.decoded;
1489
- return new Uint8Array();
1490
- }
1491
- // get Codec(): Codec {}
1492
- protoEncode(data) {
1493
- // check schema
1494
- return index$1.encode(this.proto, data);
1495
- }
1496
- protoDecode(data) {
1497
- // check schema
1498
- return index$1.decode(this.proto, data);
1499
- }
1500
- isHex(string) {
1501
- return isHex(string);
1502
- }
1503
- isBase32(string) {
1504
- return index$8.isBase32(string);
1505
- }
1506
- isBase58(string) {
1507
- return base58$1.isBase58(string);
1508
- }
1509
- fromBs32(encoded) {
1510
- return this.decode(index$8.decode(encoded));
1511
- }
1512
- fromBs58(encoded) {
1513
- return this.decode(fromBase58(encoded));
1514
- }
1515
- async toArray() {
1516
- const array = [];
1517
- for await (const value of this.encoded.values()) {
1518
- array.push(value);
1519
- }
1520
- return array;
1521
- }
1522
- fromString(string) {
1523
- const array = string.split(',');
1524
- const arrayLike = array.map(string => Number(string));
1525
- return this.decode(Uint8Array.from(arrayLike));
1526
- }
1527
- fromHex(string) {
1528
- return this.decode(fromHex(string));
1529
- }
1530
- fromArray(array) {
1531
- return this.decode(Uint8Array.from([...array]));
1532
- }
1533
- fromEncoded(encoded) {
1534
- return this.decode(encoded);
1535
- }
1536
- toString() {
1537
- if (!this.encoded)
1538
- this.encode();
1539
- return this.encoded.toString();
1540
- }
1541
- toHex() {
1542
- if (!this.encoded)
1543
- this.encode();
1544
- return toHex$1(this.encoded.toString().split(',').map(number => Number(number)));
1545
- }
1546
- /**
1547
- * @return {String} encoded
1548
- */
1549
- toBs32() {
1550
- if (!this.encoded)
1551
- this.encode();
1552
- return toBase32(this.encoded);
1553
- }
1554
- /**
1555
- * @return {String} encoded
1556
- */
1557
- toBs58() {
1558
- if (!this.encoded)
1559
- this.encode();
1560
- return toBase58(this.encoded);
1561
- }
1471
+ let BasicInterface$1 = class BasicInterface {
1472
+ encoded;
1473
+ decoded;
1474
+ keys;
1475
+ name;
1476
+ #proto;
1477
+ set proto(value) {
1478
+ this.#proto = value;
1479
+ this.keys = Object.keys(value);
1480
+ }
1481
+ get proto() {
1482
+ return this.#proto;
1483
+ }
1484
+ decode(encoded) {
1485
+ encoded = encoded || this.encoded;
1486
+ return new Object();
1487
+ }
1488
+ encode(decoded) {
1489
+ decoded = decoded || this.decoded;
1490
+ return new Uint8Array();
1491
+ }
1492
+ // get Codec(): Codec {}
1493
+ protoEncode(data) {
1494
+ // check schema
1495
+ return index$1.encode(this.proto, data);
1496
+ }
1497
+ protoDecode(data) {
1498
+ // check schema
1499
+ return index$1.decode(this.proto, data);
1500
+ }
1501
+ isHex(string) {
1502
+ return isHex(string);
1503
+ }
1504
+ isBase32(string) {
1505
+ return index$8.isBase32(string);
1506
+ }
1507
+ isBase58(string) {
1508
+ return base58$1.isBase58(string);
1509
+ }
1510
+ fromBs32(encoded) {
1511
+ return this.decode(index$8.decode(encoded));
1512
+ }
1513
+ fromBs58(encoded) {
1514
+ return this.decode(fromBase58(encoded));
1515
+ }
1516
+ async toArray() {
1517
+ const array = [];
1518
+ for await (const value of this.encoded.values()) {
1519
+ array.push(value);
1520
+ }
1521
+ return array;
1522
+ }
1523
+ fromString(string) {
1524
+ const array = string.split(',');
1525
+ const arrayLike = array.map(string => Number(string));
1526
+ return this.decode(Uint8Array.from(arrayLike));
1527
+ }
1528
+ fromHex(string) {
1529
+ return this.decode(fromHex(string));
1530
+ }
1531
+ fromArray(array) {
1532
+ return this.decode(Uint8Array.from([...array]));
1533
+ }
1534
+ fromEncoded(encoded) {
1535
+ return this.decode(encoded);
1536
+ }
1537
+ toString() {
1538
+ if (!this.encoded)
1539
+ this.encode();
1540
+ return this.encoded.toString();
1541
+ }
1542
+ toHex() {
1543
+ if (!this.encoded)
1544
+ this.encode();
1545
+ return toHex$1(this.encoded.toString().split(',').map(number => Number(number)));
1546
+ }
1547
+ /**
1548
+ * @return {String} encoded
1549
+ */
1550
+ toBs32() {
1551
+ if (!this.encoded)
1552
+ this.encode();
1553
+ return toBase32(this.encoded);
1554
+ }
1555
+ /**
1556
+ * @return {String} encoded
1557
+ */
1558
+ toBs58() {
1559
+ if (!this.encoded)
1560
+ this.encode();
1561
+ return toBase58(this.encoded);
1562
+ }
1562
1563
  };
1563
1564
 
1564
- let Codec$1 = class Codec extends BasicInterface$1 {
1565
- codecBuffer;
1566
- codec;
1567
- hashAlg;
1568
- constructor(buffer) {
1569
- super();
1570
- if (buffer) {
1571
- if (buffer instanceof Uint8Array) {
1572
- const codec = index$7.decode(buffer);
1573
- const name = this.getCodecName(codec);
1574
- if (name) {
1575
- this.name = name;
1576
- this.encoded = buffer;
1577
- this.decode(buffer);
1578
- }
1579
- else {
1580
- this.encode(Number(new TextDecoder().decode(buffer)));
1581
- }
1582
- }
1583
- else if (buffer instanceof ArrayBuffer) {
1584
- const codec = index$7.decode(buffer);
1585
- const name = this.getCodecName(codec);
1586
- if (name) {
1587
- this.name = name;
1588
- this.decode(buffer);
1589
- }
1590
- else {
1591
- this.encode(Number(new TextDecoder().decode(new Uint8Array(buffer))));
1592
- }
1593
- }
1594
- else if (typeof buffer === 'string') {
1595
- if (utils$p.getCodec(buffer))
1596
- this.fromName(buffer);
1597
- else if (this.isHex(buffer))
1598
- this.fromHex(buffer);
1599
- else if (this.isBase32(buffer))
1600
- this.fromBs32(buffer);
1601
- else if (this.isBase58(buffer))
1602
- this.fromBs58(buffer);
1603
- else
1604
- this.fromString(buffer);
1605
- }
1606
- if (!isNaN(buffer))
1607
- if (utils$p.getCodec(buffer))
1608
- this.fromCodec(buffer);
1609
- }
1610
- }
1611
- fromEncoded(encoded) {
1612
- const codec = index$7.decode(encoded);
1613
- const name = this.getCodecName(codec);
1614
- this.name = name;
1615
- this.encoded = encoded;
1616
- return this.decode(encoded);
1617
- }
1618
- getCodec(name) {
1619
- return utils$p.getCodec(name);
1620
- }
1621
- getCodecName(codec) {
1622
- return utils$p.getCodecName(codec);
1623
- }
1624
- getHashAlg(name) {
1625
- return utils$p.getHashAlg(name);
1626
- }
1627
- fromCodec(codec) {
1628
- this.name = this.getCodecName(codec);
1629
- this.hashAlg = this.getHashAlg(this.name);
1630
- this.codec = this.getCodec(this.name);
1631
- this.codecBuffer = index$7.encode(this.codec);
1632
- }
1633
- fromName(name) {
1634
- const codec = this.getCodec(name);
1635
- this.name = name;
1636
- this.codec = codec;
1637
- this.hashAlg = this.getHashAlg(name);
1638
- this.codecBuffer = index$7.encode(this.codec);
1639
- }
1640
- decode(encoded) {
1641
- encoded = encoded || this.encoded;
1642
- const codec = index$7.decode(encoded);
1643
- this.fromCodec(codec);
1644
- return this.decoded;
1645
- }
1646
- encode(codec) {
1647
- codec = codec || this.codec;
1648
- this.encoded = index$7.encode(codec);
1649
- return this.encoded;
1650
- }
1565
+ let Codec$1 = class Codec extends BasicInterface$1 {
1566
+ codecBuffer;
1567
+ codec;
1568
+ hashAlg;
1569
+ constructor(buffer) {
1570
+ super();
1571
+ if (buffer) {
1572
+ if (buffer instanceof Uint8Array) {
1573
+ const codec = index$7.decode(buffer);
1574
+ const name = this.getCodecName(codec);
1575
+ if (name) {
1576
+ this.name = name;
1577
+ this.encoded = buffer;
1578
+ this.decode(buffer);
1579
+ }
1580
+ else {
1581
+ this.encode(Number(new TextDecoder().decode(buffer)));
1582
+ }
1583
+ }
1584
+ else if (buffer instanceof ArrayBuffer) {
1585
+ const codec = index$7.decode(new Uint8Array(buffer));
1586
+ const name = this.getCodecName(codec);
1587
+ if (name) {
1588
+ this.name = name;
1589
+ this.decode(buffer);
1590
+ }
1591
+ else {
1592
+ this.encode(Number(new TextDecoder().decode(new Uint8Array(buffer))));
1593
+ }
1594
+ }
1595
+ else if (typeof buffer === 'string') {
1596
+ if (utils$p.getCodec(buffer))
1597
+ this.fromName(buffer);
1598
+ else if (this.isHex(buffer))
1599
+ this.fromHex(buffer);
1600
+ else if (this.isBase32(buffer))
1601
+ this.fromBs32(buffer);
1602
+ else if (this.isBase58(buffer))
1603
+ this.fromBs58(buffer);
1604
+ else
1605
+ this.fromString(buffer);
1606
+ }
1607
+ if (!isNaN(buffer))
1608
+ if (utils$p.getCodec(buffer))
1609
+ this.fromCodec(buffer);
1610
+ }
1611
+ }
1612
+ fromEncoded(encoded) {
1613
+ const codec = index$7.decode(encoded);
1614
+ const name = this.getCodecName(codec);
1615
+ this.name = name;
1616
+ this.encoded = encoded;
1617
+ return this.decode(encoded);
1618
+ }
1619
+ getCodec(name) {
1620
+ return utils$p.getCodec(name);
1621
+ }
1622
+ getCodecName(codec) {
1623
+ return utils$p.getCodecName(codec);
1624
+ }
1625
+ getHashAlg(name) {
1626
+ return utils$p.getHashAlg(name);
1627
+ }
1628
+ fromCodec(codec) {
1629
+ this.name = this.getCodecName(codec);
1630
+ this.hashAlg = this.getHashAlg(this.name);
1631
+ this.codec = this.getCodec(this.name);
1632
+ this.codecBuffer = index$7.encode(this.codec);
1633
+ }
1634
+ fromName(name) {
1635
+ const codec = this.getCodec(name);
1636
+ this.name = name;
1637
+ this.codec = codec;
1638
+ this.hashAlg = this.getHashAlg(name);
1639
+ this.codecBuffer = index$7.encode(this.codec);
1640
+ }
1641
+ decode(encoded) {
1642
+ encoded = encoded || this.encoded;
1643
+ const codec = index$7.decode(encoded);
1644
+ this.fromCodec(codec);
1645
+ return this.decoded;
1646
+ }
1647
+ encode(codec) {
1648
+ codec = codec || this.codec;
1649
+ this.encoded = index$7.encode(codec);
1650
+ return this.encoded;
1651
+ }
1651
1652
  };
1652
1653
 
1653
- let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1654
- constructor(buffer, options = {}) {
1655
- super();
1656
- if (options.name)
1657
- this.name = options.name;
1658
- else
1659
- this.name = 'disco-hash';
1660
- if (options.codecs)
1661
- this.codecs = options.codecs;
1662
- return this.init(buffer);
1663
- }
1664
- async init(uint8Array) {
1665
- if (uint8Array) {
1666
- if (uint8Array instanceof Uint8Array) {
1667
- this.discoCodec = new Codec$1(uint8Array, this.codecs);
1668
- const name = this.discoCodec.name;
1669
- if (name) {
1670
- this.name = name;
1671
- this.decode(uint8Array);
1672
- }
1673
- else {
1674
- await this.encode(uint8Array);
1675
- }
1676
- }
1677
- if (typeof uint8Array === 'string') {
1678
- if (this.isHex(uint8Array))
1679
- await this.fromHex(uint8Array);
1680
- if (this.isBase32(uint8Array))
1681
- await this.fromBs32(uint8Array);
1682
- else if (this.isBase58(uint8Array))
1683
- await this.fromBs58(uint8Array);
1684
- else
1685
- throw new Error(`unsupported string ${uint8Array}`);
1686
- }
1687
- else if (typeof uint8Array === 'object')
1688
- await this.fromJSON(uint8Array);
1689
- }
1690
- return this;
1691
- }
1692
- get prefix() {
1693
- const length = this.length;
1694
- const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
1695
- uint8Array.set(length);
1696
- uint8Array.set(this.discoCodec.codecBuffer, length.length);
1697
- return uint8Array;
1698
- }
1699
- get length() {
1700
- return index$7.encode(this.size);
1701
- }
1702
- get buffer() {
1703
- return this.encoded;
1704
- }
1705
- get hash() {
1706
- return this.encoded;
1707
- }
1708
- fromJSON(json) {
1709
- return this.encode(Buffer.from(JSON.stringify(json)));
1710
- }
1711
- async encode(buffer, name) {
1712
- if (!this.name && name)
1713
- this.name = name;
1714
- if (!buffer)
1715
- buffer = this.buffer;
1716
- this.discoCodec = new Codec$1(this.name, this.codecs);
1717
- this.discoCodec.fromName(this.name);
1718
- let hashAlg = this.discoCodec.hashAlg;
1719
- const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
1720
- if (hashAlg.includes('dbl')) {
1721
- hashAlg = hashAlg.replace('dbl-', '');
1722
- const hasher = await createKeccak(hashVariant);
1723
- await hasher.init();
1724
- hasher.update(buffer);
1725
- buffer = hasher.digest('binary');
1726
- }
1727
- const hasher = await createKeccak(hashVariant);
1728
- await hasher.init();
1729
- hasher.update(buffer);
1730
- this.digest = hasher.digest('binary');
1731
- this.size = this.digest.length;
1732
- this.codec = this.discoCodec.encode();
1733
- this.codec = this.discoCodec.codecBuffer;
1734
- const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
1735
- uint8Array.set(this.prefix);
1736
- uint8Array.set(this.digest, this.prefix.length);
1737
- this.encoded = uint8Array;
1738
- return this.encoded;
1739
- }
1740
- async validate(buffer) {
1741
- if (Buffer.isBuffer(buffer)) {
1742
- const codec = index$7.decode(buffer);
1743
- if (this.codecs[codec]) {
1744
- this.decode(buffer);
1745
- }
1746
- else {
1747
- await this.encode(buffer);
1748
- }
1749
- }
1750
- if (typeof buffer === 'string') {
1751
- if (this.isHex(buffer))
1752
- this.fromHex(buffer);
1753
- if (this.isBase32(buffer))
1754
- this.fromBs32(buffer);
1755
- }
1756
- if (typeof buffer === 'object')
1757
- this.fromJSON(buffer);
1758
- }
1759
- decode(buffer) {
1760
- this.encoded = buffer;
1761
- const codec = index$7.decode(buffer);
1762
- this.discoCodec = new Codec$1(codec, this.codecs);
1763
- // TODO: validate codec
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
- if (this.digest.length !== this.size) {
1768
- throw new Error(`hash length inconsistent: 0x${this.encoded.toString('hex')}`);
1769
- }
1770
- // const discoCodec = new Codec(codec, this.codecs)
1771
- this.name = this.discoCodec.name;
1772
- this.size = this.digest.length;
1773
- return {
1774
- codec: this.codec,
1775
- name: this.name,
1776
- size: this.size,
1777
- length: this.length,
1778
- digest: this.digest,
1779
- };
1780
- }
1654
+ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1655
+ codec;
1656
+ codecs;
1657
+ digest;
1658
+ size;
1659
+ constructor(buffer, options) {
1660
+ super();
1661
+ if (options.name)
1662
+ this.name = options.name;
1663
+ else
1664
+ this.name = 'disco-hash';
1665
+ if (options.codecs)
1666
+ this.codecs = options.codecs;
1667
+ return this.init(buffer);
1668
+ }
1669
+ async init(uint8Array) {
1670
+ if (uint8Array) {
1671
+ if (uint8Array instanceof Uint8Array) {
1672
+ this.codec = new Codec$1(uint8Array);
1673
+ const name = this.codec.name;
1674
+ if (name) {
1675
+ this.name = name;
1676
+ this.decode(uint8Array);
1677
+ }
1678
+ else {
1679
+ await this.encode(uint8Array);
1680
+ }
1681
+ }
1682
+ if (typeof uint8Array === 'string') {
1683
+ if (this.isHex(uint8Array))
1684
+ await this.fromHex(uint8Array);
1685
+ if (this.isBase32(uint8Array))
1686
+ await this.fromBs32(uint8Array);
1687
+ else if (this.isBase58(uint8Array))
1688
+ await this.fromBs58(uint8Array);
1689
+ else
1690
+ throw new Error(`unsupported string ${uint8Array}`);
1691
+ }
1692
+ else if (typeof uint8Array === 'object')
1693
+ await this.fromJSON(uint8Array);
1694
+ }
1695
+ return this;
1696
+ }
1697
+ get prefix() {
1698
+ const length = this.length;
1699
+ const uint8Array = new Uint8Array(length.length + this.codec.codecBuffer.length);
1700
+ uint8Array.set(length);
1701
+ uint8Array.set(this.codec.codecBuffer, length.length);
1702
+ return uint8Array;
1703
+ }
1704
+ get length() {
1705
+ return index$7.encode(this.size);
1706
+ }
1707
+ get buffer() {
1708
+ return this.encoded;
1709
+ }
1710
+ get hash() {
1711
+ return this.encoded;
1712
+ }
1713
+ fromJSON(json) {
1714
+ return this.encode(new TextEncoder().encode(JSON.stringify(json)));
1715
+ }
1716
+ async encode(buffer, name) {
1717
+ if (!this.name && name)
1718
+ this.name = name;
1719
+ if (!buffer)
1720
+ buffer = this.buffer;
1721
+ this.codec = new Codec$1(this.name);
1722
+ this.codec.fromName(this.name);
1723
+ let hashAlg = this.codec.hashAlg;
1724
+ const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
1725
+ if (hashAlg.includes('dbl')) {
1726
+ hashAlg = hashAlg.replace('dbl-', '');
1727
+ const hasher = await createKeccak(hashVariant);
1728
+ await hasher.init();
1729
+ hasher.update(buffer);
1730
+ buffer = hasher.digest('binary');
1731
+ }
1732
+ const hasher = await createKeccak(hashVariant);
1733
+ await hasher.init();
1734
+ hasher.update(buffer);
1735
+ this.digest = hasher.digest('binary');
1736
+ this.size = this.digest.length;
1737
+ const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
1738
+ uint8Array.set(this.prefix);
1739
+ uint8Array.set(this.digest, this.prefix.length);
1740
+ this.encoded = uint8Array;
1741
+ return this.encoded;
1742
+ }
1743
+ async validate(buffer) {
1744
+ if (Buffer.isBuffer(buffer)) {
1745
+ const codec = index$7.decode(buffer);
1746
+ if (this.codecs[codec]) {
1747
+ this.decode(buffer);
1748
+ }
1749
+ else {
1750
+ await this.encode(buffer);
1751
+ }
1752
+ }
1753
+ if (typeof buffer === 'string') {
1754
+ if (this.isHex(buffer))
1755
+ this.fromHex(buffer);
1756
+ if (this.isBase32(buffer))
1757
+ this.fromBs32(buffer);
1758
+ }
1759
+ if (typeof buffer === 'object')
1760
+ this.fromJSON(buffer);
1761
+ }
1762
+ decode(buffer) {
1763
+ this.encoded = buffer;
1764
+ const codec = index$7.decode(buffer);
1765
+ this.codec = new Codec$1(codec);
1766
+ // TODO: validate codec
1767
+ buffer = buffer.slice(index$7.decode.bytes);
1768
+ this.size = index$7.decode(buffer);
1769
+ this.digest = buffer.slice(index$7.decode.bytes);
1770
+ if (this.digest.length !== this.size) {
1771
+ throw new Error(`hash length inconsistent: ${this.encoded.toString()}`);
1772
+ }
1773
+ // const codec = new Codec(codec, this.codecs)
1774
+ this.name = this.codec.name;
1775
+ this.size = this.digest.length;
1776
+ return {
1777
+ codec: this.codec,
1778
+ name: this.name,
1779
+ size: this.size,
1780
+ length: this.length,
1781
+ digest: this.digest,
1782
+ };
1783
+ }
1781
1784
  };
1782
1785
 
1783
- let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
1784
- hashFormat;
1785
- init(buffer) {
1786
- if (buffer instanceof Uint8Array)
1787
- this.fromUint8Array(buffer);
1788
- else if (buffer instanceof ArrayBuffer)
1789
- this.fromArrayBuffer(buffer);
1790
- else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
1791
- return buffer;
1792
- else if (typeof buffer === 'string') {
1793
- if (this.isHex(buffer))
1794
- this.fromHex(buffer);
1795
- else if (this.isBase58(buffer))
1796
- this.fromBs58(buffer);
1797
- else if (this.isBase32(buffer))
1798
- this.fromBs32(buffer);
1799
- else
1800
- this.fromString(buffer);
1801
- }
1802
- else {
1803
- this.create(buffer);
1804
- }
1805
- return this;
1806
- }
1807
- hasCodec() {
1808
- if (!this.encoded)
1809
- return false;
1810
- const codec = new Codec$1(this.encoded);
1811
- if (codec.name)
1812
- return true;
1813
- }
1814
- decode(encoded) {
1815
- encoded = encoded || this.encoded;
1816
- const codec = new Codec$1(this.encoded);
1817
- if (codec.codecBuffer) {
1818
- encoded = encoded.slice(codec.codecBuffer.length);
1819
- this.name = codec.name;
1820
- this.decoded = this.protoDecode(encoded);
1821
- // try {
1822
- // this.decoded = JSON.parse(this.decoded)
1823
- // } catch {
1824
- // }
1825
- }
1826
- else {
1827
- throw new Error(`no codec found`);
1828
- }
1829
- return this.decoded;
1830
- }
1831
- encode(decoded) {
1832
- let encoded;
1833
- if (!decoded)
1834
- decoded = this.decoded;
1835
- const codec = new Codec$1(this.name);
1836
- if (decoded instanceof Uint8Array)
1837
- encoded = decoded;
1838
- else
1839
- encoded = this.protoEncode(decoded);
1840
- if (codec.codecBuffer) {
1841
- const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
1842
- uint8Array.set(codec.codecBuffer);
1843
- uint8Array.set(encoded, codec.codecBuffer.length);
1844
- this.encoded = uint8Array;
1845
- }
1846
- else {
1847
- throw new Error(`invalid codec`);
1848
- }
1849
- return this.encoded;
1850
- }
1851
- /**
1852
- * @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
1853
- * @param {Object} proto - {protoObject}
1854
- * @param {Object} options - {hashFormat, name}
1855
- */
1856
- constructor(buffer, proto, options) {
1857
- super();
1858
- this.proto = proto;
1859
- this.hashFormat = options?.hashFormat ? options.hashFormat : 'bs32';
1860
- if (options?.name)
1861
- this.name = options.name;
1862
- this.init(buffer);
1863
- }
1864
- /**
1865
- * @return {PeernetHash}
1866
- */
1867
- get peernetHash() {
1868
- return new CodecHash$1(this.decoded, { name: this.name });
1869
- }
1870
- /**
1871
- * @return {peernetHash}
1872
- */
1873
- async hash() {
1874
- const upper = this.hashFormat.charAt(0).toUpperCase();
1875
- const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
1876
- return (await this.peernetHash)[`to${format}`]();
1877
- }
1878
- fromUint8Array(buffer) {
1879
- this.encoded = buffer;
1880
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1881
- }
1882
- fromArrayBuffer(buffer) {
1883
- this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
1884
- return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1885
- }
1886
- /**
1887
- * @param {Object} data
1888
- */
1889
- create(data) {
1890
- const decoded = {};
1891
- if (this.keys?.length > 0) {
1892
- for (const key of this.keys) {
1893
- Object.defineProperties(decoded, {
1894
- [key]: {
1895
- enumerable: true,
1896
- configurable: true,
1897
- set: (value) => data[key],
1898
- get: () => data[key]
1899
- }
1900
- });
1901
- }
1902
- this.decoded = decoded;
1903
- return this.encode(decoded);
1904
- }
1905
- }
1786
+ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
1787
+ hashFormat;
1788
+ init(buffer) {
1789
+ if (buffer instanceof Uint8Array)
1790
+ this.fromUint8Array(buffer);
1791
+ else if (buffer instanceof ArrayBuffer)
1792
+ this.fromArrayBuffer(buffer);
1793
+ else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
1794
+ return buffer;
1795
+ else if (typeof buffer === 'string') {
1796
+ if (this.isHex(buffer))
1797
+ this.fromHex(buffer);
1798
+ else if (this.isBase58(buffer))
1799
+ this.fromBs58(buffer);
1800
+ else if (this.isBase32(buffer))
1801
+ this.fromBs32(buffer);
1802
+ else
1803
+ this.fromString(buffer);
1804
+ }
1805
+ else {
1806
+ this.create(buffer);
1807
+ }
1808
+ return this;
1809
+ }
1810
+ hasCodec() {
1811
+ if (!this.encoded)
1812
+ return false;
1813
+ const codec = new Codec$1(this.encoded);
1814
+ if (codec.name)
1815
+ return true;
1816
+ }
1817
+ decode(encoded) {
1818
+ encoded = encoded || this.encoded;
1819
+ const codec = new Codec$1(this.encoded);
1820
+ if (codec.codecBuffer) {
1821
+ encoded = encoded.slice(codec.codecBuffer.length);
1822
+ this.name = codec.name;
1823
+ this.decoded = this.protoDecode(encoded);
1824
+ // try {
1825
+ // this.decoded = JSON.parse(this.decoded)
1826
+ // } catch {
1827
+ // }
1828
+ }
1829
+ else {
1830
+ throw new Error(`no codec found`);
1831
+ }
1832
+ return this.decoded;
1833
+ }
1834
+ encode(decoded) {
1835
+ let encoded;
1836
+ if (!decoded)
1837
+ decoded = this.decoded;
1838
+ const codec = new Codec$1(this.name);
1839
+ if (decoded instanceof Uint8Array)
1840
+ encoded = decoded;
1841
+ else
1842
+ encoded = this.protoEncode(decoded);
1843
+ if (codec.codecBuffer) {
1844
+ const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
1845
+ uint8Array.set(codec.codecBuffer);
1846
+ uint8Array.set(encoded, codec.codecBuffer.length);
1847
+ this.encoded = uint8Array;
1848
+ }
1849
+ else {
1850
+ throw new Error(`invalid codec`);
1851
+ }
1852
+ return this.encoded;
1853
+ }
1854
+ /**
1855
+ * @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
1856
+ * @param {Object} proto - {protoObject}
1857
+ * @param {Object} options - {hashFormat, name}
1858
+ */
1859
+ constructor(buffer, proto, options) {
1860
+ super();
1861
+ this.proto = proto;
1862
+ this.hashFormat = options?.hashFormat ? options.hashFormat : 'bs32';
1863
+ if (options?.name)
1864
+ this.name = options.name;
1865
+ this.init(buffer);
1866
+ }
1867
+ /**
1868
+ * @return {PeernetHash}
1869
+ */
1870
+ get peernetHash() {
1871
+ return new CodecHash$1(this.decoded, { name: this.name });
1872
+ }
1873
+ /**
1874
+ * @return {peernetHash}
1875
+ */
1876
+ async hash() {
1877
+ const upper = this.hashFormat.charAt(0).toUpperCase();
1878
+ const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
1879
+ return (await this.peernetHash)[`to${format}`]();
1880
+ }
1881
+ fromUint8Array(buffer) {
1882
+ this.encoded = buffer;
1883
+ return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1884
+ }
1885
+ fromArrayBuffer(buffer) {
1886
+ this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
1887
+ return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1888
+ }
1889
+ /**
1890
+ * @param {Object} data
1891
+ */
1892
+ create(data) {
1893
+ const decoded = {};
1894
+ if (this.keys?.length > 0) {
1895
+ for (const key of this.keys) {
1896
+ Object.defineProperties(decoded, {
1897
+ [key]: {
1898
+ enumerable: true,
1899
+ configurable: true,
1900
+ set: (value) => data[key],
1901
+ get: () => data[key]
1902
+ }
1903
+ });
1904
+ }
1905
+ this.decoded = decoded;
1906
+ return this.encode(decoded);
1907
+ }
1908
+ }
1906
1909
  };
1907
- const FormatInterface = FormatInterface$1;
1910
+ const FormatInterface = FormatInterface$1;
1908
1911
  const Codec = Codec$1;
1909
1912
 
1910
1913
  const BufferToUint8Array = data => {
@@ -16059,6 +16062,8 @@ class Identity {
16059
16062
  return JSON.parse(accounts);
16060
16063
  }
16061
16064
  async load(password) {
16065
+ if (password && password.includes('.txt'))
16066
+ password = (await readFile(password)).toString();
16062
16067
  if (!password) {
16063
16068
  const importee = await import('./src/prompts/password.js');
16064
16069
  password = await importee.default();
@@ -16071,7 +16076,7 @@ class Identity {
16071
16076
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
16072
16077
  }
16073
16078
  else {
16074
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-601960df.js');
16079
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-ae8a0f11.js');
16075
16080
  const { identity, accounts } = await importee.default(password, this.network);
16076
16081
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
16077
16082
  await globalThis.walletStore.put('version', String(1));
@@ -16237,7 +16242,7 @@ class Peernet {
16237
16242
  this.root = options.root;
16238
16243
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
16239
16244
  // FolderMessageResponse
16240
- } = await import(/* webpackChunkName: "messages" */ './messages-cf68bfb3.js');
16245
+ } = await import(/* webpackChunkName: "messages" */ './messages-b724fbb6.js');
16241
16246
  /**
16242
16247
  * proto Object containing protos
16243
16248
  * @type {Object}
@@ -16286,7 +16291,7 @@ class Peernet {
16286
16291
  * @see DataHandler
16287
16292
  */
16288
16293
  pubsub.subscribe('peer:data', dataHandler);
16289
- const importee = await import('./client-471408b6.js');
16294
+ const importee = await import('./client-d63a0806.js');
16290
16295
  /**
16291
16296
  * @access public
16292
16297
  * @type {PeernetClient}
@@ -16730,4 +16735,4 @@ class Peernet {
16730
16735
  }
16731
16736
  globalThis.Peernet = Peernet;
16732
16737
 
16733
- export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P, base58$1 as b, index$6 as i, randombytes as r };
16738
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P, base58$1 as b, encrypt as e };
@@ -1,2 +1,3 @@
1
- export { P as default } from './peernet-e1e0a046.js';
1
+ export { P as default } from './peernet-76472a7f.js';
2
2
  import './value-157ab062.js';
3
+ import 'fs/promises';
@@ -8,6 +8,7 @@ import base58 from '@vandeurenglenn/base58';
8
8
  import { decrypt, encrypt } from '@leofcoin/identity-utils';
9
9
  import QrScanner from 'qr-scanner';
10
10
  import qrcode from 'qrcode';
11
+ import { readFile } from 'fs/promises';
11
12
 
12
13
  const BufferToUint8Array = data => {
13
14
  if (data.type === 'Buffer') {
@@ -319,6 +320,8 @@ class Identity {
319
320
  return JSON.parse(accounts);
320
321
  }
321
322
  async load(password) {
323
+ if (password && password.includes('.txt'))
324
+ password = (await readFile(password)).toString();
322
325
  if (!password) {
323
326
  const importee = await import('./src/prompts/password.js');
324
327
  password = await importee.default();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "src/peernet.js",
6
6
  "exports": {
package/src/identity.ts CHANGED
@@ -3,6 +3,7 @@ import base58 from '@vandeurenglenn/base58'
3
3
  import {encrypt, decrypt} from '@leofcoin/identity-utils'
4
4
  import QrScanner from 'qr-scanner'
5
5
  import qrcode from 'qrcode'
6
+ import { readFile } from 'fs/promises'
6
7
 
7
8
  export default class Identity {
8
9
  #wallet: MultiWallet
@@ -23,7 +24,8 @@ export default class Identity {
23
24
  return JSON.parse(accounts)
24
25
  }
25
26
 
26
- async load(password?: string): Promise<void> {
27
+ async load(password?: string): Promise<void> {
28
+ if (password && password.includes('.txt')) password = (await readFile(password)).toString()
27
29
  if (!password) {
28
30
  const importee: { default: () => Promise<string> } = await import('./prompts/password.js')
29
31
  password = await importee.default()