{"name":"webcrypto-core","version":"1.8.1","keywords":["webcrypto","crypto","polyfill","aes","rsa","sha","ec","shake"],"author":{"name":"PeculiarVentures"},"license":"MIT","_id":"webcrypto-core@1.8.1","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":"09d5bd8a9c48e9fbcaf412e06b1ff1a57514ce86","tarball":"http://registry-npm.ywwl.com/webcrypto-core/download/webcrypto-core-1.8.1.tgz","fileCount":6,"integrity":"sha512-P+x1MvlNCXlKbLSOY4cYrdreqPG5hbzkmawbcXLKN/mf6DZW0SdNNkZ+sjwsqVkI4A4Ko2sPZmkZtCKY58w83A==","signatures":[{"sig":"MEUCIHKExkXuJ/SQnWweZr9tbDs1L/ryCfDIWXvTZRw+8NjfAiEA2kWxqTzSnrWrfDRbdiI5WWjkb3JaRDhZFaU+18mDpOs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":164653,"size":27063,"noattachment":false,"key":"/webcrypto-core/-/webcrypto-core-1.8.1.tgz"},"main":"build/webcrypto-core.js","mocha":{"spec":["test/**/*.ts"],"require":"ts-node/register","extension":["ts"]},"types":"build/index.d.ts","module":"build/webcrypto-core.es.js","gitHead":"5f5cf1a85ec6b20e805f5b880b3aaf0409ff02cd","scripts":{"lint":"eslint . --ext .ts","test":"mocha","build":"rollup -c","clear":"rimraf build/*","predev":"if [ ! -f coverage/index.html ]; then mkdir coverage; cp .waiting.html coverage/index.html; fi","rebuild":"npm run clear && npm run build","coverage":"nyc npm test","lint:fix":"eslint --fix . --ext .ts","coveralls":"nyc report --reporter=text-lcov | coveralls","coveragehtml":"nyc report -r html","precoveragehtml":"npm run coverage"},"_npmUser":{"name":"microshine","email":"microshine@mail.ru"},"repository":{"url":"git+https://github.com/PeculiarVentures/webcrypto-core.git","type":"git"},"_npmVersion":"10.8.2","description":"Common layer to be used by crypto libraries based on WebCrypto API for input validation.","directories":{},"_nodeVersion":"20.17.0","dependencies":{"tslib":"^2.7.0","asn1js":"^3.0.5","pvtsutils":"^1.3.5","@peculiar/asn1-schema":"^2.3.13","@peculiar/json-schema":"^1.1.12"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^17.1.0","mocha":"^10.7.3","eslint":"^8.57.0","rimraf":"^6.0.1","rollup":"^4.24.0","ts-node":"^10.9.2","typescript":"^5.6.2","@types/node":"^22.7.5","@types/mocha":"^10.0.9","rollup-plugin-dts":"^6.1.1","@typescript-eslint/parser":"^7.11.0","rollup-plugin-typescript2":"^0.36.0","@typescript-eslint/eslint-plugin":"^7.11.0"},"_npmOperationalInternal":{"tmp":"tmp/webcrypto-core_1.8.1_1728419826495_0.8668276156103687","host":"s3://npm-registry-packages"},"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":1728419826729,"_cnpm_publish_time":1728419826729,"dist-tags":{"latest":"2.0.0","next":"1.0.19-next.0"}}