All files / ethers.js/src.ts/crypto ripemd160.ts

100% Statements 43/43
100% Branches 6/6
100% Functions 4/4
100% Lines 43/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29978x 29978x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29979x 29979x 29979x 1x 1x 1x 3x 2x 2x 1x  
import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160";
 
import { getBytes,  hexlify } from "../utils/index.js";
 
import type { BytesLike } from "../utils/index.js";
 
 
let locked = false;
 
const _ripemd160 = function(data: Uint8Array): Uint8Array {
    return noble_ripemd160(data);
}
 
let __ripemd160: (data: Uint8Array) => BytesLike = _ripemd160;
 
/**
 *  Compute the cryptographic RIPEMD-160 hash of %%data%%.
 *
 *  @_docloc: api/crypto:Hash Functions
 *  @returns DataHexstring
 *
 *  @example:
 *    ripemd160("0x")
 *    //_result:
 *
 *    ripemd160("0x1337")
 *    //_result:
 *
 *    ripemd160(new Uint8Array([ 0x13, 0x37 ]))
 *    //_result:
 *
 */
export function ripemd160(_data: BytesLike): string {
    const data = getBytes(_data, "data");
    return hexlify(__ripemd160(data));
}
ripemd160._ = _ripemd160;
ripemd160.lock = function(): void { locked = true; }
ripemd160.register = function(func: (data: Uint8Array) => BytesLike) {
    if (locked) { throw new TypeError("ripemd160 is locked"); }
    __ripemd160 = func;
}
Object.freeze(ripemd160);