Git Product home page Git Product logo

Comments (6)

cmdruid avatar cmdruid commented on July 28, 2024

I think you have the wrong idea with what you are doing with const tweakKey = Tap.tweak.getPubKey(pubkey) .

For Tap.getPubKey you should be using the internal pubkey, and for the address you should be using the tpubkey. For the pubkey in the script itself, it can be any keypair that you want, but it can be convenient to reuse the internal pubkey for that as well.

The internal pubkey is what gets tweaked by the taproot, creating the tpubkey, which you then encode into an address. I hope that helps.

from tapscript.

HuangCaiJin avatar HuangCaiJin commented on July 28, 2024

Uploading 1.png…

from tapscript.

HuangCaiJin avatar HuangCaiJin commented on July 28, 2024

Maybe it's because taproot hash deletion

from tapscript.

HFFP avatar HFFP commented on July 28, 2024

i fix it. see

from tapscript.

chirag9899 avatar chirag9899 commented on July 28, 2024

hey am also facing same witness mismatch problem
`
// Here is my code

const inscriptions = async () => {
const marker = Buff.encode('ord')
const mimetype = Buff.encode('image/png')
const imgdata = Buff.from('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/Pv8hOAAAAABJRU5ErkJggg==', 'base64')

// const pubKey = "02f8a93684235245259faf189eb6b5787b03dbe8711a1262409cfcfd0ee015a483";
const pvt = "06e257ee24ce8ee772d78568da1e0c281b5b816c90fa77d.........";
const pvtKey = keys.get_seckey(pvt)
const pubkey = keys.get_pubkey(pvt,true);

// Basic format of an 'inscription' script.
const script = [pubkey.hex, 'OP_CHECKSIG', 'OP_0', 'OP_IF', marker, '01', mimetype, 'OP_0', imgdata, 'OP_ENDIF']
// const tapleaf = Tap.encodeScript(script)
const tapleaf = Tap.tree.getLeaf(Script.encode(script));
const [tpubkey, cblock] = Tap.getPubKey(pubkey, { target: tapleaf });
const address = Address.p2tr.fromPubKey(tpubkey, 'regtest')

console.log('Inscription address: ', address);
console.log('Tapkey:', tpubkey);


try {
  const txdata = Tx.create({
    vin: [{
      // Use the txid of the funding transaction used to send the sats.
      txid: "c404bc4ba89e9423ff772cb45268ba6fba8b713f809484c1216f1a657aafa088",
      // Specify the index value of the output that you are going to spend from.
      vout: 1,
      // Also include the value and script of that ouput.
      prevout: {
        // Feel free to change this if you sent a different amount.
        value: 1973787,
        // This is what our address looks like in script form.
        scriptPubKey: ['OP_1', tpubkey]
      },
    }],
    vout: [{
      // We are leaving behind 1000 sats as a fee to the miners.
      value: 500,
      // This is the new script that we are locking our funds to. sent
      scriptPubKey: Address.toScriptPubKey('tb1q7gnys2cwhkm7r73px6nus0g9dcr8mjh6fe2ums')
      // scriptPubKey: [ 'OP_1', tpubkey ]
    }]
  })


  // let sig = await window.unisat.signMessage(pvtKey, txdata, 0, { extension: tapleaf });
  const sig = Signer.taproot.sign(pvtKey, txdata, 0, { extension: tapleaf })
  console.log("sig",sig)

  txdata.vin[0].witness = [sig, script, cblock]
  console.log(txdata.vin[0].witness)
  console.log(script,cblock)

  // const isValid = await Signer.taproot.verify(txdata, 0, { pubkey, throws: true })
  console.log("txdata", txdata)

  // encode
  console.log('Your txhex:', Tx.encode(txdata).hex)
  const isValid = Signer.taproot.verify(txdata, 0, { pubkey, throws: true })

  console.log("valid",isValid)

  // console.dir(txdata, { depth: null })
} catch (error) {
  console.log("error", error)
}

}

`

from tapscript.

cmdruid avatar cmdruid commented on July 28, 2024

A witness hash mismatch problem is usually because there is something wrong with the encoding of the script when you first encode it as a tapleaf.

Using Tap.encodeScript(script) should make sure that the script is encoded properly, so that when the script is verified in the witness, the encoding during verification is the same as the encoding when you first create the tapleaf.

Let me know if that helps.

from tapscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.