Hash Chain implementation using Blake2b
var HashChain = require('hash-chain')
Persistence:
var chain = // ...
const fs = require('fs')
const fd = fs.open('filename')
fs.write(fd, chain.offset, 0, 4)
fs.write(fd, chain.chain)
fs.close(fd)
const fs = require('fs')
const data = fs.readFile('filename')
var chain = new HashChain(data.subarray(4), data.readUInt32LE(0))
Generate a new seed
, optionally into an existing Buffer
buf
.
Generate and instantiate a new HashChain
from seed
Buffer
with n
elements.seed
must be HashChain.SEEDBYTES
long. Optionally offset the
chain.
Generate and instantiate a new lazy HashChain
a list of anchor points,
with dist
elements between each anchor. Optionally offset the
chain. This will only keep a buffer of dist
points in memory, lazily
generating missing points as they're accessed.
Instantiate a new HashChain
from an existing chainBuf
at offset
.
Read the Buffer
used in the chain ch
Read the current integer offset
Total number of elements in the chain
Get the element as a Buffer
at offset
from the offset
given in
the constructor. Normally HashChains only move forward, but giving a negative
integer allows you to go back. This does not increment the internal counter.
Iterate over the elements in the chain using an Iterator
Generate anchor points with dist
elements between each anchor. This can be
used to optimise initialisation of an existing chain at the expense of more
disk space.
npm install hash-chain