{"id":17674934,"url":"https://github.com/arnav-kr/dc-tokens","last_synced_at":"2025-10-09T22:03:04.932Z","repository":{"id":40383323,"uuid":"491098409","full_name":"arnav-kr/DC-Tokens","owner":"arnav-kr","description":"Discord Like Tokens for Authentication for Everyone. Uses HMAC with SHA-256","archived":false,"fork":false,"pushed_at":"2024-10-13T05:32:46.000Z","size":1374,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-17T19:29:43.463Z","etag":null,"topics":["auth","authentication","dc-token","dc-tokens","dct","discord","hacktoberfest","hmac","hmac-sha256","javascript","nodejs","token"],"latest_commit_sha":null,"homepage":"https://arnav.is-a.dev/DC-Tokens","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/arnav-kr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"patreon":"arnavkr","ko_fi":"arnav","github":"arnav-kr"}},"created_at":"2022-05-11T12:20:21.000Z","updated_at":"2025-02-09T05:21:49.000Z","dependencies_parsed_at":"2024-10-24T08:34:21.822Z","dependency_job_id":"01f434e0-165c-4b91-bdd8-92ffb42a81ad","html_url":"https://github.com/arnav-kr/DC-Tokens","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"78ab39c06390aa9c33a7d21458242c2cf593e928"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arnav-kr/DC-Tokens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnav-kr%2FDC-Tokens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnav-kr%2FDC-Tokens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnav-kr%2FDC-Tokens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnav-kr%2FDC-Tokens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnav-kr","download_url":"https://codeload.github.com/arnav-kr/DC-Tokens/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnav-kr%2FDC-Tokens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002034,"owners_count":26083286,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["auth","authentication","dc-token","dc-tokens","dct","discord","hacktoberfest","hmac","hmac-sha256","javascript","nodejs","token"],"created_at":"2024-10-24T07:09:25.051Z","updated_at":"2025-10-09T22:03:04.894Z","avatar_url":"https://github.com/arnav-kr.png","language":"TypeScript","funding_links":["https://patreon.com/arnavkr","https://ko-fi.com/arnav","https://github.com/sponsors/arnav-kr"],"categories":[],"sub_categories":[],"readme":"# DC Tokens\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/arnav-kr/DC-Tokens/main/images/DCT.svg\" width=\"200px\" /\u003e\u003c/p\u003e\n\n[![npm version](https://img.shields.io/npm/v/dc-tokens.svg?maxAge=3600)](https://npmjs.com/package/dc-tokens)\n[![npm downloads](https://img.shields.io/npm/dt/dc-tokens.svg?maxAge=3600)](https://npmjs.com/package/dc-tokens)\n\n---\n\n## About\n\nDCTokens are the discord like tokens that can be used for authentiction in your website, api, or anything you want (you can even trick people to think its an actual discord token 😉).\n\n![Token Structure](https://raw.githubusercontent.com/arnav-kr/DC-Tokens/main/images/TokenStructure.svg)\n\nIt Uses HMAC with SHA-256 to sign the tokens.\n\n## Features\n* Sign Custom Tokens (with your own private key) 📝\n* Verify Tokens ✅\n* Zero-Depencency 💪\n\n## Install\n\n**Via NPM:**\n\n```bash\nnpm install dc-tokens\n```\n\n**Via Yarn:**\n\n```bash\nyarn add dc-tokens\n```\n\n**Via PNPM**\n  \n```bash\npnpm install dc-tokens\n```\n\n[**CHANGELOG**](https://github.com/arnav-kr/DC-Tokens/blob/main/CHANGELOG.md)\n\n## Usage\n\n\u003e **NOTE:** For Node.js only (not supported in browsers)\n\n### DCT.sign(payload, privateKey, [options, callback])\n\nIf a callback is supplied, the callback is called with the `err` and the `Token`.\n\nElse returns the `DCToken` as string\n\n`payload` should be string.\n\n`privateKey` is a string or buffer.\n\n`options` is an object with the following properties:\n  * `timestamp` (in milliseconds) - defaults to `Date.now()`\n  * `epoch` (in milliseconds) - defaults to Milliseconds since Discord Epoch: `1420070400000`\n\n`callback` is a function that is called with the `err` and the `Token` as string respectively.\n\nSynchronous Sign:\n\n```js\nconst DCT = require('dc-tokens');\nlet token = DCT.sign(\"Cute little cats\", \"secret\");\n```\n\nSign asynchronously\n  \n```js\nconst DCT = require('dc-tokens');\n\nDCT.sign(\"Cute little cats\", \"secret\", { }, (err, token) =\u003e {\n  if (err) {\n    console.error(err);\n  } else {\n    console.log(token);\n  }\n});\n```\n\n### DCT.verify(token, privateKey, [options, callback])\n\nIf a callback is supplied, the callback is called with the `err` and the `TokenObject`.\n\nElse returns the `TokenObject` as string\n\nThe `TokenObject` is an object with the following structure\n\n```ts\n{\n  payload: string;\n  timestamp: Date;\n  signature: string;\n}\n```\n\n`privateKey` is a string or buffer. it should be the same key that was used to generate the token.\n\n`options` is an object with the following properties:\n  * `epoch` (in milliseconds) - defaults to Milliseconds since Discord Epoch: `1420070400000`\n\n`callback` is a function that is called with the `err` and the `TokenObject` respectively.\n\nVerify Asynchronously\n  \n```js\nconst DCT = require('dc-tokens');\n\nDCT.verify(token, privateKey, options, (err, decoded) =\u003e{\n    console.log(decoded);\n});\n```\n\nVerify Synchronously\n  \n```js\nconst DCT = require('dc-tokens');\n\nlet decoded = DCT.verify(token, privateKey, options);\n```\n\nHandiling Errors\n\n```js\nconst DCT = require('dc-tokens');\n\n// Handling Erros - Asynchronously\nDCT.verify(token, privateKey, options, (err, decoded) =\u003e{\n  if (err) {\n    console.error(err);\n  } else {\n    console.log(decoded);\n  }\n});\n\n// Handling Erros - Synchronously\ntry{\n  let decoded = DCT.verify(token, privateKey, options);\n} catch (err) {\n  console.error(err);\n}\n```\n\n## Error Codes\n\nthe error that is passed as the first paramater in the callback function in either `sign` or `verify` has a specific structure when running asynchronously.\n\n```ts\n{\n  code: DCTError;\n  message: string;\n  stack?: string;\n}\n```\n\n`DCTError` can have the following values:\n* `INVALID_TOKEN` - token is invalid\n* `TOKEN_MALFORMED` - token is malformed\n* `SIGNATURE_REQUIRED` - signature is required\n* `INVALID_SIGNATURE` - invalid signature\n* `UNCAUGHT_ERROR` - uncaught error (any other error)\n* `TIMESTAMP_MALFORMED` - malformed timestamp\n\nIf used synchronously, the error is thrown.\n\n## Report an Issue \n\nIf you have found a bug or if you have a feature request, please report them at this repository issues section.\n\n## Author\n\n[arnav-kr](https://github.com/arnav-kr)\n\n## License\n\nThe project is licensed under the [MIT](https://github.com/arnav-kr/DC-Tokens/blob/main/LICENSE) license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnav-kr%2Fdc-tokens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnav-kr%2Fdc-tokens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnav-kr%2Fdc-tokens/lists"}