Skip to content

Commit

Permalink
Merge pull request #542 from lightninglabs/v0-3-0-staging
Browse files Browse the repository at this point in the history
multi: merge staging branch into main
  • Loading branch information
Roasbeef authored Oct 3, 2023
2 parents bf4af96 + 8899ca4 commit 1c50eba
Show file tree
Hide file tree
Showing 83 changed files with 5,098 additions and 2,773 deletions.
23 changes: 2 additions & 21 deletions address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ type Tap struct {
// asset to be made possible.
GroupKey *btcec.PublicKey

// groupSig is the signature of the asset genesis with the group key
// that is used to verify asset membership in a group.
groupSig *schnorr.Signature

// ScriptKey represents a tweaked Taproot output key encumbering the
// different ways an asset can be spent.
ScriptKey btcec.PublicKey
Expand Down Expand Up @@ -130,7 +126,7 @@ type Tap struct {
// TODO(ffranr): This function takes many arguments. Add a struct to better
// organise its arguments.
func New(version Version, genesis asset.Genesis, groupKey *btcec.PublicKey,
groupSig *schnorr.Signature, scriptKey btcec.PublicKey,
groupWitness wire.TxWitness, scriptKey btcec.PublicKey,
internalKey btcec.PublicKey, amt uint64,
tapscriptSibling *commitment.TapscriptPreimage,
net *ChainParams, proofCourierAddr url.URL) (*Tap, error) {
Expand Down Expand Up @@ -171,7 +167,7 @@ func New(version Version, genesis asset.Genesis, groupKey *btcec.PublicKey,
}
}

if groupKey != nil && groupSig == nil {
if groupKey != nil && len(groupWitness) == 0 {
return nil, fmt.Errorf("address: missing group signature")
}

Expand All @@ -181,7 +177,6 @@ func New(version Version, genesis asset.Genesis, groupKey *btcec.PublicKey,
AssetVersion: asset.V0,
AssetID: genesis.ID(),
GroupKey: groupKey,
groupSig: groupSig,
ScriptKey: scriptKey,
InternalKey: internalKey,
TapscriptSibling: tapscriptSibling,
Expand All @@ -200,10 +195,6 @@ func (a *Tap) Copy() *Tap {
groupPubKey := *a.GroupKey
addressCopy.GroupKey = &groupPubKey
}
if a.groupSig != nil {
groupSig := *a.groupSig
addressCopy.groupSig = &groupSig
}

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

// AttachGroupSig attaches the asset's group signature to the address.
func (a *Tap) AttachGroupSig(sig schnorr.Signature) {
a.groupSig = &sig
}

// 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 @@ -257,13 +243,8 @@ func (a *Tap) TapCommitment() (*commitment.TapCommitment, error) {
// it in the TLV leaf.
var groupKey *asset.GroupKey
if a.GroupKey != nil {
if a.groupSig == nil {
return nil, fmt.Errorf("missing group signature")
}

groupKey = &asset.GroupKey{
GroupPubKey: *a.GroupKey,
Sig: *a.groupSig,
}
}
newAsset, err := asset.New(
Expand Down
19 changes: 12 additions & 7 deletions address/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/commitment"
"github.com/lightninglabs/taproot-assets/internal/test"
Expand Down Expand Up @@ -52,26 +53,30 @@ func randAddress(t *testing.T, net *ChainParams, v Version, groupPubKey,
)
}

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

genesis := asset.RandGenesis(t, assetType)

var (
groupKey *btcec.PublicKey
groupSig *schnorr.Signature
groupKey *btcec.PublicKey
groupWitness wire.TxWitness
)

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
groupSig = &groupInfo.Sig
groupWitness = groupInfo.Witness
}

proofCourierAddr := RandProofCourierAddr(t)

return New(
v, genesis, groupKey, groupSig, pubKeyCopy1, pubKeyCopy2,
v, genesis, groupKey, groupWitness, scriptKey, internalKey,
amount, tapscriptSibling, net, proofCourierAddr,
)
}
Expand Down
9 changes: 4 additions & 5 deletions address/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/taproot-assets/asset"
Expand Down Expand Up @@ -222,17 +221,17 @@ func (b *Book) NewAddressWithKeys(ctx context.Context, assetID asset.ID,
}

var (
groupKey *btcec.PublicKey
groupSig *schnorr.Signature
groupKey *btcec.PublicKey
groupWitness wire.TxWitness
)

if assetGroup.GroupKey != nil {
groupKey = &assetGroup.GroupPubKey
groupSig = &assetGroup.Sig
groupWitness = assetGroup.Witness
}

baseAddr, err := New(
V0, *assetGroup.Genesis, groupKey, groupSig,
V0, *assetGroup.Genesis, groupKey, groupWitness,
*scriptKey.PubKey, *internalKeyDesc.PubKey, amount,
tapscriptSibling, &b.cfg.Chain, proofCourierAddr,
)
Expand Down
28 changes: 15 additions & 13 deletions address/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/commitment"
"github.com/lightninglabs/taproot-assets/internal/test"
Expand All @@ -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 @@ -45,29 +52,24 @@ func RandAddr(t testing.TB, params *ChainParams,
var (
groupInfo *asset.GroupKey
groupPubKey *btcec.PublicKey
groupSig *schnorr.Signature
groupWitness wire.TxWitness
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
groupSig = &groupInfo.Sig
groupWitness = groupInfo.Witness

tapscriptSibling = commitment.NewPreimageFromLeaf(
txscript.NewBaseTapLeaf([]byte("not a valid script")),
)
}

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, groupSig, *scriptKey.PubKey,
V0, genesis, groupPubKey, groupWitness, *scriptKey.PubKey,
*internalKey.PubKey(), amount, tapscriptSibling, params,
proofCourierAddr,
)
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 1c50eba

Please sign in to comment.