@ledgerhq/live-common 27.3.2 → 27.4.0-next.1
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.
- package/lib/__tests__/environment.test.d.ts +2 -0
- package/lib/__tests__/environment.test.d.ts.map +1 -0
- package/lib/__tests__/environment.test.js +13 -0
- package/lib/__tests__/environment.test.js.map +1 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +0 -31
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +3 -2
- package/lib/account/support.js.map +1 -1
- package/lib/apps/hw.d.ts +4 -1
- package/lib/apps/hw.d.ts.map +1 -1
- package/lib/apps/hw.js +10 -4
- package/lib/apps/hw.js.map +1 -1
- package/lib/apps/mock.d.ts +1 -0
- package/lib/apps/mock.d.ts.map +1 -1
- package/lib/apps/mock.js +24 -2
- package/lib/apps/mock.js.map +1 -1
- package/lib/apps/runner.d.ts +8 -1
- package/lib/apps/runner.d.ts.map +1 -1
- package/lib/apps/runner.js +15 -3
- package/lib/apps/runner.js.map +1 -1
- package/lib/apps/support.js +1 -1
- package/lib/bot/engine.d.ts.map +1 -1
- package/lib/bot/engine.js +5 -2
- package/lib/bot/engine.js.map +1 -1
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +5 -3
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/types.d.ts +2 -0
- package/lib/bot/types.d.ts.map +1 -1
- package/lib/data/icons/react/index.d.ts +1 -0
- package/lib/data/icons/react/index.d.ts.map +1 -1
- package/lib/data/icons/react/index.js +3 -1
- package/lib/data/icons/react/index.js.map +1 -1
- package/lib/data/icons/react/yae.d.ts +8 -0
- package/lib/data/icons/react/yae.d.ts.map +1 -0
- package/lib/data/icons/react/yae.js +36 -0
- package/lib/data/icons/react/yae.js.map +1 -0
- package/lib/data/icons/reactNative/index.d.ts +1 -0
- package/lib/data/icons/reactNative/index.d.ts.map +1 -1
- package/lib/data/icons/reactNative/index.js +3 -1
- package/lib/data/icons/reactNative/index.js.map +1 -1
- package/lib/data/icons/reactNative/yae.d.ts +8 -0
- package/lib/data/icons/reactNative/yae.d.ts.map +1 -0
- package/lib/data/icons/reactNative/yae.js +37 -0
- package/lib/data/icons/reactNative/yae.js.map +1 -0
- package/lib/exchange/hw-app-exchange/Exchange.js +4 -4
- package/lib/families/bitcoin/account.d.ts.map +1 -1
- package/lib/families/bitcoin/bech32m.d.ts +2 -8
- package/lib/families/bitcoin/bech32m.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/js.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/js.js.map +1 -1
- package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/mock.js.map +1 -1
- package/lib/families/bitcoin/cache.d.ts +2 -15
- package/lib/families/bitcoin/cache.d.ts.map +1 -1
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +2 -15
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/logic.d.ts +1 -1
- package/lib/families/bitcoin/logic.d.ts.map +1 -1
- package/lib/families/bitcoin/logic.js.map +1 -1
- package/lib/families/bitcoin/presync.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +0 -2
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js +0 -16
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts +4 -3
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js +3 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts +2 -3
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +0 -7
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/factory.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js +0 -3
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts +2 -3
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +0 -16
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +0 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +0 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +0 -5
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +0 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +0 -5
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts +11 -5
- package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.js +8 -40
- package/lib/families/bitcoin/wallet-btc/explorer/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +1 -5
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.js +7 -9
- package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts +3 -3
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +2 -11
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +10 -7
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +1 -18
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.d.ts +1 -9
- package/lib/families/bitcoin/wallet-btc/xpub.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.js +60 -208
- package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
- package/lib/families/cardano/js-synchronisation.js +1 -1
- package/lib/families/cardano/js-synchronisation.js.map +1 -1
- package/lib/families/cardano/specs.js +1 -1
- package/lib/families/celo/specs/createSendMutation.d.ts.map +1 -1
- package/lib/families/celo/specs/createSendMutation.js +0 -2
- package/lib/families/celo/specs/createSendMutation.js.map +1 -1
- package/lib/families/celo/specs.js +1 -1
- package/lib/families/crypto_org/specs.d.ts.map +1 -1
- package/lib/families/crypto_org/specs.js +3 -2
- package/lib/families/crypto_org/specs.js.map +1 -1
- package/lib/families/ethereum/specs.js +3 -3
- package/lib/families/ethereum/specs.js.map +1 -1
- package/lib/families/evm/specs.js +6 -6
- package/lib/families/evm/specs.js.map +1 -1
- package/lib/families/filecoin/specs.d.ts.map +1 -1
- package/lib/families/filecoin/specs.js +1 -2
- package/lib/families/filecoin/specs.js.map +1 -1
- package/lib/families/hedera/api/network.d.ts.map +1 -1
- package/lib/families/hedera/api/network.js +16 -8
- package/lib/families/hedera/api/network.js.map +1 -1
- package/lib/families/hedera/errors.d.ts +4 -0
- package/lib/families/hedera/errors.d.ts.map +1 -0
- package/lib/families/hedera/errors.js +6 -0
- package/lib/families/hedera/errors.js.map +1 -0
- package/lib/families/hedera/specs.d.ts.map +1 -1
- package/lib/families/hedera/specs.js +0 -11
- package/lib/families/hedera/specs.js.map +1 -1
- package/lib/families/osmosis/specs.js +1 -1
- package/lib/families/polkadot/specs.d.ts.map +1 -1
- package/lib/families/polkadot/specs.js +1 -0
- package/lib/families/polkadot/specs.js.map +1 -1
- package/lib/families/solana/specs.d.ts.map +1 -1
- package/lib/families/solana/specs.js +1 -0
- package/lib/families/solana/specs.js.map +1 -1
- package/lib/families/tezos/bakers.whitelist-default.d.ts.map +1 -1
- package/lib/families/tezos/bakers.whitelist-default.js +1 -1
- package/lib/families/tezos/bakers.whitelist-default.js.map +1 -1
- package/lib/families/tezos/bridge/js.d.ts.map +1 -1
- package/lib/families/tezos/bridge/js.js +2 -1
- package/lib/families/tezos/bridge/js.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +6 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/hw/actions/app.d.ts +7 -0
- package/lib/hw/actions/app.d.ts.map +1 -1
- package/lib/hw/actions/app.js +25 -11
- package/lib/hw/actions/app.js.map +1 -1
- package/lib/hw/connectApp.d.ts +4 -0
- package/lib/hw/connectApp.d.ts.map +1 -1
- package/lib/hw/connectApp.js +10 -1
- package/lib/hw/connectApp.js.map +1 -1
- package/lib/manager/localization.d.ts +1 -1
- package/lib/manager/localization.d.ts.map +1 -1
- package/lib/manager/localization.js +1 -1
- package/lib/manager/localization.js.map +1 -1
- package/lib/rxjs/operators/retryWithDelay.d.ts +12 -0
- package/lib/rxjs/operators/retryWithDelay.d.ts.map +1 -0
- package/lib/rxjs/operators/retryWithDelay.js +28 -0
- package/lib/rxjs/operators/retryWithDelay.js.map +1 -0
- package/lib/rxjs/operators/throwIf.d.ts +23 -0
- package/lib/rxjs/operators/throwIf.d.ts.map +1 -0
- package/lib/rxjs/operators/throwIf.js +37 -0
- package/lib/rxjs/operators/throwIf.js.map +1 -0
- package/package.json +5 -5
- package/src/__tests__/environment.test.ts +12 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +0 -33
- package/src/account/support.ts +3 -2
- package/src/apps/hw.ts +17 -4
- package/src/apps/mock.ts +24 -2
- package/src/apps/runner.ts +28 -4
- package/src/apps/support.ts +1 -1
- package/src/bot/engine.ts +9 -1
- package/src/bot/index.ts +7 -2
- package/src/bot/types.ts +3 -0
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +33 -0
- package/src/data/icons/react/index.tsx +1 -0
- package/src/data/icons/react/yae.tsx +14 -0
- package/src/data/icons/reactNative/index.tsx +1 -0
- package/src/data/icons/reactNative/yae.tsx +15 -0
- package/src/data/icons/svg/YAE.svg +4 -0
- package/src/exchange/hw-app-exchange/Exchange.ts +4 -4
- package/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap +807 -27
- package/src/families/bitcoin/account.ts +1 -1
- package/src/families/bitcoin/bech32m.ts +2 -2
- package/src/families/bitcoin/bridge/js.ts +6 -3
- package/src/families/bitcoin/bridge/mock.ts +6 -2
- package/src/families/bitcoin/js-getFeesForTransaction.ts +1 -1
- package/src/families/bitcoin/js-synchronisation.ts +0 -1
- package/src/families/bitcoin/logic.ts +5 -2
- package/src/families/bitcoin/presync.ts +1 -1
- package/src/families/bitcoin/specs.ts +1 -1
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +0 -20
- package/src/families/bitcoin/wallet-btc/crypto/bip32.ts +6 -5
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +1 -9
- package/src/families/bitcoin/wallet-btc/crypto/factory.ts +1 -4
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +1 -20
- package/src/families/bitcoin/wallet-btc/crypto/types.ts +0 -3
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +1 -7
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +1 -7
- package/src/families/bitcoin/wallet-btc/explorer/index.ts +24 -49
- package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +6 -1
- package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +6 -1
- package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +6 -1
- package/src/families/bitcoin/wallet-btc/storage/index.ts +34 -20
- package/src/families/bitcoin/wallet-btc/utils.ts +16 -21
- package/src/families/bitcoin/wallet-btc/wallet.ts +17 -31
- package/src/families/bitcoin/wallet-btc/xpub.ts +41 -150
- package/src/families/cardano/js-synchronisation.ts +1 -1
- package/src/families/cardano/specs.ts +1 -1
- package/src/families/celo/specs/createSendMutation.ts +1 -3
- package/src/families/celo/specs.ts +1 -1
- package/src/families/crypto_org/specs.ts +3 -2
- package/src/families/ethereum/specs.ts +3 -3
- package/src/families/evm/specs.ts +6 -6
- package/src/families/filecoin/__snapshots__/bridge.integration.test.ts.snap +24 -2
- package/src/families/filecoin/specs.ts +1 -2
- package/src/families/hedera/api/network.ts +10 -3
- package/src/families/hedera/errors.ts +5 -0
- package/src/families/hedera/specs.ts +0 -17
- package/src/families/osmosis/__snapshots__/bridge.integration.test.ts.snap +101 -3
- package/src/families/osmosis/specs.ts +1 -1
- package/src/families/polkadot/specs.ts +1 -0
- package/src/families/solana/specs.ts +1 -0
- package/src/families/tezos/bakers.whitelist-default.ts +0 -2
- package/src/families/tezos/bridge/js.ts +4 -1
- package/src/featureFlags/defaultFeatures.ts +6 -0
- package/src/hw/actions/app.ts +35 -4
- package/src/hw/connectApp.ts +18 -1
- package/src/manager/localization.ts +2 -2
- package/src/rxjs/operators/retryWithDelay.ts +36 -0
- package/src/rxjs/operators/throwIf.ts +40 -0
- package/lib/families/bitcoin/wallet-btc/utils/eventemitter.d.ts +0 -6
- package/lib/families/bitcoin/wallet-btc/utils/eventemitter.d.ts.map +0 -1
- package/lib/families/bitcoin/wallet-btc/utils/eventemitter.js +0 -64
- package/lib/families/bitcoin/wallet-btc/utils/eventemitter.js.map +0 -1
- package/src/families/bitcoin/wallet-btc/utils/eventemitter.ts +0 -9
|
@@ -23,15 +23,17 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
23
23
|
// returning unordered tx within the same block)
|
|
24
24
|
spentUtxos: { [key: string]: Input[] } = {};
|
|
25
25
|
|
|
26
|
-
getLastTx(txFilter: {
|
|
26
|
+
getLastTx(txFilter: {
|
|
27
|
+
account: number;
|
|
28
|
+
index: number;
|
|
29
|
+
confirmed?: boolean;
|
|
30
|
+
}): TX | undefined {
|
|
27
31
|
if (
|
|
28
32
|
typeof this.accountIndex[`${txFilter.account}-${txFilter.index}`] ===
|
|
29
33
|
"undefined"
|
|
30
34
|
) {
|
|
31
35
|
return undefined;
|
|
32
36
|
}
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
-
// @ts-ignore
|
|
35
37
|
const tx: TX | undefined = findLast(
|
|
36
38
|
this.accountIndex[`${txFilter.account}-${txFilter.index}`].map(
|
|
37
39
|
(i) => this.txs[i]
|
|
@@ -39,7 +41,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
39
41
|
(t) => {
|
|
40
42
|
return (
|
|
41
43
|
typeof txFilter.confirmed === "undefined" ||
|
|
42
|
-
(txFilter.confirmed && t.block) ||
|
|
44
|
+
(txFilter.confirmed && !!t.block) ||
|
|
43
45
|
(!txFilter.confirmed && !t.block)
|
|
44
46
|
);
|
|
45
47
|
}
|
|
@@ -47,27 +49,25 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
47
49
|
return tx;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
getLastUnconfirmedTx() {
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
|
-
// @ts-ignore
|
|
52
|
+
getLastUnconfirmedTx(): TX | undefined {
|
|
53
53
|
const tx: TX | undefined = findLast(this.txs, (t) => {
|
|
54
54
|
return !t.block;
|
|
55
55
|
});
|
|
56
56
|
return tx;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
getTx(address: string, txId: string) {
|
|
59
|
+
getTx(address: string, txId: string): TX {
|
|
60
60
|
const index = `${address}-${txId}`;
|
|
61
61
|
return this.txs[this.primaryIndex[index]];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// TODO: only expose unspentUtxos
|
|
65
|
-
getAddressUnspentUtxos(address: Address) {
|
|
65
|
+
getAddressUnspentUtxos(address: Address): Output[] {
|
|
66
66
|
const indexAddress = address.address;
|
|
67
67
|
return this.unspentUtxos[indexAddress];
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
appendTxs(txs: TX[]) {
|
|
70
|
+
appendTxs(txs: TX[]): number {
|
|
71
71
|
const lastLength = this.txs.length;
|
|
72
72
|
|
|
73
73
|
txs.forEach((tx) => {
|
|
@@ -118,12 +118,20 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
118
118
|
return this.txs.length - lastLength;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
getUniquesAddresses(addressesFilter: {
|
|
121
|
+
getUniquesAddresses(addressesFilter: {
|
|
122
|
+
account?: number;
|
|
123
|
+
index?: number;
|
|
124
|
+
}): Address[] {
|
|
122
125
|
// TODO: to speed up, create more useful indexes in appendTxs
|
|
123
126
|
return uniqBy(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
filter(
|
|
128
|
+
this.txs,
|
|
129
|
+
(t) =>
|
|
130
|
+
(typeof addressesFilter.account === "undefined" ||
|
|
131
|
+
addressesFilter.account === t.account) &&
|
|
132
|
+
(typeof addressesFilter.index === "undefined" ||
|
|
133
|
+
addressesFilter.index === t.index)
|
|
134
|
+
).map((tx: TX) => ({
|
|
127
135
|
address: tx.address,
|
|
128
136
|
account: tx.account,
|
|
129
137
|
index: tx.index,
|
|
@@ -132,7 +140,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
132
140
|
);
|
|
133
141
|
}
|
|
134
142
|
|
|
135
|
-
removeTxs(txsFilter: { account: number; index: number }) {
|
|
143
|
+
removeTxs(txsFilter: { account: number; index: number }): void {
|
|
136
144
|
const newTxs: TX[] = [];
|
|
137
145
|
this.primaryIndex = {};
|
|
138
146
|
this.accountIndex = {};
|
|
@@ -155,7 +163,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
155
163
|
|
|
156
164
|
// We are a bit ugly because we can't rely undo unspentUTXO
|
|
157
165
|
// So we clean the address and rebuild without the pendings
|
|
158
|
-
removePendingTxs(txsFilter: { account: number; index: number }) {
|
|
166
|
+
removePendingTxs(txsFilter: { account: number; index: number }): void {
|
|
159
167
|
const newTxs: TX[] = [];
|
|
160
168
|
const txsToReAdd: TX[] = [];
|
|
161
169
|
this.primaryIndex = {};
|
|
@@ -190,14 +198,14 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
190
198
|
this.addressCache[key] = address;
|
|
191
199
|
}
|
|
192
200
|
|
|
193
|
-
exportSync() {
|
|
201
|
+
exportSync(): { txs: TX[]; addressCache: { [key: string]: string } } {
|
|
194
202
|
return {
|
|
195
203
|
txs: this.txs,
|
|
196
204
|
addressCache: this.addressCache,
|
|
197
205
|
};
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
loadSync(data: { txs: TX[]; addressCache: { [key: string]: string } }) {
|
|
208
|
+
loadSync(data: { txs: TX[]; addressCache: { [key: string]: string } }): void {
|
|
201
209
|
this.txs = [];
|
|
202
210
|
this.primaryIndex = {};
|
|
203
211
|
this.accountIndex = {};
|
|
@@ -214,11 +222,17 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
214
222
|
Base.addressCache = { ...Base.addressCache, ...this.addressCache };
|
|
215
223
|
}
|
|
216
224
|
|
|
217
|
-
async export() {
|
|
225
|
+
async export(): Promise<{
|
|
226
|
+
txs: TX[];
|
|
227
|
+
addressCache: { [key: string]: string };
|
|
228
|
+
}> {
|
|
218
229
|
return this.exportSync();
|
|
219
230
|
}
|
|
220
231
|
|
|
221
|
-
async load(data: {
|
|
232
|
+
async load(data: {
|
|
233
|
+
txs: TX[];
|
|
234
|
+
addressCache: { [key: string]: string };
|
|
235
|
+
}): Promise<void> {
|
|
222
236
|
return this.loadSync(data);
|
|
223
237
|
}
|
|
224
238
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
2
|
import * as bitcoin from "bitcoinjs-lib";
|
|
3
3
|
import bs58 from "bs58";
|
|
4
4
|
import { padStart } from "lodash";
|
|
@@ -9,18 +9,16 @@ import { fallbackValidateAddress } from "./crypto/base";
|
|
|
9
9
|
import { UnsupportedDerivation } from "../../../errors";
|
|
10
10
|
import varuint from "varuint-bitcoin";
|
|
11
11
|
|
|
12
|
-
export function parseHexString(str: any) {
|
|
12
|
+
export function parseHexString(str: any): number[] {
|
|
13
13
|
const result: Array<number> = [];
|
|
14
14
|
while (str.length >= 2) {
|
|
15
15
|
result.push(parseInt(str.substring(0, 2), 16));
|
|
16
|
-
// eslint-disable-next-line no-param-reassign
|
|
17
16
|
str = str.substring(2, str.length);
|
|
18
17
|
}
|
|
19
18
|
return result;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
export function encodeBase58Check(vchIn: any) {
|
|
23
|
-
// eslint-disable-next-line no-param-reassign
|
|
21
|
+
export function encodeBase58Check(vchIn: any): string {
|
|
24
22
|
vchIn = parseHexString(vchIn);
|
|
25
23
|
let chksum = bitcoin.crypto.sha256(Buffer.from(vchIn));
|
|
26
24
|
chksum = bitcoin.crypto.sha256(chksum);
|
|
@@ -29,29 +27,23 @@ export function encodeBase58Check(vchIn: any) {
|
|
|
29
27
|
return bs58.encode(hash);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
export function toHexDigit(number: any) {
|
|
30
|
+
export function toHexDigit(number: any): string {
|
|
33
31
|
const digits = "0123456789abcdef";
|
|
34
|
-
// eslint-disable-next-line no-bitwise
|
|
35
32
|
return digits.charAt(number >> 4) + digits.charAt(number & 0x0f);
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
export function toHexInt(number: any) {
|
|
35
|
+
export function toHexInt(number: any): string {
|
|
39
36
|
return (
|
|
40
|
-
// eslint-disable-next-line no-bitwise
|
|
41
37
|
toHexDigit((number >> 24) & 0xff) +
|
|
42
|
-
// eslint-disable-next-line no-bitwise
|
|
43
38
|
toHexDigit((number >> 16) & 0xff) +
|
|
44
|
-
// eslint-disable-next-line no-bitwise
|
|
45
39
|
toHexDigit((number >> 8) & 0xff) +
|
|
46
|
-
// eslint-disable-next-line no-bitwise
|
|
47
40
|
toHexDigit(number & 0xff)
|
|
48
41
|
);
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
export function compressPublicKey(publicKey: any) {
|
|
52
|
-
let compressedKeyIndex;
|
|
44
|
+
export function compressPublicKey(publicKey: any): string {
|
|
45
|
+
let compressedKeyIndex: string;
|
|
53
46
|
if (publicKey.substring(0, 2) !== "04") {
|
|
54
|
-
// eslint-disable-next-line no-throw-literal
|
|
55
47
|
throw new Error("Invalid public key format");
|
|
56
48
|
}
|
|
57
49
|
if (parseInt(publicKey.substring(128, 130), 16) % 2 !== 0) {
|
|
@@ -70,7 +62,7 @@ export function createXPUB(
|
|
|
70
62
|
chaincode: any,
|
|
71
63
|
publicKey: any,
|
|
72
64
|
network: any
|
|
73
|
-
) {
|
|
65
|
+
): string {
|
|
74
66
|
let xpub = toHexInt(network);
|
|
75
67
|
xpub += padStart(depth.toString(16), 2, "0");
|
|
76
68
|
xpub += padStart(fingerprint.toString(16), 8, "0");
|
|
@@ -80,7 +72,7 @@ export function createXPUB(
|
|
|
80
72
|
return xpub;
|
|
81
73
|
}
|
|
82
74
|
|
|
83
|
-
export function byteSize(count: number) {
|
|
75
|
+
export function byteSize(count: number): number {
|
|
84
76
|
if (count < 0xfd) {
|
|
85
77
|
return 1;
|
|
86
78
|
}
|
|
@@ -227,7 +219,7 @@ export function maxTxSizeCeil(
|
|
|
227
219
|
}
|
|
228
220
|
|
|
229
221
|
// refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/api_impl/BitcoinLikeTransactionApi.cpp#L253
|
|
230
|
-
export function computeDustAmount(currency: ICrypto, txSize: number) {
|
|
222
|
+
export function computeDustAmount(currency: ICrypto, txSize: number): number {
|
|
231
223
|
let dustAmount = currency.network.dustThreshold;
|
|
232
224
|
switch (currency.network.dustPolicy) {
|
|
233
225
|
case "PER_KBYTE":
|
|
@@ -242,7 +234,7 @@ export function computeDustAmount(currency: ICrypto, txSize: number) {
|
|
|
242
234
|
return dustAmount;
|
|
243
235
|
}
|
|
244
236
|
|
|
245
|
-
export function isValidAddress(address: string, currency?: Currency) {
|
|
237
|
+
export function isValidAddress(address: string, currency?: Currency): boolean {
|
|
246
238
|
if (!currency) {
|
|
247
239
|
// If the caller doesn't provide the currency, we'll
|
|
248
240
|
// fallback to a pre-taproot basic validation that doesn't
|
|
@@ -253,7 +245,10 @@ export function isValidAddress(address: string, currency?: Currency) {
|
|
|
253
245
|
return crypto.validateAddress(address);
|
|
254
246
|
}
|
|
255
247
|
|
|
256
|
-
export function isTaprootAddress(
|
|
248
|
+
export function isTaprootAddress(
|
|
249
|
+
address: string,
|
|
250
|
+
currency?: Currency
|
|
251
|
+
): boolean {
|
|
257
252
|
if (currency === "bitcoin") {
|
|
258
253
|
return cryptoFactory("bitcoin").isTaprootAddress(address);
|
|
259
254
|
} else if (currency === "bitcoin_testnet") {
|
|
@@ -263,7 +258,7 @@ export function isTaprootAddress(address: string, currency?: Currency) {
|
|
|
263
258
|
}
|
|
264
259
|
}
|
|
265
260
|
|
|
266
|
-
export function writeVarInt(buffer: Buffer, i: number, offset: number) {
|
|
261
|
+
export function writeVarInt(buffer: Buffer, i: number, offset: number): number {
|
|
267
262
|
// refer to https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f44f722d30cd14a1861c8546e6b455f73862c1e/src/bufferutils.js#L78
|
|
268
263
|
varuint.encode(i, buffer, offset);
|
|
269
264
|
offset += varuint.encode.bytes;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore
|
|
3
1
|
import { flatten } from "lodash";
|
|
4
2
|
import BigNumber from "bignumber.js";
|
|
5
3
|
import Btc from "@ledgerhq/hw-app-btc";
|
|
@@ -11,16 +9,16 @@ import { Account, SerializedAccount } from "./account";
|
|
|
11
9
|
import Xpub from "./xpub";
|
|
12
10
|
import { IExplorer } from "./explorer/types";
|
|
13
11
|
import BitcoinLikeExplorer from "./explorer";
|
|
14
|
-
import { IStorage } from "./storage/types";
|
|
12
|
+
import { IStorage, Output } from "./storage/types";
|
|
15
13
|
import BitcoinLikeStorage from "./storage";
|
|
16
14
|
import { PickingStrategy } from "./pickingstrategies/types";
|
|
17
15
|
import * as utils from "./utils";
|
|
18
16
|
import cryptoFactory from "./crypto/factory";
|
|
17
|
+
import { TX, Address } from "./storage/types";
|
|
19
18
|
|
|
20
19
|
class BitcoinLikeWallet {
|
|
21
20
|
explorerInstances: { [key: string]: IExplorer } = {};
|
|
22
21
|
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
22
|
explorers: { [key: string]: (explorerURI: string) => IExplorer } = {
|
|
25
23
|
ledgerv3: (explorerURI) =>
|
|
26
24
|
new BitcoinLikeExplorer({
|
|
@@ -34,12 +32,14 @@ class BitcoinLikeWallet {
|
|
|
34
32
|
}),
|
|
35
33
|
};
|
|
36
34
|
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
35
|
accountStorages: { [key: string]: (...args: any[]) => IStorage } = {
|
|
39
36
|
mock: () => new BitcoinLikeStorage(),
|
|
40
37
|
};
|
|
41
38
|
|
|
42
|
-
getExplorer(
|
|
39
|
+
getExplorer(
|
|
40
|
+
explorer: "ledgerv3" | "ledgerv2",
|
|
41
|
+
explorerURI: string
|
|
42
|
+
): IExplorer {
|
|
43
43
|
const id = `explorer-${explorer}-uri-${explorerURI}`;
|
|
44
44
|
this.explorerInstances[id] =
|
|
45
45
|
this.explorerInstances[id] || this.explorers[explorer](explorerURI);
|
|
@@ -56,7 +56,6 @@ class BitcoinLikeWallet {
|
|
|
56
56
|
explorer: "ledgerv3" | "ledgerv2";
|
|
57
57
|
explorerURI: string;
|
|
58
58
|
storage: "mock";
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
59
|
storageParams: any[];
|
|
61
60
|
}): Promise<Account> {
|
|
62
61
|
const crypto = cryptoFactory(params.currency);
|
|
@@ -77,31 +76,26 @@ class BitcoinLikeWallet {
|
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
async syncAccount(account: Account) {
|
|
79
|
+
async syncAccount(account: Account): Promise<number> {
|
|
82
80
|
return account.xpub.sync();
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
async getAccountNewReceiveAddress(account: Account) {
|
|
83
|
+
async getAccountNewReceiveAddress(account: Account): Promise<Address> {
|
|
87
84
|
const address = await account.xpub.getNewAddress(0, 1);
|
|
88
85
|
return address;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
|
|
92
|
-
async getAccountNewChangeAddress(account: Account) {
|
|
88
|
+
async getAccountNewChangeAddress(account: Account): Promise<Address> {
|
|
93
89
|
const address = await account.xpub.getNewAddress(1, 1);
|
|
94
90
|
return address;
|
|
95
91
|
}
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const txs = await account.xpub.storage.export();
|
|
93
|
+
async getAccountTransactions(account: Account): Promise<{ txs: TX[] }> {
|
|
94
|
+
const txs = (await account.xpub.storage.export()) as { txs: TX[] };
|
|
100
95
|
return txs;
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
async getAccountUnspentUtxos(account: Account) {
|
|
98
|
+
async getAccountUnspentUtxos(account: Account): Promise<Output[]> {
|
|
105
99
|
const addresses = await account.xpub.getXpubAddresses();
|
|
106
100
|
return flatten(
|
|
107
101
|
await Promise.all(
|
|
@@ -112,13 +106,12 @@ class BitcoinLikeWallet {
|
|
|
112
106
|
);
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
// eslint-disable-next-line class-methods-use-this
|
|
116
109
|
async estimateAccountMaxSpendable(
|
|
117
110
|
account: Account,
|
|
118
111
|
feePerByte: number,
|
|
119
112
|
excludeUTXOs: Array<{ hash: string; outputIndex: number }>,
|
|
120
113
|
outputAddresses: string[] = []
|
|
121
|
-
) {
|
|
114
|
+
): Promise<BigNumber> {
|
|
122
115
|
const addresses = await account.xpub.getXpubAddresses();
|
|
123
116
|
const changeAddresses = (await account.xpub.getAccountAddresses(1)).map(
|
|
124
117
|
(item) => item.address
|
|
@@ -168,14 +161,12 @@ class BitcoinLikeWallet {
|
|
|
168
161
|
return maxSpendable.lt(0) ? new BigNumber(0) : maxSpendable;
|
|
169
162
|
}
|
|
170
163
|
|
|
171
|
-
|
|
172
|
-
async getAccountBalance(account: Account) {
|
|
164
|
+
async getAccountBalance(account: Account): Promise<BigNumber> {
|
|
173
165
|
const balance = await account.xpub.getXpubBalance();
|
|
174
166
|
return balance;
|
|
175
167
|
}
|
|
176
168
|
|
|
177
|
-
|
|
178
|
-
async getAccountPendings(account: Account) {
|
|
169
|
+
async getAccountPendings(account: Account): Promise<TX[]> {
|
|
179
170
|
const addresses = await account.xpub.getXpubAddresses();
|
|
180
171
|
return flatten(
|
|
181
172
|
await Promise.all(
|
|
@@ -184,7 +175,6 @@ class BitcoinLikeWallet {
|
|
|
184
175
|
);
|
|
185
176
|
}
|
|
186
177
|
|
|
187
|
-
// eslint-disable-next-line class-methods-use-this
|
|
188
178
|
async buildAccountTx(params: {
|
|
189
179
|
fromAccount: Account;
|
|
190
180
|
dest: string;
|
|
@@ -205,7 +195,6 @@ class BitcoinLikeWallet {
|
|
|
205
195
|
return txInfo;
|
|
206
196
|
}
|
|
207
197
|
|
|
208
|
-
// eslint-disable-next-line class-methods-use-this
|
|
209
198
|
async signAccountTx(params: {
|
|
210
199
|
btc: Btc;
|
|
211
200
|
fromAccount: Account;
|
|
@@ -225,7 +214,7 @@ class BitcoinLikeWallet {
|
|
|
225
214
|
total: number;
|
|
226
215
|
index: number;
|
|
227
216
|
}) => void;
|
|
228
|
-
}) {
|
|
217
|
+
}): Promise<string> {
|
|
229
218
|
const {
|
|
230
219
|
btc,
|
|
231
220
|
fromAccount,
|
|
@@ -351,8 +340,7 @@ class BitcoinLikeWallet {
|
|
|
351
340
|
return tx;
|
|
352
341
|
}
|
|
353
342
|
|
|
354
|
-
|
|
355
|
-
async broadcastTx(fromAccount: Account, tx: string) {
|
|
343
|
+
async broadcastTx(fromAccount: Account, tx: string): Promise<string> {
|
|
356
344
|
const res = await fromAccount.xpub.broadcastTx(tx);
|
|
357
345
|
return res.data.result;
|
|
358
346
|
}
|
|
@@ -400,7 +388,6 @@ class BitcoinLikeWallet {
|
|
|
400
388
|
};
|
|
401
389
|
}
|
|
402
390
|
|
|
403
|
-
// eslint-disable-next-line class-methods-use-this
|
|
404
391
|
async exportToSerializedAccount(
|
|
405
392
|
account: Account
|
|
406
393
|
): Promise<SerializedAccount> {
|
|
@@ -415,7 +402,6 @@ class BitcoinLikeWallet {
|
|
|
415
402
|
};
|
|
416
403
|
}
|
|
417
404
|
|
|
418
|
-
// eslint-disable-next-line class-methods-use-this
|
|
419
405
|
exportToSerializedAccountSync(account: Account): SerializedAccount {
|
|
420
406
|
const data = account.xpub.storage.exportSync();
|
|
421
407
|
|