signed-objectid

1.0.1 • Public • Published

signed-objectid

Circle CI

Generate URL-safe signed codes based on 24-character hex string (like Mongo ObjectID)

  • Requires Node 4+ (ES2015)

Usage

  • The secret used to sign keys can be specified as a string in the environment variable SIGNED_CODE_SECRET
  • In the absence of SIGNED_CODE_SECRET, a fallback secret can be provided to the module function
  • Only 24-character hex strings are supported. Anything else will throw an Error
  • Any invalid or unverifiable input provided to unsign will return a null
const signedObjectId = require('signed-objectid')('DevTestSecret')
console.log(signedObjectId.sign('507f1f77bcf86cd799439011'))

// -> $w9@jeWfZ8hayp94dM@euVr351i1KQMHxt6mLTEfFRiXRA5QZeNb4z7df8HU

console.log(signedObjectId.unsign('$w9@jeWfZ8hayp94dM@euVr351i1KQMHxt6mLTEfFRiXRA5QZeNb4z7df8HU'))

// -> 507f1f77bcf86cd799439011

Dependents (0)

Package Sidebar

Install

npm i signed-objectid

Weekly Downloads

15

Version

1.0.1

License

MIT

Last publish

Collaborators

  • eoinsha