11package test
22
33import (
4+ "bytes"
45 "context"
56 "errors"
67 "fmt"
@@ -246,6 +247,25 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
246247 return nil , 0 , nil , nil
247248}
248249
250+ // finalScriptWitness is a sample signature suitable to put into PSBT.
251+ var finalScriptWitness = func () []byte {
252+ const pver = 0
253+ var buf bytes.Buffer
254+
255+ // Write the number of witness elements.
256+ if err := wire .WriteVarInt (& buf , pver , 1 ); err != nil {
257+ panic (err )
258+ }
259+
260+ // Write a single witness element with a signature.
261+ signature := make ([]byte , 64 )
262+ if err := wire .WriteVarBytes (& buf , pver , signature ); err != nil {
263+ panic (err )
264+ }
265+
266+ return buf .Bytes ()
267+ }()
268+
249269// SignPsbt expects a partial transaction with all inputs and outputs
250270// fully declared and tries to sign all unsigned inputs that have all
251271// required fields (UTXO information, BIP32 derivation information,
@@ -258,9 +278,19 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
258278// locking or input/output/fee value validation, PSBT finalization). Any
259279// input that is incomplete will be skipped.
260280func (m * mockWalletKit ) SignPsbt (_ context.Context ,
261- _ * psbt.Packet ) (* psbt.Packet , error ) {
281+ packet * psbt.Packet ) (* psbt.Packet , error ) {
262282
263- return nil , nil
283+ inputs := make ([]psbt.PInput , len (packet .Inputs ))
284+ copy (inputs , packet .Inputs )
285+
286+ for i := range inputs {
287+ inputs [i ].FinalScriptWitness = finalScriptWitness
288+ }
289+
290+ signedPacket := * packet
291+ signedPacket .Inputs = inputs
292+
293+ return & signedPacket , nil
264294}
265295
266296// FinalizePsbt expects a partial transaction with all inputs and
0 commit comments