Skip to content

Commit

Permalink
Merge pull request #6775 from guggero/import-taproot-pubkey
Browse files Browse the repository at this point in the history
Import Taproot pubkey
  • Loading branch information
guggero authored Aug 25, 2022
2 parents 2ad6b57 + 9fe97af commit cf9a986
Show file tree
Hide file tree
Showing 23 changed files with 2,447 additions and 983 deletions.
7 changes: 7 additions & 0 deletions docs/release-notes/release-notes-0.16.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ transaction](https://github.com/lightningnetwork/lnd/pull/6730).

* [Add list addresses RPC](https://github.com/lightningnetwork/lnd/pull/6596).

## Wallet

* [Allows Taproot public keys and tap scripts to be imported as watch-only
addresses into the internal
wallet](https://github.com/lightningnetwork/lnd/pull/6775). NOTE that funding
PSBTs from imported tap scripts is not currently possible.

## Build

[The project has updated to Go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/btcsuite/btcd/btcutil/psbt v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet v0.15.1
github.com/btcsuite/btcwallet v0.15.2-0.20220804001213-5aafe4789850
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0
github.com/btcsuite/btcwallet/walletdb v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtyd
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcwallet v0.15.1 h1:SKfh/l2Bgz9sJwHZvfiVbZ8Pl3N/8fFcWWXzsAPz9GU=
github.com/btcsuite/btcwallet v0.15.1/go.mod h1:7OFsQ8ypiRwmr67hE0z98uXgJgXGAihE79jCib9x6ag=
github.com/btcsuite/btcwallet v0.15.2-0.20220804001213-5aafe4789850 h1:yhtY53u3I6qT0yMJg35Yfa+yCVhvoqWWKTB2D2GBNJE=
github.com/btcsuite/btcwallet v0.15.2-0.20220804001213-5aafe4789850/go.mod h1:7OFsQ8ypiRwmr67hE0z98uXgJgXGAihE79jCib9x6ag=
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3 h1:M2yr5UlULvpqtxUqpMxTME/pA92Z9cpqeyvAFk9lAg0=
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3/go.mod h1:T2xSiKGpUkSLCh68aF+FMXmKK9mFqNdHl9VaqOr+JjU=
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 h1:BtEN5Empw62/RVnZ0VcJaVtVlBijnLlJY+dwjAye2Bg=
Expand Down
30 changes: 30 additions & 0 deletions input/taproot.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,33 @@ func TapscriptPartialReveal(internalKey *btcec.PublicKey,
RevealedScript: revealedLeaf.Script,
}
}

// TapscriptRootHashOnly creates a waddrmgr.Tapscript for the given internal key
// and root hash.
func TapscriptRootHashOnly(internalKey *btcec.PublicKey,
rootHash []byte) *waddrmgr.Tapscript {

controlBlock := &txscript.ControlBlock{
InternalKey: internalKey,
}

tapKey := txscript.ComputeTaprootOutputKey(internalKey, rootHash)
if tapKey.SerializeCompressed()[0] == PubKeyFormatCompressedOdd {
controlBlock.OutputKeyYIsOdd = true
}

return &waddrmgr.Tapscript{
Type: waddrmgr.TaprootKeySpendRootHash,
ControlBlock: controlBlock,
RootHash: rootHash,
}
}

// TapscriptFullKeyOnly creates a waddrmgr.Tapscript for the given full Taproot
// key.
func TapscriptFullKeyOnly(taprootKey *btcec.PublicKey) *waddrmgr.Tapscript {
return &waddrmgr.Tapscript{
Type: waddrmgr.TaprootFullKeyOnly,
FullOutputKey: taprootKey,
}
}
829 changes: 417 additions & 412 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ enum OutputScriptType {
SCRIPT_TYPE_NULLDATA = 6;
SCRIPT_TYPE_NON_STANDARD = 7;
SCRIPT_TYPE_WITNESS_UNKNOWN = 8;
SCRIPT_TYPE_WITNESS_V1_TAPROOT = 9;
}

message OutputDetail {
Expand Down
3 changes: 2 additions & 1 deletion lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5611,7 +5611,8 @@
"SCRIPT_TYPE_MULTISIG",
"SCRIPT_TYPE_NULLDATA",
"SCRIPT_TYPE_NON_STANDARD",
"SCRIPT_TYPE_WITNESS_UNKNOWN"
"SCRIPT_TYPE_WITNESS_UNKNOWN",
"SCRIPT_TYPE_WITNESS_V1_TAPROOT"
],
"default": "SCRIPT_TYPE_PUBKEY_HASH"
},
Expand Down
2 changes: 2 additions & 0 deletions lnrpc/marshall_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func MarshallOutputType(o txscript.ScriptClass) OutputScriptType {
return OutputScriptType_SCRIPT_TYPE_NON_STANDARD
case txscript.WitnessUnknownTy:
return OutputScriptType_SCRIPT_TYPE_WITNESS_UNKNOWN
case txscript.WitnessV1TaprootTy:
return OutputScriptType_SCRIPT_TYPE_WITNESS_V1_TAPROOT
default:
return OutputScriptType_SCRIPT_TYPE_PUBKEY_HASH
}
Expand Down
Loading

0 comments on commit cf9a986

Please sign in to comment.