mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-07 16:23:09 +00:00
34 lines
736 B
TypeScript
34 lines
736 B
TypeScript
export function hexToBuf(hex: string | Buffer | Uint8Array): Buffer {
|
|
if (typeof hex === 'string') {
|
|
return Buffer.from(hex.replace(/^0x/i, ''), 'hex');
|
|
} else {
|
|
return Buffer.from(hex);
|
|
}
|
|
}
|
|
|
|
export function bufToHex(buf: Uint8Array | Buffer | ArrayBuffer): string {
|
|
const _buf = Buffer.from(buf);
|
|
return _buf.toString('hex');
|
|
}
|
|
|
|
export function equalByteArrays(
|
|
a: Uint8Array | Buffer | string,
|
|
b: Uint8Array | Buffer | string
|
|
): boolean {
|
|
let aBuf: Buffer;
|
|
let bBuf: Buffer;
|
|
if (typeof a === 'string') {
|
|
aBuf = hexToBuf(a);
|
|
} else {
|
|
aBuf = Buffer.from(a);
|
|
}
|
|
|
|
if (typeof b === 'string') {
|
|
bBuf = hexToBuf(b);
|
|
} else {
|
|
bBuf = Buffer.from(b);
|
|
}
|
|
|
|
return aBuf.compare(bBuf) === 0;
|
|
}
|