{"id":18285886,"url":"https://github.com/exodusmovement/bintoken","last_synced_at":"2025-04-09T06:20:57.601Z","repository":{"id":57112427,"uuid":"370822065","full_name":"ExodusMovement/bintoken","owner":"ExodusMovement","description":"Binary encoding of named fixed-length buffers.","archived":false,"fork":false,"pushed_at":"2023-03-15T15:02:41.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-03-12T08:51:24.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"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/ExodusMovement.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-25T20:38:38.000Z","updated_at":"2023-03-15T14:21:15.000Z","dependencies_parsed_at":"2024-12-22T21:37:24.172Z","dependency_job_id":null,"html_url":"https://github.com/ExodusMovement/bintoken","commit_stats":{"total_commits":12,"total_committers":4,"mean_commits":3.0,"dds":"0.33333333333333337","last_synced_commit":"8822d2d5201d195dd988e930817066130430734a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fbintoken","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fbintoken/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fbintoken/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fbintoken/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExodusMovement","download_url":"https://codeload.github.com/ExodusMovement/bintoken/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247988019,"owners_count":21029034,"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-11-05T13:18:04.508Z","updated_at":"2025-04-09T06:20:57.571Z","avatar_url":"https://github.com/ExodusMovement.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bintoken\n\nA bintoken is an encoded binary message of a fixed length, meant to serve as a message which can be signed. Depending on the type byte, and who signed the bintoken, the message may hold different meanings.\n\nFor example, if the type indicates the message is an authentication token, and the bintoken is signed by a server's private key, this might provide a guarantee that the server verified some information at the time indicated in the bintoken.\n\nThe encoding format of the token is specified in-advance by instantiating the `BintokenEncoding` class exported by this package. The encoding is specified with property names and lengths for each property. The key names are sorted alphabetically when encoding and decoding bintokens.\n\nThe deterministic binary format simplifies signature verification. Its fixed length simplifies decoding \u0026 validation, and thus reduces the chance for malicious exploitation. Unlike with other formats such as JSON, there is only _one_ way to encode a message within a bintoken encoding scheme.\n\nHere is the generic serialization format of any bintoken encoding:\n\n- type (1 byte) : a version number which can be used to identify the context of the message.\n- [...payload properties]\n- time (4 bytes) : the timestamp (in unix seconds) when the message was created, encoded as a big-endian uint32.\n\n## Example\n\nHere is an example of a bintoken encoding which encodes only a 32-byte public key as the payload:\n\n```js\nconst BintokenEncoding = require('@exodus/bintoken')\n\nconst tokenEncoding = new BintokenEncoding({ publicKey: 32, hash: 20 })\n\nconst token = tokenEncoding.toBuffer({\n  type: 1,\n  publicKey: randomBytes(32),\n  hash: randomBytes(20),\n})\n\n/*\n  // Erroneous use\n  const token = tokenEncoding.toBuffer({ type: 1, publicKey: randomBytes(32), hash: randomBytes(20), otherProp: Buffer.alloc(0) })\n  const token = tokenEncoding.toBuffer({ type: 1, publicKey: randomBytes(31), hash: randomBytes(20) })\n  const token = tokenEncoding.toBuffer({ type: 1, publicKey: 'foo', hash: randomBytes(20) })\n  const token = tokenEncoding.toBuffer({ type: 1 })\n*/\n\nconst { type, time, publicKey, hash } = tokenEncoding.fromBuffer(token)\n\n/*\n  // Error, wrong length\n  const { type, time, publicKey } = tokenEncoding.fromBuffer(\n    Buffer.concat([token, Buffer.alloc(1)])\n  )\n*/\n```\n\nIn this example, the serialization format is:\n\n- type (1 byte) : a version number which can be used to identify the context of the message.\n- hash (20) bytes : a hash over which the message holds meaning (as implied by the type).\n- public key (32 bytes) : the public key over which the message holds meaning (as implied by the type).\n- time (4 bytes) : the timestamp (in seconds) when the message was created, encoded as a big-endian uint32.\n\nNotice that `hash` is written _before_ `publicKey` in the payload, as the properties are sorted alphabetically before being written to, or read from, a bintoken. This means **the keys you choose for your message must be the same for different applications using the same bintokens.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fbintoken","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexodusmovement%2Fbintoken","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fbintoken/lists"}