Gathering detailed insights and metrics for jws
Gathering detailed insights and metrics for jws
Gathering detailed insights and metrics for jws
Gathering detailed insights and metrics for jws
npm install jws
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
711 Stars
111 Commits
107 Forks
24 Watching
4 Branches
19 Contributors
Updated on 21 Nov 2024
JavaScript (92.39%)
Makefile (7.61%)
Cumulative downloads
Total Downloads
Last day
-6.8%
4,633,128
Compared to previous day
Last week
1.5%
26,972,550
Compared to previous week
Last month
5.5%
114,230,569
Compared to previous month
Last year
26.2%
1,159,226,807
Compared to previous year
2
An implementation of JSON Web Signatures.
This was developed against draft-ietf-jose-json-web-signature-08
and
implements the entire spec except X.509 Certificate Chain
signing/verifying (patches welcome).
There are both synchronous (jws.sign
, jws.verify
) and streaming
(jws.createSign
, jws.createVerify
) APIs.
1$ npm install jws
Array of supported algorithms. The following algorithms are currently supported.
alg Parameter Value | Digital Signature or MAC Algorithm |
---|---|
HS256 | HMAC using SHA-256 hash algorithm |
HS384 | HMAC using SHA-384 hash algorithm |
HS512 | HMAC using SHA-512 hash algorithm |
RS256 | RSASSA using SHA-256 hash algorithm |
RS384 | RSASSA using SHA-384 hash algorithm |
RS512 | RSASSA using SHA-512 hash algorithm |
PS256 | RSASSA-PSS using SHA-256 hash algorithm |
PS384 | RSASSA-PSS using SHA-384 hash algorithm |
PS512 | RSASSA-PSS using SHA-512 hash algorithm |
ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm |
ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm |
ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm |
none | No digital signature or MAC value included |
(Synchronous) Return a JSON Web Signature for a header and a payload.
Options:
header
payload
secret
or privateKey
encoding
(Optional, defaults to 'utf8')header
must be an object with an alg
property. header.alg
must be
one a value found in jws.ALGORITHMS
. See above for a table of
supported algorithms.
If payload
is not a buffer or a string, it will be coerced into a string
using JSON.stringify
.
Example
1const signature = jws.sign({ 2 header: { alg: 'HS256' }, 3 payload: 'h. jon benjamin', 4 secret: 'has a van', 5});
(Synchronous) Returns true
or false
for whether a signature matches a
secret or key.
signature
is a JWS Signature. header.alg
must be a value found in jws.ALGORITHMS
.
See above for a table of supported algorithms. secretOrKey
is a string or
buffer containing either the secret for HMAC algorithms, or the PEM
encoded public key for RSA and ECDSA.
Note that the "alg"
value from the signature header is ignored.
(Synchronous) Returns the decoded header, decoded payload, and signature parts of the JWS Signature.
Returns an object with three properties, e.g.
1{ header: { alg: 'HS256' },
2 payload: 'h. jon benjamin',
3 signature: 'YOWPewyGHKu4Y_0M_vtlEnNlqmFOclqp4Hy6hVHfFT4'
4}
Returns a new SignStream object.
Options:
header
(required)payload
key
|| privateKey
|| secret
encoding
(Optional, defaults to 'utf8')Other than header
, all options expect a string or a buffer when the
value is known ahead of time, or a stream for convenience.
key
/privateKey
/secret
may also be an object when using an encrypted
private key, see the crypto documentation.
Example:
1
2// This...
3jws.createSign({
4 header: { alg: 'RS256' },
5 privateKey: privateKeyStream,
6 payload: payloadStream,
7}).on('done', function(signature) {
8 // ...
9});
10
11// is equivalent to this:
12const signer = jws.createSign({
13 header: { alg: 'RS256' },
14});
15privateKeyStream.pipe(signer.privateKey);
16payloadStream.pipe(signer.payload);
17signer.on('done', function(signature) {
18 // ...
19});
Returns a new VerifyStream object.
Options:
signature
algorithm
key
|| publicKey
|| secret
encoding
(Optional, defaults to 'utf8')All options expect a string or a buffer when the value is known ahead of time, or a stream for convenience.
Example:
1
2// This...
3jws.createVerify({
4 publicKey: pubKeyStream,
5 signature: sigStream,
6}).on('done', function(verified, obj) {
7 // ...
8});
9
10// is equivilant to this:
11const verifier = jws.createVerify();
12pubKeyStream.pipe(verifier.publicKey);
13sigStream.pipe(verifier.signature);
14verifier.on('done', function(verified, obj) {
15 // ...
16});
A Readable Stream
that emits a single data event (the calculated
signature) when done.
function (signature) { }
A Writable Stream
that expects the JWS payload. Do not use if you
passed a payload
option to the constructor.
Example:
1payloadStream.pipe(signer.payload);
A Writable Stream
. Expects the JWS secret for HMAC, or the privateKey
for ECDSA and RSA. Do not use if you passed a secret
or key
option
to the constructor.
Example:
1privateKeyStream.pipe(signer.privateKey);
This is a Readable Stream
that emits a single data event, the result
of whether or not that signature was valid.
function (valid, obj) { }
valid
is a boolean for whether or not the signature is valid.
A Writable Stream
that expects a JWS Signature. Do not use if you
passed a signature
option to the constructor.
A Writable Stream
that expects a public key or secret. Do not use if you
passed a key
or secret
option to the constructor.
It feels like there should be some convenience options/APIs for
defining the algorithm rather than having to define a header object
with { alg: 'ES512' }
or whatever every time.
X.509 support, ugh
MIT
Copyright (c) 2013-2015 Brian J. Brennan
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The latest stable version of the package.
Stable Version
1
8.7/10
Summary
Forgeable Public/Private Tokens in jws
Affected Versions
< 3.0.0
Patched Versions
3.0.0
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 5/23 approved changesets -- score normalized to 2
Reason
branch protection is not maximal on development and all release branches
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More