canopy-network/canopy · error

invalid bls key

Error message

invalid bls key

What it means

Raised in BLS12381PrivateKey.UnmarshalJSON after the hex string decodes and BytesToBLS12381PrivateKey succeeds, but the returned key fails the type assertion to *BLS12381PrivateKey. It indicates the key factory produced an unexpected key type — effectively a corrupted or non-standard key representation in the JSON field.

Source

Thrown at lib/crypto/bls.go:135

func (b *BLS12381PrivateKey) MarshalJSON() ([]byte, error) { return json.Marshal(b.String()) }

// UnmarshalJSON() is the json.Unmarshaler implementation for the BLS12381PrivateKey object
func (b *BLS12381PrivateKey) UnmarshalJSON(bz []byte) (err error) {
	var hexString string
	if err = json.Unmarshal(bz, &hexString); err != nil {
		return
	}
	bz, err = hex.DecodeString(hexString)
	if err != nil {
		return
	}
	pk, err := BytesToBLS12381PrivateKey(bz)
	if err != nil {
		return err
	}
	bls, ok := pk.(*BLS12381PrivateKey)
	if !ok {
		return errors.New("invalid bls key")
	}
	*b = *bls
	return
}

// BLS12381PublicKey is a public key wrapper implementation that satisfies the PublicKeyI interface
// Boneh-Lynn-Shacham (BLS) signature scheme enables compact, aggregable digital signatures for secure, verifiable
// messages between multiple parties
type BLS12381PublicKey struct {
	kyber.Point
	scheme *bdn.Scheme
}

// NewBLSPublicKey creates a new BLSPublicKey reference from a kyber point
func NewBLS12381PublicKey(publicKey kyber.Point) *BLS12381PublicKey {
	return &BLS12381PublicKey{Point: publicKey, scheme: newBLSScheme()}
}

View on GitHub (pinned to ee8197d91d)

Solutions

  1. Re-export/regenerate the key; the stored JSON value does not represent a valid BLS12-381 private key.
  2. Verify the JSON field is a hex-encoded BLS private key of the expected byte length (32 bytes).
  3. Check BytesToBLS12381PrivateKey wiring if this occurs on freshly generated keys.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/crypto/bls.go:135 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of canopy-network/canopy@ee8197d91d (2026-09-06). Data as JSON: /api/errors/6774974dcc9ee909. Report an issue: GitHub.