{"id":17939421,"url":"https://github.com/libitx/univrse-js","last_synced_at":"2026-03-09T14:06:58.754Z","repository":{"id":42447437,"uuid":"356281660","full_name":"libitx/univrse-js","owner":"libitx","description":"Universal schema for data serialisation, signing and encryption.","archived":false,"fork":false,"pushed_at":"2022-04-05T17:24:46.000Z","size":2134,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T22:11:12.646Z","etag":null,"topics":["bitcoin","bsv","cbor","cryptography","encryption","signatures"],"latest_commit_sha":null,"homepage":"https://univrse.network","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/libitx.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":"2021-04-09T13:31:26.000Z","updated_at":"2023-08-29T00:31:58.000Z","dependencies_parsed_at":"2022-08-27T00:31:10.262Z","dependency_job_id":null,"html_url":"https://github.com/libitx/univrse-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/libitx/univrse-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Funivrse-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Funivrse-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Funivrse-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Funivrse-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libitx","download_url":"https://codeload.github.com/libitx/univrse-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Funivrse-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30297939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T13:46:43.843Z","status":"ssl_error","status_checked_at":"2026-03-09T13:46:42.821Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bitcoin","bsv","cbor","cryptography","encryption","signatures"],"created_at":"2024-10-29T00:07:20.387Z","updated_at":"2026-03-09T14:06:58.719Z","avatar_url":"https://github.com/libitx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Univrse.js\n\n![Univrse](https://github.com/libitx/univrse-js/raw/master/media/poster.png)\n\n![npm](https://img.shields.io/npm/v/univrse?color=informational)\n![License](https://img.shields.io/github/license/libitx/univrse-js?color=informational)\n![Build Status](https://img.shields.io/github/workflow/status/libitx/univrse-js/Node.js%20CI)\n\nUniversal schema for data serialisation, signing and encryption.\n\n* **Serialising data** - Simple, binary-friendly data exchange using the Concise Binary Object Representation (CBOR) data format.\n* **Authenticating data** - Protect integrity of data with digital signatures or message authentication code (MAC) algorithms.\n* **Securing data** - Ensure confidentiality and integrity of data for one or multiple recipients, using standardised authenticated encryption algorithms.\n\n## Sponsors\n\n\u003cp align=\"center\"\u003eSupported by:\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://coingeek.com\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n    \u003cimg src=\"https://www.chronoslabs.net/img/badges/coingeek.png\" width=\"180\" alt=\"Coingeek\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nYour sponsorship will help us continue to release and maintain software that Bitcoin businesses and developers depend on.\n\n#### 👉 [Sponsor Chronos Labs' open source work](https://www.chronoslabs.net/sponsor/)\n\n## Installation\n\nInstall Univrse with npm or yarn:\n\n```shell\nnpm install univrse\n# or\nyarn add univrse\n```\n\nAlternatively use in a browser via CDN:\n\n```html\n\u003cscript src=\"//unpkg.com/univrse/dist/univrse.min.js\"\u003e\u003c/script\u003e\n```\n\nUnivrse has a peer dependency on version 2 the bsv library which must also be installed in your project.\n\n## Usage\n\nFor full documentation, please refer to:\n\n* [univrse.network docs](https://univrse.network/docs)\n* [univrse.js API docs](https://libitx.github.io/univrse-js/)\n\n### Serialising data\n\nAny arbitrary payload can be wrapped in an `Envelope` structure, and then encoded in one of three serialisation formats:\n\n* `Envelope#toBuffer()` - Concise CBOR-encoded binary value\n* `Envelope#toString()` - Compact Base64-url encoded string value\n* `Envelope#toScript()` - Encoded in a Bitcoin `OP_RETURN` script\n\n```javascript\nimport { Envelope } from 'univrse'\n\n// Wrap any arbitrary data payload in an Envelope structure\nconst payload = 'Hello world!'\nconst env1 = Envelope.wrap(payload, { proto: 'univrse.demo' })\n\n// Encode the data in one of three serialisation formats\nconst envBuffer = env1.toBuffer()\nconst envString = env1.toString()\nconst envScript = env1.toScript()\n\n// Decode the serialised data back into an Envelope structure\nconst env2 = Envelope.fromBuffer(envBuffer)\nconst env3 = Envelope.fromString(envString)\nconst env4 = Envelope.fromScript(envScript)\n\n// Compare payload\nconsole.log(env2.payload === payload, env3.payload === payload, env4.payload === payload)\n// =\u003e true, true, true\n```\n\n### Using signatures\n\nDigital signatures or message authentication code (MAC) algorithms can be used to protect the integrity of an Envelope's data payload.\n\n```javascript\nimport { Envelope, Key } from 'univrse'\n\n// Generate keys\nconst aliceKey = await Key.generate('ec', 'secp256k1')\nconst alicePubKey = aliceKey.toPublic()\nconst appSecret = await Key.generate('oct', 256)\n\n// Sign and verify using a single key\nconst env1 = Envelope.wrap('Hello world!', { proto: 'univrse.demo' })\nawait env1.sign(aliceKey, { alg: 'ES256K', kid: 'alice' })\nconst v1 = await env1.verify(alicePub)\nconsole.log(v1)\n// =\u003e true\n\n// Sign and verify using multiple keys and algorithms\nconst env2 = Envelope.wrap('Hello world!', { proto: 'univrse.demo' })\nawait env2.sign([\n  [aliceKey, { alg: 'ES256K', kid: 'alice' }],\n  [appSecret, { alg: 'HS256', kid: 'app' }]\n])\nconst v2 = await env2.verify([alicePub, appSecret])\nconsole.log(v2)\n// =\u003e true\n```\n\n### Using encryption\n\nAuthenticated encryption algorithms may be used to ensure the confidentiality of an Envelope's data payload for one or multiple recipients.\n\n```javascript\nimport { Envelope, Key } from 'univrse'\n\n// Generate keys\nconst bobKey = await Key.generate('ec', 'secp256k1')\nconst bobPubKey = bobKey.toPublic()\nconst charlieKey = await Key.generate('ec', 'secp256k1')\nconst charliePubKey = bobKey.toPublic()\nconst appSecret = await Key.generate('oct', 256)\n\n// Encrypt and decrypt data for a single recipient\nconst env1 = Envelope.wrap('Hello world!', { proto: 'univrse.demo' })\nawait env1.encrypt(bobPubKey, { alg: 'ECDH-ES+A128GCM', kid: 'bob' })\nawait env1.decrypt(bobKey)\nconsole.log(env1.payload)\n// =\u003e \"Hello world!\"\n\n// Encrypt and decrypt data for multiple recipients using multiple algorithms\nconst env2 = Envelope.wrap('Hello world!', { proto: 'univrse.demo' })\nawait env2.encrypt([\n  [appSecret,     { alg: 'A256GCM' }],\n  [bobPubKey,     { alg: 'ECDH-ES+A128GCM', kid: 'bob' }],\n  [charliePubKey, { alg: 'ECIES-BIE1', kid: 'charlie' }]\n])\n\nconst bobEnv = Envelope.fromBuffer(env2.toBuffer())\nawait bobEnv.decryptAt(1, bobKey)\nconsole.log(bobEnv.payload)\n// =\u003e \"Hello world!\"\n\nconst charlieEnv = Envelope.fromBuffer(env2.toBuffer())\nawait charlieEnv.decryptAt(2, charlieKey)\nconsole.log(charlieEnv.payload)\n// =\u003e \"Hello world!\"\n```\n\n### Working with `bsv` keys\n\nThe `util` module provides a number of helper functions to convert to and from `bsv` keys.\n\n```javascript\nimport { KeyPair } from 'bsv'\nimport { Key, util } from 'univrse'\n\n// Convert bsv KeyPair to Univrse keys\nconst keyPair = KeyPair.fromRandom()\nconst keyFromPrivKey = util.fromBsvPrivKey(keyPair.privKey)\nconst keyFromPubKey = util.fromBsvPubKey(keyPair.pubKey)\n\n// Convert Univrse key to bsv keys\nconst key = await Key.generate('ec', 'secp256k1')\nconst privKey = util.toBsvPrivKey(key)\nconst pubKey = util.toBsvPubKey(key)\n```\n\n## License\n\nUnivrse is open source and released under the [Apache-2 License](https://github.com/libitx/univrse-js/blob/master/LICENSE).\n\nCopyright (c) 2021 Chronos Labs Ltd.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibitx%2Funivrse-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibitx%2Funivrse-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibitx%2Funivrse-js/lists"}