2022-09-05 16:14:43 -04:00
|
|
|
import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160";
|
|
|
|
|
2022-09-08 23:21:08 -04:00
|
|
|
import { getBytes, hexlify } from "../utils/index.js";
|
2022-09-05 16:14:43 -04: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;
|
|
|
|
|
2022-11-27 21:53:06 -05:00
|
|
|
/**
|
|
|
|
* Compute the cryptographic RIPEMD-160 hash of %%data%%.
|
|
|
|
*
|
2022-12-02 21:23:13 -05:00
|
|
|
* @_docloc: api/crypto:Hash Functions
|
2022-11-27 21:53:06 -05:00
|
|
|
* @returns DataHexstring
|
2022-12-09 18:21:45 -05:00
|
|
|
*
|
|
|
|
* @example:
|
|
|
|
* ripemd160("0x")
|
|
|
|
* //_result:
|
|
|
|
*
|
|
|
|
* ripemd160("0x1337")
|
|
|
|
* //_result:
|
|
|
|
*
|
|
|
|
* ripemd160(new Uint8Array([ 0x13, 0x37 ]))
|
|
|
|
* //_result:
|
|
|
|
*
|
2022-11-27 21:53:06 -05:00
|
|
|
*/
|
2022-09-05 16:14:43 -04:00
|
|
|
export function ripemd160(_data: BytesLike): string {
|
2022-09-08 23:21:08 -04:00
|
|
|
const data = getBytes(_data, "data");
|
2022-09-05 16:14:43 -04: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);
|