@@ -183,10 +183,49 @@ func (c Seedling) validateFields() error {
183183func (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