From 97dfc041179ecc33fd1a677b617176397a08a9f4 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 29 Jul 2022 18:20:03 +0200 Subject: [PATCH] lnrpc: allow importing Taproot pubkeys --- lnrpc/walletrpc/walletkit_server.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index a3608e965..4241bf603 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -17,6 +17,7 @@ import ( "time" "github.com/btcsuite/btcd/btcec/v2" + "github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil/hdkeychain" "github.com/btcsuite/btcd/btcutil/psbt" @@ -1639,7 +1640,7 @@ func parseAddrType(addrType AddressType, // distinction between the standard BIP-0049 address schema (nested witness // pubkeys everywhere) and our own BIP-0049Plus address schema (nested pubkeys // externally, witness pubkeys internally). -func (w *WalletKit) ImportAccount(ctx context.Context, +func (w *WalletKit) ImportAccount(_ context.Context, req *ImportAccountRequest) (*ImportAccountResponse, error) { accountPubKey, err := hdkeychain.NewKeyFromString(req.ExtendedPublicKey) @@ -1699,13 +1700,24 @@ func (w *WalletKit) ImportAccount(ctx context.Context, // of legacy versions (xpub, tpub), an address type must be specified as we // intend to not support importing BIP-44 keys into the wallet using the legacy // pay-to-pubkey-hash (P2PKH) scheme. -func (w *WalletKit) ImportPublicKey(ctx context.Context, +func (w *WalletKit) ImportPublicKey(_ context.Context, req *ImportPublicKeyRequest) (*ImportPublicKeyResponse, error) { - pubKey, err := btcec.ParsePubKey(req.PublicKey) + var ( + pubKey *btcec.PublicKey + err error + ) + switch req.AddressType { + case AddressType_TAPROOT_PUBKEY: + pubKey, err = schnorr.ParsePubKey(req.PublicKey) + + default: + pubKey, err = btcec.ParsePubKey(req.PublicKey) + } if err != nil { return nil, err } + addrType, err := parseAddrType(req.AddressType, true) if err != nil { return nil, err