@ledgerhq/live-common 21.21.4 → 21.24.0-beta.0
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/account/formatters.d.ts.map +1 -1
- package/lib/account/formatters.js +1 -0
- package/lib/account/formatters.js.map +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +1 -0
- package/lib/account/support.js.map +1 -1
- package/lib/apps/polyfill.d.ts.map +1 -1
- package/lib/apps/polyfill.js +1 -0
- package/lib/apps/polyfill.js.map +1 -1
- package/lib/bot/engine.js +1 -1
- package/lib/bot/engine.js.map +1 -1
- package/lib/bot/specs.d.ts +1 -0
- package/lib/bot/specs.d.ts.map +1 -1
- package/lib/bot/specs.js +3 -1
- package/lib/bot/specs.js.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 +4 -2
- package/lib/data/icons/react/index.js.map +1 -1
- package/lib/data/icons/react/sol.js +4 -2
- package/lib/data/icons/react/sol.js.map +1 -1
- package/lib/data/icons/react/ssv.d.ts +8 -0
- package/lib/data/icons/react/ssv.d.ts.map +1 -0
- package/lib/data/icons/react/ssv.js +31 -0
- package/lib/data/icons/react/ssv.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 +4 -2
- package/lib/data/icons/reactNative/index.js.map +1 -1
- package/lib/data/icons/reactNative/sol.js +4 -2
- package/lib/data/icons/reactNative/sol.js.map +1 -1
- package/lib/data/icons/reactNative/ssv.d.ts +8 -0
- package/lib/data/icons/reactNative/ssv.d.ts.map +1 -0
- package/lib/data/icons/reactNative/ssv.js +32 -0
- package/lib/data/icons/reactNative/ssv.js.map +1 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +0 -3
- package/lib/derivation.js.map +1 -1
- package/lib/env.d.ts +10 -10
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +6 -6
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/families/algorand/account.d.ts.map +1 -1
- package/lib/families/algorand/account.js +0 -4
- package/lib/families/algorand/account.js.map +1 -1
- package/lib/families/algorand/api/algodv2.d.ts +5 -0
- package/lib/families/algorand/api/algodv2.d.ts.map +1 -0
- package/lib/families/algorand/api/algodv2.js +118 -0
- package/lib/families/algorand/api/algodv2.js.map +1 -0
- package/lib/families/algorand/api/algodv2.types.d.ts +24 -0
- package/lib/families/algorand/api/algodv2.types.d.ts.map +1 -0
- package/lib/families/algorand/api/algodv2.types.js +3 -0
- package/lib/families/algorand/api/algodv2.types.js.map +1 -0
- package/lib/families/algorand/api/index.d.ts +5 -0
- package/lib/families/algorand/api/index.d.ts.map +1 -0
- package/lib/families/algorand/api/index.js +17 -0
- package/lib/families/algorand/api/index.js.map +1 -0
- package/lib/families/algorand/api/indexer.d.ts +3 -0
- package/lib/families/algorand/api/indexer.d.ts.map +1 -0
- package/lib/families/algorand/api/indexer.js +134 -0
- package/lib/families/algorand/api/indexer.js.map +1 -0
- package/lib/families/algorand/api/indexer.types.d.ts +35 -0
- package/lib/families/algorand/api/indexer.types.d.ts.map +1 -0
- package/lib/families/algorand/api/indexer.types.js +10 -0
- package/lib/families/algorand/api/indexer.types.js.map +1 -0
- package/lib/families/algorand/bridge/js.d.ts +8 -0
- package/lib/families/algorand/bridge/js.d.ts.map +1 -0
- package/lib/families/algorand/bridge/js.js +85 -0
- package/lib/families/algorand/bridge/js.js.map +1 -0
- package/lib/families/algorand/bridge/libcore.d.ts +3 -3
- package/lib/families/algorand/bridge/libcore.d.ts.map +1 -1
- package/lib/families/algorand/bridge/libcore.js.map +1 -1
- package/lib/families/algorand/bridge/mock.d.ts +2 -2
- package/lib/families/algorand/bridge/mock.d.ts.map +1 -1
- package/lib/families/algorand/bridge/mock.js.map +1 -1
- package/lib/families/algorand/buildTransaction.d.ts +8 -0
- package/lib/families/algorand/buildTransaction.d.ts.map +1 -0
- package/lib/families/algorand/buildTransaction.js +101 -0
- package/lib/families/algorand/buildTransaction.js.map +1 -0
- package/lib/families/algorand/cli-transaction.js +1 -1
- package/lib/families/algorand/cli-transaction.js.map +1 -1
- package/lib/families/algorand/deviceTransactionConfig.d.ts +2 -2
- package/lib/families/algorand/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/families/algorand/deviceTransactionConfig.js +0 -13
- package/lib/families/algorand/deviceTransactionConfig.js.map +1 -1
- package/lib/families/algorand/hw-getAddress.d.ts.map +1 -1
- package/lib/families/algorand/hw-getAddress.js +2 -24
- package/lib/families/algorand/hw-getAddress.js.map +1 -1
- package/lib/families/algorand/js-broadcast.d.ts +9 -0
- package/lib/families/algorand/js-broadcast.d.ts.map +1 -0
- package/lib/families/algorand/js-broadcast.js +63 -0
- package/lib/families/algorand/js-broadcast.js.map +1 -0
- package/lib/families/algorand/js-estimateMaxSpendable.d.ts +9 -0
- package/lib/families/algorand/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/families/algorand/js-estimateMaxSpendable.js +89 -0
- package/lib/families/algorand/js-estimateMaxSpendable.js.map +1 -0
- package/lib/families/algorand/js-getFeesForTransaction.d.ts +5 -0
- package/lib/families/algorand/js-getFeesForTransaction.d.ts.map +1 -0
- package/lib/families/algorand/js-getFeesForTransaction.js +69 -0
- package/lib/families/algorand/js-getFeesForTransaction.js.map +1 -0
- package/lib/families/algorand/js-getTransactionStatus.d.ts +11 -0
- package/lib/families/algorand/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/families/algorand/js-getTransactionStatus.js +201 -0
- package/lib/families/algorand/js-getTransactionStatus.js.map +1 -0
- package/lib/families/algorand/js-prepareTransaction.d.ts +5 -0
- package/lib/families/algorand/js-prepareTransaction.d.ts.map +1 -0
- package/lib/families/algorand/js-prepareTransaction.js +101 -0
- package/lib/families/algorand/js-prepareTransaction.js.map +1 -0
- package/lib/families/algorand/js-signOperation.d.ts +10 -0
- package/lib/families/algorand/js-signOperation.d.ts.map +1 -0
- package/lib/families/algorand/js-signOperation.js +164 -0
- package/lib/families/algorand/js-signOperation.js.map +1 -0
- package/lib/families/algorand/js-synchronization.d.ts +10 -0
- package/lib/families/algorand/js-synchronization.d.ts.map +1 -0
- package/lib/families/algorand/js-synchronization.js +411 -0
- package/lib/families/algorand/js-synchronization.js.map +1 -0
- package/lib/families/algorand/libcore-buildTransaction.d.ts +2 -2
- package/lib/families/algorand/libcore-buildTransaction.d.ts.map +1 -1
- package/lib/families/algorand/libcore-getFeesForTransaction.d.ts +4 -4
- package/lib/families/algorand/libcore-getFeesForTransaction.d.ts.map +1 -1
- package/lib/families/algorand/libcore-getFeesForTransaction.js +2 -2
- package/lib/families/algorand/libcore-getFeesForTransaction.js.map +1 -1
- package/lib/families/algorand/libcore-postBuildAccount.d.ts.map +1 -1
- package/lib/families/algorand/libcore-postBuildAccount.js +5 -11
- package/lib/families/algorand/libcore-postBuildAccount.js.map +1 -1
- package/lib/families/algorand/libcore-signOperation.d.ts +2 -2
- package/lib/families/algorand/libcore-signOperation.d.ts.map +1 -1
- package/lib/families/algorand/libcore-signOperation.js.map +1 -1
- package/lib/families/algorand/logic.d.ts +10 -0
- package/lib/families/algorand/logic.d.ts.map +1 -1
- package/lib/families/algorand/logic.js +79 -1
- package/lib/families/algorand/logic.js.map +1 -1
- package/lib/families/algorand/mock.d.ts.map +1 -1
- package/lib/families/algorand/mock.js +4 -11
- package/lib/families/algorand/mock.js.map +1 -1
- package/lib/families/algorand/serialization.js +4 -4
- package/lib/families/algorand/serialization.js.map +1 -1
- package/lib/families/algorand/specs.d.ts +2 -2
- package/lib/families/algorand/specs.d.ts.map +1 -1
- package/lib/families/algorand/specs.js +8 -16
- package/lib/families/algorand/specs.js.map +1 -1
- package/lib/families/algorand/speculos-deviceActions.d.ts +2 -2
- package/lib/families/algorand/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/algorand/speculos-deviceActions.js +4 -0
- package/lib/families/algorand/speculos-deviceActions.js.map +1 -1
- package/lib/families/algorand/test-dataset.d.ts +2 -2
- package/lib/families/algorand/test-dataset.d.ts.map +1 -1
- package/lib/families/algorand/test-dataset.js +1 -2
- package/lib/families/algorand/test-dataset.js.map +1 -1
- package/lib/families/algorand/tokens.d.ts.map +1 -1
- package/lib/families/algorand/tokens.js.map +1 -1
- package/lib/families/algorand/transaction.d.ts +5 -5
- package/lib/families/algorand/transaction.d.ts.map +1 -1
- package/lib/families/algorand/transaction.js.map +1 -1
- package/lib/families/algorand/types.d.ts +7 -5
- package/lib/families/algorand/types.d.ts.map +1 -1
- package/lib/families/algorand/types.js.map +1 -1
- package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +1 -1
- package/lib/families/bitcoin/js-prepareTransaction.js +3 -2
- package/lib/families/bitcoin/js-prepareTransaction.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +13 -14
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js +30 -22
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts +11 -0
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.d.ts.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js +32 -0
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js +3 -115
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +24 -8
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.js +114 -128
- package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts +8 -7
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.js +42 -63
- package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
- package/lib/families/tezos/bridge/js.d.ts.map +1 -1
- package/lib/families/tezos/bridge/js.js +90 -50
- package/lib/families/tezos/bridge/js.js.map +1 -1
- package/lib/families/tezos/bridge/libcore.d.ts.map +1 -1
- package/lib/families/tezos/bridge/libcore.js +2 -1
- package/lib/families/tezos/bridge/libcore.js.map +1 -1
- package/lib/families/tezos/bridge/mock.d.ts.map +1 -1
- package/lib/families/tezos/bridge/mock.js +2 -1
- package/lib/families/tezos/bridge/mock.js.map +1 -1
- package/lib/families/tezos/signOperation.d.ts.map +1 -1
- package/lib/families/tezos/signOperation.js +37 -19
- package/lib/families/tezos/signOperation.js.map +1 -1
- package/lib/families/tezos/specs.d.ts.map +1 -1
- package/lib/families/tezos/specs.js +8 -4
- package/lib/families/tezos/specs.js.map +1 -1
- package/lib/families/tezos/speculos-deviceActions.js +6 -7
- package/lib/families/tezos/speculos-deviceActions.js.map +1 -1
- package/lib/families/tezos/synchronisation.d.ts.map +1 -1
- package/lib/families/tezos/synchronisation.js +8 -5
- package/lib/families/tezos/synchronisation.js.map +1 -1
- package/lib/families/tezos/synchronisation.test.d.ts.map +1 -1
- package/lib/families/tezos/synchronisation.test.js +0 -3
- package/lib/families/tezos/synchronisation.test.js.map +1 -1
- package/lib/families/tezos/test-dataset.d.ts +2 -2
- package/lib/families/tezos/test-dataset.d.ts.map +1 -1
- package/lib/families/tezos/test-dataset.js +45 -319
- package/lib/families/tezos/test-dataset.js.map +1 -1
- package/lib/families/tezos/transaction.d.ts +2 -2
- package/lib/families/tezos/transaction.d.ts.map +1 -1
- package/lib/families/tezos/transaction.js +4 -4
- package/lib/families/tezos/transaction.js.map +1 -1
- package/lib/families/tezos/types.d.ts +2 -0
- package/lib/families/tezos/types.d.ts.map +1 -1
- package/lib/families/tezos/types.js.map +1 -1
- package/lib/generated/bridge/js.d.ts +4 -0
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +26 -24
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/bridge/libcore.d.ts +1 -1
- package/lib/generated/bridge/mock.d.ts +1 -1
- package/lib/generated/specs.d.ts +1 -1
- package/lib/generated/speculos-deviceActions.d.ts +1 -1
- package/lib/generated/test-dataset.d.ts +1 -1
- package/lib/generated/transaction.d.ts +4 -4
- package/lib/libcore/buildAccount/index.d.ts.map +1 -1
- package/lib/libcore/buildAccount/index.js +0 -1
- package/lib/libcore/buildAccount/index.js.map +1 -1
- package/lib/mock/account.js +21 -21
- package/lib/mock/account.js.map +1 -1
- package/lib/types/operation.d.ts +1 -1
- package/lib/types/operation.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -107
- package/src/account/formatters.ts +1 -0
- package/src/account/support.ts +1 -0
- package/src/apps/polyfill.ts +1 -0
- package/src/bot/engine.ts +1 -1
- package/src/bot/specs.ts +7 -1
- package/src/data/icons/react/index.tsx +1 -0
- package/src/data/icons/react/sol.tsx +1 -1
- package/src/data/icons/react/ssv.tsx +12 -0
- package/src/data/icons/reactNative/index.tsx +1 -0
- package/src/data/icons/reactNative/sol.tsx +1 -1
- package/src/data/icons/reactNative/ssv.tsx +13 -0
- package/src/data/icons/svg/SOL.svg +1 -3
- package/src/data/icons/svg/SSV.svg +4 -0
- package/src/derivation.ts +0 -2
- package/src/env.ts +6 -6
- package/src/families/algorand/account.ts +0 -9
- package/src/families/algorand/api/algodv2.ts +68 -0
- package/src/families/algorand/api/algodv2.types.ts +27 -0
- package/src/families/algorand/api/index.ts +4 -0
- package/src/families/algorand/api/indexer.ts +99 -0
- package/src/families/algorand/api/indexer.types.ts +41 -0
- package/src/families/algorand/bridge/js.ts +46 -0
- package/src/families/algorand/bridge/libcore.ts +4 -4
- package/src/families/algorand/bridge/mock.ts +3 -3
- package/src/families/algorand/buildTransaction.ts +100 -0
- package/src/families/algorand/cli-transaction.ts +1 -1
- package/src/families/algorand/deviceTransactionConfig.ts +2 -16
- package/src/families/algorand/hw-getAddress.ts +1 -10
- package/src/families/algorand/js-broadcast.ts +17 -0
- package/src/families/algorand/js-estimateMaxSpendable.ts +51 -0
- package/src/families/algorand/js-getFeesForTransaction.ts +25 -0
- package/src/families/algorand/js-getTransactionStatus.ts +178 -0
- package/src/families/algorand/js-prepareTransaction.ts +42 -0
- package/src/families/algorand/js-signOperation.ts +145 -0
- package/src/families/algorand/js-synchronization.ts +433 -0
- package/src/families/algorand/libcore-buildTransaction.ts +2 -2
- package/src/families/algorand/libcore-getFeesForTransaction.ts +4 -4
- package/src/families/algorand/libcore-postBuildAccount.ts +2 -7
- package/src/families/algorand/libcore-signOperation.ts +2 -2
- package/src/families/algorand/logic.ts +47 -0
- package/src/families/algorand/mock.ts +2 -12
- package/src/families/algorand/serialization.ts +4 -4
- package/src/families/algorand/specs.ts +16 -22
- package/src/families/algorand/speculos-deviceActions.ts +87 -82
- package/src/families/algorand/test-dataset.ts +5 -6
- package/src/families/algorand/tokens.ts +1 -0
- package/src/families/algorand/transaction.ts +13 -4
- package/src/families/algorand/types.ts +10 -5
- package/src/families/bitcoin/js-prepareTransaction.ts +3 -2
- package/src/families/bitcoin/js-synchronisation.ts +17 -15
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +33 -21
- package/src/families/bitcoin/wallet-btc/crypto/bip32.ts +36 -0
- package/src/families/bitcoin/wallet-btc/crypto/decred.ts +3 -155
- package/src/families/bitcoin/wallet-btc/storage/index.ts +23 -11
- package/src/families/bitcoin/wallet-btc/storage/types.ts +8 -10
- package/src/families/bitcoin/wallet-btc/xpub.ts +14 -10
- package/src/families/tezos/bridge/js.ts +77 -36
- package/src/families/tezos/bridge/libcore.ts +1 -0
- package/src/families/tezos/bridge/mock.ts +1 -0
- package/src/families/tezos/signOperation.ts +31 -8
- package/src/families/tezos/specs.ts +16 -5
- package/src/families/tezos/speculos-deviceActions.ts +5 -5
- package/src/families/tezos/synchronisation.test.ts +0 -3
- package/src/families/tezos/synchronisation.ts +7 -4
- package/src/families/tezos/test-dataset.ts +33 -363
- package/src/families/tezos/transaction.ts +7 -1
- package/src/families/tezos/types.ts +2 -0
- package/src/generated/bridge/js.ts +3 -0
- package/src/libcore/buildAccount/index.ts +1 -2
- package/src/mock/account.ts +27 -27
- package/src/types/operation.ts +9 -4
|
@@ -6,150 +6,7 @@ import bs58check from "bs58check";
|
|
|
6
6
|
import createBlakeHash from "blake-hash";
|
|
7
7
|
import RIPEMD160 from "ripemd160";
|
|
8
8
|
import bs58 from "bs58";
|
|
9
|
-
import
|
|
10
|
-
import createHash from "create-hash";
|
|
11
|
-
import createHmac from "create-hmac";
|
|
12
|
-
|
|
13
|
-
// the BIP32 class is inspired from https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js
|
|
14
|
-
class BIP32 {
|
|
15
|
-
privateKey: any;
|
|
16
|
-
publicKey: any;
|
|
17
|
-
chainCode: any;
|
|
18
|
-
network: any;
|
|
19
|
-
depth: number;
|
|
20
|
-
index: number;
|
|
21
|
-
ParentFingerprint: number;
|
|
22
|
-
lowR: boolean;
|
|
23
|
-
constructor(
|
|
24
|
-
privateKey,
|
|
25
|
-
publicKey,
|
|
26
|
-
chainCode,
|
|
27
|
-
network,
|
|
28
|
-
depth = 0,
|
|
29
|
-
index = 0,
|
|
30
|
-
ParentFingerprint = 0x00000000
|
|
31
|
-
) {
|
|
32
|
-
this.privateKey = privateKey;
|
|
33
|
-
this.publicKey = publicKey;
|
|
34
|
-
this.chainCode = chainCode;
|
|
35
|
-
this.network = network;
|
|
36
|
-
this.depth = depth;
|
|
37
|
-
this.index = index;
|
|
38
|
-
this.ParentFingerprint = ParentFingerprint;
|
|
39
|
-
this.lowR = false;
|
|
40
|
-
}
|
|
41
|
-
pk() {
|
|
42
|
-
if (this.publicKey === undefined)
|
|
43
|
-
this.publicKey = ecc.pointFromScalar(this.privateKey, true);
|
|
44
|
-
return this.publicKey;
|
|
45
|
-
}
|
|
46
|
-
isNeutered() {
|
|
47
|
-
return this.privateKey === undefined;
|
|
48
|
-
}
|
|
49
|
-
neutered() {
|
|
50
|
-
return new BIP32(
|
|
51
|
-
undefined,
|
|
52
|
-
this.pk(),
|
|
53
|
-
this.chainCode,
|
|
54
|
-
this.network,
|
|
55
|
-
this.depth,
|
|
56
|
-
this.index,
|
|
57
|
-
this.ParentFingerprint
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
hmacSHA512(key, data) {
|
|
61
|
-
return createHmac("sha512", key).update(data).digest();
|
|
62
|
-
}
|
|
63
|
-
hash160(buffer) {
|
|
64
|
-
const sha256Hash = createHash("sha256").update(buffer).digest();
|
|
65
|
-
return createHash("rmd160").update(sha256Hash).digest();
|
|
66
|
-
}
|
|
67
|
-
fingerprint() {
|
|
68
|
-
return this.hash160(this.pk()).slice(0, 4);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
toBase58() {
|
|
72
|
-
const network = this.network;
|
|
73
|
-
const version = !this.isNeutered()
|
|
74
|
-
? network.bip32.private
|
|
75
|
-
: network.bip32.public;
|
|
76
|
-
const buffer = Buffer.allocUnsafe(78);
|
|
77
|
-
// 4 bytes: version bytes
|
|
78
|
-
buffer.writeUInt32BE(version, 0);
|
|
79
|
-
// 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ....
|
|
80
|
-
buffer.writeUInt8(this.depth, 4);
|
|
81
|
-
// 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
|
|
82
|
-
buffer.writeUInt32BE(this.ParentFingerprint, 5);
|
|
83
|
-
// 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
|
|
84
|
-
// This is encoded in big endian. (0x00000000 if master key)
|
|
85
|
-
buffer.writeUInt32BE(this.index, 9);
|
|
86
|
-
// 32 bytes: the chain code
|
|
87
|
-
this.chainCode.copy(buffer, 13);
|
|
88
|
-
// 33 bytes: the public key or private key data
|
|
89
|
-
if (!this.isNeutered()) {
|
|
90
|
-
// 0x00 + k for private keys
|
|
91
|
-
buffer.writeUInt8(0, 45);
|
|
92
|
-
this.privateKey.copy(buffer, 46);
|
|
93
|
-
// 33 bytes: the public key
|
|
94
|
-
} else {
|
|
95
|
-
// X9.62 encoding for public keys
|
|
96
|
-
this.pk().copy(buffer, 45);
|
|
97
|
-
}
|
|
98
|
-
return bs58check.encode(buffer);
|
|
99
|
-
}
|
|
100
|
-
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
|
|
101
|
-
derive(index) {
|
|
102
|
-
const isHardened = index >= 0x80000000;
|
|
103
|
-
const data = Buffer.allocUnsafe(37);
|
|
104
|
-
// Hardened child
|
|
105
|
-
if (isHardened) {
|
|
106
|
-
data[0] = 0x00;
|
|
107
|
-
this.privateKey.copy(data, 1);
|
|
108
|
-
data.writeUInt32BE(index, 33);
|
|
109
|
-
} else {
|
|
110
|
-
this.pk().copy(data, 0);
|
|
111
|
-
data.writeUInt32BE(index, 33);
|
|
112
|
-
}
|
|
113
|
-
const I = this.hmacSHA512(this.chainCode, data);
|
|
114
|
-
const IL = I.slice(0, 32);
|
|
115
|
-
const IR = I.slice(32);
|
|
116
|
-
// if parse256(IL) >= n, proceed with the next value for i
|
|
117
|
-
if (!ecc.isPrivate(IL)) return this.derive(index + 1);
|
|
118
|
-
// Private parent key -> private child key
|
|
119
|
-
let hd;
|
|
120
|
-
if (!this.isNeutered()) {
|
|
121
|
-
// ki = parse256(IL) + kpar (mod n)
|
|
122
|
-
const ki = ecc.privateAdd(this.privateKey, IL);
|
|
123
|
-
// In case ki == 0, proceed with the next value for i
|
|
124
|
-
if (ki == null) return this.derive(index + 1);
|
|
125
|
-
hd = new BIP32(
|
|
126
|
-
ki,
|
|
127
|
-
undefined,
|
|
128
|
-
IR,
|
|
129
|
-
this.network,
|
|
130
|
-
this.depth + 1,
|
|
131
|
-
index,
|
|
132
|
-
this.fingerprint().readUInt32BE(0)
|
|
133
|
-
);
|
|
134
|
-
} else {
|
|
135
|
-
// Ki = point(parse256(IL)) + Kpar
|
|
136
|
-
// = G*IL + Kpar
|
|
137
|
-
const Ki = ecc.pointAddScalar(this.pk(), IL, true);
|
|
138
|
-
// In case Ki is the point at infinity, proceed with the next value for i
|
|
139
|
-
if (Ki === null) return this.derive(index + 1);
|
|
140
|
-
hd = new BIP32(
|
|
141
|
-
undefined,
|
|
142
|
-
Ki,
|
|
143
|
-
IR,
|
|
144
|
-
this.network,
|
|
145
|
-
this.depth + 1,
|
|
146
|
-
index,
|
|
147
|
-
this.fingerprint().readUInt32BE(0)
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
return hd;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
9
|
+
import BIP32 from "./bip32";
|
|
153
10
|
|
|
154
11
|
class Decred extends Base {
|
|
155
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -227,20 +84,11 @@ class Decred extends Base {
|
|
|
227
84
|
buffer = bs58check.decode(xpub);
|
|
228
85
|
}
|
|
229
86
|
const depth = buffer[4];
|
|
230
|
-
const parentFingerprint = buffer.readUInt32BE(5);
|
|
231
87
|
const i = buffer.readUInt32BE(9);
|
|
232
88
|
const chainCode = buffer.slice(13, 45);
|
|
233
89
|
const X = buffer.slice(45, 78);
|
|
234
|
-
const hd = new BIP32(
|
|
235
|
-
|
|
236
|
-
X,
|
|
237
|
-
chainCode,
|
|
238
|
-
this.network,
|
|
239
|
-
depth,
|
|
240
|
-
i,
|
|
241
|
-
parentFingerprint
|
|
242
|
-
);
|
|
243
|
-
const publicKey = hd.derive(account).derive(index).pk();
|
|
90
|
+
const hd = new BIP32(X, chainCode, this.network, depth, i);
|
|
91
|
+
const publicKey = hd.derive(account).derive(index).publicKey;
|
|
244
92
|
const address = Decred.getAddressFromPk(publicKey);
|
|
245
93
|
Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
|
|
246
94
|
address;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { findLast, filter, uniqBy, findIndex, has } from "lodash";
|
|
2
|
+
import Base from "../crypto/base";
|
|
2
3
|
import { Input, IStorage, Output, TX, Address } from "./types";
|
|
3
4
|
|
|
4
5
|
// a mock storage class that just use js objects
|
|
@@ -12,12 +13,14 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
12
13
|
// accounting
|
|
13
14
|
unspentUtxos: { [key: string]: Output[] } = {};
|
|
14
15
|
|
|
16
|
+
addressCache: { [key: string]: string } = {};
|
|
17
|
+
|
|
15
18
|
// only needed to handle the case when the input
|
|
16
19
|
// is seen before the output (typically explorer
|
|
17
20
|
// returning unordered tx within the same block)
|
|
18
21
|
spentUtxos: { [key: string]: Input[] } = {};
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
getLastTx(txFilter: {
|
|
21
24
|
account?: number;
|
|
22
25
|
index?: number;
|
|
23
26
|
address?: string;
|
|
@@ -38,18 +41,18 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
38
41
|
return tx;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
getTx(address: string, hash: string) {
|
|
42
45
|
const index = `${address}-${hash}`;
|
|
43
46
|
return this.txs[this.primaryIndex[index]];
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
// TODO: only expose unspentUtxos
|
|
47
|
-
|
|
50
|
+
getAddressUnspentUtxos(address: Address) {
|
|
48
51
|
const indexAddress = address.address;
|
|
49
52
|
return this.unspentUtxos[indexAddress];
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
appendTxs(txs: TX[]) {
|
|
53
56
|
const lastLength = this.txs.length;
|
|
54
57
|
|
|
55
58
|
txs.forEach((tx) => {
|
|
@@ -97,10 +100,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
97
100
|
return this.txs.length - lastLength;
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
account?: number;
|
|
102
|
-
index?: number;
|
|
103
|
-
}) {
|
|
103
|
+
getUniquesAddresses(addressesFilter: { account?: number; index?: number }) {
|
|
104
104
|
// TODO: to speed up, create more useful indexes in appendTxs
|
|
105
105
|
return uniqBy(
|
|
106
106
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -114,7 +114,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
removeTxs(txsFilter: { account: number; index: number }) {
|
|
118
118
|
const newTxs: TX[] = [];
|
|
119
119
|
this.primaryIndex = {};
|
|
120
120
|
|
|
@@ -137,7 +137,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
137
137
|
|
|
138
138
|
// We are a bit ugly because we can't rely undo unspentUTXO
|
|
139
139
|
// So we clean the address and rebuild without the pendings
|
|
140
|
-
|
|
140
|
+
removePendingTxs(txsFilter: { account: number; index: number }) {
|
|
141
141
|
const newTxs: TX[] = [];
|
|
142
142
|
const txsToReAdd: TX[] = [];
|
|
143
143
|
this.primaryIndex = {};
|
|
@@ -161,7 +161,14 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
this.txs = newTxs;
|
|
164
|
-
|
|
164
|
+
this.appendTxs(txsToReAdd);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
addAddress(key: string, address: string): void {
|
|
168
|
+
if (!this.addressCache) {
|
|
169
|
+
this.addressCache = {};
|
|
170
|
+
}
|
|
171
|
+
this.addressCache[key] = address;
|
|
165
172
|
}
|
|
166
173
|
|
|
167
174
|
exportSync() {
|
|
@@ -169,6 +176,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
169
176
|
txs: this.txs,
|
|
170
177
|
primaryIndex: this.primaryIndex,
|
|
171
178
|
unspentUtxos: this.unspentUtxos,
|
|
179
|
+
addressCache: this.addressCache,
|
|
172
180
|
};
|
|
173
181
|
}
|
|
174
182
|
|
|
@@ -176,10 +184,13 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
176
184
|
txs: TX[];
|
|
177
185
|
primaryIndex: { [key: string]: number };
|
|
178
186
|
unspentUtxos: { [key: string]: Output[] };
|
|
187
|
+
addressCache: { [key: string]: string };
|
|
179
188
|
}) {
|
|
180
189
|
this.txs = data.txs;
|
|
181
190
|
this.primaryIndex = data.primaryIndex;
|
|
182
191
|
this.unspentUtxos = data.unspentUtxos;
|
|
192
|
+
this.addressCache = data.addressCache;
|
|
193
|
+
Base.addressCache = { ...Base.addressCache, ...this.addressCache };
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
async export() {
|
|
@@ -190,6 +201,7 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
190
201
|
txs: TX[];
|
|
191
202
|
primaryIndex: { [key: string]: number };
|
|
192
203
|
unspentUtxos: { [key: string]: Output[] };
|
|
204
|
+
addressCache: { [key: string]: string };
|
|
193
205
|
}) {
|
|
194
206
|
return this.loadSync(data);
|
|
195
207
|
}
|
|
@@ -43,24 +43,22 @@ export interface Address {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export interface IStorage {
|
|
46
|
-
appendTxs(txs: TX[]):
|
|
47
|
-
getAddressUnspentUtxos(address: Address):
|
|
46
|
+
appendTxs(txs: TX[]): number;
|
|
47
|
+
getAddressUnspentUtxos(address: Address): Output[];
|
|
48
48
|
getLastTx(txFilter: {
|
|
49
49
|
account?: number;
|
|
50
50
|
index?: number;
|
|
51
51
|
address?: string;
|
|
52
52
|
confirmed?: boolean;
|
|
53
|
-
}):
|
|
54
|
-
getTx(address: string, hash: string):
|
|
53
|
+
}): TX | undefined;
|
|
54
|
+
getTx(address: string, hash: string): TX | undefined;
|
|
55
55
|
getUniquesAddresses(addressesFilter: {
|
|
56
56
|
account?: number;
|
|
57
57
|
index?: number;
|
|
58
|
-
}):
|
|
59
|
-
removeTxs(txsFilter: { account: number; index: number }):
|
|
60
|
-
removePendingTxs(txsFilter: {
|
|
61
|
-
|
|
62
|
-
index: number;
|
|
63
|
-
}): Promise<void>;
|
|
58
|
+
}): Address[];
|
|
59
|
+
removeTxs(txsFilter: { account: number; index: number }): void;
|
|
60
|
+
removePendingTxs(txsFilter: { account: number; index: number }): void;
|
|
61
|
+
addAddress(key: string, address: string): void;
|
|
64
62
|
export(): Promise<unknown>;
|
|
65
63
|
load(data: unknown): Promise<void>;
|
|
66
64
|
exportSync(): unknown;
|
|
@@ -66,6 +66,10 @@ class Xpub extends EventEmitter {
|
|
|
66
66
|
index
|
|
67
67
|
);
|
|
68
68
|
|
|
69
|
+
this.storage.addAddress(
|
|
70
|
+
`${this.derivationMode}-${this.xpub}-${account}-${index}`,
|
|
71
|
+
address
|
|
72
|
+
);
|
|
69
73
|
await this.whenSynced("address", address);
|
|
70
74
|
|
|
71
75
|
const data = {
|
|
@@ -87,13 +91,13 @@ class Xpub extends EventEmitter {
|
|
|
87
91
|
|
|
88
92
|
// in case pendings have changed we clean them out
|
|
89
93
|
// TODO perf : bad : looping in the tx array
|
|
90
|
-
const hasPendings = !!
|
|
94
|
+
const hasPendings = !!this.storage.getLastTx({
|
|
91
95
|
confirmed: false,
|
|
92
96
|
account,
|
|
93
97
|
index,
|
|
94
|
-
})
|
|
98
|
+
});
|
|
95
99
|
if (hasPendings) {
|
|
96
|
-
|
|
100
|
+
this.storage.removePendingTxs({ account, index });
|
|
97
101
|
}
|
|
98
102
|
total = await this.fetchHydrateAndStoreNewTxs(address, account, index);
|
|
99
103
|
} catch (e) {
|
|
@@ -103,7 +107,7 @@ class Xpub extends EventEmitter {
|
|
|
103
107
|
|
|
104
108
|
this.emitSynced({ ...data, total });
|
|
105
109
|
|
|
106
|
-
const lastTx =
|
|
110
|
+
const lastTx = this.storage.getLastTx({
|
|
107
111
|
account,
|
|
108
112
|
index,
|
|
109
113
|
});
|
|
@@ -200,7 +204,7 @@ class Xpub extends EventEmitter {
|
|
|
200
204
|
async getAddressBalance(address: Address) {
|
|
201
205
|
await this.whenSynced("address", address.address);
|
|
202
206
|
|
|
203
|
-
const unspentUtxos =
|
|
207
|
+
const unspentUtxos = this.storage.getAddressUnspentUtxos(address);
|
|
204
208
|
|
|
205
209
|
return unspentUtxos.reduce(
|
|
206
210
|
(total, { value }) => total.plus(value),
|
|
@@ -419,7 +423,7 @@ class Xpub extends EventEmitter {
|
|
|
419
423
|
let txs: TX[] = [];
|
|
420
424
|
let inserted = 0;
|
|
421
425
|
do {
|
|
422
|
-
const lastTx =
|
|
426
|
+
const lastTx = this.storage.getLastTx({
|
|
423
427
|
account,
|
|
424
428
|
index,
|
|
425
429
|
confirmed: true,
|
|
@@ -433,14 +437,14 @@ class Xpub extends EventEmitter {
|
|
|
433
437
|
if (pendingTxs.length === 0) {
|
|
434
438
|
pendingTxs = txs.filter((tx) => !tx.block);
|
|
435
439
|
}
|
|
436
|
-
inserted +=
|
|
440
|
+
inserted += this.storage.appendTxs(txs.filter((tx) => tx.block)); // only insert not pending tx
|
|
437
441
|
} while (txs.length - pendingTxs.length >= this.txsSyncArraySize); // check whether page is full, if not, it is the last page
|
|
438
|
-
inserted +=
|
|
442
|
+
inserted += this.storage.appendTxs(pendingTxs);
|
|
439
443
|
return inserted;
|
|
440
444
|
}
|
|
441
445
|
|
|
442
446
|
async checkAddressReorg(account: number, index: number) {
|
|
443
|
-
const lastTx =
|
|
447
|
+
const lastTx = this.storage.getLastTx({
|
|
444
448
|
account,
|
|
445
449
|
index,
|
|
446
450
|
confirmed: true,
|
|
@@ -462,7 +466,7 @@ class Xpub extends EventEmitter {
|
|
|
462
466
|
// TODO: delete only everything for this (address, block)
|
|
463
467
|
// but need to think if its possible with current storage implem
|
|
464
468
|
|
|
465
|
-
|
|
469
|
+
this.storage.removeTxs({
|
|
466
470
|
account,
|
|
467
471
|
index,
|
|
468
472
|
});
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
NotEnoughBalance,
|
|
7
7
|
NotEnoughBalanceToDelegate,
|
|
8
8
|
FeeTooHigh,
|
|
9
|
-
NotSupportedLegacyAddress,
|
|
10
9
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
11
10
|
RecommendUndelegation,
|
|
12
11
|
} from "@ledgerhq/errors";
|
|
@@ -45,6 +44,7 @@ const createTransaction: () => Transaction = () => ({
|
|
|
45
44
|
networkInfo: null,
|
|
46
45
|
useAllAmount: false,
|
|
47
46
|
taquitoError: null,
|
|
47
|
+
estimatedFees: null,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
const updateTransaction = (t, patch) => ({ ...t, ...patch });
|
|
@@ -65,7 +65,7 @@ const getTransactionStatus = async (
|
|
|
65
65
|
recipient?: Error;
|
|
66
66
|
} = {};
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const estimatedFees = t.estimatedFees || new BigNumber(0);
|
|
69
69
|
|
|
70
70
|
const { tezosResources } = account;
|
|
71
71
|
if (!tezosResources) throw new Error("tezosResources is missing");
|
|
@@ -90,17 +90,6 @@ const getTransactionStatus = async (
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
if (t.recipient.startsWith("KT") && !errors.recipient) {
|
|
94
|
-
errors.recipient = new NotSupportedLegacyAddress();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// no fee / not enough balance already handled by taquitoError
|
|
98
|
-
if (!tezosResources.revealed) {
|
|
99
|
-
// FIXME
|
|
100
|
-
// https://github.com/ecadlabs/taquito/commit/48a11cfaffe4c6bdfa6f04ebbd0b756f4b135865#diff-3b138622526cbaa55605b79011aa411652367136a3e92e43faecc654da3854e7
|
|
101
|
-
estimatedFees = estimatedFees.plus(374 || DEFAULT_FEE.REVEAL);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
93
|
if (t.mode === "send") {
|
|
105
94
|
if (!errors.amount && t.amount.eq(0)) {
|
|
106
95
|
errors.amount = new AmountRequired();
|
|
@@ -120,7 +109,11 @@ const getTransactionStatus = async (
|
|
|
120
109
|
.lt(thresholdWarning)
|
|
121
110
|
) {
|
|
122
111
|
if (isAccountDelegating(account)) {
|
|
123
|
-
|
|
112
|
+
if (t.useAllAmount) {
|
|
113
|
+
errors.amount = new RecommendUndelegation();
|
|
114
|
+
} else {
|
|
115
|
+
warnings.amount = new RecommendUndelegation();
|
|
116
|
+
}
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
}
|
|
@@ -128,15 +121,22 @@ const getTransactionStatus = async (
|
|
|
128
121
|
log("taquitoerror", String(t.taquitoError));
|
|
129
122
|
|
|
130
123
|
// remap taquito errors
|
|
131
|
-
if (t.taquitoError
|
|
124
|
+
if (t.taquitoError.endsWith("balance_too_low")) {
|
|
132
125
|
if (t.mode === "send") {
|
|
133
126
|
errors.amount = new NotEnoughBalance();
|
|
134
127
|
} else {
|
|
135
128
|
errors.amount = new NotEnoughBalanceToDelegate();
|
|
136
129
|
}
|
|
130
|
+
} else {
|
|
131
|
+
// unidentified error case
|
|
132
|
+
errors.amount = new Error(t.taquitoError);
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
|
|
136
|
+
if (!errors.amount && account.balance.lte(0)) {
|
|
137
|
+
errors.amount = new NotEnoughBalance();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
140
|
const result = {
|
|
141
141
|
errors,
|
|
142
142
|
warnings,
|
|
@@ -154,8 +154,25 @@ const prepareTransaction = async (
|
|
|
154
154
|
const { tezosResources } = account;
|
|
155
155
|
if (!tezosResources) throw new Error("tezosResources is missing");
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
if (account.balance.lte(0)) {
|
|
158
|
+
return Promise.resolve(transaction);
|
|
159
|
+
}
|
|
158
160
|
|
|
161
|
+
// basic check to confirm the transaction is "complete"
|
|
162
|
+
if (transaction.mode !== "undelegate") {
|
|
163
|
+
if (!transaction.recipient) {
|
|
164
|
+
return Promise.resolve(transaction);
|
|
165
|
+
}
|
|
166
|
+
const { recipientError } = await validateRecipient(
|
|
167
|
+
account.currency,
|
|
168
|
+
transaction.recipient
|
|
169
|
+
);
|
|
170
|
+
if (recipientError) {
|
|
171
|
+
return Promise.resolve(transaction);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const tezos = new TezosToolkit(getEnv("API_TEZOS_NODE"));
|
|
159
176
|
tezos.setProvider({
|
|
160
177
|
signer: {
|
|
161
178
|
publicKeyHash: async () => account.freshAddress,
|
|
@@ -165,20 +182,21 @@ const prepareTransaction = async (
|
|
|
165
182
|
},
|
|
166
183
|
});
|
|
167
184
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
185
|
+
if (transaction.useAllAmount) {
|
|
186
|
+
// taquito does not accept 0, so we do 1
|
|
187
|
+
// only failing case is when the account precisely has fees + 1. which is
|
|
188
|
+
// unlikely
|
|
189
|
+
transaction.amount = new BigNumber(1);
|
|
190
|
+
}
|
|
175
191
|
|
|
192
|
+
try {
|
|
176
193
|
let out;
|
|
177
194
|
switch (transaction.mode) {
|
|
178
195
|
case "send":
|
|
179
196
|
out = await tezos.estimate.transfer({
|
|
197
|
+
mutez: true,
|
|
180
198
|
to: transaction.recipient,
|
|
181
|
-
amount: transaction.amount.
|
|
199
|
+
amount: transaction.amount.toNumber(),
|
|
182
200
|
});
|
|
183
201
|
break;
|
|
184
202
|
case "delegate":
|
|
@@ -193,14 +211,15 @@ const prepareTransaction = async (
|
|
|
193
211
|
});
|
|
194
212
|
break;
|
|
195
213
|
default:
|
|
196
|
-
throw "
|
|
214
|
+
throw new Error("unsupported mode=" + transaction.mode);
|
|
197
215
|
}
|
|
198
216
|
|
|
199
|
-
transaction.fees = new BigNumber(out.suggestedFeeMutez);
|
|
200
|
-
transaction.gasLimit = new BigNumber(out.gasLimit);
|
|
201
|
-
transaction.storageLimit = new BigNumber(out.storageLimit);
|
|
202
|
-
|
|
203
217
|
if (transaction.useAllAmount) {
|
|
218
|
+
const totalFees = out.suggestedFeeMutez + out.burnFeeMutez;
|
|
219
|
+
const maxAmount = account.balance
|
|
220
|
+
.minus(totalFees + (tezosResources.revealed ? 0 : DEFAULT_FEE.REVEAL))
|
|
221
|
+
.toNumber();
|
|
222
|
+
// from https://github.com/ecadlabs/taquito/blob/a70c64c4b105381bb9f1d04c9c70e8ef26e9241c/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts#L33
|
|
204
223
|
// Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
|
|
205
224
|
// we need to increase the gasLimit and fee returned by the estimation
|
|
206
225
|
const gasBuffer = 500;
|
|
@@ -208,15 +227,37 @@ const prepareTransaction = async (
|
|
|
208
227
|
const increasedFee = (gasBuffer: number, opSize: number) => {
|
|
209
228
|
return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
|
|
210
229
|
};
|
|
211
|
-
|
|
212
|
-
|
|
230
|
+
const incr = increasedFee(gasBuffer, Number(out.opSize));
|
|
231
|
+
transaction.fees = new BigNumber(out.suggestedFeeMutez + incr);
|
|
232
|
+
transaction.gasLimit = new BigNumber(out.gasLimit + gasBuffer);
|
|
233
|
+
transaction.amount = new BigNumber(maxAmount - incr);
|
|
234
|
+
} else {
|
|
235
|
+
transaction.fees = new BigNumber(out.suggestedFeeMutez);
|
|
236
|
+
transaction.gasLimit = new BigNumber(out.gasLimit);
|
|
237
|
+
transaction.storageLimit = new BigNumber(out.storageLimit);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
transaction.storageLimit = new BigNumber(out.storageLimit);
|
|
241
|
+
transaction.estimatedFees = transaction.fees;
|
|
242
|
+
if (!tezosResources.revealed) {
|
|
243
|
+
transaction.estimatedFees = transaction.estimatedFees.plus(
|
|
244
|
+
DEFAULT_FEE.REVEAL
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
} catch (e) {
|
|
248
|
+
if (typeof e !== "object" || !e) throw e;
|
|
249
|
+
if ("id" in e) {
|
|
250
|
+
transaction.taquitoError = (e as { id: string }).id;
|
|
251
|
+
} else if ("status" in e) {
|
|
252
|
+
// in case of http 400, log & ignore (more case to handle)
|
|
253
|
+
log(
|
|
254
|
+
"taquito-network-error",
|
|
255
|
+
String((e as { message: string }).message || ""),
|
|
256
|
+
{ transaction }
|
|
213
257
|
);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
transaction.amount = account.balance.minus(s.estimatedFees);
|
|
258
|
+
} else {
|
|
259
|
+
throw e;
|
|
217
260
|
}
|
|
218
|
-
} catch (e: any) {
|
|
219
|
-
transaction.taquitoError = e.id;
|
|
220
261
|
}
|
|
221
262
|
|
|
222
263
|
return transaction;
|