epir
Version:
EllipticPIR client library (Node.js / TypeScript bindings).
41 lines • 1.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.ELEM_SIZE = exports.PACKING = exports.DIMENSION = void 0;
const crypto_1 = __importDefault(require("crypto"));
const types_1 = require("./types");
const util_1 = require("./util");
const addon_1 = require("./addon");
exports.DIMENSION = 3;
exports.PACKING = 3;
exports.ELEM_SIZE = 32;
const run = async () => {
const epir = await addon_1.createEpir();
const decCtx = await addon_1.createDecryptionContext(types_1.MG_DEFAULT_PATH);
const privkey = epir.createPrivkey();
const pubkey = epir.createPubkey(privkey);
const elem = new Uint8Array(crypto_1.default.randomBytes(exports.ELEM_SIZE));
const reply = await util_1.printMeasurement(() => {
return epir.computeReplyMock(pubkey, exports.DIMENSION, exports.PACKING, elem.buffer);
}, 'Compute mock:');
const decrypted = await util_1.printMeasurement(async () => {
return await decCtx.decryptReply(privkey, exports.DIMENSION, exports.PACKING, reply);
}, 'Decrypt reply:');
const decryptedView = new Uint8Array(decrypted);
for (let i = 0; i < exports.ELEM_SIZE; i++) {
/* istanbul ignore if */
if (elem[i] != decryptedView[i]) {
console.log('Wrong decryption result detected.');
return false;
}
}
return true;
};
exports.run = run;
/* istanbul ignore if */
if (!module.parent) {
exports.run();
}
//# sourceMappingURL=bench_reply.js.map