crypto = require 'crypto'
sha1 = require 'sha1'
crypto = require 'crypto'
sha1 = require 'sha1'
Generates a hash chain (or just a hash).
value
is the data that will be hashed. (String||Buffer)n
is the number of times to compute the hash. (Number)alg
is the algorithm to use. (String)exports.chain = (value, n = 1, alg = 'sha512') ->
sum = (val) ->
if alg is 'sha1' then return new Buffer(sha1(val), 'hex')
hash = crypto.createHash alg
hash.end val
hash.read()
[n, value] = [n - 1, sum value] until n is 0
value