bitcoinerlab / descriptors

A TypeScript library for parsing Bitcoin Descriptors, including Miniscript-based ones. Streamlines creating Partially Signed Bitcoin Transactions (PSBTs) from Descriptors. Features BIP32, single-signature, and Hardware Wallet signing capabilities, and facilitates finalizing transactions.
https://bitcoinerlab.com/modules/descriptors
41 stars 14 forks source link

new Output with descriptor: addr(TAPROOT) #35

Open DmytroShalaiev opened 6 months ago

DmytroShalaiev commented 6 months ago

new Output({ descriptor: 'addr(tb1prnwvuc8tc6t7lqn2x7eul6f8n9qmpaam8p64wanqnegnglp68dhsxnzalc)', networks.testnet }),

For now not working due to error 'No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance'

Снимок экрана 2023-12-18 в 13 57 44

Seems what address.toOutputScript for Taproot keys requiring initing EccLib in bitcoinjs as in tests https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f92ada3fda587c1c0a6aa93649afa04e8382b93/test/address.spec.ts#L71

I understand that for addr() desc for now only https://github.com/bitcoinerlab/descriptors/blob/0511e6486efb7f3a6b8a81535835c2788ee5c238/src/descriptors.ts#L1027C68-L1027C68. Just interesting do you plan to add taproot address?

DmytroShalaiev commented 6 months ago

Right now, I am working with https://github.com/bitcoinerlab/coinselect

My main goal is processing 'coinslection' from P2WPKH utxo's to P2TP outputs. and seems that initing EccLib for bitcoin-js is the only thing missing to achieve the goal.

landabaso commented 6 months ago

Hi @DmytroShalaiev,

This library doesn’t currently support Tapscript, and I won’t be able to add this feature until the beginning of next year. I'm currently quite busy on a related project involving BitcoinerLab, but please be assured that adding Tapscript support to the library is one of my top priorities.

That said, bitcoinjs-lib requires you to initialize the initEccLib for Taproot. This process will eventually be automated, but for now, you can do it manually. Please try calling initEccLib and tell me where this leads you. Depending on your situation, I might be able to propose a temporary solution for your specific needs.

Also, I'm curious to know if having p2tp outputs is an absolute necessity for you at this moment or can wait a bit.

DmytroShalaiev commented 6 months ago

Thank you so much for your time and your best

Tapscript support to the library is one of my top priorities.

It will be cool!

Depending on your situation, I might be able to propose a temporary solution for your specific needs.

Right now trying to do it, thanks.

Also, I'm curious to know if having p2tp outputs is an absolute necessity for you at this moment or can wait a bit.

I think can wait, but I will try to initEccLib.

DmytroShalaiev commented 6 months ago

So such a trick works :) and Output object with TP address created. Next step extending functions inputWeight & outputWeight for working with TP 'sizes' (https://bitcoinops.org/en/tools/calc-size/), seems it's all that needed in CoinSelection usage

Снимок экрана 2023-12-18 в 16 04 49

landabaso commented 6 months ago

Good to hear!

By the way, you don’t need both tiny-secp256k1 and @bitcoinerlab/secp256k1. Just choosing one should suffice.

Have you forked the project? It looks like you're on the right track. I believe your next step is to adapt the guessOutput() function for Taproot (tr) and then accurately determine the correct input and output sizes. Keep me updated on your progress. Once you've made headway, we can collaborate on crafting a new version.

One important aspect to consider is that releasing a new version would ideally require new test vectors. This is crucial for ensuring the reliability and robustness of the updates.

DmytroShalaiev commented 6 months ago

@landabaso I added the implementation for (P2TR keypath input) and attached a draft PR https://github.com/bitcoinerlab/descriptors/pull/36 when you have time please take a look; it will be nice to hear your feedback.

The tests are not done yet, but I think I can add them after discussion.