unisat-wallet / dev-support

14 stars 11 forks source link

sign a witness utxo in psbt but cant get the signature on the decoded input after signing #34

Open cloud6605 opened 1 month ago

cloud6605 commented 1 month ago

image

cloud6605 commented 1 month ago

image

cloud6605 commented 1 month ago

image

huanniangstudio commented 1 month ago

If the inputs of the transaction you are signing do not include your current wallet address, it cannot be signed. In this case, if you still want to sign, you need to manually input the toSignInputs parameter.

You can try using the toSignInputs parameter to specify your signing inputs. If there are still problems, please post the full signing code as below.

unisat.signPsbt("xxx",{...})

ALDO2124 commented 1 month ago

@huanniangstudio, thank you for the response, yes , i have the wallet address in the option at index 1 Screenshot 2024-06-02 174318 where address is the btc wallet address from unisat context i get the popup to sign Screenshot 2024-06-02 174915 but the hash thats returned after i click sign does not have the sign so cannot finalize the psbt which i need to do to brodcast any help on this would be appreciated

huanniangstudio commented 1 month ago

When the autoFinalized parameter is true, it will finalize the PSBT operation before returning. After this, you cannot finalize it twice.

You could set it to false to try again.

ALDO2124 commented 1 month ago

Ahh ok, so it should returned the hex for the finalized psbt right but in my case when i converted from hex to bitcoin.psbt, it had no signature so could not broadcast it

huanniangstudio commented 1 month ago

This could be an issue somewhere in the code, a reproducible code example is needed.

ALDO2124 commented 1 month ago

i tried let sign = await unisat.signPsbt(basePsbt.toHex(), { autoFinalized:true, toSignInputs:[ { index: 1, address:address, } ] })

let push = await unisat.pushPsbt(sign)

and let sign = await unisat.signPsbt(basePsbt.toHex(), { autoFinalized:false, toSignInputs:[ { index: 1, address:address, } ] }) let signedpsbt = bitcoin.Psbt.fromHex(sign) signedpsbt.finalizeAllInputs() let push = await unisat.pushPsbt(signedpsbt.toHex())

huanniangstudio commented 1 month ago

Your code should be able to sign the index 1, but it may indeed not sign the index 0. Are you sure you have already signed it in advance?

ALDO2124 commented 1 month ago

ahh yes, sorry forgot to provide you the full context i have 3 signiners that sign the psbt, then i combine the psbts which is the basePsbt in the signPsbt function then since input 0 is the 3 signers combined and input 1 is the psbt that my wallet will sign so assigned input 1 and address as my wallet address, so tldr would be that index 0 is a combined signed psbt from 3 other wallets, and input 1 is to be signed by me
reason the other 3 are for validation and the input 1 will be the gas provider for the transaction

huanniangstudio commented 1 month ago
let sign = await unisat.signPsbt(basePsbt.toHex(), { autoFinalized:false, toSignInputs:[ { index: 1, address:address, } ] })
 let signedpsbt = bitcoin.Psbt.fromHex(sign)
console.log(signedpsbt.data.inputs[1])

When you execute the above code and get the content as below, it indicates that the signature is successful.

{
  witnessUtxo: {
    script: <Buffer 00 14 b0 f2 ef.....>,
    value: 51784
  },
  partialSig: [
    {
      pubkey: <Buffer 02 b3 e9 e3....more bytes>,
      signature: <Buffer 30 44 0 ... 21 more bytes>
    }
  ]
}
ALDO2124 commented 1 month ago

yes that is the expected outcome but on mine i do not get the partialSig Screenshot 2024-06-02 224930

ALDO2124 commented 3 weeks ago

@huanniangstudio , if you need more info this is the psbt im trying to sign , its a combined psbt of a base psbt and signed psbt from 3 other multisig wallets 70736274ff01009a0100000002499454d809142f631179ae756213a29f709b27f0b807c66a11de4f93e874e1220000000000fdffffff974fa52949026050e485497bc6b1900b2d1ac11de44456cfcbda859d5337bb5d0100000000fdffffff0222020000000000001600144f4ea0253cc4b08cc02f3591c1fdcf6dfc2d0199e2c30000000000001600144f4ea0253cc4b08cc02f3591c1fdcf6dfc2d0199a2e60c000001012b22020000000000002251205d2ebd13886c80ca4ef254fffc8ab4ce3527c630cad35d751b6c2533bb5633780103048300000041147032d63a356a821804b204bc6fb6f768e160fefb36888edad296ab9f0ad88a33db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c41b3105778198979c803a22a1c82139ce83e29393a110804b78e02e14a6bacca4ceb93097299bdf52827611e45eb501dbb82825feaaf2455c16e55b9067f6f7c6583411493f448b315936fe3d38610fd61f15f893c3d8af8dc4dbaeacb35093f827e5820db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c413323735d7847be06c1b1887a2d112534517c41a603b4362c75a052b12fe6fbc6832b2f3bebba87ad1c5dc0d78324fcc477b183a5a4250bd5d6d67195934f98208341149469e94e617fb421b9298feeb0d3f7e901948b536803bde97da7752fe90c95e0db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c41f64916a217d7935b6903eba8b15efe65c38bea5f24a9b7fb1fa4a639c3f1a72dd7650fb99a24817b8cb1c69a6e92cec2d91dcd93c207c945b36c8662597dff4a832215c1020202020202020202020202020202020202020202020202020202020202020269207032d63a356a821804b204bc6fb6f768e160fefb36888edad296ab9f0ad88a33ac209469e94e617fb421b9298feeb0d3f7e901948b536803bde97da7752fe90c95e0ba2093f448b315936fe3d38610fd61f15f893c3d8af8dc4dbaeacb35093f827e5820ba529cc021160202020202020202020202020202020202020202020202020202020202020202050051814f1021167032d63a356a821804b204bc6fb6f768e160fefb36888edad296ab9f0ad88a332501db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c1ce91543211693f448b315936fe3d38610fd61f15f893c3d8af8dc4dbaeacb35093f827e58202501db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c381ea5e121169469e94e617fb421b9298feeb0d3f7e901948b536803bde97da7752fe90c95e02501db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969cd8b768770117200202020202020202020202020202020202020202020202020202020202020202011820db84236e776b1b073fd55ffdfb225335ff8b5935945a4ada1e01b1eefd11969c0001012b48ca000000000000225120dbaf82a5f3367f2a00d2d33c7acf7bf8301ce9bd6bd8283ff518bce0e8916c75000000

ALDO2124 commented 3 weeks ago

i get the data as [ { "psbt": "", "signed_psbts": [ { "pub_key": "", "signed_psbt": "" } ] } ] and i signed using ` const psbtInfo: psbtReturn[] = await req.json() const signedPsbts = psbtInfo[0].signed_psbts.map(item => item.signed_psbt);

  const unisat = (window as any).unisat;
  let basePsbt = bitcoin.Psbt.fromBase64(psbtInfo[0].psbt);
  signedPsbts.forEach(signedPsbtData => {
    const signedPsbt = bitcoin.Psbt.fromBase64(signedPsbtData);
    basePsbt.combine(signedPsbt);
  });
  let sign = await unisat.signPsbt(basePsbt.toHex(),
  {
    autoFinalized:true,
    toSignInputs:[
      {
        index: 1,
        address:address,
      }
    ],
})`