hyperledger/fabric · error

Unknown principal anonymity type: %d

Error message

Unknown principal anonymity type: %d

What it means

After unmarshaling the MSPIdentityAnonymity payload of an ANONYMITY-classified principal, satisfiesPrincipalInternalV13 accepts only ANONYMOUS and NOMINAL anonymity types. Any other enum value (or the unset zero value interpreted as unknown) falls into the default branch and produces this formatted error naming the offending numeric type.

Source

Thrown at msp/mspimpl.go:603

// The function implements the additional behavior expected of an MSP starting from v1.3.
// For pre-v1.3 functionality, the function calls the satisfiesPrincipalInternalPreV13.
func (msp *bccspmsp) satisfiesPrincipalInternalV13(id Identity, principal *m.MSPPrincipal) error {
	switch principal.PrincipalClassification {
	case m.MSPPrincipal_COMBINED:
		return errors.New("SatisfiesPrincipalInternal shall not be called with a CombinedPrincipal")
	case m.MSPPrincipal_ANONYMITY:
		anon := &m.MSPIdentityAnonymity{}
		err := proto.Unmarshal(principal.Principal, anon)
		if err != nil {
			return errors.Wrap(err, "could not unmarshal MSPIdentityAnonymity from principal")
		}
		switch anon.AnonymityType {
		case m.MSPIdentityAnonymity_ANONYMOUS:
			return errors.New("Principal is anonymous, but X.509 MSP does not support anonymous identities")
		case m.MSPIdentityAnonymity_NOMINAL:
			return nil
		default:
			return errors.Errorf("Unknown principal anonymity type: %d", anon.AnonymityType)
		}

	default:
		// Use the pre-v1.3 function to check other principal types
		return msp.satisfiesPrincipalInternalPreV13(id, principal)
	}
}

// satisfiesPrincipalInternalV142 takes as arguments the identity and the principal.
// The function returns an error if one occurred.
// The function implements the additional behavior expected of an MSP starting from v2.0.
// For v1.3 functionality, the function calls the satisfiesPrincipalInternalPreV13.
func (msp *bccspmsp) satisfiesPrincipalInternalV142(id Identity, principal *m.MSPPrincipal) error {
	_, okay := id.(*identity)
	if !okay {
		return errors.New("invalid identity type, expected *identity")
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Always set AnonymityType explicitly to ANONYMOUS or NOMINAL before marshaling the MSPIdentityAnonymity.
  2. Check the numeric value printed in the error against the mspproto.MSPIdentityAnonymity_MSPIdentityAnonymityType enum to identify the mismatch.
  3. Align fabric versions so the policy producer and the evaluating MSP agree on the anonymity enum values.

Example fix

// before
anon := &m.MSPIdentityAnonymity{} // AnonymityType left unset (0)
b, _ := proto.Marshal(anon)
// after
anon := &m.MSPIdentityAnonymity{AnonymityType: m.MSPIdentityAnonymity_NOMINAL}
b, _ := proto.Marshal(anon)
Defensive patterns

Strategy: validation

Validate before calling

anon := &m.MSPIdentityAnonymity{}
if err := proto.Unmarshal(principal.Principal, anon); err == nil {
	switch anon.AnonymityType {
	case m.MSPIdentityAnonymity_ANONYMOUS, m.MSPIdentityAnonymity_NOMINAL:
		// ok
	default:
		return fmt.Errorf("invalid anonymity type %d", anon.AnonymityType)
	}
}

Type guard

func hasKnownAnonymityType(p *m.MSPPrincipal) bool {
	anon := &m.MSPIdentityAnonymity{}
	if p == nil || p.PrincipalClassification != m.MSPPrincipal_ANONYMITY || proto.Unmarshal(p.Principal, anon) != nil {
		return false
	}
	return anon.AnonymityType == m.MSPIdentityAnonymity_ANONYMOUS || anon.AnonymityType == m.MSPIdentityAnonymity_NOMINAL
}

Prevention

When it happens

Trigger: An MSPPrincipal with PrincipalClassification=ANONYMITY whose unmarshaled MSPIdentityAnonymity.AnonymityType is not ANONYMOUS or NOMINAL - typically 0 (unset) from an incompletely initialized message, or a value from a newer proto enum unknown to this build.

Common situations: Constructing the MSPIdentityAnonymity struct without setting AnonymityType before marshaling; deserializing policies produced by a newer fabric version with added enum values; corrupted policy bytes that decode to a garbage enum.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/78fa6c1f170db849. Report an issue: GitHub.