{"id":18417359,"url":"https://github.com/stellar/js-xdr","last_synced_at":"2025-04-07T09:18:37.450Z","repository":{"id":28963225,"uuid":"32489463","full_name":"stellar/js-xdr","owner":"stellar","description":"Read/write XDR encoded data structures (RFC 4506)","archived":false,"fork":false,"pushed_at":"2024-08-31T06:52:09.000Z","size":1880,"stargazers_count":26,"open_issues_count":10,"forks_count":32,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-03-31T06:07:56.645Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stellar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2015-03-18T23:16:57.000Z","updated_at":"2025-01-06T18:24:07.000Z","dependencies_parsed_at":"2023-11-20T22:25:23.812Z","dependency_job_id":"71cd5de3-c9c5-4c8a-8585-856428ff0325","html_url":"https://github.com/stellar/js-xdr","commit_stats":{"total_commits":171,"total_committers":21,"mean_commits":8.142857142857142,"dds":0.5146198830409356,"last_synced_commit":"07174f9fcc3e1c90e014e360aa49456e4b2aaff1"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellar%2Fjs-xdr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellar%2Fjs-xdr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellar%2Fjs-xdr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellar%2Fjs-xdr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stellar","download_url":"https://codeload.github.com/stellar/js-xdr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622983,"owners_count":20968575,"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-06T04:09:03.894Z","updated_at":"2025-04-07T09:18:37.430Z","avatar_url":"https://github.com/stellar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XDR, for Javascript\n\nRead/write XDR encoded data structures (RFC 4506)\n\n[![Build Status](https://travis-ci.com/stellar/js-xdr.svg?branch=master)](https://travis-ci.com/stellar/js-xdr)\n[![Code Climate](https://codeclimate.com/github/stellar/js-xdr/badges/gpa.svg)](https://codeclimate.com/github/stellar/js-xdr)\n[![Dependency Status](https://david-dm.org/stellar/js-xdr.svg)](https://david-dm.org/stellar/js-xdr)\n[![devDependency Status](https://david-dm.org/stellar/js-xdr/dev-status.svg)](https://david-dm.org/stellar/js-xdr#info=devDependencies)\n\nXDR is an open data format, specified in\n[RFC 4506](http://tools.ietf.org/html/rfc4506.html). This library provides a way\nto read and write XDR data from javascript. It can read/write all of the\nprimitive XDR types and also provides facilities to define readers for the\ncompound XDR types (enums, structs and unions)\n\n## Installation\n\nvia npm:\n\n```shell\nnpm install --save @stellar/js-xdr\n```\n\n## Usage\n\nYou can find some [examples here](examples/).\n\nFirst, let's import the library:\n\n```javascript\nvar xdr = require('@stellar/js-xdr');\n// or\nimport xdr from '@stellar/js-xdr';\n```\n\nNow, let's look at how to decode some primitive types:\n\n```javascript\n// booleans\nxdr.Bool.fromXDR([0, 0, 0, 0]); // returns false\nxdr.Bool.fromXDR([0, 0, 0, 1]); // returns true\n\n// the inverse of `fromXDR` is `toXDR`, which returns a Buffer\nxdr.Bool.toXDR(true); // returns Buffer.from([0,0,0,1])\n\n// XDR ints and unsigned ints can be safely represented as\n// a javascript number\n\nxdr.Int.fromXDR([0xff, 0xff, 0xff, 0xff]); // returns -1\nxdr.UnsignedInt.fromXDR([0xff, 0xff, 0xff, 0xff]); // returns 4294967295\n\n// XDR Hypers, however, cannot be safely represented in the 53-bits\n// of precision we get with a JavaScript `Number`, so we allow creation from big-endian arrays of numbers, strings, or bigints.\nvar result = xdr.Hyper.fromXDR([0, 0, 0, 0, 0, 0, 0, 0]); // returns an instance of xdr.Hyper\nresult = new xdr.Hyper(0); // equivalent\n\n// convert the hyper to a string\nresult.toString(); // return '0'\n\n// math!\nvar ten = result.toBigInt() + 10;\nvar minusone = result.toBigInt() - 1;\n\n// construct a number from a string\nvar big = xdr.Hyper.fromString('1099511627776');\n\n// encode the hyper back into xdr\nbig.toXDR(); // \u003cBuffer 00 00 01 00 00 00 00 00\u003e\n```\n\n## Caveats\n\nThere are a couple of caveats to be aware of with this library:\n\n1.  We do not support quadruple precision floating point values. Attempting to\n    read or write these values will throw errors.\n2.  NaN is not handled perfectly for floats and doubles. There are several forms\n    of NaN as defined by IEEE754 and the browser polyfill for node's Buffer\n    class seems to handle them poorly.\n\n## Code generation\n\n`js-xdr` by itself does not have any ability to parse XDR IDL files and produce\na parser for your custom data types. Instead, that is the responsibility of\n[`xdrgen`](http://github.com/stellar/xdrgen). xdrgen will take your .x files\nand produce a javascript file that target this library to allow for your own\ncustom types.\n\nSee [`stellar-base`](http://github.com/stellar/js-stellar-base) for an example\n(check out the src/generated directory)\n\n## Contributing\n\nPlease [see CONTRIBUTING.md for details](CONTRIBUTING.md).\n\n### To develop and test js-xdr itself\n\n1. Clone the repo\n\n```shell\ngit clone https://github.com/stellar/js-xdr.git\n```\n\n2. Install dependencies inside js-xdr folder\n\n```shell\ncd js-xdr\nnpm i\n```\n\n3. Install Node 14\n\nBecause we support the oldest maintenance version of Node, please install and\ndevelop on Node 14 so you don't get surprised when your code works locally but\nbreaks in CI.\n\nHere's out to install `nvm` if you haven't: https://github.com/creationix/nvm\n\n```shell\nnvm install\n\n# if you've never installed 14.x before you'll want to re-install yarn\nnpm install -g yarn\n```\n\nIf you work on several projects that use different Node versions, you might it\nhelpful to install this automatic version manager:\nhttps://github.com/wbyoung/avn\n\n4. Observe the project's code style\n\nWhile you're making changes, make sure to run the linter periodically to catch any linting errors (in addition to making sure your text editor supports ESLint)\n\n```shell\nyarn fmt\n````\n\nIf you're working on a file not in `src`, limit your code to Node 14! See what's\nsupported here: https://node.green/ (The reason is that our npm library must\nsupport earlier versions of Node, so the tests need to run on those versions.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellar%2Fjs-xdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstellar%2Fjs-xdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellar%2Fjs-xdr/lists"}