{"id":13564254,"url":"https://github.com/alexfilatov/borsh","last_synced_at":"2025-08-01T09:35:34.714Z","repository":{"id":57480433,"uuid":"443865707","full_name":"alexfilatov/borsh","owner":"alexfilatov","description":"Elixir implementation of the BORSH binary serializer.","archived":false,"fork":false,"pushed_at":"2023-01-02T01:28:30.000Z","size":55,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-24T06:35:16.119Z","etag":null,"topics":["binary","near-blockchain","serialization"],"latest_commit_sha":null,"homepage":"https://borsh.io","language":"Elixir","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/alexfilatov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-02T20:42:32.000Z","updated_at":"2025-01-17T19:09:27.000Z","dependencies_parsed_at":"2023-02-01T01:25:13.515Z","dependency_job_id":null,"html_url":"https://github.com/alexfilatov/borsh","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexfilatov/borsh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfilatov%2Fborsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfilatov%2Fborsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfilatov%2Fborsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfilatov%2Fborsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexfilatov","download_url":"https://codeload.github.com/alexfilatov/borsh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfilatov%2Fborsh/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268199758,"owners_count":24211823,"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-08-01T02:00:08.611Z","response_time":67,"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":["binary","near-blockchain","serialization"],"created_at":"2024-08-01T13:01:28.725Z","updated_at":"2025-08-01T09:35:34.663Z","avatar_url":"https://github.com/alexfilatov.png","language":"Elixir","funding_links":[],"categories":["Protocols"],"sub_categories":[],"readme":"# Borsh [![Build Status](https://github.com/alexfilatov/borsh/workflows/CI/badge.svg?branch=main)](https://github.com/alexfilatov/borsh/actions?query=workflow%3ACI) [![Hex pm](https://img.shields.io/hexpm/v/borsh.svg?style=flat)](https://hex.pm/packages/borsh) [![hex.pm downloads](https://img.shields.io/hexpm/dt/borsh.svg?style=flat)](https://hex.pm/packages/borsh)\n\nBORSH, binary serializer for security-critical projects.\n\nBorsh stands for \"Binary Object Representation Serializer for Hashing\".\nIt is meant to be used in security-critical projects as it prioritizes consistency, safety, speed;\nand comes with a strict specification.\nIn short, Borsh is a non self-describing binary serialization format.\nIt is designed to serialize any objects to canonical and deterministic set of bytes.\n\nGeneral principles of Borsh serialization:\n\n- Integers are encoded in little-endian format.\n- The size of dynamic containers (such as hash maps and hash sets) is written as a 32-bit unsigned integer before the\n  values.\n- All unordered containers are ordered lexicographically by key, with a tie breaker of the value.\n- Structs are serialized in the order of their fields.\n- Enums are serialized by storing the ordinal as an 8-bit unsigned integer, followed by the data contained within the\n  enum value (if present).\n\nThis is Elixir implementation of the Borsh serializer and deserializer.\nOfficial specification: https://github.com/near/borsh#specification\n\nA little article on Medium about Borsh serializer in more\ndetails: https://medium.com/@alexfilatov/borsh-binary-serialiser-for-near-protocol-eed79a1638f4\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed by adding `borsh` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:borsh, \"~\u003e 0.1\"}\n  ]\nend\n```\n\n## Usage\n\n```elixir\n  use Borsh,\n      schema: [\n        signer_id: :string,\n        public_key: {:borsh, PublicKey},\n        nonce: :u64,\n        receiver_id: :string,\n        block_hash: [32],\n        actions: [\n          {:borsh, ActionOne}, \n          {:borsh, ActionTwo}\n        ]\n      ]\n```\n\nIn this example `ActionOne`, `ActionTwo` and `PublicKey` are structs that implement `Borsh` protocol.\n\n### Options\n\n`schema`: Borsh schema itself, structure of fields for serialisation with serialisation formats described below.\n\n### Borsh literal formats\n\n#### String literals\n\n`:string` - string, encoded as utf-8 bytes\n\n`[32]` and `[64]` - A string with 32/64 chars length.\n\n#### Number literals\n\n`:u8` - unsigned 8-bit integer\n\n`:u16` - unsigned 16-bit integer\n\n`:u32` - unsigned 32-bit integer\n\n`:u64` - unsigned 64-bit integer\n\n`:i8` - signed 8-bit integer\n\n`:i16` - signed 16-bit integer\n\n`:i32` - signed 32-bit integer\n\n`:i64` - signed 64-bit integer\n\n`:f32` - 32-bit float\n\n`:f64` - 64-bit float\n\n#### Borsh-typed literals\n\nTo define custom types for serialization, we can use the syntax `{:borsh, StructModule}` in a parent struct, when we\nwant to serialize another struct within it. There are single and arrays of borsh types.\n\n`{:borsh, Module}` - The syntax represents a single struct of a borsh-encoded module. When this struct is passed to the\nserializer, the serializer will execute the `.borsh_encode` method of the struct's module on the struct.\n\n`:borsh` - has the same effect as `{:borsh, Module}`, but the resulting serialized data cannot be decoded back into the\noriginal struct. Using `:borsh` for serialization is safe for sending transactions to the NEAR blockchain, as the main\nconcern is just the serialization itself.\n\n`[{:borsh, Module}]` - represents an enumeration of borsh-encoded structs, where each element of the list must have a\nBorsh schema.\n\n`[:borsh]` - has the same effect as [{:borsh, Module}], but the resulting serialized data cannot be decoded back into\nthe original structs. It can only be used for encoding, not decoding.\n\n`[{:borsh, Module1}, {:borsh, Module2}]` - represents an enumeration of borsh-encoded structs, where each element\nof the list must have a Borsh schema. Each element in the list can belong to a different module, and the sequence of\nelements is important. This syntax can be used for both encoding and decoding.\n\n## License\n\n    Copyright © 2021-present Alex Filatov \u003calex@alexfilatov.com\u003e\n\n    This work is free. You can redistribute it and/or modify it under the\n    terms of the MIT License. See the LICENSE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfilatov%2Fborsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexfilatov%2Fborsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfilatov%2Fborsh/lists"}