{"id":20790367,"url":"https://github.com/paragonie/sapient-js","last_synced_at":"2026-06-07T09:32:25.516Z","repository":{"id":66085417,"uuid":"199587936","full_name":"paragonie/sapient-js","owner":"paragonie","description":null,"archived":false,"fork":false,"pushed_at":"2019-10-16T09:08:04.000Z","size":29,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-20T01:21:18.322Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paragonie.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-30T06:20:53.000Z","updated_at":"2019-10-16T09:08:06.000Z","dependencies_parsed_at":"2023-02-27T01:16:21.250Z","dependency_job_id":null,"html_url":"https://github.com/paragonie/sapient-js","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fsapient-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fsapient-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fsapient-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fsapient-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paragonie","download_url":"https://codeload.github.com/paragonie/sapient-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243136282,"owners_count":20241988,"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-17T15:34:23.118Z","updated_at":"2025-12-16T08:43:33.433Z","avatar_url":"https://github.com/paragonie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sapient.js\r\n\r\n[![Travis CI](https://travis-ci.org/paragonie/sapient-js.svg?branch=master)](https://travis-ci.org/paragonie/sapient-js)\r\n[![npm version](https://img.shields.io/npm/v/sapient.svg)](https://npm.im/sapient)\r\n\r\n**Sapient** secures your Node.js applications' server-to-server HTTP(S) traffic even in the wake of a\r\nTLS security breakdown (compromised certificate authority, etc.).\r\n\r\nSapient allows you to quickly and easily add application-layer cryptography to your API requests\r\nand responses.\r\n\r\n## Features at a Glance\r\n\r\n* Secure APIs:\r\n  * Shared-key encryption\r\n    * XChaCha20-Poly1305\r\n  * Shared-key authentication\r\n    * HMAC-SHA512-256\r\n  * Anonymous public-key encryption\r\n    * X25519 + BLAKE2b + XChaCha20-Poly1305\r\n  * Public-key digital signatures\r\n    * Ed25519\r\n* Digital signatures and authentication are backwards-compatible\r\n  with unsigned JSON API clients and servers\r\n  * The signaure and authentication tag will go into HTTP headers,\r\n    rather than the request/response body.\r\n\r\n# Installing Sapient\r\n\r\n```terminal\r\nnpm install --save sapient\r\n```\r\n\r\n**Optional:**\r\n\r\nSapient uses [Sodium-Plus](https://github.com/paragonie/sodium-plus) internally.\r\nThe default Sodium-Plus backend is cross-platform, but you can obtain greater\r\nperformance by installing `sodium-native` too.\r\n\r\n```terminal\r\nnpm install --save sodium-native\r\n```\r\n\r\nThis isn't strictly necessary, and sodium-native doesn't work in browsers, but\r\nif you're not targeting browsers, you can get a significant performance boost.\r\n\r\n## Basic Usage\r\n\r\nSee the [request-promise](https://www.npmjs.com/package/request-promise)\r\ndocumentation.\r\n\r\nTo use Sapient, you'll simply need to preprocess your `options` objects.\r\n\r\n```javascript\r\nconst rp = require('request-promise-native');\r\nconst {Sapient, SigningSecretKey} = require('sapient');\r\n\r\n(async function () {\r\n    let sk = await SigningSecretKey.generate();\r\n    let request = {\r\n        'method': 'POST',\r\n        'uri': 'https://example.com',\r\n        'form': {\r\n            'important': 'some value that needs integrity',\r\n            'test': 12345,\r\n            'now': '2019-07-31T09:00:00+00:00'\r\n        }\r\n    };\r\n    let response = await rp(await Sapient.signFormRequest(request, sk));\r\n    console.log(response.statusCode);\r\n    try {\r\n        await Sapient.verifySignedResponse(response, sk.getPublicKey());\r\n    } catch (e) {\r\n        console.log(e.message);\r\n    }\r\n})();\r\n```\r\n\r\n### Real World Example\r\n\r\nThis code will fetch data from [the PHP Chronicle](https://php-chronicle.pie-hosted.com),\r\nverify the signature, return an object representing the JSON data that we authenticated.\r\n\r\n```javascript\r\nconst rp = require('request-promise-native');\r\nconst {Sapient, SigningPublicKey} = require('sapient');\r\n\r\n(async function () {\r\n    let publicKey = SigningPublicKey.fromString(\r\n        'MoavD16iqe9-QVhIy-ewD4DMp0QRH-drKfwhfeDAUG0='\r\n    );\r\n    let request = {\r\n        'method': 'GET',\r\n        'uri': 'https://php-chronicle.pie-hosted.com/chronicle/lookup/WQG3tH3CiLHg_upN0ABhKiYWOGwH3n9l4pM04bXwG54=',\r\n        'resolveWithFullResponse': true\r\n    };\r\n    let response = await rp(request);\r\n    console.log(await Sapient.decodeSignedJsonResponse(response, publicKey));\r\n})();\r\n```\r\n\r\nThis should result in the following (except with differing timestamps):\r\n```\r\n{ version: '1.1.x',\r\n  datetime: '2019-07-31T03:37:48-04:00',\r\n  status: 'OK',\r\n  results: \r\n   [ { contents: '{\\n    \"repository\": \"paragonie\\\\/certainty\",\\n    \"sha256\": \"cb2eca3fbfa232c9e3874e3852d43b33589f27face98eef10242a853d83a437a\",\\n    \"signature\": \"d368533011b7e9eb09d1cc3a78faef70adcd1188aaee7a47698e0783339275b9b506a982c98dee119969c599581275f76733e0c2f96380405faed1d8678a0302\",\\n    \"time\": \"2019-05-15T16:26:42-04:00\"\\n}',\r\n       prevhash: '1RrlFkZRs6Srb9W2cNh-cGAzk5bkd9sVEes6ZShJ-ZA=',\r\n       currhash: '8wL2OsihjC2ihOfyjqs2YwvZbry11veuWucqjhz4f6Y=',\r\n       summaryhash: 'WQG3tH3CiLHg_upN0ABhKiYWOGwH3n9l4pM04bXwG54=',\r\n       created: '2019-05-15T16:26:45-04:00',\r\n       publickey: 'mPLfrUEV_qnwlsNUhbO_ILBulKysO3rPYYWqWAYCA0I=',\r\n       signature: 'W8OKNuUa8Bma0TpKWmYXxFdyvyuPaq87hvcD6VIwQgfxFowSPM5L_6q7p4FGcXDQtxP41qKHf-ANEfgxOqztAw==' } ] } \r\n```\r\n\r\n## Things that Use Sapient\r\n\r\n* [Certainty.js](https://github.com/paragonie/certainty-js)\r\n* [Chronicle](https://github.com/paragonie/chronicle)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fsapient-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparagonie%2Fsapient-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fsapient-js/lists"}