const bigInt = require("big-integer"); const assert = require("assert"); function writeUint32(h, val) { h.dataView.setUint32(h.offset, val, true); h.offset += 4; } function writeUint32ToPointer(h, p, val) { h.dataView.setUint32(p, val, true); } function alloc(h, n) { const o = h.offset; h.offset += n; return o; } function writeBigInt(h, bi) { for (let i=0; i<8; i++) { const v = bi.shiftRight(i*32).and(0xFFFFFFFF).toJSNumber(); writeUint32(h, v); } } function toMontgomeryQ(p) { const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); return p.times(bigInt.one.shiftLeft(256)).mod(q); } function toMontgomeryR(p) { const r = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); return p.times(bigInt.one.shiftLeft(256)).mod(r); } function writePoint(h, p) { writeBigInt(h, toMontgomeryQ(p[0])); writeBigInt(h, toMontgomeryQ(p[1])); } function writePoint2(h, p) { writeBigInt(h, toMontgomeryQ(p[0][0])); writeBigInt(h, toMontgomeryQ(p[0][1])); writeBigInt(h, toMontgomeryQ(p[1][0])); writeBigInt(h, toMontgomeryQ(p[1][1])); } function writeTransformedPolynomial(h, p) { const keys = Object.keys(p); writeUint32(h, keys.length); for (let i=0; i