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

@lp-labs/document-key-envelope

v0.1.0

Published

Versioned AES-KW and RSA-OAEP envelopes for AES-GCM document keys.

Readme

@lp-labs/document-key-envelope

Wrap an AES-256-GCM document CryptoKey with WebCrypto AES-KW or RSA-OAEP and unwrap it as a non-extractable encryption key. The envelope is versioned and records the wrapping algorithm; raw document key bytes are never returned by this API.

Install

npm install @lp-labs/document-key-envelope

No runtime or peer dependencies; ESM, CommonJS, and declarations are included.

Quickstart

import { webcrypto } from 'node:crypto';
import { unwrapDocumentKey, wrapDocumentKey } from '@lp-labs/document-key-envelope';

const wrappingKey = await webcrypto.subtle.generateKey({ name: 'AES-KW', length: 256 }, false, [
  'wrapKey',
  'unwrapKey',
]);
const documentKey = await webcrypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, [
  'encrypt',
  'decrypt',
]);
const envelope = await wrapDocumentKey(documentKey, wrappingKey);
const restored = await unwrapDocumentKey(envelope, wrappingKey);
if (restored.extractable) throw new Error('Unwrapped key must be non-extractable');

API and customization

wrapDocumentKey(documentKey, wrappingKey, subtle?) returns a version 1 DocumentKeyEnvelope (AES-KW or RSA-OAEP, AES-GCM, wrapped bytes). unwrapDocumentKey(envelope, unwrappingKey, subtle?) returns a non-extractable 256-bit AES-GCM CryptoKey with encrypt/decrypt usages. copyDocumentKeyEnvelope validates and clones an envelope. DocumentKeyEnvelope is the TypeScript export. Omit subtle to use global WebCrypto or inject SubtleCrypto.

Wrapping requires an extractable input CryptoKey because the WebCrypto wrapKey operation requires export internally; this library never exposes those key bytes. AES-KW requires a compatible key with wrap/unwrap usage; RSA-OAEP requires a compatible public/private pair. Unsupported versions, mismatched key algorithms, invalid envelope sizes, or cryptographic failures reject.

Runtime and scope

Requires WebCrypto wrapKey/unwrapKey support for AES-KW and/or RSA-OAEP. The caller provisions, stores, rotates, and authorizes wrapping keys and should protect envelopes as sensitive data. This does not provide a key-management service, password derivation, native PDF encryption, or trust validation.

Exports

Runtime: wrapDocumentKey, unwrapDocumentKey, copyDocumentKeyEnvelope. Type: DocumentKeyEnvelope.

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.