UNPKG

@neuraiproject/neurai-message

Version:
1,684 lines (1,667 loc) 368 kB
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; 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 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( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // node_modules/bech32/dist/index.js var require_dist = __commonJS({ "node_modules/bech32/dist/index.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bech32m = exports.bech32 = void 0; var ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; var ALPHABET_MAP = {}; for (let z = 0; z < ALPHABET.length; z++) { const x = ALPHABET.charAt(z); ALPHABET_MAP[x] = z; } function polymodStep(pre) { const b = pre >> 25; return (pre & 33554431) << 5 ^ -(b >> 0 & 1) & 996825010 ^ -(b >> 1 & 1) & 642813549 ^ -(b >> 2 & 1) & 513874426 ^ -(b >> 3 & 1) & 1027748829 ^ -(b >> 4 & 1) & 705979059; } function prefixChk(prefix) { let chk = 1; for (let i = 0; i < prefix.length; ++i) { const c = prefix.charCodeAt(i); if (c < 33 || c > 126) return "Invalid prefix (" + prefix + ")"; chk = polymodStep(chk) ^ c >> 5; } chk = polymodStep(chk); for (let i = 0; i < prefix.length; ++i) { const v = prefix.charCodeAt(i); chk = polymodStep(chk) ^ v & 31; } return chk; } function convert(data, inBits, outBits, pad) { let value = 0; let bits = 0; const maxV = (1 << outBits) - 1; const result = []; for (let i = 0; i < data.length; ++i) { value = value << inBits | data[i]; bits += inBits; while (bits >= outBits) { bits -= outBits; result.push(value >> bits & maxV); } } if (pad) { if (bits > 0) { result.push(value << outBits - bits & maxV); } } else { if (bits >= inBits) return "Excess padding"; if (value << outBits - bits & maxV) return "Non-zero padding"; } return result; } function toWords(bytes) { return convert(bytes, 8, 5, true); } function fromWordsUnsafe(words) { const res = convert(words, 5, 8, false); if (Array.isArray(res)) return res; } function fromWords(words) { const res = convert(words, 5, 8, false); if (Array.isArray(res)) return res; throw new Error(res); } function getLibraryFromEncoding(encoding) { let ENCODING_CONST; if (encoding === "bech32") { ENCODING_CONST = 1; } else { ENCODING_CONST = 734539939; } function encode(prefix, words, LIMIT) { LIMIT = LIMIT || 90; if (prefix.length + 7 + words.length > LIMIT) throw new TypeError("Exceeds length limit"); prefix = prefix.toLowerCase(); let chk = prefixChk(prefix); if (typeof chk === "string") throw new Error(chk); let result = prefix + "1"; for (let i = 0; i < words.length; ++i) { const x = words[i]; if (x >> 5 !== 0) throw new Error("Non 5-bit word"); chk = polymodStep(chk) ^ x; result += ALPHABET.charAt(x); } for (let i = 0; i < 6; ++i) { chk = polymodStep(chk); } chk ^= ENCODING_CONST; for (let i = 0; i < 6; ++i) { const v = chk >> (5 - i) * 5 & 31; result += ALPHABET.charAt(v); } return result; } function __decode(str, LIMIT) { LIMIT = LIMIT || 90; if (str.length < 8) return str + " too short"; if (str.length > LIMIT) return "Exceeds length limit"; const lowered = str.toLowerCase(); const uppered = str.toUpperCase(); if (str !== lowered && str !== uppered) return "Mixed-case string " + str; str = lowered; const split2 = str.lastIndexOf("1"); if (split2 === -1) return "No separator character for " + str; if (split2 === 0) return "Missing prefix for " + str; const prefix = str.slice(0, split2); const wordChars = str.slice(split2 + 1); if (wordChars.length < 6) return "Data too short"; let chk = prefixChk(prefix); if (typeof chk === "string") return chk; const words = []; for (let i = 0; i < wordChars.length; ++i) { const c = wordChars.charAt(i); const v = ALPHABET_MAP[c]; if (v === void 0) return "Unknown character " + c; chk = polymodStep(chk) ^ v; if (i + 6 >= wordChars.length) continue; words.push(v); } if (chk !== ENCODING_CONST) return "Invalid checksum for " + str; return { prefix, words }; } function decodeUnsafe(str, LIMIT) { const res = __decode(str, LIMIT); if (typeof res === "object") return res; } function decode(str, LIMIT) { const res = __decode(str, LIMIT); if (typeof res === "object") return res; throw new Error(res); } return { decodeUnsafe, decode, encode, toWords, fromWordsUnsafe, fromWords }; } exports.bech32 = getLibraryFromEncoding("bech32"); exports.bech32m = getLibraryFromEncoding("bech32m"); } }); // node_modules/create-hash/index.js var require_create_hash = __commonJS({ "node_modules/create-hash/index.js"(exports, module) { module.exports = __require("crypto").createHash; } }); // node_modules/safe-buffer/index.js var require_safe_buffer = __commonJS({ "node_modules/safe-buffer/index.js"(exports, module) { var buffer = __require("buffer"); var Buffer2 = buffer.Buffer; function copyProps(src, dst) { for (var key in src) { dst[key] = src[key]; } } if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) { module.exports = buffer; } else { copyProps(buffer, exports); exports.Buffer = SafeBuffer; } function SafeBuffer(arg, encodingOrOffset, length) { return Buffer2(arg, encodingOrOffset, length); } SafeBuffer.prototype = Object.create(Buffer2.prototype); copyProps(Buffer2, SafeBuffer); SafeBuffer.from = function(arg, encodingOrOffset, length) { if (typeof arg === "number") { throw new TypeError("Argument must not be a number"); } return Buffer2(arg, encodingOrOffset, length); }; SafeBuffer.alloc = function(size, fill, encoding) { if (typeof size !== "number") { throw new TypeError("Argument must be a number"); } var buf = Buffer2(size); if (fill !== void 0) { if (typeof encoding === "string") { buf.fill(fill, encoding); } else { buf.fill(fill); } } else { buf.fill(0); } return buf; }; SafeBuffer.allocUnsafe = function(size) { if (typeof size !== "number") { throw new TypeError("Argument must be a number"); } return Buffer2(size); }; SafeBuffer.allocUnsafeSlow = function(size) { if (typeof size !== "number") { throw new TypeError("Argument must be a number"); } return buffer.SlowBuffer(size); }; } }); // node_modules/base-x/src/index.js var require_src = __commonJS({ "node_modules/base-x/src/index.js"(exports, module) { "use strict"; var _Buffer = require_safe_buffer().Buffer; function base(ALPHABET) { if (ALPHABET.length >= 255) { throw new TypeError("Alphabet too long"); } var BASE_MAP = new Uint8Array(256); for (var j = 0; j < BASE_MAP.length; j++) { BASE_MAP[j] = 255; } for (var i = 0; i < ALPHABET.length; i++) { var x = ALPHABET.charAt(i); var xc = x.charCodeAt(0); if (BASE_MAP[xc] !== 255) { throw new TypeError(x + " is ambiguous"); } BASE_MAP[xc] = i; } var BASE = ALPHABET.length; var LEADER = ALPHABET.charAt(0); var FACTOR = Math.log(BASE) / Math.log(256); var iFACTOR = Math.log(256) / Math.log(BASE); function encode(source) { if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source); } if (!_Buffer.isBuffer(source)) { throw new TypeError("Expected Buffer"); } if (source.length === 0) { return ""; } var zeroes = 0; var length = 0; var pbegin = 0; var pend = source.length; while (pbegin !== pend && source[pbegin] === 0) { pbegin++; zeroes++; } var size = (pend - pbegin) * iFACTOR + 1 >>> 0; var b58 = new Uint8Array(size); while (pbegin !== pend) { var carry = source[pbegin]; var i2 = 0; for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) { carry += 256 * b58[it1] >>> 0; b58[it1] = carry % BASE >>> 0; carry = carry / BASE >>> 0; } if (carry !== 0) { throw new Error("Non-zero carry"); } length = i2; pbegin++; } var it2 = size - length; while (it2 !== size && b58[it2] === 0) { it2++; } var str = LEADER.repeat(zeroes); for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); } return str; } function decodeUnsafe(source) { if (typeof source !== "string") { throw new TypeError("Expected String"); } if (source.length === 0) { return _Buffer.alloc(0); } var psz = 0; var zeroes = 0; var length = 0; while (source[psz] === LEADER) { zeroes++; psz++; } var size = (source.length - psz) * FACTOR + 1 >>> 0; var b256 = new Uint8Array(size); while (psz < source.length) { var charCode = source.charCodeAt(psz); if (charCode > 255) { return; } var carry = BASE_MAP[charCode]; if (carry === 255) { return; } var i2 = 0; for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) { carry += BASE * b256[it3] >>> 0; b256[it3] = carry % 256 >>> 0; carry = carry / 256 >>> 0; } if (carry !== 0) { throw new Error("Non-zero carry"); } length = i2; psz++; } var it4 = size - length; while (it4 !== size && b256[it4] === 0) { it4++; } var vch = _Buffer.allocUnsafe(zeroes + (size - it4)); vch.fill(0, 0, zeroes); var j2 = zeroes; while (it4 !== size) { vch[j2++] = b256[it4++]; } return vch; } function decode(string) { var buffer = decodeUnsafe(string); if (buffer) { return buffer; } throw new Error("Non-base" + BASE + " character"); } return { encode, decodeUnsafe, decode }; } module.exports = base; } }); // node_modules/bs58/index.js var require_bs58 = __commonJS({ "node_modules/bs58/index.js"(exports, module) { var basex = require_src(); var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; module.exports = basex(ALPHABET); } }); // node_modules/bs58check/base.js var require_base = __commonJS({ "node_modules/bs58check/base.js"(exports, module) { "use strict"; var base58 = require_bs58(); var Buffer2 = require_safe_buffer().Buffer; module.exports = function(checksumFn) { function encode(payload) { var checksum = checksumFn(payload); return base58.encode(Buffer2.concat([ payload, checksum ], payload.length + 4)); } function decodeRaw(buffer) { var payload = buffer.slice(0, -4); var checksum = buffer.slice(-4); var newChecksum = checksumFn(payload); if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return; return payload; } function decodeUnsafe(string) { var buffer = base58.decodeUnsafe(string); if (!buffer) return; return decodeRaw(buffer); } function decode(string) { var buffer = base58.decode(string); var payload = decodeRaw(buffer, checksumFn); if (!payload) throw new Error("Invalid checksum"); return payload; } return { encode, decode, decodeUnsafe }; }; } }); // node_modules/bs58check/index.js var require_bs58check = __commonJS({ "node_modules/bs58check/index.js"(exports, module) { "use strict"; var createHash2 = require_create_hash(); var bs58checkBase = require_base(); function sha256x2(buffer) { var tmp = createHash2("sha256").update(buffer).digest(); return createHash2("sha256").update(tmp).digest(); } module.exports = bs58checkBase(sha256x2); } }); // node_modules/bitcoinjs-message/node_modules/bech32/index.js var require_bech32 = __commonJS({ "node_modules/bitcoinjs-message/node_modules/bech32/index.js"(exports, module) { "use strict"; var ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; var ALPHABET_MAP = {}; for (z = 0; z < ALPHABET.length; z++) { x = ALPHABET.charAt(z); if (ALPHABET_MAP[x] !== void 0) throw new TypeError(x + " is ambiguous"); ALPHABET_MAP[x] = z; } var x; var z; function polymodStep(pre) { var b = pre >> 25; return (pre & 33554431) << 5 ^ -(b >> 0 & 1) & 996825010 ^ -(b >> 1 & 1) & 642813549 ^ -(b >> 2 & 1) & 513874426 ^ -(b >> 3 & 1) & 1027748829 ^ -(b >> 4 & 1) & 705979059; } function prefixChk(prefix) { var chk = 1; for (var i = 0; i < prefix.length; ++i) { var c = prefix.charCodeAt(i); if (c < 33 || c > 126) return "Invalid prefix (" + prefix + ")"; chk = polymodStep(chk) ^ c >> 5; } chk = polymodStep(chk); for (i = 0; i < prefix.length; ++i) { var v = prefix.charCodeAt(i); chk = polymodStep(chk) ^ v & 31; } return chk; } function encode(prefix, words, LIMIT) { LIMIT = LIMIT || 90; if (prefix.length + 7 + words.length > LIMIT) throw new TypeError("Exceeds length limit"); prefix = prefix.toLowerCase(); var chk = prefixChk(prefix); if (typeof chk === "string") throw new Error(chk); var result = prefix + "1"; for (var i = 0; i < words.length; ++i) { var x2 = words[i]; if (x2 >> 5 !== 0) throw new Error("Non 5-bit word"); chk = polymodStep(chk) ^ x2; result += ALPHABET.charAt(x2); } for (i = 0; i < 6; ++i) { chk = polymodStep(chk); } chk ^= 1; for (i = 0; i < 6; ++i) { var v = chk >> (5 - i) * 5 & 31; result += ALPHABET.charAt(v); } return result; } function __decode(str, LIMIT) { LIMIT = LIMIT || 90; if (str.length < 8) return str + " too short"; if (str.length > LIMIT) return "Exceeds length limit"; var lowered = str.toLowerCase(); var uppered = str.toUpperCase(); if (str !== lowered && str !== uppered) return "Mixed-case string " + str; str = lowered; var split2 = str.lastIndexOf("1"); if (split2 === -1) return "No separator character for " + str; if (split2 === 0) return "Missing prefix for " + str; var prefix = str.slice(0, split2); var wordChars = str.slice(split2 + 1); if (wordChars.length < 6) return "Data too short"; var chk = prefixChk(prefix); if (typeof chk === "string") return chk; var words = []; for (var i = 0; i < wordChars.length; ++i) { var c = wordChars.charAt(i); var v = ALPHABET_MAP[c]; if (v === void 0) return "Unknown character " + c; chk = polymodStep(chk) ^ v; if (i + 6 >= wordChars.length) continue; words.push(v); } if (chk !== 1) return "Invalid checksum for " + str; return { prefix, words }; } function decodeUnsafe() { var res = __decode.apply(null, arguments); if (typeof res === "object") return res; } function decode(str) { var res = __decode.apply(null, arguments); if (typeof res === "object") return res; throw new Error(res); } function convert(data, inBits, outBits, pad) { var value = 0; var bits = 0; var maxV = (1 << outBits) - 1; var result = []; for (var i = 0; i < data.length; ++i) { value = value << inBits | data[i]; bits += inBits; while (bits >= outBits) { bits -= outBits; result.push(value >> bits & maxV); } } if (pad) { if (bits > 0) { result.push(value << outBits - bits & maxV); } } else { if (bits >= inBits) return "Excess padding"; if (value << outBits - bits & maxV) return "Non-zero padding"; } return result; } function toWordsUnsafe(bytes) { var res = convert(bytes, 8, 5, true); if (Array.isArray(res)) return res; } function toWords(bytes) { var res = convert(bytes, 8, 5, true); if (Array.isArray(res)) return res; throw new Error(res); } function fromWordsUnsafe(words) { var res = convert(words, 5, 8, false); if (Array.isArray(res)) return res; } function fromWords(words) { var res = convert(words, 5, 8, false); if (Array.isArray(res)) return res; throw new Error(res); } module.exports = { decodeUnsafe, decode, encode, toWordsUnsafe, toWords, fromWordsUnsafe, fromWords }; } }); // node_modules/buffer-equals/index.js var require_buffer_equals = __commonJS({ "node_modules/buffer-equals/index.js"(exports, module) { "use strict"; module.exports = function(a, b) { if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { throw new TypeError("Arguments must be Buffers"); } if (a === b) { return true; } if (typeof a.equals === "function") { return a.equals(b); } if (a.length !== b.length) { return false; } for (var i = 0; i < a.length; i++) { if (a[i] !== b[i]) { return false; } } return true; }; } }); // node_modules/file-uri-to-path/index.js var require_file_uri_to_path = __commonJS({ "node_modules/file-uri-to-path/index.js"(exports, module) { var sep = __require("path").sep || "/"; module.exports = fileUriToPath; function fileUriToPath(uri) { if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) { throw new TypeError("must pass in a file:// URI to convert to a file path"); } var rest = decodeURI(uri.substring(7)); var firstSlash = rest.indexOf("/"); var host = rest.substring(0, firstSlash); var path = rest.substring(firstSlash + 1); if ("localhost" == host) host = ""; if (host) { host = sep + sep + host; } path = path.replace(/^(.+)\|/, "$1:"); if (sep == "\\") { path = path.replace(/\//g, "\\"); } if (/^.+\:/.test(path)) { } else { path = sep + path; } return host + path; } } }); // node_modules/bindings/bindings.js var require_bindings = __commonJS({ "node_modules/bindings/bindings.js"(exports, module) { var fs = __require("fs"); var path = __require("path"); var fileURLToPath = require_file_uri_to_path(); var join = path.join; var dirname = path.dirname; var exists = fs.accessSync && function(path2) { try { fs.accessSync(path2); } catch (e) { return false; } return true; } || fs.existsSync || path.existsSync; var defaults = { arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ", compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled", platform: process.platform, arch: process.arch, nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch, version: process.versions.node, bindings: "bindings.node", try: [ // node-gyp's linked version in the "build" dir ["module_root", "build", "bindings"], // node-waf and gyp_addon (a.k.a node-gyp) ["module_root", "build", "Debug", "bindings"], ["module_root", "build", "Release", "bindings"], // Debug files, for development (legacy behavior, remove for node v0.9) ["module_root", "out", "Debug", "bindings"], ["module_root", "Debug", "bindings"], // Release files, but manually compiled (legacy behavior, remove for node v0.9) ["module_root", "out", "Release", "bindings"], ["module_root", "Release", "bindings"], // Legacy from node-waf, node <= 0.4.x ["module_root", "build", "default", "bindings"], // Production "Release" buildtype binary (meh...) ["module_root", "compiled", "version", "platform", "arch", "bindings"], // node-qbs builds ["module_root", "addon-build", "release", "install-root", "bindings"], ["module_root", "addon-build", "debug", "install-root", "bindings"], ["module_root", "addon-build", "default", "install-root", "bindings"], // node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch} ["module_root", "lib", "binding", "nodePreGyp", "bindings"] ] }; function bindings(opts) { if (typeof opts == "string") { opts = { bindings: opts }; } else if (!opts) { opts = {}; } Object.keys(defaults).map(function(i2) { if (!(i2 in opts)) opts[i2] = defaults[i2]; }); if (!opts.module_root) { opts.module_root = exports.getRoot(exports.getFileName()); } if (path.extname(opts.bindings) != ".node") { opts.bindings += ".node"; } var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require; var tries = [], i = 0, l = opts.try.length, n, b, err; for (; i < l; i++) { n = join.apply( null, opts.try[i].map(function(p) { return opts[p] || p; }) ); tries.push(n); try { b = opts.path ? requireFunc.resolve(n) : requireFunc(n); if (!opts.path) { b.path = n; } return b; } catch (e) { if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) { throw e; } } } err = new Error( "Could not locate the bindings file. Tried:\n" + tries.map(function(a) { return opts.arrow + a; }).join("\n") ); err.tries = tries; throw err; } module.exports = exports = bindings; exports.getFileName = function getFileName(calling_file) { var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName; Error.stackTraceLimit = 10; Error.prepareStackTrace = function(e, st) { for (var i = 0, l = st.length; i < l; i++) { fileName = st[i].getFileName(); if (fileName !== __filename) { if (calling_file) { if (fileName !== calling_file) { return; } } else { return; } } } }; Error.captureStackTrace(dummy); dummy.stack; Error.prepareStackTrace = origPST; Error.stackTraceLimit = origSTL; var fileSchema = "file://"; if (fileName.indexOf(fileSchema) === 0) { fileName = fileURLToPath(fileName); } return fileName; }; exports.getRoot = function getRoot(file) { var dir = dirname(file), prev; while (true) { if (dir === ".") { dir = process.cwd(); } if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) { return dir; } if (prev === dir) { throw new Error( 'Could not find module root given file: "' + file + '". Do you have a `package.json` file? ' ); } prev = dir; dir = join(dir, ".."); } }; } }); // node_modules/secp256k1/bindings.js var require_bindings2 = __commonJS({ "node_modules/secp256k1/bindings.js"(exports, module) { "use strict"; module.exports = require_bindings()("secp256k1"); } }); // node_modules/secp256k1/lib/assert.js var require_assert = __commonJS({ "node_modules/secp256k1/lib/assert.js"(exports) { "use strict"; var toString = Object.prototype.toString; exports.isArray = function(value, message) { if (!Array.isArray(value)) throw TypeError(message); }; exports.isBoolean = function(value, message) { if (toString.call(value) !== "[object Boolean]") throw TypeError(message); }; exports.isBuffer = function(value, message) { if (!Buffer.isBuffer(value)) throw TypeError(message); }; exports.isFunction = function(value, message) { if (toString.call(value) !== "[object Function]") throw TypeError(message); }; exports.isNumber = function(value, message) { if (toString.call(value) !== "[object Number]") throw TypeError(message); }; exports.isObject = function(value, message) { if (toString.call(value) !== "[object Object]") throw TypeError(message); }; exports.isBufferLength = function(buffer, length, message) { if (buffer.length !== length) throw RangeError(message); }; exports.isBufferLength2 = function(buffer, length1, length2, message) { if (buffer.length !== length1 && buffer.length !== length2) throw RangeError(message); }; exports.isLengthGTZero = function(value, message) { if (value.length === 0) throw RangeError(message); }; exports.isNumberInInterval = function(number, x, y, message) { if (number <= x || number >= y) throw RangeError(message); }; } }); // node_modules/bip66/index.js var require_bip66 = __commonJS({ "node_modules/bip66/index.js"(exports, module) { var Buffer2 = require_safe_buffer().Buffer; function check(buffer) { if (buffer.length < 8) return false; if (buffer.length > 72) return false; if (buffer[0] !== 48) return false; if (buffer[1] !== buffer.length - 2) return false; if (buffer[2] !== 2) return false; var lenR = buffer[3]; if (lenR === 0) return false; if (5 + lenR >= buffer.length) return false; if (buffer[4 + lenR] !== 2) return false; var lenS = buffer[5 + lenR]; if (lenS === 0) return false; if (6 + lenR + lenS !== buffer.length) return false; if (buffer[4] & 128) return false; if (lenR > 1 && buffer[4] === 0 && !(buffer[5] & 128)) return false; if (buffer[lenR + 6] & 128) return false; if (lenS > 1 && buffer[lenR + 6] === 0 && !(buffer[lenR + 7] & 128)) return false; return true; } function decode(buffer) { if (buffer.length < 8) throw new Error("DER sequence length is too short"); if (buffer.length > 72) throw new Error("DER sequence length is too long"); if (buffer[0] !== 48) throw new Error("Expected DER sequence"); if (buffer[1] !== buffer.length - 2) throw new Error("DER sequence length is invalid"); if (buffer[2] !== 2) throw new Error("Expected DER integer"); var lenR = buffer[3]; if (lenR === 0) throw new Error("R length is zero"); if (5 + lenR >= buffer.length) throw new Error("R length is too long"); if (buffer[4 + lenR] !== 2) throw new Error("Expected DER integer (2)"); var lenS = buffer[5 + lenR]; if (lenS === 0) throw new Error("S length is zero"); if (6 + lenR + lenS !== buffer.length) throw new Error("S length is invalid"); if (buffer[4] & 128) throw new Error("R value is negative"); if (lenR > 1 && buffer[4] === 0 && !(buffer[5] & 128)) throw new Error("R value excessively padded"); if (buffer[lenR + 6] & 128) throw new Error("S value is negative"); if (lenS > 1 && buffer[lenR + 6] === 0 && !(buffer[lenR + 7] & 128)) throw new Error("S value excessively padded"); return { r: buffer.slice(4, 4 + lenR), s: buffer.slice(6 + lenR) }; } function encode(r, s) { var lenR = r.length; var lenS = s.length; if (lenR === 0) throw new Error("R length is zero"); if (lenS === 0) throw new Error("S length is zero"); if (lenR > 33) throw new Error("R length is too long"); if (lenS > 33) throw new Error("S length is too long"); if (r[0] & 128) throw new Error("R value is negative"); if (s[0] & 128) throw new Error("S value is negative"); if (lenR > 1 && r[0] === 0 && !(r[1] & 128)) throw new Error("R value excessively padded"); if (lenS > 1 && s[0] === 0 && !(s[1] & 128)) throw new Error("S value excessively padded"); var signature = Buffer2.allocUnsafe(6 + lenR + lenS); signature[0] = 48; signature[1] = signature.length - 2; signature[2] = 2; signature[3] = r.length; r.copy(signature, 4); signature[4 + lenR] = 2; signature[5 + lenR] = s.length; s.copy(signature, 6 + lenR); return signature; } module.exports = { check, decode, encode }; } }); // node_modules/secp256k1/lib/der.js var require_der = __commonJS({ "node_modules/secp256k1/lib/der.js"(exports) { "use strict"; var Buffer2 = require_safe_buffer().Buffer; var bip66 = require_bip66(); var EC_PRIVKEY_EXPORT_DER_COMPRESSED = Buffer2.from([ // begin 48, 129, 211, 2, 1, 1, 4, 32, // private key 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // middle 160, 129, 133, 48, 129, 130, 2, 1, 1, 48, 44, 6, 7, 42, 134, 72, 206, 61, 1, 1, 2, 33, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 252, 47, 48, 6, 4, 1, 0, 4, 1, 7, 4, 33, 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 2, 33, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 186, 174, 220, 230, 175, 72, 160, 59, 191, 210, 94, 140, 208, 54, 65, 65, 2, 1, 1, 161, 36, 3, 34, 0, // public key 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]); var EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED = Buffer2.from([ // begin 48, 130, 1, 19, 2, 1, 1, 4, 32, // private key 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // middle 160, 129, 165, 48, 129, 162, 2, 1, 1, 48, 44, 6, 7, 42, 134, 72, 206, 61, 1, 1, 2, 33, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 252, 47, 48, 6, 4, 1, 0, 4, 1, 7, 4, 65, 4, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17, 8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184, 2, 33, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 186, 174, 220, 230, 175, 72, 160, 59, 191, 210, 94, 140, 208, 54, 65, 65, 2, 1, 1, 161, 68, 3, 66, 0, // public key 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]); exports.privateKeyExport = function(privateKey, publicKey, compressed) { var result = Buffer2.from(compressed ? EC_PRIVKEY_EXPORT_DER_COMPRESSED : EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED); privateKey.copy(result, compressed ? 8 : 9); publicKey.copy(result, compressed ? 181 : 214); return result; }; exports.privateKeyImport = function(privateKey) { var length = privateKey.length; var index = 0; if (length < index + 1 || privateKey[index] !== 48) return; index += 1; if (length < index + 1 || !(privateKey[index] & 128)) return; var lenb = privateKey[index] & 127; index += 1; if (lenb < 1 || lenb > 2) return; if (length < index + lenb) return; var len = privateKey[index + lenb - 1] | (lenb > 1 ? privateKey[index + lenb - 2] << 8 : 0); index += lenb; if (length < index + len) return; if (length < index + 3 || privateKey[index] !== 2 || privateKey[index + 1] !== 1 || privateKey[index + 2] !== 1) { return; } index += 3; if (length < index + 2 || privateKey[index] !== 4 || privateKey[index + 1] > 32 || length < index + 2 + privateKey[index + 1]) { return; } return privateKey.slice(index + 2, index + 2 + privateKey[index + 1]); }; exports.signatureExport = function(sigObj) { var r = Buffer2.concat([Buffer2.from([0]), sigObj.r]); for (var lenR = 33, posR = 0; lenR > 1 && r[posR] === 0 && !(r[posR + 1] & 128); --lenR, ++posR) ; var s = Buffer2.concat([Buffer2.from([0]), sigObj.s]); for (var lenS = 33, posS = 0; lenS > 1 && s[posS] === 0 && !(s[posS + 1] & 128); --lenS, ++posS) ; return bip66.encode(r.slice(posR), s.slice(posS)); }; exports.signatureImport = function(sig) { var r = Buffer2.alloc(32, 0); var s = Buffer2.alloc(32, 0); try { var sigObj = bip66.decode(sig); if (sigObj.r.length === 33 && sigObj.r[0] === 0) sigObj.r = sigObj.r.slice(1); if (sigObj.r.length > 32) throw new Error("R length is too long"); if (sigObj.s.length === 33 && sigObj.s[0] === 0) sigObj.s = sigObj.s.slice(1); if (sigObj.s.length > 32) throw new Error("S length is too long"); } catch (err) { return; } sigObj.r.copy(r, 32 - sigObj.r.length); sigObj.s.copy(s, 32 - sigObj.s.length); return { r, s }; }; exports.signatureImportLax = function(sig) { var r = Buffer2.alloc(32, 0); var s = Buffer2.alloc(32, 0); var length = sig.length; var index = 0; if (sig[index++] !== 48) return; var lenbyte = sig[index++]; if (lenbyte & 128) { index += lenbyte - 128; if (index > length) return; } if (sig[index++] !== 2) return; var rlen = sig[index++]; if (rlen & 128) { lenbyte = rlen - 128; if (index + lenbyte > length) return; for (; lenbyte > 0 && sig[index] === 0; index += 1, lenbyte -= 1) ; for (rlen = 0; lenbyte > 0; index += 1, lenbyte -= 1) rlen = (rlen << 8) + sig[index]; } if (rlen > length - index) return; var rindex = index; index += rlen; if (sig[index++] !== 2) return; var slen = sig[index++]; if (slen & 128) { lenbyte = slen - 128; if (index + lenbyte > length) return; for (; lenbyte > 0 && sig[index] === 0; index += 1, lenbyte -= 1) ; for (slen = 0; lenbyte > 0; index += 1, lenbyte -= 1) slen = (slen << 8) + sig[index]; } if (slen > length - index) return; var sindex = index; index += slen; for (; rlen > 0 && sig[rindex] === 0; rlen -= 1, rindex += 1) ; if (rlen > 32) return; var rvalue = sig.slice(rindex, rindex + rlen); rvalue.copy(r, 32 - rvalue.length); for (; slen > 0 && sig[sindex] === 0; slen -= 1, sindex += 1) ; if (slen > 32) return; var svalue = sig.slice(sindex, sindex + slen); svalue.copy(s, 32 - svalue.length); return { r, s }; }; } }); // node_modules/secp256k1/lib/messages.json var require_messages = __commonJS({ "node_modules/secp256k1/lib/messages.json"(exports, module) { module.exports = { COMPRESSED_TYPE_INVALID: "compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID: "private key should be a Buffer", EC_PRIVATE_KEY_LENGTH_INVALID: "private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID: "private key range is invalid", EC_PRIVATE_KEY_TWEAK_ADD_FAIL: "tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL: "tweak out of range", EC_PRIVATE_KEY_EXPORT_DER_FAIL: "couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL: "couldn't import from DER format", EC_PUBLIC_KEYS_TYPE_INVALID: "public keys should be an Array", EC_PUBLIC_KEYS_LENGTH_INVALID: "public keys Array should have at least 1 element", EC_PUBLIC_KEY_TYPE_INVALID: "public key should be a Buffer", EC_PUBLIC_KEY_LENGTH_INVALID: "public key length is invalid", EC_PUBLIC_KEY_PARSE_FAIL: "the public key could not be parsed or is invalid", EC_PUBLIC_KEY_CREATE_FAIL: "private was invalid, try again", EC_PUBLIC_KEY_TWEAK_ADD_FAIL: "tweak out of range or resulting public key is invalid", EC_PUBLIC_KEY_TWEAK_MUL_FAIL: "tweak out of range", EC_PUBLIC_KEY_COMBINE_FAIL: "the sum of the public keys is not valid", ECDH_FAIL: "scalar was invalid (zero or overflow)", ECDSA_SIGNATURE_TYPE_INVALID: "signature should be a Buffer", ECDSA_SIGNATURE_LENGTH_INVALID: "signature length is invalid", ECDSA_SIGNATURE_PARSE_FAIL: "couldn't parse signature", ECDSA_SIGNATURE_PARSE_DER_FAIL: "couldn't parse DER signature", ECDSA_SIGNATURE_SERIALIZE_DER_FAIL: "couldn't serialize signature to DER format", ECDSA_SIGN_FAIL: "nonce generation function failed or private key is invalid", ECDSA_RECOVER_FAIL: "couldn't recover public key from signature", MSG32_TYPE_INVALID: "message should be a Buffer", MSG32_LENGTH_INVALID: "message length is invalid", OPTIONS_TYPE_INVALID: "options should be an Object", OPTIONS_DATA_TYPE_INVALID: "options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID: "options.data length is invalid", OPTIONS_NONCEFN_TYPE_INVALID: "options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID: "recovery should be a Number", RECOVERY_ID_VALUE_INVALID: "recovery should have value between -1 and 4", TWEAK_TYPE_INVALID: "tweak should be a Buffer", TWEAK_LENGTH_INVALID: "tweak length is invalid" }; } }); // node_modules/secp256k1/lib/index.js var require_lib = __commonJS({ "node_modules/secp256k1/lib/index.js"(exports, module) { "use strict"; var assert = require_assert(); var der = require_der(); var messages = require_messages(); function initCompressedValue(value, defaultValue) { if (value === void 0) return defaultValue; assert.isBoolean(value, messages.COMPRESSED_TYPE_INVALID); return value; } module.exports = function(secp256k1) { return { privateKeyVerify: function(privateKey) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); return privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey); }, privateKeyExport: function(privateKey, compressed) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); compressed = initCompressedValue(compressed, true); var publicKey = secp256k1.privateKeyExport(privateKey, compressed); return der.privateKeyExport(privateKey, publicKey, compressed); }, privateKeyImport: function(privateKey) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); privateKey = der.privateKeyImport(privateKey); if (privateKey && privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)) return privateKey; throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL); }, privateKeyNegate: function(privateKey) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); return secp256k1.privateKeyNegate(privateKey); }, privateKeyModInverse: function(privateKey) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); return secp256k1.privateKeyModInverse(privateKey); }, privateKeyTweakAdd: function(privateKey, tweak) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID); assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID); return secp256k1.privateKeyTweakAdd(privateKey, tweak); }, privateKeyTweakMul: function(privateKey, tweak) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID); assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID); return secp256k1.privateKeyTweakMul(privateKey, tweak); }, publicKeyCreate: function(privateKey, compressed) { assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID); assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); compressed = initCompressedValue(compressed, true); return secp256k1.publicKeyCreate(privateKey, compressed); }, publicKeyConvert: function(publicKey, compressed) { assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID); assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID); compressed = initCompressedValue(compressed, true); return secp256k1.publicKeyConvert(publicKey, compressed); }, publicKeyVerify: function(publicKey) { assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID); return secp256k1.publicKeyVerify(publicKey); }, publicKeyTweakAdd: function(publicKey, tweak, compressed) { assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID); assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID); assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID); assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID); compressed = initCompressedValue(compressed, true); return secp256k1.publicKeyTweakAdd(publicKey, tweak, compressed); }, publicKeyTweakMul: function(publicKey, tweak, compressed) { assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID); assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID); assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID); assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID); compressed = initCompressedValue(compressed, true); return secp256k1.publicKeyTweakMul(publicKey, tweak, compressed); }, publicKeyCombine: function(publicKeys, compressed) { assert.isArray(publicKeys, messages.EC_PUBLIC_KEYS_TYPE_INVALID); assert.isLengthGTZero(publicKeys, messages.EC_PUBLIC_KEYS_LENGTH_INVALID); for (var i = 0; i < publicKeys.length; ++i) { assert.isBuffer(publicKeys[i], messages.EC_PUBLIC_KEY_TYPE_INVALID); assert.isBufferLength2(publicKeys[i], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID); } compressed = initCompressedValue(compressed, true); return secp256k1.publicKeyCombine(publicKeys, compressed); }, signatureNormalize: function(signature) { assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID); assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID); return secp256k1.signatureNormalize(signature); }, signatureExport: function(signature) { assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID); assert.isBufferLength(signature, 64, messages.ECDSA_SI