Files
self/circuits/utils/computeEContent.ts
0xturboblitz 431fba1b69 add circuits
2023-10-03 12:39:36 +02:00

22 lines
657 B
TypeScript

import {sha256} from 'js-sha256';
// hash logic here because the one in utils.ts only works with node
export function hash(bytesArray: number[]) {
let unsignedBytesArray = bytesArray.map(toUnsignedByte);
let hash = sha256(unsignedBytesArray);
return hexToSignedBytes(hash);
}
export function hexToSignedBytes(hexString: string): number[] {
let bytes = [];
for (let i = 0; i < hexString.length - 1; i += 2) {
let byte = parseInt(hexString.substr(i, 2), 16);
bytes.push(byte >= 128 ? byte - 256 : byte);
}
return bytes;
}
export function toUnsignedByte(signedByte: number) {
return signedByte < 0 ? signedByte + 256 : signedByte;
}