unisat-wallet / dev-support

35 stars 18 forks source link

sign message using schnor signatures from unisat wallet #75

Open cloud6605 opened 2 months ago

cloud6605 commented 2 months ago

Hi, is there a way to sign message using schnor signatures from unisat wallet? I've looking for a way to, given "message": string -> return schnorr signature signed by user's private key. image

slient-coder commented 2 months ago

When do you need to use sign message using schnorr signatures? The signPsbt method can sign a P2TR transaction using the schnorr method.

bombnp commented 2 months ago

When do you need to use sign message using schnorr signatures? The signPsbt method can sign a P2TR transaction using the schnorr method.

Hi @slient-coder. I'm the one who submitted this issue.

I'm building a dApp for interfacing with CAT20 protocol. There's a logic in CAT20 smart contract lib that requires signing a custom sighash with user's tweaked private key and return the schnorr signature to use in the smart contract state verification. I'm not trying to sign a transaction to be broadcasted.

I tried to see if I can use signPsbt() and extract the signature from the witness, but it does not work for me because:

  1. I need to sign a custom sighash. I can't control sighash in signPsbt(), but I can control what is signed in signMessage.
  2. There are a lot of checks in signTaprootInput() function in bitcoinjs-lib used by your extension, which prevents me from signing it if some conditions are invalid (prevout public key does not match signing public key, tapleaf hash does not contain signing public key, etc.).

I looked around other wallets and none of them supports signing message as schnorr signature too. If you implement this, you would be the first wallet to support complex CAT20 operations that requires schnorr signatures from user's private key.