@exodus/hw-ledger 3.3.0 → 3.3.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/CHANGELOG.md +6 -0
- package/lib/module/assets/utils/psbt.js +46 -19
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.3.0...@exodus/hw-ledger@3.3.1) (2024-10-24)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- support legacy transaction signing ([#10154](https://github.com/ExodusMovement/exodus-hydra/issues/10154)) ([55c3d63](https://github.com/ExodusMovement/exodus-hydra/commit/55c3d63e809397b94aa08309b03715fe6d0ed831))
|
|
11
|
+
|
|
6
12
|
## [3.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.2.0...@exodus/hw-ledger@3.3.0) (2024-10-22)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert';
|
|
2
2
|
import { DefaultWalletPolicy, WalletPolicy } from '@exodus/ledger-bitcoin';
|
|
3
|
-
import { payments, address as baddress } from '@exodus/bitcoinjs';
|
|
3
|
+
import { payments, address as baddress, Transaction } from '@exodus/bitcoinjs';
|
|
4
4
|
import { buildBip44PathFromNumber, assertBip44PathNumber, splitBip44PathToNumber, splitBip44DerivationPath, } from './derivation-paths';
|
|
5
5
|
export function assertPsbtOnlyHasAllowedDerivationPaths(psbt, masterFingerprint, derivationPaths) {
|
|
6
6
|
for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
|
|
@@ -36,12 +36,23 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
36
36
|
const scriptPubKeyToDerivationPathMap = computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap);
|
|
37
37
|
for (let inputIndex = 0; inputIndex < psbt.getGlobalInputCount(); inputIndex++) {
|
|
38
38
|
const witnessUtxo = psbt.getInputWitnessUtxo(inputIndex);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const nonWitnessUtxo = psbt.getInputNonWitnessUtxo(inputIndex);
|
|
40
|
+
let scriptPubKey;
|
|
41
|
+
if (witnessUtxo) {
|
|
42
|
+
scriptPubKey = witnessUtxo.scriptPubKey;
|
|
43
|
+
}
|
|
44
|
+
else if (nonWitnessUtxo) {
|
|
45
|
+
const prevOutputIndex = psbt.getInputOutputIndex(inputIndex);
|
|
46
|
+
const decodedTransaction = Transaction.fromBuffer(nonWitnessUtxo);
|
|
47
|
+
scriptPubKey = decodedTransaction.outs[prevOutputIndex].script;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error('missing witnessUtxo or nonWitnessUtxo');
|
|
51
|
+
}
|
|
52
|
+
let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey.toString('hex')];
|
|
42
53
|
if (addressToDerivationPathMap && !derivationPath) {
|
|
43
54
|
try {
|
|
44
|
-
const address = baddress.fromOutputScript(
|
|
55
|
+
const address = baddress.fromOutputScript(scriptPubKey);
|
|
45
56
|
derivationPath = addressToDerivationPathMap[address];
|
|
46
57
|
}
|
|
47
58
|
catch { }
|
|
@@ -50,7 +61,7 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
50
61
|
const publicKey = derivationPathToPublicKeyMap[derivationPath];
|
|
51
62
|
assert(Buffer.isBuffer(publicKey), `no public key found for derivation path`);
|
|
52
63
|
const derivationPathNumerical = splitBip44PathToNumber(derivationPath);
|
|
53
|
-
if (isTaproot(
|
|
64
|
+
if (isTaproot(scriptPubKey)) {
|
|
54
65
|
psbt.setInputTapBip32Derivation(inputIndex, publicKey.slice(1), [], masterFingerprintBuffer, derivationPathNumerical);
|
|
55
66
|
}
|
|
56
67
|
else {
|
|
@@ -83,25 +94,41 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
|
|
|
83
94
|
}
|
|
84
95
|
function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
|
|
85
96
|
return Object.entries(derivationPathToPublicKeyMap).reduce((acc, [derivationPath, publicKey]) => {
|
|
86
|
-
if (derivationPath.startsWith('m/
|
|
87
|
-
const
|
|
97
|
+
if (derivationPath.startsWith('m/44')) {
|
|
98
|
+
const p2pkh = payments.p2pkh({
|
|
88
99
|
pubkey: publicKey,
|
|
89
100
|
}).output;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
assert(p2pkh, 'failed to compute p2pkh scriptPubKey');
|
|
102
|
+
Object.assign(acc, {
|
|
103
|
+
[p2pkh.toString('hex')]: derivationPath,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (derivationPath.startsWith('m/49')) {
|
|
107
|
+
const nestedSegwit = payments.p2sh({
|
|
108
|
+
redeem: payments.p2wpkh({ pubkey: publicKey }),
|
|
109
|
+
}).output;
|
|
110
|
+
assert(nestedSegwit, 'failed to compute p2pkh scriptPubKey');
|
|
111
|
+
Object.assign(acc, {
|
|
112
|
+
[nestedSegwit.toString('hex')]: derivationPath,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else if (derivationPath.startsWith('m/84')) {
|
|
116
|
+
const p2wpkh = payments.p2wpkh({
|
|
117
|
+
pubkey: publicKey,
|
|
118
|
+
}).output;
|
|
119
|
+
assert(p2wpkh, 'failed to compute p2wpkh scriptPubKey');
|
|
120
|
+
Object.assign(acc, {
|
|
121
|
+
[p2wpkh.toString('hex')]: derivationPath,
|
|
122
|
+
});
|
|
95
123
|
}
|
|
96
124
|
else if (derivationPath.startsWith('m/86')) {
|
|
97
|
-
const
|
|
125
|
+
const p2tr = payments.p2tr({
|
|
98
126
|
internalPubkey: publicKey.slice(1),
|
|
99
127
|
}).output;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
128
|
+
assert(p2tr, 'failed to compute p2tr scriptPubKey');
|
|
129
|
+
Object.assign(acc, {
|
|
130
|
+
[p2tr.toString('hex')]: derivationPath,
|
|
131
|
+
});
|
|
105
132
|
}
|
|
106
133
|
return acc;
|
|
107
134
|
}, Object.create(null));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/hw-ledger",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "The ledger module",
|
|
5
5
|
"author": "Exodus Movement, Inc.",
|
|
6
6
|
"repository": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"redux": "^4.2.1",
|
|
65
65
|
"tiny-secp256k1": "^2.2.3"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "75c0ccc137017dbd6fea08e2c42f6b46e2e85f9c"
|
|
68
68
|
}
|