# webcrypto-core

> Common layer to be used by crypto libraries based on WebCrypto API for input validation.

Latest version **1.9.2** (published 2026-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install webcrypto-core
pnpm add webcrypto-core
yarn add webcrypto-core
bun add webcrypto-core
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.9.2 |
| Published | 2026-05-01 |
| First published | 2016-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 152.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 30 |
| Author | PeculiarVentures |
| Maintainers | peculiarventures, microshine |
| Keywords | webcrypto, crypto, polyfill, aes, rsa, sha, ec, shake |

## Links

- npm: https://www.npmjs.com/package/webcrypto-core
- Repository: https://github.com/PeculiarVentures/webcrypto-core
- Homepage: https://github.com/PeculiarVentures/webcrypto-core#readme
- Issues: https://github.com/PeculiarVentures/webcrypto-core/issues
- npm.io page: https://npm.io/package/webcrypto-core

## Dependencies (5)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [asn1js](https://npm.io/package/asn1js.md) ^3.0.10
- [@peculiar/utils](https://npm.io/package/@peculiar/utils.md) ^2.0.2
- [@peculiar/asn1-schema](https://npm.io/package/@peculiar/asn1-schema.md) ^2.7.0
- [@peculiar/json-schema](https://npm.io/package/@peculiar/json-schema.md) ^1.1.12

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.9.2 (latest) — 2026-05-01
- 1.0.19-next.0 (next) — 2020-04-05
- 1.9.1 — 2026-05-01
- 1.9.0 — 2026-04-30
- 1.8.1 — 2024-10-08
- 1.8.0 — 2024-05-28
- 1.7.9 — 2024-03-28
- 1.7.8 — 2024-01-22
- 1.7.7 — 2023-03-21
- 1.7.6 — 2023-02-10
- 1.7.5 — 2022-05-12
- 1.7.4 — 2022-05-12
- 1.7.3 — 2022-03-31
- 1.7.2 — 2022-03-25
- 1.7.1 — 2022-03-07
- … 66 more at https://npm.io/package/webcrypto-core/versions

## README

<h1 align="center">
  webcrypto-core
</h1>

<div align="center">

![NPM License](https://img.shields.io/npm/l/webcrypto-core)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/PeculiarVentures/webcrypto-core/test.yml?label=test)
[![npm version](https://img.shields.io/npm/v/webcrypto-core.svg)](https://www.npmjs.com/package/webcrypto-core)
![Coveralls](https://img.shields.io/coverallsCoverage/github/PeculiarVentures/webcrypto-core)
[![npm downloads](https://img.shields.io/npm/dm/webcrypto-core.svg)](https://www.npmjs.com/package/webcrypto-core)

</div>

We have created a number of WebCrypto polyfills including: [node-webcrypto-ossl](https://github.com/PeculiarVentures/node-webcrypto-ossl), [node-webcrypto-p11](https://github.com/PeculiarVentures/node-webcrypto-p11), and [webcrypto-liner](https://github.com/PeculiarVentures/webcrypto-liner).  `webcrypto-core` was designed to be a common layer to be used by all of these libraries for input validation.

Unless you intend to create a WebCrypto polyfill this library is probably not useful to you.

## Installing

```
npm install webcrypto-core
```

## Example

Current examples shows how you can implement your own WebCrypt interface

```js
const core = require(".");
const crypto = require("crypto");

class Sha1Provider extends core.ProviderCrypto {

  constructor() {
    super();

    this.name = "SHA-1";
    this.usages = [];
  }

  async onDigest(algorithm, data) {
    const hash = crypto.createHash("SHA1").update(Buffer.from(data)).digest();
    return new Uint8Array(hash).buffer;
  }

}

class SubtleCrypto extends core.SubtleCrypto {
  constructor() {
    super();

    // Add SHA1 provider to SubtleCrypto
    this.providers.set(new Sha1Provider());
  }
}

class Crypto extends core.Crypto {

  constructor() {
    this.subtle = new SubtleCrypto();
  }

  getRandomValues(array) {
    const buffer = Buffer.from(array.buffer);
    crypto.randomFillSync(buffer);
    return array;
  }

}

const webcrypto = new Crypto();
webcrypto.subtle.digest("SHA-1", Buffer.from("TEST MESSAGE"))
  .then((hash) => {
    console.log(Buffer.from(hash).toString("hex")); // dbca505deb07e1612d944a69c0c851f79f3a4a60
  })
  .catch((err) => {
    console.error(err);
  });
```

---
_Source: https://npm.io/package/webcrypto-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
