Skip to content

cose

COSE wire-format layer (FIP-1253): typed structures ↔ bytes for the envelope’s protected/unprotected headers, Enc_structure (AAD), and the tagged CBOR envelope itself. See docs/tech-spec.md, “Wire profile” and “CDDL”. No AEAD, no key wrap, no chunk framing — those live above this.

InterfaceDescription
CborValueObjectPlain-object form of CborValue. Defined as an interface because TypeScript does not allow this recursive type through Record<string, CborValue>.
DecodedEnvelope-
DecodedProtectedHeaderA decoded protected header with its original encoded bytes. Use bytes verbatim when building the Enc_structure.
DecodedRecipientA decoded COSE_recipient. No key unwrapping happens at this layer.
EncodeEnvelopeInput-
ProtectedHeaderFieldsLogical protected-header fields, independent of their CBOR encoding.
RecipientInputInput for one COSE_recipient. This layer shapes it; it never wraps a key.
Type AliasDescription
AlgOne of the two content-encryption schemes supported by this package.
CborValueCBOR values supported by this profile.
EnvelopeTagWhich of the two COSE containers this is — and so which context string the AAD carries.
UnprotectedHeaderMapContent unprotected header map.
VariableDescription
ALG_A256KWAES key wrap, RFC 9053 §6.2.1. The only wrap this version supports.
ALG_ECDH_ES_A256KWECDH-ES + AES key wrap. Deferred — defined here so recipients using it can be recognised and skipped, not unwrapped.
ENVELOPE_TYPEtyp header value identifying this envelope format.
HEADER_ALGalg, RFC 9052 §3.1. Selects the encryption scheme, see the ALG_* constants.
HEADER_APP_METADATAapp_metadata, private use. Opaque, string-keyed map carried and authenticated but never interpreted.
HEADER_CHUNK_SIZEchunk_size, algorithm-specific label per RFC 9052 §3.1. Required for the chunked scheme, must not appear when alg is ALG_AES_256_GCM (3) — whole-object AEAD has no chunk layout.
HEADER_CONTENT_TYPEcontent_type, RFC 9052 §3.1. Media type of the plaintext. Optional.
HEADER_CRITcrit, RFC 9052 §3.1. Names header labels a processor must understand and act on. For the acceptance rule see CriticalHeaderError.
HEADER_IViv, RFC 9052 §3.1: a 12-byte nonce (scheme 1) or a 7-byte base nonce (chunked).
HEADER_KIDkid, RFC 9052 §3.1. Recipients only; a byte string. Never a content header in this profile.
HEADER_PARTIAL_IVPartial IV, RFC 9052 §3.1. Forbidden in both content buckets.
HEADER_PLAINTEXT_LENGTHplaintext_length, private use (RFC 9052 §3.1). Optional; written only when the caller knew the content length before the envelope was emitted.
HEADER_TYPtyp, RFC 9052 §3.1. Must equal ENVELOPE_TYPE.
MAX_APP_METADATA_DEPTHHow deep the allowlist walk in headers.ts will descend into an app_metadata value or a recipient’s unprotected map, on encode and decode alike.
MAX_ENVELOPE_SIZECeiling on the encoded envelope alone, not the detached ciphertext after it.
TAG_ENCRYPTCOSE_Encrypt, RFC 9052 §5.1. Carries a recipients array for key wrapping.
TAG_ENCRYPT0COSE_Encrypt0, RFC 9052 §5.2. No recipients array; used when the CEK is out of band.
FunctionDescription
assertValidRecipientHeadersValidate the protected and unprotected headers of a COSE_recipient without unwrapping its key.
decodeEnvelopeDecode the envelope at the start of data. Bytes after envelopeLength are untouched detached ciphertext.
decodeProtectedHeaderDecode a protected header from its exact wire bytes and preserve those bytes in DecodedProtectedHeader.
decodeUnprotectedHeaderValidate and return the content unprotected header.
describeCborTypeReturn a human-readable type name for validation errors.
encodeEnvelopeEncode an envelope with detached ciphertext. The caller appends the ciphertext separately. See docs/tech-spec.md, “Blob layout”.
encodeProtectedHeaderEncode the protected header as a deterministically encoded CBOR map.
encodeUnprotectedHeaderBuild the content unprotected header. This profile defines no unprotected content parameters, so the encoder always emits a new empty map.
encStructureBuild the Enc_structure bytes for an envelope: [context, protected, external_aad], with external_aad always empty.
ivLengthForAlgThe IV length this profile requires for alg: 12 bytes (scheme 1) or 7 bytes (chunked base nonce).