@@ -121,6 +121,39 @@ function verifyInputSignatures(
121121 ) ;
122122}
123123
124+ /**
125+ * Helper to verify signatures for all inputs in a PSBT
126+ * @param bitgoPsbt - The PSBT to verify
127+ * @param fixture - The test fixture containing input metadata
128+ * @param rootWalletKeys - Wallet keys for verification
129+ * @param replayProtectionKey - Key for replay protection inputs
130+ * @param replayProtectionScript - Script for replay protection inputs
131+ * @param signatureStage - The signing stage (unsigned, halfsigned, fullsigned)
132+ */
133+ function verifyAllInputSignatures (
134+ bitgoPsbt : BitGoPsbt ,
135+ fixture : Fixture ,
136+ rootWalletKeys : RootWalletKeys ,
137+ replayProtectionKey : ECPair ,
138+ replayProtectionScript : Uint8Array ,
139+ signatureStage : SignatureStage ,
140+ ) : void {
141+ const parsed = bitgoPsbt . parseTransactionWithWalletKeys ( rootWalletKeys , {
142+ outputScripts : [ replayProtectionScript ] ,
143+ } ) ;
144+
145+ fixture . psbtInputs . forEach ( ( input , index ) => {
146+ verifyInputSignatures (
147+ bitgoPsbt ,
148+ parsed ,
149+ rootWalletKeys ,
150+ replayProtectionKey ,
151+ index ,
152+ getExpectedSignatures ( input . type , signatureStage ) ,
153+ ) ;
154+ } ) ;
155+ }
156+
124157describe ( "verifySignature" , function ( ) {
125158 const supportedNetworks = utxolib . getNetworkList ( ) . filter ( ( network ) => {
126159 return (
@@ -173,57 +206,40 @@ describe("verifySignature", function () {
173206
174207 describe ( "unsigned PSBT" , function ( ) {
175208 it ( "should return false for unsigned inputs" , function ( ) {
176- const parsed = unsignedBitgoPsbt . parseTransactionWithWalletKeys ( rootWalletKeys , {
177- outputScripts : [ replayProtectionScript ] ,
178- } ) ;
179- // Verify all xpubs return false for all inputs
180- unsignedFixture . psbtInputs . forEach ( ( input , index ) => {
181- verifyInputSignatures (
182- unsignedBitgoPsbt ,
183- parsed ,
184- rootWalletKeys ,
185- replayProtectionKey ,
186- index ,
187- getExpectedSignatures ( input . type , "unsigned" ) ,
188- ) ;
189- } ) ;
209+ verifyAllInputSignatures (
210+ unsignedBitgoPsbt ,
211+ unsignedFixture ,
212+ rootWalletKeys ,
213+ replayProtectionKey ,
214+ replayProtectionScript ,
215+ "unsigned" ,
216+ ) ;
190217 } ) ;
191218 } ) ;
192219
193220 describe ( "half-signed PSBT" , function ( ) {
194221 it ( "should return true for signed xpubs and false for unsigned" , function ( ) {
195- const parsed = halfsignedBitgoPsbt . parseTransactionWithWalletKeys ( rootWalletKeys , {
196- outputScripts : [ replayProtectionScript ] ,
197- } ) ;
198- halfsignedFixture . psbtInputs . forEach ( ( input , index ) => {
199- verifyInputSignatures (
200- halfsignedBitgoPsbt ,
201- parsed ,
202- rootWalletKeys ,
203- replayProtectionKey ,
204- index ,
205- getExpectedSignatures ( input . type , "halfsigned" ) ,
206- ) ;
207- } ) ;
222+ verifyAllInputSignatures (
223+ halfsignedBitgoPsbt ,
224+ halfsignedFixture ,
225+ rootWalletKeys ,
226+ replayProtectionKey ,
227+ replayProtectionScript ,
228+ "halfsigned" ,
229+ ) ;
208230 } ) ;
209231 } ) ;
210232
211233 describe ( "fully signed PSBT" , function ( ) {
212234 it ( "should have 2 signatures (2-of-3 multisig)" , function ( ) {
213- // In fullsigned fixtures, verify 2 signatures exist per multisig input
214- const parsed = fullsignedBitgoPsbt . parseTransactionWithWalletKeys ( rootWalletKeys , {
215- outputScripts : [ replayProtectionScript ] ,
216- } ) ;
217- fullsignedFixture . psbtInputs . forEach ( ( input , index ) => {
218- verifyInputSignatures (
219- fullsignedBitgoPsbt ,
220- parsed ,
221- rootWalletKeys ,
222- replayProtectionKey ,
223- index ,
224- getExpectedSignatures ( input . type , "fullsigned" ) ,
225- ) ;
226- } ) ;
235+ verifyAllInputSignatures (
236+ fullsignedBitgoPsbt ,
237+ fullsignedFixture ,
238+ rootWalletKeys ,
239+ replayProtectionKey ,
240+ replayProtectionScript ,
241+ "fullsigned" ,
242+ ) ;
227243 } ) ;
228244 } ) ;
229245
0 commit comments