Skip to content

Commit

Permalink
Merge pull request #490 from lightninglabs/group-key-witness-support
Browse files Browse the repository at this point in the history
Group key witness support
  • Loading branch information
Roasbeef authored Oct 3, 2023
2 parents cbcfdd7 + 6686744 commit 8899ca4
Show file tree
Hide file tree
Showing 61 changed files with 2,620 additions and 1,396 deletions.
21 changes: 0 additions & 21 deletions address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/commitment"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightningnetwork/lnd/tlv"
)

Expand Down Expand Up @@ -98,12 +97,6 @@ type Tap struct {
// asset to be made possible.
GroupKey *btcec.PublicKey

// groupWitness is a stack of witness elements that authorizes the
// membership of an asset in a partiular asset group. The witness can
// be a single signature or a script from the tapscript tree committed
// to with the TapscriptRoot, and follows the witness rules in BIP-341.
groupWitness wire.TxWitness

// ScriptKey represents a tweaked Taproot output key encumbering the
// different ways an asset can be spent.
ScriptKey btcec.PublicKey
Expand Down Expand Up @@ -184,7 +177,6 @@ func New(version Version, genesis asset.Genesis, groupKey *btcec.PublicKey,
AssetVersion: asset.V0,
AssetID: genesis.ID(),
GroupKey: groupKey,
groupWitness: groupWitness,
ScriptKey: scriptKey,
InternalKey: internalKey,
TapscriptSibling: tapscriptSibling,
Expand All @@ -203,9 +195,6 @@ func (a *Tap) Copy() *Tap {
groupPubKey := *a.GroupKey
addressCopy.GroupKey = &groupPubKey
}
if len(a.groupWitness) != 0 {
addressCopy.groupWitness = fn.CopySlice(a.groupWitness)
}

return &addressCopy
}
Expand All @@ -226,11 +215,6 @@ func (a *Tap) AttachGenesis(gen asset.Genesis) {
a.assetGen = gen
}

// AttachGroupWitness attaches the asset's group witness to the address.
func (a *Tap) AttachGroupWitness(wit wire.TxWitness) {
a.groupWitness = wit
}

// TapCommitmentKey is the key that maps to the root commitment for the asset
// group specified by a Taproot Asset address.
func (a *Tap) TapCommitmentKey() [32]byte {
Expand Down Expand Up @@ -259,13 +243,8 @@ func (a *Tap) TapCommitment() (*commitment.TapCommitment, error) {
// it in the TLV leaf.
var groupKey *asset.GroupKey
if a.GroupKey != nil {
if len(a.groupWitness) == 0 {
return nil, fmt.Errorf("missing group signature")
}

groupKey = &asset.GroupKey{
GroupPubKey: *a.GroupKey,
Witness: a.groupWitness,
}
}
newAsset, err := asset.New(
Expand Down
12 changes: 8 additions & 4 deletions address/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func randAddress(t *testing.T, net *ChainParams, v Version, groupPubKey,
)
}

pubKeyCopy1 := *pubKey
pubKeyCopy2 := *pubKey
scriptKey := *pubKey
internalKey := *pubKey

genesis := asset.RandGenesis(t, assetType)

Expand All @@ -64,15 +64,19 @@ func randAddress(t *testing.T, net *ChainParams, v Version, groupPubKey,
)

if groupPubKey {
groupInfo := asset.RandGroupKey(t, genesis)
protoAsset := asset.NewAssetNoErr(
t, genesis, amount, 0, 0,
asset.NewScriptKey(&scriptKey), nil,
)
groupInfo := asset.RandGroupKey(t, genesis, protoAsset)
groupKey = &groupInfo.GroupPubKey
groupWitness = groupInfo.Witness
}

proofCourierAddr := RandProofCourierAddr(t)

return New(
v, genesis, groupKey, groupWitness, pubKeyCopy1, pubKeyCopy2,
v, genesis, groupKey, groupWitness, scriptKey, internalKey,
amount, tapscriptSibling, net, proofCourierAddr,
)
}
Expand Down
20 changes: 11 additions & 9 deletions address/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func RandAddr(t testing.TB, params *ChainParams,
*asset.Genesis, *asset.GroupKey) {

scriptKeyPriv := test.RandPrivKey(t)
scriptKey := asset.NewScriptKeyBip86(keychain.KeyDescriptor{
PubKey: scriptKeyPriv.PubKey(),
KeyLocator: keychain.KeyLocator{
Family: keychain.KeyFamily(test.RandIntn(255) + 1),
Index: uint32(test.RandIntn(255)),
},
})

internalKey := test.RandPrivKey(t)

Expand All @@ -49,7 +56,10 @@ func RandAddr(t testing.TB, params *ChainParams,
tapscriptSibling *commitment.TapscriptPreimage
)
if test.RandInt[uint32]()%2 == 0 {
groupInfo = asset.RandGroupKey(t, genesis)
protoAsset := asset.NewAssetNoErr(
t, genesis, amount, 0, 0, scriptKey, nil,
)
groupInfo = asset.RandGroupKey(t, genesis, protoAsset)
groupPubKey = &groupInfo.GroupPubKey
groupWitness = groupInfo.Witness

Expand All @@ -58,14 +68,6 @@ func RandAddr(t testing.TB, params *ChainParams,
)
}

scriptKey := asset.NewScriptKeyBip86(keychain.KeyDescriptor{
PubKey: scriptKeyPriv.PubKey(),
KeyLocator: keychain.KeyLocator{
Family: keychain.KeyFamily(test.RandIntn(255) + 1),
Index: uint32(test.RandIntn(255)),
},
})

tapAddr, err := New(
V0, genesis, groupPubKey, groupWitness, *scriptKey.PubKey,
*internalKey.PubKey(), amount, tapscriptSibling, params,
Expand Down
4 changes: 2 additions & 2 deletions address/testdata/address_tlv_encoding_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
"chain_params_hrp": "taptb",
"asset_version": 0,
"asset_id": "7f3a94b3048ecbce4f2b1686e2df89bde52d5ead1aed011f75fa6578dcab0839",
"group_key": "03f32d239904d1addae728d1917a94bc1d20455b12b251a9222d035e5014a9f759",
"group_key": "02cd028e8899c3324c75a41f6f34b0038fa640b96b93e421c9860c52a7efa9d395",
"script_key": "02a0afeb165f0ec36880b68e0baabd9ad9c62fd1a69aa998bc30e9a346202e078f",
"internal_key": "02a0afeb165f0ec36880b68e0baabd9ad9c62fd1a69aa998bc30e9a346202e078f",
"tapscript_sibling": "",
"amount": 1,
"proof_courier_addr": "hashmail://rand.hashmail.proof.courier:443"
},
"expected": "taptb1qqqsqqspqqzzqle6jjesfrktee8jk95xut0cn00994026xhdqy0ht7n90rw2kzpeq5ss8uedywvsf5ddmtnj35v3022tc8fqg4d39vj34y3z6q672q22na6eqcss9g90avt97rkrdzqtdrst427e4kwx9lg6dx4fnz7rp6drgcszupu0pqss9g90avt97rkrdzqtdrst427e4kwx9lg6dx4fnz7rp6drgcszupu0pgqszrp2dpshx6rdv95kcw309aexzmny9e5xzumgd4skjmpwwpex7mmx9e3k7atjd9jhyw35xseskkqklz",
"expected": "taptb1qqqsqqspqqzzqle6jjesfrktee8jk95xut0cn00994026xhdqy0ht7n90rw2kzpeq5ss9ngz36yfnsejf366g8m0xjcq8raxgzukhylyy8ycvrzj5lh6n5u4qcss9g90avt97rkrdzqtdrst427e4kwx9lg6dx4fnz7rp6drgcszupu0pqss9g90avt97rkrdzqtdrst427e4kwx9lg6dx4fnz7rp6drgcszupu0pgqszrp2dpshx6rdv95kcw309aexzmny9e5xzumgd4skjmpwwpex7mmx9e3k7atjd9jhyw35xses833965",
"comment": "signet group collectible"
},
{
Expand Down
Loading

0 comments on commit 8899ca4

Please sign in to comment.