litesign

extends fs module, easy way to manipulate file system, support both sync functions and async functions

Usage no npm install needed!

<script type="module">
  import litesign from 'https://cdn.skypack.dev/litesign';
</script>

README

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