{"id":22731378,"url":"https://github.com/sno2/shard","last_synced_at":"2026-03-19T23:31:34.771Z","repository":{"id":112569105,"uuid":"368749461","full_name":"sno2/shard","owner":"sno2","description":"An authentic unique ID for everyone and everything.","archived":false,"fork":false,"pushed_at":"2021-05-19T05:09:37.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-05T03:28:26.600Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sno2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-05-19T05:02:49.000Z","updated_at":"2022-12-01T00:44:15.000Z","dependencies_parsed_at":"2023-05-16T08:45:14.260Z","dependency_job_id":null,"html_url":"https://github.com/sno2/shard","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fshard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fshard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fshard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fshard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sno2","download_url":"https://codeload.github.com/sno2/shard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246264707,"owners_count":20749508,"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-12-10T19:21:55.882Z","updated_at":"2026-01-08T06:05:41.250Z","avatar_url":"https://github.com/sno2.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shard\n\nAn authentic unique ID for everyone and everything.\n\n```\n64 (44) Timestamp                               20 (6) Service   14 (14) Noise 0\n 00010111010101011101110111010011101111000111    000000           00000000000000\n```\n\n## Usage\n\nThe shard module is very easy to use, simply import Shard like:\n\n```ts\n// Imports\nimport { Shard } from \"https://deno.land/x/shard/mod.ts\";\n```\n\nTo generate a new shard simply create a new instance of shard:\n\n```ts\nconst sid = new Shard();\n```\n\nTo get a string representative of the shard simply call `\u003cShard\u003e.str()`.\n\n```ts\nsid.str();\n// 20dLrFRw1eE\n```\n\nTo get the timestamp, shard/serviceID or count simply call their respective methods:\n\n```ts\nsid.count(); // 0\nsid.service(); // serviceID\nsid.timestamp(); // 1603702991291\nsid.date(); // 2020-10-26T09:03:31.309Z\n```\n\nYou can also change either of the values by passing a value into their respective values.\n\nTo load a generated shard simply pass it into the Shard constructor as an argument.\n\n```ts\nnew Shard(\"20dLrFRw1eE\");\n```\n\n## Multi-threaded\n\nIf you're using Shard when using multiple threads or workers you should also define the serviceID in the shard object to prevent ID collisions:\n\n```ts\nnew Shard({ service: 1 });\n```\n\n## Shards with Integrity\n\nShards with integrity is a concept very similar to JSON Web Tokens, the only differences are that an integrity shard doesn't store header info or JSON data. An integrity shard stores a hash, expiration timestamp, last updated timestamp and issued at timestamp, version and the shard (id) itself. This reaches the same goals as JWT just for storing an authentic ID. The ID cannot be manipulated, nor can any of the timestamps.\n\n```ts\n// Imports\nimport { IntegrityShard } from \"https://deno.land/x/shard\";\n```\n\nCreate a new integrity shard.\n\n```ts\nconst myShard = new Shard();\n\nconst token = new IntegrityShard({\n\tsecret: \"hello-world\",\n\tshard: myShard\n});\n\n// Should be passed as Authorization header.\nconst Authorization = token.str();\n\n// Should be passed as X-Refresh-Token header.\nconst xRefreshToken = token.getRefreshToken();\n```\n\nTo verify a refresh token execute the following:\n\n```ts\ntoken.verifyRefreshToken(xRefreshToken);\n// \"refresh token expired\"\n// \"refresh token invalid\"\n// undefined\n```\n\nThe refresh token verification will return a string upon failure, or undefined if there are no issues with the refresh token.\n\nTo validate the integrity of the integrity shard execute the following:\n\n```ts\ntoken.verify();\n// \"token expired\"\n// \"token invalid\"\n// undefined\n```\n\nThe integrity shard verification will return a string upon failure, or undefined if there are no issues with the integrity shard.\n\n### Extend integrity shard lifetime\n\n```ts\nconst token = IntegrityShard.from(secret, req.headers.authorization);\n\n// Verify that the token has not been tampered with.\nconst __tokenVerify = token.verify();\nif (typeof __tokenVerify === \"string\")\n\tthrow new Error(__tokenVerify);\n\nconst __refreshTokenVerify = token.verifyRefreshToken(req.headers[\"refresh-token\"]);\nif (typeof __refreshTokenVerify === \"string\")\n\tthrow new Error(__refreshTokenVerify);\n\n// give this new token to the client\nconst newIntegrityShard = token.ext();\nconst newToken = newIntegrityShard.str();\nconst newRefreshToken = newToken.getRefreshToken();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fshard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsno2%2Fshard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fshard/lists"}