@leofcoin/chain 1.5.22 → 1.5.24

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 { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, t as toBase58, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-de7cd283.js';
1
+ import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-de7cd283.js';
2
2
 
3
3
  const logger$1 = new Logger(version$1);
4
4
  const _constructorGuard = {};
@@ -1196,6 +1196,18 @@ class State extends Contract {
1196
1196
  return Promise.all(lastTransactions.map(transaction => transaction.hash()));
1197
1197
  };
1198
1198
  }
1199
+ async clearPool() {
1200
+ await globalThis.transactionPoolStore.clear();
1201
+ }
1202
+ /**
1203
+ * drastic measurement, removes everything!
1204
+ */
1205
+ async clearAll() {
1206
+ await globalThis.accountsStore.clear();
1207
+ await globalThis.chainStore.clear();
1208
+ await globalThis.blockStore.clear();
1209
+ await globalThis.transactionPoolStore.clear();
1210
+ }
1199
1211
  async init() {
1200
1212
  this.jobber = new Jobber(30000);
1201
1213
  if (super.init)
@@ -1591,10 +1603,43 @@ class State extends Contract {
1591
1603
  }
1592
1604
  }
1593
1605
 
1606
+ class VersionControl extends State {
1607
+ constructor() {
1608
+ super();
1609
+ }
1610
+ async init() {
1611
+ super.init && await super.init();
1612
+ console.log('init');
1613
+ try {
1614
+ const version = await globalThis.chainStore.get('version');
1615
+ this.version = new TextDecoder().decode(version);
1616
+ console.log(this.version);
1617
+ /**
1618
+ * protocol version control!
1619
+ * note v1 and 1.1 delete everything because of big changes, this is not what we want in the future
1620
+ * in the future we want newer nodes to handle the new changes and still confirm old version transactions
1621
+ * unless there is a security issue!
1622
+ */
1623
+ if (this.version !== '1.1.1') {
1624
+ this.version = '1.1.1';
1625
+ await this.clearAll();
1626
+ await globalThis.chainStore.put('version', this.version);
1627
+ }
1628
+ // if (version)
1629
+ }
1630
+ catch (e) {
1631
+ console.log(e);
1632
+ this.version = '1.1.1';
1633
+ await this.clearAll();
1634
+ await globalThis.chainStore.put('version', this.version);
1635
+ }
1636
+ }
1637
+ }
1638
+
1594
1639
  globalThis.BigNumber = BigNumber;
1595
1640
  const ignorelist = [];
1596
1641
  // check if browser or local
1597
- class Chain extends State {
1642
+ class Chain extends VersionControl {
1598
1643
  #state;
1599
1644
  #slotTime;
1600
1645
  /** {Address[]} */
@@ -1674,46 +1719,7 @@ class Chain extends State {
1674
1719
  console.log('handle native contracts');
1675
1720
  // handle native contracts
1676
1721
  }
1677
- async clearPool() {
1678
- await globalThis.transactionPoolStore.clear();
1679
- }
1680
- /**
1681
- * drastic measurement, removes everything!
1682
- */
1683
- async #clearAll() {
1684
- await globalThis.accountsStore.clear();
1685
- await globalThis.chainStore.clear();
1686
- await globalThis.blockStore.clear();
1687
- await globalThis.transactionPoolStore.clear();
1688
- }
1689
1722
  async #init() {
1690
- try {
1691
- const version = await globalThis.chainStore.get('version');
1692
- this.version = new TextDecoder().decode(version);
1693
- /**
1694
- * protocol version control!
1695
- * note v1 and 1.1 delete everything because of big changes, this is not what we want in the future
1696
- * in the future we want newer nodes to handle the new changes and still confirm old version transactions
1697
- * unless there is a security issue!
1698
- */
1699
- if (this.version !== '1.0.0') {
1700
- this.version = '1.0.0';
1701
- await this.#clearAll();
1702
- await globalThis.chainStore.put('version', this.version);
1703
- }
1704
- else if (this.version !== '1.1.1') {
1705
- this.version = '1.1.1';
1706
- await this.#clearAll();
1707
- await globalThis.chainStore.put('version', this.version);
1708
- }
1709
- // if (version)
1710
- }
1711
- catch (e) {
1712
- console.log(e);
1713
- this.version = '1.0.0';
1714
- await this.#clearAll();
1715
- await globalThis.chainStore.put('version', new TextEncoder().encode(this.version));
1716
- }
1717
1723
  // this.node = await new Node()
1718
1724
  this.#participants = [];
1719
1725
  this.#participating = false;
@@ -1722,6 +1728,8 @@ class Chain extends State {
1722
1728
  await this.#setup();
1723
1729
  this.utils = { BigNumber, formatUnits, parseUnits };
1724
1730
  // this.#state = new State()
1731
+ // todo some functions rely on state
1732
+ await super.init();
1725
1733
  await globalThis.peernet.addRequestHandler('bw-request-message', () => {
1726
1734
  return new BWMessage(globalThis.peernet.client.bw) || { up: 0, down: 0 };
1727
1735
  });
@@ -1737,8 +1745,6 @@ class Chain extends State {
1737
1745
  globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
1738
1746
  globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
1739
1747
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
1740
- // todo some functions rely on state
1741
- await super.init();
1742
1748
  globalThis.pubsub.publish('chain:ready', true);
1743
1749
  return this;
1744
1750
  }
@@ -0,0 +1,37 @@
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-c27ce598.js';
2
+ import './index-b3d08518.js';
3
+
4
+ /**
5
+ * @params {String} network
6
+ * @return {object} { identity, accounts, config }
7
+ */
8
+ var index = async (password, network) => {
9
+ if (!password)
10
+ throw new Error('wallets need to be password protected.');
11
+ let wallet = new MultiWallet(network);
12
+ /**
13
+ * @type {string}
14
+ */
15
+ let mnemonic = await wallet.generate(password);
16
+ wallet = new MultiWallet(network);
17
+ await wallet.recover(mnemonic, password, network);
18
+ mnemonic = new Uint8Array(await encrypt(password, mnemonic));
19
+ const multiWIF = new Uint8Array(await encrypt(password, await wallet.multiWIF));
20
+ /**
21
+ * @type {object}
22
+ */
23
+ const external = await wallet.account(1).external(1);
24
+ const externalAddress = await external.address;
25
+ const internal = await wallet.account(1).internal(1);
26
+ const internalAddress = await internal.address;
27
+ return {
28
+ identity: {
29
+ mnemonic: base58$1.encode(mnemonic),
30
+ multiWIF: base58$1.encode(multiWIF),
31
+ walletId: await external.id
32
+ },
33
+ accounts: [['main account', externalAddress, internalAddress]]
34
+ };
35
+ };
36
+
37
+ export { index as default };