Skip to content

Commit

Permalink
Remove sighash types from sign options (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorkirov authored Sep 27, 2024
1 parent d602c9a commit 33ce28e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 7 additions & 5 deletions transactions/bitcoin/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { areByteArraysEqual } from './utils';

export type SignOptions = {
ledgerTransport?: Transport;
allowedSigHash?: btc.SigHash[];
inputsToSign?: InputToSign[];
};

Expand Down Expand Up @@ -192,8 +191,12 @@ export abstract class AddressContext {
if (signIndexes[index]) {
throw new Error(`Duplicate signing index ${index} for address ${this._address}`);
}
const input = transaction.getInput(index);

signIndexes[index] = inputToSign.sigHash ? [inputToSign.sigHash] : undefined;
signIndexes[index] = undefined;
if (input.sighashType !== undefined) {
signIndexes[index] = [input.sighashType];
}
});
}
}
Expand All @@ -210,9 +213,8 @@ export abstract class AddressContext {
const matchesNonWitnessUtxo = areByteArraysEqual(nonWitnessLockingScript, witnessScript);

if (matchesWitnessUtxo || matchesNonWitnessUtxo) {
signIndexes[i] = options.allowedSigHash;

if (options.allowedSigHash === undefined && input.sighashType !== undefined) {
signIndexes[i] = undefined;
if (input.sighashType !== undefined) {
signIndexes[i] = [input.sighashType];
}
}
Expand Down
8 changes: 4 additions & 4 deletions transactions/bitcoin/enhancedPsbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class EnhancedPsbt {
private readonly _inputsToSign?: InputToSign[];

// TODO: Try and make this non-nullable by computing it in the constructor
private readonly _inputsToSignMap?: Record<number, { address: string; sigHash?: number }[]>;
private readonly _inputsToSignMap?: Record<number, { address: string }[]>;

private readonly _isSigHashAll?: boolean;

Expand All @@ -65,10 +65,10 @@ export class EnhancedPsbt {
this._inputsToSignMap[inputIndex] = [];
}

this._inputsToSignMap[inputIndex].push({ address: input.address, sigHash: input.sigHash });
this._inputsToSignMap[inputIndex].push({ address: input.address });

const txnInput = txn.getInput(inputIndex);
const sigHashToCheck = txnInput.sighashType ?? input.sigHash ?? btc.SigHash.DEFAULT;
const sigHashToCheck = txnInput.sighashType ?? btc.SigHash.DEFAULT;

// we need to do check for single first as it's value is 3 while none is 2 and all is 1
if ((sigHashToCheck & btc.SigHash.SINGLE) === btc.SigHash.SINGLE) {
Expand Down Expand Up @@ -195,7 +195,7 @@ export class EnhancedPsbt {
throw new Error(`Could not parse input ${inputIndex}`);
}

const sigHash = this._inputsToSignMap?.[inputIndex]?.[0]?.sigHash ?? inputRaw.sighashType;
const sigHash = inputRaw.sighashType;
inputs.push({
extendedUtxo: inputExtendedUtxo,
sigHash,
Expand Down
1 change: 0 additions & 1 deletion transactions/bitcoin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export type TransactionSummary = {
export type PSBTCompilationOptions = {
ledgerTransport?: Transport;
finalize?: boolean;
allowedSigHash?: btc.SigHash[];
};

export type IOInscription = {
Expand Down

0 comments on commit 33ce28e

Please sign in to comment.