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/context

v1.1.0

Published

WebCrypto and X.509 bindings for @m-doc/core, for Node, the browser and React Native

Readme

@m-doc/core does no cryptography itself. It takes an MdocContext holding the primitives it needs — hashing, ECDH, COSE signing, X.509 chain validation — so an application can bind it to whatever its platform provides.

This package is a ready-made one, built on WebCrypto, @noble/curves and @peculiar/x509. Nothing in it is Node-specific: the same implementation runs in the browser, and in React Native with a WebCrypto polyfill.

Part of m-doc. Every runnable example starts by creating one of these.

Installation

npm i @m-doc/context

Usage

import { createMdocContext } from '@m-doc/context'

const ctx = createMdocContext()

await DeviceResponse.decode(bytes).verify({ trustedCertificates, sessionTranscript }, ctx)

createMdocContext reads globalThis.crypto, which Node 20 and every current browser provide, and throws at construction where there is none. Pass one in where the runtime has no global:

import { polyfillWebCrypto } from 'my-react-native-polyfill'

const ctx = createMdocContext({ crypto: polyfillWebCrypto })

That is the whole API:

type MdocContextOptions = { crypto?: WebCrypto }

const createMdocContext: (options?: MdocContextOptions) => MdocContext

What it implements

| Operation | Implementation | | --- | --- | | cose.sign1.sign / verify | ECDSA P-256, compact signatures, @noble/curves | | cose.mac0.sign / verify | HMAC-SHA-256, @noble/hashes | | crypto.calculateEphemeralMacKey | ECDH P-256 → HKDF-SHA-256 over the session transcript digest, @panva/hkdf | | crypto.digest / crypto.random | WebCrypto subtle.digest and getRandomValues | | x509.* | @peculiar/x509 for parsing and chain building, jose for public-key import |

Two things to know

This context is ES256-only. SignatureAlgorithm in @m-doc/core names EdDSA, ES384/512, PS256/384/512 and RS256/384/512, but this implementation covers P-256 alone. Supply your own MdocContext for anything else — that is what the interface is for.

Signature verification deliberately accepts non-canonical (high-S) signatures, because they do occur in the wild.

Trust anchors should be roots, not leaves. verifyCertificateChain builds the chain, requires a presented certificate to equal one of the trust anchors, then verifies each link's signature and validity period. Passing a document signer as its own anchor degenerates to an equality check, and skips the validity period along with it. Anchor on IACA roots — a VICAL is where you get them.

Requirements

Node 20.19 or newer, or any runtime with WebCrypto. Ships ESM and CJS, with type declarations for both.

License

Apache-2.0.