npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sapient

v0.4.1

Published

Secure API ENgineering Toolkit

Downloads

5

Readme

Sapient.js

Travis CI npm version

Sapient secures your Node.js applications' server-to-server HTTP(S) traffic even in the wake of a TLS security breakdown (compromised certificate authority, etc.).

Sapient allows you to quickly and easily add application-layer cryptography to your API requests and responses.

Features at a Glance

  • Secure APIs:
    • Shared-key encryption
      • XChaCha20-Poly1305
    • Shared-key authentication
      • HMAC-SHA512-256
    • Anonymous public-key encryption
      • X25519 + BLAKE2b + XChaCha20-Poly1305
    • Public-key digital signatures
      • Ed25519
  • Digital signatures and authentication are backwards-compatible with unsigned JSON API clients and servers
    • The signaure and authentication tag will go into HTTP headers, rather than the request/response body.

Installing Sapient

npm install --save sapient

Optional:

Sapient uses Sodium-Plus internally. The default Sodium-Plus backend is cross-platform, but you can obtain greater performance by installing sodium-native too.

npm install --save sodium-native

This isn't strictly necessary, and sodium-native doesn't work in browsers, but if you're not targeting browsers, you can get a significant performance boost.

Basic Usage

See the request-promise documentation.

To use Sapient, you'll simply need to preprocess your options objects.

const rp = require('request-promise-native');
const {Sapient, SigningSecretKey} = require('sapient');

(async function () {
    let sk = await SigningSecretKey.generate();
    let request = {
        'method': 'POST',
        'uri': 'https://example.com',
        'form': {
            'important': 'some value that needs integrity',
            'test': 12345,
            'now': '2019-07-31T09:00:00+00:00'
        }
    };
    let response = await rp(await Sapient.signFormRequest(request, sk));
    console.log(response.statusCode);
    try {
        await Sapient.verifySignedResponse(response, sk.getPublicKey());
    } catch (e) {
        console.log(e.message);
    }
})();

Real World Example

This code will fetch data from the PHP Chronicle, verify the signature, return an object representing the JSON data that we authenticated.

const rp = require('request-promise-native');
const {Sapient, SigningPublicKey} = require('sapient');

(async function () {
    let publicKey = SigningPublicKey.fromString(
        'MoavD16iqe9-QVhIy-ewD4DMp0QRH-drKfwhfeDAUG0='
    );
    let request = {
        'method': 'GET',
        'uri': 'https://php-chronicle.pie-hosted.com/chronicle/lookup/WQG3tH3CiLHg_upN0ABhKiYWOGwH3n9l4pM04bXwG54=',
        'resolveWithFullResponse': true
    };
    let response = await rp(request);
    console.log(await Sapient.decodeSignedJsonResponse(response, publicKey));
})();

This should result in the following (except with differing timestamps):

{ version: '1.1.x',
  datetime: '2019-07-31T03:37:48-04:00',
  status: 'OK',
  results: 
   [ { contents: '{\n    "repository": "paragonie\\/certainty",\n    "sha256": "cb2eca3fbfa232c9e3874e3852d43b33589f27face98eef10242a853d83a437a",\n    "signature": "d368533011b7e9eb09d1cc3a78faef70adcd1188aaee7a47698e0783339275b9b506a982c98dee119969c599581275f76733e0c2f96380405faed1d8678a0302",\n    "time": "2019-05-15T16:26:42-04:00"\n}',
       prevhash: '1RrlFkZRs6Srb9W2cNh-cGAzk5bkd9sVEes6ZShJ-ZA=',
       currhash: '8wL2OsihjC2ihOfyjqs2YwvZbry11veuWucqjhz4f6Y=',
       summaryhash: 'WQG3tH3CiLHg_upN0ABhKiYWOGwH3n9l4pM04bXwG54=',
       created: '2019-05-15T16:26:45-04:00',
       publickey: 'mPLfrUEV_qnwlsNUhbO_ILBulKysO3rPYYWqWAYCA0I=',
       signature: 'W8OKNuUa8Bma0TpKWmYXxFdyvyuPaq87hvcD6VIwQgfxFowSPM5L_6q7p4FGcXDQtxP41qKHf-ANEfgxOqztAw==' } ] } 

Things that Use Sapient