{"id":21594455,"url":"https://github.com/foxhound-systems/hs-obfuscate","last_synced_at":"2025-05-05T21:15:00.612Z","repository":{"id":175889570,"uuid":"306457358","full_name":"foxhound-systems/hs-obfuscate","owner":"foxhound-systems","description":"Library for easy obfuscation and deobfuscation of integer IDs in custom data types","archived":false,"fork":false,"pushed_at":"2025-01-08T18:22:01.000Z","size":15,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-05T21:14:51.528Z","etag":null,"topics":["hashids","haskell","obfuscation"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foxhound-systems.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":"2020-10-22T20:59:34.000Z","updated_at":"2025-01-08T18:22:06.000Z","dependencies_parsed_at":"2023-07-12T00:16:12.855Z","dependency_job_id":null,"html_url":"https://github.com/foxhound-systems/hs-obfuscate","commit_stats":null,"previous_names":["foxhound-systems/hs-obfuscate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxhound-systems%2Fhs-obfuscate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxhound-systems%2Fhs-obfuscate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxhound-systems%2Fhs-obfuscate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxhound-systems%2Fhs-obfuscate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxhound-systems","download_url":"https://codeload.github.com/foxhound-systems/hs-obfuscate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252577026,"owners_count":21770721,"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":["hashids","haskell","obfuscation"],"created_at":"2024-11-24T17:18:26.366Z","updated_at":"2025-05-05T21:15:00.584Z","avatar_url":"https://github.com/foxhound-systems.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Obfuscate\r\n=========\r\n\r\nThis library makes it easy to use obfuscation in your application code, allowing you to obscure numeric ids before sending them to a client (such as in a JSON API or other web service). This library is backed by [`foxhound-systems/hashids-st`](https://github.com/foxhound-systems/hashids-st), which itself is an implementation of the [Hashids.org](https://hashids.org/) obfuscation interface.\r\n\r\n## Implementation\r\n\r\nThe `Web.Obfuscate` module provides `CanObfuscate` and `CanDeobfuscate` typeclasses along with several default instances for basic data types. In addition to manually defining your own instances, `Web.Obfuscate.TH` will derive a sensible default using `deriveObfuscate`.\r\n\r\n\r\n## Example Usage\r\n\r\n### Basic Usage\r\n\r\n```haskell\r\nimport Web.Obfuscate\r\nimport Hashids\r\n\r\n...\r\n\r\nhashidsContext :: HashidsContext\r\nhashidsContext = ctx\r\n    where\r\n      (Right ctx) = mkHashidsContext \"test-salt-please-ignore\" 7 defaultAlphabet\r\n\r\ngetUser :: Obfuscated UserId -\u003e IO (User)\r\ngetUser obfuscatedUserId =\r\n    maybeUserId \u003c- deobfuscate hashidsContext obfuscatedUserId\r\n    case maybeUserId of\r\n        Just userId -\u003e\r\n          fetchUserById userId\r\n\r\n        Nothing -\u003e\r\n          throwIO err400\r\n\r\n```\r\n\r\n### Deriving Obfuscation Instances with Template Haskell\r\n\r\n```haskell\r\n{-# LANGUAGE TemplateHaskell #-}\r\n\r\nmodule ForumResponse\r\n  where\r\n\r\nimport Web.Obfuscate\r\nimport Web.Obfuscate.TH\r\nimport qualified Data.Text as T\r\n\r\n-- Another module that defines another custom obfuscatable type\r\nimport ForumAdministrator\r\n\r\ndata ForumResponse = ForumResponse\r\n  { frForumId :: ForumId\r\n  , frName :: Text\r\n  , frDescription :: Text\r\n  , frCreator :: ForumAdministrator\r\n  , frAdministrators :: [ForumAdministrator]\r\n  }\r\n\r\n$(deriveObfuscate defaultObfuscationOptions ''ForumResponse)\r\n```\r\n\r\nThe above Template Haskell code will generate something like the following:\r\n\r\n```haskell\r\ndata ObfuscatedForumResponse = ObfuscatedForumResponse\r\n    { obfrForumId :: Obfuscated ForumId\r\n    , obfrName :: Text\r\n    , obfrDescription :: Text\r\n    , obfrCreator :: Obfuscated ForumAdministrator\r\n    , obfrAdministrators :: Obfuscated [ForumAdministrator]\r\n    }\r\n\r\ntype instance Obfuscated ForumResponse = ObfuscatedForumResponse\r\n\r\ninstance CanObfuscate ForumResponse where\r\n    obfuscate ctx forumResponse =\r\n        ObfuscatedForumResponse\r\n            { obfrForumId = obfuscate ctx $ frForumId forumResponse\r\n            , obfrName = frName forumResponse\r\n            , obfrDescription = frDescription forumResponse\r\n            , obfrCreator = obfuscate ctx $ frCreator forumResponse\r\n            , obfrAdministrators = obfuscate ctx $ frAdministrators forumResponse\r\n            }\r\n\r\ninstance CanDeobfuscateForumResponse where\r\n    deobfuscate ctx obfuscatedForumResponse = do\r\n        forumId \u003c- deobfuscate ctx $ obfrForumId obfuscatedForumResponse\r\n        creator \u003c- deobfuscate ctx $ obfrCreator obfuscatedForumResponse\r\n        administrators \u003c- deobfuscate ctx $ obfrAdministrators obfuscatedForumResponse\r\n        pure $ ForumResponse\r\n            { frForumId = forumId\r\n            , frName = obfrName obfuscatedForumResponse\r\n            , frDescription = obfrDescription obfuscatedForumResponse\r\n            , frCreator = creator\r\n            , frAdministrators = administrators\r\n            }\r\n```\r\n\r\n## Development\r\n\r\nDevelopment of this library is done using Nix. With `nix` installed, following command to start a ghcid session in an isolated environment and run the reloading tests:\r\n\r\n```\r\nnix-shell --run \"make tests-watch\"\r\n```\r\n\r\nRun `nix-build` to perform a full build of the library.\r\n\r\n## License\r\n\r\nSee the [LICENSE](https://github.com/foxhound-systems/hs-obfuscate/blob/master/LICENSE) file.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxhound-systems%2Fhs-obfuscate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxhound-systems%2Fhs-obfuscate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxhound-systems%2Fhs-obfuscate/lists"}