mirror of
https://github.com/zkitter/ffjavascript.git
synced 2026-01-10 07:28:07 -05:00
small fix dataView buffer
This commit is contained in:
@@ -89,7 +89,7 @@ export function beInt2Buff(n, len) {
|
||||
export function leBuff2int(buff) {
|
||||
let res = 0n;
|
||||
let i = 0;
|
||||
const buffV = new DataView(buff.buffer);
|
||||
const buffV = new DataView(buff.buffer, buff.byteOffset);
|
||||
while (i<buff.length) {
|
||||
if (i + 4 <= buff.length) {
|
||||
res += BigInt(buffV.getUint32(i, true)) << BigInt( i*8);
|
||||
|
||||
@@ -12,10 +12,18 @@ describe("Utils native", () => {
|
||||
it("Should convert integer to buffer little-endian", () => {
|
||||
const buff = utilsN.leInt2Buff(num, 32);
|
||||
const numFromBuff = utilsN.leBuff2int(buff);
|
||||
|
||||
|
||||
assert(ScalarN.eq(num, numFromBuff), true);
|
||||
});
|
||||
|
||||
it("Should convert integer to buffer little-endian 2", () => {
|
||||
const buff1 = Buffer.from("Rollup_DB_EthAddr");
|
||||
const buff2= Buffer.from("Rollup_DB_ChainID");
|
||||
const numFromBuff = utilsN.leBuff2int(buff1);
|
||||
const numFromBuff2 = utilsN.leBuff2int(buff2);
|
||||
|
||||
assert.equal(ScalarN.eq(numFromBuff, numFromBuff2), false)
|
||||
});
|
||||
it("Should convert integer to buffer big-endian", () => {
|
||||
const buff = utilsN.beInt2Buff(num, 32);
|
||||
const numFromBuff = utilsN.beBuff2int(buff);
|
||||
|
||||
Reference in New Issue
Block a user