{"id":17835061,"url":"https://github.com/namesmt/sencrypt","last_synced_at":"2025-03-19T15:30:20.046Z","repository":{"id":250164505,"uuid":"833515531","full_name":"NamesMT/sencrypt","owner":"NamesMT","description":"Simple encrypted secret helper","archived":false,"fork":false,"pushed_at":"2025-03-08T11:03:03.000Z","size":183,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T04:42:57.409Z","etag":null,"topics":[],"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/NamesMT.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T08:02:27.000Z","updated_at":"2025-03-08T01:52:12.000Z","dependencies_parsed_at":"2024-09-18T03:13:08.987Z","dependency_job_id":"e81e75da-0aaa-4df0-87cd-8f943b86d5b4","html_url":"https://github.com/NamesMT/sencrypt","commit_stats":null,"previous_names":["namesmt/sencrypt"],"tags_count":5,"template":false,"template_full_name":"NamesMT/starter-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamesMT%2Fsencrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamesMT%2Fsencrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamesMT%2Fsencrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamesMT%2Fsencrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NamesMT","download_url":"https://codeload.github.com/NamesMT/sencrypt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243997127,"owners_count":20380981,"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-10-27T20:16:43.646Z","updated_at":"2025-03-19T15:30:19.752Z","avatar_url":"https://github.com/NamesMT.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sencrypt ![TypeScript heart icon](https://img.shields.io/badge/♡-%23007ACC.svg?logo=typescript\u0026logoColor=white)\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Codecov][codecov-src]][codecov-href]\n[![Bundlejs][bundlejs-src]][bundlejs-href]\n[![jsDocs.io][jsDocs-src]][jsDocs-href]\n\n**sencrypt** (SEncrypt - Stateful-salt Encryption)\n\nSEncrypt is a collection of helpers to implement an encrypted secret system.\n\nSEncrypt requires a storage interface to be passed in, which is used by `SHash` to store the stateful salt.\n\nSEncrypt takes a `plaintext`, encrypts it with a secret hash generated by SHash (which requires a `salt`, `partition`, and `id`), and stores the ciphertext\n\nSEncrypt extends upon and uses [**SHash**](https://github.com/NamesMT/shash) under-the-hood to manage the secret hash key.  \nPlease take a look at SHash.\n\nSEncrypt supports any encryption algorithm, it is recommended to use AES-GCM for the balance of security and performance,\n\nNote: Encryption algorithm is not included in this package, you can use any encryption algorithm you want.\n\n## Features\n- [x] TypeScript ready!\n\n## Usage\n### Install package:\n```sh\n# npm\nnpm install @namesmt/sencrypt\n\n# yarn\nyarn add @namesmt/sencrypt\n\n# pnpm (recommended)\npnpm install @namesmt/sencrypt\n```\n\n### Import and use:\n```ts\n// ESM\nimport { SEncrypt, SEncryptEncrypterInterface, SEncryptStorageInterface } from '@namesmt/sencrypt'\nimport { decrypt as aesGcmDecrypt, encrypt as aesGcmEncrypt } from '@namesmt/aes-gcm'\n\n/**\n * This is a simple in-memory storage implementation.\n * \n * This is not recommended for production use, but it is useful for testing.\n */\nexport class MemoryStorage implements SEncryptStorageInterface {\n  saltStore: Record\u003cstring, string\u003e = {}\n\n  cipherStore: Record\u003cstring, string\u003e = {}\n\n  async getSalt(partition: string, id: string) { return this.saltStore[`${partition}#${id}`] }\n  async setSalt(partition: string, id: string, value: string) { this.saltStore[`${partition}#${id}`] = value }\n\n  async getCiphertext(partition: string, id: string) { return this.cipherStore[`${partition}#${id}`] }\n  async setCiphertext(partition: string, id: string, value: string) { this.cipherStore[`${partition}#${id}`] = value }\n}\n\nexport class AesGcmEncrypter implements SEncryptEncrypterInterface {\n  encrypt = aesGcmEncrypt\n\n  decrypt = aesGcmDecrypt\n}\n\n// A simple hash function for demo purposes\nfunction demoHash(str: string) {\n  return `${str}-demohashed`\n}\n\nconst {\n  encrypt, // Encrypts plaintext into ciphertext, secured with a hash key created from the given salt, partition and id.\n  encryptStore, // ^^^ but also stores the ciphertext into the storage.\n  decrypt, // Decrypts a ciphertext that was secured with a hash key created from the given salt, partition and id, back into plaintext.\n  decryptStored, // ^^^ but the ciphertext is retrieved from the storage.\n  decryptStoredFlash, // ^^^ and the ciphertext is deleted from the storage after decryption.\n} = new SEncrypt(new MemoryStorage(), demoHash, new AesGcmEncrypter()) // You could pass in any hashing and encryption algorithm.\n\nconst encrypted = await encrypt('salt', 'partition', 'id', 'plaintext') // encrypted string of 'plaintext'\nconst decrypted = await decrypt('salt', 'partition', 'id', encrypted) // returns 'plaintext'\n\nconst storedEncrypted = await encryptStore('salt', 'partition', 'id', 'plaintext') // encrypted string of 'plaintext'\nconst storedDecrypted = await decryptStored('salt', 'partition', 'id') // returns 'plaintext'\nconst storedDecryptedFlash = await decryptStoredFlash('salt', 'partition', 'id') // returns 'plaintext'\n\nconst storedDecrypted_error = await decryptStored('salt', 'partition', 'id') // Should throw an error because the ciphertext is not found.\n```\n\n## Roadmap\n- [ ] Become the legendary 10000x developer\n\n## License [![License][license-src]][license-href]\n[MIT](./LICENSE) License © 2024 [NamesMT](https://github.com/NamesMT)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/@namesmt/sencrypt?labelColor=18181B\u0026color=F0DB4F\n[npm-version-href]: https://npmjs.com/package/@namesmt/sencrypt\n[npm-downloads-src]: https://img.shields.io/npm/dm/@namesmt/sencrypt?labelColor=18181B\u0026color=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/@namesmt/sencrypt\n[codecov-src]: https://img.shields.io/codecov/c/gh/namesmt/sencrypt/main?labelColor=18181B\u0026color=F0DB4F\n[codecov-href]: https://codecov.io/gh/namesmt/sencrypt\n[license-src]: https://img.shields.io/github/license/namesmt/sencrypt.svg?labelColor=18181B\u0026color=F0DB4F\n[license-href]: https://github.com/namesmt/sencrypt/blob/main/LICENSE\n[bundlejs-src]: https://img.shields.io/bundlejs/size/@namesmt/sencrypt?labelColor=18181B\u0026color=F0DB4F\n[bundlejs-href]: https://bundlejs.com/?q=@namesmt/sencrypt\n[jsDocs-src]: https://img.shields.io/badge/Check_out-jsDocs.io---?labelColor=18181B\u0026color=F0DB4F\n[jsDocs-href]: https://www.jsdocs.io/package/@namesmt/sencrypt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamesmt%2Fsencrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnamesmt%2Fsencrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamesmt%2Fsencrypt/lists"}