{"id":13725144,"url":"https://github.com/lukeed/csprng","last_synced_at":"2025-10-09T18:23:51.937Z","repository":{"id":60774764,"uuid":"307529674","full_name":"lukeed/csprng","owner":"lukeed","description":"A tiny (~90B) isomorphic wrapper for `crypto.randomBytes` in Node.js and browsers.","archived":false,"fork":false,"pushed_at":"2023-03-31T19:54:09.000Z","size":13,"stargazers_count":68,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T19:50:04.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"lukeed"}},"created_at":"2020-10-26T23:18:58.000Z","updated_at":"2024-08-08T06:24:30.000Z","dependencies_parsed_at":"2024-02-25T09:37:54.585Z","dependency_job_id":"5d867930-f692-4008-aa61-20185bb6ff00","html_url":"https://github.com/lukeed/csprng","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"686b7dd9c2ee235faf98da2aaa9fcbe0315175b2"},"previous_names":["lukeed/crypto.random"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fcsprng","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fcsprng/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fcsprng/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fcsprng/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/csprng/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252943905,"owners_count":21829336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:14.165Z","updated_at":"2025-10-09T18:23:46.897Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript"],"sub_categories":[],"readme":"# @lukeed/csprng ![CI](https://github.com/lukeed/csprng/workflows/CI/badge.svg) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/csprng)](https://codecov.io/gh/lukeed/csprng)\n\n\u003e A tiny (~90B) isomorphic wrapper for `crypto.randomBytes` in Node.js and browsers.\n\n***Why?***\n\nThis package allows you/dependents to import a cryptographically secure generator (CSPRNG) _without_ worrying about (aka, checking the runtime environment for) the different `crypto` implementations. Instead, by extracting a `random` function into a third-party/external package, one can rely on bundlers and/or module resolution to load the correct implementation for the desired environment.\n\nIn other words, one can include the browser-specific implementation when bundling for the browser, completely ignoring the Node.js code – or vice versa.\n\nBy default, this module is set up to work with Rollup, webpack, and Node's native ESM _and_ CommonJS path resolutions.\n\n## Install\n\n```\n$ npm install --save @lukeed/csprng\n```\n\n\n## Usage\n\n***General Usage***\n\n```js\n// Rely on bundlers/environment detection\nimport { random } from '@lukeed/csprng';\n\nconst array = random(12);\n// browser =\u003e Uint8Array(12) [...]\n// Node.js =\u003e \u003cBuffer ...\u003e\n```\n\n***Specific Environment***\n\n```js\n// Choose the \"browser\" implementation explicitly.\n//=\u003e ! NOTE ! Will break in Node.js environments!\nimport { random } from '@lukeed/csprng/browser';\n\nconst array = random(1024);\n//=\u003e Uint8Array(1024) [...]\n\n// ---\n\n// Choose the \"node\" implementation explicitly.\n//=\u003e ! NOTE ! Will break in browser environments!\nimport { random } from '@lukeed/csprng/node';\n\nconst array = random(1024);\n//=\u003e \u003cBuffer ...\u003e\n```\n\n\n## API\n\n### random(length)\nReturns: `Buffer` or `Uint8Array`\n\nReturns a typed array of given `length`.\n\n\n#### length\nType: `Number`\n\nThe desired length of your output TypedArray.\n\n\n## Related\n\n- [uid](https://github.com/lukeed/uid) - A tiny (134B) and fast utility to randomize unique IDs of fixed length\n- [@lukeed/uuid](https://github.com/lukeed/uuid) - A tiny (230B), fast, and cryptographically secure UUID (V4) generator for Node and the browser\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fcsprng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fcsprng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fcsprng/lists"}