litesign

0.2.1 • Public • Published

sign

sign object with regular algorithm

APIS

/**
 * calculate the obj sign
 * @param  {String} algorithm can be `sha1`, `sha256`, default sha1
 * @param  {String} secret    secret string
 * @param  {Object} obj   data for calculate hash
 * @param  {Number} timestamp
 * @return {String} result hash string
 */
exports.sign(algorithm, secret, obj, timestamp);

/**
 * check sign
 * @param  {String} algorithm
 * @param  {String} secret
 * @param  {Object} obj
 * @param  {String} hashStr  the result sign str
 * @return {Boolean}
 */
exports.checkSign(algorithm, secret, obj, hashStr)

object stringify method

this method stringify object like this:

// input
{a: 1, b: {c: 1, d: 2}}
// stringify
a=1&b={c=1&d=2}

// input
{a: 1, b: {d: [2,3,4], c: 1}}
// stringify
a=1&b={c=1&d={2,3,4}}

because js object is not guarantee object property order, so sort porperty asc is necessary to make sure the stringify is stable

Dependencies (1)

Dev Dependencies (3)

Package Sidebar

Install

npm i litesign

Weekly Downloads

0

Version

0.2.1

License

none

Last publish

Collaborators

  • fish