Skip to content

Commit 9ec0c8d

Browse files
committed
tapgarden: adjust validation for external key re-issuance
This commit fixes two checks that prevented us to re-issue more assets into an existing group using an external group key.
1 parent bb5a2a6 commit 9ec0c8d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

tapgarden/planter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,12 @@ func (c *ChainPlanter) prepAssetSeedling(ctx context.Context,
26682668
// If a group internal key or tapscript root is specified, emission must
26692669
// also be enabled.
26702670
if !req.EnableEmission {
2671-
if req.GroupInternalKey != nil {
2671+
// For re-issuing grouped assets or regular (non-grouped)
2672+
// assets, the group internal key shouldn't be set. It is,
2673+
// however, set for re-issuance with an external key, because
2674+
// the internal group key is the key we compare the external key
2675+
// against.
2676+
if req.GroupInternalKey != nil && req.ExternalKey.IsNone() {
26722677
return fmt.Errorf("cannot specify group internal key " +
26732678
"without enabling emission")
26742679
}

tapgarden/seedling.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,43 @@ func (c Seedling) validateFields() error {
183183
func (c Seedling) validateGroupKey(group asset.AssetGroup,
184184
anchorMeta *proof.MetaReveal) error {
185185

186-
// We must be able to sign with the group key.
187-
if !group.GroupKey.IsLocal() {
186+
// If an external key isn't specified but the actual group key used
187+
// isn't local to this daemon, we won't be able to sign with it.
188+
if c.ExternalKey.IsNone() && !group.GroupKey.IsLocal() {
188189
groupKeyBytes := c.GroupInfo.GroupPubKey.SerializeCompressed()
189190
return fmt.Errorf("can't sign with group key %x", groupKeyBytes)
190191
}
191192

193+
// If there is an external key defined, we need to check that it matches
194+
// the group key.
195+
err := fn.MapOptionZ(
196+
c.ExternalKey, func(extKey asset.ExternalKey) error {
197+
if group.GroupKey == nil {
198+
return fmt.Errorf("group key is nil")
199+
}
200+
201+
if group.GroupKey.RawKey.PubKey == nil {
202+
return fmt.Errorf("group raw key is nil")
203+
}
204+
205+
pk, err := extKey.PubKey()
206+
if err != nil {
207+
return fmt.Errorf("error getting external "+
208+
"key: %w", err)
209+
}
210+
211+
if !pk.IsEqual(group.RawKey.PubKey) {
212+
return fmt.Errorf("external key does not " +
213+
"match group key")
214+
}
215+
216+
return nil
217+
},
218+
)
219+
if err != nil {
220+
return fmt.Errorf("error validating external key: %w", err)
221+
}
222+
192223
// The seedling asset type must match the group asset type.
193224
if c.AssetType != group.Genesis.Type {
194225
return fmt.Errorf("seedling type does not match "+

0 commit comments

Comments
 (0)