Skip to content

Commit

Permalink
multi: rename asset.GroupPubKey to GroupPubKeyV0
Browse files Browse the repository at this point in the history
Renamed the function to `GroupPubKeyV0` to allow for the introduction
of future versions while maintaining clarity and compatibility.
  • Loading branch information
ffranr committed Dec 5, 2024
1 parent 23735cc commit 2fa1fb5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tapgarden/caretaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 2fa1fb5

Please sign in to comment.