{"id":19626106,"url":"https://github.com/deepsourcecorp/shifty","last_synced_at":"2025-04-28T05:33:11.518Z","repository":{"id":37945503,"uuid":"454349387","full_name":"DeepSourceCorp/shifty","owner":"DeepSourceCorp","description":"Shifty is a tiny zero-dependency secrets generator, built for the web using TypeScript.","archived":false,"fork":false,"pushed_at":"2023-10-02T00:44:52.000Z","size":84,"stargazers_count":48,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T15:19:10.198Z","etag":null,"topics":["password","secrets","security","web-cryptography-api"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/DeepSourceCorp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-02-01T10:46:26.000Z","updated_at":"2024-04-02T17:42:10.000Z","dependencies_parsed_at":"2024-01-16T20:53:44.291Z","dependency_job_id":"dd77020f-87bd-4f89-95dc-cdb5d73421ea","html_url":"https://github.com/DeepSourceCorp/shifty","commit_stats":null,"previous_names":["deepsourcelabs/shifty"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fshifty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fshifty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fshifty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fshifty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepSourceCorp","download_url":"https://codeload.github.com/DeepSourceCorp/shifty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224098470,"owners_count":17255508,"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":["password","secrets","security","web-cryptography-api"],"created_at":"2024-11-11T11:44:59.017Z","updated_at":"2024-11-11T11:45:00.341Z","avatar_url":"https://github.com/DeepSourceCorp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\u003cp\u003e\n  \u003cimg src=\"./.github/logo-light.svg#gh-light-mode-only\" alt=\"Shifty\" width=\"300\"\u003e\n  \u003cimg src=\"./.github/logo-dark.svg#gh-dark-mode-only\" alt=\"Shifty\" width=\"300\"\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\n[![DeepSource](https://deepsource.io/gh/deepsourcelabs/shifty.svg/?label=active+issues\u0026show_trend=true\u0026token=-guPFvlwSE5CSxHrlAc563Bz)](https://deepsource.io/gh/deepsourcelabs/shifty/?ref=repository-badge) [![DeepSource](https://deepsource.io/gh/deepsourcelabs/shifty.svg/?label=resolved+issues\u0026show_trend=true\u0026token=-guPFvlwSE5CSxHrlAc563Bz)](https://deepsource.io/gh/deepsourcelabs/shifty/?ref=repository-badge)\n\n  \u003cp\u003eShifty is a tiny zero-dependency secrets generator, built for the web using TypeScript.\u003c/p\u003e\n\n\u003c/div\u003e\n\n## Installation\n\n```sh\nyarn add @deepsource/shifty\n```\n\n## Usage\n\n\u003e Shifty is built for the browser and won't work with Node. You can use the built-in [crypto](https://nodejs.org/api/crypto.html#crypto) module instead.\n\n```js\nimport Shifty from \"@deepsource/shifty\";\n\nconst shifty = new Shifty((harden = true), (defaultLength = 16));\nshifty.generate((length = 12)); // G8qZt7PEha^s\n```\n\n### Options\n\n##### `Shifty`\n\n| Parameter       | Default | Description                                                         |\n| --------------- | ------- | ------------------------------------------------------------------- |\n| `harden`        | `true`  | This flag enables adding special characters in the generated secret |\n| `defaultLength` | `16`    | Set the default length of the secrets generated                     |\n\n##### `Shifty.generate`\n\n| Parameter | Default                | Description                          |\n| --------- | ---------------------- | ------------------------------------ |\n| `length`  | `Shifty.defaultLength` | Length of the secret to be generated |\n\n## How it works\n\nThe Web Crypto API is an interface allowing a script to use cryptographic primitives in order to build systems using cryptography. This library leverages the Web Crypto API to generate secrets and passwords for the web.\n\nIn case the browser does not support the Web Crypto API, the library uses a fallback, it generates the string using Math.random(). This is not cryptographically safe, but is still usable.\n\nThe algorithm for generating the password is quite simple\n\n1. Generate a array of 8-bit unsigned integers using Uint8Array\n2. Check if the browser crypto API is supported\n   1. If the browser supports crypto, use the generate array as the seed to fill in with random values using window.crypto.getRandomValues\n   2. Else use the fallback method, loop over the seed array, for every element, generate a random number between 0 to 255\n3. Initalize the secret string\n4. Start a while loop, until the length condition is matched\n   1. Start a for loop over the generated numbers\n   2. Convert the number to a character using `String.fromCharCode`\n   3. If the character code is valid, append it to the secret string from step 3\n   4. If the character limit is satisfied, break. Else, regenerate the seed array from step 2\n5. Return the generated string\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsourcecorp%2Fshifty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepsourcecorp%2Fshifty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsourcecorp%2Fshifty/lists"}