lnd icon indicating copy to clipboard operation
lnd copied to clipboard

lnrpc/walletrpc: expose pubkey import for taproot addresses over the RPC interface

Open Roasbeef opened this issue 3 years ago • 3 comments
trafficstars

Today the WalletKit RPC sub-server has support for normal pubkey import: https://github.com/lightningnetwork/lnd/blob/master/lnrpc/walletrpc/walletkit.proto#L93-L102. However, if you attempt to specify that the pubkey should be interpreted as a taproot output, then you'll run into this error message (deep in btcwallet): https://github.com/btcsuite/btcwallet/blob/master/wallet/import.go#L376-L378.

Thankfully, the taproot native ImportTaprootScript method exists for this purpose: https://github.com/btcsuite/btcwallet/blob/master/wallet/import.go#L407-L412.

In order to allow users to import taproot outputs into the wallet for watch-only functionality, we should update the RPC call to route through this new btcwallet call instead iff a taproot address type (for the pubkey) is detected.

Steps To Completion

  • [ ] Update the logic in walletrpc.ImportPubkey to route to the new ImportTaprootScript call internally within the wallet.
    • As this call is very generalized, we'll want to either expose a slimmed down version (import taproot vs taproot script or w/e), or just make all the parameters available in a new nested message only specifies for the taproot output import case.
  • [ ] Add new integration tests for watch-only scenarios after the import of a taproot key.

Roasbeef avatar Jun 21 '22 23:06 Roasbeef

That is an oversight of a recent PR of mine. https://github.com/btcsuite/btcwallet/blob/master/wallet/import.go#L376-L378 should support importing a raw public key as a Taproot address, so that should be fixed.

The ImportTaprootScript was built for importing a p2tr address with a script tree, I don't think that supports BIP86 just yet. But basically on the lnd (walletrpc) side, it should be possible to import both a p2tr BIP86 public key as well as one with a script tree.

guggero avatar Jun 22 '22 07:06 guggero

The ImportTaprootScript was built for importing a p2tr address with a script tree, I don't think that supports BIP86 just yet.

Cool, I thought maybe it would be possible to just do the BIP 86 tweak computation, then pass that in as the main tapscript tree.

Roasbeef avatar Jun 22 '22 18:06 Roasbeef

Revolves around manageutxo

dstadulis avatar Jul 27 '22 18:07 dstadulis