Skip to content

Commit 68e4f8c

Browse files
authored
Merge pull request #41 from BitGo/utxo_psbt2
fix(psbt): pass value to hashForSignature for fork support
2 parents d94d4a2 + 3a9e630 commit 68e4f8c

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

src/psbt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ function getHashForSig(inputIndex, input, cache, forValidate, sighashTypes) {
10221022
inputIndex,
10231023
meaningfulScript,
10241024
sighashType,
1025+
prevout.value,
10251026
);
10261027
}
10271028
return {

src/transaction.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export declare class Transaction<TNumber extends number | bigint = number> {
4444
* hashType, and then hashes the result.
4545
* This hash can then be used to sign the provided transaction input.
4646
*/
47-
hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number): Buffer;
47+
hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number, prevOutValue?: TNumber): Buffer;
4848
hashForWitnessV1(inIndex: number, prevOutScripts: Buffer[], values: TNumber[], hashType: number, leafHash?: Buffer, annex?: Buffer): Buffer;
4949
hashForWitnessV0(inIndex: number, prevOutScript: Buffer, value: TNumber, hashType: number): Buffer;
5050
getHash(forWitness?: boolean): Buffer;

src/transaction.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ class Transaction {
204204
* hashType, and then hashes the result.
205205
* This hash can then be used to sign the provided transaction input.
206206
*/
207-
hashForSignature(inIndex, prevOutScript, hashType) {
207+
hashForSignature(
208+
inIndex,
209+
prevOutScript,
210+
hashType,
211+
// @ts-expect-error Optional for override in forks
212+
prevOutValue,
213+
) {
208214
typeforce(
209215
types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number),
210216
arguments,

ts_src/psbt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ function getHashForSig(
13481348
inputIndex,
13491349
meaningfulScript,
13501350
sighashType,
1351+
prevout.value,
13511352
);
13521353
}
13531354

ts_src/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export class Transaction<TNumber extends number | bigint = number> {
285285
inIndex: number,
286286
prevOutScript: Buffer,
287287
hashType: number,
288+
// @ts-expect-error Optional for override in forks
289+
prevOutValue?: TNumber,
288290
): Buffer {
289291
typeforce(
290292
types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number),

0 commit comments

Comments
 (0)