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IAAI,kBAE5B,QACF","file":"/npm/bls-lib@0.3.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/bls-lib@0.3.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","let initCb = require('nop')\nconst Buffer = require('safe-buffer').Buffer\nconst mod = require('./build/bls_lib.js')\nconst crypto = require('crypto')\ncrypto.getRandomValues = crypto.randomFillSync\n\nlet init = false\n\nexports.mod = mod\n\n/**\n * Takes a callback that is called once the module is setup\n * @params {Function} cb - the callback to be called once the module is initialized\n */\nexports.onModuleInit = function (cb) {\n  if (init) {\n    cb()\n  } else {\n    init = true\n    initCb = cb\n  }\n}\n\n/**\n * The FP254BNB curve\n */\nexports.MCLBN_CURVE_FP254BNB = 0\n\n/**\n * The FP382_1 curve\n */\nexports.MCLBN_CURVE_FP382_1 = 1\n\n/**\n * The FP382_2 curve\n */\nexports.MCLBN_CURVE_FP382_2 = 2\n\n/**\n * The BLS12-381 curve\n */\nexports.MCL_BLS12_381 = 5\n\nconst MCLBN_FP_UNIT_SIZE = 6\nconst FR_SIZE = MCLBN_FP_UNIT_SIZE * 8\nconst ID_SIZE = FR_SIZE\nconst G1_SIZE = FR_SIZE * 3\nconst G2_SIZE = FR_SIZE * 3 * 2\n\nmod.onRuntimeInitialized = function () {\n  /**\n   * Initializes the library to use a given curve\n   * @param {number} curve - the curves that can be used are MCLBN_CURVE_FP254BNB, MCLBN_CURVE_FP382_1 or MCLBN_CURVE_FP382_2\n   */\n  exports.init = function (curve = exports.MCLBN_CURVE_FP254BNB) {\n    return mod._blsInit(curve, MCLBN_FP_UNIT_SIZE)\n  }\n\n  /**\n   * Allocates a secret key\n   * @returns {number} the pointer to the key\n   */\n  exports.secretKey = function () {\n    return mod._malloc(FR_SIZE)\n  }\n\n  /**\n   * Allocates a secret key\n   * @returns {number} the pointer to the key\n   */\n  exports.publicKey = function () {\n    return mod._malloc(G2_SIZE)\n  }\n\n  /**\n   * Allocates a signature\n   * @returns {number} the pointer to the signature\n   */\n  exports.signature = function () {\n    return mod._malloc(G1_SIZE)\n  }\n\n  /**\n   * Frees a pointer\n   */\n  exports.free = function (x) {\n    mod._free(x)\n  }\n\n  /**\n   * Frees an array of pointers\n   */\n  exports.freeArray = function (a) {\n    a.forEach(el => mod._free(el))\n  }\n\n  /**\n   * Creates an ID from an int to use with threshold groups\n   * @param {number} sk - a pointer to the secret key, secret key struct is used to hold the id\n   * @param {number} n - a int representing the ID. n cannot be zero.\n   */\n  exports.idSetInt = function (sk, n) {\n    if (n === 0) {\n      throw new Error('id cannot be zero')\n    }\n    mod._blsIdSetInt(sk, n)\n  }\n\n  /**\n   * Creates an ID from an int and returns a pointer to it\n   * @param {number} n - a int representing the ID. n cannot be zero.\n   * @return {number}\n   */\n  exports.idImportFromInt = function (n) {\n    const sk = exports.secretKey()\n    exports.idSetInt(sk, n)\n    return sk\n  }\n\n  /**\n   * Creates an ID from an int and returns a pointer to it\n   * @param {number} n - a int representing the ID. n cannot be zero.\n   * @return {number}\n   */\n  exports.idImport = function (n) {\n    if (Number.isInteger(n)) {\n      return exports.idImportFromInt(n)\n    } else {\n      const sk = exports.secretKey()\n      mod._blsHashToSecretKey(sk, n)\n      return sk\n    }\n  }\n\n  /**\n   * Signs a message\n   * @param {number} sig - a pointer to the a signature\n   * @param {number} sk - a pointer to the secret key\n   * @param {TypedArray|String} msg - the message to sign\n   */\n  exports.sign = wrapInput(mod._blsSign)\n\n  /**\n   * Verifies a signature\n   * @param {number} sig - a pointer to the a signature\n   * @param {number} pk - a pointer to the secret key\n   * @param {TypedArray|String} msg - the message that was signed\n   * @returns {Boolean}\n   */\n  exports.verify = returnBool(wrapInput(mod._blsVerify))\n\n  /**\n   * Given a pointer to a public key, this returns a 64 byte Int8Array containing the key\n   * @param {number} pk - a pointer to the secret key\n   * @return {TypedArray}\n   */\n  exports.publicKeyExport = wrapOutput(mod._blsPublicKeySerialize, 64)\n\n  /**\n   * Given a pointer to a secret key, this returns a 32 byte Int8Array containing the key\n   * @param {number} pk - a pointer to the secret key\n   * @return {TypedArray}\n   */\n  exports.secretKeyExport = wrapOutput(mod._blsSecretKeySerialize, 32)\n\n  /**\n   * Given a pointer to a signature, this returns a 32 byte Int8Array containing the signature\n   * @param {number} pk - a pointer to the secret key\n   * @return {TypedArray}\n   */\n  exports.signatureExport = wrapOutput(mod._blsSignatureSerialize, 32)\n\n  /**\n   * Generates a secret key given a seed phrase\n   * @param {number} sk - a pointer to a secret key\n   * @param {String|TypedArray} seed - the seed phrase\n   */\n  exports.hashToSecretKey = wrapInput(mod._blsHashToSecretKey)\n\n  /**\n   * Writes a secretKey to memory\n   * @param {number} sk - a pointer to a secret key\n   * @param {TypedArray} array - the secret key as a 32 byte TypedArray\n   */\n  exports.secretKeyDeserialize = wrapDeserialize(mod._blsSecretKeyDeserialize)\n\n  /**\n   * Writes a secretKey to memory and returns a pointer to it\n   * @param {number} sk - a pointer to a secret key\n   * @param {TypedArray} array - the secret key as a 32 byte TypedArray\n   * @return {Number}\n   */\n  exports.secretKeyImport = function (buf) {\n    const sk = exports.secretKey()\n    exports.secretKeyDeserialize(sk, buf)\n    return sk\n  }\n\n  /**\n   * Writes a publicKey to memory\n   * @param {number} sk - a pointer to a public key\n   * @param {TypedArray} array - the secret key as a 64 byte TypedArray\n   */\n  exports.publicKeyDeserialize = wrapDeserialize(mod._blsPublicKeyDeserialize)\n\n  /**\n   * Writes a publicKey to memory and returns a pointer to it\n   * @param {TypedArray} array - the secret key as a 64 byte TypedArray\n   * @return {Number}\n   */\n  exports.publicKeyImport = function (buf) {\n    const pk = exports.publicKey()\n    exports.publicKeyDeserialize(pk, buf)\n    return pk\n  }\n\n  /**\n   * Writes a signature to memory\n   * @param {number} sig - a pointer to a signature\n   * @param {TypedArray} array - the signature as a 32 byte TypedArray\n   */\n  exports.signatureDeserialize = wrapDeserialize(mod._blsSignatureDeserialize)\n\n  /**\n   * Writes a signature to memory and returns a pointer to it\n   * @param {TypedArray} array - the signature as a 32 byte TypedArray\n   * @return {Number}\n   */\n  exports.signatureImport = function (buf) {\n    const sig = exports.signature()\n    exports.signatureDeserialize(sig, buf)\n    return sig\n  }\n\n  /**\n   * Initializes a secret key by a Cryptographically Secure Pseudo Random Number Generator\n   * @param {TypedArray} array - the secret key as a TypedArray\n   */\n  exports.secretKeySetByCSPRNG = mod._blsSecretKeySetByCSPRNG\n\n  /**\n   * Creates a public key from the secret key\n   * @param {TypedArray} array - the public key as a TypedArray\n   * @param {TypedArray} array - the secret key as a TypedArray\n   */\n  exports.getPublicKey = mod._blsGetPublicKey\n\n  /**\n   * Recovers a secret key for a group given the groups secret keys shares and the groups ids\n   * @param {number} sk - a pointer to a secret key that will be generated\n   * @param {Array<number>} sksArray - an array of pointers to the groups secret key shares. The length of the array should be the threshold number for the group\n   * @param {Array<numbers>} idArrah - an array of pointers to ids in the groups. The length of the array should be the threshold number for the group\n   */\n  exports.secretKeyRecover = wrapRecover(mod._blsSecretKeyRecover, FR_SIZE, ID_SIZE)\n\n  /**\n   * Recovers a public key for a group given the groups public keys shares and the groups ids\n   * @param {number} pk - a pointer to a public key that will be generated\n   * @param {Array<number>} pksArray - an array of pointers to the groups public key shares. The length of the array should be the threshold number for the group\n   * @param {Array<numbers>} idArrah - an array of pointers to ids in the groups. The length of the array should be the threshold number for the group\n   */\n  exports.publicKeyRecover = wrapRecover(mod._blsPublicKeyRecover, G2_SIZE, ID_SIZE)\n\n  /**\n   * Recovers a signature for a group given the groups public keys shares and the groups ids\n   * @param {number} sig - a pointer to the signature that will be generated\n   * @param {Array<number>} sigArray - an array of pointers to signature shares. The length of the array should be the threshold number for the group\n   * @param {Array<numbers>} idArrah - an array of pointers to ids in the groups. The length of the array should be the threshold number for the group\n   */\n  exports.signatureRecover = wrapRecover(mod._blsSignatureRecover, G1_SIZE, ID_SIZE)\n\n  /**\n   * Creates a secret key share for a group member given the groups members id (which is the secret key) and array of master secret keys\n   * @param {number} skshare - a pointer to a secret key that will be generated\n   * @param {Array<number>} msk - an array of master secret keys. The number of keys is the threshold of the group.\n   * @param {number} id - the id of the member\n   */\n  exports.secretKeyShare = wrapKeyShare(mod._blsSecretKeyShare, FR_SIZE)\n\n  /**\n   * Creates a public key share for a group member given the groups members id (which is a the secret key) and array of master public keys\n   * @param {number} pkshare - a pointer to a secret key that will be generated\n   * @param {Array<number>} mpk - an array of master public keys. The number of keys is the threshold of the group.\n   * @param {number} id - the id of the member\n   */\n  exports.publicKeyShare = wrapKeyShare(mod._blsPublicKeyShare, G2_SIZE)\n\n  /**\n   * Takes two publicKeys and adds them together. pubkey1 = pubkey1 + pubkey2\n   * @param {number} pubkey1 - a pointer to a public key\n   * @param {number} pubkey2 - a pointer to a public key\n   */\n  exports.publicKeyAdd = mod._blsPublicKeyAdd\n\n  /**\n   * Takes two secretKeys and adds them together. seckey1 = seckey1 + seckey2\n   * @param {number} seckey1 - a pointer to a secret key\n   * @param {number} seckey2 - a pointer to a secret key\n   */\n  exports.secretKeyAdd = mod._blsSecretKeyAdd\n\n  /**\n   * Takes two publicKeys and tests their equality\n   * @param {number} pubkey1 - a pointer to a public key\n   * @param {number} pubkey2 - a pointer to a public key\n   * return {Boolean}\n   */\n  exports.publicKeyIsEqual = returnBool(mod._blsPublicKeyIsEqual)\n\n  /**\n   * Does Diffie–Hellman key exchange\n   * @param {number} sharedSecretKey - a pointer to a secretKey that will be populated with the shared secret\n   * @param {number} secretKey - a pointer to a secret key\n   * @param {number} pubkey - a pointer to a public key\n   */\n  exports.dhKeyExchange = mod._blsDHKeyExchange\n\n  initCb()\n}\n\nfunction returnBool (func) {\n  return function () {\n    return func.apply(null, arguments) === 1\n  }\n}\n\nfunction wrapInput (func) {\n  return function () {\n    const args = [...arguments]\n    let buf = args.pop()\n    if (typeof buf === 'string') {\n      buf = Buffer.from(buf)\n    }\n    const pos = mod._malloc(buf.length)\n\n    mod.HEAP8.set(buf, pos)\n    let r = func(...args, pos, buf.length)\n    mod._free(pos)\n    return r\n  }\n}\n\nfunction wrapDeserialize (func) {\n  func = wrapInput(func)\n  return function (p, buf) {\n    const r = func(p, buf)\n    if (r === 0) {\n      throw new Error('Deserialize err')\n    }\n  }\n}\n\nfunction wrapOutput (func, size) {\n  return function (x) {\n    const pos = mod._malloc(size)\n    const n = func(pos, size, x)\n    const a = mod.HEAP8.slice(pos, pos + n)\n    mod._free(pos)\n    return a\n  }\n}\n\nfunction memcpy (dst, src, size) {\n  for (let i = 0; i < size; i++) {\n    mod.HEAP8[dst + i] = mod.HEAP8[src + i]\n  }\n}\n\nfunction wrapKeyShare (func, dataSize) {\n  return function (x, vec, id) {\n    const k = vec.length\n    const p = mod._malloc(dataSize * k)\n    for (let i = 0; i < k; i++) {\n      memcpy(p + i * dataSize, vec[i], dataSize)\n    }\n    const r = func(x, p, k, id)\n    mod._free(p)\n    return r\n  }\n}\n\nfunction wrapRecover (func, dataSize, idDataSize) {\n  return function (x, vec, idVec) {\n    const n = vec.length\n    const p = mod._malloc(dataSize * n)\n    const q = mod._malloc(idDataSize * n)\n    for (let i = 0; i < n; i++) {\n      memcpy(p + i * dataSize, vec[i], dataSize)\n      memcpy(q + i * idDataSize, idVec[i], idDataSize)\n    }\n    const r = func(x, p, q, n)\n    mod._free(q)\n    mod._free(p)\n    return r\n  }\n}\n"]}