diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 2d20978..0483a8d 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -3,6 +3,7 @@ import Blockchains from '@depay/web3-blockchains'; import { ethers } from 'ethers'; import { SignClient } from '@depay/walletconnect-v2'; import { CoinbaseWalletSDK } from '@depay/coinbase-wallet-sdk'; +import { MiniKit, ResponseEvent } from '@depay/worldcoin-precompiled'; let supported$1 = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain']; supported$1.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain']; @@ -1609,4947 +1610,6 @@ class WalletLink { WalletLink.getConnectedInstance = getConnectedInstance; WalletLink.setConnectedInstance = setConnectedInstance; -function _arrayLikeToArray(r, a) { - (null == a || a > r.length) && (a = r.length); - for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; - return n; -} -function _arrayWithHoles(r) { - if (Array.isArray(r)) return r; -} -function _arrayWithoutHoles(r) { - if (Array.isArray(r)) return _arrayLikeToArray(r); -} -function _assertThisInitialized(e) { - if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return e; -} -function asyncGeneratorStep(n, t, e, r, o, a, c) { - try { - var i = n[a](c), - u = i.value; - } catch (n) { - return void e(n); - } - i.done ? t(u) : Promise.resolve(u).then(r, o); -} -function _asyncToGenerator(n) { - return function () { - var t = this, - e = arguments; - return new Promise(function (r, o) { - var a = n.apply(t, e); - function _next(n) { - asyncGeneratorStep(a, r, o, _next, _throw, "next", n); - } - function _throw(n) { - asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); - } - _next(void 0); - }); - }; -} -function _callSuper(t, o, e) { - return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); -} -function _classCallCheck(a, n) { - if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); -} -function _construct(t, e, r) { - if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); - var o = [null]; - o.push.apply(o, e); - var p = new (t.bind.apply(t, o))(); - return r && _setPrototypeOf(p, r.prototype), p; -} -function _defineProperties(e, r) { - for (var t = 0; t < r.length; t++) { - var o = r[t]; - o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); - } -} -function _createClass(e, r, t) { - return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { - writable: !1 - }), e; -} -function _defineProperty(e, r, t) { - return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { - value: t, - enumerable: !0, - configurable: !0, - writable: !0 - }) : e[r] = t, e; -} -function _get() { - return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { - var p = _superPropBase(e, t); - if (p) { - var n = Object.getOwnPropertyDescriptor(p, t); - return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; - } - }, _get.apply(null, arguments); -} -function _getPrototypeOf(t) { - return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { - return t.__proto__ || Object.getPrototypeOf(t); - }, _getPrototypeOf(t); -} -function _inherits(t, e) { - if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); - t.prototype = Object.create(e && e.prototype, { - constructor: { - value: t, - writable: !0, - configurable: !0 - } - }), Object.defineProperty(t, "prototype", { - writable: !1 - }), e && _setPrototypeOf(t, e); -} -function _isNativeFunction(t) { - try { - return -1 !== Function.toString.call(t).indexOf("[native code]"); - } catch (n) { - return "function" == typeof t; - } -} -function _isNativeReflectConstruct() { - try { - var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); - } catch (t) {} - return (_isNativeReflectConstruct = function () { - return !!t; - })(); -} -function _iterableToArray(r) { - if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); -} -function _iterableToArrayLimit(r, l) { - var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; - if (null != t) { - var e, - n, - i, - u, - a = [], - f = !0, - o = !1; - try { - if (i = (t = t.call(r)).next, 0 === l) { - if (Object(t) !== t) return; - f = !1; - } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); - } catch (r) { - o = !0, n = r; - } finally { - try { - if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; - } finally { - if (o) throw n; - } - } - return a; - } -} -function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} -function ownKeys(e, r) { - var t = Object.keys(e); - if (Object.getOwnPropertySymbols) { - var o = Object.getOwnPropertySymbols(e); - r && (o = o.filter(function (r) { - return Object.getOwnPropertyDescriptor(e, r).enumerable; - })), t.push.apply(t, o); - } - return t; -} -function _objectSpread2(e) { - for (var r = 1; r < arguments.length; r++) { - var t = null != arguments[r] ? arguments[r] : {}; - r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { - _defineProperty(e, r, t[r]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { - Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); - }); - } - return e; -} -function _possibleConstructorReturn(t, e) { - if (e && ("object" == typeof e || "function" == typeof e)) return e; - if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); - return _assertThisInitialized(t); -} -function _regeneratorRuntime() { - _regeneratorRuntime = function () { - return e; - }; - var t, - e = {}, - r = Object.prototype, - n = r.hasOwnProperty, - o = Object.defineProperty || function (t, e, r) { - t[e] = r.value; - }, - i = "function" == typeof Symbol ? Symbol : {}, - a = i.iterator || "@@iterator", - c = i.asyncIterator || "@@asyncIterator", - u = i.toStringTag || "@@toStringTag"; - function define(t, e, r) { - return Object.defineProperty(t, e, { - value: r, - enumerable: !0, - configurable: !0, - writable: !0 - }), t[e]; - } - try { - define({}, ""); - } catch (t) { - define = function (t, e, r) { - return t[e] = r; - }; - } - function wrap(t, e, r, n) { - var i = e && e.prototype instanceof Generator ? e : Generator, - a = Object.create(i.prototype), - c = new Context(n || []); - return o(a, "_invoke", { - value: makeInvokeMethod(t, r, c) - }), a; - } - function tryCatch(t, e, r) { - try { - return { - type: "normal", - arg: t.call(e, r) - }; - } catch (t) { - return { - type: "throw", - arg: t - }; - } - } - e.wrap = wrap; - var h = "suspendedStart", - l = "suspendedYield", - f = "executing", - s = "completed", - y = {}; - function Generator() {} - function GeneratorFunction() {} - function GeneratorFunctionPrototype() {} - var p = {}; - define(p, a, function () { - return this; - }); - var d = Object.getPrototypeOf, - v = d && d(d(values([]))); - v && v !== r && n.call(v, a) && (p = v); - var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); - function defineIteratorMethods(t) { - ["next", "throw", "return"].forEach(function (e) { - define(t, e, function (t) { - return this._invoke(e, t); - }); - }); - } - function AsyncIterator(t, e) { - function invoke(r, o, i, a) { - var c = tryCatch(t[r], t, o); - if ("throw" !== c.type) { - var u = c.arg, - h = u.value; - return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { - invoke("next", t, i, a); - }, function (t) { - invoke("throw", t, i, a); - }) : e.resolve(h).then(function (t) { - u.value = t, i(u); - }, function (t) { - return invoke("throw", t, i, a); - }); - } - a(c.arg); - } - var r; - o(this, "_invoke", { - value: function (t, n) { - function callInvokeWithMethodAndArg() { - return new e(function (e, r) { - invoke(t, n, e, r); - }); - } - return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); - } - }); - } - function makeInvokeMethod(e, r, n) { - var o = h; - return function (i, a) { - if (o === f) throw Error("Generator is already running"); - if (o === s) { - if ("throw" === i) throw a; - return { - value: t, - done: !0 - }; - } - for (n.method = i, n.arg = a;;) { - var c = n.delegate; - if (c) { - var u = maybeInvokeDelegate(c, n); - if (u) { - if (u === y) continue; - return u; - } - } - if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { - if (o === h) throw o = s, n.arg; - n.dispatchException(n.arg); - } else "return" === n.method && n.abrupt("return", n.arg); - o = f; - var p = tryCatch(e, r, n); - if ("normal" === p.type) { - if (o = n.done ? s : l, p.arg === y) continue; - return { - value: p.arg, - done: n.done - }; - } - "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); - } - }; - } - function maybeInvokeDelegate(e, r) { - var n = r.method, - o = e.iterator[n]; - if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; - var i = tryCatch(o, e.iterator, r.arg); - if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; - var a = i.arg; - return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); - } - function pushTryEntry(t) { - var e = { - tryLoc: t[0] - }; - 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); - } - function resetTryEntry(t) { - var e = t.completion || {}; - e.type = "normal", delete e.arg, t.completion = e; - } - function Context(t) { - this.tryEntries = [{ - tryLoc: "root" - }], t.forEach(pushTryEntry, this), this.reset(!0); - } - function values(e) { - if (e || "" === e) { - var r = e[a]; - if (r) return r.call(e); - if ("function" == typeof e.next) return e; - if (!isNaN(e.length)) { - var o = -1, - i = function next() { - for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; - return next.value = t, next.done = !0, next; - }; - return i.next = i; - } - } - throw new TypeError(typeof e + " is not iterable"); - } - return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { - value: GeneratorFunctionPrototype, - configurable: !0 - }), o(GeneratorFunctionPrototype, "constructor", { - value: GeneratorFunction, - configurable: !0 - }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { - var e = "function" == typeof t && t.constructor; - return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); - }, e.mark = function (t) { - return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; - }, e.awrap = function (t) { - return { - __await: t - }; - }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { - return this; - }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { - void 0 === i && (i = Promise); - var a = new AsyncIterator(wrap(t, r, n, o), i); - return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { - return t.done ? t.value : a.next(); - }); - }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { - return this; - }), define(g, "toString", function () { - return "[object Generator]"; - }), e.keys = function (t) { - var e = Object(t), - r = []; - for (var n in e) r.push(n); - return r.reverse(), function next() { - for (; r.length;) { - var t = r.pop(); - if (t in e) return next.value = t, next.done = !1, next; - } - return next.done = !0, next; - }; - }, e.values = values, Context.prototype = { - constructor: Context, - reset: function (e) { - if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); - }, - stop: function () { - this.done = !0; - var t = this.tryEntries[0].completion; - if ("throw" === t.type) throw t.arg; - return this.rval; - }, - dispatchException: function (e) { - if (this.done) throw e; - var r = this; - function handle(n, o) { - return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; - } - for (var o = this.tryEntries.length - 1; o >= 0; --o) { - var i = this.tryEntries[o], - a = i.completion; - if ("root" === i.tryLoc) return handle("end"); - if (i.tryLoc <= this.prev) { - var c = n.call(i, "catchLoc"), - u = n.call(i, "finallyLoc"); - if (c && u) { - if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); - if (this.prev < i.finallyLoc) return handle(i.finallyLoc); - } else if (c) { - if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); - } else { - if (!u) throw Error("try statement without catch or finally"); - if (this.prev < i.finallyLoc) return handle(i.finallyLoc); - } - } - } - }, - abrupt: function (t, e) { - for (var r = this.tryEntries.length - 1; r >= 0; --r) { - var o = this.tryEntries[r]; - if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { - var i = o; - break; - } - } - i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); - var a = i ? i.completion : {}; - return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); - }, - complete: function (t, e) { - if ("throw" === t.type) throw t.arg; - return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; - }, - finish: function (t) { - for (var e = this.tryEntries.length - 1; e >= 0; --e) { - var r = this.tryEntries[e]; - if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; - } - }, - catch: function (t) { - for (var e = this.tryEntries.length - 1; e >= 0; --e) { - var r = this.tryEntries[e]; - if (r.tryLoc === t) { - var n = r.completion; - if ("throw" === n.type) { - var o = n.arg; - resetTryEntry(r); - } - return o; - } - } - throw Error("illegal catch attempt"); - }, - delegateYield: function (e, r, n) { - return this.delegate = { - iterator: values(e), - resultName: r, - nextLoc: n - }, "next" === this.method && (this.arg = t), y; - } - }, e; -} -function _setPrototypeOf(t, e) { - return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { - return t.__proto__ = e, t; - }, _setPrototypeOf(t, e); -} -function _slicedToArray(r, e) { - return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); -} -function _superPropBase(t, o) { - for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); - return t; -} -function _superPropGet(t, e, o, r) { - var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), e, o); - return 2 & r && "function" == typeof p ? function (t) { - return p.apply(o, t); - } : p; -} -function _toConsumableArray(r) { - return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); -} -function _toPrimitive(t, r) { - if ("object" != typeof t || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || "default"); - if ("object" != typeof i) return i; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return ("string" === r ? String : Number)(t); -} -function _toPropertyKey(t) { - var i = _toPrimitive(t, "string"); - return "symbol" == typeof i ? i : i + ""; -} -function _typeof(o) { - "@babel/helpers - typeof"; - - return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { - return typeof o; - } : function (o) { - return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; - }, _typeof(o); -} -function _unsupportedIterableToArray(r, a) { - if (r) { - if ("string" == typeof r) return _arrayLikeToArray(r, a); - var t = {}.toString.call(r).slice(8, -1); - return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; - } -} -function _wrapNativeSuper(t) { - var r = "function" == typeof Map ? new Map() : void 0; - return _wrapNativeSuper = function (t) { - if (null === t || !_isNativeFunction(t)) return t; - if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); - if (void 0 !== r) { - if (r.has(t)) return r.get(t); - r.set(t, Wrapper); - } - function Wrapper() { - return _construct(t, arguments, _getPrototypeOf(this).constructor); - } - return Wrapper.prototype = Object.create(t.prototype, { - constructor: { - value: Wrapper, - enumerable: !1, - writable: !0, - configurable: !0 - } - }), _setPrototypeOf(Wrapper, t); - }, _wrapNativeSuper(t); -} - -function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; -} - -function getAugmentedNamespace(n) { - var f = n.default; - if (typeof f == "function") { - var a = function () { - return f.apply(this, arguments); - }; - a.prototype = f.prototype; - } else a = {}; - Object.defineProperty(a, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; -} - -var buffer = {}; - -var base64Js = {}; - -base64Js.byteLength = byteLength; -base64Js.toByteArray = toByteArray; -base64Js.fromByteArray = fromByteArray; -var lookup = []; -var revLookup = []; -var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; -var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i]; - revLookup[code.charCodeAt(i)] = i; -} - -// Support decoding URL-safe base64 strings, as Node.js does. -// See: https://en.wikipedia.org/wiki/Base64#URL_applications -revLookup['-'.charCodeAt(0)] = 62; -revLookup['_'.charCodeAt(0)] = 63; -function getLens(b64) { - var len = b64.length; - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4'); - } - - // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - var validLen = b64.indexOf('='); - if (validLen === -1) validLen = len; - var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; - return [validLen, placeHoldersLen]; -} - -// base64 is 4/3 + up to two characters of the original data -function byteLength(b64) { - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; -} -function _byteLength(b64, validLen, placeHoldersLen) { - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; -} -function toByteArray(b64) { - var tmp; - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); - var curByte = 0; - - // if there are placeholders, only get up to the last complete 4 chars - var len = placeHoldersLen > 0 ? validLen - 4 : validLen; - var i; - for (i = 0; i < len; i += 4) { - tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; - arr[curByte++] = tmp >> 16 & 0xFF; - arr[curByte++] = tmp >> 8 & 0xFF; - arr[curByte++] = tmp & 0xFF; - } - if (placeHoldersLen === 2) { - tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; - arr[curByte++] = tmp & 0xFF; - } - if (placeHoldersLen === 1) { - tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; - arr[curByte++] = tmp >> 8 & 0xFF; - arr[curByte++] = tmp & 0xFF; - } - return arr; -} -function tripletToBase64(num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; -} -function encodeChunk(uint8, start, end) { - var tmp; - var output = []; - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF); - output.push(tripletToBase64(tmp)); - } - return output.join(''); -} -function fromByteArray(uint8) { - var tmp; - var len = uint8.length; - var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes - var parts = []; - var maxChunkLength = 16383; // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); - } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1]; - parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '=='); - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1]; - parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '='); - } - return parts.join(''); -} - -var ieee754 = {}; - -/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ -ieee754.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var nBits = -7; - var i = isLE ? nBytes - 1 : 0; - var d = isLE ? -1 : 1; - var s = buffer[offset + i]; - i += d; - e = s & (1 << -nBits) - 1; - s >>= -nBits; - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} - m = e & (1 << -nBits) - 1; - e >>= -nBits; - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : (s ? -1 : 1) * Infinity; - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen); -}; -ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; - var i = isLE ? 0 : nBytes - 1; - var d = isLE ? 1 : -1; - var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; - value = Math.abs(value); - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; - } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; - } - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; - } - } - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - e = e << mLen | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - buffer[offset + i - d] |= s * 128; -}; - -(function (exports) { - - var base64 = base64Js; - var ieee754$1 = ieee754; - var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' // eslint-disable-line dot-notation - ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation - : null; - exports.Buffer = Buffer; - exports.SlowBuffer = SlowBuffer; - exports.INSPECT_MAX_BYTES = 50; - var K_MAX_LENGTH = 0x7fffffff; - exports.kMaxLength = K_MAX_LENGTH; - - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ - Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); - if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') { - console.error('This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'); - } - function typedArraySupport() { - // Can typed array instances can be augmented? - try { - var arr = new Uint8Array(1); - var proto = { - foo: function foo() { - return 42; - } - }; - Object.setPrototypeOf(proto, Uint8Array.prototype); - Object.setPrototypeOf(arr, proto); - return arr.foo() === 42; - } catch (e) { - return false; - } - } - Object.defineProperty(Buffer.prototype, 'parent', { - enumerable: true, - get: function get() { - if (!Buffer.isBuffer(this)) return undefined; - return this.buffer; - } - }); - Object.defineProperty(Buffer.prototype, 'offset', { - enumerable: true, - get: function get() { - if (!Buffer.isBuffer(this)) return undefined; - return this.byteOffset; - } - }); - function createBuffer(length) { - if (length > K_MAX_LENGTH) { - throw new RangeError('The value "' + length + '" is invalid for option "size"'); - } - // Return an augmented `Uint8Array` instance - var buf = new Uint8Array(length); - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - function Buffer(arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new TypeError('The "string" argument must be of type string. Received type number'); - } - return allocUnsafe(arg); - } - return from(arg, encodingOrOffset, length); - } - Buffer.poolSize = 8192; // not used by this implementation - - function from(value, encodingOrOffset, length) { - if (typeof value === 'string') { - return fromString(value, encodingOrOffset); - } - if (ArrayBuffer.isView(value)) { - return fromArrayView(value); - } - if (value == null) { - throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value)); - } - if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - if (typeof SharedArrayBuffer !== 'undefined' && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - if (typeof value === 'number') { - throw new TypeError('The "value" argument must not be of type number. Received type number'); - } - var valueOf = value.valueOf && value.valueOf(); - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length); - } - var b = fromObject(value); - if (b) return b; - if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') { - return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); - } - throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value)); - } - - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length); - }; - - // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: - // https://github.com/feross/buffer/pull/148 - Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); - Object.setPrototypeOf(Buffer, Uint8Array); - function assertSize(size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be of type number'); - } else if (size < 0) { - throw new RangeError('The value "' + size + '" is invalid for option "size"'); - } - } - function alloc(size, fill, encoding) { - assertSize(size); - if (size <= 0) { - return createBuffer(size); - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpreted as a start offset. - return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); - } - return createBuffer(size); - } - - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - Buffer.alloc = function (size, fill, encoding) { - return alloc(size, fill, encoding); - }; - function allocUnsafe(size) { - assertSize(size); - return createBuffer(size < 0 ? 0 : checked(size) | 0); - } - - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - Buffer.allocUnsafe = function (size) { - return allocUnsafe(size); - }; - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(size); - }; - function fromString(string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8'; - } - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding); - } - var length = byteLength(string, encoding) | 0; - var buf = createBuffer(length); - var actual = buf.write(string, encoding); - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual); - } - return buf; - } - function fromArrayLike(array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0; - var buf = createBuffer(length); - for (var i = 0; i < length; i += 1) { - buf[i] = array[i] & 255; - } - return buf; - } - function fromArrayView(arrayView) { - if (isInstance(arrayView, Uint8Array)) { - var copy = new Uint8Array(arrayView); - return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); - } - return fromArrayLike(arrayView); - } - function fromArrayBuffer(array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('"offset" is outside of buffer bounds'); - } - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('"length" is outside of buffer bounds'); - } - var buf; - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array); - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset); - } else { - buf = new Uint8Array(array, byteOffset, length); - } - - // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - function fromObject(obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0; - var buf = createBuffer(len); - if (buf.length === 0) { - return buf; - } - obj.copy(buf, 0, 0, len); - return buf; - } - if (obj.length !== undefined) { - if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { - return createBuffer(0); - } - return fromArrayLike(obj); - } - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { - return fromArrayLike(obj.data); - } - } - function checked(length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes'); - } - return length | 0; - } - function SlowBuffer(length) { - if (+length != length) { - // eslint-disable-line eqeqeq - length = 0; - } - return Buffer.alloc(+length); - } - Buffer.isBuffer = function isBuffer(b) { - return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false - }; - Buffer.compare = function compare(a, b) { - if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); - if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'); - } - if (a === b) return 0; - var x = a.length; - var y = b.length; - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; - } - } - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; - Buffer.isEncoding = function isEncoding(encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true; - default: - return false; - } - }; - Buffer.concat = function concat(list, length) { - if (!Array.isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers'); - } - if (list.length === 0) { - return Buffer.alloc(0); - } - var i; - if (length === undefined) { - length = 0; - for (i = 0; i < list.length; ++i) { - length += list[i].length; - } - } - var buffer = Buffer.allocUnsafe(length); - var pos = 0; - for (i = 0; i < list.length; ++i) { - var buf = list[i]; - if (isInstance(buf, Uint8Array)) { - if (pos + buf.length > buffer.length) { - if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); - buf.copy(buffer, pos); - } else { - Uint8Array.prototype.set.call(buffer, buf, pos); - } - } else if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers'); - } else { - buf.copy(buffer, pos); - } - pos += buf.length; - } - return buffer; - }; - function byteLength(string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length; - } - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength; - } - if (typeof string !== 'string') { - throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string)); - } - var len = string.length; - var mustMatch = arguments.length > 2 && arguments[2] === true; - if (!mustMatch && len === 0) return 0; - - // Use a for loop to avoid recursion - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len; - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length; - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2; - case 'hex': - return len >>> 1; - case 'base64': - return base64ToBytes(string).length; - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 - } - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - } - Buffer.byteLength = byteLength; - function slowToString(encoding, start, end) { - var loweredCase = false; - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0; - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return ''; - } - if (end === undefined || end > this.length) { - end = this.length; - } - if (end <= 0) { - return ''; - } - - // Force coercion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0; - start >>>= 0; - if (end <= start) { - return ''; - } - if (!encoding) encoding = 'utf8'; - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end); - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end); - case 'ascii': - return asciiSlice(this, start, end); - case 'latin1': - case 'binary': - return latin1Slice(this, start, end); - case 'base64': - return base64Slice(this, start, end); - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end); - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); - encoding = (encoding + '').toLowerCase(); - loweredCase = true; - } - } - } - - // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) - // to detect a Buffer instance. It's not possible to use `instanceof Buffer` - // reliably in a browserify context because there could be multiple different - // copies of the 'buffer' package in use. This method works even for Buffer - // instances that were created from another copy of the `buffer` package. - // See: https://github.com/feross/buffer/issues/154 - Buffer.prototype._isBuffer = true; - function swap(b, n, m) { - var i = b[n]; - b[n] = b[m]; - b[m] = i; - } - Buffer.prototype.swap16 = function swap16() { - var len = this.length; - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits'); - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1); - } - return this; - }; - Buffer.prototype.swap32 = function swap32() { - var len = this.length; - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits'); - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3); - swap(this, i + 1, i + 2); - } - return this; - }; - Buffer.prototype.swap64 = function swap64() { - var len = this.length; - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits'); - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7); - swap(this, i + 1, i + 6); - swap(this, i + 2, i + 5); - swap(this, i + 3, i + 4); - } - return this; - }; - Buffer.prototype.toString = function toString() { - var length = this.length; - if (length === 0) return ''; - if (arguments.length === 0) return utf8Slice(this, 0, length); - return slowToString.apply(this, arguments); - }; - Buffer.prototype.toLocaleString = Buffer.prototype.toString; - Buffer.prototype.equals = function equals(b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); - if (this === b) return true; - return Buffer.compare(this, b) === 0; - }; - Buffer.prototype.inspect = function inspect() { - var str = ''; - var max = exports.INSPECT_MAX_BYTES; - str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); - if (this.length > max) str += ' ... '; - return ''; - }; - if (customInspectSymbol) { - Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; - } - Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { - if (isInstance(target, Uint8Array)) { - target = Buffer.from(target, target.offset, target.byteLength); - } - if (!Buffer.isBuffer(target)) { - throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + _typeof(target)); - } - if (start === undefined) { - start = 0; - } - if (end === undefined) { - end = target ? target.length : 0; - } - if (thisStart === undefined) { - thisStart = 0; - } - if (thisEnd === undefined) { - thisEnd = this.length; - } - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index'); - } - if (thisStart >= thisEnd && start >= end) { - return 0; - } - if (thisStart >= thisEnd) { - return -1; - } - if (start >= end) { - return 1; - } - start >>>= 0; - end >>>= 0; - thisStart >>>= 0; - thisEnd >>>= 0; - if (this === target) return 0; - var x = thisEnd - thisStart; - var y = end - start; - var len = Math.min(x, y); - var thisCopy = this.slice(thisStart, thisEnd); - var targetCopy = target.slice(start, end); - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i]; - y = targetCopy[i]; - break; - } - } - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; - - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1; - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset; - byteOffset = 0; - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff; - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000; - } - byteOffset = +byteOffset; // Coerce to Number. - if (numberIsNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : buffer.length - 1; - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset; - if (byteOffset >= buffer.length) { - if (dir) return -1;else byteOffset = buffer.length - 1; - } else if (byteOffset < 0) { - if (dir) byteOffset = 0;else return -1; - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding); - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1; - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir); - } else if (typeof val === 'number') { - val = val & 0xFF; // Search for a byte value [0-255] - if (typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); - } - } - return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); - } - throw new TypeError('val must be string, number or Buffer'); - } - function arrayIndexOf(arr, val, byteOffset, encoding, dir) { - var indexSize = 1; - var arrLength = arr.length; - var valLength = val.length; - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase(); - if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1; - } - indexSize = 2; - arrLength /= 2; - valLength /= 2; - byteOffset /= 2; - } - } - function read(buf, i) { - if (indexSize === 1) { - return buf[i]; - } else { - return buf.readUInt16BE(i * indexSize); - } - } - var i; - if (dir) { - var foundIndex = -1; - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i; - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; - } else { - if (foundIndex !== -1) i -= i - foundIndex; - foundIndex = -1; - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; - for (i = byteOffset; i >= 0; i--) { - var found = true; - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false; - break; - } - } - if (found) return i; - } - } - return -1; - } - Buffer.prototype.includes = function includes(val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1; - }; - Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true); - }; - Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false); - }; - function hexWrite(buf, string, offset, length) { - offset = Number(offset) || 0; - var remaining = buf.length - offset; - if (!length) { - length = remaining; - } else { - length = Number(length); - if (length > remaining) { - length = remaining; - } - } - var strLen = string.length; - if (length > strLen / 2) { - length = strLen / 2; - } - var i; - for (i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16); - if (numberIsNaN(parsed)) return i; - buf[offset + i] = parsed; - } - return i; - } - function utf8Write(buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); - } - function asciiWrite(buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length); - } - function base64Write(buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length); - } - function ucs2Write(buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); - } - Buffer.prototype.write = function write(string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8'; - length = this.length; - offset = 0; - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset; - length = this.length; - offset = 0; - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0; - if (isFinite(length)) { - length = length >>> 0; - if (encoding === undefined) encoding = 'utf8'; - } else { - encoding = length; - length = undefined; - } - } else { - throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); - } - var remaining = this.length - offset; - if (length === undefined || length > remaining) length = remaining; - if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds'); - } - if (!encoding) encoding = 'utf8'; - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length); - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length); - case 'ascii': - case 'latin1': - case 'binary': - return asciiWrite(this, string, offset, length); - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length); - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length); - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - }; - Buffer.prototype.toJSON = function toJSON() { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - }; - }; - function base64Slice(buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf); - } else { - return base64.fromByteArray(buf.slice(start, end)); - } - } - function utf8Slice(buf, start, end) { - end = Math.min(buf.length, end); - var res = []; - var i = start; - while (i < end) { - var firstByte = buf[i]; - var codePoint = null; - var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; - if (i + bytesPerSequence <= end) { - var secondByte = void 0, - thirdByte = void 0, - fourthByte = void 0, - tempCodePoint = void 0; - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte; - } - break; - case 2: - secondByte = buf[i + 1]; - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F; - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint; - } - } - break; - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F; - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint; - } - } - break; - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F; - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint; - } - } - } - } - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD; - bytesPerSequence = 1; - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000; - res.push(codePoint >>> 10 & 0x3FF | 0xD800); - codePoint = 0xDC00 | codePoint & 0x3FF; - } - res.push(codePoint); - i += bytesPerSequence; - } - return decodeCodePointsArray(res); - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000; - function decodeCodePointsArray(codePoints) { - var len = codePoints.length; - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints); // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = ''; - var i = 0; - while (i < len) { - res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); - } - return res; - } - function asciiSlice(buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F); - } - return ret; - } - function latin1Slice(buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - return ret; - } - function hexSlice(buf, start, end) { - var len = buf.length; - if (!start || start < 0) start = 0; - if (!end || end < 0 || end > len) end = len; - var out = ''; - for (var i = start; i < end; ++i) { - out += hexSliceLookupTable[buf[i]]; - } - return out; - } - function utf16leSlice(buf, start, end) { - var bytes = buf.slice(start, end); - var res = ''; - // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) - for (var i = 0; i < bytes.length - 1; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - return res; - } - Buffer.prototype.slice = function slice(start, end) { - var len = this.length; - start = ~~start; - end = end === undefined ? len : ~~end; - if (start < 0) { - start += len; - if (start < 0) start = 0; - } else if (start > len) { - start = len; - } - if (end < 0) { - end += len; - if (end < 0) end = 0; - } else if (end > len) { - end = len; - } - if (end < start) end = start; - var newBuf = this.subarray(start, end); - // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(newBuf, Buffer.prototype); - return newBuf; - }; - - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset(offset, ext, length) { - if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); - } - Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - return val; - }; - Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - checkOffset(offset, byteLength, this.length); - } - var val = this[offset + --byteLength]; - var mul = 1; - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul; - } - return val; - }; - Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - return this[offset]; - }; - Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] | this[offset + 1] << 8; - }; - Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] << 8 | this[offset + 1]; - }; - Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000; - }; - Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); - }; - Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var lo = first + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 24); - var hi = this[++offset] + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + last * Math.pow(2, 24); - return BigInt(lo) + (BigInt(hi) << BigInt(32)); - }); - Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var hi = first * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + this[++offset]; - var lo = this[++offset] * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + last; - return (BigInt(hi) << BigInt(32)) + BigInt(lo); - }); - Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - mul *= 0x80; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var i = byteLength; - var mul = 1; - var val = this[offset + --i]; - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul; - } - mul *= 0x80; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - if (!(this[offset] & 0x80)) return this[offset]; - return (0xff - this[offset] + 1) * -1; - }; - Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset] | this[offset + 1] << 8; - return val & 0x8000 ? val | 0xFFFF0000 : val; - }; - Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset + 1] | this[offset] << 8; - return val & 0x8000 ? val | 0xFFFF0000 : val; - }; - Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; - }; - Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; - }; - Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var val = this[offset + 4] + this[offset + 5] * Math.pow(2, 8) + this[offset + 6] * Math.pow(2, 16) + (last << 24); // Overflow - - return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 24)); - }); - Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var val = (first << 24) + - // Overflow - this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + this[++offset]; - return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + last); - }); - Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754$1.read(this, offset, true, 23, 4); - }; - Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754$1.read(this, offset, false, 23, 4); - }; - Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754$1.read(this, offset, true, 52, 8); - }; - Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754$1.read(this, offset, false, 52, 8); - }; - function checkInt(buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); - if (offset + ext > buf.length) throw new RangeError('Index out of range'); - } - Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - var mul = 1; - var i = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = value / mul & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - var i = byteLength - 1; - var mul = 1; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = value / mul & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); - this[offset] = value & 0xff; - return offset + 1; - }; - Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - this[offset] = value >>> 8; - this[offset + 1] = value & 0xff; - return offset + 2; - }; - Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - this[offset + 3] = value >>> 24; - this[offset + 2] = value >>> 16; - this[offset + 1] = value >>> 8; - this[offset] = value & 0xff; - return offset + 4; - }; - Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 0xff; - return offset + 4; - }; - function wrtBigUInt64LE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - var lo = Number(value & BigInt(0xffffffff)); - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - var hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - return offset; - } - function wrtBigUInt64BE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - var lo = Number(value & BigInt(0xffffffff)); - buf[offset + 7] = lo; - lo = lo >> 8; - buf[offset + 6] = lo; - lo = lo >> 8; - buf[offset + 5] = lo; - lo = lo >> 8; - buf[offset + 4] = lo; - var hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); - buf[offset + 3] = hi; - hi = hi >> 8; - buf[offset + 2] = hi; - hi = hi >> 8; - buf[offset + 1] = hi; - hi = hi >> 8; - buf[offset] = hi; - return offset + 8; - } - Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); - }); - Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); - }); - Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - var i = 0; - var mul = 1; - var sub = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1; - } - this[offset + i] = (value / mul >> 0) - sub & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - var i = byteLength - 1; - var mul = 1; - var sub = 0; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1; - } - this[offset + i] = (value / mul >> 0) - sub & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); - if (value < 0) value = 0xff + value + 1; - this[offset] = value & 0xff; - return offset + 1; - }; - Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - this[offset] = value >>> 8; - this[offset + 1] = value & 0xff; - return offset + 2; - }; - Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - this[offset + 2] = value >>> 16; - this[offset + 3] = value >>> 24; - return offset + 4; - }; - Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (value < 0) value = 0xffffffff + value + 1; - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 0xff; - return offset + 4; - }; - Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); - }); - Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); - }); - function checkIEEE754(buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range'); - if (offset < 0) throw new RangeError('Index out of range'); - } - function writeFloat(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - checkIEEE754(buf, value, offset, 4); - } - ieee754$1.write(buf, value, offset, littleEndian, 23, 4); - return offset + 4; - } - Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert); - }; - Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert); - }; - function writeDouble(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - checkIEEE754(buf, value, offset, 8); - } - ieee754$1.write(buf, value, offset, littleEndian, 52, 8); - return offset + 8; - } - Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert); - }; - Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert); - }; - - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy(target, targetStart, start, end) { - if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer'); - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (targetStart >= target.length) targetStart = target.length; - if (!targetStart) targetStart = 0; - if (end > 0 && end < start) end = start; - - // Copy 0 bytes; we're done - if (end === start) return 0; - if (target.length === 0 || this.length === 0) return 0; - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds'); - } - if (start < 0 || start >= this.length) throw new RangeError('Index out of range'); - if (end < 0) throw new RangeError('sourceEnd out of bounds'); - - // Are we oob? - if (end > this.length) end = this.length; - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start; - } - var len = end - start; - if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { - // Use built-in when available, missing from IE11 - this.copyWithin(targetStart, start, end); - } else { - Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); - } - return len; - }; - - // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - Buffer.prototype.fill = function fill(val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start; - start = 0; - end = this.length; - } else if (typeof end === 'string') { - encoding = end; - end = this.length; - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string'); - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding); - } - if (val.length === 1) { - var code = val.charCodeAt(0); - if (encoding === 'utf8' && code < 128 || encoding === 'latin1') { - // Fast path: If `val` fits into a single byte, use that numeric value. - val = code; - } - } - } else if (typeof val === 'number') { - val = val & 255; - } else if (typeof val === 'boolean') { - val = Number(val); - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index'); - } - if (end <= start) { - return this; - } - start = start >>> 0; - end = end === undefined ? this.length : end >>> 0; - if (!val) val = 0; - var i; - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val; - } - } else { - var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); - var len = bytes.length; - if (len === 0) { - throw new TypeError('The value "' + val + '" is invalid for argument "value"'); - } - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len]; - } - } - return this; - }; - - // CUSTOM ERRORS - // ============= - - // Simplified versions from Node, changed for Buffer-only usage - var errors = {}; - function E(sym, getMessage, Base) { - errors[sym] = /*#__PURE__*/function (_Base) { - function NodeError() { - var _this; - _classCallCheck(this, NodeError); - _this = _callSuper(this, NodeError); - Object.defineProperty(_this, 'message', { - value: getMessage.apply(_this, arguments), - writable: true, - configurable: true - }); - - // Add the error code to the name to include it in the stack trace. - _this.name = "".concat(_this.name, " [").concat(sym, "]"); - // Access the stack to generate the error message including the error code - // from the name. - _this.stack; // eslint-disable-line no-unused-expressions - // Reset the name to the actual name. - delete _this.name; - return _this; - } - _inherits(NodeError, _Base); - return _createClass(NodeError, [{ - key: "code", - get: function get() { - return sym; - }, - set: function set(value) { - Object.defineProperty(this, 'code', { - configurable: true, - enumerable: true, - value: value, - writable: true - }); - } - }, { - key: "toString", - value: function toString() { - return "".concat(this.name, " [").concat(sym, "]: ").concat(this.message); - } - }]); - }(Base); - } - E('ERR_BUFFER_OUT_OF_BOUNDS', function (name) { - if (name) { - return "".concat(name, " is outside of buffer bounds"); - } - return 'Attempt to access memory outside buffer bounds'; - }, RangeError); - E('ERR_INVALID_ARG_TYPE', function (name, actual) { - return "The \"".concat(name, "\" argument must be of type number. Received type ").concat(_typeof(actual)); - }, TypeError); - E('ERR_OUT_OF_RANGE', function (str, range, input) { - var msg = "The value of \"".concat(str, "\" is out of range."); - var received = input; - if (Number.isInteger(input) && Math.abs(input) > Math.pow(2, 32)) { - received = addNumericalSeparator(String(input)); - } else if (typeof input === 'bigint') { - received = String(input); - if (input > Math.pow(BigInt(2), BigInt(32)) || input < -Math.pow(BigInt(2), BigInt(32))) { - received = addNumericalSeparator(received); - } - received += 'n'; - } - msg += " It must be ".concat(range, ". Received ").concat(received); - return msg; - }, RangeError); - function addNumericalSeparator(val) { - var res = ''; - var i = val.length; - var start = val[0] === '-' ? 1 : 0; - for (; i >= start + 4; i -= 3) { - res = "_".concat(val.slice(i - 3, i)).concat(res); - } - return "".concat(val.slice(0, i)).concat(res); - } - - // CHECK FUNCTIONS - // =============== - - function checkBounds(buf, offset, byteLength) { - validateNumber(offset, 'offset'); - if (buf[offset] === undefined || buf[offset + byteLength] === undefined) { - boundsError(offset, buf.length - (byteLength + 1)); - } - } - function checkIntBI(value, min, max, buf, offset, byteLength) { - if (value > max || value < min) { - var n = typeof min === 'bigint' ? 'n' : ''; - var range; - if (byteLength > 3) { - if (min === 0 || min === BigInt(0)) { - range = ">= 0".concat(n, " and < 2").concat(n, " ** ").concat((byteLength + 1) * 8).concat(n); - } else { - range = ">= -(2".concat(n, " ** ").concat((byteLength + 1) * 8 - 1).concat(n, ") and < 2 ** ") + "".concat((byteLength + 1) * 8 - 1).concat(n); - } - } else { - range = ">= ".concat(min).concat(n, " and <= ").concat(max).concat(n); - } - throw new errors.ERR_OUT_OF_RANGE('value', range, value); - } - checkBounds(buf, offset, byteLength); - } - function validateNumber(value, name) { - if (typeof value !== 'number') { - throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value); - } - } - function boundsError(value, length, type) { - if (Math.floor(value) !== value) { - validateNumber(value, type); - throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); - } - if (length < 0) { - throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); - } - throw new errors.ERR_OUT_OF_RANGE(type || 'offset', ">= ".concat(type ? 1 : 0, " and <= ").concat(length), value); - } - - // HELPER FUNCTIONS - // ================ - - var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; - function base64clean(str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split('=')[0]; - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = str.trim().replace(INVALID_BASE64_RE, ''); - // Node converts strings with length < 2 to '' - if (str.length < 2) return ''; - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '='; - } - return str; - } - function utf8ToBytes(string, units) { - units = units || Infinity; - var codePoint; - var length = string.length; - var leadSurrogate = null; - var bytes = []; - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue; - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue; - } - - // valid lead - leadSurrogate = codePoint; - continue; - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - leadSurrogate = codePoint; - continue; - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - } - leadSurrogate = null; - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break; - bytes.push(codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break; - bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break; - bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break; - bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); - } else { - throw new Error('Invalid code point'); - } - } - return bytes; - } - function asciiToBytes(str) { - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF); - } - return byteArray; - } - function utf16leToBytes(str, units) { - var c, hi, lo; - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break; - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - return byteArray; - } - function base64ToBytes(str) { - return base64.toByteArray(base64clean(str)); - } - function blitBuffer(src, dst, offset, length) { - var i; - for (i = 0; i < length; ++i) { - if (i + offset >= dst.length || i >= src.length) break; - dst[i + offset] = src[i]; - } - return i; - } - - // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass - // the `instanceof` check but they should be treated as of that type. - // See: https://github.com/feross/buffer/issues/166 - function isInstance(obj, type) { - return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; - } - function numberIsNaN(obj) { - // For IE11 support - return obj !== obj; // eslint-disable-line no-self-compare - } - - // Create lookup table for `toString('hex')` - // See: https://github.com/feross/buffer/issues/219 - var hexSliceLookupTable = function () { - var alphabet = '0123456789abcdef'; - var table = new Array(256); - for (var i = 0; i < 16; ++i) { - var i16 = i * 16; - for (var j = 0; j < 16; ++j) { - table[i16 + j] = alphabet[i] + alphabet[j]; - } - } - return table; - }(); - - // Return not function with Error if BigInt not supported - function defineBigIntMethod(fn) { - return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn; - } - function BufferBigIntNotDefined() { - throw new Error('BigInt not supported'); - } -})(buffer); - -function isHex(value) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref$strict = _ref.strict, - strict = _ref$strict === void 0 ? true : _ref$strict; - if (!value) return false; - if (typeof value !== 'string') return false; - return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x'); -} - -/** - * @description Retrieves the size of the value (in bytes). - * - * @param value The value (hex or byte array) to retrieve the size of. - * @returns The size of the value (in bytes). - */ -function size(value) { - if (isHex(value, { - strict: false - })) return Math.ceil((value.length - 2) / 2); - return value.length; -} - -var version = '2.21.7'; - -var errorConfig = { - getDocsUrl: function getDocsUrl(_ref) { - var docsBaseUrl = _ref.docsBaseUrl, - _ref$docsPath = _ref.docsPath, - docsPath = _ref$docsPath === void 0 ? '' : _ref$docsPath, - docsSlug = _ref.docsSlug; - return docsPath ? "".concat(docsBaseUrl !== null && docsBaseUrl !== void 0 ? docsBaseUrl : 'https://viem.sh').concat(docsPath).concat(docsSlug ? "#".concat(docsSlug) : '') : undefined; - }, - version: version -}; -var BaseError = /*#__PURE__*/function (_Error) { - function BaseError(shortMessage) { - var _errorConfig$getDocsU, _errorConfig, _args$name; - var _this; - var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - _classCallCheck(this, BaseError); - var details = function (_args$cause) { - if (args.cause instanceof BaseError) return args.cause.details; - if ((_args$cause = args.cause) !== null && _args$cause !== void 0 && _args$cause.message) return args.cause.message; - return args.details; - }(); - var docsPath = function () { - if (args.cause instanceof BaseError) return args.cause.docsPath || args.docsPath; - return args.docsPath; - }(); - var docsUrl = (_errorConfig$getDocsU = (_errorConfig = errorConfig).getDocsUrl) === null || _errorConfig$getDocsU === void 0 ? void 0 : _errorConfig$getDocsU.call(_errorConfig, _objectSpread2(_objectSpread2({}, args), {}, { - docsPath: docsPath - })); - var message = [shortMessage || 'An error occurred.', ''].concat(_toConsumableArray(args.metaMessages ? [].concat(_toConsumableArray(args.metaMessages), ['']) : []), _toConsumableArray(docsUrl ? ["Docs: ".concat(docsUrl)] : []), _toConsumableArray(details ? ["Details: ".concat(details)] : []), _toConsumableArray(errorConfig.version ? ["Version: ".concat(errorConfig.version)] : [])).join('\n'); - _this = _callSuper(this, BaseError, [message, args.cause ? { - cause: args.cause - } : undefined]); - Object.defineProperty(_this, "details", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "docsPath", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "metaMessages", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "shortMessage", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "version", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "name", { - enumerable: true, - configurable: true, - writable: true, - value: 'BaseError' - }); - _this.details = details; - _this.docsPath = docsPath; - _this.metaMessages = args.metaMessages; - _this.name = (_args$name = args.name) !== null && _args$name !== void 0 ? _args$name : _this.name; - _this.shortMessage = shortMessage; - _this.version = version; - return _this; - } - _inherits(BaseError, _Error); - return _createClass(BaseError, [{ - key: "walk", - value: function walk(fn) { - return _walk(this, fn); - } - }]); -}(/*#__PURE__*/_wrapNativeSuper(Error)); -function _walk(err, fn) { - if (fn !== null && fn !== void 0 && fn(err)) return err; - if (err && _typeof(err) === 'object' && 'cause' in err) return _walk(err.cause, fn); - return fn ? null : err; -} - -var AbiEncodingLengthMismatchError = /*#__PURE__*/function (_BaseError8) { - function AbiEncodingLengthMismatchError(_ref7) { - var expectedLength = _ref7.expectedLength, - givenLength = _ref7.givenLength; - _classCallCheck(this, AbiEncodingLengthMismatchError); - return _callSuper(this, AbiEncodingLengthMismatchError, [['ABI encoding params/values length mismatch.', "Expected length (params): ".concat(expectedLength), "Given length (values): ".concat(givenLength)].join('\n'), { - name: 'AbiEncodingLengthMismatchError' - }]); - } - _inherits(AbiEncodingLengthMismatchError, _BaseError8); - return _createClass(AbiEncodingLengthMismatchError); -}(BaseError); -var BytesSizeMismatchError = /*#__PURE__*/function (_BaseError19) { - function BytesSizeMismatchError(_ref17) { - var expectedSize = _ref17.expectedSize, - givenSize = _ref17.givenSize; - _classCallCheck(this, BytesSizeMismatchError); - return _callSuper(this, BytesSizeMismatchError, ["Expected bytes".concat(expectedSize, ", got bytes").concat(givenSize, "."), { - name: 'BytesSizeMismatchError' - }]); - } - _inherits(BytesSizeMismatchError, _BaseError19); - return _createClass(BytesSizeMismatchError); -}(BaseError); -var UnsupportedPackedAbiType = /*#__PURE__*/function (_BaseError26) { - function UnsupportedPackedAbiType(type) { - _classCallCheck(this, UnsupportedPackedAbiType); - return _callSuper(this, UnsupportedPackedAbiType, ["Type \"".concat(type, "\" is not supported for packed encoding."), { - name: 'UnsupportedPackedAbiType' - }]); - } - _inherits(UnsupportedPackedAbiType, _BaseError26); - return _createClass(UnsupportedPackedAbiType); -}(BaseError); - -var SizeExceedsPaddingSizeError = /*#__PURE__*/function (_BaseError2) { - function SizeExceedsPaddingSizeError(_ref2) { - var size = _ref2.size, - targetSize = _ref2.targetSize, - type = _ref2.type; - _classCallCheck(this, SizeExceedsPaddingSizeError); - return _callSuper(this, SizeExceedsPaddingSizeError, ["".concat(type.charAt(0).toUpperCase()).concat(type.slice(1).toLowerCase(), " size (").concat(size, ") exceeds padding size (").concat(targetSize, ")."), { - name: 'SizeExceedsPaddingSizeError' - }]); - } - _inherits(SizeExceedsPaddingSizeError, _BaseError2); - return _createClass(SizeExceedsPaddingSizeError); -}(BaseError); - -function pad(hexOrBytes) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref.dir, - _ref$size = _ref.size, - size = _ref$size === void 0 ? 32 : _ref$size; - if (typeof hexOrBytes === 'string') return padHex(hexOrBytes, { - dir: dir, - size: size - }); - return padBytes(hexOrBytes, { - dir: dir, - size: size - }); -} -function padHex(hex_) { - var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref2.dir, - _ref2$size = _ref2.size, - size = _ref2$size === void 0 ? 32 : _ref2$size; - if (size === null) return hex_; - var hex = hex_.replace('0x', ''); - if (hex.length > size * 2) throw new SizeExceedsPaddingSizeError({ - size: Math.ceil(hex.length / 2), - targetSize: size, - type: 'hex' - }); - return "0x".concat(hex[dir === 'right' ? 'padEnd' : 'padStart'](size * 2, '0')); -} -function padBytes(bytes) { - var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref3.dir, - _ref3$size = _ref3.size, - size = _ref3$size === void 0 ? 32 : _ref3$size; - if (size === null) return bytes; - if (bytes.length > size) throw new SizeExceedsPaddingSizeError({ - size: bytes.length, - targetSize: size, - type: 'bytes' - }); - var paddedBytes = new Uint8Array(size); - for (var i = 0; i < size; i++) { - var padEnd = dir === 'right'; - paddedBytes[padEnd ? i : size - i - 1] = bytes[padEnd ? i : bytes.length - i - 1]; - } - return paddedBytes; -} - -var IntegerOutOfRangeError = /*#__PURE__*/function (_BaseError) { - function IntegerOutOfRangeError(_ref) { - var max = _ref.max, - min = _ref.min, - signed = _ref.signed, - size = _ref.size, - value = _ref.value; - _classCallCheck(this, IntegerOutOfRangeError); - return _callSuper(this, IntegerOutOfRangeError, ["Number \"".concat(value, "\" is not in safe ").concat(size ? "".concat(size * 8, "-bit ").concat(signed ? 'signed' : 'unsigned', " ") : '', "integer range ").concat(max ? "(".concat(min, " to ").concat(max, ")") : "(above ".concat(min, ")")), { - name: 'IntegerOutOfRangeError' - }]); - } - _inherits(IntegerOutOfRangeError, _BaseError); - return _createClass(IntegerOutOfRangeError); -}(BaseError); -var SizeOverflowError = /*#__PURE__*/function (_BaseError5) { - function SizeOverflowError(_ref2) { - var givenSize = _ref2.givenSize, - maxSize = _ref2.maxSize; - _classCallCheck(this, SizeOverflowError); - return _callSuper(this, SizeOverflowError, ["Size cannot exceed ".concat(maxSize, " bytes. Given size: ").concat(givenSize, " bytes."), { - name: 'SizeOverflowError' - }]); - } - _inherits(SizeOverflowError, _BaseError5); - return _createClass(SizeOverflowError); -}(BaseError); - -function assertSize(hexOrBytes, _ref) { - var size$1 = _ref.size; - if (size(hexOrBytes) > size$1) throw new SizeOverflowError({ - givenSize: size(hexOrBytes), - maxSize: size$1 - }); -} - -var hexes = /*#__PURE__*/Array.from({ - length: 256 -}, function (_v, i) { - return i.toString(16).padStart(2, '0'); -}); -/** - * Encodes a string, number, bigint, or ByteArray into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex - * - Example: https://viem.sh/docs/utilities/toHex#usage - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { toHex } from 'viem' - * const data = toHex('Hello world') - * // '0x48656c6c6f20776f726c6421' - * - * @example - * import { toHex } from 'viem' - * const data = toHex(420) - * // '0x1a4' - * - * @example - * import { toHex } from 'viem' - * const data = toHex('Hello world', { size: 32 }) - * // '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000' - */ -function toHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (typeof value === 'number' || typeof value === 'bigint') return numberToHex(value, opts); - if (typeof value === 'string') { - return stringToHex(value, opts); - } - if (typeof value === 'boolean') return boolToHex(value, opts); - return bytesToHex(value, opts); -} -/** - * Encodes a boolean into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#booltohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(true) - * // '0x1' - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(false) - * // '0x0' - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(true, { size: 32 }) - * // '0x0000000000000000000000000000000000000000000000000000000000000001' - */ -function boolToHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var hex = "0x".concat(Number(value)); - if (typeof opts.size === 'number') { - assertSize(hex, { - size: opts.size - }); - return pad(hex, { - size: opts.size - }); - } - return hex; -} -/** - * Encodes a bytes array into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#bytestohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { bytesToHex } from 'viem' - * const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * // '0x48656c6c6f20576f726c6421' - * - * @example - * import { bytesToHex } from 'viem' - * const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]), { size: 32 }) - * // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' - */ -function bytesToHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var string = ''; - for (var i = 0; i < value.length; i++) { - string += hexes[value[i]]; - } - var hex = "0x".concat(string); - if (typeof opts.size === 'number') { - assertSize(hex, { - size: opts.size - }); - return pad(hex, { - dir: 'right', - size: opts.size - }); - } - return hex; -} -/** - * Encodes a number or bigint into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#numbertohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { numberToHex } from 'viem' - * const data = numberToHex(420) - * // '0x1a4' - * - * @example - * import { numberToHex } from 'viem' - * const data = numberToHex(420, { size: 32 }) - * // '0x00000000000000000000000000000000000000000000000000000000000001a4' - */ -function numberToHex(value_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var signed = opts.signed, - size = opts.size; - var value = BigInt(value_); - var maxValue; - if (size) { - if (signed) maxValue = (1n << BigInt(size) * 8n - 1n) - 1n;else maxValue = Math.pow(2n, BigInt(size) * 8n) - 1n; - } else if (typeof value_ === 'number') { - maxValue = BigInt(Number.MAX_SAFE_INTEGER); - } - var minValue = typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0; - if (maxValue && value > maxValue || value < minValue) { - var suffix = typeof value_ === 'bigint' ? 'n' : ''; - throw new IntegerOutOfRangeError({ - max: maxValue ? "".concat(maxValue).concat(suffix) : undefined, - min: "".concat(minValue).concat(suffix), - signed: signed, - size: size, - value: "".concat(value_).concat(suffix) - }); - } - var hex = "0x".concat((signed && value < 0 ? (1n << BigInt(size * 8)) + BigInt(value) : value).toString(16)); - if (size) return pad(hex, { - size: size - }); - return hex; -} -var encoder$2 = /*#__PURE__*/new TextEncoder(); -/** - * Encodes a UTF-8 string into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#stringtohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { stringToHex } from 'viem' - * const data = stringToHex('Hello World!') - * // '0x48656c6c6f20576f726c6421' - * - * @example - * import { stringToHex } from 'viem' - * const data = stringToHex('Hello World!', { size: 32 }) - * // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' - */ -function stringToHex(value_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var value = encoder$2.encode(value_); - return bytesToHex(value, opts); -} - -var encoder$1 = /*#__PURE__*/new TextEncoder(); -/** - * Encodes a UTF-8 string, hex value, bigint, number or boolean to a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes - * - Example: https://viem.sh/docs/utilities/toBytes#usage - * - * @param value Value to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes('Hello world') - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes(420) - * // Uint8Array([1, 164]) - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes(420, { size: 4 }) - * // Uint8Array([0, 0, 1, 164]) - */ -function toBytes$1(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (typeof value === 'number' || typeof value === 'bigint') return numberToBytes(value, opts); - if (typeof value === 'boolean') return boolToBytes(value, opts); - if (isHex(value)) return hexToBytes(value, opts); - return stringToBytes(value, opts); -} -/** - * Encodes a boolean into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#booltobytes - * - * @param value Boolean value to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { boolToBytes } from 'viem' - * const data = boolToBytes(true) - * // Uint8Array([1]) - * - * @example - * import { boolToBytes } from 'viem' - * const data = boolToBytes(true, { size: 32 }) - * // Uint8Array([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, 1]) - */ -function boolToBytes(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var bytes = new Uint8Array(1); - bytes[0] = Number(value); - if (typeof opts.size === 'number') { - assertSize(bytes, { - size: opts.size - }); - return pad(bytes, { - size: opts.size - }); - } - return bytes; -} -// We use very optimized technique to convert hex string to byte array -var charCodeMap = { - zero: 48, - nine: 57, - A: 65, - F: 70, - a: 97, - f: 102 -}; -function charCodeToBase16(_char) { - if (_char >= charCodeMap.zero && _char <= charCodeMap.nine) return _char - charCodeMap.zero; - if (_char >= charCodeMap.A && _char <= charCodeMap.F) return _char - (charCodeMap.A - 10); - if (_char >= charCodeMap.a && _char <= charCodeMap.f) return _char - (charCodeMap.a - 10); - return undefined; -} -/** - * Encodes a hex string into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#hextobytes - * - * @param hex Hex string to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { hexToBytes } from 'viem' - * const data = hexToBytes('0x48656c6c6f20776f726c6421') - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * - * @example - * import { hexToBytes } from 'viem' - * const data = hexToBytes('0x48656c6c6f20776f726c6421', { size: 32 }) - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - */ -function hexToBytes(hex_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var hex = hex_; - if (opts.size) { - assertSize(hex, { - size: opts.size - }); - hex = pad(hex, { - dir: 'right', - size: opts.size - }); - } - var hexString = hex.slice(2); - if (hexString.length % 2) hexString = "0".concat(hexString); - var length = hexString.length / 2; - var bytes = new Uint8Array(length); - for (var index = 0, j = 0; index < length; index++) { - var nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++)); - var nibbleRight = charCodeToBase16(hexString.charCodeAt(j++)); - if (nibbleLeft === undefined || nibbleRight === undefined) { - throw new BaseError("Invalid byte sequence (\"".concat(hexString[j - 2]).concat(hexString[j - 1], "\" in \"").concat(hexString, "\").")); - } - bytes[index] = nibbleLeft * 16 + nibbleRight; - } - return bytes; -} -/** - * Encodes a number into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#numbertobytes - * - * @param value Number to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { numberToBytes } from 'viem' - * const data = numberToBytes(420) - * // Uint8Array([1, 164]) - * - * @example - * import { numberToBytes } from 'viem' - * const data = numberToBytes(420, { size: 4 }) - * // Uint8Array([0, 0, 1, 164]) - */ -function numberToBytes(value, opts) { - var hex = numberToHex(value, opts); - return hexToBytes(hex); -} -/** - * Encodes a UTF-8 string into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#stringtobytes - * - * @param value String to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { stringToBytes } from 'viem' - * const data = stringToBytes('Hello world!') - * // Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]) - * - * @example - * import { stringToBytes } from 'viem' - * const data = stringToBytes('Hello world!', { size: 32 }) - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - */ -function stringToBytes(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var bytes = encoder$1.encode(value); - if (typeof opts.size === 'number') { - assertSize(bytes, { - size: opts.size - }); - return pad(bytes, { - dir: 'right', - size: opts.size - }); - } - return bytes; -} - -function number(n) { - if (!Number.isSafeInteger(n) || n < 0) throw new Error("positive integer expected, not ".concat(n)); -} -// copied from utils -function isBytes$1(a) { - return a instanceof Uint8Array || a != null && _typeof(a) === 'object' && a.constructor.name === 'Uint8Array'; -} -function bytes(b) { - if (!isBytes$1(b)) throw new Error('Uint8Array expected'); - for (var _len = arguments.length, lengths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - lengths[_key - 1] = arguments[_key]; - } - if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length ".concat(lengths, ", not of length=").concat(b.length)); -} -function exists(instance) { - var checkFinished = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - if (instance.destroyed) throw new Error('Hash instance has been destroyed'); - if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called'); -} -function output(out, instance) { - bytes(out); - var min = instance.outputLen; - if (out.length < min) { - throw new Error("digestInto() expects output buffer of length at least ".concat(min)); - } -} - -var U32_MASK64 = /* @__PURE__ */BigInt(Math.pow(2, 32) - 1); -var _32n = /* @__PURE__ */BigInt(32); -// We are not using BigUint64Array, because they are extremely slow as per 2022 -function fromBig(n) { - var le = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - if (le) return { - h: Number(n & U32_MASK64), - l: Number(n >> _32n & U32_MASK64) - }; - return { - h: Number(n >> _32n & U32_MASK64) | 0, - l: Number(n & U32_MASK64) | 0 - }; -} -function split(lst) { - var le = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var Ah = new Uint32Array(lst.length); - var Al = new Uint32Array(lst.length); - for (var i = 0; i < lst.length; i++) { - var _fromBig = fromBig(lst[i], le), - h = _fromBig.h, - l = _fromBig.l; - var _ref = [h, l]; - Ah[i] = _ref[0]; - Al[i] = _ref[1]; - } - return [Ah, Al]; -} -// Left rotate for Shift in [1, 32) -var rotlSH = function rotlSH(h, l, s) { - return h << s | l >>> 32 - s; -}; -var rotlSL = function rotlSL(h, l, s) { - return l << s | h >>> 32 - s; -}; -// Left rotate for Shift in (32, 64), NOTE: 32 is special case. -var rotlBH = function rotlBH(h, l, s) { - return l << s - 32 | h >>> 64 - s; -}; -var rotlBL = function rotlBL(h, l, s) { - return h << s - 32 | l >>> 64 - s; -}; - -var u32 = function u32(arr) { - return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4)); -}; -var isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44; -// The byte swap operation for uint32 -var byteSwap = function byteSwap(word) { - return word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff; -}; -// In place byte swap for Uint32Array -function byteSwap32(arr) { - for (var i = 0; i < arr.length; i++) { - arr[i] = byteSwap(arr[i]); - } -} -function utf8ToBytes(str) { - if (typeof str !== 'string') throw new Error("utf8ToBytes expected string, got ".concat(_typeof(str))); - return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809 -} -/** - * Normalizes (non-hex) string or Uint8Array to Uint8Array. - * Warning: when Uint8Array is passed, it would NOT get copied. - * Keep in mind for future mutable operations. - */ -function toBytes(data) { - if (typeof data === 'string') data = utf8ToBytes(data); - bytes(data); - return data; -} -// For runtime check if class implements interface -var Hash = /*#__PURE__*/function () { - function Hash() { - _classCallCheck(this, Hash); - } - return _createClass(Hash, [{ - key: "clone", - value: - // Safe version that clones internal state - function clone() { - return this._cloneInto(); - } - }]); -}(); -function wrapConstructor(hashCons) { - var hashC = function hashC(msg) { - return hashCons().update(toBytes(msg)).digest(); - }; - var tmp = hashCons(); - hashC.outputLen = tmp.outputLen; - hashC.blockLen = tmp.blockLen; - hashC.create = function () { - return hashCons(); - }; - return hashC; -} - -// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size. -// It's called a sponge function. -// Various per round constants calculations -var SHA3_PI = []; -var SHA3_ROTL = []; -var _SHA3_IOTA = []; -var _0n = /* @__PURE__ */BigInt(0); -var _1n = /* @__PURE__ */BigInt(1); -var _2n = /* @__PURE__ */BigInt(2); -var _7n = /* @__PURE__ */BigInt(7); -var _256n = /* @__PURE__ */BigInt(256); -var _0x71n = /* @__PURE__ */BigInt(0x71); -for (var round = 0, R = _1n, x = 1, y = 0; round < 24; round++) { - // Pi - var _ref = [y, (2 * x + 3 * y) % 5]; - x = _ref[0]; - y = _ref[1]; - SHA3_PI.push(2 * (5 * y + x)); - // Rotational - SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64); - // Iota - var t = _0n; - for (var j = 0; j < 7; j++) { - R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n; - if (R & _2n) t ^= _1n << (_1n << /* @__PURE__ */BigInt(j)) - _1n; - } - _SHA3_IOTA.push(t); -} -var _split = /* @__PURE__ */split(_SHA3_IOTA, true), - _split2 = _slicedToArray(_split, 2), - SHA3_IOTA_H = _split2[0], - SHA3_IOTA_L = _split2[1]; -// Left rotation (without 0, 32, 64) -var rotlH = function rotlH(h, l, s) { - return s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s); -}; -var rotlL = function rotlL(h, l, s) { - return s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s); -}; -// Same as keccakf1600, but allows to skip some rounds -function keccakP(s) { - var rounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 24; - var B = new Uint32Array(5 * 2); - // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js) - for (var _round = 24 - rounds; _round < 24; _round++) { - // Theta θ - for (var _x = 0; _x < 10; _x++) B[_x] = s[_x] ^ s[_x + 10] ^ s[_x + 20] ^ s[_x + 30] ^ s[_x + 40]; - for (var _x2 = 0; _x2 < 10; _x2 += 2) { - var idx1 = (_x2 + 8) % 10; - var idx0 = (_x2 + 2) % 10; - var B0 = B[idx0]; - var B1 = B[idx0 + 1]; - var Th = rotlH(B0, B1, 1) ^ B[idx1]; - var Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1]; - for (var _y = 0; _y < 50; _y += 10) { - s[_x2 + _y] ^= Th; - s[_x2 + _y + 1] ^= Tl; - } - } - // Rho (ρ) and Pi (π) - var curH = s[2]; - var curL = s[3]; - for (var _t = 0; _t < 24; _t++) { - var shift = SHA3_ROTL[_t]; - var _Th = rotlH(curH, curL, shift); - var _Tl = rotlL(curH, curL, shift); - var PI = SHA3_PI[_t]; - curH = s[PI]; - curL = s[PI + 1]; - s[PI] = _Th; - s[PI + 1] = _Tl; - } - // Chi (χ) - for (var _y2 = 0; _y2 < 50; _y2 += 10) { - for (var _x3 = 0; _x3 < 10; _x3++) B[_x3] = s[_y2 + _x3]; - for (var _x4 = 0; _x4 < 10; _x4++) s[_y2 + _x4] ^= ~B[(_x4 + 2) % 10] & B[(_x4 + 4) % 10]; - } - // Iota (ι) - s[0] ^= SHA3_IOTA_H[_round]; - s[1] ^= SHA3_IOTA_L[_round]; - } - B.fill(0); -} -var Keccak = /*#__PURE__*/function (_Hash) { - // NOTE: we accept arguments in bytes instead of bits here. - function Keccak(blockLen, suffix, outputLen) { - var _this; - var enableXOF = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; - var rounds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 24; - _classCallCheck(this, Keccak); - _this = _callSuper(this, Keccak); - _this.blockLen = blockLen; - _this.suffix = suffix; - _this.outputLen = outputLen; - _this.enableXOF = enableXOF; - _this.rounds = rounds; - _this.pos = 0; - _this.posOut = 0; - _this.finished = false; - _this.destroyed = false; - // Can be passed from user as dkLen - number(outputLen); - // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes - if (0 >= _this.blockLen || _this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function'); - _this.state = new Uint8Array(200); - _this.state32 = u32(_this.state); - return _this; - } - _inherits(Keccak, _Hash); - return _createClass(Keccak, [{ - key: "keccak", - value: function keccak() { - if (!isLE) byteSwap32(this.state32); - keccakP(this.state32, this.rounds); - if (!isLE) byteSwap32(this.state32); - this.posOut = 0; - this.pos = 0; - } - }, { - key: "update", - value: function update(data) { - exists(this); - var blockLen = this.blockLen, - state = this.state; - data = toBytes(data); - var len = data.length; - for (var pos = 0; pos < len;) { - var take = Math.min(blockLen - this.pos, len - pos); - for (var i = 0; i < take; i++) state[this.pos++] ^= data[pos++]; - if (this.pos === blockLen) this.keccak(); - } - return this; - } - }, { - key: "finish", - value: function finish() { - if (this.finished) return; - this.finished = true; - var state = this.state, - suffix = this.suffix, - pos = this.pos, - blockLen = this.blockLen; - // Do the padding - state[pos] ^= suffix; - if ((suffix & 0x80) !== 0 && pos === blockLen - 1) this.keccak(); - state[blockLen - 1] ^= 0x80; - this.keccak(); - } - }, { - key: "writeInto", - value: function writeInto(out) { - exists(this, false); - bytes(out); - this.finish(); - var bufferOut = this.state; - var blockLen = this.blockLen; - for (var pos = 0, len = out.length; pos < len;) { - if (this.posOut >= blockLen) this.keccak(); - var take = Math.min(blockLen - this.posOut, len - pos); - out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos); - this.posOut += take; - pos += take; - } - return out; - } - }, { - key: "xofInto", - value: function xofInto(out) { - // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF - if (!this.enableXOF) throw new Error('XOF is not possible for this instance'); - return this.writeInto(out); - } - }, { - key: "xof", - value: function xof(bytes) { - number(bytes); - return this.xofInto(new Uint8Array(bytes)); - } - }, { - key: "digestInto", - value: function digestInto(out) { - output(out, this); - if (this.finished) throw new Error('digest() was already called'); - this.writeInto(out); - this.destroy(); - return out; - } - }, { - key: "digest", - value: function digest() { - return this.digestInto(new Uint8Array(this.outputLen)); - } - }, { - key: "destroy", - value: function destroy() { - this.destroyed = true; - this.state.fill(0); - } - }, { - key: "_cloneInto", - value: function _cloneInto(to) { - var blockLen = this.blockLen, - suffix = this.suffix, - outputLen = this.outputLen, - rounds = this.rounds, - enableXOF = this.enableXOF; - to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds)); - to.state32.set(this.state32); - to.pos = this.pos; - to.posOut = this.posOut; - to.finished = this.finished; - to.rounds = rounds; - // Suffix can change in cSHAKE - to.suffix = suffix; - to.outputLen = outputLen; - to.enableXOF = enableXOF; - to.destroyed = this.destroyed; - return to; - } - }]); -}(Hash); -var gen = function gen(suffix, blockLen, outputLen) { - return wrapConstructor(function () { - return new Keccak(blockLen, suffix, outputLen); - }); -}; -/** - * keccak-256 hash function. Different from SHA3-256. - * @param message - that would be hashed - */ -var keccak_256 = /* @__PURE__ */gen(0x01, 136, 256 / 8); - -function keccak256(value, to_) { - var to = to_ || 'hex'; - var bytes = keccak_256(isHex(value, { - strict: false - }) ? toBytes$1(value) : value); - if (to === 'bytes') return bytes; - return toHex(bytes); -} - -var InvalidAddressError = /*#__PURE__*/function (_BaseError) { - function InvalidAddressError(_ref) { - var address = _ref.address; - _classCallCheck(this, InvalidAddressError); - return _callSuper(this, InvalidAddressError, ["Address \"".concat(address, "\" is invalid."), { - metaMessages: ['- Address must be a hex value of 20 bytes (40 hex characters).', '- Address must match its checksum counterpart.'], - name: 'InvalidAddressError' - }]); - } - _inherits(InvalidAddressError, _BaseError); - return _createClass(InvalidAddressError); -}(BaseError); - -/** - * Map with a LRU (Least recently used) policy. - * - * @link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU - */ -var LruMap = /*#__PURE__*/function (_Map) { - function LruMap(size) { - var _this; - _classCallCheck(this, LruMap); - _this = _callSuper(this, LruMap); - Object.defineProperty(_this, "maxSize", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - _this.maxSize = size; - return _this; - } - _inherits(LruMap, _Map); - return _createClass(LruMap, [{ - key: "get", - value: function get(key) { - var value = _superPropGet(LruMap, "get", this, 3)([key]); - if (_superPropGet(LruMap, "has", this, 3)([key]) && value !== undefined) { - this["delete"](key); - _superPropGet(LruMap, "set", this, 3)([key, value]); - } - return value; - } - }, { - key: "set", - value: function set(key, value) { - _superPropGet(LruMap, "set", this, 3)([key, value]); - if (this.maxSize && this.size > this.maxSize) { - var firstKey = this.keys().next().value; - if (firstKey) this["delete"](firstKey); - } - return this; - } - }]); -}(/*#__PURE__*/_wrapNativeSuper(Map)); - -var checksumAddressCache = /*#__PURE__*/new LruMap(8192); -function checksumAddress(address_, -/** - * Warning: EIP-1191 checksum addresses are generally not backwards compatible with the - * wider Ethereum ecosystem, meaning it will break when validated against an application/tool - * that relies on EIP-55 checksum encoding (checksum without chainId). - * - * It is highly recommended to not use this feature unless you - * know what you are doing. - * - * See more: https://github.com/ethereum/EIPs/issues/1121 - */ -chainId) { - if (checksumAddressCache.has("".concat(address_, ".").concat(chainId))) return checksumAddressCache.get("".concat(address_, ".").concat(chainId)); - var hexAddress = chainId ? "".concat(chainId).concat(address_.toLowerCase()) : address_.substring(2).toLowerCase(); - var hash = keccak256(stringToBytes(hexAddress), 'bytes'); - var address = (chainId ? hexAddress.substring("".concat(chainId, "0x").length) : hexAddress).split(''); - for (var i = 0; i < 40; i += 2) { - if (hash[i >> 1] >> 4 >= 8 && address[i]) { - address[i] = address[i].toUpperCase(); - } - if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) { - address[i + 1] = address[i + 1].toUpperCase(); - } - } - var result = "0x".concat(address.join('')); - checksumAddressCache.set("".concat(address_, ".").concat(chainId), result); - return result; -} - -var addressRegex = /^0x[a-fA-F0-9]{40}$/; -/** @internal */ -var isAddressCache = /*#__PURE__*/new LruMap(8192); -function isAddress(address, options) { - var _ref = options !== null && options !== void 0 ? options : {}, - _ref$strict = _ref.strict, - strict = _ref$strict === void 0 ? true : _ref$strict; - var cacheKey = "".concat(address, ".").concat(strict); - if (isAddressCache.has(cacheKey)) return isAddressCache.get(cacheKey); - var result = function () { - if (!addressRegex.test(address)) return false; - if (address.toLowerCase() === address) return true; - if (strict) return checksumAddress(address) === address; - return true; - }(); - isAddressCache.set(cacheKey, result); - return result; -} - -function concatHex(values) { - return "0x".concat(values.reduce(function (acc, x) { - return acc + x.replace('0x', ''); - }, '')); -} - -var arrayRegex = /^(.*)\[([0-9]*)\]$/; -// `bytes`: binary type of `M` bytes, `0 < M <= 32` -// https://regexr.com/6va55 -var bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/; -// `(u)int`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0` -// https://regexr.com/6v8hp -var integerRegex = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/; - -function encodePacked(types, values) { - if (types.length !== values.length) throw new AbiEncodingLengthMismatchError({ - expectedLength: types.length, - givenLength: values.length - }); - var data = []; - for (var i = 0; i < types.length; i++) { - var type = types[i]; - var value = values[i]; - data.push(encode(type, value)); - } - return concatHex(data); -} -function encode(type, value) { - var isArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - if (type === 'address') { - var address = value; - if (!isAddress(address)) throw new InvalidAddressError({ - address: address - }); - return pad(address.toLowerCase(), { - size: isArray ? 32 : null - }); - } - if (type === 'string') return stringToHex(value); - if (type === 'bytes') return value; - if (type === 'bool') return pad(boolToHex(value), { - size: isArray ? 32 : 1 - }); - var intMatch = type.match(integerRegex); - if (intMatch) { - var _intMatch = _slicedToArray(intMatch, 3); - _intMatch[0]; - var baseType = _intMatch[1], - _intMatch$ = _intMatch[2], - bits = _intMatch$ === void 0 ? '256' : _intMatch$; - var size = Number.parseInt(bits) / 8; - return numberToHex(value, { - size: isArray ? 32 : size, - signed: baseType === 'int' - }); - } - var bytesMatch = type.match(bytesRegex); - if (bytesMatch) { - var _bytesMatch = _slicedToArray(bytesMatch, 2); - _bytesMatch[0]; - var _size = _bytesMatch[1]; - if (Number.parseInt(_size) !== (value.length - 2) / 2) throw new BytesSizeMismatchError({ - expectedSize: Number.parseInt(_size), - givenSize: (value.length - 2) / 2 - }); - return pad(value, { - dir: 'right', - size: isArray ? 32 : null - }); - } - var arrayMatch = type.match(arrayRegex); - if (arrayMatch && Array.isArray(value)) { - var _arrayMatch = _slicedToArray(arrayMatch, 2); - _arrayMatch[0]; - var childType = _arrayMatch[1]; - var data = []; - for (var i = 0; i < value.length; i++) { - data.push(encode(childType, value[i], true)); - } - if (data.length === 0) return '0x'; - return concatHex(data); - } - throw new UnsupportedPackedAbiType(type); -} - -function isBytes(value) { - if (!value) return false; - if (_typeof(value) !== 'object') return false; - if (!('BYTES_PER_ELEMENT' in value)) return false; - return value.BYTES_PER_ELEMENT === 1 && value.constructor.name === 'Uint8Array'; -} - -function hashToField(input) { - if (isBytes(input) || isHex(input)) return hashEncodedBytes(input); - return hashString(input); -} -function packAndEncode(input) { - var _input$reduce = input.reduce(function (_ref, _ref2) { - var _ref3 = _slicedToArray(_ref, 2), - types2 = _ref3[0], - values2 = _ref3[1]; - var _ref4 = _slicedToArray(_ref2, 2), - type = _ref4[0], - value = _ref4[1]; - types2.push(type); - values2.push(value); - return [types2, values2]; - }, [[], []]), - _input$reduce2 = _slicedToArray(_input$reduce, 2), - types = _input$reduce2[0], - values = _input$reduce2[1]; - return hashEncodedBytes(encodePacked(types, values)); -} -function hashString(input) { - var bytesInput = buffer.Buffer.from(input); - return hashEncodedBytes(bytesInput); -} -function hashEncodedBytes(input) { - var hash = BigInt(keccak256(input)) >> 8n; - var rawDigest = hash.toString(16); - return { - hash: hash, - digest: "0x".concat(rawDigest.padStart(64, "0")) - }; -} -var generateSignal = function generateSignal(signal) { - if (!signal || typeof signal === "string") return hashToField(signal !== null && signal !== void 0 ? signal : ""); - return packAndEncode(signal.types.map(function (type, index) { - return [type, signal.values[index]]; - })); -}; -var encodeAction = function encodeAction(action) { - if (!action) return ""; - if (typeof action === "string") return action; - return action.types.map(function (type, index) { - return "".concat(type, "(").concat(action.values[index], ")"); - }).join(","); -}; - -var createStoreImpl = function createStoreImpl(createState) { - var state; - var listeners = /* @__PURE__ */new Set(); - var setState = function setState(partial, replace) { - var nextState = typeof partial === "function" ? partial(state) : partial; - if (!Object.is(nextState, state)) { - var previousState = state; - state = (replace != null ? replace : _typeof(nextState) !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState); - listeners.forEach(function (listener) { - return listener(state, previousState); - }); - } - }; - var getState = function getState() { - return state; - }; - var getInitialState = function getInitialState() { - return initialState; - }; - var subscribe = function subscribe(listener) { - listeners.add(listener); - return function () { - return listeners["delete"](listener); - }; - }; - var destroy = function destroy() { - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref) { - var _ref2 = _slicedToArray(_ref, 1), - k = _ref2[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production") { - console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."); - } - listeners.clear(); - }; - var api = { - setState: setState, - getState: getState, - getInitialState: getInitialState, - subscribe: subscribe, - destroy: destroy - }; - var initialState = state = createState(setState, getState, api); - return api; -}; -var createStore = function createStore(createState) { - return createState ? createStoreImpl(createState) : createStoreImpl; -}; - -var ReactExports = {}; - -var emptyModule = /*#__PURE__*/Object.freeze({ - __proto__: null, - 'default': ReactExports -}); - -var withSelector = {exports: {}}; - -var require$$0 = /*@__PURE__*/getAugmentedNamespace(emptyModule); - -var shim = {exports: {}}; - -var useSyncExternalStoreShim_development = {}; - -var hasRequiredUseSyncExternalStoreShim_development; -function requireUseSyncExternalStoreShim_development() { - if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development; - hasRequiredUseSyncExternalStoreShim_development = 1; - { - (function () { - - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); - } - var React = require$$0; - var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; - function error(format) { - { - { - for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; - } - printWarning('error', format, args); - } - } - } - function printWarning(level, format, args) { - // When changing this logic, you might want to also - // update consoleWithStackDev.www.js as well. - { - var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - var stack = ReactDebugCurrentFrame.getStackAddendum(); - if (stack !== '') { - format += '%s'; - args = args.concat([stack]); - } // eslint-disable-next-line react-internal/safe-string-coercion - - var argsWithFormat = args.map(function (item) { - return String(item); - }); // Careful: RN currently depends on this prefix - - argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it - // breaks IE9: https://github.com/facebook/react/issues/13610 - // eslint-disable-next-line react-internal/no-production-logging - - Function.prototype.apply.call(console[level], console, argsWithFormat); - } - } - - /** - * inlined Object.is polyfill to avoid requiring consumers ship their own - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - */ - function is(x, y) { - return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare - ; - } - var objectIs = typeof Object.is === 'function' ? Object.is : is; - - // dispatch for CommonJS interop named imports. - - var useState = React.useState, - useEffect = React.useEffect, - useLayoutEffect = React.useLayoutEffect, - useDebugValue = React.useDebugValue; - var didWarnOld18Alpha = false; - var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works - // because of a very particular set of implementation details and assumptions - // -- change any one of them and it will break. The most important assumption - // is that updates are always synchronous, because concurrent rendering is - // only available in versions of React that also have a built-in - // useSyncExternalStore API. And we only use this shim when the built-in API - // does not exist. - // - // Do not assume that the clever hacks used by this hook also work in general. - // The point of this shim is to replace the need for hacks by other libraries. - - function useSyncExternalStore(subscribe, getSnapshot, - // Note: The shim does not use getServerSnapshot, because pre-18 versions of - // React do not expose a way to check if we're hydrating. So users of the shim - // will need to track that themselves and return the correct value - // from `getSnapshot`. - getServerSnapshot) { - { - if (!didWarnOld18Alpha) { - if (React.startTransition !== undefined) { - didWarnOld18Alpha = true; - error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.'); - } - } - } // Read the current snapshot from the store on every render. Again, this - // breaks the rules of React, and only works here because of specific - // implementation details, most importantly that updates are - // always synchronous. - - var value = getSnapshot(); - { - if (!didWarnUncachedGetSnapshot) { - var cachedValue = getSnapshot(); - if (!objectIs(value, cachedValue)) { - error('The result of getSnapshot should be cached to avoid an infinite loop'); - didWarnUncachedGetSnapshot = true; - } - } - } // Because updates are synchronous, we don't queue them. Instead we force a - // re-render whenever the subscribed state changes by updating an some - // arbitrary useState hook. Then, during render, we call getSnapshot to read - // the current value. - // - // Because we don't actually use the state returned by the useState hook, we - // can save a bit of memory by storing other stuff in that slot. - // - // To implement the early bailout, we need to track some things on a mutable - // object. Usually, we would put that in a useRef hook, but we can stash it in - // our useState hook instead. - // - // To force a re-render, we call forceUpdate({inst}). That works because the - // new object always fails an equality check. - - var _useState = useState({ - inst: { - value: value, - getSnapshot: getSnapshot - } - }), - inst = _useState[0].inst, - forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated - // in the layout phase so we can access it during the tearing check that - // happens on subscribe. - - useLayoutEffect(function () { - inst.value = value; - inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the - // commit phase if there was an interleaved mutation. In concurrent mode - // this can happen all the time, but even in synchronous mode, an earlier - // effect may have mutated the store. - - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - }, [subscribe, value, getSnapshot]); - useEffect(function () { - // Check for changes right before subscribing. Subsequent changes will be - // detected in the subscription handler. - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - var handleStoreChange = function handleStoreChange() { - // TODO: Because there is no cross-renderer API for batching updates, it's - // up to the consumer of this library to wrap their subscription event - // with unstable_batchedUpdates. Should we try to detect when this isn't - // the case and print a warning in development? - // The store changed. Check if the snapshot changed since the last time we - // read from the store. - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - }; // Subscribe to the store and return a clean-up function. - - return subscribe(handleStoreChange); - }, [subscribe]); - useDebugValue(value); - return value; - } - function checkIfSnapshotChanged(inst) { - var latestGetSnapshot = inst.getSnapshot; - var prevValue = inst.value; - try { - var nextValue = latestGetSnapshot(); - return !objectIs(prevValue, nextValue); - } catch (error) { - return true; - } - } - function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) { - // Note: The shim does not use getServerSnapshot, because pre-18 versions of - // React do not expose a way to check if we're hydrating. So users of the shim - // will need to track that themselves and return the correct value - // from `getSnapshot`. - return getSnapshot(); - } - var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); - var isServerEnvironment = !canUseDOM; - var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore; - var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; - useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2; - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); - } - })(); - } - return useSyncExternalStoreShim_development; -} - -var hasRequiredShim; -function requireShim() { - if (hasRequiredShim) return shim.exports; - hasRequiredShim = 1; - (function (module) { - - { - module.exports = requireUseSyncExternalStoreShim_development(); - } - })(shim); - return shim.exports; -} - -var withSelector_development = {}; - -var hasRequiredWithSelector_development; -function requireWithSelector_development() { - if (hasRequiredWithSelector_development) return withSelector_development; - hasRequiredWithSelector_development = 1; - { - (function () { - - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); - } - var React = require$$0; - var shim = requireShim(); - - /** - * inlined Object.is polyfill to avoid requiring consumers ship their own - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - */ - function is(x, y) { - return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare - ; - } - var objectIs = typeof Object.is === 'function' ? Object.is : is; - var useSyncExternalStore = shim.useSyncExternalStore; - - // for CommonJS interop. - - var useRef = React.useRef, - useEffect = React.useEffect, - useMemo = React.useMemo, - useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. - - function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { - // Use this to track the rendered snapshot. - var instRef = useRef(null); - var inst; - if (instRef.current === null) { - inst = { - hasValue: false, - value: null - }; - instRef.current = inst; - } else { - inst = instRef.current; - } - var _useMemo = useMemo(function () { - // Track the memoized state using closure variables that are local to this - // memoized instance of a getSnapshot function. Intentionally not using a - // useRef hook, because that state would be shared across all concurrent - // copies of the hook/component. - var hasMemo = false; - var memoizedSnapshot; - var memoizedSelection; - var memoizedSelector = function memoizedSelector(nextSnapshot) { - if (!hasMemo) { - // The first time the hook is called, there is no memoized result. - hasMemo = true; - memoizedSnapshot = nextSnapshot; - var _nextSelection = selector(nextSnapshot); - if (isEqual !== undefined) { - // Even if the selector has changed, the currently rendered selection - // may be equal to the new selection. We should attempt to reuse the - // current value if possible, to preserve downstream memoizations. - if (inst.hasValue) { - var currentSelection = inst.value; - if (isEqual(currentSelection, _nextSelection)) { - memoizedSelection = currentSelection; - return currentSelection; - } - } - } - memoizedSelection = _nextSelection; - return _nextSelection; - } // We may be able to reuse the previous invocation's result. - - // We may be able to reuse the previous invocation's result. - var prevSnapshot = memoizedSnapshot; - var prevSelection = memoizedSelection; - if (objectIs(prevSnapshot, nextSnapshot)) { - // The snapshot is the same as last time. Reuse the previous selection. - return prevSelection; - } // The snapshot has changed, so we need to compute a new selection. - - // The snapshot has changed, so we need to compute a new selection. - var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data - // has changed. If it hasn't, return the previous selection. That signals - // to React that the selections are conceptually equal, and we can bail - // out of rendering. - - // If a custom isEqual function is provided, use that to check if the data - // has changed. If it hasn't, return the previous selection. That signals - // to React that the selections are conceptually equal, and we can bail - // out of rendering. - if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { - return prevSelection; - } - memoizedSnapshot = nextSnapshot; - memoizedSelection = nextSelection; - return nextSelection; - }; // Assigning this to a constant so that Flow knows it can't change. - - // Assigning this to a constant so that Flow knows it can't change. - var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; - var getSnapshotWithSelector = function getSnapshotWithSelector() { - return memoizedSelector(getSnapshot()); - }; - var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () { - return memoizedSelector(maybeGetServerSnapshot()); - }; - return [getSnapshotWithSelector, getServerSnapshotWithSelector]; - }, [getSnapshot, getServerSnapshot, selector, isEqual]), - getSelection = _useMemo[0], - getServerSelection = _useMemo[1]; - var value = useSyncExternalStore(subscribe, getSelection, getServerSelection); - useEffect(function () { - inst.hasValue = true; - inst.value = value; - }, [value]); - useDebugValue(value); - return value; - } - withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); - } - })(); - } - return withSelector_development; -} - -(function (module) { - - { - module.exports = requireWithSelector_development(); - } -})(withSelector); -var useSyncExternalStoreExports = /*@__PURE__*/getDefaultExportFromCjs(withSelector.exports); - -var useDebugValue = ReactExports.useDebugValue; -var useSyncExternalStoreWithSelector = useSyncExternalStoreExports.useSyncExternalStoreWithSelector; -var didWarnAboutEqualityFn = false; -var identity = function identity(arg) { - return arg; -}; -function useStore(api) { - var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity; - var equalityFn = arguments.length > 2 ? arguments[2] : undefined; - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref) { - var _ref2 = _slicedToArray(_ref, 1), - k = _ref2[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) { - console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"); - didWarnAboutEqualityFn = true; - } - var slice = useSyncExternalStoreWithSelector(api.subscribe, api.getState, api.getServerState || api.getInitialState, selector, equalityFn); - useDebugValue(slice); - return slice; -} -var createImpl = function createImpl(createState) { - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref3) { - var _ref4 = _slicedToArray(_ref3, 1), - k = _ref4[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production" && typeof createState !== "function") { - console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."); - } - var api = typeof createState === "function" ? createStore(createState) : createState; - var useBoundStore = function useBoundStore(selector, equalityFn) { - return useStore(api, selector, equalityFn); - }; - Object.assign(useBoundStore, api); - return useBoundStore; -}; -var create = function create(createState) { - return createState ? createImpl(createState) : createImpl; -}; - -// src/types/bridge.ts -var AppErrorCodes = /* @__PURE__ */function (AppErrorCodes2) { - AppErrorCodes2["ConnectionFailed"] = "connection_failed"; - AppErrorCodes2["VerificationRejected"] = "verification_rejected"; - AppErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached"; - AppErrorCodes2["CredentialUnavailable"] = "credential_unavailable"; - AppErrorCodes2["MalformedRequest"] = "malformed_request"; - AppErrorCodes2["InvalidNetwork"] = "invalid_network"; - AppErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed"; - AppErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending"; - AppErrorCodes2["UnexpectedResponse"] = "unexpected_response"; - AppErrorCodes2["FailedByHostApp"] = "failed_by_host_app"; - AppErrorCodes2["GenericError"] = "generic_error"; - return AppErrorCodes2; -}(AppErrorCodes || {}); -var VerificationLevel = /* @__PURE__ */function (VerificationLevel2) { - VerificationLevel2["Orb"] = "orb"; - VerificationLevel2["Device"] = "device"; - return VerificationLevel2; -}(VerificationLevel || {}); - -// src/lib/validation.ts -function validate_bridge_url(bridge_url, is_staging) { - try { - new URL(bridge_url); - } catch (e) { - return { - valid: false, - errors: ["Failed to parse Bridge URL."] - }; - } - var test_url = new URL(bridge_url); - var errors = []; - if (is_staging && ["localhost", "127.0.0.1"].includes(test_url.hostname)) { - console.log("Using staging app_id with localhost bridge_url. Skipping validation."); - return { - valid: true - }; - } - if (test_url.protocol !== "https:") { - errors.push("Bridge URL must use HTTPS."); - } - if (test_url.port) { - errors.push("Bridge URL must use the default port (443)."); - } - if (test_url.pathname !== "/") { - errors.push("Bridge URL must not have a path."); - } - if (test_url.search) { - errors.push("Bridge URL must not have query parameters."); - } - if (test_url.hash) { - errors.push("Bridge URL must not have a fragment."); - } - if (!test_url.hostname.endsWith(".worldcoin.org") && !test_url.hostname.endsWith(".toolsforhumanity.com")) { - console.warn("Bridge URL should be a subdomain of worldcoin.org or toolsforhumanity.com. The user's identity wallet may refuse to connect. This is a temporary measure and may be removed in the future."); - } - if (errors.length) { - return { - valid: false, - errors: errors - }; - } - return { - valid: true - }; -} -var DEFAULT_VERIFICATION_LEVEL = "orb" /* Orb */; -var buffer_encode = function buffer_encode(buffer$1) { - return buffer.Buffer.from(buffer$1).toString("base64"); -}; -var buffer_decode = function buffer_decode(encoded) { - return buffer.Buffer.from(encoded, "base64"); -}; -var verification_level_to_credential_types = function verification_level_to_credential_types(verification_level) { - switch (verification_level) { - case "device" /* Device */: - return ["orb" /* Orb */, "device" /* Device */]; - case "orb" /* Orb */: - return ["orb" /* Orb */]; - default: - throw new Error("Unknown verification level: ".concat(verification_level)); - } -}; -var credential_type_to_verification_level = function credential_type_to_verification_level(credential_type) { - switch (credential_type) { - case "orb" /* Orb */: - return "orb" /* Orb */; - case "device" /* Device */: - return "device" /* Device */; - default: - throw new Error("Unknown credential_type: ".concat(credential_type)); - } -}; - -// src/lib/crypto.ts -var encoder = new TextEncoder(); -var decoder = new TextDecoder(); -var generateKey = /*#__PURE__*/function () { - var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { - return _regeneratorRuntime().wrap(function _callee$(_context) { - while (1) switch (_context.prev = _context.next) { - case 0: - _context.t0 = window.crypto.getRandomValues(new Uint8Array(12)); - _context.next = 3; - return window.crypto.subtle.generateKey({ - name: "AES-GCM", - length: 256 - }, true, ["encrypt", "decrypt"]); - case 3: - _context.t1 = _context.sent; - return _context.abrupt("return", { - iv: _context.t0, - key: _context.t1 - }); - case 5: - case "end": - return _context.stop(); - } - }, _callee); - })); - return function generateKey() { - return _ref.apply(this, arguments); - }; -}(); -var exportKey = /*#__PURE__*/function () { - var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) { - return _regeneratorRuntime().wrap(function _callee2$(_context2) { - while (1) switch (_context2.prev = _context2.next) { - case 0: - _context2.t0 = buffer_encode; - _context2.next = 3; - return window.crypto.subtle.exportKey("raw", key); - case 3: - _context2.t1 = _context2.sent; - return _context2.abrupt("return", (0, _context2.t0)(_context2.t1)); - case 5: - case "end": - return _context2.stop(); - } - }, _callee2); - })); - return function exportKey(_x) { - return _ref2.apply(this, arguments); - }; -}(); -var encryptRequest = /*#__PURE__*/function () { - var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, iv, request) { - return _regeneratorRuntime().wrap(function _callee3$(_context3) { - while (1) switch (_context3.prev = _context3.next) { - case 0: - _context3.t0 = buffer_encode(iv); - _context3.t1 = buffer_encode; - _context3.next = 4; - return window.crypto.subtle.encrypt({ - name: "AES-GCM", - iv: iv - }, key, encoder.encode(request)); - case 4: - _context3.t2 = _context3.sent; - _context3.t3 = (0, _context3.t1)(_context3.t2); - return _context3.abrupt("return", { - iv: _context3.t0, - payload: _context3.t3 - }); - case 7: - case "end": - return _context3.stop(); - } - }, _callee3); - })); - return function encryptRequest(_x2, _x3, _x4) { - return _ref3.apply(this, arguments); - }; -}(); -var decryptResponse = /*#__PURE__*/function () { - var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, iv, payload) { - return _regeneratorRuntime().wrap(function _callee4$(_context4) { - while (1) switch (_context4.prev = _context4.next) { - case 0: - _context4.t0 = decoder; - _context4.next = 3; - return window.crypto.subtle.decrypt({ - name: "AES-GCM", - iv: iv - }, key, buffer_decode(payload)); - case 3: - _context4.t1 = _context4.sent; - return _context4.abrupt("return", _context4.t0.decode.call(_context4.t0, _context4.t1)); - case 5: - case "end": - return _context4.stop(); - } - }, _callee4); - })); - return function decryptResponse(_x5, _x6, _x7) { - return _ref4.apply(this, arguments); - }; -}(); - -// src/bridge.ts -var DEFAULT_BRIDGE_URL = "https://bridge.worldcoin.org"; -create(function (set, get) { - return { - iv: null, - key: null, - result: null, - errorCode: null, - requestId: null, - connectorURI: null, - bridge_url: DEFAULT_BRIDGE_URL, - verificationState: "loading_widget" /* PreparingClient */, - createClient: function () { - var _createClient = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) { - var bridge_url, app_id, verification_level, action_description, action, signal, _yield$generateKey, key, iv, validation, res, _yield$res$json, request_id; - return _regeneratorRuntime().wrap(function _callee5$(_context5) { - while (1) switch (_context5.prev = _context5.next) { - case 0: - bridge_url = _ref5.bridge_url, app_id = _ref5.app_id, verification_level = _ref5.verification_level, action_description = _ref5.action_description, action = _ref5.action, signal = _ref5.signal; - _context5.next = 3; - return generateKey(); - case 3: - _yield$generateKey = _context5.sent; - key = _yield$generateKey.key; - iv = _yield$generateKey.iv; - if (!bridge_url) { - _context5.next = 12; - break; - } - validation = validate_bridge_url(bridge_url, app_id.includes("staging")); - if (validation.valid) { - _context5.next = 12; - break; - } - console.error(validation.errors.join("\n")); - set({ - verificationState: "failed" /* Failed */ - }); - throw new Error("Invalid bridge_url. Please check the console for more details."); - case 12: - _context5.t0 = fetch; - _context5.t1 = new URL("/request", bridge_url !== null && bridge_url !== void 0 ? bridge_url : DEFAULT_BRIDGE_URL); - _context5.t2 = { - "Content-Type": "application/json" - }; - _context5.t3 = JSON; - _context5.next = 18; - return encryptRequest(key, iv, JSON.stringify({ - app_id: app_id, - action_description: action_description, - action: encodeAction(action), - signal: generateSignal(signal).digest, - credential_types: verification_level_to_credential_types(verification_level !== null && verification_level !== void 0 ? verification_level : DEFAULT_VERIFICATION_LEVEL), - verification_level: verification_level !== null && verification_level !== void 0 ? verification_level : DEFAULT_VERIFICATION_LEVEL - })); - case 18: - _context5.t4 = _context5.sent; - _context5.t5 = _context5.t3.stringify.call(_context5.t3, _context5.t4); - _context5.t6 = { - method: "POST", - headers: _context5.t2, - body: _context5.t5 - }; - _context5.next = 23; - return (0, _context5.t0)(_context5.t1, _context5.t6); - case 23: - res = _context5.sent; - if (res.ok) { - _context5.next = 27; - break; - } - set({ - verificationState: "failed" /* Failed */ - }); - throw new Error("Failed to create client"); - case 27: - _context5.next = 29; - return res.json(); - case 29: - _yield$res$json = _context5.sent; - request_id = _yield$res$json.request_id; - _context5.t7 = set; - _context5.t8 = iv; - _context5.t9 = key; - _context5.t10 = request_id; - _context5.t11 = bridge_url !== null && bridge_url !== void 0 ? bridge_url : DEFAULT_BRIDGE_URL; - _context5.t12 = "https://worldcoin.org/verify?t=wld&i=".concat(request_id, "&k="); - _context5.t13 = encodeURIComponent; - _context5.next = 40; - return exportKey(key); - case 40: - _context5.t14 = _context5.sent; - _context5.t15 = (0, _context5.t13)(_context5.t14); - _context5.t16 = _context5.t12.concat.call(_context5.t12, _context5.t15).concat(bridge_url && bridge_url !== DEFAULT_BRIDGE_URL ? "&b=".concat(encodeURIComponent(bridge_url)) : ""); - _context5.t17 = { - iv: _context5.t8, - key: _context5.t9, - requestId: _context5.t10, - bridge_url: _context5.t11, - verificationState: "awaiting_connection", - connectorURI: _context5.t16 - }; - (0, _context5.t7)(_context5.t17); - case 45: - case "end": - return _context5.stop(); - } - }, _callee5); - })); - function createClient(_x8) { - return _createClient.apply(this, arguments); - } - return createClient; - }(), - pollForUpdates: function () { - var _pollForUpdates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() { - var key, res, _yield$res$json2, response, status, result; - return _regeneratorRuntime().wrap(function _callee6$(_context6) { - while (1) switch (_context6.prev = _context6.next) { - case 0: - key = get().key; - if (key) { - _context6.next = 3; - break; - } - throw new Error("No keypair found. Please call `createClient` first."); - case 3: - _context6.next = 5; - return fetch(new URL("/response/".concat(get().requestId), get().bridge_url)); - case 5: - res = _context6.sent; - if (res.ok) { - _context6.next = 8; - break; - } - return _context6.abrupt("return", set({ - errorCode: "connection_failed" /* ConnectionFailed */, - verificationState: "failed" /* Failed */ - })); - case 8: - _context6.next = 10; - return res.json(); - case 10: - _yield$res$json2 = _context6.sent; - response = _yield$res$json2.response; - status = _yield$res$json2.status; - if (!(status != "completed" /* Completed */)) { - _context6.next = 15; - break; - } - return _context6.abrupt("return", set({ - verificationState: status == "retrieved" /* Retrieved */ ? "awaiting_app" /* WaitingForApp */ : "awaiting_connection" /* WaitingForConnection */ - })); - case 15: - _context6.t0 = JSON; - _context6.next = 18; - return decryptResponse(key, buffer_decode(response.iv), response.payload); - case 18: - _context6.t1 = _context6.sent; - result = _context6.t0.parse.call(_context6.t0, _context6.t1); - if (!("error_code" in result)) { - _context6.next = 22; - break; - } - return _context6.abrupt("return", set({ - errorCode: result.error_code, - verificationState: "failed" /* Failed */ - })); - case 22: - if ("credential_type" in result) { - result = _objectSpread2({ - verification_level: credential_type_to_verification_level(result.credential_type) - }, result); - } - set({ - result: result, - key: null, - requestId: null, - connectorURI: null, - verificationState: "confirmed" /* Confirmed */ - }); - case 24: - case "end": - return _context6.stop(); - } - }, _callee6); - })); - function pollForUpdates() { - return _pollForUpdates.apply(this, arguments); - } - return pollForUpdates; - }(), - reset: function reset() { - set({ - iv: null, - key: null, - result: null, - errorCode: null, - requestId: null, - connectorURI: null, - verificationState: "loading_widget" /* PreparingClient */ - }); - } - }; -}); - -var _VerificationErrorMes; -(_VerificationErrorMes = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_VerificationErrorMes, AppErrorCodes.VerificationRejected, "You\u2019ve cancelled the request in World App."), AppErrorCodes.MaxVerificationsReached, "You have already verified the maximum number of times for this action."), AppErrorCodes.CredentialUnavailable, "It seems you do not have the verification level required by this app."), AppErrorCodes.MalformedRequest, "There was a problem with this request. Please try again or contact the app owner."), AppErrorCodes.InvalidNetwork, "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details."), AppErrorCodes.InclusionProofFailed, "There was an issue fetching your credential. Please try again."), AppErrorCodes.InclusionProofPending, "Your identity is still being registered. Please wait a few minutes and try again."), AppErrorCodes.UnexpectedResponse, "Unexpected response from your wallet. Please try again."), AppErrorCodes.FailedByHostApp, "Verification failed by the app. Please contact the app owner for details."), AppErrorCodes.GenericError, "Something unexpected went wrong. Please try again."), _defineProperty(_VerificationErrorMes, AppErrorCodes.ConnectionFailed, "Connection to your wallet failed. Please try again.")); -_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "input_error" /* InputError */, "There was a problem with this request. Please try again or contact the app owner."), "payment_rejected" /* PaymentRejected */, "You\u2019ve cancelled the payment in World App."), "invalid_receiver" /* InvalidReceiver */, "The receiver address is invalid. Please contact the app owner."), "insufficient_balance" /* InsufficientBalance */, "You do not have enough balance to complete this transaction."), "transaction_failed" /* TransactionFailed */, "The transaction failed. Please try again."), "generic_error" /* GenericError */, "Something unexpected went wrong. Please try again."), "user_blocked" /* UserBlocked */, "User's region is blocked from making payments."); -_defineProperty(_defineProperty(_defineProperty({}, "malformed_request" /* MalformedRequest */, "Provided parameters in the request are invalid."), "user_rejected" /* UserRejected */, "User rejected the request."), "generic_error" /* GenericError */, "Something unexpected went wrong."); -_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "invalid_operation" /* InvalidOperation */, "Transaction included an operation that was invalid"), "user_rejected" /* UserRejected */, "User rejected the request."), "input_error" /* InputError */, "Invalid payload."), "simulation_failed" /* SimulationFailed */, "The transaction simulation failed."), "transaction_failed" /* TransactionFailed */, "The transaction failed. Please try again later."), "generic_error" /* GenericError */, "Something unexpected went wrong. Please try again."), "disallowed_operation" /* DisallowedOperation */, "The operation requested is not allowed. Please refer to the docs."), "invalid_contract" /* InvalidContract */, "The contract address is not allowed for your application. Please check your developer portal configurations"), "malicious_operation" /* MaliciousOperation */, "The operation requested is considered malicious."); -_defineProperty(_defineProperty(_defineProperty({}, "invalid_message" /* InvalidMessage */, "Invalid message requested"), "user_rejected" /* UserRejected */, "User rejected the request."), "generic_error" /* GenericError */, "Something unexpected went wrong."); -var MiniKitInstallErrorMessage = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "unknown" /* Unknown */, "Failed to install MiniKit."), "already_installed" /* AlreadyInstalled */, "MiniKit is already installed."), "outside_of_worldapp" /* OutsideOfWorldApp */, "MiniApp launched outside of WorldApp."), "not_on_client" /* NotOnClient */, "Window object is not available."), "app_out_of_date" /* AppOutOfDate */, "WorldApp is out of date. Please update the app."); - -// helpers/send-webview-event.ts -var sendWebviewEvent = function sendWebviewEvent(payload) { - if (window.webkit) { - var _window$webkit, _window$webkit$postMe; - (_window$webkit = window.webkit) === null || _window$webkit === void 0 || (_window$webkit = _window$webkit.messageHandlers) === null || _window$webkit === void 0 || (_window$webkit = _window$webkit.minikit) === null || _window$webkit === void 0 || (_window$webkit$postMe = _window$webkit.postMessage) === null || _window$webkit$postMe === void 0 || _window$webkit$postMe.call(_window$webkit, payload); - } else if (window.Android) { - var _window$Android$postM, _window$Android; - (_window$Android$postM = (_window$Android = window.Android).postMessage) === null || _window$Android$postM === void 0 || _window$Android$postM.call(_window$Android, JSON.stringify(payload)); - } -}; - -// types/responses.ts -var ResponseEvent = /* @__PURE__ */function (ResponseEvent2) { - ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action"; - ResponseEvent2["MiniAppPayment"] = "miniapp-payment"; - ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth"; - ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction"; - ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message"; - ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data"; - return ResponseEvent2; -}(ResponseEvent || {}); -_defineProperty(_defineProperty({}, "USDCE" /* USDCE */, 6), "WLD" /* WLD */, 18); - -// helpers/siwe/validate-wallet-auth-command-input.ts -var validateWalletAuthCommandInput = function validateWalletAuthCommandInput(params) { - if (!params.nonce) { - return { - valid: false, - message: "'nonce' is required" - }; - } - if (params.nonce.length < 8) { - return { - valid: false, - message: "'nonce' must be at least 8 characters" - }; - } - if (params.statement && params.statement.includes("\n")) { - return { - valid: false, - message: "'statement' must not contain newlines" - }; - } - if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */new Date()) { - return { - valid: false, - message: "'expirationTime' must be in the future" - }; - } - if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) { - return { - valid: false, - message: "'expirationTime' must be within 7 days" - }; - } - if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) { - return { - valid: false, - message: "'notBefore' must be within 7 days" - }; - } - return { - valid: true - }; -}; -var generateSiweMessage = function generateSiweMessage(siweMessageData) { - var siweMessage = ""; - if (siweMessageData.scheme) { - siweMessage += "".concat(siweMessageData.scheme, "://").concat(siweMessageData.domain, " wants you to sign in with your Ethereum account:\n"); - } else { - siweMessage += "".concat(siweMessageData.domain, " wants you to sign in with your Ethereum account:\n"); - } - if (siweMessageData.address) { - siweMessage += "".concat(siweMessageData.address, "\n"); - } else { - siweMessage += "{address}\n"; - } - siweMessage += "\n"; - if (siweMessageData.statement) { - siweMessage += "".concat(siweMessageData.statement, "\n"); - } - siweMessage += "\n"; - siweMessage += "URI: ".concat(siweMessageData.uri, "\n"); - siweMessage += "Version: ".concat(siweMessageData.version, "\n"); - siweMessage += "Chain ID: ".concat(siweMessageData.chain_id, "\n"); - siweMessage += "Nonce: ".concat(siweMessageData.nonce, "\n"); - siweMessage += "Issued At: ".concat(siweMessageData.issued_at, "\n"); - if (siweMessageData.expiration_time) { - siweMessage += "Expiration Time: ".concat(siweMessageData.expiration_time, "\n"); - } - if (siweMessageData.not_before) { - siweMessage += "Not Before: ".concat(siweMessageData.not_before, "\n"); - } - if (siweMessageData.request_id) { - siweMessage += "Request ID: ".concat(siweMessageData.request_id, "\n"); - } - return siweMessage; -}; -var validatePaymentPayload = function validatePaymentPayload(payload) { - if (payload.tokens.some(function (token) { - return token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1; - })) { - console.error("USDCE amount should be greater than $0.1"); - return false; - } - if (payload.reference.length > 36) { - console.error("Reference must not exceed 36 characters"); - return false; - } - return true; -}; - -// minikit.ts -var sendMiniKitEvent = function sendMiniKitEvent(payload) { - sendWebviewEvent(payload); -}; -var _MiniKit = /*#__PURE__*/function () { - function _MiniKit() { - _classCallCheck(this, _MiniKit); - } - return _createClass(_MiniKit, null, [{ - key: "sendInit", - value: function sendInit() { - sendWebviewEvent({ - command: "init", - payload: { - version: this.MINIKIT_VERSION - } - }); - } - }, { - key: "subscribe", - value: function subscribe(event, handler) { - if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) { - var originalHandler = handler; - var wrappedHandler = function wrappedHandler(payload) { - if (payload.status === "success") { - _MiniKit.walletAddress = payload.address; - } - originalHandler(payload); - }; - this.listeners[event] = wrappedHandler; - } else { - this.listeners[event] = handler; - } - } - }, { - key: "unsubscribe", - value: function unsubscribe(event) { - delete this.listeners[event]; - } - }, { - key: "trigger", - value: function trigger(event, payload) { - if (!this.listeners[event]) { - console.error("No handler for event ".concat(event)); - return; - } - this.listeners[event](payload); - } - }, { - key: "commandsValid", - value: function commandsValid(input) { - var _this = this; - return input.every(function (command) { - return command.supported_versions.includes(_this.commandVersion[command.name]); - }); - } - }, { - key: "install", - value: function install() { - if (typeof window === "undefined" || Boolean(window.MiniKit)) { - return { - success: false, - errorCode: "already_installed" /* AlreadyInstalled */, - errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */] - }; - } - if (!window.WorldApp) { - return { - success: false, - errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */, - errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */] - }; - } - if (!this.commandsValid(window.WorldApp.supported_commands)) { - return { - success: false, - errorCode: "app_out_of_date" /* AppOutOfDate */, - errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */] - }; - } - try { - window.MiniKit = _MiniKit; - this.sendInit(); - } catch (error) { - console.error(MiniKitInstallErrorMessage["unknown" /* Unknown */], error); - return { - success: false, - errorCode: "unknown" /* Unknown */, - errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */] - }; - } - return { - success: true - }; - } - }, { - key: "isInstalled", - value: function isInstalled(debug) { - if (debug) console.log("MiniKit is alive!"); - return Boolean(window.MiniKit); - } - }]); -}(); -_MiniKit.MINIKIT_VERSION = 1; -_MiniKit.commandVersion = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "verify" /* Verify */, 1), "pay" /* Pay */, 1), "wallet-auth" /* WalletAuth */, 1), "send-transaction" /* SendTransaction */, 1), "sign-message" /* SignMessage */, 1), "sign-typed-data" /* SignTypedData */, 1); -_MiniKit.listeners = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "miniapp-verify-action" /* MiniAppVerifyAction */, function miniappVerifyAction() {}), "miniapp-payment" /* MiniAppPayment */, function miniappPayment() {}), "miniapp-wallet-auth" /* MiniAppWalletAuth */, function miniappWalletAuth() {}), "miniapp-send-transaction" /* MiniAppSendTransaction */, function miniappSendTransaction() {}), "miniapp-sign-message" /* MiniAppSignMessage */, function miniappSignMessage() {}), "miniapp-sign-typed-data" /* MiniAppSignTypedData */, function miniappSignTypedData() {}); -_MiniKit.walletAddress = null; -_MiniKit.commands = { - verify: function verify(payload) { - var timestamp = (/* @__PURE__ */new Date()).toISOString(); - var eventPayload = _objectSpread2(_objectSpread2({}, payload), {}, { - signal: payload.signal || "", - verification_level: payload.verification_level || VerificationLevel.Orb, - timestamp: timestamp - }); - sendMiniKitEvent({ - command: "verify" /* Verify */, - version: _MiniKit.commandVersion["verify" /* Verify */], - payload: eventPayload - }); - return eventPayload; - }, - pay: function pay(payload) { - if (typeof window === "undefined") { - console.error("'pay' method is only available in a browser environment."); - return null; - } - if (!validatePaymentPayload(payload)) { - return null; - } - var network = "optimism" /* Optimism */; - var eventPayload = _objectSpread2(_objectSpread2({}, payload), {}, { - network: network - }); - sendMiniKitEvent({ - command: "pay" /* Pay */, - version: _MiniKit.commandVersion["pay" /* Pay */], - payload: eventPayload - }); - return eventPayload; - }, - walletAuth: function walletAuth(payload) { - var _payload$statement, _payload$expirationTi, _payload$expirationTi2, _payload$notBefore$to, _payload$notBefore, _payload$requestId; - if (typeof window === "undefined") { - console.error("'walletAuth' method is only available in a browser environment."); - return null; - } - var validationResult = validateWalletAuthCommandInput(payload); - if (!validationResult.valid) { - console.error("Failed to validate wallet auth input:\n\n -->", validationResult.message); - return null; - } - var protocol = null; - try { - var currentUrl = new URL(window.location.href); - protocol = currentUrl.protocol.split(":")[0]; - } catch (error) { - console.error("Failed to get current URL", error); - return null; - } - var siweMessage = generateSiweMessage({ - scheme: protocol, - domain: window.location.host, - statement: (_payload$statement = payload.statement) !== null && _payload$statement !== void 0 ? _payload$statement : void 0, - uri: window.location.href, - version: 1, - chain_id: 10, - nonce: payload.nonce, - issued_at: (/* @__PURE__ */new Date()).toISOString(), - expiration_time: (_payload$expirationTi = (_payload$expirationTi2 = payload.expirationTime) === null || _payload$expirationTi2 === void 0 ? void 0 : _payload$expirationTi2.toISOString()) !== null && _payload$expirationTi !== void 0 ? _payload$expirationTi : void 0, - not_before: (_payload$notBefore$to = (_payload$notBefore = payload.notBefore) === null || _payload$notBefore === void 0 ? void 0 : _payload$notBefore.toISOString()) !== null && _payload$notBefore$to !== void 0 ? _payload$notBefore$to : void 0, - request_id: (_payload$requestId = payload.requestId) !== null && _payload$requestId !== void 0 ? _payload$requestId : void 0 - }); - var walletAuthPayload = { - siweMessage: siweMessage - }; - sendMiniKitEvent({ - command: "wallet-auth" /* WalletAuth */, - version: _MiniKit.commandVersion["wallet-auth" /* WalletAuth */], - payload: walletAuthPayload - }); - return walletAuthPayload; - }, - sendTransaction: function sendTransaction(payload) { - sendMiniKitEvent({ - command: "send-transaction" /* SendTransaction */, - version: 1, - payload: payload - }); - return payload; - }, - signMessage: function signMessage(payload) { - sendMiniKitEvent({ - command: "sign-message" /* SignMessage */, - version: 1, - payload: payload - }); - return payload; - }, - signTypedData: function signTypedData(payload) { - sendMiniKitEvent({ - command: "sign-typed-data" /* SignTypedData */, - version: 1, - payload: payload - }); - return payload; - } -}; -var MiniKit = _MiniKit; - function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } class Worldapp { diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 0d58f38..a8faaf1 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -1,8 +1,8 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@depay/web3-client-evm'), require('@depay/web3-blockchains'), require('ethers'), require('@depay/walletconnect-v2'), require('@depay/coinbase-wallet-sdk')) : - typeof define === 'function' && define.amd ? define(['exports', '@depay/web3-client-evm', '@depay/web3-blockchains', 'ethers', '@depay/walletconnect-v2', '@depay/coinbase-wallet-sdk'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Web3Wallets = {}, global.Web3Client, global.Web3Blockchains, global.ethers, global.WalletConnectV2, global.CoinbaseWalletSdk)); -}(this, (function (exports, web3ClientEvm, Blockchains, ethers, walletconnectV2, coinbaseWalletSdk) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@depay/web3-client-evm'), require('@depay/web3-blockchains'), require('ethers'), require('@depay/walletconnect-v2'), require('@depay/coinbase-wallet-sdk'), require('@depay/worldcoin-precompiled')) : + typeof define === 'function' && define.amd ? define(['exports', '@depay/web3-client-evm', '@depay/web3-blockchains', 'ethers', '@depay/walletconnect-v2', '@depay/coinbase-wallet-sdk', '@depay/worldcoin-precompiled'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Web3Wallets = {}, global.Web3Client, global.Web3Blockchains, global.ethers, global.WalletConnectV2, global.CoinbaseWalletSdk, global.WorldcoinPrecompiled)); +}(this, (function (exports, web3ClientEvm, Blockchains, ethers, walletconnectV2, coinbaseWalletSdk, worldcoinPrecompiled) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } @@ -1613,4947 +1613,6 @@ WalletLink.getConnectedInstance = getConnectedInstance; WalletLink.setConnectedInstance = setConnectedInstance; - function _arrayLikeToArray(r, a) { - (null == a || a > r.length) && (a = r.length); - for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; - return n; - } - function _arrayWithHoles(r) { - if (Array.isArray(r)) return r; - } - function _arrayWithoutHoles(r) { - if (Array.isArray(r)) return _arrayLikeToArray(r); - } - function _assertThisInitialized(e) { - if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - return e; - } - function asyncGeneratorStep(n, t, e, r, o, a, c) { - try { - var i = n[a](c), - u = i.value; - } catch (n) { - return void e(n); - } - i.done ? t(u) : Promise.resolve(u).then(r, o); - } - function _asyncToGenerator(n) { - return function () { - var t = this, - e = arguments; - return new Promise(function (r, o) { - var a = n.apply(t, e); - function _next(n) { - asyncGeneratorStep(a, r, o, _next, _throw, "next", n); - } - function _throw(n) { - asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); - } - _next(void 0); - }); - }; - } - function _callSuper(t, o, e) { - return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); - } - function _classCallCheck(a, n) { - if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); - } - function _construct(t, e, r) { - if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); - var o = [null]; - o.push.apply(o, e); - var p = new (t.bind.apply(t, o))(); - return r && _setPrototypeOf(p, r.prototype), p; - } - function _defineProperties(e, r) { - for (var t = 0; t < r.length; t++) { - var o = r[t]; - o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); - } - } - function _createClass(e, r, t) { - return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { - writable: !1 - }), e; - } - function _defineProperty(e, r, t) { - return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { - value: t, - enumerable: !0, - configurable: !0, - writable: !0 - }) : e[r] = t, e; - } - function _get() { - return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { - var p = _superPropBase(e, t); - if (p) { - var n = Object.getOwnPropertyDescriptor(p, t); - return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; - } - }, _get.apply(null, arguments); - } - function _getPrototypeOf(t) { - return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { - return t.__proto__ || Object.getPrototypeOf(t); - }, _getPrototypeOf(t); - } - function _inherits(t, e) { - if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); - t.prototype = Object.create(e && e.prototype, { - constructor: { - value: t, - writable: !0, - configurable: !0 - } - }), Object.defineProperty(t, "prototype", { - writable: !1 - }), e && _setPrototypeOf(t, e); - } - function _isNativeFunction(t) { - try { - return -1 !== Function.toString.call(t).indexOf("[native code]"); - } catch (n) { - return "function" == typeof t; - } - } - function _isNativeReflectConstruct() { - try { - var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); - } catch (t) {} - return (_isNativeReflectConstruct = function () { - return !!t; - })(); - } - function _iterableToArray(r) { - if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); - } - function _iterableToArrayLimit(r, l) { - var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; - if (null != t) { - var e, - n, - i, - u, - a = [], - f = !0, - o = !1; - try { - if (i = (t = t.call(r)).next, 0 === l) { - if (Object(t) !== t) return; - f = !1; - } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); - } catch (r) { - o = !0, n = r; - } finally { - try { - if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; - } finally { - if (o) throw n; - } - } - return a; - } - } - function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - function ownKeys(e, r) { - var t = Object.keys(e); - if (Object.getOwnPropertySymbols) { - var o = Object.getOwnPropertySymbols(e); - r && (o = o.filter(function (r) { - return Object.getOwnPropertyDescriptor(e, r).enumerable; - })), t.push.apply(t, o); - } - return t; - } - function _objectSpread2(e) { - for (var r = 1; r < arguments.length; r++) { - var t = null != arguments[r] ? arguments[r] : {}; - r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { - _defineProperty(e, r, t[r]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { - Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); - }); - } - return e; - } - function _possibleConstructorReturn(t, e) { - if (e && ("object" == typeof e || "function" == typeof e)) return e; - if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); - return _assertThisInitialized(t); - } - function _regeneratorRuntime() { - _regeneratorRuntime = function () { - return e; - }; - var t, - e = {}, - r = Object.prototype, - n = r.hasOwnProperty, - o = Object.defineProperty || function (t, e, r) { - t[e] = r.value; - }, - i = "function" == typeof Symbol ? Symbol : {}, - a = i.iterator || "@@iterator", - c = i.asyncIterator || "@@asyncIterator", - u = i.toStringTag || "@@toStringTag"; - function define(t, e, r) { - return Object.defineProperty(t, e, { - value: r, - enumerable: !0, - configurable: !0, - writable: !0 - }), t[e]; - } - try { - define({}, ""); - } catch (t) { - define = function (t, e, r) { - return t[e] = r; - }; - } - function wrap(t, e, r, n) { - var i = e && e.prototype instanceof Generator ? e : Generator, - a = Object.create(i.prototype), - c = new Context(n || []); - return o(a, "_invoke", { - value: makeInvokeMethod(t, r, c) - }), a; - } - function tryCatch(t, e, r) { - try { - return { - type: "normal", - arg: t.call(e, r) - }; - } catch (t) { - return { - type: "throw", - arg: t - }; - } - } - e.wrap = wrap; - var h = "suspendedStart", - l = "suspendedYield", - f = "executing", - s = "completed", - y = {}; - function Generator() {} - function GeneratorFunction() {} - function GeneratorFunctionPrototype() {} - var p = {}; - define(p, a, function () { - return this; - }); - var d = Object.getPrototypeOf, - v = d && d(d(values([]))); - v && v !== r && n.call(v, a) && (p = v); - var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); - function defineIteratorMethods(t) { - ["next", "throw", "return"].forEach(function (e) { - define(t, e, function (t) { - return this._invoke(e, t); - }); - }); - } - function AsyncIterator(t, e) { - function invoke(r, o, i, a) { - var c = tryCatch(t[r], t, o); - if ("throw" !== c.type) { - var u = c.arg, - h = u.value; - return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { - invoke("next", t, i, a); - }, function (t) { - invoke("throw", t, i, a); - }) : e.resolve(h).then(function (t) { - u.value = t, i(u); - }, function (t) { - return invoke("throw", t, i, a); - }); - } - a(c.arg); - } - var r; - o(this, "_invoke", { - value: function (t, n) { - function callInvokeWithMethodAndArg() { - return new e(function (e, r) { - invoke(t, n, e, r); - }); - } - return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); - } - }); - } - function makeInvokeMethod(e, r, n) { - var o = h; - return function (i, a) { - if (o === f) throw Error("Generator is already running"); - if (o === s) { - if ("throw" === i) throw a; - return { - value: t, - done: !0 - }; - } - for (n.method = i, n.arg = a;;) { - var c = n.delegate; - if (c) { - var u = maybeInvokeDelegate(c, n); - if (u) { - if (u === y) continue; - return u; - } - } - if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { - if (o === h) throw o = s, n.arg; - n.dispatchException(n.arg); - } else "return" === n.method && n.abrupt("return", n.arg); - o = f; - var p = tryCatch(e, r, n); - if ("normal" === p.type) { - if (o = n.done ? s : l, p.arg === y) continue; - return { - value: p.arg, - done: n.done - }; - } - "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); - } - }; - } - function maybeInvokeDelegate(e, r) { - var n = r.method, - o = e.iterator[n]; - if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; - var i = tryCatch(o, e.iterator, r.arg); - if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; - var a = i.arg; - return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); - } - function pushTryEntry(t) { - var e = { - tryLoc: t[0] - }; - 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); - } - function resetTryEntry(t) { - var e = t.completion || {}; - e.type = "normal", delete e.arg, t.completion = e; - } - function Context(t) { - this.tryEntries = [{ - tryLoc: "root" - }], t.forEach(pushTryEntry, this), this.reset(!0); - } - function values(e) { - if (e || "" === e) { - var r = e[a]; - if (r) return r.call(e); - if ("function" == typeof e.next) return e; - if (!isNaN(e.length)) { - var o = -1, - i = function next() { - for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; - return next.value = t, next.done = !0, next; - }; - return i.next = i; - } - } - throw new TypeError(typeof e + " is not iterable"); - } - return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { - value: GeneratorFunctionPrototype, - configurable: !0 - }), o(GeneratorFunctionPrototype, "constructor", { - value: GeneratorFunction, - configurable: !0 - }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { - var e = "function" == typeof t && t.constructor; - return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); - }, e.mark = function (t) { - return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; - }, e.awrap = function (t) { - return { - __await: t - }; - }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { - return this; - }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { - void 0 === i && (i = Promise); - var a = new AsyncIterator(wrap(t, r, n, o), i); - return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { - return t.done ? t.value : a.next(); - }); - }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { - return this; - }), define(g, "toString", function () { - return "[object Generator]"; - }), e.keys = function (t) { - var e = Object(t), - r = []; - for (var n in e) r.push(n); - return r.reverse(), function next() { - for (; r.length;) { - var t = r.pop(); - if (t in e) return next.value = t, next.done = !1, next; - } - return next.done = !0, next; - }; - }, e.values = values, Context.prototype = { - constructor: Context, - reset: function (e) { - if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); - }, - stop: function () { - this.done = !0; - var t = this.tryEntries[0].completion; - if ("throw" === t.type) throw t.arg; - return this.rval; - }, - dispatchException: function (e) { - if (this.done) throw e; - var r = this; - function handle(n, o) { - return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; - } - for (var o = this.tryEntries.length - 1; o >= 0; --o) { - var i = this.tryEntries[o], - a = i.completion; - if ("root" === i.tryLoc) return handle("end"); - if (i.tryLoc <= this.prev) { - var c = n.call(i, "catchLoc"), - u = n.call(i, "finallyLoc"); - if (c && u) { - if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); - if (this.prev < i.finallyLoc) return handle(i.finallyLoc); - } else if (c) { - if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); - } else { - if (!u) throw Error("try statement without catch or finally"); - if (this.prev < i.finallyLoc) return handle(i.finallyLoc); - } - } - } - }, - abrupt: function (t, e) { - for (var r = this.tryEntries.length - 1; r >= 0; --r) { - var o = this.tryEntries[r]; - if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { - var i = o; - break; - } - } - i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); - var a = i ? i.completion : {}; - return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); - }, - complete: function (t, e) { - if ("throw" === t.type) throw t.arg; - return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; - }, - finish: function (t) { - for (var e = this.tryEntries.length - 1; e >= 0; --e) { - var r = this.tryEntries[e]; - if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; - } - }, - catch: function (t) { - for (var e = this.tryEntries.length - 1; e >= 0; --e) { - var r = this.tryEntries[e]; - if (r.tryLoc === t) { - var n = r.completion; - if ("throw" === n.type) { - var o = n.arg; - resetTryEntry(r); - } - return o; - } - } - throw Error("illegal catch attempt"); - }, - delegateYield: function (e, r, n) { - return this.delegate = { - iterator: values(e), - resultName: r, - nextLoc: n - }, "next" === this.method && (this.arg = t), y; - } - }, e; - } - function _setPrototypeOf(t, e) { - return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { - return t.__proto__ = e, t; - }, _setPrototypeOf(t, e); - } - function _slicedToArray(r, e) { - return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); - } - function _superPropBase(t, o) { - for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); - return t; - } - function _superPropGet(t, e, o, r) { - var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), e, o); - return 2 & r && "function" == typeof p ? function (t) { - return p.apply(o, t); - } : p; - } - function _toConsumableArray(r) { - return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); - } - function _toPrimitive(t, r) { - if ("object" != typeof t || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || "default"); - if ("object" != typeof i) return i; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return ("string" === r ? String : Number)(t); - } - function _toPropertyKey(t) { - var i = _toPrimitive(t, "string"); - return "symbol" == typeof i ? i : i + ""; - } - function _typeof(o) { - "@babel/helpers - typeof"; - - return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { - return typeof o; - } : function (o) { - return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; - }, _typeof(o); - } - function _unsupportedIterableToArray(r, a) { - if (r) { - if ("string" == typeof r) return _arrayLikeToArray(r, a); - var t = {}.toString.call(r).slice(8, -1); - return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; - } - } - function _wrapNativeSuper(t) { - var r = "function" == typeof Map ? new Map() : void 0; - return _wrapNativeSuper = function (t) { - if (null === t || !_isNativeFunction(t)) return t; - if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); - if (void 0 !== r) { - if (r.has(t)) return r.get(t); - r.set(t, Wrapper); - } - function Wrapper() { - return _construct(t, arguments, _getPrototypeOf(this).constructor); - } - return Wrapper.prototype = Object.create(t.prototype, { - constructor: { - value: Wrapper, - enumerable: !1, - writable: !0, - configurable: !0 - } - }), _setPrototypeOf(Wrapper, t); - }, _wrapNativeSuper(t); - } - - function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function getAugmentedNamespace(n) { - var f = n.default; - if (typeof f == "function") { - var a = function () { - return f.apply(this, arguments); - }; - a.prototype = f.prototype; - } else a = {}; - Object.defineProperty(a, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; - } - - var buffer = {}; - - var base64Js = {}; - - base64Js.byteLength = byteLength; - base64Js.toByteArray = toByteArray; - base64Js.fromByteArray = fromByteArray; - var lookup = []; - var revLookup = []; - var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; - var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i]; - revLookup[code.charCodeAt(i)] = i; - } - - // Support decoding URL-safe base64 strings, as Node.js does. - // See: https://en.wikipedia.org/wiki/Base64#URL_applications - revLookup['-'.charCodeAt(0)] = 62; - revLookup['_'.charCodeAt(0)] = 63; - function getLens(b64) { - var len = b64.length; - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4'); - } - - // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - var validLen = b64.indexOf('='); - if (validLen === -1) validLen = len; - var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; - return [validLen, placeHoldersLen]; - } - - // base64 is 4/3 + up to two characters of the original data - function byteLength(b64) { - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; - } - function _byteLength(b64, validLen, placeHoldersLen) { - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; - } - function toByteArray(b64) { - var tmp; - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); - var curByte = 0; - - // if there are placeholders, only get up to the last complete 4 chars - var len = placeHoldersLen > 0 ? validLen - 4 : validLen; - var i; - for (i = 0; i < len; i += 4) { - tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; - arr[curByte++] = tmp >> 16 & 0xFF; - arr[curByte++] = tmp >> 8 & 0xFF; - arr[curByte++] = tmp & 0xFF; - } - if (placeHoldersLen === 2) { - tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; - arr[curByte++] = tmp & 0xFF; - } - if (placeHoldersLen === 1) { - tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; - arr[curByte++] = tmp >> 8 & 0xFF; - arr[curByte++] = tmp & 0xFF; - } - return arr; - } - function tripletToBase64(num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; - } - function encodeChunk(uint8, start, end) { - var tmp; - var output = []; - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF); - output.push(tripletToBase64(tmp)); - } - return output.join(''); - } - function fromByteArray(uint8) { - var tmp; - var len = uint8.length; - var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes - var parts = []; - var maxChunkLength = 16383; // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); - } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1]; - parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '=='); - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1]; - parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '='); - } - return parts.join(''); - } - - var ieee754 = {}; - - /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ - ieee754.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var nBits = -7; - var i = isLE ? nBytes - 1 : 0; - var d = isLE ? -1 : 1; - var s = buffer[offset + i]; - i += d; - e = s & (1 << -nBits) - 1; - s >>= -nBits; - nBits += eLen; - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} - m = e & (1 << -nBits) - 1; - e >>= -nBits; - nBits += mLen; - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : (s ? -1 : 1) * Infinity; - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen); - }; - ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; - var i = isLE ? 0 : nBytes - 1; - var d = isLE ? 1 : -1; - var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; - value = Math.abs(value); - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - if (e + eBias >= 1) { - value += rt / c; - } else { - value += rt * Math.pow(2, 1 - eBias); - } - if (value * c >= 2) { - e++; - c /= 2; - } - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; - } - } - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - e = e << mLen | m; - eLen += mLen; - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - buffer[offset + i - d] |= s * 128; - }; - - (function (exports) { - - var base64 = base64Js; - var ieee754$1 = ieee754; - var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' // eslint-disable-line dot-notation - ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation - : null; - exports.Buffer = Buffer; - exports.SlowBuffer = SlowBuffer; - exports.INSPECT_MAX_BYTES = 50; - var K_MAX_LENGTH = 0x7fffffff; - exports.kMaxLength = K_MAX_LENGTH; - - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ - Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); - if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') { - console.error('This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'); - } - function typedArraySupport() { - // Can typed array instances can be augmented? - try { - var arr = new Uint8Array(1); - var proto = { - foo: function foo() { - return 42; - } - }; - Object.setPrototypeOf(proto, Uint8Array.prototype); - Object.setPrototypeOf(arr, proto); - return arr.foo() === 42; - } catch (e) { - return false; - } - } - Object.defineProperty(Buffer.prototype, 'parent', { - enumerable: true, - get: function get() { - if (!Buffer.isBuffer(this)) return undefined; - return this.buffer; - } - }); - Object.defineProperty(Buffer.prototype, 'offset', { - enumerable: true, - get: function get() { - if (!Buffer.isBuffer(this)) return undefined; - return this.byteOffset; - } - }); - function createBuffer(length) { - if (length > K_MAX_LENGTH) { - throw new RangeError('The value "' + length + '" is invalid for option "size"'); - } - // Return an augmented `Uint8Array` instance - var buf = new Uint8Array(length); - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - function Buffer(arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new TypeError('The "string" argument must be of type string. Received type number'); - } - return allocUnsafe(arg); - } - return from(arg, encodingOrOffset, length); - } - Buffer.poolSize = 8192; // not used by this implementation - - function from(value, encodingOrOffset, length) { - if (typeof value === 'string') { - return fromString(value, encodingOrOffset); - } - if (ArrayBuffer.isView(value)) { - return fromArrayView(value); - } - if (value == null) { - throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value)); - } - if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - if (typeof SharedArrayBuffer !== 'undefined' && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - if (typeof value === 'number') { - throw new TypeError('The "value" argument must not be of type number. Received type number'); - } - var valueOf = value.valueOf && value.valueOf(); - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length); - } - var b = fromObject(value); - if (b) return b; - if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') { - return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); - } - throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value)); - } - - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length); - }; - - // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: - // https://github.com/feross/buffer/pull/148 - Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); - Object.setPrototypeOf(Buffer, Uint8Array); - function assertSize(size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be of type number'); - } else if (size < 0) { - throw new RangeError('The value "' + size + '" is invalid for option "size"'); - } - } - function alloc(size, fill, encoding) { - assertSize(size); - if (size <= 0) { - return createBuffer(size); - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpreted as a start offset. - return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); - } - return createBuffer(size); - } - - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - Buffer.alloc = function (size, fill, encoding) { - return alloc(size, fill, encoding); - }; - function allocUnsafe(size) { - assertSize(size); - return createBuffer(size < 0 ? 0 : checked(size) | 0); - } - - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - Buffer.allocUnsafe = function (size) { - return allocUnsafe(size); - }; - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(size); - }; - function fromString(string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8'; - } - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding); - } - var length = byteLength(string, encoding) | 0; - var buf = createBuffer(length); - var actual = buf.write(string, encoding); - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual); - } - return buf; - } - function fromArrayLike(array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0; - var buf = createBuffer(length); - for (var i = 0; i < length; i += 1) { - buf[i] = array[i] & 255; - } - return buf; - } - function fromArrayView(arrayView) { - if (isInstance(arrayView, Uint8Array)) { - var copy = new Uint8Array(arrayView); - return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); - } - return fromArrayLike(arrayView); - } - function fromArrayBuffer(array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('"offset" is outside of buffer bounds'); - } - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('"length" is outside of buffer bounds'); - } - var buf; - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array); - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset); - } else { - buf = new Uint8Array(array, byteOffset, length); - } - - // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - function fromObject(obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0; - var buf = createBuffer(len); - if (buf.length === 0) { - return buf; - } - obj.copy(buf, 0, 0, len); - return buf; - } - if (obj.length !== undefined) { - if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { - return createBuffer(0); - } - return fromArrayLike(obj); - } - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { - return fromArrayLike(obj.data); - } - } - function checked(length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes'); - } - return length | 0; - } - function SlowBuffer(length) { - if (+length != length) { - // eslint-disable-line eqeqeq - length = 0; - } - return Buffer.alloc(+length); - } - Buffer.isBuffer = function isBuffer(b) { - return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false - }; - Buffer.compare = function compare(a, b) { - if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); - if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'); - } - if (a === b) return 0; - var x = a.length; - var y = b.length; - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; - } - } - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; - Buffer.isEncoding = function isEncoding(encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true; - default: - return false; - } - }; - Buffer.concat = function concat(list, length) { - if (!Array.isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers'); - } - if (list.length === 0) { - return Buffer.alloc(0); - } - var i; - if (length === undefined) { - length = 0; - for (i = 0; i < list.length; ++i) { - length += list[i].length; - } - } - var buffer = Buffer.allocUnsafe(length); - var pos = 0; - for (i = 0; i < list.length; ++i) { - var buf = list[i]; - if (isInstance(buf, Uint8Array)) { - if (pos + buf.length > buffer.length) { - if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); - buf.copy(buffer, pos); - } else { - Uint8Array.prototype.set.call(buffer, buf, pos); - } - } else if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers'); - } else { - buf.copy(buffer, pos); - } - pos += buf.length; - } - return buffer; - }; - function byteLength(string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length; - } - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength; - } - if (typeof string !== 'string') { - throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string)); - } - var len = string.length; - var mustMatch = arguments.length > 2 && arguments[2] === true; - if (!mustMatch && len === 0) return 0; - - // Use a for loop to avoid recursion - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len; - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length; - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2; - case 'hex': - return len >>> 1; - case 'base64': - return base64ToBytes(string).length; - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 - } - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - } - Buffer.byteLength = byteLength; - function slowToString(encoding, start, end) { - var loweredCase = false; - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0; - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return ''; - } - if (end === undefined || end > this.length) { - end = this.length; - } - if (end <= 0) { - return ''; - } - - // Force coercion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0; - start >>>= 0; - if (end <= start) { - return ''; - } - if (!encoding) encoding = 'utf8'; - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end); - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end); - case 'ascii': - return asciiSlice(this, start, end); - case 'latin1': - case 'binary': - return latin1Slice(this, start, end); - case 'base64': - return base64Slice(this, start, end); - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end); - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); - encoding = (encoding + '').toLowerCase(); - loweredCase = true; - } - } - } - - // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) - // to detect a Buffer instance. It's not possible to use `instanceof Buffer` - // reliably in a browserify context because there could be multiple different - // copies of the 'buffer' package in use. This method works even for Buffer - // instances that were created from another copy of the `buffer` package. - // See: https://github.com/feross/buffer/issues/154 - Buffer.prototype._isBuffer = true; - function swap(b, n, m) { - var i = b[n]; - b[n] = b[m]; - b[m] = i; - } - Buffer.prototype.swap16 = function swap16() { - var len = this.length; - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits'); - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1); - } - return this; - }; - Buffer.prototype.swap32 = function swap32() { - var len = this.length; - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits'); - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3); - swap(this, i + 1, i + 2); - } - return this; - }; - Buffer.prototype.swap64 = function swap64() { - var len = this.length; - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits'); - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7); - swap(this, i + 1, i + 6); - swap(this, i + 2, i + 5); - swap(this, i + 3, i + 4); - } - return this; - }; - Buffer.prototype.toString = function toString() { - var length = this.length; - if (length === 0) return ''; - if (arguments.length === 0) return utf8Slice(this, 0, length); - return slowToString.apply(this, arguments); - }; - Buffer.prototype.toLocaleString = Buffer.prototype.toString; - Buffer.prototype.equals = function equals(b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); - if (this === b) return true; - return Buffer.compare(this, b) === 0; - }; - Buffer.prototype.inspect = function inspect() { - var str = ''; - var max = exports.INSPECT_MAX_BYTES; - str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); - if (this.length > max) str += ' ... '; - return ''; - }; - if (customInspectSymbol) { - Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; - } - Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { - if (isInstance(target, Uint8Array)) { - target = Buffer.from(target, target.offset, target.byteLength); - } - if (!Buffer.isBuffer(target)) { - throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + _typeof(target)); - } - if (start === undefined) { - start = 0; - } - if (end === undefined) { - end = target ? target.length : 0; - } - if (thisStart === undefined) { - thisStart = 0; - } - if (thisEnd === undefined) { - thisEnd = this.length; - } - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index'); - } - if (thisStart >= thisEnd && start >= end) { - return 0; - } - if (thisStart >= thisEnd) { - return -1; - } - if (start >= end) { - return 1; - } - start >>>= 0; - end >>>= 0; - thisStart >>>= 0; - thisEnd >>>= 0; - if (this === target) return 0; - var x = thisEnd - thisStart; - var y = end - start; - var len = Math.min(x, y); - var thisCopy = this.slice(thisStart, thisEnd); - var targetCopy = target.slice(start, end); - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i]; - y = targetCopy[i]; - break; - } - } - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; - - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1; - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset; - byteOffset = 0; - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff; - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000; - } - byteOffset = +byteOffset; // Coerce to Number. - if (numberIsNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : buffer.length - 1; - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset; - if (byteOffset >= buffer.length) { - if (dir) return -1;else byteOffset = buffer.length - 1; - } else if (byteOffset < 0) { - if (dir) byteOffset = 0;else return -1; - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding); - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1; - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir); - } else if (typeof val === 'number') { - val = val & 0xFF; // Search for a byte value [0-255] - if (typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); - } - } - return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); - } - throw new TypeError('val must be string, number or Buffer'); - } - function arrayIndexOf(arr, val, byteOffset, encoding, dir) { - var indexSize = 1; - var arrLength = arr.length; - var valLength = val.length; - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase(); - if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1; - } - indexSize = 2; - arrLength /= 2; - valLength /= 2; - byteOffset /= 2; - } - } - function read(buf, i) { - if (indexSize === 1) { - return buf[i]; - } else { - return buf.readUInt16BE(i * indexSize); - } - } - var i; - if (dir) { - var foundIndex = -1; - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i; - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; - } else { - if (foundIndex !== -1) i -= i - foundIndex; - foundIndex = -1; - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; - for (i = byteOffset; i >= 0; i--) { - var found = true; - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false; - break; - } - } - if (found) return i; - } - } - return -1; - } - Buffer.prototype.includes = function includes(val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1; - }; - Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true); - }; - Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false); - }; - function hexWrite(buf, string, offset, length) { - offset = Number(offset) || 0; - var remaining = buf.length - offset; - if (!length) { - length = remaining; - } else { - length = Number(length); - if (length > remaining) { - length = remaining; - } - } - var strLen = string.length; - if (length > strLen / 2) { - length = strLen / 2; - } - var i; - for (i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16); - if (numberIsNaN(parsed)) return i; - buf[offset + i] = parsed; - } - return i; - } - function utf8Write(buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); - } - function asciiWrite(buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length); - } - function base64Write(buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length); - } - function ucs2Write(buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); - } - Buffer.prototype.write = function write(string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8'; - length = this.length; - offset = 0; - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset; - length = this.length; - offset = 0; - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0; - if (isFinite(length)) { - length = length >>> 0; - if (encoding === undefined) encoding = 'utf8'; - } else { - encoding = length; - length = undefined; - } - } else { - throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); - } - var remaining = this.length - offset; - if (length === undefined || length > remaining) length = remaining; - if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds'); - } - if (!encoding) encoding = 'utf8'; - var loweredCase = false; - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length); - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length); - case 'ascii': - case 'latin1': - case 'binary': - return asciiWrite(this, string, offset, length); - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length); - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length); - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } - }; - Buffer.prototype.toJSON = function toJSON() { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - }; - }; - function base64Slice(buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf); - } else { - return base64.fromByteArray(buf.slice(start, end)); - } - } - function utf8Slice(buf, start, end) { - end = Math.min(buf.length, end); - var res = []; - var i = start; - while (i < end) { - var firstByte = buf[i]; - var codePoint = null; - var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; - if (i + bytesPerSequence <= end) { - var secondByte = void 0, - thirdByte = void 0, - fourthByte = void 0, - tempCodePoint = void 0; - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte; - } - break; - case 2: - secondByte = buf[i + 1]; - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F; - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint; - } - } - break; - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F; - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint; - } - } - break; - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F; - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint; - } - } - } - } - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD; - bytesPerSequence = 1; - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000; - res.push(codePoint >>> 10 & 0x3FF | 0xD800); - codePoint = 0xDC00 | codePoint & 0x3FF; - } - res.push(codePoint); - i += bytesPerSequence; - } - return decodeCodePointsArray(res); - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000; - function decodeCodePointsArray(codePoints) { - var len = codePoints.length; - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints); // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = ''; - var i = 0; - while (i < len) { - res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); - } - return res; - } - function asciiSlice(buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F); - } - return ret; - } - function latin1Slice(buf, start, end) { - var ret = ''; - end = Math.min(buf.length, end); - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - return ret; - } - function hexSlice(buf, start, end) { - var len = buf.length; - if (!start || start < 0) start = 0; - if (!end || end < 0 || end > len) end = len; - var out = ''; - for (var i = start; i < end; ++i) { - out += hexSliceLookupTable[buf[i]]; - } - return out; - } - function utf16leSlice(buf, start, end) { - var bytes = buf.slice(start, end); - var res = ''; - // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) - for (var i = 0; i < bytes.length - 1; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - return res; - } - Buffer.prototype.slice = function slice(start, end) { - var len = this.length; - start = ~~start; - end = end === undefined ? len : ~~end; - if (start < 0) { - start += len; - if (start < 0) start = 0; - } else if (start > len) { - start = len; - } - if (end < 0) { - end += len; - if (end < 0) end = 0; - } else if (end > len) { - end = len; - } - if (end < start) end = start; - var newBuf = this.subarray(start, end); - // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(newBuf, Buffer.prototype); - return newBuf; - }; - - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset(offset, ext, length) { - if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); - } - Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - return val; - }; - Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - checkOffset(offset, byteLength, this.length); - } - var val = this[offset + --byteLength]; - var mul = 1; - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul; - } - return val; - }; - Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - return this[offset]; - }; - Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] | this[offset + 1] << 8; - }; - Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] << 8 | this[offset + 1]; - }; - Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000; - }; - Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); - }; - Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var lo = first + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 24); - var hi = this[++offset] + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + last * Math.pow(2, 24); - return BigInt(lo) + (BigInt(hi) << BigInt(32)); - }); - Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var hi = first * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + this[++offset]; - var lo = this[++offset] * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + last; - return (BigInt(hi) << BigInt(32)) + BigInt(lo); - }); - Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var val = this[offset]; - var mul = 1; - var i = 0; - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul; - } - mul *= 0x80; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - var i = byteLength; - var mul = 1; - var val = this[offset + --i]; - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul; - } - mul *= 0x80; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - if (!(this[offset] & 0x80)) return this[offset]; - return (0xff - this[offset] + 1) * -1; - }; - Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset] | this[offset + 1] << 8; - return val & 0x8000 ? val | 0xFFFF0000 : val; - }; - Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - var val = this[offset + 1] | this[offset] << 8; - return val & 0x8000 ? val | 0xFFFF0000 : val; - }; - Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; - }; - Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; - }; - Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var val = this[offset + 4] + this[offset + 5] * Math.pow(2, 8) + this[offset + 6] * Math.pow(2, 16) + (last << 24); // Overflow - - return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * Math.pow(2, 8) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 24)); - }); - Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, 'offset'); - var first = this[offset]; - var last = this[offset + 7]; - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - var val = (first << 24) + - // Overflow - this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + this[++offset]; - return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * Math.pow(2, 24) + this[++offset] * Math.pow(2, 16) + this[++offset] * Math.pow(2, 8) + last); - }); - Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754$1.read(this, offset, true, 23, 4); - }; - Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754$1.read(this, offset, false, 23, 4); - }; - Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754$1.read(this, offset, true, 52, 8); - }; - Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754$1.read(this, offset, false, 52, 8); - }; - function checkInt(buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); - if (offset + ext > buf.length) throw new RangeError('Index out of range'); - } - Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - var mul = 1; - var i = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = value / mul & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - var i = byteLength - 1; - var mul = 1; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = value / mul & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); - this[offset] = value & 0xff; - return offset + 1; - }; - Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); - this[offset] = value >>> 8; - this[offset + 1] = value & 0xff; - return offset + 2; - }; - Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - this[offset + 3] = value >>> 24; - this[offset + 2] = value >>> 16; - this[offset + 1] = value >>> 8; - this[offset] = value & 0xff; - return offset + 4; - }; - Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 0xff; - return offset + 4; - }; - function wrtBigUInt64LE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - var lo = Number(value & BigInt(0xffffffff)); - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - var hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - return offset; - } - function wrtBigUInt64BE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - var lo = Number(value & BigInt(0xffffffff)); - buf[offset + 7] = lo; - lo = lo >> 8; - buf[offset + 6] = lo; - lo = lo >> 8; - buf[offset + 5] = lo; - lo = lo >> 8; - buf[offset + 4] = lo; - var hi = Number(value >> BigInt(32) & BigInt(0xffffffff)); - buf[offset + 3] = hi; - hi = hi >> 8; - buf[offset + 2] = hi; - hi = hi >> 8; - buf[offset + 1] = hi; - hi = hi >> 8; - buf[offset] = hi; - return offset + 8; - } - Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); - }); - Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')); - }); - Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - var i = 0; - var mul = 1; - var sub = 0; - this[offset] = value & 0xFF; - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1; - } - this[offset + i] = (value / mul >> 0) - sub & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - var i = byteLength - 1; - var mul = 1; - var sub = 0; - this[offset + i] = value & 0xFF; - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1; - } - this[offset + i] = (value / mul >> 0) - sub & 0xFF; - } - return offset + byteLength; - }; - Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); - if (value < 0) value = 0xff + value + 1; - this[offset] = value & 0xff; - return offset + 1; - }; - Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); - this[offset] = value >>> 8; - this[offset + 1] = value & 0xff; - return offset + 2; - }; - Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - this[offset] = value & 0xff; - this[offset + 1] = value >>> 8; - this[offset + 2] = value >>> 16; - this[offset + 3] = value >>> 24; - return offset + 4; - }; - Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); - if (value < 0) value = 0xffffffff + value + 1; - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 0xff; - return offset + 4; - }; - Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); - }); - Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')); - }); - function checkIEEE754(buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range'); - if (offset < 0) throw new RangeError('Index out of range'); - } - function writeFloat(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - checkIEEE754(buf, value, offset, 4); - } - ieee754$1.write(buf, value, offset, littleEndian, 23, 4); - return offset + 4; - } - Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert); - }; - Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert); - }; - function writeDouble(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) { - checkIEEE754(buf, value, offset, 8); - } - ieee754$1.write(buf, value, offset, littleEndian, 52, 8); - return offset + 8; - } - Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert); - }; - Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert); - }; - - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy(target, targetStart, start, end) { - if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer'); - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (targetStart >= target.length) targetStart = target.length; - if (!targetStart) targetStart = 0; - if (end > 0 && end < start) end = start; - - // Copy 0 bytes; we're done - if (end === start) return 0; - if (target.length === 0 || this.length === 0) return 0; - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds'); - } - if (start < 0 || start >= this.length) throw new RangeError('Index out of range'); - if (end < 0) throw new RangeError('sourceEnd out of bounds'); - - // Are we oob? - if (end > this.length) end = this.length; - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start; - } - var len = end - start; - if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { - // Use built-in when available, missing from IE11 - this.copyWithin(targetStart, start, end); - } else { - Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); - } - return len; - }; - - // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - Buffer.prototype.fill = function fill(val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start; - start = 0; - end = this.length; - } else if (typeof end === 'string') { - encoding = end; - end = this.length; - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string'); - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding); - } - if (val.length === 1) { - var code = val.charCodeAt(0); - if (encoding === 'utf8' && code < 128 || encoding === 'latin1') { - // Fast path: If `val` fits into a single byte, use that numeric value. - val = code; - } - } - } else if (typeof val === 'number') { - val = val & 255; - } else if (typeof val === 'boolean') { - val = Number(val); - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index'); - } - if (end <= start) { - return this; - } - start = start >>> 0; - end = end === undefined ? this.length : end >>> 0; - if (!val) val = 0; - var i; - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val; - } - } else { - var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); - var len = bytes.length; - if (len === 0) { - throw new TypeError('The value "' + val + '" is invalid for argument "value"'); - } - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len]; - } - } - return this; - }; - - // CUSTOM ERRORS - // ============= - - // Simplified versions from Node, changed for Buffer-only usage - var errors = {}; - function E(sym, getMessage, Base) { - errors[sym] = /*#__PURE__*/function (_Base) { - function NodeError() { - var _this; - _classCallCheck(this, NodeError); - _this = _callSuper(this, NodeError); - Object.defineProperty(_this, 'message', { - value: getMessage.apply(_this, arguments), - writable: true, - configurable: true - }); - - // Add the error code to the name to include it in the stack trace. - _this.name = "".concat(_this.name, " [").concat(sym, "]"); - // Access the stack to generate the error message including the error code - // from the name. - _this.stack; // eslint-disable-line no-unused-expressions - // Reset the name to the actual name. - delete _this.name; - return _this; - } - _inherits(NodeError, _Base); - return _createClass(NodeError, [{ - key: "code", - get: function get() { - return sym; - }, - set: function set(value) { - Object.defineProperty(this, 'code', { - configurable: true, - enumerable: true, - value: value, - writable: true - }); - } - }, { - key: "toString", - value: function toString() { - return "".concat(this.name, " [").concat(sym, "]: ").concat(this.message); - } - }]); - }(Base); - } - E('ERR_BUFFER_OUT_OF_BOUNDS', function (name) { - if (name) { - return "".concat(name, " is outside of buffer bounds"); - } - return 'Attempt to access memory outside buffer bounds'; - }, RangeError); - E('ERR_INVALID_ARG_TYPE', function (name, actual) { - return "The \"".concat(name, "\" argument must be of type number. Received type ").concat(_typeof(actual)); - }, TypeError); - E('ERR_OUT_OF_RANGE', function (str, range, input) { - var msg = "The value of \"".concat(str, "\" is out of range."); - var received = input; - if (Number.isInteger(input) && Math.abs(input) > Math.pow(2, 32)) { - received = addNumericalSeparator(String(input)); - } else if (typeof input === 'bigint') { - received = String(input); - if (input > Math.pow(BigInt(2), BigInt(32)) || input < -Math.pow(BigInt(2), BigInt(32))) { - received = addNumericalSeparator(received); - } - received += 'n'; - } - msg += " It must be ".concat(range, ". Received ").concat(received); - return msg; - }, RangeError); - function addNumericalSeparator(val) { - var res = ''; - var i = val.length; - var start = val[0] === '-' ? 1 : 0; - for (; i >= start + 4; i -= 3) { - res = "_".concat(val.slice(i - 3, i)).concat(res); - } - return "".concat(val.slice(0, i)).concat(res); - } - - // CHECK FUNCTIONS - // =============== - - function checkBounds(buf, offset, byteLength) { - validateNumber(offset, 'offset'); - if (buf[offset] === undefined || buf[offset + byteLength] === undefined) { - boundsError(offset, buf.length - (byteLength + 1)); - } - } - function checkIntBI(value, min, max, buf, offset, byteLength) { - if (value > max || value < min) { - var n = typeof min === 'bigint' ? 'n' : ''; - var range; - if (byteLength > 3) { - if (min === 0 || min === BigInt(0)) { - range = ">= 0".concat(n, " and < 2").concat(n, " ** ").concat((byteLength + 1) * 8).concat(n); - } else { - range = ">= -(2".concat(n, " ** ").concat((byteLength + 1) * 8 - 1).concat(n, ") and < 2 ** ") + "".concat((byteLength + 1) * 8 - 1).concat(n); - } - } else { - range = ">= ".concat(min).concat(n, " and <= ").concat(max).concat(n); - } - throw new errors.ERR_OUT_OF_RANGE('value', range, value); - } - checkBounds(buf, offset, byteLength); - } - function validateNumber(value, name) { - if (typeof value !== 'number') { - throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value); - } - } - function boundsError(value, length, type) { - if (Math.floor(value) !== value) { - validateNumber(value, type); - throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); - } - if (length < 0) { - throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); - } - throw new errors.ERR_OUT_OF_RANGE(type || 'offset', ">= ".concat(type ? 1 : 0, " and <= ").concat(length), value); - } - - // HELPER FUNCTIONS - // ================ - - var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; - function base64clean(str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split('=')[0]; - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = str.trim().replace(INVALID_BASE64_RE, ''); - // Node converts strings with length < 2 to '' - if (str.length < 2) return ''; - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '='; - } - return str; - } - function utf8ToBytes(string, units) { - units = units || Infinity; - var codePoint; - var length = string.length; - var leadSurrogate = null; - var bytes = []; - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue; - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - continue; - } - - // valid lead - leadSurrogate = codePoint; - continue; - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - leadSurrogate = codePoint; - continue; - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD); - } - leadSurrogate = null; - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break; - bytes.push(codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break; - bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break; - bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break; - bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80); - } else { - throw new Error('Invalid code point'); - } - } - return bytes; - } - function asciiToBytes(str) { - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF); - } - return byteArray; - } - function utf16leToBytes(str, units) { - var c, hi, lo; - var byteArray = []; - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break; - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - return byteArray; - } - function base64ToBytes(str) { - return base64.toByteArray(base64clean(str)); - } - function blitBuffer(src, dst, offset, length) { - var i; - for (i = 0; i < length; ++i) { - if (i + offset >= dst.length || i >= src.length) break; - dst[i + offset] = src[i]; - } - return i; - } - - // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass - // the `instanceof` check but they should be treated as of that type. - // See: https://github.com/feross/buffer/issues/166 - function isInstance(obj, type) { - return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; - } - function numberIsNaN(obj) { - // For IE11 support - return obj !== obj; // eslint-disable-line no-self-compare - } - - // Create lookup table for `toString('hex')` - // See: https://github.com/feross/buffer/issues/219 - var hexSliceLookupTable = function () { - var alphabet = '0123456789abcdef'; - var table = new Array(256); - for (var i = 0; i < 16; ++i) { - var i16 = i * 16; - for (var j = 0; j < 16; ++j) { - table[i16 + j] = alphabet[i] + alphabet[j]; - } - } - return table; - }(); - - // Return not function with Error if BigInt not supported - function defineBigIntMethod(fn) { - return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn; - } - function BufferBigIntNotDefined() { - throw new Error('BigInt not supported'); - } - })(buffer); - - function isHex(value) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref$strict = _ref.strict, - strict = _ref$strict === void 0 ? true : _ref$strict; - if (!value) return false; - if (typeof value !== 'string') return false; - return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x'); - } - - /** - * @description Retrieves the size of the value (in bytes). - * - * @param value The value (hex or byte array) to retrieve the size of. - * @returns The size of the value (in bytes). - */ - function size(value) { - if (isHex(value, { - strict: false - })) return Math.ceil((value.length - 2) / 2); - return value.length; - } - - var version = '2.21.7'; - - var errorConfig = { - getDocsUrl: function getDocsUrl(_ref) { - var docsBaseUrl = _ref.docsBaseUrl, - _ref$docsPath = _ref.docsPath, - docsPath = _ref$docsPath === void 0 ? '' : _ref$docsPath, - docsSlug = _ref.docsSlug; - return docsPath ? "".concat(docsBaseUrl !== null && docsBaseUrl !== void 0 ? docsBaseUrl : 'https://viem.sh').concat(docsPath).concat(docsSlug ? "#".concat(docsSlug) : '') : undefined; - }, - version: version - }; - var BaseError = /*#__PURE__*/function (_Error) { - function BaseError(shortMessage) { - var _errorConfig$getDocsU, _errorConfig, _args$name; - var _this; - var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - _classCallCheck(this, BaseError); - var details = function (_args$cause) { - if (args.cause instanceof BaseError) return args.cause.details; - if ((_args$cause = args.cause) !== null && _args$cause !== void 0 && _args$cause.message) return args.cause.message; - return args.details; - }(); - var docsPath = function () { - if (args.cause instanceof BaseError) return args.cause.docsPath || args.docsPath; - return args.docsPath; - }(); - var docsUrl = (_errorConfig$getDocsU = (_errorConfig = errorConfig).getDocsUrl) === null || _errorConfig$getDocsU === void 0 ? void 0 : _errorConfig$getDocsU.call(_errorConfig, _objectSpread2(_objectSpread2({}, args), {}, { - docsPath: docsPath - })); - var message = [shortMessage || 'An error occurred.', ''].concat(_toConsumableArray(args.metaMessages ? [].concat(_toConsumableArray(args.metaMessages), ['']) : []), _toConsumableArray(docsUrl ? ["Docs: ".concat(docsUrl)] : []), _toConsumableArray(details ? ["Details: ".concat(details)] : []), _toConsumableArray(errorConfig.version ? ["Version: ".concat(errorConfig.version)] : [])).join('\n'); - _this = _callSuper(this, BaseError, [message, args.cause ? { - cause: args.cause - } : undefined]); - Object.defineProperty(_this, "details", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "docsPath", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "metaMessages", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "shortMessage", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "version", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(_this, "name", { - enumerable: true, - configurable: true, - writable: true, - value: 'BaseError' - }); - _this.details = details; - _this.docsPath = docsPath; - _this.metaMessages = args.metaMessages; - _this.name = (_args$name = args.name) !== null && _args$name !== void 0 ? _args$name : _this.name; - _this.shortMessage = shortMessage; - _this.version = version; - return _this; - } - _inherits(BaseError, _Error); - return _createClass(BaseError, [{ - key: "walk", - value: function walk(fn) { - return _walk(this, fn); - } - }]); - }(/*#__PURE__*/_wrapNativeSuper(Error)); - function _walk(err, fn) { - if (fn !== null && fn !== void 0 && fn(err)) return err; - if (err && _typeof(err) === 'object' && 'cause' in err) return _walk(err.cause, fn); - return fn ? null : err; - } - - var AbiEncodingLengthMismatchError = /*#__PURE__*/function (_BaseError8) { - function AbiEncodingLengthMismatchError(_ref7) { - var expectedLength = _ref7.expectedLength, - givenLength = _ref7.givenLength; - _classCallCheck(this, AbiEncodingLengthMismatchError); - return _callSuper(this, AbiEncodingLengthMismatchError, [['ABI encoding params/values length mismatch.', "Expected length (params): ".concat(expectedLength), "Given length (values): ".concat(givenLength)].join('\n'), { - name: 'AbiEncodingLengthMismatchError' - }]); - } - _inherits(AbiEncodingLengthMismatchError, _BaseError8); - return _createClass(AbiEncodingLengthMismatchError); - }(BaseError); - var BytesSizeMismatchError = /*#__PURE__*/function (_BaseError19) { - function BytesSizeMismatchError(_ref17) { - var expectedSize = _ref17.expectedSize, - givenSize = _ref17.givenSize; - _classCallCheck(this, BytesSizeMismatchError); - return _callSuper(this, BytesSizeMismatchError, ["Expected bytes".concat(expectedSize, ", got bytes").concat(givenSize, "."), { - name: 'BytesSizeMismatchError' - }]); - } - _inherits(BytesSizeMismatchError, _BaseError19); - return _createClass(BytesSizeMismatchError); - }(BaseError); - var UnsupportedPackedAbiType = /*#__PURE__*/function (_BaseError26) { - function UnsupportedPackedAbiType(type) { - _classCallCheck(this, UnsupportedPackedAbiType); - return _callSuper(this, UnsupportedPackedAbiType, ["Type \"".concat(type, "\" is not supported for packed encoding."), { - name: 'UnsupportedPackedAbiType' - }]); - } - _inherits(UnsupportedPackedAbiType, _BaseError26); - return _createClass(UnsupportedPackedAbiType); - }(BaseError); - - var SizeExceedsPaddingSizeError = /*#__PURE__*/function (_BaseError2) { - function SizeExceedsPaddingSizeError(_ref2) { - var size = _ref2.size, - targetSize = _ref2.targetSize, - type = _ref2.type; - _classCallCheck(this, SizeExceedsPaddingSizeError); - return _callSuper(this, SizeExceedsPaddingSizeError, ["".concat(type.charAt(0).toUpperCase()).concat(type.slice(1).toLowerCase(), " size (").concat(size, ") exceeds padding size (").concat(targetSize, ")."), { - name: 'SizeExceedsPaddingSizeError' - }]); - } - _inherits(SizeExceedsPaddingSizeError, _BaseError2); - return _createClass(SizeExceedsPaddingSizeError); - }(BaseError); - - function pad(hexOrBytes) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref.dir, - _ref$size = _ref.size, - size = _ref$size === void 0 ? 32 : _ref$size; - if (typeof hexOrBytes === 'string') return padHex(hexOrBytes, { - dir: dir, - size: size - }); - return padBytes(hexOrBytes, { - dir: dir, - size: size - }); - } - function padHex(hex_) { - var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref2.dir, - _ref2$size = _ref2.size, - size = _ref2$size === void 0 ? 32 : _ref2$size; - if (size === null) return hex_; - var hex = hex_.replace('0x', ''); - if (hex.length > size * 2) throw new SizeExceedsPaddingSizeError({ - size: Math.ceil(hex.length / 2), - targetSize: size, - type: 'hex' - }); - return "0x".concat(hex[dir === 'right' ? 'padEnd' : 'padStart'](size * 2, '0')); - } - function padBytes(bytes) { - var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - dir = _ref3.dir, - _ref3$size = _ref3.size, - size = _ref3$size === void 0 ? 32 : _ref3$size; - if (size === null) return bytes; - if (bytes.length > size) throw new SizeExceedsPaddingSizeError({ - size: bytes.length, - targetSize: size, - type: 'bytes' - }); - var paddedBytes = new Uint8Array(size); - for (var i = 0; i < size; i++) { - var padEnd = dir === 'right'; - paddedBytes[padEnd ? i : size - i - 1] = bytes[padEnd ? i : bytes.length - i - 1]; - } - return paddedBytes; - } - - var IntegerOutOfRangeError = /*#__PURE__*/function (_BaseError) { - function IntegerOutOfRangeError(_ref) { - var max = _ref.max, - min = _ref.min, - signed = _ref.signed, - size = _ref.size, - value = _ref.value; - _classCallCheck(this, IntegerOutOfRangeError); - return _callSuper(this, IntegerOutOfRangeError, ["Number \"".concat(value, "\" is not in safe ").concat(size ? "".concat(size * 8, "-bit ").concat(signed ? 'signed' : 'unsigned', " ") : '', "integer range ").concat(max ? "(".concat(min, " to ").concat(max, ")") : "(above ".concat(min, ")")), { - name: 'IntegerOutOfRangeError' - }]); - } - _inherits(IntegerOutOfRangeError, _BaseError); - return _createClass(IntegerOutOfRangeError); - }(BaseError); - var SizeOverflowError = /*#__PURE__*/function (_BaseError5) { - function SizeOverflowError(_ref2) { - var givenSize = _ref2.givenSize, - maxSize = _ref2.maxSize; - _classCallCheck(this, SizeOverflowError); - return _callSuper(this, SizeOverflowError, ["Size cannot exceed ".concat(maxSize, " bytes. Given size: ").concat(givenSize, " bytes."), { - name: 'SizeOverflowError' - }]); - } - _inherits(SizeOverflowError, _BaseError5); - return _createClass(SizeOverflowError); - }(BaseError); - - function assertSize(hexOrBytes, _ref) { - var size$1 = _ref.size; - if (size(hexOrBytes) > size$1) throw new SizeOverflowError({ - givenSize: size(hexOrBytes), - maxSize: size$1 - }); - } - - var hexes = /*#__PURE__*/Array.from({ - length: 256 - }, function (_v, i) { - return i.toString(16).padStart(2, '0'); - }); - /** - * Encodes a string, number, bigint, or ByteArray into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex - * - Example: https://viem.sh/docs/utilities/toHex#usage - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { toHex } from 'viem' - * const data = toHex('Hello world') - * // '0x48656c6c6f20776f726c6421' - * - * @example - * import { toHex } from 'viem' - * const data = toHex(420) - * // '0x1a4' - * - * @example - * import { toHex } from 'viem' - * const data = toHex('Hello world', { size: 32 }) - * // '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000' - */ - function toHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (typeof value === 'number' || typeof value === 'bigint') return numberToHex(value, opts); - if (typeof value === 'string') { - return stringToHex(value, opts); - } - if (typeof value === 'boolean') return boolToHex(value, opts); - return bytesToHex(value, opts); - } - /** - * Encodes a boolean into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#booltohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(true) - * // '0x1' - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(false) - * // '0x0' - * - * @example - * import { boolToHex } from 'viem' - * const data = boolToHex(true, { size: 32 }) - * // '0x0000000000000000000000000000000000000000000000000000000000000001' - */ - function boolToHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var hex = "0x".concat(Number(value)); - if (typeof opts.size === 'number') { - assertSize(hex, { - size: opts.size - }); - return pad(hex, { - size: opts.size - }); - } - return hex; - } - /** - * Encodes a bytes array into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#bytestohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { bytesToHex } from 'viem' - * const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * // '0x48656c6c6f20576f726c6421' - * - * @example - * import { bytesToHex } from 'viem' - * const data = bytesToHex(Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]), { size: 32 }) - * // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' - */ - function bytesToHex(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var string = ''; - for (var i = 0; i < value.length; i++) { - string += hexes[value[i]]; - } - var hex = "0x".concat(string); - if (typeof opts.size === 'number') { - assertSize(hex, { - size: opts.size - }); - return pad(hex, { - dir: 'right', - size: opts.size - }); - } - return hex; - } - /** - * Encodes a number or bigint into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#numbertohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { numberToHex } from 'viem' - * const data = numberToHex(420) - * // '0x1a4' - * - * @example - * import { numberToHex } from 'viem' - * const data = numberToHex(420, { size: 32 }) - * // '0x00000000000000000000000000000000000000000000000000000000000001a4' - */ - function numberToHex(value_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var signed = opts.signed, - size = opts.size; - var value = BigInt(value_); - var maxValue; - if (size) { - if (signed) maxValue = (1n << BigInt(size) * 8n - 1n) - 1n;else maxValue = Math.pow(2n, BigInt(size) * 8n) - 1n; - } else if (typeof value_ === 'number') { - maxValue = BigInt(Number.MAX_SAFE_INTEGER); - } - var minValue = typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0; - if (maxValue && value > maxValue || value < minValue) { - var suffix = typeof value_ === 'bigint' ? 'n' : ''; - throw new IntegerOutOfRangeError({ - max: maxValue ? "".concat(maxValue).concat(suffix) : undefined, - min: "".concat(minValue).concat(suffix), - signed: signed, - size: size, - value: "".concat(value_).concat(suffix) - }); - } - var hex = "0x".concat((signed && value < 0 ? (1n << BigInt(size * 8)) + BigInt(value) : value).toString(16)); - if (size) return pad(hex, { - size: size - }); - return hex; - } - var encoder$2 = /*#__PURE__*/new TextEncoder(); - /** - * Encodes a UTF-8 string into a hex string - * - * - Docs: https://viem.sh/docs/utilities/toHex#stringtohex - * - * @param value Value to encode. - * @param opts Options. - * @returns Hex value. - * - * @example - * import { stringToHex } from 'viem' - * const data = stringToHex('Hello World!') - * // '0x48656c6c6f20576f726c6421' - * - * @example - * import { stringToHex } from 'viem' - * const data = stringToHex('Hello World!', { size: 32 }) - * // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' - */ - function stringToHex(value_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var value = encoder$2.encode(value_); - return bytesToHex(value, opts); - } - - var encoder$1 = /*#__PURE__*/new TextEncoder(); - /** - * Encodes a UTF-8 string, hex value, bigint, number or boolean to a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes - * - Example: https://viem.sh/docs/utilities/toBytes#usage - * - * @param value Value to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes('Hello world') - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes(420) - * // Uint8Array([1, 164]) - * - * @example - * import { toBytes } from 'viem' - * const data = toBytes(420, { size: 4 }) - * // Uint8Array([0, 0, 1, 164]) - */ - function toBytes$1(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (typeof value === 'number' || typeof value === 'bigint') return numberToBytes(value, opts); - if (typeof value === 'boolean') return boolToBytes(value, opts); - if (isHex(value)) return hexToBytes(value, opts); - return stringToBytes(value, opts); - } - /** - * Encodes a boolean into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#booltobytes - * - * @param value Boolean value to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { boolToBytes } from 'viem' - * const data = boolToBytes(true) - * // Uint8Array([1]) - * - * @example - * import { boolToBytes } from 'viem' - * const data = boolToBytes(true, { size: 32 }) - * // Uint8Array([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, 1]) - */ - function boolToBytes(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var bytes = new Uint8Array(1); - bytes[0] = Number(value); - if (typeof opts.size === 'number') { - assertSize(bytes, { - size: opts.size - }); - return pad(bytes, { - size: opts.size - }); - } - return bytes; - } - // We use very optimized technique to convert hex string to byte array - var charCodeMap = { - zero: 48, - nine: 57, - A: 65, - F: 70, - a: 97, - f: 102 - }; - function charCodeToBase16(_char) { - if (_char >= charCodeMap.zero && _char <= charCodeMap.nine) return _char - charCodeMap.zero; - if (_char >= charCodeMap.A && _char <= charCodeMap.F) return _char - (charCodeMap.A - 10); - if (_char >= charCodeMap.a && _char <= charCodeMap.f) return _char - (charCodeMap.a - 10); - return undefined; - } - /** - * Encodes a hex string into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#hextobytes - * - * @param hex Hex string to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { hexToBytes } from 'viem' - * const data = hexToBytes('0x48656c6c6f20776f726c6421') - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) - * - * @example - * import { hexToBytes } from 'viem' - * const data = hexToBytes('0x48656c6c6f20776f726c6421', { size: 32 }) - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - */ - function hexToBytes(hex_) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var hex = hex_; - if (opts.size) { - assertSize(hex, { - size: opts.size - }); - hex = pad(hex, { - dir: 'right', - size: opts.size - }); - } - var hexString = hex.slice(2); - if (hexString.length % 2) hexString = "0".concat(hexString); - var length = hexString.length / 2; - var bytes = new Uint8Array(length); - for (var index = 0, j = 0; index < length; index++) { - var nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++)); - var nibbleRight = charCodeToBase16(hexString.charCodeAt(j++)); - if (nibbleLeft === undefined || nibbleRight === undefined) { - throw new BaseError("Invalid byte sequence (\"".concat(hexString[j - 2]).concat(hexString[j - 1], "\" in \"").concat(hexString, "\").")); - } - bytes[index] = nibbleLeft * 16 + nibbleRight; - } - return bytes; - } - /** - * Encodes a number into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#numbertobytes - * - * @param value Number to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { numberToBytes } from 'viem' - * const data = numberToBytes(420) - * // Uint8Array([1, 164]) - * - * @example - * import { numberToBytes } from 'viem' - * const data = numberToBytes(420, { size: 4 }) - * // Uint8Array([0, 0, 1, 164]) - */ - function numberToBytes(value, opts) { - var hex = numberToHex(value, opts); - return hexToBytes(hex); - } - /** - * Encodes a UTF-8 string into a byte array. - * - * - Docs: https://viem.sh/docs/utilities/toBytes#stringtobytes - * - * @param value String to encode. - * @param opts Options. - * @returns Byte array value. - * - * @example - * import { stringToBytes } from 'viem' - * const data = stringToBytes('Hello world!') - * // Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]) - * - * @example - * import { stringToBytes } from 'viem' - * const data = stringToBytes('Hello world!', { size: 32 }) - * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - */ - function stringToBytes(value) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var bytes = encoder$1.encode(value); - if (typeof opts.size === 'number') { - assertSize(bytes, { - size: opts.size - }); - return pad(bytes, { - dir: 'right', - size: opts.size - }); - } - return bytes; - } - - function number(n) { - if (!Number.isSafeInteger(n) || n < 0) throw new Error("positive integer expected, not ".concat(n)); - } - // copied from utils - function isBytes$1(a) { - return a instanceof Uint8Array || a != null && _typeof(a) === 'object' && a.constructor.name === 'Uint8Array'; - } - function bytes(b) { - if (!isBytes$1(b)) throw new Error('Uint8Array expected'); - for (var _len = arguments.length, lengths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - lengths[_key - 1] = arguments[_key]; - } - if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error("Uint8Array expected of length ".concat(lengths, ", not of length=").concat(b.length)); - } - function exists(instance) { - var checkFinished = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - if (instance.destroyed) throw new Error('Hash instance has been destroyed'); - if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called'); - } - function output(out, instance) { - bytes(out); - var min = instance.outputLen; - if (out.length < min) { - throw new Error("digestInto() expects output buffer of length at least ".concat(min)); - } - } - - var U32_MASK64 = /* @__PURE__ */BigInt(Math.pow(2, 32) - 1); - var _32n = /* @__PURE__ */BigInt(32); - // We are not using BigUint64Array, because they are extremely slow as per 2022 - function fromBig(n) { - var le = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - if (le) return { - h: Number(n & U32_MASK64), - l: Number(n >> _32n & U32_MASK64) - }; - return { - h: Number(n >> _32n & U32_MASK64) | 0, - l: Number(n & U32_MASK64) | 0 - }; - } - function split(lst) { - var le = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var Ah = new Uint32Array(lst.length); - var Al = new Uint32Array(lst.length); - for (var i = 0; i < lst.length; i++) { - var _fromBig = fromBig(lst[i], le), - h = _fromBig.h, - l = _fromBig.l; - var _ref = [h, l]; - Ah[i] = _ref[0]; - Al[i] = _ref[1]; - } - return [Ah, Al]; - } - // Left rotate for Shift in [1, 32) - var rotlSH = function rotlSH(h, l, s) { - return h << s | l >>> 32 - s; - }; - var rotlSL = function rotlSL(h, l, s) { - return l << s | h >>> 32 - s; - }; - // Left rotate for Shift in (32, 64), NOTE: 32 is special case. - var rotlBH = function rotlBH(h, l, s) { - return l << s - 32 | h >>> 64 - s; - }; - var rotlBL = function rotlBL(h, l, s) { - return h << s - 32 | l >>> 64 - s; - }; - - var u32 = function u32(arr) { - return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4)); - }; - var isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44; - // The byte swap operation for uint32 - var byteSwap = function byteSwap(word) { - return word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff; - }; - // In place byte swap for Uint32Array - function byteSwap32(arr) { - for (var i = 0; i < arr.length; i++) { - arr[i] = byteSwap(arr[i]); - } - } - function utf8ToBytes(str) { - if (typeof str !== 'string') throw new Error("utf8ToBytes expected string, got ".concat(_typeof(str))); - return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809 - } - /** - * Normalizes (non-hex) string or Uint8Array to Uint8Array. - * Warning: when Uint8Array is passed, it would NOT get copied. - * Keep in mind for future mutable operations. - */ - function toBytes(data) { - if (typeof data === 'string') data = utf8ToBytes(data); - bytes(data); - return data; - } - // For runtime check if class implements interface - var Hash = /*#__PURE__*/function () { - function Hash() { - _classCallCheck(this, Hash); - } - return _createClass(Hash, [{ - key: "clone", - value: - // Safe version that clones internal state - function clone() { - return this._cloneInto(); - } - }]); - }(); - function wrapConstructor(hashCons) { - var hashC = function hashC(msg) { - return hashCons().update(toBytes(msg)).digest(); - }; - var tmp = hashCons(); - hashC.outputLen = tmp.outputLen; - hashC.blockLen = tmp.blockLen; - hashC.create = function () { - return hashCons(); - }; - return hashC; - } - - // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size. - // It's called a sponge function. - // Various per round constants calculations - var SHA3_PI = []; - var SHA3_ROTL = []; - var _SHA3_IOTA = []; - var _0n = /* @__PURE__ */BigInt(0); - var _1n = /* @__PURE__ */BigInt(1); - var _2n = /* @__PURE__ */BigInt(2); - var _7n = /* @__PURE__ */BigInt(7); - var _256n = /* @__PURE__ */BigInt(256); - var _0x71n = /* @__PURE__ */BigInt(0x71); - for (var round = 0, R = _1n, x = 1, y = 0; round < 24; round++) { - // Pi - var _ref = [y, (2 * x + 3 * y) % 5]; - x = _ref[0]; - y = _ref[1]; - SHA3_PI.push(2 * (5 * y + x)); - // Rotational - SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64); - // Iota - var t = _0n; - for (var j = 0; j < 7; j++) { - R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n; - if (R & _2n) t ^= _1n << (_1n << /* @__PURE__ */BigInt(j)) - _1n; - } - _SHA3_IOTA.push(t); - } - var _split = /* @__PURE__ */split(_SHA3_IOTA, true), - _split2 = _slicedToArray(_split, 2), - SHA3_IOTA_H = _split2[0], - SHA3_IOTA_L = _split2[1]; - // Left rotation (without 0, 32, 64) - var rotlH = function rotlH(h, l, s) { - return s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s); - }; - var rotlL = function rotlL(h, l, s) { - return s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s); - }; - // Same as keccakf1600, but allows to skip some rounds - function keccakP(s) { - var rounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 24; - var B = new Uint32Array(5 * 2); - // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js) - for (var _round = 24 - rounds; _round < 24; _round++) { - // Theta θ - for (var _x = 0; _x < 10; _x++) B[_x] = s[_x] ^ s[_x + 10] ^ s[_x + 20] ^ s[_x + 30] ^ s[_x + 40]; - for (var _x2 = 0; _x2 < 10; _x2 += 2) { - var idx1 = (_x2 + 8) % 10; - var idx0 = (_x2 + 2) % 10; - var B0 = B[idx0]; - var B1 = B[idx0 + 1]; - var Th = rotlH(B0, B1, 1) ^ B[idx1]; - var Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1]; - for (var _y = 0; _y < 50; _y += 10) { - s[_x2 + _y] ^= Th; - s[_x2 + _y + 1] ^= Tl; - } - } - // Rho (ρ) and Pi (π) - var curH = s[2]; - var curL = s[3]; - for (var _t = 0; _t < 24; _t++) { - var shift = SHA3_ROTL[_t]; - var _Th = rotlH(curH, curL, shift); - var _Tl = rotlL(curH, curL, shift); - var PI = SHA3_PI[_t]; - curH = s[PI]; - curL = s[PI + 1]; - s[PI] = _Th; - s[PI + 1] = _Tl; - } - // Chi (χ) - for (var _y2 = 0; _y2 < 50; _y2 += 10) { - for (var _x3 = 0; _x3 < 10; _x3++) B[_x3] = s[_y2 + _x3]; - for (var _x4 = 0; _x4 < 10; _x4++) s[_y2 + _x4] ^= ~B[(_x4 + 2) % 10] & B[(_x4 + 4) % 10]; - } - // Iota (ι) - s[0] ^= SHA3_IOTA_H[_round]; - s[1] ^= SHA3_IOTA_L[_round]; - } - B.fill(0); - } - var Keccak = /*#__PURE__*/function (_Hash) { - // NOTE: we accept arguments in bytes instead of bits here. - function Keccak(blockLen, suffix, outputLen) { - var _this; - var enableXOF = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; - var rounds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 24; - _classCallCheck(this, Keccak); - _this = _callSuper(this, Keccak); - _this.blockLen = blockLen; - _this.suffix = suffix; - _this.outputLen = outputLen; - _this.enableXOF = enableXOF; - _this.rounds = rounds; - _this.pos = 0; - _this.posOut = 0; - _this.finished = false; - _this.destroyed = false; - // Can be passed from user as dkLen - number(outputLen); - // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes - if (0 >= _this.blockLen || _this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function'); - _this.state = new Uint8Array(200); - _this.state32 = u32(_this.state); - return _this; - } - _inherits(Keccak, _Hash); - return _createClass(Keccak, [{ - key: "keccak", - value: function keccak() { - if (!isLE) byteSwap32(this.state32); - keccakP(this.state32, this.rounds); - if (!isLE) byteSwap32(this.state32); - this.posOut = 0; - this.pos = 0; - } - }, { - key: "update", - value: function update(data) { - exists(this); - var blockLen = this.blockLen, - state = this.state; - data = toBytes(data); - var len = data.length; - for (var pos = 0; pos < len;) { - var take = Math.min(blockLen - this.pos, len - pos); - for (var i = 0; i < take; i++) state[this.pos++] ^= data[pos++]; - if (this.pos === blockLen) this.keccak(); - } - return this; - } - }, { - key: "finish", - value: function finish() { - if (this.finished) return; - this.finished = true; - var state = this.state, - suffix = this.suffix, - pos = this.pos, - blockLen = this.blockLen; - // Do the padding - state[pos] ^= suffix; - if ((suffix & 0x80) !== 0 && pos === blockLen - 1) this.keccak(); - state[blockLen - 1] ^= 0x80; - this.keccak(); - } - }, { - key: "writeInto", - value: function writeInto(out) { - exists(this, false); - bytes(out); - this.finish(); - var bufferOut = this.state; - var blockLen = this.blockLen; - for (var pos = 0, len = out.length; pos < len;) { - if (this.posOut >= blockLen) this.keccak(); - var take = Math.min(blockLen - this.posOut, len - pos); - out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos); - this.posOut += take; - pos += take; - } - return out; - } - }, { - key: "xofInto", - value: function xofInto(out) { - // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF - if (!this.enableXOF) throw new Error('XOF is not possible for this instance'); - return this.writeInto(out); - } - }, { - key: "xof", - value: function xof(bytes) { - number(bytes); - return this.xofInto(new Uint8Array(bytes)); - } - }, { - key: "digestInto", - value: function digestInto(out) { - output(out, this); - if (this.finished) throw new Error('digest() was already called'); - this.writeInto(out); - this.destroy(); - return out; - } - }, { - key: "digest", - value: function digest() { - return this.digestInto(new Uint8Array(this.outputLen)); - } - }, { - key: "destroy", - value: function destroy() { - this.destroyed = true; - this.state.fill(0); - } - }, { - key: "_cloneInto", - value: function _cloneInto(to) { - var blockLen = this.blockLen, - suffix = this.suffix, - outputLen = this.outputLen, - rounds = this.rounds, - enableXOF = this.enableXOF; - to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds)); - to.state32.set(this.state32); - to.pos = this.pos; - to.posOut = this.posOut; - to.finished = this.finished; - to.rounds = rounds; - // Suffix can change in cSHAKE - to.suffix = suffix; - to.outputLen = outputLen; - to.enableXOF = enableXOF; - to.destroyed = this.destroyed; - return to; - } - }]); - }(Hash); - var gen = function gen(suffix, blockLen, outputLen) { - return wrapConstructor(function () { - return new Keccak(blockLen, suffix, outputLen); - }); - }; - /** - * keccak-256 hash function. Different from SHA3-256. - * @param message - that would be hashed - */ - var keccak_256 = /* @__PURE__ */gen(0x01, 136, 256 / 8); - - function keccak256(value, to_) { - var to = to_ || 'hex'; - var bytes = keccak_256(isHex(value, { - strict: false - }) ? toBytes$1(value) : value); - if (to === 'bytes') return bytes; - return toHex(bytes); - } - - var InvalidAddressError = /*#__PURE__*/function (_BaseError) { - function InvalidAddressError(_ref) { - var address = _ref.address; - _classCallCheck(this, InvalidAddressError); - return _callSuper(this, InvalidAddressError, ["Address \"".concat(address, "\" is invalid."), { - metaMessages: ['- Address must be a hex value of 20 bytes (40 hex characters).', '- Address must match its checksum counterpart.'], - name: 'InvalidAddressError' - }]); - } - _inherits(InvalidAddressError, _BaseError); - return _createClass(InvalidAddressError); - }(BaseError); - - /** - * Map with a LRU (Least recently used) policy. - * - * @link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU - */ - var LruMap = /*#__PURE__*/function (_Map) { - function LruMap(size) { - var _this; - _classCallCheck(this, LruMap); - _this = _callSuper(this, LruMap); - Object.defineProperty(_this, "maxSize", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - _this.maxSize = size; - return _this; - } - _inherits(LruMap, _Map); - return _createClass(LruMap, [{ - key: "get", - value: function get(key) { - var value = _superPropGet(LruMap, "get", this, 3)([key]); - if (_superPropGet(LruMap, "has", this, 3)([key]) && value !== undefined) { - this["delete"](key); - _superPropGet(LruMap, "set", this, 3)([key, value]); - } - return value; - } - }, { - key: "set", - value: function set(key, value) { - _superPropGet(LruMap, "set", this, 3)([key, value]); - if (this.maxSize && this.size > this.maxSize) { - var firstKey = this.keys().next().value; - if (firstKey) this["delete"](firstKey); - } - return this; - } - }]); - }(/*#__PURE__*/_wrapNativeSuper(Map)); - - var checksumAddressCache = /*#__PURE__*/new LruMap(8192); - function checksumAddress(address_, - /** - * Warning: EIP-1191 checksum addresses are generally not backwards compatible with the - * wider Ethereum ecosystem, meaning it will break when validated against an application/tool - * that relies on EIP-55 checksum encoding (checksum without chainId). - * - * It is highly recommended to not use this feature unless you - * know what you are doing. - * - * See more: https://github.com/ethereum/EIPs/issues/1121 - */ - chainId) { - if (checksumAddressCache.has("".concat(address_, ".").concat(chainId))) return checksumAddressCache.get("".concat(address_, ".").concat(chainId)); - var hexAddress = chainId ? "".concat(chainId).concat(address_.toLowerCase()) : address_.substring(2).toLowerCase(); - var hash = keccak256(stringToBytes(hexAddress), 'bytes'); - var address = (chainId ? hexAddress.substring("".concat(chainId, "0x").length) : hexAddress).split(''); - for (var i = 0; i < 40; i += 2) { - if (hash[i >> 1] >> 4 >= 8 && address[i]) { - address[i] = address[i].toUpperCase(); - } - if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) { - address[i + 1] = address[i + 1].toUpperCase(); - } - } - var result = "0x".concat(address.join('')); - checksumAddressCache.set("".concat(address_, ".").concat(chainId), result); - return result; - } - - var addressRegex = /^0x[a-fA-F0-9]{40}$/; - /** @internal */ - var isAddressCache = /*#__PURE__*/new LruMap(8192); - function isAddress(address, options) { - var _ref = options !== null && options !== void 0 ? options : {}, - _ref$strict = _ref.strict, - strict = _ref$strict === void 0 ? true : _ref$strict; - var cacheKey = "".concat(address, ".").concat(strict); - if (isAddressCache.has(cacheKey)) return isAddressCache.get(cacheKey); - var result = function () { - if (!addressRegex.test(address)) return false; - if (address.toLowerCase() === address) return true; - if (strict) return checksumAddress(address) === address; - return true; - }(); - isAddressCache.set(cacheKey, result); - return result; - } - - function concatHex(values) { - return "0x".concat(values.reduce(function (acc, x) { - return acc + x.replace('0x', ''); - }, '')); - } - - var arrayRegex = /^(.*)\[([0-9]*)\]$/; - // `bytes`: binary type of `M` bytes, `0 < M <= 32` - // https://regexr.com/6va55 - var bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/; - // `(u)int`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0` - // https://regexr.com/6v8hp - var integerRegex = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/; - - function encodePacked(types, values) { - if (types.length !== values.length) throw new AbiEncodingLengthMismatchError({ - expectedLength: types.length, - givenLength: values.length - }); - var data = []; - for (var i = 0; i < types.length; i++) { - var type = types[i]; - var value = values[i]; - data.push(encode(type, value)); - } - return concatHex(data); - } - function encode(type, value) { - var isArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - if (type === 'address') { - var address = value; - if (!isAddress(address)) throw new InvalidAddressError({ - address: address - }); - return pad(address.toLowerCase(), { - size: isArray ? 32 : null - }); - } - if (type === 'string') return stringToHex(value); - if (type === 'bytes') return value; - if (type === 'bool') return pad(boolToHex(value), { - size: isArray ? 32 : 1 - }); - var intMatch = type.match(integerRegex); - if (intMatch) { - var _intMatch = _slicedToArray(intMatch, 3); - _intMatch[0]; - var baseType = _intMatch[1], - _intMatch$ = _intMatch[2], - bits = _intMatch$ === void 0 ? '256' : _intMatch$; - var size = Number.parseInt(bits) / 8; - return numberToHex(value, { - size: isArray ? 32 : size, - signed: baseType === 'int' - }); - } - var bytesMatch = type.match(bytesRegex); - if (bytesMatch) { - var _bytesMatch = _slicedToArray(bytesMatch, 2); - _bytesMatch[0]; - var _size = _bytesMatch[1]; - if (Number.parseInt(_size) !== (value.length - 2) / 2) throw new BytesSizeMismatchError({ - expectedSize: Number.parseInt(_size), - givenSize: (value.length - 2) / 2 - }); - return pad(value, { - dir: 'right', - size: isArray ? 32 : null - }); - } - var arrayMatch = type.match(arrayRegex); - if (arrayMatch && Array.isArray(value)) { - var _arrayMatch = _slicedToArray(arrayMatch, 2); - _arrayMatch[0]; - var childType = _arrayMatch[1]; - var data = []; - for (var i = 0; i < value.length; i++) { - data.push(encode(childType, value[i], true)); - } - if (data.length === 0) return '0x'; - return concatHex(data); - } - throw new UnsupportedPackedAbiType(type); - } - - function isBytes(value) { - if (!value) return false; - if (_typeof(value) !== 'object') return false; - if (!('BYTES_PER_ELEMENT' in value)) return false; - return value.BYTES_PER_ELEMENT === 1 && value.constructor.name === 'Uint8Array'; - } - - function hashToField(input) { - if (isBytes(input) || isHex(input)) return hashEncodedBytes(input); - return hashString(input); - } - function packAndEncode(input) { - var _input$reduce = input.reduce(function (_ref, _ref2) { - var _ref3 = _slicedToArray(_ref, 2), - types2 = _ref3[0], - values2 = _ref3[1]; - var _ref4 = _slicedToArray(_ref2, 2), - type = _ref4[0], - value = _ref4[1]; - types2.push(type); - values2.push(value); - return [types2, values2]; - }, [[], []]), - _input$reduce2 = _slicedToArray(_input$reduce, 2), - types = _input$reduce2[0], - values = _input$reduce2[1]; - return hashEncodedBytes(encodePacked(types, values)); - } - function hashString(input) { - var bytesInput = buffer.Buffer.from(input); - return hashEncodedBytes(bytesInput); - } - function hashEncodedBytes(input) { - var hash = BigInt(keccak256(input)) >> 8n; - var rawDigest = hash.toString(16); - return { - hash: hash, - digest: "0x".concat(rawDigest.padStart(64, "0")) - }; - } - var generateSignal = function generateSignal(signal) { - if (!signal || typeof signal === "string") return hashToField(signal !== null && signal !== void 0 ? signal : ""); - return packAndEncode(signal.types.map(function (type, index) { - return [type, signal.values[index]]; - })); - }; - var encodeAction = function encodeAction(action) { - if (!action) return ""; - if (typeof action === "string") return action; - return action.types.map(function (type, index) { - return "".concat(type, "(").concat(action.values[index], ")"); - }).join(","); - }; - - var createStoreImpl = function createStoreImpl(createState) { - var state; - var listeners = /* @__PURE__ */new Set(); - var setState = function setState(partial, replace) { - var nextState = typeof partial === "function" ? partial(state) : partial; - if (!Object.is(nextState, state)) { - var previousState = state; - state = (replace != null ? replace : _typeof(nextState) !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState); - listeners.forEach(function (listener) { - return listener(state, previousState); - }); - } - }; - var getState = function getState() { - return state; - }; - var getInitialState = function getInitialState() { - return initialState; - }; - var subscribe = function subscribe(listener) { - listeners.add(listener); - return function () { - return listeners["delete"](listener); - }; - }; - var destroy = function destroy() { - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref) { - var _ref2 = _slicedToArray(_ref, 1), - k = _ref2[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production") { - console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."); - } - listeners.clear(); - }; - var api = { - setState: setState, - getState: getState, - getInitialState: getInitialState, - subscribe: subscribe, - destroy: destroy - }; - var initialState = state = createState(setState, getState, api); - return api; - }; - var createStore = function createStore(createState) { - return createState ? createStoreImpl(createState) : createStoreImpl; - }; - - var ReactExports = {}; - - var emptyModule = /*#__PURE__*/Object.freeze({ - __proto__: null, - 'default': ReactExports - }); - - var withSelector = {exports: {}}; - - var require$$0 = /*@__PURE__*/getAugmentedNamespace(emptyModule); - - var shim = {exports: {}}; - - var useSyncExternalStoreShim_development = {}; - - var hasRequiredUseSyncExternalStoreShim_development; - function requireUseSyncExternalStoreShim_development() { - if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development; - hasRequiredUseSyncExternalStoreShim_development = 1; - { - (function () { - - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); - } - var React = require$$0; - var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; - function error(format) { - { - { - for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; - } - printWarning('error', format, args); - } - } - } - function printWarning(level, format, args) { - // When changing this logic, you might want to also - // update consoleWithStackDev.www.js as well. - { - var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - var stack = ReactDebugCurrentFrame.getStackAddendum(); - if (stack !== '') { - format += '%s'; - args = args.concat([stack]); - } // eslint-disable-next-line react-internal/safe-string-coercion - - var argsWithFormat = args.map(function (item) { - return String(item); - }); // Careful: RN currently depends on this prefix - - argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it - // breaks IE9: https://github.com/facebook/react/issues/13610 - // eslint-disable-next-line react-internal/no-production-logging - - Function.prototype.apply.call(console[level], console, argsWithFormat); - } - } - - /** - * inlined Object.is polyfill to avoid requiring consumers ship their own - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - */ - function is(x, y) { - return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare - ; - } - var objectIs = typeof Object.is === 'function' ? Object.is : is; - - // dispatch for CommonJS interop named imports. - - var useState = React.useState, - useEffect = React.useEffect, - useLayoutEffect = React.useLayoutEffect, - useDebugValue = React.useDebugValue; - var didWarnOld18Alpha = false; - var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works - // because of a very particular set of implementation details and assumptions - // -- change any one of them and it will break. The most important assumption - // is that updates are always synchronous, because concurrent rendering is - // only available in versions of React that also have a built-in - // useSyncExternalStore API. And we only use this shim when the built-in API - // does not exist. - // - // Do not assume that the clever hacks used by this hook also work in general. - // The point of this shim is to replace the need for hacks by other libraries. - - function useSyncExternalStore(subscribe, getSnapshot, - // Note: The shim does not use getServerSnapshot, because pre-18 versions of - // React do not expose a way to check if we're hydrating. So users of the shim - // will need to track that themselves and return the correct value - // from `getSnapshot`. - getServerSnapshot) { - { - if (!didWarnOld18Alpha) { - if (React.startTransition !== undefined) { - didWarnOld18Alpha = true; - error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.'); - } - } - } // Read the current snapshot from the store on every render. Again, this - // breaks the rules of React, and only works here because of specific - // implementation details, most importantly that updates are - // always synchronous. - - var value = getSnapshot(); - { - if (!didWarnUncachedGetSnapshot) { - var cachedValue = getSnapshot(); - if (!objectIs(value, cachedValue)) { - error('The result of getSnapshot should be cached to avoid an infinite loop'); - didWarnUncachedGetSnapshot = true; - } - } - } // Because updates are synchronous, we don't queue them. Instead we force a - // re-render whenever the subscribed state changes by updating an some - // arbitrary useState hook. Then, during render, we call getSnapshot to read - // the current value. - // - // Because we don't actually use the state returned by the useState hook, we - // can save a bit of memory by storing other stuff in that slot. - // - // To implement the early bailout, we need to track some things on a mutable - // object. Usually, we would put that in a useRef hook, but we can stash it in - // our useState hook instead. - // - // To force a re-render, we call forceUpdate({inst}). That works because the - // new object always fails an equality check. - - var _useState = useState({ - inst: { - value: value, - getSnapshot: getSnapshot - } - }), - inst = _useState[0].inst, - forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated - // in the layout phase so we can access it during the tearing check that - // happens on subscribe. - - useLayoutEffect(function () { - inst.value = value; - inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the - // commit phase if there was an interleaved mutation. In concurrent mode - // this can happen all the time, but even in synchronous mode, an earlier - // effect may have mutated the store. - - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - }, [subscribe, value, getSnapshot]); - useEffect(function () { - // Check for changes right before subscribing. Subsequent changes will be - // detected in the subscription handler. - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - var handleStoreChange = function handleStoreChange() { - // TODO: Because there is no cross-renderer API for batching updates, it's - // up to the consumer of this library to wrap their subscription event - // with unstable_batchedUpdates. Should we try to detect when this isn't - // the case and print a warning in development? - // The store changed. Check if the snapshot changed since the last time we - // read from the store. - if (checkIfSnapshotChanged(inst)) { - // Force a re-render. - forceUpdate({ - inst: inst - }); - } - }; // Subscribe to the store and return a clean-up function. - - return subscribe(handleStoreChange); - }, [subscribe]); - useDebugValue(value); - return value; - } - function checkIfSnapshotChanged(inst) { - var latestGetSnapshot = inst.getSnapshot; - var prevValue = inst.value; - try { - var nextValue = latestGetSnapshot(); - return !objectIs(prevValue, nextValue); - } catch (error) { - return true; - } - } - function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) { - // Note: The shim does not use getServerSnapshot, because pre-18 versions of - // React do not expose a way to check if we're hydrating. So users of the shim - // will need to track that themselves and return the correct value - // from `getSnapshot`. - return getSnapshot(); - } - var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); - var isServerEnvironment = !canUseDOM; - var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore; - var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; - useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2; - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); - } - })(); - } - return useSyncExternalStoreShim_development; - } - - var hasRequiredShim; - function requireShim() { - if (hasRequiredShim) return shim.exports; - hasRequiredShim = 1; - (function (module) { - - { - module.exports = requireUseSyncExternalStoreShim_development(); - } - })(shim); - return shim.exports; - } - - var withSelector_development = {}; - - var hasRequiredWithSelector_development; - function requireWithSelector_development() { - if (hasRequiredWithSelector_development) return withSelector_development; - hasRequiredWithSelector_development = 1; - { - (function () { - - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); - } - var React = require$$0; - var shim = requireShim(); - - /** - * inlined Object.is polyfill to avoid requiring consumers ship their own - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - */ - function is(x, y) { - return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare - ; - } - var objectIs = typeof Object.is === 'function' ? Object.is : is; - var useSyncExternalStore = shim.useSyncExternalStore; - - // for CommonJS interop. - - var useRef = React.useRef, - useEffect = React.useEffect, - useMemo = React.useMemo, - useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. - - function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { - // Use this to track the rendered snapshot. - var instRef = useRef(null); - var inst; - if (instRef.current === null) { - inst = { - hasValue: false, - value: null - }; - instRef.current = inst; - } else { - inst = instRef.current; - } - var _useMemo = useMemo(function () { - // Track the memoized state using closure variables that are local to this - // memoized instance of a getSnapshot function. Intentionally not using a - // useRef hook, because that state would be shared across all concurrent - // copies of the hook/component. - var hasMemo = false; - var memoizedSnapshot; - var memoizedSelection; - var memoizedSelector = function memoizedSelector(nextSnapshot) { - if (!hasMemo) { - // The first time the hook is called, there is no memoized result. - hasMemo = true; - memoizedSnapshot = nextSnapshot; - var _nextSelection = selector(nextSnapshot); - if (isEqual !== undefined) { - // Even if the selector has changed, the currently rendered selection - // may be equal to the new selection. We should attempt to reuse the - // current value if possible, to preserve downstream memoizations. - if (inst.hasValue) { - var currentSelection = inst.value; - if (isEqual(currentSelection, _nextSelection)) { - memoizedSelection = currentSelection; - return currentSelection; - } - } - } - memoizedSelection = _nextSelection; - return _nextSelection; - } // We may be able to reuse the previous invocation's result. - - // We may be able to reuse the previous invocation's result. - var prevSnapshot = memoizedSnapshot; - var prevSelection = memoizedSelection; - if (objectIs(prevSnapshot, nextSnapshot)) { - // The snapshot is the same as last time. Reuse the previous selection. - return prevSelection; - } // The snapshot has changed, so we need to compute a new selection. - - // The snapshot has changed, so we need to compute a new selection. - var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data - // has changed. If it hasn't, return the previous selection. That signals - // to React that the selections are conceptually equal, and we can bail - // out of rendering. - - // If a custom isEqual function is provided, use that to check if the data - // has changed. If it hasn't, return the previous selection. That signals - // to React that the selections are conceptually equal, and we can bail - // out of rendering. - if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { - return prevSelection; - } - memoizedSnapshot = nextSnapshot; - memoizedSelection = nextSelection; - return nextSelection; - }; // Assigning this to a constant so that Flow knows it can't change. - - // Assigning this to a constant so that Flow knows it can't change. - var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; - var getSnapshotWithSelector = function getSnapshotWithSelector() { - return memoizedSelector(getSnapshot()); - }; - var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () { - return memoizedSelector(maybeGetServerSnapshot()); - }; - return [getSnapshotWithSelector, getServerSnapshotWithSelector]; - }, [getSnapshot, getServerSnapshot, selector, isEqual]), - getSelection = _useMemo[0], - getServerSelection = _useMemo[1]; - var value = useSyncExternalStore(subscribe, getSelection, getServerSelection); - useEffect(function () { - inst.hasValue = true; - inst.value = value; - }, [value]); - useDebugValue(value); - return value; - } - withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; - /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') { - __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); - } - })(); - } - return withSelector_development; - } - - (function (module) { - - { - module.exports = requireWithSelector_development(); - } - })(withSelector); - var useSyncExternalStoreExports = /*@__PURE__*/getDefaultExportFromCjs(withSelector.exports); - - var useDebugValue = ReactExports.useDebugValue; - var useSyncExternalStoreWithSelector = useSyncExternalStoreExports.useSyncExternalStoreWithSelector; - var didWarnAboutEqualityFn = false; - var identity = function identity(arg) { - return arg; - }; - function useStore(api) { - var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity; - var equalityFn = arguments.length > 2 ? arguments[2] : undefined; - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref) { - var _ref2 = _slicedToArray(_ref, 1), - k = _ref2[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) { - console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"); - didWarnAboutEqualityFn = true; - } - var slice = useSyncExternalStoreWithSelector(api.subscribe, api.getState, api.getServerState || api.getInitialState, selector, equalityFn); - useDebugValue(slice); - return slice; - } - var createImpl = function createImpl(createState) { - if ((_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries({}).filter(function (_ref3) { - var _ref4 = _slicedToArray(_ref3, 1), - k = _ref4[0]; - return /^VITE_/.test(k); - }))), {}, { - NODE_ENV: "product" , - MODE: "product" , - BASE_URL: '/', - DEV: "product" !== 'production', - PROD: "product" === 'production' - }) ? "product" : void 0) !== "production" && typeof createState !== "function") { - console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."); - } - var api = typeof createState === "function" ? createStore(createState) : createState; - var useBoundStore = function useBoundStore(selector, equalityFn) { - return useStore(api, selector, equalityFn); - }; - Object.assign(useBoundStore, api); - return useBoundStore; - }; - var create = function create(createState) { - return createState ? createImpl(createState) : createImpl; - }; - - // src/types/bridge.ts - var AppErrorCodes = /* @__PURE__ */function (AppErrorCodes2) { - AppErrorCodes2["ConnectionFailed"] = "connection_failed"; - AppErrorCodes2["VerificationRejected"] = "verification_rejected"; - AppErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached"; - AppErrorCodes2["CredentialUnavailable"] = "credential_unavailable"; - AppErrorCodes2["MalformedRequest"] = "malformed_request"; - AppErrorCodes2["InvalidNetwork"] = "invalid_network"; - AppErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed"; - AppErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending"; - AppErrorCodes2["UnexpectedResponse"] = "unexpected_response"; - AppErrorCodes2["FailedByHostApp"] = "failed_by_host_app"; - AppErrorCodes2["GenericError"] = "generic_error"; - return AppErrorCodes2; - }(AppErrorCodes || {}); - var VerificationLevel = /* @__PURE__ */function (VerificationLevel2) { - VerificationLevel2["Orb"] = "orb"; - VerificationLevel2["Device"] = "device"; - return VerificationLevel2; - }(VerificationLevel || {}); - - // src/lib/validation.ts - function validate_bridge_url(bridge_url, is_staging) { - try { - new URL(bridge_url); - } catch (e) { - return { - valid: false, - errors: ["Failed to parse Bridge URL."] - }; - } - var test_url = new URL(bridge_url); - var errors = []; - if (is_staging && ["localhost", "127.0.0.1"].includes(test_url.hostname)) { - console.log("Using staging app_id with localhost bridge_url. Skipping validation."); - return { - valid: true - }; - } - if (test_url.protocol !== "https:") { - errors.push("Bridge URL must use HTTPS."); - } - if (test_url.port) { - errors.push("Bridge URL must use the default port (443)."); - } - if (test_url.pathname !== "/") { - errors.push("Bridge URL must not have a path."); - } - if (test_url.search) { - errors.push("Bridge URL must not have query parameters."); - } - if (test_url.hash) { - errors.push("Bridge URL must not have a fragment."); - } - if (!test_url.hostname.endsWith(".worldcoin.org") && !test_url.hostname.endsWith(".toolsforhumanity.com")) { - console.warn("Bridge URL should be a subdomain of worldcoin.org or toolsforhumanity.com. The user's identity wallet may refuse to connect. This is a temporary measure and may be removed in the future."); - } - if (errors.length) { - return { - valid: false, - errors: errors - }; - } - return { - valid: true - }; - } - var DEFAULT_VERIFICATION_LEVEL = "orb" /* Orb */; - var buffer_encode = function buffer_encode(buffer$1) { - return buffer.Buffer.from(buffer$1).toString("base64"); - }; - var buffer_decode = function buffer_decode(encoded) { - return buffer.Buffer.from(encoded, "base64"); - }; - var verification_level_to_credential_types = function verification_level_to_credential_types(verification_level) { - switch (verification_level) { - case "device" /* Device */: - return ["orb" /* Orb */, "device" /* Device */]; - case "orb" /* Orb */: - return ["orb" /* Orb */]; - default: - throw new Error("Unknown verification level: ".concat(verification_level)); - } - }; - var credential_type_to_verification_level = function credential_type_to_verification_level(credential_type) { - switch (credential_type) { - case "orb" /* Orb */: - return "orb" /* Orb */; - case "device" /* Device */: - return "device" /* Device */; - default: - throw new Error("Unknown credential_type: ".concat(credential_type)); - } - }; - - // src/lib/crypto.ts - var encoder = new TextEncoder(); - var decoder = new TextDecoder(); - var generateKey = /*#__PURE__*/function () { - var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { - return _regeneratorRuntime().wrap(function _callee$(_context) { - while (1) switch (_context.prev = _context.next) { - case 0: - _context.t0 = window.crypto.getRandomValues(new Uint8Array(12)); - _context.next = 3; - return window.crypto.subtle.generateKey({ - name: "AES-GCM", - length: 256 - }, true, ["encrypt", "decrypt"]); - case 3: - _context.t1 = _context.sent; - return _context.abrupt("return", { - iv: _context.t0, - key: _context.t1 - }); - case 5: - case "end": - return _context.stop(); - } - }, _callee); - })); - return function generateKey() { - return _ref.apply(this, arguments); - }; - }(); - var exportKey = /*#__PURE__*/function () { - var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) { - return _regeneratorRuntime().wrap(function _callee2$(_context2) { - while (1) switch (_context2.prev = _context2.next) { - case 0: - _context2.t0 = buffer_encode; - _context2.next = 3; - return window.crypto.subtle.exportKey("raw", key); - case 3: - _context2.t1 = _context2.sent; - return _context2.abrupt("return", (0, _context2.t0)(_context2.t1)); - case 5: - case "end": - return _context2.stop(); - } - }, _callee2); - })); - return function exportKey(_x) { - return _ref2.apply(this, arguments); - }; - }(); - var encryptRequest = /*#__PURE__*/function () { - var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, iv, request) { - return _regeneratorRuntime().wrap(function _callee3$(_context3) { - while (1) switch (_context3.prev = _context3.next) { - case 0: - _context3.t0 = buffer_encode(iv); - _context3.t1 = buffer_encode; - _context3.next = 4; - return window.crypto.subtle.encrypt({ - name: "AES-GCM", - iv: iv - }, key, encoder.encode(request)); - case 4: - _context3.t2 = _context3.sent; - _context3.t3 = (0, _context3.t1)(_context3.t2); - return _context3.abrupt("return", { - iv: _context3.t0, - payload: _context3.t3 - }); - case 7: - case "end": - return _context3.stop(); - } - }, _callee3); - })); - return function encryptRequest(_x2, _x3, _x4) { - return _ref3.apply(this, arguments); - }; - }(); - var decryptResponse = /*#__PURE__*/function () { - var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, iv, payload) { - return _regeneratorRuntime().wrap(function _callee4$(_context4) { - while (1) switch (_context4.prev = _context4.next) { - case 0: - _context4.t0 = decoder; - _context4.next = 3; - return window.crypto.subtle.decrypt({ - name: "AES-GCM", - iv: iv - }, key, buffer_decode(payload)); - case 3: - _context4.t1 = _context4.sent; - return _context4.abrupt("return", _context4.t0.decode.call(_context4.t0, _context4.t1)); - case 5: - case "end": - return _context4.stop(); - } - }, _callee4); - })); - return function decryptResponse(_x5, _x6, _x7) { - return _ref4.apply(this, arguments); - }; - }(); - - // src/bridge.ts - var DEFAULT_BRIDGE_URL = "https://bridge.worldcoin.org"; - create(function (set, get) { - return { - iv: null, - key: null, - result: null, - errorCode: null, - requestId: null, - connectorURI: null, - bridge_url: DEFAULT_BRIDGE_URL, - verificationState: "loading_widget" /* PreparingClient */, - createClient: function () { - var _createClient = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) { - var bridge_url, app_id, verification_level, action_description, action, signal, _yield$generateKey, key, iv, validation, res, _yield$res$json, request_id; - return _regeneratorRuntime().wrap(function _callee5$(_context5) { - while (1) switch (_context5.prev = _context5.next) { - case 0: - bridge_url = _ref5.bridge_url, app_id = _ref5.app_id, verification_level = _ref5.verification_level, action_description = _ref5.action_description, action = _ref5.action, signal = _ref5.signal; - _context5.next = 3; - return generateKey(); - case 3: - _yield$generateKey = _context5.sent; - key = _yield$generateKey.key; - iv = _yield$generateKey.iv; - if (!bridge_url) { - _context5.next = 12; - break; - } - validation = validate_bridge_url(bridge_url, app_id.includes("staging")); - if (validation.valid) { - _context5.next = 12; - break; - } - console.error(validation.errors.join("\n")); - set({ - verificationState: "failed" /* Failed */ - }); - throw new Error("Invalid bridge_url. Please check the console for more details."); - case 12: - _context5.t0 = fetch; - _context5.t1 = new URL("/request", bridge_url !== null && bridge_url !== void 0 ? bridge_url : DEFAULT_BRIDGE_URL); - _context5.t2 = { - "Content-Type": "application/json" - }; - _context5.t3 = JSON; - _context5.next = 18; - return encryptRequest(key, iv, JSON.stringify({ - app_id: app_id, - action_description: action_description, - action: encodeAction(action), - signal: generateSignal(signal).digest, - credential_types: verification_level_to_credential_types(verification_level !== null && verification_level !== void 0 ? verification_level : DEFAULT_VERIFICATION_LEVEL), - verification_level: verification_level !== null && verification_level !== void 0 ? verification_level : DEFAULT_VERIFICATION_LEVEL - })); - case 18: - _context5.t4 = _context5.sent; - _context5.t5 = _context5.t3.stringify.call(_context5.t3, _context5.t4); - _context5.t6 = { - method: "POST", - headers: _context5.t2, - body: _context5.t5 - }; - _context5.next = 23; - return (0, _context5.t0)(_context5.t1, _context5.t6); - case 23: - res = _context5.sent; - if (res.ok) { - _context5.next = 27; - break; - } - set({ - verificationState: "failed" /* Failed */ - }); - throw new Error("Failed to create client"); - case 27: - _context5.next = 29; - return res.json(); - case 29: - _yield$res$json = _context5.sent; - request_id = _yield$res$json.request_id; - _context5.t7 = set; - _context5.t8 = iv; - _context5.t9 = key; - _context5.t10 = request_id; - _context5.t11 = bridge_url !== null && bridge_url !== void 0 ? bridge_url : DEFAULT_BRIDGE_URL; - _context5.t12 = "https://worldcoin.org/verify?t=wld&i=".concat(request_id, "&k="); - _context5.t13 = encodeURIComponent; - _context5.next = 40; - return exportKey(key); - case 40: - _context5.t14 = _context5.sent; - _context5.t15 = (0, _context5.t13)(_context5.t14); - _context5.t16 = _context5.t12.concat.call(_context5.t12, _context5.t15).concat(bridge_url && bridge_url !== DEFAULT_BRIDGE_URL ? "&b=".concat(encodeURIComponent(bridge_url)) : ""); - _context5.t17 = { - iv: _context5.t8, - key: _context5.t9, - requestId: _context5.t10, - bridge_url: _context5.t11, - verificationState: "awaiting_connection", - connectorURI: _context5.t16 - }; - (0, _context5.t7)(_context5.t17); - case 45: - case "end": - return _context5.stop(); - } - }, _callee5); - })); - function createClient(_x8) { - return _createClient.apply(this, arguments); - } - return createClient; - }(), - pollForUpdates: function () { - var _pollForUpdates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() { - var key, res, _yield$res$json2, response, status, result; - return _regeneratorRuntime().wrap(function _callee6$(_context6) { - while (1) switch (_context6.prev = _context6.next) { - case 0: - key = get().key; - if (key) { - _context6.next = 3; - break; - } - throw new Error("No keypair found. Please call `createClient` first."); - case 3: - _context6.next = 5; - return fetch(new URL("/response/".concat(get().requestId), get().bridge_url)); - case 5: - res = _context6.sent; - if (res.ok) { - _context6.next = 8; - break; - } - return _context6.abrupt("return", set({ - errorCode: "connection_failed" /* ConnectionFailed */, - verificationState: "failed" /* Failed */ - })); - case 8: - _context6.next = 10; - return res.json(); - case 10: - _yield$res$json2 = _context6.sent; - response = _yield$res$json2.response; - status = _yield$res$json2.status; - if (!(status != "completed" /* Completed */)) { - _context6.next = 15; - break; - } - return _context6.abrupt("return", set({ - verificationState: status == "retrieved" /* Retrieved */ ? "awaiting_app" /* WaitingForApp */ : "awaiting_connection" /* WaitingForConnection */ - })); - case 15: - _context6.t0 = JSON; - _context6.next = 18; - return decryptResponse(key, buffer_decode(response.iv), response.payload); - case 18: - _context6.t1 = _context6.sent; - result = _context6.t0.parse.call(_context6.t0, _context6.t1); - if (!("error_code" in result)) { - _context6.next = 22; - break; - } - return _context6.abrupt("return", set({ - errorCode: result.error_code, - verificationState: "failed" /* Failed */ - })); - case 22: - if ("credential_type" in result) { - result = _objectSpread2({ - verification_level: credential_type_to_verification_level(result.credential_type) - }, result); - } - set({ - result: result, - key: null, - requestId: null, - connectorURI: null, - verificationState: "confirmed" /* Confirmed */ - }); - case 24: - case "end": - return _context6.stop(); - } - }, _callee6); - })); - function pollForUpdates() { - return _pollForUpdates.apply(this, arguments); - } - return pollForUpdates; - }(), - reset: function reset() { - set({ - iv: null, - key: null, - result: null, - errorCode: null, - requestId: null, - connectorURI: null, - verificationState: "loading_widget" /* PreparingClient */ - }); - } - }; - }); - - var _VerificationErrorMes; - (_VerificationErrorMes = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_VerificationErrorMes, AppErrorCodes.VerificationRejected, "You\u2019ve cancelled the request in World App."), AppErrorCodes.MaxVerificationsReached, "You have already verified the maximum number of times for this action."), AppErrorCodes.CredentialUnavailable, "It seems you do not have the verification level required by this app."), AppErrorCodes.MalformedRequest, "There was a problem with this request. Please try again or contact the app owner."), AppErrorCodes.InvalidNetwork, "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details."), AppErrorCodes.InclusionProofFailed, "There was an issue fetching your credential. Please try again."), AppErrorCodes.InclusionProofPending, "Your identity is still being registered. Please wait a few minutes and try again."), AppErrorCodes.UnexpectedResponse, "Unexpected response from your wallet. Please try again."), AppErrorCodes.FailedByHostApp, "Verification failed by the app. Please contact the app owner for details."), AppErrorCodes.GenericError, "Something unexpected went wrong. Please try again."), _defineProperty(_VerificationErrorMes, AppErrorCodes.ConnectionFailed, "Connection to your wallet failed. Please try again.")); - _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "input_error" /* InputError */, "There was a problem with this request. Please try again or contact the app owner."), "payment_rejected" /* PaymentRejected */, "You\u2019ve cancelled the payment in World App."), "invalid_receiver" /* InvalidReceiver */, "The receiver address is invalid. Please contact the app owner."), "insufficient_balance" /* InsufficientBalance */, "You do not have enough balance to complete this transaction."), "transaction_failed" /* TransactionFailed */, "The transaction failed. Please try again."), "generic_error" /* GenericError */, "Something unexpected went wrong. Please try again."), "user_blocked" /* UserBlocked */, "User's region is blocked from making payments."); - _defineProperty(_defineProperty(_defineProperty({}, "malformed_request" /* MalformedRequest */, "Provided parameters in the request are invalid."), "user_rejected" /* UserRejected */, "User rejected the request."), "generic_error" /* GenericError */, "Something unexpected went wrong."); - _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "invalid_operation" /* InvalidOperation */, "Transaction included an operation that was invalid"), "user_rejected" /* UserRejected */, "User rejected the request."), "input_error" /* InputError */, "Invalid payload."), "simulation_failed" /* SimulationFailed */, "The transaction simulation failed."), "transaction_failed" /* TransactionFailed */, "The transaction failed. Please try again later."), "generic_error" /* GenericError */, "Something unexpected went wrong. Please try again."), "disallowed_operation" /* DisallowedOperation */, "The operation requested is not allowed. Please refer to the docs."), "invalid_contract" /* InvalidContract */, "The contract address is not allowed for your application. Please check your developer portal configurations"), "malicious_operation" /* MaliciousOperation */, "The operation requested is considered malicious."); - _defineProperty(_defineProperty(_defineProperty({}, "invalid_message" /* InvalidMessage */, "Invalid message requested"), "user_rejected" /* UserRejected */, "User rejected the request."), "generic_error" /* GenericError */, "Something unexpected went wrong."); - var MiniKitInstallErrorMessage = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "unknown" /* Unknown */, "Failed to install MiniKit."), "already_installed" /* AlreadyInstalled */, "MiniKit is already installed."), "outside_of_worldapp" /* OutsideOfWorldApp */, "MiniApp launched outside of WorldApp."), "not_on_client" /* NotOnClient */, "Window object is not available."), "app_out_of_date" /* AppOutOfDate */, "WorldApp is out of date. Please update the app."); - - // helpers/send-webview-event.ts - var sendWebviewEvent = function sendWebviewEvent(payload) { - if (window.webkit) { - var _window$webkit, _window$webkit$postMe; - (_window$webkit = window.webkit) === null || _window$webkit === void 0 || (_window$webkit = _window$webkit.messageHandlers) === null || _window$webkit === void 0 || (_window$webkit = _window$webkit.minikit) === null || _window$webkit === void 0 || (_window$webkit$postMe = _window$webkit.postMessage) === null || _window$webkit$postMe === void 0 || _window$webkit$postMe.call(_window$webkit, payload); - } else if (window.Android) { - var _window$Android$postM, _window$Android; - (_window$Android$postM = (_window$Android = window.Android).postMessage) === null || _window$Android$postM === void 0 || _window$Android$postM.call(_window$Android, JSON.stringify(payload)); - } - }; - - // types/responses.ts - var ResponseEvent = /* @__PURE__ */function (ResponseEvent2) { - ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action"; - ResponseEvent2["MiniAppPayment"] = "miniapp-payment"; - ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth"; - ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction"; - ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message"; - ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data"; - return ResponseEvent2; - }(ResponseEvent || {}); - _defineProperty(_defineProperty({}, "USDCE" /* USDCE */, 6), "WLD" /* WLD */, 18); - - // helpers/siwe/validate-wallet-auth-command-input.ts - var validateWalletAuthCommandInput = function validateWalletAuthCommandInput(params) { - if (!params.nonce) { - return { - valid: false, - message: "'nonce' is required" - }; - } - if (params.nonce.length < 8) { - return { - valid: false, - message: "'nonce' must be at least 8 characters" - }; - } - if (params.statement && params.statement.includes("\n")) { - return { - valid: false, - message: "'statement' must not contain newlines" - }; - } - if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */new Date()) { - return { - valid: false, - message: "'expirationTime' must be in the future" - }; - } - if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) { - return { - valid: false, - message: "'expirationTime' must be within 7 days" - }; - } - if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) { - return { - valid: false, - message: "'notBefore' must be within 7 days" - }; - } - return { - valid: true - }; - }; - var generateSiweMessage = function generateSiweMessage(siweMessageData) { - var siweMessage = ""; - if (siweMessageData.scheme) { - siweMessage += "".concat(siweMessageData.scheme, "://").concat(siweMessageData.domain, " wants you to sign in with your Ethereum account:\n"); - } else { - siweMessage += "".concat(siweMessageData.domain, " wants you to sign in with your Ethereum account:\n"); - } - if (siweMessageData.address) { - siweMessage += "".concat(siweMessageData.address, "\n"); - } else { - siweMessage += "{address}\n"; - } - siweMessage += "\n"; - if (siweMessageData.statement) { - siweMessage += "".concat(siweMessageData.statement, "\n"); - } - siweMessage += "\n"; - siweMessage += "URI: ".concat(siweMessageData.uri, "\n"); - siweMessage += "Version: ".concat(siweMessageData.version, "\n"); - siweMessage += "Chain ID: ".concat(siweMessageData.chain_id, "\n"); - siweMessage += "Nonce: ".concat(siweMessageData.nonce, "\n"); - siweMessage += "Issued At: ".concat(siweMessageData.issued_at, "\n"); - if (siweMessageData.expiration_time) { - siweMessage += "Expiration Time: ".concat(siweMessageData.expiration_time, "\n"); - } - if (siweMessageData.not_before) { - siweMessage += "Not Before: ".concat(siweMessageData.not_before, "\n"); - } - if (siweMessageData.request_id) { - siweMessage += "Request ID: ".concat(siweMessageData.request_id, "\n"); - } - return siweMessage; - }; - var validatePaymentPayload = function validatePaymentPayload(payload) { - if (payload.tokens.some(function (token) { - return token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1; - })) { - console.error("USDCE amount should be greater than $0.1"); - return false; - } - if (payload.reference.length > 36) { - console.error("Reference must not exceed 36 characters"); - return false; - } - return true; - }; - - // minikit.ts - var sendMiniKitEvent = function sendMiniKitEvent(payload) { - sendWebviewEvent(payload); - }; - var _MiniKit = /*#__PURE__*/function () { - function _MiniKit() { - _classCallCheck(this, _MiniKit); - } - return _createClass(_MiniKit, null, [{ - key: "sendInit", - value: function sendInit() { - sendWebviewEvent({ - command: "init", - payload: { - version: this.MINIKIT_VERSION - } - }); - } - }, { - key: "subscribe", - value: function subscribe(event, handler) { - if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) { - var originalHandler = handler; - var wrappedHandler = function wrappedHandler(payload) { - if (payload.status === "success") { - _MiniKit.walletAddress = payload.address; - } - originalHandler(payload); - }; - this.listeners[event] = wrappedHandler; - } else { - this.listeners[event] = handler; - } - } - }, { - key: "unsubscribe", - value: function unsubscribe(event) { - delete this.listeners[event]; - } - }, { - key: "trigger", - value: function trigger(event, payload) { - if (!this.listeners[event]) { - console.error("No handler for event ".concat(event)); - return; - } - this.listeners[event](payload); - } - }, { - key: "commandsValid", - value: function commandsValid(input) { - var _this = this; - return input.every(function (command) { - return command.supported_versions.includes(_this.commandVersion[command.name]); - }); - } - }, { - key: "install", - value: function install() { - if (typeof window === "undefined" || Boolean(window.MiniKit)) { - return { - success: false, - errorCode: "already_installed" /* AlreadyInstalled */, - errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */] - }; - } - if (!window.WorldApp) { - return { - success: false, - errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */, - errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */] - }; - } - if (!this.commandsValid(window.WorldApp.supported_commands)) { - return { - success: false, - errorCode: "app_out_of_date" /* AppOutOfDate */, - errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */] - }; - } - try { - window.MiniKit = _MiniKit; - this.sendInit(); - } catch (error) { - console.error(MiniKitInstallErrorMessage["unknown" /* Unknown */], error); - return { - success: false, - errorCode: "unknown" /* Unknown */, - errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */] - }; - } - return { - success: true - }; - } - }, { - key: "isInstalled", - value: function isInstalled(debug) { - if (debug) console.log("MiniKit is alive!"); - return Boolean(window.MiniKit); - } - }]); - }(); - _MiniKit.MINIKIT_VERSION = 1; - _MiniKit.commandVersion = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "verify" /* Verify */, 1), "pay" /* Pay */, 1), "wallet-auth" /* WalletAuth */, 1), "send-transaction" /* SendTransaction */, 1), "sign-message" /* SignMessage */, 1), "sign-typed-data" /* SignTypedData */, 1); - _MiniKit.listeners = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "miniapp-verify-action" /* MiniAppVerifyAction */, function miniappVerifyAction() {}), "miniapp-payment" /* MiniAppPayment */, function miniappPayment() {}), "miniapp-wallet-auth" /* MiniAppWalletAuth */, function miniappWalletAuth() {}), "miniapp-send-transaction" /* MiniAppSendTransaction */, function miniappSendTransaction() {}), "miniapp-sign-message" /* MiniAppSignMessage */, function miniappSignMessage() {}), "miniapp-sign-typed-data" /* MiniAppSignTypedData */, function miniappSignTypedData() {}); - _MiniKit.walletAddress = null; - _MiniKit.commands = { - verify: function verify(payload) { - var timestamp = (/* @__PURE__ */new Date()).toISOString(); - var eventPayload = _objectSpread2(_objectSpread2({}, payload), {}, { - signal: payload.signal || "", - verification_level: payload.verification_level || VerificationLevel.Orb, - timestamp: timestamp - }); - sendMiniKitEvent({ - command: "verify" /* Verify */, - version: _MiniKit.commandVersion["verify" /* Verify */], - payload: eventPayload - }); - return eventPayload; - }, - pay: function pay(payload) { - if (typeof window === "undefined") { - console.error("'pay' method is only available in a browser environment."); - return null; - } - if (!validatePaymentPayload(payload)) { - return null; - } - var network = "optimism" /* Optimism */; - var eventPayload = _objectSpread2(_objectSpread2({}, payload), {}, { - network: network - }); - sendMiniKitEvent({ - command: "pay" /* Pay */, - version: _MiniKit.commandVersion["pay" /* Pay */], - payload: eventPayload - }); - return eventPayload; - }, - walletAuth: function walletAuth(payload) { - var _payload$statement, _payload$expirationTi, _payload$expirationTi2, _payload$notBefore$to, _payload$notBefore, _payload$requestId; - if (typeof window === "undefined") { - console.error("'walletAuth' method is only available in a browser environment."); - return null; - } - var validationResult = validateWalletAuthCommandInput(payload); - if (!validationResult.valid) { - console.error("Failed to validate wallet auth input:\n\n -->", validationResult.message); - return null; - } - var protocol = null; - try { - var currentUrl = new URL(window.location.href); - protocol = currentUrl.protocol.split(":")[0]; - } catch (error) { - console.error("Failed to get current URL", error); - return null; - } - var siweMessage = generateSiweMessage({ - scheme: protocol, - domain: window.location.host, - statement: (_payload$statement = payload.statement) !== null && _payload$statement !== void 0 ? _payload$statement : void 0, - uri: window.location.href, - version: 1, - chain_id: 10, - nonce: payload.nonce, - issued_at: (/* @__PURE__ */new Date()).toISOString(), - expiration_time: (_payload$expirationTi = (_payload$expirationTi2 = payload.expirationTime) === null || _payload$expirationTi2 === void 0 ? void 0 : _payload$expirationTi2.toISOString()) !== null && _payload$expirationTi !== void 0 ? _payload$expirationTi : void 0, - not_before: (_payload$notBefore$to = (_payload$notBefore = payload.notBefore) === null || _payload$notBefore === void 0 ? void 0 : _payload$notBefore.toISOString()) !== null && _payload$notBefore$to !== void 0 ? _payload$notBefore$to : void 0, - request_id: (_payload$requestId = payload.requestId) !== null && _payload$requestId !== void 0 ? _payload$requestId : void 0 - }); - var walletAuthPayload = { - siweMessage: siweMessage - }; - sendMiniKitEvent({ - command: "wallet-auth" /* WalletAuth */, - version: _MiniKit.commandVersion["wallet-auth" /* WalletAuth */], - payload: walletAuthPayload - }); - return walletAuthPayload; - }, - sendTransaction: function sendTransaction(payload) { - sendMiniKitEvent({ - command: "send-transaction" /* SendTransaction */, - version: 1, - payload: payload - }); - return payload; - }, - signMessage: function signMessage(payload) { - sendMiniKitEvent({ - command: "sign-message" /* SignMessage */, - version: 1, - payload: payload - }); - return payload; - }, - signTypedData: function signTypedData(payload) { - sendMiniKitEvent({ - command: "sign-typed-data" /* SignTypedData */, - version: 1, - payload: payload - }); - return payload; - } - }; - var MiniKit = _MiniKit; - function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } class Worldapp { @@ -6571,7 +1630,7 @@ };} constructor () { - MiniKit.install(); + worldcoinPrecompiled.MiniKit.install(); this.name = this.constructor.info.name; this.logo = this.constructor.info.logo; this.blockchains = this.constructor.info.blockchains; @@ -6591,7 +1650,7 @@ transaction.nonce = (await this.transactionCount({ blockchain: 'worldchain', address: transaction.from })).toString(); console.log('after nonce transaction', transaction); - MiniKit.subscribe(ResponseEvent.MiniAppSendTransaction, (payload)=> { + worldcoinPrecompiled.MiniKit.subscribe(worldcoinPrecompiled.ResponseEvent.MiniAppSendTransaction, (payload)=> { console.log('payload', payload); if (payload.status == "success") { this.fetchTransaction(transaction, payload).then((transactionHash)=>{ @@ -6606,7 +1665,7 @@ } }); - MiniKit.commands.sendTransaction({ + worldcoinPrecompiled.MiniKit.commands.sendTransaction({ transaction: [ { address: transaction.to, @@ -6676,26 +1735,26 @@ async account() { if(!this.getProvider()) { return undefined } - return MiniKit.walletAddress + return worldcoinPrecompiled.MiniKit.walletAddress } connect() { return new Promise((resolve, reject)=>{ - if(MiniKit.walletAddress) { - return resolve(MiniKit.walletAddress) + if(worldcoinPrecompiled.MiniKit.walletAddress) { + return resolve(worldcoinPrecompiled.MiniKit.walletAddress) } - MiniKit.subscribe(ResponseEvent.MiniAppWalletAuth, async (payload) => { + worldcoinPrecompiled.MiniKit.subscribe(worldcoinPrecompiled.ResponseEvent.MiniAppWalletAuth, async (payload) => { if (payload.status === "error") { return reject() } else { - return resolve(MiniKit.walletAddress) + return resolve(worldcoinPrecompiled.MiniKit.walletAddress) } }); - MiniKit.commands.walletAuth({ + worldcoinPrecompiled.MiniKit.commands.walletAuth({ nonce: crypto.randomUUID().replace(/-/g, ""), expirationTime: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000), notBefore: new Date(new Date().getTime() - 24 * 60 * 60 * 1000), @@ -6730,12 +1789,12 @@ } async transactionCount({ blockchain, address }) { - if(!_optionalChain$1([MiniKit, 'optionalAccess', _9 => _9.walletAddress])) { + if(!_optionalChain$1([worldcoinPrecompiled.MiniKit, 'optionalAccess', _9 => _9.walletAddress])) { return 0 } else { return web3ClientEvm.request({ blockchain: 'worldchain', - address: _optionalChain$1([MiniKit, 'optionalAccess', _10 => _10.walletAddress]), + address: _optionalChain$1([worldcoinPrecompiled.MiniKit, 'optionalAccess', _10 => _10.walletAddress]), api: [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"AddedOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"approvedHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"ApproveHash","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"handler","type":"address"}],"name":"ChangedFallbackHandler","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"guard","type":"address"}],"name":"ChangedGuard","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"threshold","type":"uint256"}],"name":"ChangedThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"module","type":"address"}],"name":"DisabledModule","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"module","type":"address"}],"name":"EnabledModule","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"txHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"payment","type":"uint256"}],"name":"ExecutionFailure","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"module","type":"address"}],"name":"ExecutionFromModuleFailure","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"module","type":"address"}],"name":"ExecutionFromModuleSuccess","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"txHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"payment","type":"uint256"}],"name":"ExecutionSuccess","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"RemovedOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"initiator","type":"address"},{"indexed":false,"internalType":"address[]","name":"owners","type":"address[]"},{"indexed":false,"internalType":"uint256","name":"threshold","type":"uint256"},{"indexed":false,"internalType":"address","name":"initializer","type":"address"},{"indexed":false,"internalType":"address","name":"fallbackHandler","type":"address"}],"name":"SafeSetup","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"msgHash","type":"bytes32"}],"name":"SignMsg","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"addOwnerWithThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"hashToApprove","type":"bytes32"}],"name":"approveHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"approvedHashes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"changeThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"dataHash","type":"bytes32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"bytes","name":"signatures","type":"bytes"},{"internalType":"uint256","name":"requiredSignatures","type":"uint256"}],"name":"checkNSignatures","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"dataHash","type":"bytes32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"name":"checkSignatures","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"prevModule","type":"address"},{"internalType":"address","name":"module","type":"address"}],"name":"disableModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"domainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"enableModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"},{"internalType":"uint256","name":"safeTxGas","type":"uint256"},{"internalType":"uint256","name":"baseGas","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"address","name":"gasToken","type":"address"},{"internalType":"address","name":"refundReceiver","type":"address"},{"internalType":"uint256","name":"_nonce","type":"uint256"}],"name":"encodeTransactionData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"},{"internalType":"uint256","name":"safeTxGas","type":"uint256"},{"internalType":"uint256","name":"baseGas","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"address","name":"gasToken","type":"address"},{"internalType":"addresspayable","name":"refundReceiver","type":"address"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"name":"execTransaction","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"}],"name":"execTransactionFromModule","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"}],"name":"execTransactionFromModuleReturnData","outputs":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getChainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"start","type":"address"},{"internalType":"uint256","name":"pageSize","type":"uint256"}],"name":"getModulesPaginated","outputs":[{"internalType":"address[]","name":"array","type":"address[]"},{"internalType":"address","name":"next","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOwners","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"offset","type":"uint256"},{"internalType":"uint256","name":"length","type":"uint256"}],"name":"getStorageAt","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"},{"internalType":"uint256","name":"safeTxGas","type":"uint256"},{"internalType":"uint256","name":"baseGas","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"address","name":"gasToken","type":"address"},{"internalType":"address","name":"refundReceiver","type":"address"},{"internalType":"uint256","name":"_nonce","type":"uint256"}],"name":"getTransactionHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"isModuleEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"prevOwner","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"removeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"enumEnum.Operation","name":"operation","type":"uint8"}],"name":"requiredTxGas","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"handler","type":"address"}],"name":"setFallbackHandler","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"guard","type":"address"}],"name":"setGuard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_owners","type":"address[]"},{"internalType":"uint256","name":"_threshold","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"address","name":"fallbackHandler","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"uint256","name":"payment","type":"uint256"},{"internalType":"addresspayable","name":"paymentReceiver","type":"address"}],"name":"setup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"signedMessages","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"targetContract","type":"address"},{"internalType":"bytes","name":"calldataPayload","type":"bytes"}],"name":"simulateAndRevert","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"prevOwner","type":"address"},{"internalType":"address","name":"oldOwner","type":"address"},{"internalType":"address","name":"newOwner","type":"address"}],"name":"swapOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}], method: 'nonce' }) @@ -6746,7 +1805,7 @@ return new Promise((resolve, reject)=>{ - MiniKit.subscribe(ResponseEvent.MiniAppSignMessage, async (payload) => { + worldcoinPrecompiled.MiniKit.subscribe(worldcoinPrecompiled.ResponseEvent.MiniAppSignMessage, async (payload) => { if (payload.status === "error") { return reject() } else { @@ -6754,7 +1813,7 @@ } }); - MiniKit.commands.signMessage({ message }); + worldcoinPrecompiled.MiniKit.commands.signMessage({ message }); }) } diff --git a/package.evm.json b/package.evm.json index add2e71..8a187e8 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-wallets-evm", "moduleName": "Web3Wallets", - "version": "17.3.0", + "version": "17.4.0", "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", @@ -28,6 +28,7 @@ "@depay/walletconnect-v2": "^2.12.2", "@depay/web3-blockchains": "^9.6.1", "@depay/web3-client-evm": "^10.19.0", + "@depay/worldcoin-precompiled": "^0.0.32", "ethers": "^5.7.1" }, "engines": { diff --git a/package.json b/package.json index 0a0c532..ab799e1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-wallets", "moduleName": "Web3Wallets", - "version": "17.3.0", + "version": "17.4.0", "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 69edabc..a21fb5b 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-wallets-solana", "moduleName": "Web3Wallets", - "version": "17.3.0", + "version": "17.4.0", "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js",