From 5dd7ce77330d42fb9dd331adc25bdf32ad98675e Mon Sep 17 00:00:00 2001 From: Ethan Celletti Date: Tue, 25 Jul 2023 14:39:11 -0700 Subject: [PATCH] Updating unity assets (#82) --- UnityAssets/Bls.jslib | 6 + UnityAssets/README | 11 + UnityAssets/WebGlBls.cs | 10 - UnityAssets/WebGlBlsCryptography.cs | 28 + UnityAssets/bls.js | 1190 +++++++++++++++++++++++++++ 5 files changed, 1235 insertions(+), 10 deletions(-) create mode 100644 UnityAssets/Bls.jslib create mode 100644 UnityAssets/README delete mode 100644 UnityAssets/WebGlBls.cs create mode 100644 UnityAssets/WebGlBlsCryptography.cs create mode 100644 UnityAssets/bls.js diff --git a/UnityAssets/Bls.jslib b/UnityAssets/Bls.jslib new file mode 100644 index 00000000..15fbb3e7 --- /dev/null +++ b/UnityAssets/Bls.jslib @@ -0,0 +1,6 @@ +var BLS = { + VerifySignature: function (publicKey, messageHash, signature) { + return blsVerify(publicKey, messageHash, signature); + }, +}; +mergeInto(LibraryManager.library, BLS); diff --git a/UnityAssets/README b/UnityAssets/README new file mode 100644 index 00000000..3a176233 --- /dev/null +++ b/UnityAssets/README @@ -0,0 +1,11 @@ +The following files should be added to the `Plugins/ICP.NET/` directory in Unity +- UnityHttp.cs - An alternative HttpClient that uses UnityWebRequest (needed for WebGL) + To use, create a `UnityHttpClient` instance and when creating an `HttpAgent` pass it as a parameter instead of the default +- WebGlBlsCrytography.cs - The WebGL version of the bls signature verify library, run in the browswer vs in C#/WASM + To use, create a `WebGlBlsCrytography` instance and when creating an `HttpAgent` pass it as a parameter instead of the default +- Bls.jslib - The bridge between the C# code and JS to allow C# to invoke the JS bls signature verification + +Other files: +- bls.js - Add to unity project and reference from an HTML file with a script tag. Loads in the JS bls signature verification that will be used with `WebGlBlsCrytography.cs`. + To generate the bls.js file, run `npx esbuild --bundle src/index.ts --outfile=dist/index.js` on github.com/dfinity/agent-js project in the directory `packages/bls-verify/` + Also modify the bls.js file to change `var blsVerify = ...` to `window.blsVerify = ...`. // TODO find a better way to export function \ No newline at end of file diff --git a/UnityAssets/WebGlBls.cs b/UnityAssets/WebGlBls.cs deleted file mode 100644 index 65a420a0..00000000 --- a/UnityAssets/WebGlBls.cs +++ /dev/null @@ -1,10 +0,0 @@ - -#if UNITY_WEBGL -public class WebGlBlsCryptography : IBlsCryptography -{ - public bool VerifySignature(byte[] publicKey, byte[] messageHash, byte[] signature) - { - return true; - } -} -#endif \ No newline at end of file diff --git a/UnityAssets/WebGlBlsCryptography.cs b/UnityAssets/WebGlBlsCryptography.cs new file mode 100644 index 00000000..c59b2b44 --- /dev/null +++ b/UnityAssets/WebGlBlsCryptography.cs @@ -0,0 +1,28 @@ +using Cysharp.Threading.Tasks; +using EdjCase.ICP.Agent.Agents.Http; +using EdjCase.ICP.BLS; +using System; +using System.Net; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.Networking; + +#if UNITY_WEBGL +public class WebGlBlsCryptography : IBlsCryptography +{ + public bool VerifySignature(byte[] publicKey, byte[] messageHash, byte[] signature) + { + return BrowserBlsLib.VerifySignature(publicKey, messageHash, signature); + } +} + +internal static class BrowserBlsLib +{ + [DllImport("__Internal")] + public static extern bool VerifySignature(byte[] publicKey, byte[] messageHash, byte[] signature); +} +#endif + diff --git a/UnityAssets/bls.js b/UnityAssets/bls.js new file mode 100644 index 00000000..a9f5ff6e --- /dev/null +++ b/UnityAssets/bls.js @@ -0,0 +1,1190 @@ +"use strict"; +(() => { + var __create = Object.create; + var __defProp = Object.defineProperty; + var __getOwnPropDesc = Object.getOwnPropertyDescriptor; + var __getOwnPropNames = Object.getOwnPropertyNames; + var __getProtoOf = Object.getPrototypeOf; + var __hasOwnProp = Object.prototype.hasOwnProperty; + var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] + }) : x)(function(x) { + if (typeof require !== "undefined") + return require.apply(this, arguments); + throw new Error('Dynamic require of "' + x + '" is not supported'); + }); + var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; + }; + var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; + }; + var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod + )); + + // src/vendor/amcl-js/src/ctx.js + var require_ctx = __commonJS({ + "src/vendor/amcl-js/src/ctx.js"(exports, module) { + "use strict"; + var CTX2 = function(input_parameter) { + "use strict"; + var ctx = this, CTXLIST, prepareModule; + CTXLIST = { + ED25519: { + "BITS": "256", + "FIELD": "25519", + "CURVE": "ED25519", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 2, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": -1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + MDC: { + "BITS": "256", + "FIELD": "MDC", + "CURVE": "MDC", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + X448: { + "BITS": "448", + "FIELD": "GOLDILOCKS", + "CURVE": "X448", + "@NB": 56, + "@BASE": 23, + "@NBT": 448, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 2, + "@QI": 0, + "@TW": 0, + "@CT": 2, + "@CA": 156326, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + SECP160R1: { + "BITS": "160", + "FIELD": "SECP160R1", + "CURVE": "SECP160R1", + "@NB": 20, + "@BASE": 24, + "@NBT": 160, + "@M8": 1, + "@RZ": 3, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + C25519: { + "BITS": "256", + "FIELD": "25519", + "CURVE": "C25519", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 2, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 2, + "@CA": 486662, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + C13318: { + "BITS": "256", + "FIELD": "25519", + "CURVE": "C13318", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 2, + "@RZ": 2, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + JUBJUB: { + "BITS": "256", + "FIELD": "JUBJUB", + "CURVE": "JUBJUB", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 32, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 5, + "@TW": 0, + "@CT": 1, + "@CA": -1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + SECP256K1: { + "BITS": "256", + "FIELD": "SECP256K1", + "CURVE": "SECP256K1", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": -11, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 3, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + NIST256: { + "BITS": "256", + "FIELD": "NIST256", + "CURVE": "NIST256", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": -10, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + SM2: { + "BITS": "256", + "FIELD": "SM2", + "CURVE": "SM2", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": -9, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + NIST384: { + "BITS": "384", + "FIELD": "NIST384", + "CURVE": "NIST384", + "@NB": 48, + "@BASE": 23, + "@NBT": 384, + "@M8": 1, + "@RZ": -12, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 48, + "@SH": 7, + "@AK": 24 + }, + BRAINPOOL: { + "BITS": "256", + "FIELD": "BRAINPOOL", + "CURVE": "BRAINPOOL", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": -3, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + ANSSI: { + "BITS": "256", + "FIELD": "ANSSI", + "CURVE": "ANSSI", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": -5, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + HIFIVE: { + "BITS": "336", + "FIELD": "HIFIVE", + "CURVE": "HIFIVE", + "@NB": 42, + "@BASE": 23, + "@NBT": 336, + "@M8": 2, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 48, + "@SH": 9, + "@AK": 24 + }, + GOLDILOCKS: { + "BITS": "448", + "FIELD": "GOLDILOCKS", + "CURVE": "GOLDILOCKS", + "@NB": 56, + "@BASE": 23, + "@NBT": 448, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 2, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + C41417: { + "BITS": "416", + "FIELD": "C41417", + "CURVE": "C41417", + "@NB": 52, + "@BASE": 22, + "@NBT": 414, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 4, + "@AK": 32 + }, + C1174: { + "BITS": "256", + "FIELD": "C1174", + "CURVE": "C1174", + "@NB": 32, + "@BASE": 24, + "@NBT": 251, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + C1665: { + "BITS": "168", + "FIELD": "C1665", + "CURVE": "C1665", + "@NB": 21, + "@BASE": 23, + "@NBT": 166, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + NIST521: { + "BITS": "528", + "FIELD": "NIST521", + "CURVE": "NIST521", + "@NB": 66, + "@BASE": 23, + "@NBT": 521, + "@M8": 1, + "@RZ": -4, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 8, + "@AK": 32 + }, + NUMS256W: { + "BITS": "256", + "FIELD": "256PM", + "CURVE": "NUMS256W", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": 7, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + NUMS256E: { + "BITS": "256", + "FIELD": "256PM", + "CURVE": "NUMS256E", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + NUMS384W: { + "BITS": "384", + "FIELD": "384PM", + "CURVE": "NUMS384W", + "@NB": 48, + "@BASE": 23, + "@NBT": 384, + "@M8": 1, + "@RZ": -4, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 48, + "@SH": 7, + "@AK": 24 + }, + NUMS384E: { + "BITS": "384", + "FIELD": "384PM", + "CURVE": "NUMS384E", + "@NB": 48, + "@BASE": 23, + "@NBT": 384, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 48, + "@SH": 7, + "@AK": 24 + }, + NUMS512W: { + "BITS": "512", + "FIELD": "512PM", + "CURVE": "NUMS512W", + "@NB": 64, + "@BASE": 23, + "@NBT": 512, + "@M8": 1, + "@RZ": -4, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": -3, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + NUMS512E: { + "BITS": "512", + "FIELD": "512PM", + "CURVE": "NUMS512E", + "@NB": 64, + "@BASE": 23, + "@NBT": 512, + "@M8": 1, + "@RZ": 0, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 1, + "@QI": 0, + "@TW": 0, + "@CT": 1, + "@CA": 1, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + TWEEDLEDUM: { + "BITS": "255", + "FIELD": "TWEEDLEDUM", + "CURVE": "TWEEDLEDUM", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 33, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 5, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + TWEEDLEDEE: { + "BITS": "255", + "FIELD": "TWEEDLEDEE", + "CURVE": "TWEEDLEDEE", + "@NB": 32, + "@BASE": 24, + "@NBT": 255, + "@M8": 34, + "@RZ": 1, + "@RZ2A": 0, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 5, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 0, + "@ST": 0, + "@SX": 0, + "@AB": 0, + "@HT": 32, + "@SH": 9, + "@AK": 16 + }, + FP256BN: { + "BITS": "256", + "FIELD": "FP256BN", + "CURVE": "FP256BN", + "@NB": 32, + "@BASE": 24, + "@NBT": 256, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 1, + "@ST": 1, + "@SX": 1, + "@AB": 66, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + FP512BN: { + "BITS": "512", + "FIELD": "FP512BN", + "CURVE": "FP512BN", + "@NB": 64, + "@BASE": 23, + "@NBT": 512, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 1, + "@ST": 1, + "@SX": 0, + "@AB": 130, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + BN254: { + "BITS": "256", + "FIELD": "BN254", + "CURVE": "BN254", + "@NB": 32, + "@BASE": 24, + "@NBT": 254, + "@M8": 1, + "@RZ": -1, + "@RZ2A": -1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 1, + "@ST": 0, + "@SX": 1, + "@AB": 66, + "@HT": 32, + "@SH": 10, + "@AK": 16 + }, + BN254CX: { + "BITS": "256", + "FIELD": "BN254CX", + "CURVE": "BN254CX", + "@NB": 32, + "@BASE": 24, + "@NBT": 254, + "@M8": 1, + "@RZ": -1, + "@RZ2A": -1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 1, + "@ST": 0, + "@SX": 1, + "@AB": 66, + "@HT": 32, + "@SH": 10, + "@AK": 16 + }, + BN462: { + "BITS": "464", + "FIELD": "BN462", + "CURVE": "BN462", + "@NB": 58, + "@BASE": 23, + "@NBT": 462, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 1, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 1, + "@ST": 0, + "@SX": 0, + "@AB": 118, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + BLS12383: { + "BITS": "384", + "FIELD": "BLS12383", + "CURVE": "BLS12383", + "@NB": 48, + "@BASE": 23, + "@NBT": 383, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 2, + "@ST": 1, + "@SX": 0, + "@AB": 65, + "@HT": 32, + "@SH": 8, + "@AK": 16 + }, + BLS24479: { + "BITS": "480", + "FIELD": "BLS24479", + "CURVE": "BLS24479", + "@NB": 60, + "@BASE": 23, + "@NBT": 479, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 4, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 3, + "@ST": 1, + "@SX": 0, + "@AB": 49, + "@HT": 48, + "@SH": 4, + "@AK": 24 + }, + BLS48556: { + "BITS": "560", + "FIELD": "BLS48556", + "CURVE": "BLS48556", + "@NB": 70, + "@BASE": 23, + "@NBT": 556, + "@M8": 1, + "@RZ": -1, + "@RZ2A": 2, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 4, + "@ST": 1, + "@SX": 0, + "@AB": 32, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + BLS48286: { + "BITS": "288", + "FIELD": "BLS48286", + "CURVE": "BLS48286", + "@NB": 36, + "@BASE": 23, + "@NBT": 286, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 1, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 4, + "@ST": 1, + "@SX": 0, + "@AB": 17, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + BLS48581: { + "BITS": "584", + "FIELD": "BLS48581", + "CURVE": "BLS48581", + "@NB": 73, + "@BASE": 23, + "@NBT": 581, + "@M8": 1, + "@RZ": 2, + "@RZ2A": 2, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 1, + "@CT": 0, + "@CA": 0, + "@PF": 4, + "@ST": 0, + "@SX": 1, + "@AB": 33, + "@HT": 64, + "@SH": 11, + "@AK": 32 + }, + BLS12381: { + "BITS": "381", + "FIELD": "BLS12381", + "CURVE": "BLS12381", + "@NB": 48, + "@BASE": 23, + "@NBT": 381, + "@M8": 1, + "@RZ": 11, + "@RZ2A": -2, + "@RZ2B": -1, + "@HC": 11, + "@HC2": 3, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 2, + "@ST": 1, + "@SX": 1, + "@AB": 65, + "@HT": 32, + "@SH": 10, + "@AK": 16 + }, + BLS12461: { + "BITS": "464", + "FIELD": "BLS12461", + "CURVE": "BLS12461", + "@NB": 58, + "@BASE": 23, + "@NBT": 461, + "@M8": 1, + "@RZ": 1, + "@RZ2A": 4, + "@RZ2B": 0, + "@HC": 0, + "@HC2": 0, + "@MT": 0, + "@QI": 0, + "@TW": 0, + "@CT": 0, + "@CA": 0, + "@PF": 2, + "@ST": 1, + "@SX": 1, + "@AB": 78, + "@HT": 32, + "@SH": 11, + "@AK": 16 + }, + RSA2048: { + "BITS": "1024", + "TFF": "2048", + "@NB": 128, + "@BASE": 22, + "@ML": 2 + }, + RSA3072: { + "BITS": "384", + "TFF": "3072", + "@NB": 48, + "@BASE": 23, + "@ML": 8 + }, + RSA4096: { + "BITS": "512", + "TFF": "4096", + "@NB": 64, + "@BASE": 23, + "@ML": 8 + } + }; + prepareModule = function(moduleName, fileName, propertyName) { + if (!propertyName) { + propertyName = moduleName; + } + if (typeof __require !== "undefined") { + if (!fileName) { + fileName = moduleName.toLowerCase(); + } + ctx[propertyName] = __require("./" + fileName)[moduleName](ctx); + } else { + ctx[propertyName] = window[moduleName](ctx); + } + }; + prepareModule("AES"); + prepareModule("GCM"); + prepareModule("UInt64"); + prepareModule("HMAC"); + prepareModule("HASH256"); + prepareModule("HASH384"); + prepareModule("HASH512"); + prepareModule("SHA3"); + prepareModule("RAND"); + prepareModule("SHARE"); + prepareModule("NHS"); + if (typeof input_parameter === "undefined") { + return; + } + ctx.config = CTXLIST[input_parameter]; + prepareModule("BIG"); + prepareModule("DBIG", "big"); + if (typeof ctx.config["TFF"] !== "undefined") { + prepareModule("FF"); + prepareModule("RSA"); + prepareModule("rsa_public_key", "rsa"); + prepareModule("rsa_private_key", "rsa"); + return; + } + if (typeof ctx.config["CURVE"] !== "undefined") { + prepareModule("ROM_CURVE_" + ctx.config["CURVE"], "rom_curve", "ROM_CURVE"); + prepareModule("ROM_FIELD_" + ctx.config["FIELD"], "rom_field", "ROM_FIELD"); + prepareModule("FP"); + prepareModule("ECP"); + prepareModule("ECDH"); + prepareModule("HPKE"); + if (ctx.config["@PF"] == 1 || ctx.config["@PF"] == 2) { + prepareModule("FP2"); + prepareModule("FP4"); + prepareModule("FP12"); + prepareModule("ECP2"); + prepareModule("PAIR"); + prepareModule("MPIN"); + prepareModule("BLS"); + } + if (ctx.config["@PF"] == 3) { + prepareModule("FP2"); + prepareModule("FP4"); + prepareModule("FP8"); + prepareModule("FP24"); + prepareModule("ECP4"); + prepareModule("PAIR4"); + prepareModule("MPIN192"); + prepareModule("BLS192"); + } + if (ctx.config["@PF"] == 4) { + prepareModule("FP2"); + prepareModule("FP4"); + prepareModule("FP8"); + prepareModule("FP16"); + prepareModule("FP48"); + prepareModule("ECP8"); + prepareModule("PAIR8"); + prepareModule("MPIN256"); + prepareModule("BLS256"); + } + return; + } + }; + if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = CTX2; + } + } + }); + + // src/vendor/amcl-js/index.js + var require_amcl_js = __commonJS({ + "src/vendor/amcl-js/index.js"(exports, module) { + module.exports.CTX = require_ctx(); + } + }); + + // src/index.ts + var import_amcl_js = __toESM(require_amcl_js(), 1); + + // src/utils.ts + function toHex(buffer) { + return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join(""); + } + var hexRe = new RegExp(/^([0-9A-F]{2})*$/i); + + // src/index.ts + window.blsVerify = async (primaryKey, signature, message) => { + const pk = typeof primaryKey === "string" ? primaryKey : toHex(primaryKey); + const sig = typeof signature === "string" ? signature : toHex(signature); + const msg = typeof message === "string" ? message : toHex(message); + const ctx = new import_amcl_js.CTX("BLS12381"); + if (ctx.BLS.init() !== 0) { + throw new Error("Cannot initialize BLS"); + } + return ctx.BLS.core_verify( + ctx.BLS.stringtobytes(sig), + ctx.BLS.stringtobytes(msg), + ctx.BLS.stringtobytes(pk) + ) == 0; + }; +})();