toip.tools

class · Browser and Node

Tagged

A wrapper class for representing a CBOR tag with an arbitrary nested value.

Tagged is a symmetric primitive: it can be passed to encode() to emit a CBOR tag header followed by the encoded form of value, and it can be returned from a tag decoder (via Tagged.decoder(tag) or Tagged.preserve()) to round-trip a tag through decode without losing the tag number.

Use Tagged for one-off tag handling where defining a dedicated typeEncoders entry and tag decoder pair would be heavyweight, e.g. when wrapping a structure in a single application-specific tag (COSE, dCBOR envelopes, etc.).

For systematic mapping of a JS type to a tag (e.g. CID -> tag 42), prefer a dedicated typeEncoders entry instead.

@toip-tools/coseView source
TypeScriptImport
import { Tagged } from "@toip-tools/cose";

Constructor

TypeScriptConstructor
new (tag: number, value: any): Tagged;

Parameters

tagrequired
number
  • CBOR tag number, a non-negative integer
valuerequired
any
  • The value to be tagged; encoded recursively

Returns