{"id":13825841,"url":"https://github.com/socketsupply/secret-local-storage","last_synced_at":"2025-04-11T13:14:13.827Z","repository":{"id":100550759,"uuid":"176991629","full_name":"socketsupply/secret-local-storage","owner":"socketsupply","description":"A wrapper around 'localStorage/sessionStorage' to provide storage encryption with libsodium","archived":false,"fork":false,"pushed_at":"2019-11-01T18:26:31.000Z","size":25,"stargazers_count":22,"open_issues_count":1,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T01:09:39.590Z","etag":null,"topics":["browser","local","secure","sodium","storage"],"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/socketsupply.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2019-03-21T17:15:44.000Z","updated_at":"2024-02-02T17:06:40.000Z","dependencies_parsed_at":"2023-03-22T12:16:55.107Z","dependency_job_id":null,"html_url":"https://github.com/socketsupply/secret-local-storage","commit_stats":null,"previous_names":["jwerle/secret-local-storage","little-core-labs/secret-local-storage"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketsupply%2Fsecret-local-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketsupply%2Fsecret-local-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketsupply%2Fsecret-local-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketsupply%2Fsecret-local-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketsupply","download_url":"https://codeload.github.com/socketsupply/secret-local-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248406419,"owners_count":21098213,"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":["browser","local","secure","sodium","storage"],"created_at":"2024-08-04T09:01:27.854Z","updated_at":"2025-04-11T13:14:13.800Z","avatar_url":"https://github.com/socketsupply.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"secret-local-storage\n====================\n\nA wrapper around 'localStorage/sessionStorage' to provide storage encryption with libsodium\n\n## Installation\n\n```sh\n$ npm install secret-local-storage\n```\n\n## Usage\n\n```js\nconst { keygen } = require('secret-local-storage/keygen')\nconst secretKey = keygen()\nconst secretStorage = require('secret-local-storage')(secretKey) // will generate key by default\n\nsecretStorage.setItem('someKey', 'some secret value')\nconsole.log(secretStorage.getItem('someKey')) // some secret value\nconsole.log(localStorage.getItem('someKey')) // 5J3nmcMCcABSwJN\n```\n\n## Example\n\n```js\nconst secretStorage = require('secret-local-storage')('3e852b5d881b22261b8e417e217a9fa9757f4532305c4e46e2a6966aa89840f6')\n\nlocalStorage.setItem('hello', 'world')\nconsole.log(secretStorage.getItem('hello')); // outputs 'hello'\n\nsecretStorage.setItem('hello', 'world')\nconsole.log(localStorage.getItem('hello')); // should be encrypted\n```\n\n## API\n\nThe `SecretLocalStorage` class implements the same API as the [Storage][Storage]\nAPI.\n\n### `const secretStorage = require('secret-local-storage')(secretKey, opts)`\n\nCreate a secret storage instance with an optional secret key and options where:\n\n* `secretKey` is a 32-byte buffer or 64 character 'hex' encoded string. The\n  encoding of the secret key can be specified with `opts.secretKeyEncoding`.\n  If you do not supply a secret key, then one will be generated for you. This\n  should be saved and re-used to read the encrypted values.\n\n* `opts` is an optional object to configure the storage where:\n  * `opts.secretKeyEncoding` is the encoding of the secret key\n  * `opts.valueEncoding` is an object containing `encode(value)` and\n    `decode(buffer)` functions.\n  * `opts.storage` can be [Storage][Storage] interface or a function that\n    returns one.\n  * `opts.seed` is an optionl seed value to generate the secret key that\n    should be 32 bytes\n\n#### `secretKey.secretKey`\n\nA 32 byte secret key used for encryption and child key derivation.\n\n#### `secretStorage.storage`\n\nThe [Storage][Storage] interface backing the `SecretLocalStorage` instance.\n\n#### `secretKey.valueEncoding`\n\nThe value encoding used for encoding and ecoding value written to storage.\n\n##### `secretKey.valueEncoding.encode(value)`\n\nEncodes `value` into a `Buffer`\n\n##### `secretKey.valueEncoding.decode(buffer)`\n\nDecodes `buffer` into a value. Most likely, a string.\n\n#### `secretStorage.key(n)`\n\nThe same API as [Storage.key()][Storage.key].\n\n#### `secretStorage.getItem(key)`\n\nThe same API as [Storage.getItem()][Storage.getItem]. If decryption fails, this\nfunction will return the original value found in storage.\n\n#### `secretStorage.setItem(key)`\n\nThe same API as [Storage.setItem()][Storage.setItem].\n\n#### `secretStorage.removeItem(key)`\n\nThe same API as [Storage.removeItem()][Storage.removeItem].\n\n#### `secretStorage.clear(key)`\n\nThe same API as [Storage.clear()][Storage.clear].\n\n## License\n\nMIT\n\n\n[Storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage\n[Storage.key]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/key\n[Storage.clear]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear\n[Storage.getItem]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem\n[Storage.setItem]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem\n[Storage.removeItem]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketsupply%2Fsecret-local-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketsupply%2Fsecret-local-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketsupply%2Fsecret-local-storage/lists"}