// Creates a BLAKE2b hashing context
// Requires an output length between 1 and 64 bytes
// Takes an optional Uint8Array key
-function Blake2b (outlen, key, salt, personal) {
+function Blake2b (outlen: number, key?: Uint8Array, salt?: Uint8Array, personal?: Uint8Array) {
// zero out parameter_block before usage
parameter_block.fill(0)
// state, 'param block'
}
}
-Blake2b.prototype.update = function (input) {
+Blake2b.prototype.update = function (input: Uint8Array) {
if (!(input instanceof Uint8Array))
throw new TypeError('input must be Uint8Array or Buffer')
blake2bUpdate(this, input)
return this
}
-Blake2b.prototype.digest = function (out) {
+Blake2b.prototype.digest = function (out?: 'binary' | 'hex' | Uint8Array) {
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out
if (!(buf instanceof Uint8Array))
throw new TypeError('out must be "binary", "hex", Uint8Array, or Buffer')
// Updates a BLAKE2b streaming hash
// Requires hash context and Uint8Array (byte array)
-function blake2bUpdate (ctx, input) {
+function blake2bUpdate (ctx, input: Uint8Array) {
for (var i = 0; i < input.length; i++) {
if (ctx.c === 128) { // buffer full ?
ctx.t += ctx.c // add counters
// Completes a BLAKE2b streaming hash
// Returns a Uint8Array containing the message digest
-function blake2bFinal (ctx, out) {
+function blake2bFinal (ctx, out: Uint8Array) {
ctx.t += ctx.c // mark last block offset
while (ctx.c < 128) { // fill up with zeros
return out
}
-function hexSlice (buf) {
+function hexSlice (buf: Uint8Array) {
var str = ''
for (var i = 0; i < buf.length; i++) str += toHex(buf[i])
return str
var Proto = Blake2b
-export default function createHash (outlen, key?, salt?, personal?, noAssert?) {
+export default function createHash (outlen: number, key?: Uint8Array, salt?: Uint8Array, personal?: Uint8Array, noAssert?: boolean) {
if (noAssert !== true) {
if (outlen < BYTES_MIN)
throw new RangeError('outlen must be at least ' + BYTES_MIN + ', was given ' + outlen)