hyperledger/fabric · error

invalid type of envelope for chaincode package

Error message

invalid type of envelope for chaincode package

What it means

InitFromBuffer extracts a signed CDS from the envelope and then verifies the channel header type equals HeaderType_CHAINCODE_PACKAGE. An envelope of any other type is rejected, since only chaincode-package envelopes carry signed deployment specs.

Source

Thrown at core/common/ccprovider/sigcdspackage.go:235

	}

	return nil
}

// InitFromBuffer sets the buffer if valid and returns ChaincodeData
func (ccpack *SignedCDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {
	env := &common.Envelope{}
	err := proto.Unmarshal(buf, env)
	if err != nil {
		return nil, errors.New("failed to unmarshal envelope from bytes")
	}
	cHdr, sDepSpec, err := ccpackage.ExtractSignedCCDepSpec(env)
	if err != nil {
		return nil, err
	}

	if cHdr.Type != int32(common.HeaderType_CHAINCODE_PACKAGE) {
		return nil, errors.New("invalid type of envelope for chaincode package")
	}

	depSpec := &pb.ChaincodeDeploymentSpec{}
	err = proto.Unmarshal(sDepSpec.ChaincodeDeploymentSpec, depSpec)
	if err != nil {
		return nil, errors.New("error getting deployment spec")
	}

	databytes, id, data, err := ccpack.getCDSData(sDepSpec)
	if err != nil {
		return nil, err
	}

	ccpack.buf = buf
	ccpack.sDepSpec = sDepSpec
	ccpack.depSpec = depSpec
	ccpack.env = env
	ccpack.data = data

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Load the file produced by `peer chaincode signpackage` — its envelope type is CHAINCODE_PACKAGE
  2. Verify you are not passing a transaction/config envelope to GetCCPackage
  3. Check for mixed-up files in the deployment artifacts directory

Example fix

// before
envBytes := readTxEnvelopeBytes() // HeaderType_TRANSACTION
// after
envBytes := readSignedPackageBytes() // HeaderType_CHAINCODE_PACKAGE
Defensive patterns

Strategy: validation

Validate before calling

func isChaincodePackageEnv(env *common.Envelope) (bool, error) {
    p := &common.Payload{}
    if err := proto.Unmarshal(env.Payload, p); err != nil { return false, err }
    h := &common.Header{}
    if err := proto.Unmarshal(p.Header, h); err != nil { return false, err }
    return h.ChannelHeader != nil && h.ChannelHeader.Type == int32(common.HeaderType_CHAINCODE_PACKAGE), nil
}

Type guard

func isChaincodePackageType(t int32) bool { return t == int32(common.HeaderType_CHAINCODE_PACKAGE) }

Try / catch

cd, err := GetCCPackage(buf, idFunc)
if err != nil {
    if strings.Contains(err.Error(), "invalid type of envelope") {
        return fmt.Errorf("wrong artifact: expected a CHAINCODE_PACKAGE envelope: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: InitFromBuffer called with a valid protobuf Envelope whose header type is not CHAINCODE_PACKAGE (e.g. a transaction, config, or ESCC/VSCC envelope).

Common situations: Accidentally passing a transaction envelope or another artifact file to the package loader; confusing signed package files with other fabric envelope files on disk.

Related errors


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