Skip to content

WrappedKeyCodec

WrappedKeyCodec<Brand, Kind> = object

Defined in: src/codecs/wrapped/index.ts:102

Codec returned by createWrappedKeyId.

Wraps a caller-owned integer lookup key into a public Id and recovers it on unwrap. The codec is deterministic under fixed key material: the same lookup key always yields the same public ID (equality leakage).

  • wrap / unwrap / safeUnwrap / safeVerify are async (WebCrypto).
  • is, parse, safeParse, and toJsonSchema are synchronous and require no key material — they validate prefix and base32 shape only.
  • The Kind type parameter drives value types at the TypeScript boundary: u32 / i32number; u64 / i64bigint.

Security properties (correctness-grade verification, not AEAD):

  • The construction is deterministic — the same lookup key always yields the same public ID (equality leakage).
  • The verification tag is a fixed 64-bit (8-byte) truncation of a domain-separated HMAC over the brand, kind, and lookup key lane.
  • False-accept rate is approximately keyring_size / 2^64 per unwrap trial — correctness-grade verification, not AEAD-strength origin authentication.
  • Consumers requiring full AEAD guarantees must use a different construction.

Brand extends string

Kind extends WrappedKind

readonly ~standard: StandardSchemaProps<Brand>

Defined in: src/codecs/wrapped/index.ts:147

fromUUID(value): Id<Brand>

Defined in: src/codecs/wrapped/index.ts:159

Parses a UUID string into an Id<Brand>. Accepts case-insensitive 8-4-4-4-12 hyphenated form only. Throws IdsError with code: "invalid_id" on bad input. See ADR-0024.

string

Id<Brand>


is(value): value is Id<Brand>

Defined in: src/codecs/wrapped/index.ts:141

Strict type guard: true only for already-canonical Id<Brand> strings.

unknown

value is Id<Brand>


parse(value): Id<Brand>

Defined in: src/codecs/wrapped/index.ts:143

Normalise to canonical form, or throw on parse failure.

unknown

Id<Brand>


safeFromUUID(value): ParseResult<Brand>

Defined in: src/codecs/wrapped/index.ts:164

Non-throwing UUID parse. Returns { ok: true, id } or { ok: false, error: "not_string" | "invalid_uuid" }. See ADR-0024.

unknown

ParseResult<Brand>


safeParse(value): ParseResult<Brand>

Defined in: src/codecs/wrapped/index.ts:145

Normalise to canonical form, or return { ok: false, error }.

unknown

ParseResult<Brand>


safeUnwrap(input): Promise<UnwrapResult<Brand, Kind>>

Defined in: src/codecs/wrapped/index.ts:126

Non-throwing path for untrusted input.

Structurally parses input first (same rules as safeParse), then verifies the payload. Returns { ok: false, error } on any failure — ParseError for structural problems or "verification_failed" for tag mismatch — without throwing. Tamper, wrong keyring, and revoked-key cases all surface as "verification_failed".

unknown

Promise<UnwrapResult<Brand, Kind>>


safeVerify(input): Promise<SafeVerifyResult<Brand>>

Defined in: src/codecs/wrapped/index.ts:139

Verify-only alias of safeUnwrap for untrusted input.

Structurally parses input, then verifies the payload — returning { ok: true, id } on success (dropping the recovered lookupKey) or { ok: false, error } on any failure, without throwing. Deliberately redundant with safeUnwrap (a wrapped ID cannot be verified without unwrapping it): use safeUnwrap when the lookup key is needed, and safeVerify to gate on authenticity alone. This is the method that lets the codec satisfy the HTTP adapters’ IdVerifiableCodec interface under verify: true. See ADR-0036.

unknown

Promise<SafeVerifyResult<Brand>>


toJsonSchema(): JsonSchema

Defined in: src/codecs/wrapped/index.ts:146

JsonSchema


toUUID(id): string

Defined in: src/codecs/wrapped/index.ts:153

Converts a trusted Id<Brand> to an RFC 9562 canonical (lowercase, hyphenated) UUID string by reinterpreting the 16-byte payload verbatim. Total — cannot fail. Returns a plain string (brand is shed). See ADR-0024.

Id<Brand>

string


unwrap(id): Promise<LookupKeyForKind<Kind>>

Defined in: src/codecs/wrapped/index.ts:116

Verify the payload of a trusted Id<Brand> and return the lookup key.

Throws IdsError with code: "verification_failed" if no entry in the wrapping keyring matches the payload tag. Use safeUnwrap for untrusted input.

Id<Brand>

Promise<LookupKeyForKind<Kind>>


wrap(lookupKey): Promise<Id<Brand>>

Defined in: src/codecs/wrapped/index.ts:108

Wrap lookupKey into a public ID using the current (first) wrapping key.

Throws if lookupKey is out of range or the wrong JS type for Kind.

LookupKeyForKind<Kind>

Promise<Id<Brand>>