ElementsProject / libwally-core

Useful primitives for wallets
Other
282 stars 135 forks source link

Single-sig P2TR pkScript/sigScript functions #304

Open benma opened 2 years ago

benma commented 2 years ago

Are there plans for this?

https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki

jgriffiths commented 2 years ago

Hi @benma

We do have plans for supporting receiving and spending from taproot outputs. However at this stage we are still in the planning stage of how we will structure our multisig trees, and the anonymity set is very small, so this isn't our highest priority at present.

ChristopherA commented 2 years ago

Any updates on the roadmap for P2TR support for libwally? Is there a fork somewhere that has a feature branch starting work on it?

We have multiple wallet projects, both our own and others in the Airgapped Wallet Community stalled on this.

/cc @jesseposner @jonasnick @wolfmcnally

jgriffiths commented 2 years ago

Hi @ChristopherA long time no chat, hope you are well.

Wally supports paying to P2TR outputs already, I assume you mean support for receiving and spending from taproot inputs. Its likely that we will support taproot through descriptors when that is merged, along with whatever support functions make sense in that context. Until very recently we had no resources for wally development; that situation should have improved now.

Currently I'm planning to fix the build issues, add PSBT v2 support and then complete descriptor/miniscript support, at which point the missing parts for TR can be assessed.

greenaddress commented 1 year ago

@instagibbs could you do a PR to cover this use case as a basis for what you will use/need in core lightning?

There may be more needed I didn't check yet

instagibbs commented 1 year ago

https://github.com/ElementsProject/libwally-core/pull/351 to track the proposed support

jgriffiths commented 1 year ago

@instagibbs I think we should add a function to convert a non-neutered BIP32 ext_key to a keyspend only key, i.e. implement:

internal_key:       lift_x(derived_key)
32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key)))G

From BIP86 - something like bip32_key_get_keyspend_private_key/bip32_key_get_keyspend_public_key.

We should probably also expose x-only key conversion and fetching from an ext_key. Following that we have all the primitives for singlesig keyspend only TR wallets except schnorr sigs.

instagibbs commented 1 year ago

Sounds right, I implemented the rest inside of CLN directly, such as the BIP86-like committment https://github.com/instagibbs/lightning/blob/eltoo_support/bitcoin/signature.c#L251

and regular BIP340 signing: https://github.com/instagibbs/lightning/blob/eltoo_support/bitcoin/signature.c#L141

instagibbs commented 1 year ago

notice all my interfaces are using compressed keys; xonly keys are only used "just in time" when required for blockchain usage.

instagibbs commented 1 year ago

https://github.com/ElementsProject/libwally-core/releases/tag/release_0.9.0 now has support for PSBT signing of keyspends, in addition to more general sighash support of tapscript.