{"_id":"webcrypto-core@2.0.0","bugs":{"url":"https://github.com/PeculiarVentures/webcrypto-core/issues"},"dist":{"shasum":"5c6ac804a267a0d6db9f7ac8cdd9aced8ceb51a4","tarball":"http://registry-npm.ywwl.com/webcrypto-core/download/webcrypto-core-2.0.0.tgz","fileCount":129,"integrity":"sha512-dQv+gpwrrDy5nCmy/qvlUU3/Sx6CMISXkku1dSF9vjkhCMUcw7pA7A/qnwe/nKjriN6la534i+cYH58gTxyhXg==","signatures":[{"sig":"MEYCIQCKvltmMCybJgIREGTwWfPvW7rT4f/Dh2MBWgpbaS2suAIhAMPnVJcNOHG4Uh9w6wnHfHgt6SkhZbu+uIU89TIZ/bf1","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIQCn+/UHuZtg7eiEW4vKaedfO3oseYzrnef8r3eIf0W7sQIfMNZLJtWi69CtJmCI/D7A4H0FpvEKvakVLyl44etfcw=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/webcrypto-core@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":125332,"size":24727,"noattachment":false,"key":"/webcrypto-core/-/webcrypto-core-2.0.0.tgz"},"main":"./build/index.js","name":"webcrypto-core","type":"module","types":"./build/index.d.ts","author":{"name":"PeculiarVentures"},"module":"./build/index.js","engines":{"node":"^20.19.0 || >=22.12.0"},"exports":{".":"./build/index.js","./package.json":"./package.json"},"gitHead":"c566ac91e39759f6eb370c2ea4e1bbc7db5c05d9","license":"MIT","scripts":{"lint":"oxlint","test":"vitest run","build":"tsdown","format":"oxfmt","prepack":"npm run build","coverage":"vitest run --coverage","lint:fix":"oxlint --fix","typecheck":"tsc --noEmit","format:check":"oxfmt --check"},"version":"2.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"4c6acfa2-7fb0-4534-90a4-e44e0b9eef89"}},"homepage":"https://github.com/PeculiarVentures/webcrypto-core#readme","keywords":["webcrypto","crypto","polyfill","aes","rsa","sha","ec","shake"],"repository":{"url":"git+https://github.com/PeculiarVentures/webcrypto-core.git","type":"git"},"_npmVersion":"11.19.0","description":"Common layer to be used by crypto libraries based on WebCrypto API for input validation.","directories":{},"maintainers":[{"name":"peculiarventures","email":"info@peculiarventures.com"},{"name":"microshine","email":"microshine@mail.ru"}],"sideEffects":false,"_nodeVersion":"24.21.0","dependencies":{"@peculiar/utils":"^4.1.0"},"_hasShrinkwrap":false,"devDependencies":{"oxfmt":"^0.74.0","asn1js":"^4.0.0","oxlint":"^1.89.0","tsdown":"^0.23.2","vitest":"^5.0.5","typescript":"^6.0.3","@types/node":"^26.6.5","@vitest/coverage-v8":"^5.0.5","@peculiar/asn1-schema":"^3.0.0","@peculiar/json-schema":"^3.0.0","@arethetypeswrong/core":"^0.18.5"},"peerDependencies":{"asn1js":"^4.0.0","@peculiar/asn1-schema":"^3.0.0","@peculiar/json-schema":"^3.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/webcrypto-core_2.0.0_1793092866019_0.028714125750125663"},"readme":"<h1 align=\"center\">\n  webcrypto-core\n</h1>\n\n<div align=\"center\">\n\n![NPM License](https://img.shields.io/npm/l/webcrypto-core)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/PeculiarVentures/webcrypto-core/publish.yml?branch=master&label=publish)\n[![npm version](https://img.shields.io/npm/v/webcrypto-core.svg)](https://www.npmjs.com/package/webcrypto-core)\n![Coveralls](https://img.shields.io/coverallsCoverage/github/PeculiarVentures/webcrypto-core)\n[![npm downloads](https://img.shields.io/npm/dm/webcrypto-core.svg)](https://www.npmjs.com/package/webcrypto-core)\n\n</div>\n\nWe 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.\n\nUnless you intend to create a WebCrypto polyfill this library is probably not useful to you.\n\n## Install\n\n```sh\nnpm install webcrypto-core\n```\n\nThe package is ESM-only with TypeScript declarations, and requires Node.js `^20.19.0 || >=22.12.0`. CommonJS code can still `require()` it on those versions. `@peculiar/asn1-schema`, `@peculiar/json-schema` and `asn1js` are peer dependencies; npm 7+ installs them automatically.\n\n## Breaking Changes In v2\n\nv2 is ESM-only and requires Node.js `^20.19.0 || >=22.12.0` (1.x declared no range). CommonJS code can still `require(\"webcrypto-core\")` on these versions; Node.js 22.0–22.11 can't. Apart from `BufferSourceConverter` and `PemConverter`, the public API is unchanged: the same exports and type declarations as 1.9.2.\n\n- **TypeScript compiling to CommonJS:** use `\"module\": \"node20\"` or `\"nodenext\"` (`node16` fails with TS1479). ESM and bundler setups need no changes. Consumers don't need `experimentalDecorators`.\n- **Jest in CommonJS mode:** switch to ESM mode or Vitest, or add `webcrypto-core` and its `@peculiar/*` and `asn1js` dependencies to `transformIgnorePatterns`.\n- **Deep imports** (`webcrypto-core/build/...`) stay blocked by `exports`; import from `webcrypto-core`.\n- **Peer dependencies:** `@peculiar/asn1-schema` `^3.0.0`, `@peculiar/json-schema` `^3.0.0` and `asn1js` `^4.0.0`. webcrypto-core registers its ASN.1 and JWK classes in the schema storages of those packages, so an app needs exactly one copy of each; a conflicting major now fails at install (`ERESOLVE`) instead of at runtime. Libraries built on the older majors (`@peculiar/webcrypto` 1, `@peculiar/x509` 2) have to move together.\n- **`BufferSourceConverter` is no longer exported.** It was a re-export of the deprecated `@peculiar/utils/legacy` class. Use the functions from `@peculiar/utils/bytes` instead: `toArrayBuffer`, `toUint8Array`, `isBufferSource`, `equal` (was `isEqual`) and `concat` (takes an array).\n- **`PemConverter` is removed.** Use `pem` from `@peculiar/utils/pem`:\n  - `toArrayBuffer(text)` / `toUint8Array(text)` → `pem.decodeFirst(text)`. It returns a `Uint8Array`, reads the first block of a bundle, skips text before the block and throws if there's no block. Base64 with no BEGIN/END lines, or mismatched BEGIN/END labels, now throw. Single-line PEM, which `PemConverter` decoded to empty bytes, now decodes correctly.\n  - `fromBufferSource(data, tag)` → `pem.encode(label, data)`. The label is used as given (pass `\"PUBLIC KEY\"`, not `\"public key\"`) and the output ends with a newline.\n  - `isPEM`, `getTagName`, `hasTagName`, `isCertificate`, `isCertificateRequest`, `isCRL`, `isPublicKey` → `pem.decode(text)` returns the blocks with their `label`, and `pem.find(text, \"CERTIFICATE\")` finds a block by label. Labels compare case-sensitively.\n- **`@peculiar/utils` 4** replaces 2 (same functions, ESM-only). JWK import still accepts only unpadded base64url, as in 1.x.\n\n## Example\n\nThe example below implements a minimal WebCrypto interface with a SHA-1 provider.\n\n```js\nimport * as nodeCrypto from \"node:crypto\";\nimport * as core from \"webcrypto-core\";\n\nclass Sha1Provider extends core.ProviderCrypto {\n  name = \"SHA-1\";\n  usages = [];\n\n  async onDigest(algorithm, data) {\n    const hash = nodeCrypto.createHash(\"sha1\").update(new Uint8Array(data)).digest();\n    return new Uint8Array(hash).buffer;\n  }\n}\n\nclass SubtleCrypto extends core.SubtleCrypto {\n  constructor() {\n    super();\n\n    // Add SHA-1 provider to SubtleCrypto\n    this.providers.set(new Sha1Provider());\n  }\n}\n\nclass Crypto extends core.Crypto {\n  subtle = new SubtleCrypto();\n\n  getRandomValues(array) {\n    return nodeCrypto.getRandomValues(array);\n  }\n}\n\nconst crypto = new Crypto();\nconst hash = await crypto.subtle.digest(\"SHA-1\", new TextEncoder().encode(\"TEST MESSAGE\"));\nconsole.log(Buffer.from(hash).toString(\"hex\")); // dbca505deb07e1612d944a69c0c851f79f3a4a60\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for the development setup, checks and release process.\n","publish_time":1793092866105,"_cnpm_publish_time":1793092866105,"dist-tags":{"latest":"2.0.0","next":"1.0.19-next.0"}}