vulpemventures / liquidjs-lib

A javascript Liquid library for node.js and browsers.
MIT License
27 stars 14 forks source link

Example to show P2TR or Taproot address #114

Open afeezaziz opened 8 months ago

afeezaziz commented 8 months ago

It seems that this library can support taproot receiving address, can there be example on how to generate a P2TR receiving address using this library?

tiero commented 8 months ago

The time we added support for Taproot, BitcoinJS (which we fork from) didnt yet agreed on a payments.p2tr interface, so you have to generate it low-level so to speak.

This is an example of how to build a Taproot address with https://github.com/vulpemventures/liquidjs-lib/blob/master/test/integration/taproot.spec.ts#L38-L73

The key-path spend is simply passing a public key as the first argument of bip341.taprootOutputScript and the taproot tree as second.

You can then get the taproot address from the script passing the network object

const unconfidentialAddress = address.fromOutputScript(
      output,
      networks.regtest,
    );
    const confidentialAddress = address.toConfidential(
      unconfidentialAddress,
      bob.publicKey,
    );
tiero commented 8 months ago

Let me know if it's enough, I keep it open in case, will close later