UNPKG

@bitgo/bls

Version:

Implementation of bls signature verification for ethereum 2.0

48 lines (36 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupBls = setupBls; exports.init = init; exports.destroy = destroy; exports.getContext = getContext; var _eth2BlsWasm = _interopRequireDefault(require("@bitgo/eth2-bls-wasm")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-disable require-atomic-updates */ let blsGlobal = null; let blsGlobalPromise = null; async function setupBls() { if (!blsGlobal) { await _eth2BlsWasm.default.init(); blsGlobal = _eth2BlsWasm.default; } return blsGlobal; } // Cache a promise for Bls instead of Bls to make sure it is initialized only once async function init() { if (!blsGlobalPromise) { blsGlobalPromise = setupBls(); } return blsGlobalPromise; } function destroy() { blsGlobal = null; blsGlobalPromise = null; } function getContext() { if (!blsGlobal) { throw new Error("BLS not initialized"); } return blsGlobal; }