canopy-network/canopy · error

unrecognized public key format

Error message

unrecognized public key format

What it means

Generic guard raised in NewPublicKeyFromBytes when the byte slice length matches none of the supported key sizes (Ed25519, ETH/secp256k1, secp256k1, BLS12-381) AND NewMultiBLSFromPublicKey also fails to parse it as a multisig key. The byte slice is not recognizable as any supported public key format.

Source

Thrown at lib/crypto/key.go:116

	}
	return NewPublicKeyFromBytes(bz)
}

// NewPublicKeyFromBytes() creates a new PublicKeyI interface from a byte slice
func NewPublicKeyFromBytes(bz []byte) (PublicKeyI, error) {
	switch len(bz) {
	case Ed25519PubKeySize:
		return BytesToED25519Public(bz), nil
	case ETHSECP256K1PubKeySize, ETHSECP256K1PubKeySize + 1:
		return BytesToEthSECP256K1Public(bz)
	case SECP256K1PubKeySize:
		return BytesToSECP256K1Public(bz)
	case BLS12381PubKeySize:
		return BytesToBLS12381Public(bz)
	}
	multiKey, err := NewMultiBLSFromPublicKey(bz)
	if err != nil {
		return nil, fmt.Errorf("unrecognized public key format")
	}
	return multiKey, nil
}

// PrivateKeyToFile() writes a private key to a file located at filepath
func PrivateKeyToFile(key PrivateKeyI, filepath string) error {
	bz, err := json.MarshalIndent(key, "", "  ")
	if err != nil {
		return err
	}
	return os.WriteFile(filepath, bz, 0600)
}

// NewPrivateKeyFromString() creates a new PrivateKeyI interface from a hex string
func NewPrivateKeyFromString(s string) (PrivateKeyI, error) {
	bz, err := hex.DecodeString(s)
	if err != nil {
		return nil, err

View on GitHub (pinned to ee8197d91d)

Solutions

  1. Check the byte length of the input; it must match one of the supported key sizes (e.g. 32 for ed25519, 33/65 for secp256k1).
  2. If the key is a multisig BLS key, verify it is serialized in the format NewMultiBLSFromPublicKey expects.
  3. Trace where the bytes were produced/stored — truncation or wrong encoding (hex vs raw) is the usual cause.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/crypto/key.go:116 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/b9869b2493453b58. Report an issue: GitHub.