epir
Version:
EllipticPIR client library (Node.js / TypeScript bindings).
31 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("./util");
const types_1 = require("./types");
const wasm_libepir_1 = require("./wasm.libepir");
const worker = self;
const execute = async (helper, params) => {
const ciphers = [];
const cipher_ = helper.malloc(types_1.CIPHER_SIZE);
const key_ = helper.malloc(params.key);
const r_ = helper.malloc(types_1.SCALAR_SIZE);
for (let i = 0; i < params.count; i++) {
const encrypt = params.isFast ? 'ecelgamal_encrypt_fast' : 'ecelgamal_encrypt';
helper.set(params.random, i * types_1.SCALAR_SIZE, types_1.SCALAR_SIZE, r_);
helper.call(encrypt, cipher_, key_, params.msg & 0xffffffff, Math.floor(params.msg / 0x100000000), r_);
const cipher = helper.slice(cipher_, types_1.CIPHER_SIZE);
ciphers.push(cipher);
}
const ciphersConcat = util_1.arrayBufferConcat(ciphers);
worker.postMessage({
msg: params.msg,
ciphers: ciphersConcat,
}, [ciphersConcat]);
helper.free(cipher_);
helper.free(key_);
helper.free(r_);
};
worker.onmessage = async (ev) => {
execute(await wasm_libepir_1.createLibEpirHelper(), ev.data);
};
//# sourceMappingURL=wasm.SelectorFactory.worker.js.map