{"_id":"polyfill-crypto-methods","_rev":"4-071aaf73bf3095f7c3985a9e58fb14a5","name":"polyfill-crypto-methods","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"polyfill-crypto-methods","version":"0.1.0","keywords":["Web Crypto API","webcrypto","crypto","getRandomValues","randomBytes","randomUUID","polyfill","browser","node","wechat","wx","微信","小程序","crypto-js","jsencrypt","@noble/curves"],"author":{"name":"Atypiape"},"license":"MIT","_id":"polyfill-crypto-methods@0.1.0","maintainers":[{"name":"atypiape","email":"atypiape@163.com"}],"homepage":"https://github.com/atypiape/polyfill-crypto-methods.git","bugs":{"url":"https://github.com/atypiape/polyfill-crypto-methods/issues"},"dist":{"shasum":"af69d1b571fd923c93c364f354c151bce613e3ed","tarball":"https://registry.npmjs.org/polyfill-crypto-methods/-/polyfill-crypto-methods-0.1.0.tgz","fileCount":5,"integrity":"sha512-f/P2pr6p8KoRXJquRNRENfdaHwXeHEtMCseK17aDStXZmgO/cP9J5TS/+7kYXGWWUf4wtDlafqa8e5Va50POvg==","signatures":[{"sig":"MEQCIGt3sAgI4Vwp6KZGP0fKs2fX6btcBgONlVm/bBEHxIrDAiBs/TD4svqW2+RlwY8MRJqL0YZY+B6Uo3qbMnEy0alRXw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11001},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"gitHead":"ea54dfdab8c332a6c7dcb00ca767d0a4b6b9ac11","scripts":{"dev":"vite","build":"tsc && vite build && tsc --build tsconfig.declare.json"},"_npmUser":{"name":"atypiape","email":"atypiape@163.com"},"repository":{"url":"git+https://github.com/atypiape/polyfill-crypto-methods.git","type":"git"},"_npmVersion":"10.2.3","description":"Polyfill for Crypto instance methods of Web Crypto API","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^5.0.0","typescript":"^5.2.2"},"_npmOperationalInternal":{"tmp":"tmp/polyfill-crypto-methods_0.1.0_1702723073930_0.13935850876884714","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"polyfill-crypto-methods","version":"0.2.0","keywords":["Web Crypto API","webcrypto","crypto","getRandomValues","randomBytes","randomUUID","polyfill","browser","node","wechat","wx","微信","小程序","crypto-js","jsencrypt","@noble/curves"],"author":{"name":"Atypiape"},"license":"MIT","_id":"polyfill-crypto-methods@0.2.0","maintainers":[{"name":"atypiape","email":"atypiape@163.com"}],"homepage":"https://github.com/atypiape/polyfill-crypto-methods.git","bugs":{"url":"https://github.com/atypiape/polyfill-crypto-methods/issues"},"dist":{"shasum":"e4593a81421256bfd754cf6e35660ca1bfa92612","tarball":"https://registry.npmjs.org/polyfill-crypto-methods/-/polyfill-crypto-methods-0.2.0.tgz","fileCount":5,"integrity":"sha512-wJZASFxPQymAtyxXheFrhuJrRQfHDbt31AB8n4d8JyZM5VeXWmoPLMmVBaNcwvLTsOqFNrdC7VW0S+6Oree6UQ==","signatures":[{"sig":"MEQCIFvy2Vwr65nLNIYzWfFDIg4TbUr9UNc9m1DKoek8MukfAiBZ0iUEUfJYNG85aDILgqvIyaasRcHXh1hfcAEcx544bQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11233},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"gitHead":"7224d16cb871a6bab82ee48a8d9f16652cadda69","scripts":{"dev":"vite","build":"tsc && vite build && tsc --build tsconfig.declare.json"},"_npmUser":{"name":"atypiape","email":"atypiape@163.com"},"repository":{"url":"git+https://github.com/atypiape/polyfill-crypto-methods.git","type":"git"},"_npmVersion":"10.2.4","description":"Polyfill for Crypto instance methods of Web Crypto API","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"vite":"^5.0.0","typescript":"^5.2.2"},"_npmOperationalInternal":{"tmp":"tmp/polyfill-crypto-methods_0.2.0_1710159491440_0.43489569656918614","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"polyfill-crypto-methods","version":"0.2.1","keywords":["Web Crypto API","webcrypto","crypto","getRandomValues","randomBytes","randomUUID","polyfill","browser","node","wechat","wx","微信","小程序","crypto-js","jsencrypt","@noble/curves"],"author":{"name":"Atypiape"},"license":"MIT","_id":"polyfill-crypto-methods@0.2.1","maintainers":[{"name":"atypiape","email":"atypiape@163.com"}],"homepage":"https://github.com/atypiape/polyfill-crypto-methods.git","bugs":{"url":"https://github.com/atypiape/polyfill-crypto-methods/issues"},"dist":{"shasum":"c07d29b34bb379ac07869f70a0ab6cefe197fc76","tarball":"https://registry.npmjs.org/polyfill-crypto-methods/-/polyfill-crypto-methods-0.2.1.tgz","fileCount":5,"integrity":"sha512-LgFgbfzfCYaPK0SuqS5TVV+UlIC9KDod0KeLnFG1qbz0cnq926S3zrfo+xlOJVuY8ZI4rCNtTyEFBc5T9gyqmw==","signatures":[{"sig":"MEQCIE+ayWbfBh+yERtdTxgEY8ieajgIGqZD7tcoJxD33rH8AiBLjwN5ItZ0UUg2Wk/2VbT5PqMiJid+xChdOAeXbZptnQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11274},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"gitHead":"7eff622e389b738f02e9203d61ad5a48ad2d2146","scripts":{"dev":"vite","build":"tsc && vite build && tsc --build tsconfig.declare.json"},"_npmUser":{"name":"atypiape","email":"atypiape@163.com"},"repository":{"url":"git+https://github.com/atypiape/polyfill-crypto-methods.git","type":"git"},"_npmVersion":"10.8.2","description":"Polyfill for Crypto instance methods of Web Crypto API","directories":{},"_nodeVersion":"20.19.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^5.0.0","typescript":"^5.2.2"},"_npmOperationalInternal":{"tmp":"tmp/polyfill-crypto-methods_0.2.1_1744278775136_0.040396325824741064","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"polyfill-crypto-methods","version":"1.0.0","description":"Polyfill for Crypto instance methods of Web Crypto API","type":"module","author":{"name":"Atypiape"},"license":"MIT","homepage":"https://github.com/atypiape/polyfill-crypto-methods.git","repository":{"type":"git","url":"git+https://github.com/atypiape/polyfill-crypto-methods.git"},"keywords":["Web Crypto API","webcrypto","crypto","getRandomValues","randomBytes","randomUUID","polyfill","browser","node","wechat","wx","微信","小程序","crypto-js","jsencrypt","@noble/curves"],"main":"./dist/index.umd.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"scripts":{"dev":"vite","build":"tsc && vite build && tsc --build tsconfig.declare.json"},"devDependencies":{"typescript":"^5.2.2","vite":"^5.0.0"},"_id":"polyfill-crypto-methods@1.0.0","gitHead":"2965d7c3b44eca897fd4b385b946b87bd9ca415c","bugs":{"url":"https://github.com/atypiape/polyfill-crypto-methods/issues"},"_nodeVersion":"20.19.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-1/oLepJ06Lo/cu+zjVdEwA9sprX94mXCBlrj5Al9YT66jrC8dE/N3LQ2xy+I4nnoikweOvZWcpvwzIdCUCZbNQ==","shasum":"9748165f1244aa79cff24d5d26bf33e5d72c10b3","tarball":"https://registry.npmjs.org/polyfill-crypto-methods/-/polyfill-crypto-methods-1.0.0.tgz","fileCount":5,"unpackedSize":11273,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDPSRWvkilyo55KdfBzJefwF8wsps0qDeZzuyAlS0fn1QIgbbHVz3DD2sel49mIUBgBNVBfZ5iMCyuct27TBCm1j2o="}]},"_npmUser":{"name":"atypiape","email":"atypiape@163.com"},"directories":{},"maintainers":[{"name":"atypiape","email":"atypiape@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/polyfill-crypto-methods_1.0.0_1749714882799_0.5236253017930308"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-16T10:37:53.929Z","modified":"2025-06-12T07:54:43.219Z","0.1.0":"2023-12-16T10:37:54.122Z","0.2.0":"2024-03-11T12:18:11.580Z","0.2.1":"2025-04-10T09:52:55.324Z","1.0.0":"2025-06-12T07:54:42.959Z"},"bugs":{"url":"https://github.com/atypiape/polyfill-crypto-methods/issues"},"author":{"name":"Atypiape"},"license":"MIT","homepage":"https://github.com/atypiape/polyfill-crypto-methods.git","keywords":["Web Crypto API","webcrypto","crypto","getRandomValues","randomBytes","randomUUID","polyfill","browser","node","wechat","wx","微信","小程序","crypto-js","jsencrypt","@noble/curves"],"repository":{"type":"git","url":"git+https://github.com/atypiape/polyfill-crypto-methods.git"},"description":"Polyfill for Crypto instance methods of Web Crypto API","maintainers":[{"name":"atypiape","email":"atypiape@163.com"}],"readme":"# Polyfill-Crypto-Methods\n\nThis is a polyfill for the [Crypto](https://developer.mozilla.org/docs/Web/API/Crypto) **instance methods** of the [Web Crypto API](https://developer.mozilla.org/docs/Web/API/Web_Crypto_API):\n\n- [`crypto.getRandomValues()`](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues)\n- [`crypto.randomUUID()`](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID)\n- [`crypto.randomBytes()`](https://nodejs.cn/api/crypto.html#crypto_crypto_randombytes_size_callback) (from `Node.js`)\n\nYou just need to import this library at the top of your code entry.\n\nThis library was originally developed for `WeChat Miniprogram` because it does not support the [Web Crypto API](https://developer.mozilla.org/docs/Web/API/Web_Crypto_API). This lack of support prevents the use of some third-party encryption libraries, such as [crypto-js](https://www.npmjs.com/package/crypto-js), [jsencrypt](https://www.npmjs.com/package/jsencrypt), [@noble/curves](https://www.npmjs.com/package/@noble/curves), etc.\n\n---\n\n向不支持 [Web Crypto API](https://developer.mozilla.org/docs/Web/API/Web_Crypto_API) 的运行环境，全局注入 [Crypto](https://developer.mozilla.org/docs/Web/API/Crypto) **实例方法**：\n\n- [`crypto.getRandomValues()`](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues)\n- [`crypto.randomUUID()`](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID)\n- [`crypto.randomBytes()`](https://nodejs.cn/api/crypto.html#crypto_crypto_randombytes_size_callback) (来自 `Node.js`)\n\n你只需在代码入口的顶部导入这个库。\n\n该库最初用于微信小程序，由于小程序不支持 [Web Crypto API](https://developer.mozilla.org/docs/Web/API/Web_Crypto_API)，导致无法使用一些第三方加密库，比如 [crypto-js](https://www.npmjs.com/package/crypto-js)、[jsencrypt](https://www.npmjs.com/package/jsencrypt)、[@noble/curves](https://www.npmjs.com/package/@noble/curves) 等。\n\n## Usage\n\n**NPM**\n\n```bash\nnpm i polyfill-crypto-methods\n```\n\n**YARN**\n\n```bash\nyarn add polyfill-crypto-methods\n```\n\n### Examples\n\n```javascript\nimport 'polyfill-crypto-methods';\n\n// Output: true\nconsole.log(globalThis.crypto === crypto);\n\nconst int8 = crypto.getRandomValues(new Int8Array(4));\nconst int16 = crypto.getRandomValues(new Int16Array(4));\nconst int32 = crypto.getRandomValues(new Int32Array(4));\nconst uint8 = crypto.getRandomValues(new Uint8Array(4));\nconst uint16 = crypto.getRandomValues(new Uint16Array(4));\nconst uint32 = crypto.getRandomValues(new Uint32Array(4));\n\n// Output: [-69, 52, -69, 8]\nconsole.log(int8);\n// Output: [-12857, 11870, 1874, -30545]\nconsole.log(int16);\n// Output: [740598374, 1682174651, -440338757, -391071704]\nconsole.log(int32);\n// Output: [133, 69, 14, 216]\nconsole.log(uint8);\n// Output: [45360, 53346, 43256, 34054]\nconsole.log(uint16);\n// Output: [1771376779, 3593883952, 3543639388, 2288005852]\nconsole.log(uint32);\n\nconst uuid = crypto.randomUUID();\n// Output: \"e6c5350a-b7f3-9b9c-3a3c-d0eab9e63122\"\nconsole.log(uuid);\n\n// Sync\nconst bytes = crypto.randomBytes(4);\n// Output: [123, 56, 189, 201]\nconsole.log(bytes);\n\n// Async\nconst ret = crypto.randomBytes(4, (err, arr) => {\n  // Output: null, [92, 112, 228, 144]\n  console.log(err, arr);\n});\n```\n\n```javascript\nimport { crypto as myCrypto } from 'polyfill-crypto-methods';\n\n// Output: true\nconsole.log(globalThis.crypto === myCrypto);\n\n// Sync\nconst bytes = myCrypto.randomBytes(4);\n// Output: [123, 56, 189, 201]\nconsole.log(bytes);\n\n// Async\nconst ret = myCrypto.randomBytes(4, (err, arr) => {\n  // Output: null, [92, 112, 228, 144]\n  console.log(err, arr);\n});\n```\n","readmeFilename":"README.md"}