UNPKG

epir

Version:

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

68 lines 2.21 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createLibEpirHelper = exports.LibEpirHelper = void 0; const libepir_1 = __importDefault(require("../dist/libepir")); class LibEpirHelper { constructor(libepir) { this.libepir = libepir; this.free = this.libepir._free; this.addFunction = this.libepir.addFunction; this.removeFunction = this.libepir.removeFunction; } store(offset, n, len) { for (let i = 0; i < len; i++) { this.libepir.HEAPU8[offset + i] = n & 0xff; n >>= 8; } } store32(offset, n) { this.store(offset, n, 4); } store64(offset, n) { this.store(offset, n, 8); } set(buf, offset, len, buf_) { this.libepir.HEAPU8.set(new Uint8Array(buf, offset, len), buf_); } malloc(param) { if (typeof param == 'number') { return this.libepir._malloc(param); } else { const buf_ = this.libepir._malloc(param.byteLength); this.set(param, 0, param.byteLength, buf_); return buf_; } } call(func, ...params) { const bufs = []; params = params.map((param) => { if (typeof param === 'number' || param === null) { return param; } else { const buf_ = this.malloc(param); bufs.push(buf_); return buf_; } }); const ret = this.libepir[`_epir_${func}`].apply(null, params); bufs.forEach((buf_) => this.free(buf_)); return ret; } slice(begin, len) { return this.libepir.HEAPU8.slice(begin, begin + len).buffer; } subarray(begin, len) { return this.libepir.HEAPU8.subarray(begin, begin + len); } } exports.LibEpirHelper = LibEpirHelper; const createLibEpirHelper = async () => { return new LibEpirHelper(await libepir_1.default()); }; exports.createLibEpirHelper = createLibEpirHelper; //# sourceMappingURL=wasm.libepir.js.map