Skip to content

Commit 2bd9192

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 5225722 commit 2bd9192

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

tapgarden/planter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,11 @@ 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-issuance or regular assets, the group internal key
2672+
// shouldn't be set. It is, however, set for re-issuance with
2673+
// an external key, because the internal group key is the key
2674+
// we compare the external key against.
2675+
if req.GroupInternalKey != nil && req.ExternalKey.IsNone() {
26722676
return fmt.Errorf("cannot specify group internal key " +
26732677
"without enabling emission")
26742678
}

tapgarden/seedling.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,49 @@ 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() {
188-
groupKeyBytes := c.GroupInfo.GroupPubKey.SerializeCompressed()
189-
return fmt.Errorf("can't sign with group key %x", groupKeyBytes)
186+
switch {
187+
// If we have an external key, we need to check that the group key
188+
// matches the external key.
189+
case c.ExternalKey.IsSome():
190+
err := fn.MapOptionZ(
191+
c.ExternalKey, func(extKey asset.ExternalKey) error {
192+
if group.GroupKey == nil {
193+
return fmt.Errorf("group key is nil")
194+
}
195+
196+
if group.GroupKey.RawKey.PubKey == nil {
197+
return fmt.Errorf("group raw key is " +
198+
"nil")
199+
}
200+
201+
pk, err := extKey.PubKey()
202+
if err != nil {
203+
return fmt.Errorf("error getting "+
204+
"external key: %w", err)
205+
}
206+
207+
if !pk.IsEqual(group.RawKey.PubKey) {
208+
return fmt.Errorf("external key " +
209+
"does not match group key")
210+
}
211+
212+
return nil
213+
},
214+
)
215+
if err != nil {
216+
return fmt.Errorf("error validating external key: %w",
217+
err)
218+
}
219+
220+
// If it's not an external key, we need to check that we can actually
221+
// sign with the group key.
222+
default:
223+
if !group.GroupKey.IsLocal() {
224+
groupPubKey := c.GroupInfo.GroupPubKey
225+
groupKeyBytes := groupPubKey.SerializeCompressed()
226+
return fmt.Errorf("can't sign with group key %x",
227+
groupKeyBytes)
228+
}
190229
}
191230

192231
// The seedling asset type must match the group asset type.

0 commit comments

Comments
 (0)