Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Bitcoin scripts in Taproot constructs #13

Closed
lgalabru opened this issue Dec 19, 2022 · 1 comment
Closed

Support Bitcoin scripts in Taproot constructs #13

lgalabru opened this issue Dec 19, 2022 · 1 comment

Comments

@lgalabru
Copy link

hey @paulmillr!
First things first, thank you for this lib and your work in general!
I'm trying to use to use micro-btc-signer and noticed that - unless I missed something when using / reading this lib - there's a limitation in the current implementation, when crafting taproot constructs.
Per the code, it looks like we can only create CHECKSIGVERIFY based multisigs constructs and I was wondering why.
If I try to craft a set of conditions involving a HTLC, the lib is aborting my construct.
Reproducer:

const keypairFromSecret = (hexSecretKey: string): Keypair => {
    let secretKey = hex.decode(hexSecretKey);
    let schnorrPublicKey = secp.schnorr.getPublicKey(secretKey);
    return {
        schnorrPublicKey,
        secretKey,
    }
}

let aliceKeyPair = keypairFromSecret("2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90");
let bobKeyPair = keypairFromSecret("81b637d8fcd2c6da6359e6963113a1170de795e4b725b84d1e0b4cfd9ec58ce9");
let internalKeyPair = keypairFromSecret("1229101a0fcf2104e8808dab35661134aa5903867d44deb73ce1c7e4eb925be8");
let preimage = sha256(hex.decode("107661134f21fc7c02223d50ab9eb3600bc3ffc3712423a1e47bb1f9a9dbf55f"))

let scriptAlice = new Uint8Array([0x02, 144, 0x00, btc.OP.CHECKSEQUENCEVERIFY, btc.OP.DROP, 0x20, ...aliceKeyPair.schnorrPublicKey, 0xac]);

let scriptBob = new Uint8Array([btc.OP.SHA256, 0x20, ...preimage, btc.OP.EQUALVERIFY, 0x20, ...bobKeyPair.schnorrPublicKey, 0xac]);

let taprootTree = btc.taprootListToTree([{
    script: scriptAlice,
    leafVersion: 0xc0
  },  {
    script: scriptBob,
    leafVersion: 0xc0 
  }
])

let taprootCommitment = btc.p2tr(internalKeyPair.schnorrPublicKey, taprootTree);
// Execution aborted with
// Error: Reader(): Error: OutScript.encode/tr_ns: wrong element

I could be miss using the lib, please let me know if I'm missing something.
Thanks!

@paulmillr
Copy link
Owner

Fixed. please check the new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants