Skip to content

Commit 483cccb

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): replace outputScripts with publicKeys in parsing functions
Update parseTransactionWithWalletKeys and verifyReplayProtectionSignature to use publicKeys instead of outputScripts for replay protection validation. This provides a cleaner API and better aligns with the key-based security model. Issue: BTC-2786 Co-authored-by: llm-git <[email protected]>
1 parent 6c16e60 commit 483cccb

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

packages/wasm-utxo/test/fixedScript/parseTransactionWithWalletKeys.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import * as utxolib from "@bitgo/utxo-lib";
33
import { fixedScriptWallet } from "../../js/index.js";
44
import { BitGoPsbt, InputScriptType } from "../../js/fixedScriptWallet/index.js";
55
import type { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
6+
import type { ECPair } from "../../js/index.js";
67
import {
78
loadPsbtFixture,
89
loadWalletKeysFromFixture,
910
getPsbtBuffer,
11+
loadReplayProtectionKeyFromFixture,
1012
type Fixture,
1113
} from "./fixtureUtil.js";
1214

@@ -36,12 +38,6 @@ function getOtherWalletKeys(): utxolib.bitgo.RootWalletKeys {
3638
}
3739

3840
describe("parseTransactionWithWalletKeys", function () {
39-
// Replay protection script that matches Rust tests
40-
const replayProtectionScript = Buffer.from(
41-
"a91420b37094d82a513451ff0ccd9db23aba05bc5ef387",
42-
"hex",
43-
);
44-
4541
const supportedNetworks = utxolib.getNetworkList().filter((network) => {
4642
return (
4743
utxolib.isMainnet(network) &&
@@ -60,13 +56,15 @@ describe("parseTransactionWithWalletKeys", function () {
6056
let fullsignedPsbtBytes: Buffer;
6157
let bitgoPsbt: BitGoPsbt;
6258
let rootWalletKeys: RootWalletKeys;
59+
let replayProtectionKey: ECPair;
6360
let fixture: Fixture;
6461

6562
before(function () {
6663
fixture = loadPsbtFixture(networkName, "fullsigned");
6764
fullsignedPsbtBytes = getPsbtBuffer(fixture);
6865
bitgoPsbt = fixedScriptWallet.BitGoPsbt.fromBytes(fullsignedPsbtBytes, networkName);
6966
rootWalletKeys = loadWalletKeysFromFixture(fixture);
67+
replayProtectionKey = loadReplayProtectionKeyFromFixture(fixture);
7068
});
7169

7270
it("should have matching unsigned transaction ID", function () {
@@ -80,7 +78,7 @@ describe("parseTransactionWithWalletKeys", function () {
8078

8179
it("should parse transaction and identify internal/external outputs", function () {
8280
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
83-
outputScripts: [replayProtectionScript],
81+
publicKeys: [replayProtectionKey],
8482
});
8583

8684
// Verify all inputs have addresses and values
@@ -147,7 +145,7 @@ describe("parseTransactionWithWalletKeys", function () {
147145

148146
it("should parse inputs with correct scriptType", function () {
149147
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
150-
outputScripts: [replayProtectionScript],
148+
publicKeys: [replayProtectionKey],
151149
});
152150

153151
// Verify all inputs have scriptType matching fixture
@@ -166,7 +164,7 @@ describe("parseTransactionWithWalletKeys", function () {
166164
assert.throws(
167165
() => {
168166
bitgoPsbt.parseTransactionWithWalletKeys(getOtherWalletKeys(), {
169-
outputScripts: [replayProtectionScript],
167+
publicKeys: [replayProtectionKey],
170168
});
171169
},
172170
(error: Error) => {

packages/wasm-utxo/test/fixedScript/verifySignature.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ function verifyInputSignatures(
7070
): void {
7171
// Handle replay protection inputs (P2shP2pk)
7272
if ("hasReplayProtectionSignature" in expectedSignatures) {
73-
const replayProtectionScript = Buffer.from(
74-
"a91420b37094d82a513451ff0ccd9db23aba05bc5ef387",
75-
"hex",
76-
);
7773
const hasReplaySig = bitgoPsbt.verifyReplayProtectionSignature(inputIndex, {
78-
outputScripts: [replayProtectionScript],
74+
publicKeys: [replayProtectionKey],
7975
});
8076
assert.strictEqual(
8177
hasReplaySig,
@@ -127,19 +123,17 @@ function verifyInputSignatures(
127123
* @param fixture - The test fixture containing input metadata
128124
* @param rootWalletKeys - Wallet keys for verification
129125
* @param replayProtectionKey - Key for replay protection inputs
130-
* @param replayProtectionScript - Script for replay protection inputs
131126
* @param signatureStage - The signing stage (unsigned, halfsigned, fullsigned)
132127
*/
133128
function verifyAllInputSignatures(
134129
bitgoPsbt: BitGoPsbt,
135130
fixture: Fixture,
136131
rootWalletKeys: RootWalletKeys,
137132
replayProtectionKey: ECPair,
138-
replayProtectionScript: Uint8Array,
139133
signatureStage: SignatureStage,
140134
): void {
141135
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
142-
outputScripts: [replayProtectionScript],
136+
publicKeys: [replayProtectionKey],
143137
});
144138

145139
fixture.psbtInputs.forEach((input, index) => {
@@ -178,18 +172,13 @@ describe("verifySignature", function () {
178172
let unsignedBitgoPsbt: BitGoPsbt;
179173
let halfsignedBitgoPsbt: BitGoPsbt;
180174
let fullsignedBitgoPsbt: BitGoPsbt;
181-
let replayProtectionScript: Uint8Array;
182175

183176
before(function () {
184177
unsignedFixture = loadPsbtFixture(networkName, "unsigned");
185178
halfsignedFixture = loadPsbtFixture(networkName, "halfsigned");
186179
fullsignedFixture = loadPsbtFixture(networkName, "fullsigned");
187180
rootWalletKeys = loadWalletKeysFromFixture(fullsignedFixture);
188181
replayProtectionKey = loadReplayProtectionKeyFromFixture(fullsignedFixture);
189-
replayProtectionScript = Buffer.from(
190-
"a91420b37094d82a513451ff0ccd9db23aba05bc5ef387",
191-
"hex",
192-
);
193182
unsignedBitgoPsbt = fixedScriptWallet.BitGoPsbt.fromBytes(
194183
getPsbtBuffer(unsignedFixture),
195184
networkName,
@@ -211,7 +200,6 @@ describe("verifySignature", function () {
211200
unsignedFixture,
212201
rootWalletKeys,
213202
replayProtectionKey,
214-
replayProtectionScript,
215203
"unsigned",
216204
);
217205
});
@@ -224,7 +212,6 @@ describe("verifySignature", function () {
224212
halfsignedFixture,
225213
rootWalletKeys,
226214
replayProtectionKey,
227-
replayProtectionScript,
228215
"halfsigned",
229216
);
230217
});
@@ -237,7 +224,6 @@ describe("verifySignature", function () {
237224
fullsignedFixture,
238225
rootWalletKeys,
239226
replayProtectionKey,
240-
replayProtectionScript,
241227
"fullsigned",
242228
);
243229
});

0 commit comments

Comments
 (0)