From 2fa1fb59b9bb9e40106120e3250ca00da2892f45 Mon Sep 17 00:00:00 2001 From: ffranr Date: Wed, 4 Dec 2024 14:58:22 +0000 Subject: [PATCH] multi: rename asset.GroupPubKey to GroupPubKeyV0 Renamed the function to `GroupPubKeyV0` to allow for the introduction of future versions while maintaining clarity and compatibility. --- asset/asset.go | 15 ++++++++------- asset/asset_test.go | 4 ++-- itest/assertions.go | 2 +- tapgarden/caretaker.go | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/asset/asset.go b/asset/asset.go index 25bd33d3f..661267f2c 100644 --- a/asset/asset.go +++ b/asset/asset.go @@ -996,17 +996,18 @@ func (g *GroupKeyRevealV0) GroupPubKey(assetID ID) (*btcec.PublicKey, error) { return nil, fmt.Errorf("group reveal raw key invalid: %w", err) } - return GroupPubKey(rawKey, assetID[:], g.TapscriptRoot()) + return GroupPubKeyV0(rawKey, assetID[:], g.TapscriptRoot()) } -// GroupPubKey derives a tweaked group key from a public key and two tweaks; -// the single tweak is the asset ID of the group anchor asset, and the tapTweak -// is the root of a tapscript tree that commits to script-based conditions for -// reissuing assets as part of this asset group. The tweaked key is defined by: +// GroupPubKeyV0 derives a version 0 tweaked group key from a public key and two +// tweaks; the single tweak is the asset ID of the group anchor asset, and the +// tapTweak is the root of a tapscript tree that commits to script-based +// conditions for reissuing assets as part of this asset group. The tweaked key +// is defined by: // // internalKey = rawKey + singleTweak * G // tweakedGroupKey = TapTweak(internalKey, tapTweak) -func GroupPubKey(rawKey *btcec.PublicKey, singleTweak, tapTweak []byte) ( +func GroupPubKeyV0(rawKey *btcec.PublicKey, singleTweak, tapTweak []byte) ( *btcec.PublicKey, error) { if len(singleTweak) != sha256.Size { @@ -1417,7 +1418,7 @@ func (req *GroupKeyRequest) BuildGroupVirtualTx(genBuilder GenesisTxBuilder) ( // Compute the tweaked group key and set it in the asset before // creating the virtual minting transaction. genesisTweak := req.AnchorGen.ID() - tweakedGroupKey, err := GroupPubKey( + tweakedGroupKey, err := GroupPubKeyV0( req.RawKey.PubKey, genesisTweak[:], req.TapscriptRoot, ) if err != nil { diff --git a/asset/asset_test.go b/asset/asset_test.go index 449e08be8..44f37fc69 100644 --- a/asset/asset_test.go +++ b/asset/asset_test.go @@ -920,10 +920,10 @@ func TestAssetGroupKey(t *testing.T) { // Group key tweaking should fail when given invalid tweaks. badTweak := test.RandBytes(33) - _, err = GroupPubKey(groupPub, badTweak, badTweak) + _, err = GroupPubKeyV0(groupPub, badTweak, badTweak) require.Error(t, err) - _, err = GroupPubKey(groupPub, groupTweak[:], badTweak) + _, err = GroupPubKeyV0(groupPub, groupTweak[:], badTweak) require.Error(t, err) } diff --git a/itest/assertions.go b/itest/assertions.go index 2c0abdd40..33a640dd1 100644 --- a/itest/assertions.go +++ b/itest/assertions.go @@ -1403,7 +1403,7 @@ func AssertGroupAnchor(t *testing.T, anchorGen *asset.Genesis, // TODO(jhb): add tapscript root support anchorTweak := anchorGen.ID() - computedGroupPubKey, err := asset.GroupPubKey( + computedGroupPubKey, err := asset.GroupPubKeyV0( internalPubKey, anchorTweak[:], nil, ) require.NoError(t, err) diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index a3434f3a1..6968251f0 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1562,7 +1562,7 @@ func GenRawGroupAnchorVerifier(ctx context.Context) func(*asset.Genesis, groupAnchor, err := groupAnchors.Get(assetGroupKey) if err != nil { singleTweak := gen.ID() - tweakedGroupKey, err := asset.GroupPubKey( + tweakedGroupKey, err := asset.GroupPubKeyV0( groupKey.RawKey.PubKey, singleTweak[:], groupKey.TapscriptRoot, )