@ledgerhq/live-common 21.32.1 → 21.32.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +1 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.d.ts +2 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.d.ts.map +1 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.js +126 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.js.map +1 -0
- package/lib/apps/hw.d.ts.map +1 -1
- package/lib/apps/hw.js +4 -3
- package/lib/apps/hw.js.map +1 -1
- package/lib/apps/logic.d.ts.map +1 -1
- package/lib/apps/logic.js +7 -5
- package/lib/apps/logic.js.map +1 -1
- package/lib/bot/engine.d.ts.map +1 -1
- package/lib/bot/engine.js +3 -0
- package/lib/bot/engine.js.map +1 -1
- package/lib/env.d.ts +10 -5
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +5 -0
- 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/errors.d.ts +3 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +3 -2
- package/lib/errors.js.map +1 -1
- package/lib/exchange/platform/transfer/index.d.ts.map +1 -1
- package/lib/exchange/platform/transfer/index.js +15 -1
- package/lib/exchange/platform/transfer/index.js.map +1 -1
- package/lib/families/algorand/buildTransaction.d.ts +2 -2
- package/lib/families/algorand/buildTransaction.d.ts.map +1 -1
- package/lib/families/algorand/buildTransaction.js +13 -19
- package/lib/families/algorand/buildTransaction.js.map +1 -1
- package/lib/families/algorand/js-getFeesForTransaction.js +4 -6
- package/lib/families/algorand/js-getFeesForTransaction.js.map +1 -1
- package/lib/families/algorand/js-signOperation.js +3 -7
- package/lib/families/algorand/js-signOperation.js.map +1 -1
- package/lib/families/algorand/js-synchronization.d.ts.map +1 -1
- package/lib/families/algorand/js-synchronization.js +1 -0
- package/lib/families/algorand/js-synchronization.js.map +1 -1
- package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-signOperation.js +3 -5
- package/lib/families/bitcoin/js-signOperation.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +4 -3
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js +8 -7
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js +2 -2
- package/lib/families/bitcoin/wallet-btc/crypto/bip32.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +3 -7
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts +3 -4
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +27 -53
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js +2 -7
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts +1 -6
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +0 -51
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +5 -6
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +63 -33
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +3 -5
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +77 -46
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/celo/speculos-deviceActions.js +1 -2
- package/lib/families/celo/speculos-deviceActions.js.map +1 -1
- package/lib/families/ethereum/signOperation.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +26 -15
- package/lib/families/ethereum/signOperation.js.map +1 -1
- package/lib/families/ethereum/specs.d.ts.map +1 -1
- package/lib/families/ethereum/specs.js +2 -4
- package/lib/families/ethereum/specs.js.map +1 -1
- package/lib/families/ethereum/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/ethereum/speculos-deviceActions.js +4 -0
- package/lib/families/ethereum/speculos-deviceActions.js.map +1 -1
- package/lib/families/ethereum/transaction.d.ts +4 -1
- package/lib/families/ethereum/transaction.d.ts.map +1 -1
- package/lib/families/ethereum/transaction.js +15 -27
- package/lib/families/ethereum/transaction.js.map +1 -1
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +1 -1
- package/lib/families/solana/test-dataset.d.ts.map +1 -1
- package/lib/families/solana/test-dataset.js +1 -2
- package/lib/families/solana/test-dataset.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/families/tezos/synchronisation.d.ts.map +1 -1
- package/lib/families/tezos/synchronisation.js +2 -0
- package/lib/families/tezos/synchronisation.js.map +1 -1
- package/lib/families/tron/synchronisation.test.js +1 -0
- package/lib/families/tron/synchronisation.test.js.map +1 -1
- package/lib/featureFlags/FeatureToggle.js +2 -2
- package/lib/featureFlags/FeatureToggle.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -1
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/types.d.ts +1 -1
- package/lib/featureFlags/types.d.ts.map +1 -1
- package/lib/load/speculos.d.ts +7 -0
- package/lib/load/speculos.d.ts.map +1 -1
- package/lib/load/speculos.js +27 -11
- package/lib/load/speculos.js.map +1 -1
- package/lib/platform/PlatformAppProvider/helpers.d.ts +1 -0
- package/lib/platform/PlatformAppProvider/helpers.d.ts.map +1 -1
- package/lib/platform/PlatformAppProvider/helpers.js +23 -1
- package/lib/platform/PlatformAppProvider/helpers.js.map +1 -1
- package/lib/platform/PlatformAppProvider/index.d.ts.map +1 -1
- package/lib/platform/PlatformAppProvider/index.js +2 -1
- package/lib/platform/PlatformAppProvider/index.js.map +1 -1
- package/lib/types/manager.d.ts +4 -3
- package/lib/types/manager.d.ts.map +1 -1
- package/lib/types/manager.js +4 -3
- package/lib/types/manager.js.map +1 -1
- package/package.json +21 -21
- package/src/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +109 -23
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.ts +78 -0
- package/src/apps/hw.ts +4 -3
- package/src/apps/logic.ts +6 -3
- package/src/bot/engine.ts +3 -0
- package/src/{__tests__ → data/flags}/.DS_Store +0 -0
- package/src/env.ts +5 -0
- package/src/errors.ts +3 -0
- package/src/exchange/platform/transfer/index.ts +21 -1
- package/src/families/algorand/buildTransaction.ts +4 -8
- package/src/families/algorand/js-getFeesForTransaction.ts +1 -1
- package/src/families/algorand/js-signOperation.ts +2 -2
- package/src/families/algorand/js-synchronization.ts +1 -0
- package/src/families/bitcoin/js-signOperation.ts +3 -5
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +31 -18
- package/src/families/bitcoin/wallet-btc/crypto/bip32.ts +2 -2
- package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +3 -17
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +5 -39
- package/src/families/bitcoin/wallet-btc/crypto/decred.ts +2 -15
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +1 -71
- package/src/families/bitcoin/wallet-btc/crypto/types.ts +7 -0
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +23 -41
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +30 -49
- package/src/families/celo/speculos-deviceActions.ts +0 -1
- package/src/families/ethereum/signOperation.ts +21 -20
- package/src/families/ethereum/specs.ts +0 -2
- package/src/families/ethereum/speculos-deviceActions.ts +4 -0
- package/src/families/ethereum/transaction.ts +10 -24
- package/src/families/solana/test-dataset.ts +3 -4
- package/src/families/tezos/bridge/js.ts +6 -1
- package/src/families/tezos/synchronisation.ts +2 -0
- package/src/families/tron/synchronisation.test.ts +2 -0
- package/src/featureFlags/FeatureToggle.tsx +2 -2
- package/src/featureFlags/defaultFeatures.ts +1 -1
- package/src/featureFlags/types.ts +1 -1
- package/src/load/speculos.ts +23 -10
- package/src/platform/PlatformAppProvider/helpers.ts +29 -0
- package/src/platform/PlatformAppProvider/index.tsx +3 -2
- package/src/types/manager.ts +4 -3
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +0 -6195
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { publicKeyTweakAdd } from "secp256k1";
|
|
2
2
|
import createHmac from "create-hmac";
|
|
3
3
|
|
|
4
4
|
// the BIP32 class is inspired from https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js
|
|
@@ -28,7 +28,7 @@ class BIP32 {
|
|
|
28
28
|
const I = createHmac("sha512", this.chainCode).update(data).digest();
|
|
29
29
|
const IL = I.slice(0, 32);
|
|
30
30
|
const IR = I.slice(32);
|
|
31
|
-
const Ki =
|
|
31
|
+
const Ki = Buffer.from(publicKeyTweakAdd(this.publicKey, IL));
|
|
32
32
|
return new BIP32(Ki, IR, this.network, this.depth + 1, index);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -119,31 +119,17 @@ class Bitcoin extends Base {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// get address given an address type
|
|
122
|
-
|
|
122
|
+
customGetAddress(
|
|
123
123
|
derivationMode: string,
|
|
124
124
|
xpub: string,
|
|
125
125
|
account: number,
|
|
126
126
|
index: number
|
|
127
127
|
): string {
|
|
128
|
-
if (
|
|
129
|
-
Base.addressCache[
|
|
130
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
131
|
-
]
|
|
132
|
-
) {
|
|
133
|
-
return Base.addressCache[
|
|
134
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
135
|
-
];
|
|
136
|
-
}
|
|
137
128
|
switch (derivationMode) {
|
|
138
129
|
case DerivationModes.TAPROOT:
|
|
139
|
-
|
|
140
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
141
|
-
] = this.getTaprootAddress(xpub, account, index);
|
|
142
|
-
return Base.addressCache[
|
|
143
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
144
|
-
];
|
|
130
|
+
return this.getTaprootAddress(xpub, account, index);
|
|
145
131
|
default:
|
|
146
|
-
return super.
|
|
132
|
+
return super.customGetAddress(derivationMode, xpub, account, index);
|
|
147
133
|
}
|
|
148
134
|
}
|
|
149
135
|
|
|
@@ -1,73 +1,44 @@
|
|
|
1
|
-
// Fix the "More than one instance of bitcore-lib-cash" issue. Refer to https://github.com/bitpay/bitcore/issues/1457
|
|
2
|
-
delete global._bitcoreCash;
|
|
3
|
-
import * as bch from "bitcore-lib-cash";
|
|
4
1
|
import bchaddr from "bchaddrjs";
|
|
5
2
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
3
|
// @ts-ignore
|
|
7
4
|
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
8
5
|
import { InvalidAddress } from "@ledgerhq/errors";
|
|
9
6
|
import { DerivationModes } from "../types";
|
|
10
|
-
import { ICrypto } from "./types";
|
|
11
7
|
import Base from "./base";
|
|
12
8
|
|
|
13
9
|
// a mock explorer class that just use js objects
|
|
14
|
-
class BitcoinCash
|
|
10
|
+
class BitcoinCash extends Base {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
12
|
network: any;
|
|
17
13
|
|
|
18
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
15
|
constructor({ network }: { network: any }) {
|
|
16
|
+
super({ network });
|
|
20
17
|
this.network = network;
|
|
21
18
|
this.network.dustThreshold = 5430;
|
|
22
19
|
this.network.dustPolicy = "FIXED";
|
|
23
20
|
this.network.usesTimestampedTransaction = false;
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
// Based on https://github.com/go-faast/bitcoin-cash-payments/blob/54397eb97c7a9bf08b32e10bef23d5f27aa5ab01/index.js#L63-L73
|
|
27
23
|
// eslint-disable-next-line
|
|
28
24
|
getLegacyBitcoinCashAddress(
|
|
29
25
|
xpub: string,
|
|
30
26
|
account: number,
|
|
31
27
|
index: number
|
|
32
28
|
): string {
|
|
33
|
-
|
|
34
|
-
const child = node.derive(account).derive(index);
|
|
35
|
-
const address = new bch.Address(child.publicKey, bch.Networks.livenet);
|
|
36
|
-
const addrstr = address.toString().split(":");
|
|
37
|
-
if (addrstr.length === 2) {
|
|
38
|
-
return bchaddr.toCashAddress(bchaddr.toLegacyAddress(addrstr[1]));
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Unable to derive cash address for ${address}`);
|
|
29
|
+
return bchaddr.toCashAddress(super.getLegacyAddress(xpub, account, index));
|
|
41
30
|
}
|
|
42
31
|
|
|
43
32
|
// get address given an address type
|
|
44
|
-
|
|
33
|
+
customGetAddress(
|
|
45
34
|
derivationMode: string,
|
|
46
35
|
xpub: string,
|
|
47
36
|
account: number,
|
|
48
37
|
index: number
|
|
49
38
|
): string {
|
|
50
|
-
|
|
51
|
-
Base.addressCache[
|
|
52
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
53
|
-
]
|
|
54
|
-
) {
|
|
55
|
-
return Base.addressCache[
|
|
56
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
const address = this.getLegacyBitcoinCashAddress(xpub, account, index);
|
|
60
|
-
Base.addressCache[
|
|
61
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
62
|
-
] = address;
|
|
63
|
-
return address;
|
|
39
|
+
return this.getLegacyBitcoinCashAddress(xpub, account, index);
|
|
64
40
|
}
|
|
65
41
|
|
|
66
|
-
// infer address type from its syntax
|
|
67
|
-
//
|
|
68
|
-
// TODO: improve the prefix matching: make the expected prefix
|
|
69
|
-
// correspond to the actual type (currently, a `ltc1` prefix
|
|
70
|
-
// could match a native Bitcoin address type for instance)
|
|
71
42
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
43
|
getDerivationMode(address: string) {
|
|
73
44
|
return DerivationModes.LEGACY;
|
|
@@ -85,11 +56,6 @@ class BitcoinCash implements ICrypto {
|
|
|
85
56
|
validateAddress(address: string): boolean {
|
|
86
57
|
return bchaddr.isValidAddress(address);
|
|
87
58
|
}
|
|
88
|
-
|
|
89
|
-
// eslint-disable-next-line
|
|
90
|
-
isTaprootAddress(address: string): boolean {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
59
|
}
|
|
94
60
|
|
|
95
61
|
export default BitcoinCash;
|
|
@@ -68,21 +68,12 @@ class Decred extends Base {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// get address given an address type
|
|
71
|
-
|
|
71
|
+
customGetAddress(
|
|
72
72
|
derivationMode: string,
|
|
73
73
|
xpub: string,
|
|
74
74
|
account: number,
|
|
75
75
|
index: number
|
|
76
76
|
): string {
|
|
77
|
-
if (
|
|
78
|
-
Base.addressCache[
|
|
79
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
80
|
-
]
|
|
81
|
-
) {
|
|
82
|
-
return Base.addressCache[
|
|
83
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
77
|
let buffer: Buffer;
|
|
87
78
|
try {
|
|
88
79
|
buffer = Decred.bs58check.decode(xpub);
|
|
@@ -95,11 +86,7 @@ class Decred extends Base {
|
|
|
95
86
|
const X = buffer.slice(45, 78);
|
|
96
87
|
const hd = new BIP32(X, chainCode, this.network, depth, i);
|
|
97
88
|
const publicKey = hd.derive(account).derive(index).publicKey;
|
|
98
|
-
|
|
99
|
-
Base.addressCache[
|
|
100
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
101
|
-
] = address;
|
|
102
|
-
return address;
|
|
89
|
+
return Decred.getAddressFromPk(publicKey);
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
92
|
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import * as bjs from "bitcoinjs-lib";
|
|
2
|
-
import * as bip32 from "bip32";
|
|
3
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
2
|
// @ts-ignore
|
|
5
3
|
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
6
4
|
import * as bech32 from "bech32";
|
|
7
5
|
import { DerivationModes } from "../types";
|
|
8
|
-
import { ICrypto } from "./types";
|
|
9
6
|
import Base from "./base";
|
|
10
7
|
|
|
11
8
|
// Todo copy paste from bitcoin.ts. we can merge them later
|
|
12
|
-
class Litecoin extends Base
|
|
9
|
+
class Litecoin extends Base {
|
|
13
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
11
|
network: any;
|
|
15
12
|
|
|
@@ -21,73 +18,6 @@ class Litecoin extends Base implements ICrypto {
|
|
|
21
18
|
this.network.usesTimestampedTransaction = false;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
getLegacyAddress(xpub: string, account: number, index: number): string {
|
|
25
|
-
const { address } = bjs.payments.p2pkh({
|
|
26
|
-
pubkey: bip32.fromBase58(xpub, this.network).derive(account).derive(index)
|
|
27
|
-
.publicKey,
|
|
28
|
-
network: this.network,
|
|
29
|
-
});
|
|
30
|
-
return String(address);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getSegWitAddress(xpub: string, account: number, index: number): string {
|
|
34
|
-
const { address } = bjs.payments.p2sh({
|
|
35
|
-
redeem: bjs.payments.p2wpkh({
|
|
36
|
-
pubkey: bip32
|
|
37
|
-
.fromBase58(xpub, this.network)
|
|
38
|
-
.derive(account)
|
|
39
|
-
.derive(index).publicKey,
|
|
40
|
-
network: this.network,
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
return String(address);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getNativeSegWitAddress(xpub: string, account: number, index: number): string {
|
|
47
|
-
const { address } = bjs.payments.p2wpkh({
|
|
48
|
-
pubkey: bip32.fromBase58(xpub, this.network).derive(account).derive(index)
|
|
49
|
-
.publicKey,
|
|
50
|
-
network: this.network,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return String(address);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getAddress(
|
|
57
|
-
derivationMode: DerivationModes,
|
|
58
|
-
xpub: string,
|
|
59
|
-
account: number,
|
|
60
|
-
index: number
|
|
61
|
-
): string {
|
|
62
|
-
if (
|
|
63
|
-
Base.addressCache[
|
|
64
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
65
|
-
]
|
|
66
|
-
) {
|
|
67
|
-
return Base.addressCache[
|
|
68
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
let address: string;
|
|
72
|
-
switch (derivationMode) {
|
|
73
|
-
case DerivationModes.LEGACY:
|
|
74
|
-
address = this.getLegacyAddress(xpub, account, index);
|
|
75
|
-
break;
|
|
76
|
-
case DerivationModes.SEGWIT:
|
|
77
|
-
address = this.getSegWitAddress(xpub, account, index);
|
|
78
|
-
break;
|
|
79
|
-
case DerivationModes.NATIVE_SEGWIT:
|
|
80
|
-
address = this.getNativeSegWitAddress(xpub, account, index);
|
|
81
|
-
break;
|
|
82
|
-
default:
|
|
83
|
-
throw new Error("Should not be reachable");
|
|
84
|
-
}
|
|
85
|
-
Base.addressCache[
|
|
86
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
87
|
-
] = address;
|
|
88
|
-
return address;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
21
|
// infer address type from its syntax
|
|
92
22
|
getDerivationMode(address: string) {
|
|
93
23
|
if (address.match("^(ltc1).*")) {
|
|
@@ -7,6 +7,13 @@ export interface ICrypto {
|
|
|
7
7
|
account: number,
|
|
8
8
|
index: number
|
|
9
9
|
): string;
|
|
10
|
+
customGetAddress(
|
|
11
|
+
derivationMode: string,
|
|
12
|
+
xpub: string,
|
|
13
|
+
account: number,
|
|
14
|
+
index: number
|
|
15
|
+
): string;
|
|
16
|
+
|
|
10
17
|
getDerivationMode(address: string): string;
|
|
11
18
|
|
|
12
19
|
toOutputScript(address: string): Buffer;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
-
// @ts-ignore
|
|
6
3
|
import zec from "zcash-bitcore-lib";
|
|
7
4
|
import bs58check from "bs58check";
|
|
8
|
-
import
|
|
5
|
+
import * as bjs from "bitcoinjs-lib";
|
|
9
6
|
import { InvalidAddress } from "@ledgerhq/errors";
|
|
10
7
|
import { DerivationModes } from "../types";
|
|
11
|
-
import { ICrypto } from "./types";
|
|
12
8
|
import Base from "./base";
|
|
13
9
|
|
|
14
|
-
class ZCash
|
|
10
|
+
class ZCash extends Base {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
12
|
network: any;
|
|
17
13
|
|
|
18
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
15
|
constructor({ network }: { network: any }) {
|
|
16
|
+
super({ network });
|
|
20
17
|
this.network = network;
|
|
21
18
|
this.network.dustThreshold = 10000;
|
|
22
19
|
this.network.dustPolicy = "FIXED";
|
|
@@ -32,41 +29,22 @@ class ZCash implements ICrypto {
|
|
|
32
29
|
return bs58check.encode(Buffer.from(taddr));
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
private static toBitcoinAddr(taddr: string) {
|
|
36
|
-
// refer to https://runkitcdn.com/gojomo/baddr2taddr/1.0.2
|
|
37
|
-
const baddr = new Uint8Array(21);
|
|
38
|
-
baddr.set(bs58check.decode(taddr).slice(2), 1);
|
|
39
|
-
return bs58check.encode(Buffer.from(baddr));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
32
|
// eslint-disable-next-line
|
|
43
33
|
getLegacyAddress(xpub: string, account: number, index: number): string {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const pk = bjs.crypto.hash160(this.getPubkeyAt(xpub, account, index));
|
|
35
|
+
const payload = Buffer.allocUnsafe(22);
|
|
36
|
+
payload.writeUInt16BE(this.network.pubKeyHash, 0);
|
|
37
|
+
pk.copy(payload, 2);
|
|
38
|
+
return bs58check.encode(payload);
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
customGetAddress(
|
|
51
42
|
derivationMode: string,
|
|
52
43
|
xpub: string,
|
|
53
44
|
account: number,
|
|
54
45
|
index: number
|
|
55
46
|
): string {
|
|
56
|
-
|
|
57
|
-
Base.addressCache[
|
|
58
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
59
|
-
]
|
|
60
|
-
) {
|
|
61
|
-
return Base.addressCache[
|
|
62
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
const address = this.getLegacyAddress(xpub, account, index);
|
|
66
|
-
Base.addressCache[
|
|
67
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
68
|
-
] = address;
|
|
69
|
-
return address;
|
|
47
|
+
return this.getLegacyAddress(xpub, account, index);
|
|
70
48
|
}
|
|
71
49
|
|
|
72
50
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -78,22 +56,26 @@ class ZCash implements ICrypto {
|
|
|
78
56
|
if (!this.validateAddress(address)) {
|
|
79
57
|
throw new InvalidAddress();
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
ZCash.toBitcoinAddr(address),
|
|
84
|
-
coininfo.bitcoin.main.toBitcoinJS()
|
|
59
|
+
const version = Number(
|
|
60
|
+
"0x" + bs58check.decode(address).slice(0, 2).toString("hex")
|
|
85
61
|
);
|
|
62
|
+
if (version === this.network.pubKeyHash) {
|
|
63
|
+
//Pay-to-PubkeyHash
|
|
64
|
+
return bjs.payments.p2pkh({ hash: bs58check.decode(address).slice(2) })
|
|
65
|
+
.output as Buffer;
|
|
66
|
+
}
|
|
67
|
+
if (version === this.network.scriptHash) {
|
|
68
|
+
//Pay-to-Script-Hash
|
|
69
|
+
return bjs.payments.p2sh({ hash: bs58check.decode(address).slice(2) })
|
|
70
|
+
.output as Buffer;
|
|
71
|
+
}
|
|
72
|
+
throw new InvalidAddress();
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
// eslint-disable-next-line class-methods-use-this
|
|
89
76
|
validateAddress(address: string): boolean {
|
|
90
77
|
return zec.Address.isValid(address, "livenet");
|
|
91
78
|
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line
|
|
94
|
-
isTaprootAddress(address: string): boolean {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
79
|
}
|
|
98
80
|
|
|
99
81
|
export default ZCash;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { toOutputScript } from "bitcoinjs-lib/src/address";
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import zec from "zcash-bitcore-lib";
|
|
7
1
|
import bs58check from "bs58check";
|
|
8
|
-
import coininfo from "coininfo";
|
|
9
2
|
import { InvalidAddress } from "@ledgerhq/errors";
|
|
10
3
|
import { DerivationModes } from "../types";
|
|
11
|
-
import { ICrypto } from "./types";
|
|
12
4
|
import Base from "./base";
|
|
5
|
+
import * as bjs from "bitcoinjs-lib";
|
|
13
6
|
|
|
14
|
-
class Zen
|
|
7
|
+
class Zen extends Base {
|
|
15
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
9
|
network: any;
|
|
17
10
|
|
|
18
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
12
|
constructor({ network }: { network: any }) {
|
|
13
|
+
super({ network });
|
|
20
14
|
// refer to https://github.com/HorizenOfficial/zen/blob/master/src/chainparams.cpp for the blockchain params
|
|
21
15
|
this.network = network;
|
|
22
16
|
this.network.versions = {
|
|
@@ -26,15 +20,15 @@ class Zen implements ICrypto {
|
|
|
26
20
|
},
|
|
27
21
|
bip44: 121,
|
|
28
22
|
private: 0x80,
|
|
29
|
-
public:
|
|
30
|
-
scripthash:
|
|
23
|
+
public: 0x2089,
|
|
24
|
+
scripthash: 0x2096,
|
|
31
25
|
};
|
|
32
26
|
this.network.name = "Zencash";
|
|
33
27
|
this.network.unit = "ZEN";
|
|
34
28
|
this.network.messagePrefix = "Zencash Signed Message:\n";
|
|
35
29
|
this.network.wif = 0x80;
|
|
36
|
-
this.network.pubKeyHash =
|
|
37
|
-
this.network.scriptHash =
|
|
30
|
+
this.network.pubKeyHash = 0x2089;
|
|
31
|
+
this.network.scriptHash = 0x2096;
|
|
38
32
|
this.network.dustThreshold = 10000;
|
|
39
33
|
this.network.dustPolicy = "FIXED";
|
|
40
34
|
this.network.usesTimestampedTransaction = false;
|
|
@@ -50,43 +44,22 @@ class Zen implements ICrypto {
|
|
|
50
44
|
return bs58check.encode(Buffer.from(taddr));
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
private static toBitcoinAddr(taddr: string) {
|
|
54
|
-
// refer to https://runkitcdn.com/gojomo/baddr2taddr/1.0.2
|
|
55
|
-
const baddr = new Uint8Array(21);
|
|
56
|
-
baddr.set(bs58check.decode(taddr).slice(2), 1);
|
|
57
|
-
return bs58check.encode(Buffer.from(baddr));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
47
|
// eslint-disable-next-line
|
|
61
48
|
getLegacyAddress(xpub: string, account: number, index: number): string {
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return this.baddrToTaddr(bs58check.encode(Buffer.from(baddr)));
|
|
49
|
+
const pk = bjs.crypto.hash160(this.getPubkeyAt(xpub, account, index));
|
|
50
|
+
const payload = Buffer.allocUnsafe(22);
|
|
51
|
+
payload.writeUInt16BE(this.network.pubKeyHash, 0);
|
|
52
|
+
pk.copy(payload, 2);
|
|
53
|
+
return bs58check.encode(payload);
|
|
68
54
|
}
|
|
69
55
|
|
|
70
|
-
|
|
56
|
+
customGetAddress(
|
|
71
57
|
derivationMode: string,
|
|
72
58
|
xpub: string,
|
|
73
59
|
account: number,
|
|
74
60
|
index: number
|
|
75
61
|
): string {
|
|
76
|
-
|
|
77
|
-
Base.addressCache[
|
|
78
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
79
|
-
]
|
|
80
|
-
) {
|
|
81
|
-
return Base.addressCache[
|
|
82
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
const address = this.getLegacyAddress(xpub, account, index);
|
|
86
|
-
Base.addressCache[
|
|
87
|
-
`${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
|
|
88
|
-
] = address;
|
|
89
|
-
return address;
|
|
62
|
+
return this.getLegacyAddress(xpub, account, index);
|
|
90
63
|
}
|
|
91
64
|
|
|
92
65
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -98,10 +71,23 @@ class Zen implements ICrypto {
|
|
|
98
71
|
if (!this.validateAddress(address)) {
|
|
99
72
|
throw new InvalidAddress();
|
|
100
73
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
74
|
+
let outputScript: Buffer;
|
|
75
|
+
const version = Number(
|
|
76
|
+
"0x" + bs58check.decode(address).slice(0, 2).toString("hex")
|
|
104
77
|
);
|
|
78
|
+
if (version === this.network.pubKeyHash) {
|
|
79
|
+
//Pay-to-PubkeyHash
|
|
80
|
+
outputScript = bjs.payments.p2pkh({
|
|
81
|
+
hash: bs58check.decode(address).slice(2),
|
|
82
|
+
}).output as Buffer;
|
|
83
|
+
} else if (version === this.network.scriptHash) {
|
|
84
|
+
//Pay-to-Script-Hash
|
|
85
|
+
outputScript = bjs.payments.p2sh({
|
|
86
|
+
hash: bs58check.decode(address).slice(2),
|
|
87
|
+
}).output as Buffer;
|
|
88
|
+
} else {
|
|
89
|
+
throw new InvalidAddress();
|
|
90
|
+
}
|
|
105
91
|
// refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/scripts/BitcoinLikeScript.cpp#L139 and https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/networks.cpp#L39 for bip115 Script and its network parameters
|
|
106
92
|
const bip115Script = Buffer.from(
|
|
107
93
|
"209ec9845acb02fab24e1c0368b3b517c1a4488fba97f0e3459ac053ea0100000003c01f02b4",
|
|
@@ -122,11 +108,6 @@ class Zen implements ICrypto {
|
|
|
122
108
|
(res[1] === 0x89 || res[1] === 0x96)
|
|
123
109
|
);
|
|
124
110
|
}
|
|
125
|
-
|
|
126
|
-
// eslint-disable-next-line
|
|
127
|
-
isTaprootAddress(address: string): boolean {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
111
|
}
|
|
131
112
|
|
|
132
113
|
export default Zen;
|
|
@@ -2,6 +2,7 @@ import invariant from "invariant";
|
|
|
2
2
|
import { Observable, from, of } from "rxjs";
|
|
3
3
|
import { mergeMap } from "rxjs/operators";
|
|
4
4
|
import eip55 from "eip55";
|
|
5
|
+
import { encode } from "rlp";
|
|
5
6
|
import { BigNumber } from "bignumber.js";
|
|
6
7
|
import { log } from "@ledgerhq/logs";
|
|
7
8
|
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
@@ -17,6 +18,7 @@ import { modes } from "./modules";
|
|
|
17
18
|
import { isNFTActive } from "../../nft";
|
|
18
19
|
import { getEnv } from "../../env";
|
|
19
20
|
import { LoadConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
21
|
+
import { Transaction as EthereumTx } from "@ethereumjs/tx";
|
|
20
22
|
export const signOperation = ({
|
|
21
23
|
account,
|
|
22
24
|
deviceId,
|
|
@@ -54,18 +56,16 @@ export const signOperation = ({
|
|
|
54
56
|
throw new FeeNotLoaded();
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
const { tx, fillTransactionDataResult } =
|
|
58
|
-
account,
|
|
59
|
-
|
|
60
|
-
nonce
|
|
61
|
-
);
|
|
62
|
-
const to = eip55.encode("0x" + tx.to.toString("hex"));
|
|
59
|
+
const { ethTxObject, tx, common, fillTransactionDataResult } =
|
|
60
|
+
buildEthereumTx(account, transaction, nonce);
|
|
61
|
+
const to = eip55.encode((tx.to || "").toString());
|
|
63
62
|
const value = new BigNumber(
|
|
64
63
|
"0x" + (tx.value.toString("hex") || "0")
|
|
65
64
|
);
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
65
|
+
// rawData Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
|
|
66
|
+
const rawData = tx.raw();
|
|
67
|
+
rawData[6] = Buffer.from([common.chainIdBN().toNumber()]);
|
|
68
|
+
const txHex = Buffer.from(encode(rawData)).toString("hex");
|
|
69
69
|
const loadConfig: LoadConfig = {};
|
|
70
70
|
if (isNFTActive(account.currency)) {
|
|
71
71
|
loadConfig.nftExplorerBaseURL =
|
|
@@ -106,26 +106,27 @@ export const signOperation = ({
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
o.next({
|
|
110
|
-
type: "device-signature-requested",
|
|
111
|
-
});
|
|
109
|
+
o.next({ type: "device-signature-requested" });
|
|
112
110
|
const result = await eth.signTransaction(
|
|
113
111
|
freshAddressPath,
|
|
114
112
|
txHex,
|
|
115
113
|
resolution
|
|
116
114
|
);
|
|
117
115
|
if (cancelled) return;
|
|
118
|
-
o.next({
|
|
119
|
-
type: "device-signature-granted",
|
|
120
|
-
});
|
|
116
|
+
o.next({ type: "device-signature-granted" });
|
|
121
117
|
// Second, we re-set some tx fields from the device signature
|
|
122
|
-
const v = result.v
|
|
118
|
+
const v = `0x${result.v}`;
|
|
119
|
+
const r = `0x${result.r}`;
|
|
120
|
+
const s = `0x${result.s}`;
|
|
121
|
+
|
|
122
|
+
const signedTx = new EthereumTx(
|
|
123
|
+
{ ...ethTxObject, v, r, s },
|
|
124
|
+
{ common }
|
|
125
|
+
);
|
|
123
126
|
|
|
124
|
-
tx.v = Buffer.from(v, "hex");
|
|
125
|
-
tx.r = Buffer.from(result.r, "hex");
|
|
126
|
-
tx.s = Buffer.from(result.s, "hex");
|
|
127
127
|
// Generate the signature ready to be broadcasted
|
|
128
|
-
const signature = `0x${
|
|
128
|
+
const signature = `0x${signedTx.serialize().toString("hex")}`;
|
|
129
|
+
|
|
129
130
|
// build optimistic operation
|
|
130
131
|
const txHash = ""; // resolved at broadcast time
|
|
131
132
|
|
|
@@ -118,7 +118,6 @@ const ethereum: AppSpec<Transaction> = {
|
|
|
118
118
|
appQuery: {
|
|
119
119
|
model: DeviceModelId.nanoS,
|
|
120
120
|
appName: "Ethereum",
|
|
121
|
-
appVersion: "1.5.0-rc3",
|
|
122
121
|
},
|
|
123
122
|
testTimeout: 4 * 60 * 1000,
|
|
124
123
|
transactionCheck: ({ maxSpendable }) => {
|
|
@@ -380,7 +379,6 @@ const ethereumRopsten: AppSpec<Transaction> = {
|
|
|
380
379
|
appQuery: {
|
|
381
380
|
model: DeviceModelId.nanoS,
|
|
382
381
|
appName: "Ethereum",
|
|
383
|
-
appVersion: "1.5.0-rc3",
|
|
384
382
|
},
|
|
385
383
|
testTimeout: 2 * 60 * 1000,
|
|
386
384
|
transactionCheck: ({ maxSpendable }) => {
|