signed-token
v2.0.0
Published
signed crypto token
Downloads
10
Readme
signed-token
signed HMAC crypto token
Generation and validation of signed HMAC token with variable lengths. The token is url-safe Base64 encoded and can be used in urls as well as forms.
TOC
Example
Asynchronous using Promises
const signedToken = require('signed-token')
const stfn = signedToken('my secret')
stfn.create()
.then((token) => stfn.verify(token))
.then((res) => console.log(res)) // res === tokenSynchronous
const signedToken = require('signed-token')
const stfn = signedToken('my secret')
const token = stfn.createSync()
const res = stfn.verifySync(token)
res === token
//> trueAPI
signedToken(secret, [opts])
creates a signedToken instance, wrapping secret
Parameters
| parameter | type | description |
| ---------------------- | ------ | ---------------------------------------------------- |
| secret | string | common secret |
| [opts] | object | optional: |
| [opts.digest=sha265] | string | optional: hmac digest |
| [opts.commonlen=24] | number | optional: length of random bytes for common length |
| [opts.tokenlen=64] | number | optional: length of token |
Returns object, {create, verify, createSync, verifySync, hmac}
create
creates a signed token
Returns Promise, {string} signed token url safe base64 encoded
createSync
sync generation of a signed token
Returns string signed token url safe base64 encoded
verify
verify a signed token using secret
Returns Promise, {string|undefined} - token if it was correctly signed
verifySync
sync validation of signed token
Returns string,undefined,
token if it was correctly signed
Installation
Requires nodejs >= v12.0.0
$ npm install --save signed-tokenTests
$ npm testLICENSE
UNLICENSE https://unlicense.org
