# one-webcrypto

> Import the webcrypto API as a single module in both nodejs and browsers.

Latest version **1.0.3** (published 2021-11-02) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-11-02 |
| First published | 2021-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Philipp Krüger |
| Maintainers | philipp-fission |

## Links

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

## Recent versions

- 1.0.3 (latest) — 2021-11-02
- 1.0.2 — 2021-11-02
- 1.0.1 — 2021-10-15
- 1.0.0 — 2021-10-15

## README

# one-webcrypto

The [WebCrypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) is available in [most browsers](https://caniuse.com/cryptography), under a global variable:

```js
// in web pages
const webcrypto = window.crypto
// in web workers, etc.
const webcrypto = self.crypto
// or generally under
const webcrypto = globalThis.crypto
```

It is also [available in NodeJS](https://nodejs.org/api/webcrypto.html#webcrypto_web_crypto_api) since version 15.

However, it is accessed differently:

```js
// in node with commonjs
const webcrypto = require("crypto").webcrypto
// in node with ES Modules
import crypto from "crypto"
const webcrypto = crypto.webcrypto
```

These different ways of getting access to valuable cryptographic primitives (see `webcrypto.subtle`) accross platforms (node & browsers) are hard to get right.


## Usage

With this package, you can just import the [WebCrypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) like so:

```js
import { webcrypto } from "one-webcrypto"

webcrypto.getRandomValues( //...
await webcrypto.subtle.generateKey( //...
```

Or with CommonJS:

```js
const { webcrypto } = require("one-webcrypto")
```


## Compatibility Issues

This package uses a fairly new package.json standard field, the `exports` field.

Read more about it:
* ["export maps" in nodejs documentation](https://nodejs.org/api/packages.html#packages_package_entry_points). 
* ["package exports" in webpack documentation](https://webpack.js.org/guides/package-exports/)
* [original "pkg exports" proposal](https://github.com/jkrems/proposal-pkg-exports/)

We're also making use of webpack's pseudo-standard of the ["browser" flag](https://webpack.js.org/guides/package-exports/#target-environment) for imports.

So if your environment doesn't support that, it _may_ or _may not_ work.

We know that this setup works (*should work*) with
* NodeJS 15+ (thus also e.g. mocha)
* ESBuild
* Webpack 5
* Vite
* SvelteKit
* Snowpack
* Parcel 2

We know that this setup can have issues with
* Create React App

If you have **any experience** (whether it supports the claims above or not), **please create an issue**.
The idea is to help each other out in these crazy bundler times and document what works and what doesn't. :)

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