2021-07-05 15:48:57 +10:00
|
|
|
export function hexToBuf(str: string): Buffer {
|
2021-07-09 15:12:52 +10:00
|
|
|
return Buffer.from(str.replace(/^0x/i, ''), 'hex');
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 15:57:47 +10:00
|
|
|
export function bufToHex(buf: Uint8Array | Buffer | ArrayBuffer): string {
|
2021-07-09 15:12:52 +10:00
|
|
|
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;
|
2021-07-05 15:48:57 +10:00
|
|
|
}
|