npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@m-doc/mdl

v1.1.0

Published

ISO/IEC 18013-5 mDL profile: element identifiers, age attestations and driving privileges

Readme

The mDL profile of ISO/IEC 18013-5:2021: what its element identifiers are, how each one is encoded, and the handful of rules that are easy to get wrong when issuing or verifying one.

@m-doc/core reads and writes the document; this package says what belongs in it. It defines no value models of its own — everything here is constants, types and functions over the claims you already have.

Part of m-doc. Used throughout the runnable examples.

Installation

npm i @m-doc/mdl

Age attestations

An mDL conveys age without revealing a date of birth, through age_over_NN elements. §7.2.5 defines what a request for one means, and it is not "return the element with that name":

provide the nearest age attestation equal to or larger than NN with value TRUE, or smaller than NN with value FALSE

import { resolveAgeAttestation } from '@m-doc/mdl'

// The document holds only age_over_21, and that answers a request for 18
resolveAgeAttestation({ age_over_21: true }, 18)
// → { identifier: 'age_over_21', age: 21, value: true }

// Not being over 65 says nothing about being over 18
resolveAgeAttestation({ age_over_65: false }, 18)
// → undefined

Issuing works from the other side. §7.2.5 requires the values to hold at the MSO's validFrom, not at the moment of issuance, so that is what you pass:

import { ageAt, buildAgeAttestations, readAgeAttestations } from '@m-doc/mdl'

buildAgeAttestations(birthDate, validFrom, [16, 18, 21, 65])
// → { age_over_16: true, age_over_18: true, age_over_21: false, age_over_65: false }

readAgeAttestations(claims)     // every age_over_NN present, ascending
// → [{ identifier: 'age_over_18', age: 18, value: true }, …]

ageAt(birthDate, someDate)      // whole years

Driving privileges

The claim arrives as decoded CBOR — an array of Maps. Read it into something typed:

import { privilegesFor, readDrivingPrivileges } from '@m-doc/mdl'

readDrivingPrivileges(claims.driving_privileges)
// → [{ vehicleCategoryCode: 'B', issueDate: DateOnly, codes: [{ code: '01', sign: '=', value: '1' }] }]

privilegesFor(claims.driving_privileges, 'B')

Element identifiers and encodings

Every element Table 5 names has one fixed encoding — there is no choosing.

import { encodingFor, MDL_ELEMENT_ENCODING } from '@m-doc/mdl'

encodingFor('family_name')          // 'tstr'
encodingFor('birth_date')           // 'full-date'
encodingFor('portrait')             // 'bstr'
encodingFor('height')               // 'uint'
encodingFor('driving_privileges')   // 'structure'
encodingFor('issue_date')           // 'tdate-or-full-date' — Table 5 allows either
encodingFor('age_over_65')          // 'bool' — any NN, not only the listed ones
encodingFor('org.example.custom')   // undefined

MDL_ELEMENT_ENCODING is the map itself, if you would rather iterate it. encodingFor is the one to call, because it also answers for age_over_NN, where NN is open-ended.

import {
  MDL_DOC_TYPE,               // 'org.iso.18013.5.1.mDL'
  MDL_NAMESPACE,              // 'org.iso.18013.5.1'
  jurisdictionNamespace,      // jurisdictionNamespace('DE') → 'org.iso.18013.5.1.DE'
  MDL_MANDATORY_ELEMENTS,     // Table 5, presence M
  MDL_OPTIONAL_ELEMENTS,      // Table 5, presence O
  parseAgeOverIdentifier,     // 'age_over_18' → 18
  Sex,                        // ISO/IEC 5218
  EYE_COLOURS,
  HAIR_COLOURS,
} from '@m-doc/mdl'

The identifier types are exported too — MdlElementIdentifier, MdlMandatoryElementIdentifier, MdlOptionalElementIdentifier, AgeOverIdentifier, MdlEncoding, EyeColour, HairColour, SexValue — so a typo in an element name is a compile error rather than a claim nobody reads.

Profile checks

import { findMissingMandatoryElements, isExpired, isNotYetValid } from '@m-doc/mdl'

findMissingMandatoryElements(claims)   // Table 5 elements the document lacks
isExpired(claims)                      // undefined where expiry_date was not disclosed
isNotYetValid(claims, someDate)

findMissingMandatoryElements is a finding on a document that was meant to be complete — one straight from an issuer. A presented mDL is allowed to disclose a subset; that is the point of selective disclosure.

isExpired and isNotYetValid return undefined rather than false when the date they need was not disclosed, so "we do not know" never reads as "it is fine".

Requirements

Node 20.19 or newer. Ships ESM and CJS, with type declarations for both. Depends only on @m-doc/core, and only for its DateOnly type.

License

Apache-2.0.