17 lines
438 B
TypeScript
17 lines
438 B
TypeScript
export function bytesToUint256LittleEndian(bytes: Uint8Array): bigint {
|
|
let value: bigint = 0n;
|
|
|
|
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
value = (value << 8n) | BigInt(bytes[i]);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
export function uint256ToBytesLittleEndian(value: bigint): Uint8Array {
|
|
const bytes = new Uint8Array(4);
|
|
for (let i = 0; i < 4; i++) {
|
|
bytes[i] = Number((value >> (8n * BigInt(i))) & 0xffn);
|
|
}
|
|
return bytes;
|
|
}
|