{"name":"webcrypto-core","version":"1.9.2","keywords":["webcrypto","crypto","polyfill","aes","rsa","sha","ec","shake"],"author":{"name":"PeculiarVentures"},"license":"MIT","_id":"webcrypto-core@1.9.2","maintainers":[{"name":"peculiarventures","email":"info@peculiarventures.com"},{"name":"microshine","email":"microshine@mail.ru"}],"homepage":"https://github.com/PeculiarVentures/webcrypto-core#readme","bugs":{"url":"https://github.com/PeculiarVentures/webcrypto-core/issues"},"nyc":{"exclude":["**/*.d.ts"],"include":["src/**/*.ts"],"reporter":["lcov","text-summary"],"extension":[".ts",".tsx"]},"dist":{"shasum":"22dd6a0fb55217b1301eab7151d01d5c68e52ccb","tarball":"http://registry-npm.ywwl.com/webcrypto-core/download/webcrypto-core-1.9.2.tgz","fileCount":6,"integrity":"sha512-gsXecm82UQNlTBURJGuqOWy1Ww08S3kZUcr3aOJS02Pk0xLtkfeUAVC0u0xhgdonFme80edSJUIJyuvL/7250Q==","signatures":[{"sig":"MEYCIQCs6T8o2NjRX9v7geZTPAoUCHsLwCIk1dL4h46A1XuvYAIhAPg+LiDO5D5uhvS+SHs/c5Mhy4ca50DQsb2gKtWl5V7y","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/webcrypto-core@1.9.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":156070,"size":25794,"noattachment":false,"key":"/webcrypto-core/-/webcrypto-core-1.9.2.tgz"},"main":"build/webcrypto-core.js","_from":"file:release-package/webcrypto-core-1.9.2.tgz","mocha":{"spec":["test/**/*.ts"],"require":"ts-node/register","extension":["ts"]},"types":"build/index.d.ts","module":"build/webcrypto-core.es.js","exports":{".":{"types":"./build/index.d.ts","import":"./build/webcrypto-core.es.js","require":"./build/webcrypto-core.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint","test":"vitest run","build":"rollup -c","clear":"rimraf build/*","rebuild":"npm run clear && npm run build","coverage":"vitest --coverage","lint:fix":"npm run lint -- --fix","typecheck":"tsc --noEmit","test:watch":"vitest"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4c6acfa2-7fb0-4534-90a4-e44e0b9eef89"}},"_resolved":"/home/runner/work/webcrypto-core/webcrypto-core/release-package/webcrypto-core-1.9.2.tgz","_integrity":"sha512-gsXecm82UQNlTBURJGuqOWy1Ww08S3kZUcr3aOJS02Pk0xLtkfeUAVC0u0xhgdonFme80edSJUIJyuvL/7250Q==","repository":{"url":"git+https://github.com/PeculiarVentures/webcrypto-core.git","type":"git"},"_npmVersion":"11.11.0","description":"Common layer to be used by crypto libraries based on WebCrypto API for input validation.","directories":{},"_nodeVersion":"24.14.1","dependencies":{"tslib":"^2.8.1","asn1js":"^3.0.10","@peculiar/utils":"^2.0.2","@peculiar/asn1-schema":"^2.7.0","@peculiar/json-schema":"^1.1.12"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^6.1.3","rollup":"^4.60.2","vitest":"^4.1.5","typescript":"^6.0.3","rollup-plugin-dts":"^6.4.1","@vitest/coverage-v8":"^4.1.5","@rollup/plugin-typescript":"^12.3.0","@peculiar/eslint-config-base":"^0.2.9","eslint-import-resolver-typescript":"^4.4.4"},"_npmOperationalInternal":{"tmp":"tmp/webcrypto-core_1.9.2_1777648797512_0.792896689114533","host":"s3://npm-registry-packages-npm-production"},"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":1777648797758,"_cnpm_publish_time":1777648797758,"dist-tags":{"latest":"2.0.0","next":"1.0.19-next.0"}}