diff --git a/btc/bitcoind.go b/btc/bitcoind.go index eeadb30..e884129 100644 --- a/btc/bitcoind.go +++ b/btc/bitcoind.go @@ -209,11 +209,15 @@ func (i *ImportWallet) Format(hdKey *hdkeychain.ExtendedKey, if err != nil { return "", fmt.Errorf("could not create address: %w", err) } + addrP2TR, err := lnd.P2TRAddr(privKey.PubKey(), params) + if err != nil { + return "", fmt.Errorf("could not create address: %w", err) + } return fmt.Sprintf("%s 1970-01-01T00:00:01Z label=%s/%d/%d/ "+ - "# addr=%s,%s,%s", wif.String(), path, branch, index, + "# addr=%s,%s,%s,%s", wif.String(), path, branch, index, addrP2PKH.EncodeAddress(), addrNP2WKH.EncodeAddress(), - addrP2WKH.EncodeAddress(), + addrP2WKH.EncodeAddress(), addrP2TR.EncodeAddress(), ), nil } diff --git a/cmd/chantools/derivekey.go b/cmd/chantools/derivekey.go index b0c4f7b..1bc6955 100644 --- a/cmd/chantools/derivekey.go +++ b/cmd/chantools/derivekey.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil/hdkeychain" "github.com/guggero/chantools/lnd" @@ -16,6 +15,7 @@ Public key: %x Extended public key (xpub): %v Address: %v Legacy address: %v +Taproot address: %v Private key (WIF): %s Extended private key (xprv): %s ` @@ -99,6 +99,11 @@ func deriveKey(extendedKey *hdkeychain.ExtendedKey, path string, return fmt.Errorf("could not create address: %w", err) } + addrP2TR, err := lnd.P2TRAddr(pubKey, chainParams) + if err != nil { + return fmt.Errorf("could not create address: %w", err) + } + privKey, xPriv := na, na if !neuter { privKey, xPriv = wif.String(), child.String() @@ -107,7 +112,7 @@ func deriveKey(extendedKey *hdkeychain.ExtendedKey, path string, result := fmt.Sprintf( deriveKeyFormat, path, chainParams.Name, pubKey.SerializeCompressed(), neutered, addrP2WKH, addrP2PKH, - privKey, xPriv, + addrP2TR, privKey, xPriv, ) fmt.Println(result) diff --git a/cmd/chantools/root.go b/cmd/chantools/root.go index 106afeb..9c12d09 100644 --- a/cmd/chantools/root.go +++ b/cmd/chantools/root.go @@ -26,7 +26,7 @@ import ( const ( defaultAPIURL = "https://blockstream.info/api" - version = "0.10.5" + version = "0.10.6" na = "n/a" Commit = "" diff --git a/lnd/hdkeychain.go b/lnd/hdkeychain.go index f29676f..53509b5 100644 --- a/lnd/hdkeychain.go +++ b/lnd/hdkeychain.go @@ -3,6 +3,7 @@ package lnd import ( "crypto/sha256" "fmt" + "github.com/btcsuite/btcd/btcec/v2/schnorr" "strconv" "strings" @@ -21,6 +22,7 @@ const ( HardenedKeyStart = uint32(hdkeychain.HardenedKeyStart) WalletDefaultDerivationPath = "m/84'/0'/0'" WalletBIP49DerivationPath = "m/49'/0'/0'" + WalletBIP86DerivationPath = "m/86'/0'/0'" LndDerivationPath = "m/1017'/%d'/%d'" ) @@ -199,6 +201,7 @@ func AllDerivationPaths(params *chaincfg.Params) ([]string, [][]uint32, error) { pathStrings := []string{ WalletBIP49DerivationPath, WalletDefaultDerivationPath, + WalletBIP86DerivationPath, mkPath(keychain.KeyFamilyPaymentBase), } paths := make([][]uint32, len(pathStrings)) @@ -350,6 +353,15 @@ func NP2WKHAddr(pubKey *btcec.PublicKey, return btcutil.NewAddressScriptHash(script, params) } +func P2TRAddr(pubKey *btcec.PublicKey, + params *chaincfg.Params) (*btcutil.AddressTaproot, error) { + + taprootKey := txscript.ComputeTaprootKeyNoScript(pubKey) + return btcutil.NewAddressTaproot( + schnorr.SerializePubKey(taprootKey), params, + ) +} + func P2AnchorStaticRemote(pubKey *btcec.PublicKey, params *chaincfg.Params) (*btcutil.AddressWitnessScriptHash, []byte, error) {