From: Chris Duncan Date: Tue, 26 Nov 2024 21:52:29 +0000 (-0800) Subject: Add typings to blake2b functions. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=0f17ee41f885979df5e8253d0d2d31312199da71;p=libnemo.git Add typings to blake2b functions. --- diff --git a/src/lib/blake2b.ts b/src/lib/blake2b.ts index cc7a2f5..41237d6 100644 --- a/src/lib/blake2b.ts +++ b/src/lib/blake2b.ts @@ -196,7 +196,7 @@ var parameter_block = new Uint8Array([ // 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' @@ -228,14 +228,14 @@ function Blake2b (outlen, key, salt, personal) { } } -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') @@ -250,7 +250,7 @@ Blake2b.prototype.final = Blake2b.prototype.digest // 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 @@ -263,7 +263,7 @@ function blake2bUpdate (ctx, input) { // 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 @@ -277,7 +277,7 @@ function blake2bFinal (ctx, out) { 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 @@ -290,7 +290,7 @@ function toHex (n) { 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)