Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Jan 8, 2025
1 parent 2311735 commit cabfd1d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
30 changes: 30 additions & 0 deletions asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,9 @@ type GroupKey struct {

// GroupKeyRequest contains the essential fields used to derive a group key.
type GroupKeyRequest struct {
// Version is the version of the group key construction.
Version GroupKeyVersion

// RawKey is the raw group key before the tweak with the genesis point
// has been applied.
RawKey keychain.KeyDescriptor
Expand Down Expand Up @@ -2055,7 +2058,15 @@ func NewGroupKeyRequest(internalKey keychain.KeyDescriptor,
customTapscriptRoot fn.Option[chainhash.Hash]) (*GroupKeyRequest,
error) {

// Specify the group key version based on the presence of an external
// key.
var version GroupKeyVersion
if externalKey.IsSome() {
version = GroupKeyV1
}

req := &GroupKeyRequest{
Version: version,
RawKey: internalKey,
ExternalKey: externalKey,
AnchorGen: anchorGen,
Expand Down Expand Up @@ -2106,6 +2117,25 @@ func (req *GroupKeyRequest) Validate() error {
sha256.Size)
}

// Version 1 specific checks.
if req.Version == GroupKeyV1 {
tapscriptRoot, err := chainhash.NewHash(req.TapscriptRoot)
if err != nil {
return fmt.Errorf("version 1 group key request " +
"tapscript root must be a valid hash")
}

if tapscriptRoot.IsEqual(&chainhash.Hash{}) {
return fmt.Errorf("version 1 group key request " +
"tapscript root must not be all zeros")
}
}

if req.ExternalKey.IsSome() && req.Version != GroupKeyV1 {
return fmt.Errorf("external key can only be specified for " +
"version 1 group key request")
}

return nil
}

Expand Down
16 changes: 7 additions & 9 deletions proof/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"fmt"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/commitment"
"github.com/lightninglabs/taproot-assets/fn"
)

// Blob either represents a serialized proof file, including the checksum or a
Expand Down Expand Up @@ -388,21 +386,21 @@ func committedProofs(baseProof *Proof, tapTreeRoot *commitment.TapCommitment,
if newAsset.GroupKey != nil {
groupKey := newAsset.GroupKey

// Check if the asset is the group anchor.
err := groupAnchorVerifier(&newAsset.Genesis, groupKey)
if err == nil {
// TODO(ffranr): Handle custom tapscript
// subtree.
groupReveal, err := asset.NewGroupKeyRevealV1(
*groupKey.RawKey.PubKey,
newAsset.Genesis.ID(),
fn.None[chainhash.Hash](),
// At this point, we know that the asset is the
// group anchor. We'll now create the group key
// reveal for this asset.
groupReveal, err := asset.NewGroupKeyReveal(
*groupKey, newAsset.Genesis.ID(),
)
if err != nil {
return nil, fmt.Errorf("unable to " +
"create group key reveal")
}

assetProof.GroupKeyReveal = &groupReveal
assetProof.GroupKeyReveal = groupReveal
}
}

Expand Down
12 changes: 8 additions & 4 deletions tapgarden/planter.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ func buildGroupReqs(genesisPoint wire.OutPoint, assetOutputIndex uint32,
genTXs = append(genTXs, *genTx)

newGroupKey := &asset.GroupKey{
Version: groupReq.Version,
RawKey: *seedling.GroupInternalKey,
TapscriptRoot: seedling.GroupTapscriptRoot,
}
Expand Down Expand Up @@ -1786,11 +1787,14 @@ func (c *ChainPlanter) sealBatch(ctx context.Context, params SealParams,
switch {
case ok:
// Set the provided witness; it will be validated below.
subtreeRoot := groupReq.CustomTapscriptRoot
groupKey = &asset.GroupKey{
RawKey: groupReq.RawKey,
GroupPubKey: genTX.TweakedKey,
TapscriptRoot: groupReq.TapscriptRoot,
Witness: groupWitness.Witness,
Version: groupReq.Version,
RawKey: groupReq.RawKey,
GroupPubKey: genTX.TweakedKey,
TapscriptRoot: groupReq.TapscriptRoot,
CustomTapscriptRoot: subtreeRoot,
Witness: groupWitness.Witness,
}

default:
Expand Down

0 comments on commit cabfd1d

Please sign in to comment.