jwa
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
buffer-equal-constant-time | 1.0.1 | 3.05 kB | BSD-3-Clause | prod | |
ecdsa-sig-formatter | 1.0.11 | 6.94 kB | Apache-2.0 | prod | |
safe-buffer | 5.2.1 | 9.74 kB | MIT | prod |
JWA, short for JSON Web Algorithms, is an npm package that provides an implementation for all JSON Web Signature (JWS) algorithms. Its purpose is to support cryptographic processes tied to JSON Web Signatures, enabling the use of all the required, recommended, and optional cryptographic algorithms specified for JWS. These include HMAC using SHA-256, SHA-384, and SHA-512 hash algorithms; RSASSA using SHA-256, SHA-384, SHA-512 hash algorithms; RSASSA-PSS using SHA-256, SHA-384, SHA-512 hash algorithms; ECDSA using SHA-256, SHA-384, SHA-512 hash algorithms with their respective curves; and the case where no digital signature or MAC value is needed.
Using JWA in your JavaScript project is quite straightforward. Import the module using require('jwa'). From there, you can invoke the imported function with the appropriate algorithm as a string argument.
Here are two examples:
For HMAC:
const jwa = require('jwa');
const hmac = jwa('HS256');
const input = 'super important stuff';
const secret = 'shhhhhh';
const signature = hmac.sign(input, secret);
hmac.verify(input, signature, secret) // returns true
hmac.verify(input, signature, 'trickery!') // returns false
For keys:
const fs = require('fs');
const jwa = require('jwa');
const privateKey = fs.readFileSync(__dirname + '/ecdsa-p521-private.pem');
const publicKey = fs.readFileSync(__dirname + '/ecdsa-p521-public.pem');
const ecdsa = jwa('ES512');
const input = 'very important stuff';
const signature = ecdsa.sign(input, privateKey);
ecdsa.verify(input, signature, publicKey) // returns true
The primary source of documentation for the JWA npm package can be found in its README file on the GitHub project page, node-jwa. This documentation provides an overview of the tool as well as how to use it, including various use-case examples. As an open-source project, discussions and additional insights related to the package can likely also be found in the issues and pull requests of the GitHub repository.