Skip to content

Commit 8710cc5

Browse files
davidkaplanbitgollm-git
andcommitted
fix(utxo-lib): restore PSBT cache values after signing non-segwit
Preserve original cache values in withUnsafeNonSegwit instead of hardcoding the restored values. Issue: BTC-2286 Co-authored-by: llm-git <[email protected]>
1 parent 4628408 commit 8710cc5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/utxo-lib/src/bitgo/PsbtUtil.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ export function toPsbtBuffer(data: Buffer | string): Buffer {
133133
* This function allows signing or validating a psbt with non-segwit inputs those do not contain nonWitnessUtxo.
134134
*/
135135
export function withUnsafeNonSegwit<T>(psbt: Psbt, fn: () => T, unsafe = true): T {
136+
const prevValue = (psbt as any).__CACHE.__UNSAFE_SIGN_NONSEGWIT;
137+
const prevValueWarn = (psbt as any).__CACHE.__WARN_UNSAFE_SIGN_NONSEGWIT;
136138
(psbt as any).__CACHE.__UNSAFE_SIGN_NONSEGWIT = unsafe;
137139
(psbt as any).__CACHE.__WARN_UNSAFE_SIGN_NONSEGWIT = !unsafe;
138140
try {
139141
return fn();
140142
} finally {
141-
(psbt as any).__CACHE.__UNSAFE_SIGN_NONSEGWIT = false;
142-
(psbt as any).__CACHE.__WARN_UNSAFE_SIGN_NONSEGWIT = true;
143+
(psbt as any).__CACHE.__UNSAFE_SIGN_NONSEGWIT = prevValue;
144+
(psbt as any).__CACHE.__WARN_UNSAFE_SIGN_NONSEGWIT = prevValueWarn;
143145
}
144146
}

0 commit comments

Comments
 (0)