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

27 lines
769 B
TypeScript
Raw Normal View History

2022-09-05 23:14:43 +03:00
import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160";
import { getBytes, hexlify } from "../utils/index.js";
2022-09-05 23:14:43 +03:00
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;
export function ripemd160(_data: BytesLike): string {
const data = getBytes(_data, "data");
2022-09-05 23:14:43 +03:00
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);