@exodus/hw-ledger 2.3.0 → 2.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
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
|
+
## [2.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@2.3.0...@exodus/hw-ledger@2.3.1) (2024-02-13)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- add dummy inputs when signing psbt on ledger ([#5680](https://github.com/ExodusMovement/exodus-hydra/issues/5680)) ([b11c6c6](https://github.com/ExodusMovement/exodus-hydra/commit/b11c6c67db196d7b970ded3228e7482ff1881c57))
|
|
11
|
+
|
|
6
12
|
## [2.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@2.2.6...@exodus/hw-ledger@2.3.0) (2024-02-08)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -3,7 +3,7 @@ import { AppClient, PsbtV2 } from '@exodus/ledger-bitcoin';
|
|
|
3
3
|
import { BIP322 } from '@exodus/bip322-js';
|
|
4
4
|
import { splitBip44DerivationPath } from './utils';
|
|
5
5
|
import assert from 'minimalistic-assert';
|
|
6
|
-
import { assertPsbtOnlyHasAllowedDerivationPaths, tagPsbtWithDerivationPaths, getWalletPolicy, derivationPathsToWalletPolicy, } from './utils/psbt';
|
|
6
|
+
import { assertPsbtOnlyHasAllowedDerivationPaths, tagPsbtWithDerivationPaths, getWalletPolicy, derivationPathsToWalletPolicy, addDummyInputs, } from './utils/psbt';
|
|
7
7
|
import { buildBip322PSBT } from './utils/bip322';
|
|
8
8
|
async function createHandler(transport) {
|
|
9
9
|
const app = new AppClient(transport);
|
|
@@ -34,6 +34,7 @@ async function createHandler(transport) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
tagPsbtWithDerivationPaths(psbt, fpr, derivationPathToPublicKeyMap);
|
|
37
|
+
addDummyInputs(psbt);
|
|
37
38
|
assertPsbtOnlyHasAllowedDerivationPaths(psbt, fpr, params.derivationPaths);
|
|
38
39
|
const signatures = [];
|
|
39
40
|
const walletPolicies = await derivationPathsToWalletPolicy(fpr, app, params.derivationPaths);
|
|
@@ -4,3 +4,4 @@ export declare function assertPsbtOnlyHasAllowedDerivationPaths(psbt: PsbtV2, ma
|
|
|
4
4
|
export declare function tagPsbtWithDerivationPaths(psbt: PsbtV2, masterFingerprint: string, derivationPathToPublicKeyMap: Record<string, Buffer>): void;
|
|
5
5
|
export declare const getWalletPolicy: (fpr: string, xpub: string, purpose: string, coin: string, account: string) => DefaultWalletPolicy;
|
|
6
6
|
export declare function derivationPathsToWalletPolicy(fpr: string, app: any, derivationPaths: string[]): Promise<WalletPolicy[]>;
|
|
7
|
+
export declare function addDummyInputs(psbt: PsbtV2): void;
|
|
@@ -119,3 +119,40 @@ export async function derivationPathsToWalletPolicy(fpr, app, derivationPaths) {
|
|
|
119
119
|
}
|
|
120
120
|
return walletPolicies;
|
|
121
121
|
}
|
|
122
|
+
function canModifyInputs(psbt) {
|
|
123
|
+
const SIGHASH_ALL = 0x01;
|
|
124
|
+
const SIGHASH_NONE = 0x02;
|
|
125
|
+
const SIGHASH_SINGLE = 0x03;
|
|
126
|
+
for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
|
|
127
|
+
if ([SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, undefined].includes(psbt.getInputSighashType(i))) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
export function addDummyInputs(psbt) {
|
|
134
|
+
const canAddDummy = canModifyInputs(psbt);
|
|
135
|
+
if (!canAddDummy) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let outputAmount = 0;
|
|
139
|
+
for (let i = 0; i < psbt.getGlobalOutputCount(); i++) {
|
|
140
|
+
outputAmount += psbt.getOutputAmount(i);
|
|
141
|
+
}
|
|
142
|
+
let inputAmount = 0;
|
|
143
|
+
for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
|
|
144
|
+
const witnessUtxo = psbt.getInputWitnessUtxo(i);
|
|
145
|
+
if (witnessUtxo) {
|
|
146
|
+
inputAmount += witnessUtxo.amount;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (outputAmount > inputAmount) {
|
|
150
|
+
const newInputIndex = psbt.getGlobalInputCount();
|
|
151
|
+
const amount = outputAmount - inputAmount;
|
|
152
|
+
psbt.setGlobalInputCount(newInputIndex + 1);
|
|
153
|
+
const FIRST_BITCOIN_TXID = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
|
|
154
|
+
psbt.setInputPreviousTxId(newInputIndex, Buffer.from(FIRST_BITCOIN_TXID, 'hex'));
|
|
155
|
+
psbt.setInputOutputIndex(newInputIndex, 0);
|
|
156
|
+
psbt.setInputWitnessUtxo(newInputIndex, amount, Buffer.from('01', 'hex'));
|
|
157
|
+
}
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/hw-ledger",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "The ledger module",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"repository": {
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"ts-jest": "^29.0.3",
|
|
69
69
|
"typescript": "^4.7.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "fac836c7ae4dbf64c3df293db1fb34b632400a02"
|
|
72
72
|
}
|