scure-btc-signer: Custom Script Tapscript not working?

That’s probably my fault; Overall the library is way more straightforward and battery packed than other fragmented libraries, but I’m struggling to make a simple tapscript work (which seems pretty straightforward with bitcoinjs or cmd/tapscript, at the cost of fragmentation)…

I’m creating a tapscript with a custom script that will pay for another transaction on a meta protocol:

 const { publicKey } = getP2TRWallet()
  const taprootInternalKey = ecdsaPublicKeyToSchnorr(publicKey)
  const outputScript = btc.Script.encode([
    taprootInternalKey,
    btc.OP.CHECKSIG,
    btc.OP.OP_0,
    btc.OP.IF,
   randomId,
    btc.OP.ENDIF
  ])

  const taprootPayment = btc.p2tr(
    taprootInternalKey,
    [
      {
        script: outputScript,
        leafVersion: 192,
      }
    ],
    network,
    true
  )
  return taprootPayment

and then, I pay to taprootPayment.address. Of course. This work flawlessly, the problem only really happens when I create the transaction to spend from this tapscript, in which the input is:

tx.addInput({
  txid: hex.decode(utxo.txid),
  index: utxo.vout,
  witnessUtxo: {
    script: tapscriptCommitment.script,
    amount: BigInt(utxo.value)
  },
  ...tapscriptCommitment,
  sighashType: btc.SigHash.ALL,
  sequence: 0xfffffffd
})

And then I proceed to build the outputs etc, sign the transaction, and submit to the blockchain. ALL GOOD.

Except that the tapscript does not get embedded on the hex of the transaction, check here: https://mempool.space/testnet/tx/f8d7bf9143bb8f41f0934ee35791ae75ebe6ffa4bb23de3287b635ecd8d9eb8f (clicking on details, you can see that there’s no P2TR tapscript)

My best bet, is that I’m creating the custom script wrong in some manner. Still getting used to the library to consolidate on my own projects.

Would appreciate any help you can provide @paulmillr 🙏

About this issue

  • Original URL
  • State: open
  • Created 3 months ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

for example, see Example (fake) in ordinals.test.js. Docs would be coming after the feature is more stable. Custom scripts are there.

thank you Paul! keen to get ordinals/runes stuff through

the branch would be ready later this week: there would still be time before halving.