@leofcoin/peernet 1.0.3 → 1.0.6

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-e1e0a046.js';
1
+ import { L as LittlePubSub } from './peernet-6a78293a.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  var clientApi = _pubsub => {
@@ -1,27 +1,6 @@
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-6a78293a.js';
2
2
  import './value-157ab062.js';
3
3
 
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
4
  /**
26
5
  * @params {String} network
27
6
  * @return {object} { identity, accounts, config }
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-e1e0a046.js';
1
+ import { F as FormatInterface } from './peernet-6a78293a.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  var proto$b = {
@@ -1467,444 +1467,446 @@ var utils$p = {
1467
1467
  */
1468
1468
  var isHex = (function (string) { return /^[A-F0-9]+$/i.test(string); });
1469
1469
 
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
- }
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
+ }
1562
1562
  };
1563
1563
 
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
- }
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(new Uint8Array(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
+ }
1651
1651
  };
1652
1652
 
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
- }
1653
+ let CodecHash$1 = class CodecHash extends BasicInterface$1 {
1654
+ codec;
1655
+ codecs;
1656
+ digest;
1657
+ size;
1658
+ constructor(buffer, options) {
1659
+ super();
1660
+ if (options.name)
1661
+ this.name = options.name;
1662
+ else
1663
+ this.name = 'disco-hash';
1664
+ if (options.codecs)
1665
+ this.codecs = options.codecs;
1666
+ return this.init(buffer);
1667
+ }
1668
+ async init(uint8Array) {
1669
+ if (uint8Array) {
1670
+ if (uint8Array instanceof Uint8Array) {
1671
+ this.codec = new Codec$1(uint8Array);
1672
+ const name = this.codec.name;
1673
+ if (name) {
1674
+ this.name = name;
1675
+ this.decode(uint8Array);
1676
+ }
1677
+ else {
1678
+ await this.encode(uint8Array);
1679
+ }
1680
+ }
1681
+ if (typeof uint8Array === 'string') {
1682
+ if (this.isHex(uint8Array))
1683
+ await this.fromHex(uint8Array);
1684
+ if (this.isBase32(uint8Array))
1685
+ await this.fromBs32(uint8Array);
1686
+ else if (this.isBase58(uint8Array))
1687
+ await this.fromBs58(uint8Array);
1688
+ else
1689
+ throw new Error(`unsupported string ${uint8Array}`);
1690
+ }
1691
+ else if (typeof uint8Array === 'object')
1692
+ await this.fromJSON(uint8Array);
1693
+ }
1694
+ return this;
1695
+ }
1696
+ get prefix() {
1697
+ const length = this.length;
1698
+ const uint8Array = new Uint8Array(length.length + this.codec.codecBuffer.length);
1699
+ uint8Array.set(length);
1700
+ uint8Array.set(this.codec.codecBuffer, length.length);
1701
+ return uint8Array;
1702
+ }
1703
+ get length() {
1704
+ return index$7.encode(this.size);
1705
+ }
1706
+ get buffer() {
1707
+ return this.encoded;
1708
+ }
1709
+ get hash() {
1710
+ return this.encoded;
1711
+ }
1712
+ fromJSON(json) {
1713
+ return this.encode(new TextEncoder().encode(JSON.stringify(json)));
1714
+ }
1715
+ async encode(buffer, name) {
1716
+ if (!this.name && name)
1717
+ this.name = name;
1718
+ if (!buffer)
1719
+ buffer = this.buffer;
1720
+ this.codec = new Codec$1(this.name);
1721
+ this.codec.fromName(this.name);
1722
+ let hashAlg = this.codec.hashAlg;
1723
+ const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
1724
+ if (hashAlg.includes('dbl')) {
1725
+ hashAlg = hashAlg.replace('dbl-', '');
1726
+ const hasher = await createKeccak(hashVariant);
1727
+ await hasher.init();
1728
+ hasher.update(buffer);
1729
+ buffer = hasher.digest('binary');
1730
+ }
1731
+ const hasher = await createKeccak(hashVariant);
1732
+ await hasher.init();
1733
+ hasher.update(buffer);
1734
+ this.digest = hasher.digest('binary');
1735
+ this.size = this.digest.length;
1736
+ const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
1737
+ uint8Array.set(this.prefix);
1738
+ uint8Array.set(this.digest, this.prefix.length);
1739
+ this.encoded = uint8Array;
1740
+ return this.encoded;
1741
+ }
1742
+ async validate(buffer) {
1743
+ if (Buffer.isBuffer(buffer)) {
1744
+ const codec = index$7.decode(buffer);
1745
+ if (this.codecs[codec]) {
1746
+ this.decode(buffer);
1747
+ }
1748
+ else {
1749
+ await this.encode(buffer);
1750
+ }
1751
+ }
1752
+ if (typeof buffer === 'string') {
1753
+ if (this.isHex(buffer))
1754
+ this.fromHex(buffer);
1755
+ if (this.isBase32(buffer))
1756
+ this.fromBs32(buffer);
1757
+ }
1758
+ if (typeof buffer === 'object')
1759
+ this.fromJSON(buffer);
1760
+ }
1761
+ decode(buffer) {
1762
+ this.encoded = buffer;
1763
+ const codec = index$7.decode(buffer);
1764
+ this.codec = new Codec$1(codec);
1765
+ // TODO: validate codec
1766
+ buffer = buffer.slice(index$7.decode.bytes);
1767
+ this.size = index$7.decode(buffer);
1768
+ this.digest = buffer.slice(index$7.decode.bytes);
1769
+ if (this.digest.length !== this.size) {
1770
+ throw new Error(`hash length inconsistent: ${this.encoded.toString()}`);
1771
+ }
1772
+ // const codec = new Codec(codec, this.codecs)
1773
+ this.name = this.codec.name;
1774
+ this.size = this.digest.length;
1775
+ return {
1776
+ codec: this.codec,
1777
+ name: this.name,
1778
+ size: this.size,
1779
+ length: this.length,
1780
+ digest: this.digest,
1781
+ };
1782
+ }
1781
1783
  };
1782
1784
 
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
- }
1785
+ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
1786
+ hashFormat;
1787
+ init(buffer) {
1788
+ if (buffer instanceof Uint8Array)
1789
+ this.fromUint8Array(buffer);
1790
+ else if (buffer instanceof ArrayBuffer)
1791
+ this.fromArrayBuffer(buffer);
1792
+ else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
1793
+ return buffer;
1794
+ else if (typeof buffer === 'string') {
1795
+ if (this.isHex(buffer))
1796
+ this.fromHex(buffer);
1797
+ else if (this.isBase58(buffer))
1798
+ this.fromBs58(buffer);
1799
+ else if (this.isBase32(buffer))
1800
+ this.fromBs32(buffer);
1801
+ else
1802
+ this.fromString(buffer);
1803
+ }
1804
+ else {
1805
+ this.create(buffer);
1806
+ }
1807
+ return this;
1808
+ }
1809
+ hasCodec() {
1810
+ if (!this.encoded)
1811
+ return false;
1812
+ const codec = new Codec$1(this.encoded);
1813
+ if (codec.name)
1814
+ return true;
1815
+ }
1816
+ decode(encoded) {
1817
+ encoded = encoded || this.encoded;
1818
+ const codec = new Codec$1(this.encoded);
1819
+ if (codec.codecBuffer) {
1820
+ encoded = encoded.slice(codec.codecBuffer.length);
1821
+ this.name = codec.name;
1822
+ this.decoded = this.protoDecode(encoded);
1823
+ // try {
1824
+ // this.decoded = JSON.parse(this.decoded)
1825
+ // } catch {
1826
+ // }
1827
+ }
1828
+ else {
1829
+ throw new Error(`no codec found`);
1830
+ }
1831
+ return this.decoded;
1832
+ }
1833
+ encode(decoded) {
1834
+ let encoded;
1835
+ if (!decoded)
1836
+ decoded = this.decoded;
1837
+ const codec = new Codec$1(this.name);
1838
+ if (decoded instanceof Uint8Array)
1839
+ encoded = decoded;
1840
+ else
1841
+ encoded = this.protoEncode(decoded);
1842
+ if (codec.codecBuffer) {
1843
+ const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
1844
+ uint8Array.set(codec.codecBuffer);
1845
+ uint8Array.set(encoded, codec.codecBuffer.length);
1846
+ this.encoded = uint8Array;
1847
+ }
1848
+ else {
1849
+ throw new Error(`invalid codec`);
1850
+ }
1851
+ return this.encoded;
1852
+ }
1853
+ /**
1854
+ * @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
1855
+ * @param {Object} proto - {protoObject}
1856
+ * @param {Object} options - {hashFormat, name}
1857
+ */
1858
+ constructor(buffer, proto, options) {
1859
+ super();
1860
+ this.proto = proto;
1861
+ this.hashFormat = options?.hashFormat ? options.hashFormat : 'bs32';
1862
+ if (options?.name)
1863
+ this.name = options.name;
1864
+ this.init(buffer);
1865
+ }
1866
+ /**
1867
+ * @return {PeernetHash}
1868
+ */
1869
+ get peernetHash() {
1870
+ return new CodecHash$1(this.decoded, { name: this.name });
1871
+ }
1872
+ /**
1873
+ * @return {peernetHash}
1874
+ */
1875
+ async hash() {
1876
+ const upper = this.hashFormat.charAt(0).toUpperCase();
1877
+ const format = `${upper}${this.hashFormat.substring(1, this.hashFormat.length)}`;
1878
+ return (await this.peernetHash)[`to${format}`]();
1879
+ }
1880
+ fromUint8Array(buffer) {
1881
+ this.encoded = buffer;
1882
+ return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1883
+ }
1884
+ fromArrayBuffer(buffer) {
1885
+ this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
1886
+ return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
1887
+ }
1888
+ /**
1889
+ * @param {Object} data
1890
+ */
1891
+ create(data) {
1892
+ const decoded = {};
1893
+ if (this.keys?.length > 0) {
1894
+ for (const key of this.keys) {
1895
+ Object.defineProperties(decoded, {
1896
+ [key]: {
1897
+ enumerable: true,
1898
+ configurable: true,
1899
+ set: (value) => data[key],
1900
+ get: () => data[key]
1901
+ }
1902
+ });
1903
+ }
1904
+ this.decoded = decoded;
1905
+ return this.encode(decoded);
1906
+ }
1907
+ }
1906
1908
  };
1907
- const FormatInterface = FormatInterface$1;
1909
+ const FormatInterface = FormatInterface$1;
1908
1910
  const Codec = Codec$1;
1909
1911
 
1910
1912
  const BufferToUint8Array = data => {
@@ -16059,6 +16061,15 @@ class Identity {
16059
16061
  return JSON.parse(accounts);
16060
16062
  }
16061
16063
  async load(password) {
16064
+ if (password && password.includes('.txt')) {
16065
+ const { readFile } = await import('fs/promises');
16066
+ try {
16067
+ password = (await readFile(password)).toString();
16068
+ }
16069
+ catch (error) {
16070
+ console.error(error);
16071
+ }
16072
+ }
16062
16073
  if (!password) {
16063
16074
  const importee = await import('./src/prompts/password.js');
16064
16075
  password = await importee.default();
@@ -16071,7 +16082,7 @@ class Identity {
16071
16082
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
16072
16083
  }
16073
16084
  else {
16074
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-601960df.js');
16085
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-88c7fc2e.js');
16075
16086
  const { identity, accounts } = await importee.default(password, this.network);
16076
16087
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
16077
16088
  await globalThis.walletStore.put('version', String(1));
@@ -16237,7 +16248,7 @@ class Peernet {
16237
16248
  this.root = options.root;
16238
16249
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
16239
16250
  // FolderMessageResponse
16240
- } = await import(/* webpackChunkName: "messages" */ './messages-cf68bfb3.js');
16251
+ } = await import(/* webpackChunkName: "messages" */ './messages-ba0fcf7e.js');
16241
16252
  /**
16242
16253
  * proto Object containing protos
16243
16254
  * @type {Object}
@@ -16286,7 +16297,7 @@ class Peernet {
16286
16297
  * @see DataHandler
16287
16298
  */
16288
16299
  pubsub.subscribe('peer:data', dataHandler);
16289
- const importee = await import('./client-471408b6.js');
16300
+ const importee = await import('./client-cbaadd55.js');
16290
16301
  /**
16291
16302
  * @access public
16292
16303
  * @type {PeernetClient}
@@ -16730,4 +16741,4 @@ class Peernet {
16730
16741
  }
16731
16742
  globalThis.Peernet = Peernet;
16732
16743
 
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 };
16744
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P, base58$1 as b, encrypt as e };
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-e1e0a046.js';
1
+ export { P as default } from './peernet-6a78293a.js';
2
2
  import './value-157ab062.js';
@@ -319,6 +319,15 @@ class Identity {
319
319
  return JSON.parse(accounts);
320
320
  }
321
321
  async load(password) {
322
+ if (password && password.includes('.txt')) {
323
+ const { readFile } = await import('fs/promises');
324
+ try {
325
+ password = (await readFile(password)).toString();
326
+ }
327
+ catch (error) {
328
+ console.error(error);
329
+ }
330
+ }
322
331
  if (!password) {
323
332
  const importee = await import('./src/prompts/password.js');
324
333
  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.6",
4
4
  "description": "",
5
5
  "main": "src/peernet.js",
6
6
  "exports": {
package/src/identity.ts CHANGED
@@ -23,7 +23,16 @@ export default class Identity {
23
23
  return JSON.parse(accounts)
24
24
  }
25
25
 
26
- async load(password?: string): Promise<void> {
26
+ async load(password?: string): Promise<void> {
27
+ if (password && password.includes('.txt')) {
28
+
29
+ const { readFile } = await import('fs/promises')
30
+ try {
31
+ password = (await readFile(password)).toString()
32
+ } catch (error) {
33
+ console.error(error)
34
+ }
35
+ }
27
36
  if (!password) {
28
37
  const importee: { default: () => Promise<string> } = await import('./prompts/password.js')
29
38
  password = await importee.default()