UNPKG

epir

Version:

EllipticPIR client library (Node.js / TypeScript bindings).

95 lines 3.56 kB
"use strict"; /** * Node.js (TypeScript) bindings for Native C EllipticPIR library interface. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEpir = exports.Epir = exports.SelectorFactory = exports.createDecryptionContext = void 0; const types_1 = require("./types"); const bindings_1 = __importDefault(require("bindings")); const epir_napi = bindings_1.default('epir'); const createDecryptionContext = async (param, mmax = types_1.DEFAULT_MMAX) => { const napi = await new Promise((resolve) => { if ((typeof param === 'undefined') || (typeof param === 'string') || (param instanceof ArrayBuffer)) { resolve(new epir_napi.DecryptionContext(param, mmax)); } else { // We ensure that all the JS callbacks are called. const napi = new epir_napi.DecryptionContext({ cb: (points_computed) => { param.cb(points_computed); if (points_computed == mmax) { resolve(napi); } }, interval: param.interval }, mmax); } }); return napi; }; exports.createDecryptionContext = createDecryptionContext; class SelectorFactory extends types_1.SelectorFactoryBase { constructor(isFast, key, /* istanbul ignore next */ capacities = types_1.DEFAULT_CAPACITIES) { super(isFast, key, capacities); this.isFast = isFast; this.key = key; this.capacities = capacities; this.napi = new epir_napi.SelectorFactory(isFast, key, capacities[0], capacities[1]); } fill() { return this.napi.fill(); } create(indexCounts, idx, refill = true) { const selector = this.napi.create(indexCounts, idx); if (refill) this.fill(); return selector; } } exports.SelectorFactory = SelectorFactory; class Epir { createPrivkey() { return epir_napi.create_privkey(); } createPubkey(privkey) { return epir_napi.pubkey_from_privkey(privkey); } encrypt(pubkey, msg, r) { return r ? epir_napi.encrypt(pubkey, msg, r) : epir_napi.encrypt(pubkey, msg); } encryptFast(privkey, msg, r) { return r ? epir_napi.encrypt_fast(privkey, msg, r) : epir_napi.encrypt_fast(privkey, msg); } ciphersCount(index_counts) { return epir_napi.ciphers_count(index_counts); } elementsCount(index_counts) { return epir_napi.elements_count(index_counts); } createSelector(pubkey, index_counts, idx, r) { return epir_napi.selector_create(pubkey, index_counts, idx, r); } createSelectorFast(privkey, index_counts, idx, r) { return epir_napi.selector_create_fast(privkey, index_counts, idx, r); } // For testing. computeReplySize(dimension, packing, elem_size) { return epir_napi.reply_size(dimension, packing, elem_size); } computeReplyRCount(dimension, packing, elem_size) { return epir_napi.reply_r_count(dimension, packing, elem_size); } computeReplyMock(pubkey, dimension, packing, elem, r) { return (r ? epir_napi.reply_mock(pubkey, dimension, packing, elem, r) : epir_napi.reply_mock(pubkey, dimension, packing, elem)); } } exports.Epir = Epir; const createEpir = async () => { return new Epir(); }; exports.createEpir = createEpir; //# sourceMappingURL=addon.js.map