@oceanprotocol/lib 7.0.0-next.1 → 7.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -1
- package/ComputeExamples.md +1 -1
- package/dist/lib.cjs +3 -3
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.modern.js +3 -3
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.mjs +3 -3
- package/dist/lib.module.mjs.map +1 -1
- package/dist/lib.umd.js +3 -3
- package/dist/lib.umd.js.map +1 -1
- package/dist/types/services/providers/BaseProvider.d.ts +29 -29
- package/dist/types/services/providers/HttpProvider.d.ts +1 -1
- package/dist/types/services/providers/P2pProvider.d.ts +32 -27
- package/package.json +3 -3
package/dist/lib.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@oceanprotocol/contracts/addresses/address.json"),require("fs"),require("ethers"),require("@oasisprotocol/sapphire-paratime"),require("bignumber.js"),require("decimal.js"),require("@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json"),require("@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json"),require("@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json"),require("@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json"),require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json"),require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json"),require("@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json"),require("@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json"),require("cross-fetch"),require("@oceanprotocol/ddo-js"),require("uint8arrays/alloc"),require("uint8arrays/concat"),require("uint8arrays/equals"),require("uint8arrays/from-string"),require("uint8arrays/to-string"),require("jsonwebtoken"),require("eciesjs"),require("libp2p"),require("@chainsafe/libp2p-noise"),require("@chainsafe/libp2p-yamux"),require("@libp2p/websockets"),require("@libp2p/tcp"),require("@libp2p/bootstrap"),require("@libp2p/identify"),require("@libp2p/kad-dht"),require("@multiformats/multiaddr"),require("crypto-js/sha256.js"),require("crypto")):"function"==typeof define&&define.amd?define(["exports","@oceanprotocol/contracts/addresses/address.json","fs","ethers","@oasisprotocol/sapphire-paratime","bignumber.js","decimal.js","@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json","@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json","@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json","@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json","@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json","@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json","@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json","@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json","@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json","cross-fetch","@oceanprotocol/ddo-js","uint8arrays/alloc","uint8arrays/concat","uint8arrays/equals","uint8arrays/from-string","uint8arrays/to-string","jsonwebtoken","eciesjs","libp2p","@chainsafe/libp2p-noise","@chainsafe/libp2p-yamux","@libp2p/websockets","@libp2p/tcp","@libp2p/bootstrap","@libp2p/identify","@libp2p/kad-dht","@multiformats/multiaddr","crypto-js/sha256.js","crypto"],t):t((e||self).lib={},e.DefaultContractsAddresses,e.fs,e.ethers,e.sapphire,e.BigNumber,e.Decimal,e.DispenserAbi,e.FixedRateExchangeAbi,e.FactoryRouter,e.ERC20Template$1,e.ERC20TemplateEnterprise,e.ERC721Template,e.ERC721Factory,e.ERC20Template,e.ERC20Template4,e.AccessList,e.AccessListFactory,e.Escrow,e.ContractABI,e.crossFetch,e.ddoJs,e.alloc$1,e.concat,e.equals$2,e.fromString,e.toString,e.jsonwebtoken,e.eciesjs,e.libp2P,e.libp2pNoise,e.libp2pYamux,e.websockets,e.tcp,e.bootstrap,e.identify,e.kadDht,e.multiaddr,e.sha256$2,e.crypto$1)}(this,function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g,v,p,y,b,P,w,E,S,A,T,x,k,C,O,F,D,j,I,N,L,U,R,M,B){function _(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function G(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var q,V,z=/*#__PURE__*/_(t),H=/*#__PURE__*/_(r),K=/*#__PURE__*/G(o),Z=/*#__PURE__*/_(i),J=/*#__PURE__*/_(s),$=/*#__PURE__*/_(a),W=/*#__PURE__*/_(u),Y=/*#__PURE__*/_(c),X=/*#__PURE__*/_(l),Q=/*#__PURE__*/_(f),ee=/*#__PURE__*/_(h),te=/*#__PURE__*/_(d),re=/*#__PURE__*/_(m),ne=/*#__PURE__*/_(g),oe=/*#__PURE__*/_(v),ie=/*#__PURE__*/_(p),se=/*#__PURE__*/_(y),ae=/*#__PURE__*/_(b),ue=/*#__PURE__*/_(P),ce=/*#__PURE__*/_(k),le=/*#__PURE__*/_(M);e.FileObjectType=void 0,(q=e.FileObjectType||(e.FileObjectType={})).URL="url",q.IPFS="ipfs",q.ARWEAVE="arweave",q.S3="s3",q.FTP="ftp",e.EncryptMethod=void 0,(V=e.EncryptMethod||(e.EncryptMethod={})).AES="AES",V.ECIES="ECIES";var fe,he={DOWNLOAD:"download",ENCRYPT:"encrypt",ENCRYPT_FILE:"encryptFile",DECRYPT_DDO:"decryptDDO",GET_DDO:"getDDO",QUERY:"query",NONCE:"nonce",STATUS:"status",DETAILED_STATUS:"detailedStatus",FIND_DDO:"findDDO",GET_FEES:"getFees",FILE_INFO:"fileInfo",VALIDATE_DDO:"validateDDO",COMPUTE_GET_ENVIRONMENTS:"getComputeEnvironments",COMPUTE_START:"startCompute",FREE_COMPUTE_START:"freeStartCompute",COMPUTE_STOP:"stopCompute",COMPUTE_GET_STATUS:"getComputeStatus",COMPUTE_GET_STREAMABLE_LOGS:"getComputeStreamableLogs",COMPUTE_GET_RESULT:"getComputeResult",COMPUTE_INITIALIZE:"initializeCompute",STOP_NODE:"stopNode",REINDEX_TX:"reindexTx",REINDEX_CHAIN:"reindexChain",HANDLE_INDEXING_THREAD:"handleIndexingThread",COLLECT_FEES:"collectFees",POLICY_SERVER_PASSTHROUGH:"PolicyServerPassthrough",GET_P2P_PEER:"getP2PPeer",GET_P2P_PEERS:"getP2PPeers",GET_P2P_NETWORK_STATS:"getP2PNetworkStats",FIND_PEER:"findPeer",CREATE_AUTH_TOKEN:"createAuthToken",INVALIDATE_AUTH_TOKEN:"invalidateAuthToken",FETCH_CONFIG:"fetchConfig",PUSH_CONFIG:"pushConfig",GET_LOGS:"getLogs",JOBS:"jobs"};function de(e,t){this.v=e,this.k=t}function me(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function ge(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:t}})}return ge=function(e){this.s=e,this.n=e.next},ge.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var r=this.s.return;return void 0===r?Promise.resolve({value:e,done:!0}):t(r.apply(this.s,arguments))},throw:function(e){var r=this.s.return;return void 0===r?Promise.reject(e):t(r.apply(this.s,arguments))}},new ge(e)}function ve(e){return new de(e,0)}function pe(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return me(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?me(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function ye(){return ye=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ye.apply(null,arguments)}function be(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,we(e,t)}function Pe(){Pe=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var i=Object.create((t&&t.prototype instanceof p?t:p).prototype),s=new F(n||[]);return o(i,"_invoke",{value:x(e,r,s)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",d="suspendedYield",m="executing",g="completed",v={};function p(){}function y(){}function b(){}var P={};c(P,s,function(){return this});var w=Object.getPrototypeOf,E=w&&w(w(D([])));E&&E!==r&&n.call(E,s)&&(P=E);var S=b.prototype=p.prototype=Object.create(P);function A(e){["next","throw","return"].forEach(function(t){c(e,t,function(e){return this._invoke(t,e)})})}function T(e,t){function r(o,i,s,a){var u=f(e[o],e,i);if("throw"!==u.type){var c=u.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then(function(e){r("next",e,s,a)},function(e){r("throw",e,s,a)}):t.resolve(l).then(function(e){c.value=e,s(c)},function(e){return r("throw",e,s,a)})}a(u.arg)}var i;o(this,"_invoke",{value:function(e,n){function o(){return new t(function(t,o){r(e,n,t,o)})}return i=i?i.then(o,o):o()}})}function x(t,r,n){var o=h;return function(i,s){if(o===m)throw Error("Generator is already running");if(o===g){if("throw"===i)throw s;return{value:e,done:!0}}for(n.method=i,n.arg=s;;){var a=n.delegate;if(a){var u=k(a,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=m;var c=f(t,r,n);if("normal"===c.type){if(o=n.done?g:d,c.arg===v)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=g,n.method="throw",n.arg=c.arg)}}}function k(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=f(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var s=i.arg;return s?s.done?(r[t.resultName]=s.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):s:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function F(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function D(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=b,o(S,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=c(b,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,c(e,u,"GeneratorFunction")),e.prototype=Object.create(S),e},t.awrap=function(e){return{__await:e}},A(T.prototype),c(T.prototype,a,function(){return this}),t.AsyncIterator=T,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var s=new T(l(e,r,n,o),i);return t.isGeneratorFunction(r)?s:s.next().then(function(e){return e.done?e.value:s.next()})},A(S),c(S,u,"Generator"),c(S,s,function(){return this}),c(S,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=D,F.prototype={constructor:F,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return a.type="throw",a.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return o("end");if(s.tryLoc<=this.prev){var u=n.call(s,"catchLoc"),c=n.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return o(s.catchLoc,!0);if(this.prev<s.finallyLoc)return o(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return o(s.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return o(s.finallyLoc)}}}},abrupt:function(e,t){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"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:D(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function we(e,t){return we=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},we(e,t)}function Ee(e){return function(){return new Se(e.apply(this,arguments))}}function Se(e){var t,r;function n(t,r){try{var i=e[t](r),s=i.value,a=s instanceof de;Promise.resolve(a?s.v:s).then(function(r){if(a){var u="return"===t?"return":"next";if(!s.k||r.done)return n(u,r);r=e[u](r).value}o(i.done?"return":"normal",r)},function(e){n("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?n(t.key,t.arg):r=null}this._invoke=function(e,o){return new Promise(function(i,s){var a={key:e,arg:o,resolve:i,reject:s,next:null};r?r=r.next=a:(t=r=a,n(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}Se.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},Se.prototype.next=function(e){return this._invoke("next",e)},Se.prototype.throw=function(e){return this._invoke("throw",e)},Se.prototype.return=function(e){return this._invoke("return",e)},e.LogLevel=void 0,(fe=e.LogLevel||(e.LogLevel={}))[fe.None=-1]="None",fe[fe.Error=0]="Error",fe[fe.Warn=1]="Warn",fe[fe.Log=2]="Log",fe[fe.Verbose=3]="Verbose";var Ae=/*#__PURE__*/function(){function t(t){this.logLevel=void 0,this.logLevel=t,this.logLevel=t||e.LogLevel.Error}var r=t.prototype;return r.setLevel=function(e){this.logLevel=e},r.bypass=function(){this.dispatch.apply(this,["log",-Infinity].concat([].slice.call(arguments)))},r.debug=function(){this.dispatch.apply(this,["debug",e.LogLevel.Verbose].concat([].slice.call(arguments)))},r.log=function(){this.dispatch.apply(this,["log",e.LogLevel.Log].concat([].slice.call(arguments)))},r.warn=function(){this.dispatch.apply(this,["warn",e.LogLevel.Warn].concat([].slice.call(arguments)))},r.error=function(){this.dispatch.apply(this,["error",e.LogLevel.Error].concat([].slice.call(arguments)))},r.dispatch=function(e,t){var r;this.logLevel>=t&&(r=console)[e].apply(r,[].slice.call(arguments,2))},t}(),Te=new Ae,xe={chainId:null,network:"unknown",nodeUri:"http://127.0.0.1:8545",oceanNodeUri:"http://127.0.0.1:8001",explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},ke=[ye({},xe),ye({},xe,{chainId:8996,network:"development",oceanNodeUri:"http://127.0.0.1:8001",sdk:"evm"}),ye({},xe,{chainId:11155111,network:"sepolia",nodeUri:"https://sepolia.infura.io/v3",explorerUri:"https://sepolia.etherscan.io",gasFeeMultiplier:1.1,sdk:"evm"}),ye({},xe,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),ye({},xe,{chainId:8453,network:"base",nodeUri:"https://mainnet.base.org",explorerUri:"https://etherscan.io",startBlock:30562198,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),ye({},xe,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6,sdk:"evm"}),ye({},xe,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com",sdk:"evm"}),ye({},xe,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1,sdk:"evm"}),ye({},xe,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05,sdk:"evm"}),ye({},xe,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05,sdk:"evm"}),ye({},xe,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05,sdk:"evm"}),ye({},xe,{chainId:100,network:"gen-x-testnet",nodeUri:"https://rpc.genx.minimal-gaia-x.eu",explorerUri:"https://explorer.genx.minimal-gaia-x.eu/",gasFeeMultiplier:1,sdk:"evm"}),ye({},xe,{chainId:10,network:"optimism",nodeUri:"https://mainnet.optimism.io",explorerUri:"https://optimistic.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),ye({},xe,{chainId:11155420,network:"optimism_sepolia",nodeUri:"https://sepolia.optimism.io",explorerUri:"https://sepolia-optimism.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),ye({},xe,{chainId:23294,network:"oasis_sapphire",nodeUri:"https://sapphire.oasis.io",explorerUri:"https://explorer.oasis.io/mainnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),ye({},xe,{chainId:23295,network:"oasis_sapphire_testnet",nodeUri:"https://testnet.sapphire.oasis.dev",explorerUri:"https://explorer.oasis.io/testnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),ye({},xe,{chainId:32456,network:"pontus-x-devnet",nodeUri:"https://rpc.dev.pontus-x.eu",explorerUri:"https://explorer.dev.pontus-x.eu/testnet/pontusx",sdk:"evm"})],Ce=[23294,23295],Oe=function(){return process.env.NODE_ENDPOINT||process.env.NODE_URL?{oceanNodeUri:process.env.NODE_ENDPOINT||process.env.NODE_URL}:{}},Fe=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getAddressesFromEnv=function(e,t){var r;if(t&&t[e]){var n=t[e];r=ye({nftFactoryAddress:n.ERC721Factory,opfCommunityFeeCollector:n.OPFCommunityFeeCollector,fixedRateExchangeAddress:n.FixedPrice,dispenserAddress:n.Dispenser,oceanTokenAddress:n.Ocean,routerFactoryAddress:n.Router,chainId:n.chainId,startBlock:n.startBlock,accessListFactory:n.AccessListFactory,escrow:n.Escrow,EnterpriseFeeCollector:n.EnterpriseFeeCollector},Oe())}else if(z.default[e]){var o=z.default[e];r=ye({nftFactoryAddress:o.ERC721Factory,opfCommunityFeeCollector:o.OPFCommunityFeeCollector,fixedRateExchangeAddress:o.FixedPrice,dispenserAddress:o.Dispenser,oceanTokenAddress:o.Ocean,routerFactoryAddress:o.Router,chainId:o.chainId,startBlock:o.startBlock,accessListFactory:o.AccessListFactory,escrow:o.Escrow,EnterpriseFeeCollector:o.EnterpriseFeeCollector},Oe())}return r},t.getConfig=function(e,t){var r,n="string"==typeof e?"network":"chainId",o=ke.find(function(t){return t[n]===e});if(!o)return Te.error("No config found for given network '"+e+"'"),null;try{r=process.env.ADDRESS_FILE?JSON.parse(H.default.readFileSync(process.env.ADDRESS_FILE,"utf8")):null}catch(e){console.log(e),r=null}var i=this.getAddressesFromEnv(o.network,r);return!i&&Ce.includes(o.chainId)&&(i=this.getAddressesFromEnv(o.network.replace("sapph","saph"),r)),"sdk"in o&&null!==o.sdk||(o.sdk=Ce.includes(o.chainId)?"oasis":"evm"),i&&"accessListFactory"in i&&(o.accessListFactory=i.accessListFactory),o=ye({},o,i),ye({},o,{nodeUri:t?o.nodeUri+"/"+t:o.nodeUri})},e}(),De=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],je=function(e,t,r,n){try{var o=arguments;return Promise.resolve(t.provider.getNetwork()).then(function(i){var s=i.chainId;return Promise.resolve(t.provider.getFeeData()).then(function(t){var i={};if(t.maxPriorityFeePerGas){var a=t.maxPriorityFeePerGas.toString(),u=t.maxFeePerGas.toString();r>1&&(a=Math.round(Number(t.maxPriorityFeePerGas)*r).toString(),u=Math.round(Number(t.maxFeePerGas)*r).toString()),i={maxPriorityFeePerGas:(Number(s)===Ge||Number(s)===_e)&&Number(a)<Re?Re:Number(s)===qe&&Number(a)<Me?Me:Ce.includes(Number(s))&&Number(a)<Be?Be:Number(a),maxFeePerGas:(Number(s)===Ge||Number(s)===_e)&&Number(u)<Re?Re:Number(s)===qe&&Number(u)<Me?Me:Ce.includes(Number(s))&&Number(u)<Be?Be:Number(u)}}else i={gasPrice:t.gasPrice};return i.gasLimit=BigInt(new Z.default(e).plus(20000n).toString()),function(e,t){try{var r=Promise.resolve(n.apply(void 0,[].slice.call(o,4).concat([i]))).then(function(e){return Promise.resolve(e.wait()).then(function(){return e})})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){return Te.error("Send tx error: ",e),null})})})}catch(e){return Promise.reject(e)}},Ie=function(e,t,r,o){try{var i=function(e){return"0"===e&&(e=18),n.parseUnits(r,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(Le(e,t)).then(i))}catch(e){return Promise.reject(e)}},Ne=function(e,t,r,o){try{var i=function(e){return"0"===e&&(e=18),n.formatUnits(r,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(Le(e,t)).then(i))}catch(e){return Promise.reject(e)}},Le=function(e,t){try{var r=new n.ethers.Contract(t,De,e);return Promise.resolve(r.decimals())}catch(e){return Promise.reject(e)}},Ue=function(e,t){try{return Promise.resolve(e.provider.getFeeData()).then(function(e){var r=BigInt(e.gasPrice.toString());return t?(r*BigInt(t)).toString(10):r.toString()})}catch(e){return Promise.reject(e)}},Re=3e10,Me=4e9,Be=1e10,_e=137,Ge=80001,qe=11155111;function Ve(e,t){return e}function ze(e,t){if(e&&e.logs)return e.logs.filter(function(e){return e instanceof n.EventLog&&e.eventName===t})[0]}var He=/*#__PURE__*/function(){function e(e,t,r,n){this.signer=void 0,this.config=void 0,this.abi=void 0,this.signer=e,this.config=r||(new Fe).getConfig(t),this.abi=n||this.getDefaultAbi()}var t=e.prototype;return t.getSignerAccordingSdk=function(){return this.config&&"sdk"in this.config&&"oasis"===this.config.sdk?K.wrap(this.signer):this.signer},t.amountToUnits=function(e,t,r){try{return Promise.resolve(Ie(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.unitsToAmount=function(e,t,r){try{return Promise.resolve(Ne(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.getFairGasPrice=function(){try{var e;return Promise.resolve(Ue(this.signer,null==(e=this.config)?void 0:e.gasFeeMultiplier))}catch(e){return Promise.reject(e)}},t.getContract=function(e,t){if(!e)throw new Error("Contract address is required but not provided");return Ve(new n.ethers.Contract(e,new n.ethers.Interface(JSON.stringify(t||this.abi)),this.signer))},e}(),Ke=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,r,n,o,i)||this).address=void 0,s.contract=void 0,s.address=t,s.contract=s.getContract(s.address),s}return be(t,e),t}(He),Ze=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return $.default.abi},r.status=function(e){try{var t=this;return Promise.resolve(t.contract.status(e)).then(function(e){if(!e)throw new Error("Np dispenser found for the given datatoken address");var r=e.isMinter,n=e.owner,o=e.active;return Promise.resolve(t.unitsToAmount(null,e.maxTokens,18)).then(function(i){return Promise.resolve(t.unitsToAmount(null,e.maxBalance,18)).then(function(s){return Promise.resolve(t.unitsToAmount(null,e.balance,18)).then(function(t){return{active:o,owner:n,isMinter:r,maxTokens:i,maxBalance:s,balance:t,allowedSwapper:e.allowedSwapper}})})})})}catch(e){return Promise.reject(e)}},r.create=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.contract.create.estimateGas(e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o)).then(function(a){var u;return i?a:Promise.resolve(je(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.create,e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.contract.activate.estimateGas(e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18))).then(function(i){var s;return n?i:Promise.resolve(je(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.activate,e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18)))})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.contract.deactivate.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.deactivate,e))})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.dispense=function(e,t,r,n){void 0===t&&(t="1");try{var o=this;return Promise.resolve(o.contract.dispense.estimateGas(e,o.amountToUnits(null,t,18),r)).then(function(i){var s;return n?i:Promise.resolve(je(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.dispense,e,o.amountToUnits(null,t,18),r))})}catch(e){return Promise.reject(e)}},r.ownerWithdraw=function(e,t){try{var r=this;return Promise.resolve(r.contract.ownerWithdraw.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.ownerWithdraw,e))})}catch(e){return Promise.reject(e)}},r.isDispensable=function(e,t,r,n){void 0===n&&(n="1");try{return Promise.resolve(this.status(e)).then(function(o){return!!o&&!1!==o.active&&Promise.resolve(t.balance(e,r)).then(function(e){return!(new J.default(e).greaterThanOrEqualTo(o.maxBalance)||new J.default(String(n)).greaterThan(o.maxTokens)||!new J.default(o.balance).greaterThanOrEqualTo(n)&&!0!==o.isMinter)})})}catch(e){return Promise.reject(e)}},t}(Ke),Je="0x0000000000000000000000000000000000000000",$e=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return W.default.abi},r.generateExchangeId=function(e,t){try{return Promise.resolve(this.contract.generateExchangeId(e,t))}catch(e){return Promise.reject(e)}},r.buyDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Je),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.buyDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(je(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.buyDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.sellDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Je),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.sellDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(je(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.sellDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.getNumberOfExchanges=function(){try{return Promise.resolve(this.contract.getNumberOfExchanges()).then(Number)}catch(e){return Promise.reject(e)}},r.setRate=function(e,t,r){try{var n=this,o=n.contract.setRate,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.setRate,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(je(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.getRate=function(e){try{var t=this;return Promise.resolve(t.contract.getRate(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDatatokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getDTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.datatoken,r,Number(e.dtDecimals)))})})}catch(e){return Promise.reject(e)}},r.getBasetokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getBTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.baseToken,r,Number(e.btDecimals)))})})}catch(e){return Promise.reject(e)}},r.getAllowedSwapper=function(e){try{return Promise.resolve(this.contract.getAllowedSwapper(e))}catch(e){return Promise.reject(e)}},r.calcBaseInGivenDatatokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseInGivenOutDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e.baseTokenAmount,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.unitsToAmount(o.baseToken,e.publishMarketFeeAmount,Number(o.btDecimals))).then(function(r){return Promise.resolve(n.unitsToAmount(o.baseToken,e.oceanFeeAmount,Number(o.btDecimals))).then(function(i){return Promise.resolve(n.unitsToAmount(o.baseToken,e.consumeMarketFeeAmount,Number(o.btDecimals))).then(function(e){return{baseTokenAmount:t,marketFeeAmount:r,oceanFeeAmount:i,consumeMarketFeeAmount:e}})})})})})})})})}catch(e){return Promise.reject(e)}},r.getAmountBasetokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseOutGivenInDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e[0],Number(o.btDecimals)))})})})})}catch(e){return Promise.reject(e)}},r.getExchange=function(e){try{var t=this;return Promise.resolve(t.contract.getExchange(e)).then(function(r){var n=r.btDecimals.toString(),o=r.dtDecimals.toString(),i=r.allowedSwapper,s=r.exchangeOwner,a=r.withMint,u=r.baseToken,c=r.datatoken,l=r.active;return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtBalance,Number(r.dtDecimals))).then(function(f){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btBalance,Number(r.btDecimals))).then(function(h){return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtSupply,Number(r.dtDecimals))).then(function(d){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btSupply,Number(r.btDecimals))).then(function(m){return Promise.resolve(t.unitsToAmount(null,r.fixedRate,18)).then(function(t){return{active:l,datatoken:c,baseToken:u,withMint:a,exchangeOwner:s,allowedSwapper:i,dtDecimals:o,btDecimals:n,dtBalance:f,btBalance:h,dtSupply:d,btSupply:m,fixedRate:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getFeesInfo=function(e){try{var t=this;return Promise.resolve(t.contract.getFeesInfo(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(n){return Promise.resolve(t.unitsToAmount(null,r.opcFee.toString(),18)).then(function(o){return Promise.resolve(t.unitsToAmount(null,r.marketFee.toString(),18)).then(function(i){var s=r.marketFeeCollector;return Promise.resolve(t.unitsToAmount(n.baseToken,r.marketFeeAvailable,Number(n.btDecimals))).then(function(a){return Promise.resolve(t.unitsToAmount(n.baseToken,r.oceanFeeAvailable,Number(n.btDecimals))).then(function(t){return{opcFee:o,marketFee:i,marketFeeCollector:s,marketFeeAvailable:a,oceanFeeAvailable:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getExchanges=function(){try{return Promise.resolve(this.contract.getExchanges())}catch(e){return Promise.reject(e)}},r.isActive=function(e){try{return Promise.resolve(this.contract.isActive(e))}catch(e){return Promise.reject(e)}},r.activateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!0)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!0))}):null})}catch(e){return Promise.reject(e)}},r.deactivateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!1)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!1))}):null})}catch(e){return Promise.reject(e)}},r.collectBasetokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.baseToken,t,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.contract.collectBT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectBT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectDatatokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.contract.collectDT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectDT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectMarketFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectMarketFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectMarketFee,e))}):null})}catch(e){return Promise.reject(e)}},r.collectOceanFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectOceanFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectOceanFee,e))}):null})}catch(e){return Promise.reject(e)}},r.getOPCCollector=function(){try{return Promise.resolve(this.contract.opcCollector())}catch(e){return Promise.reject(e)}},r.getRouter=function(){try{return Promise.resolve(this.contract.router())}catch(e){return Promise.reject(e)}},r.getExchangeOwner=function(e){try{return Promise.resolve(this.getExchange(e)).then(function(e){return e.exchangeOwner})}catch(e){return Promise.reject(e)}},r.updateMarketFee=function(e,t,r){try{var n=this,o=n.contract.updateMarketFee,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.updateMarketFee,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(je(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.updateMarketFeeCollector=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.updateMarketFeeCollector.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.updateMarketFeeCollector,e,t))})}catch(e){return Promise.reject(e)}},t}(Ke),We=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return Y.default.abi},r.buyDatatokenBatch=function(e,t){try{var r=this;return Promise.resolve(r.contract.buyDTBatch.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.buyDTBatch,e))})}catch(e){return Promise.reject(e)}},r.isApprovedToken=function(e){try{return Promise.resolve(this.contract.isApprovedToken(e))}catch(e){return Promise.reject(e)}},r.isFixedPrice=function(e){try{return Promise.resolve(this.contract.isFixedRateContract(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.routerOwner())}catch(e){return Promise.reject(e)}},r.getNFTFactory=function(){try{return Promise.resolve(this.contract.factory())}catch(e){return Promise.reject(e)}},r.addApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.removeApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.addFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.removeFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.addDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.removeDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.getOPCFee=function(e){try{return Promise.resolve(this.contract.getOPCFee(e)).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentOPCFee=function(){try{return Promise.resolve(this.contract.swapOceanFee()).then(Number)}catch(e){return Promise.reject(e)}},r.updateOPCFee=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getOwner()).then(function(a){if(a!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(s.contract.updateOPCFee.estimateGas(t,r,n,o)).then(function(e){var a;return i?e:Promise.resolve(je(e,s.getSignerAccordingSdk(),null==(a=s.config)?void 0:a.gasFeeMultiplier,s.contract.updateOPCFee,t,r,n,o))})})}catch(e){return Promise.reject(e)}},t}(Ke),Ye={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function Xe(e){var t=e||Ye,r=Math.floor(Math.random()*t.adjectives.length),n=Math.floor(Math.random()*t.nouns.length),o=Math.floor(100*Math.random()),i=t.adjectives[r].replace(/^\w/,function(e){return e.toUpperCase()}),s=t.nouns[n].replace(/^\w/,function(e){return e.toUpperCase()});return{name:i+" "+s+" Token",symbol:(i.substring(0,3)+s.substring(0,3)).toUpperCase()+"-"+o}}function Qe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var et=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return te.default.abi},r.createNFT=function(e,t){try{var r=this;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){var n=Xe(),o=n.symbol;e.name=n.name,e.symbol=o}var i=e.templateIndex;return Promise.resolve(r.getCurrentNFTTemplateCount()).then(function(n){if(i>n)throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");return Promise.resolve(r.getNFTTemplate(e.templateIndex)).then(function(n){if(!1===n.isActive)throw new Error("Template is not active");return Promise.resolve(r.contract.deployERC721Contract.estimateGas(e.name,e.symbol,e.templateIndex,Je,Je,e.tokenURI,e.transferable,e.owner)).then(function(n){return t?n:Qe(function(){var t;return Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(t=r.config)?void 0:t.gasFeeMultiplier,r.contract.deployERC721Contract,e.name,e.symbol,e.templateIndex,Je,Je,e.tokenURI,e.transferable,e.owner)).then(function(e){if(!e){var t="Tx for deploying new NFT contract does not exist or status is not successful.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return ze(e,"NFTCreated").args[0]})})},function(e){console.error("Creation of NFT failed: "+e)})})})})}catch(e){return Promise.reject(e)}},r.getCurrentNFTCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentTokenCount=function(){try{return Promise.resolve(this.contract.getCurrentTokenCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getCurrentNFTTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentTokenTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getNFTTemplate=function(e){try{var t=this;return Promise.resolve(t.getCurrentNFTTemplateCount()).then(function(r){if(e>r)throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");return Promise.resolve(t.contract.getNFTTemplate(e))})}catch(e){return Promise.reject(e)}},r.getTokenTemplate=function(e){try{return Promise.resolve(this.contract.getTokenTemplate(e))}catch(e){return Promise.reject(e)}},r.checkDatatoken=function(e){try{return Promise.resolve(this.contract.erc20List(e))}catch(e){return Promise.reject(e)}},r.checkNFT=function(e){try{return Promise.resolve(this.contract.erc721List(e))}catch(e){return Promise.reject(e)}},r.addNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Je)throw new Error("Template cannot be ZERO address");return Promise.resolve(n.contract.add721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.add721TokenTemplate,t))})})}catch(e){return Promise.reject(e)}},r.disableNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.disable721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disable721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},r.reactivateNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.reactivate721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivate721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},r.addTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Je)throw new Error("Template cannot be address ZERO");return Promise.resolve(n.contract.addTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addTokenTemplate,t))})})}catch(e){return Promise.reject(e)}},r.disableTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!1===e.isActive)throw new Error("Template is already disabled");return Promise.resolve(n.contract.disableTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disableTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},r.reactivateTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!0===e.isActive)throw new Error("Template is already active");return Promise.resolve(n.contract.reactivateTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivateTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},r.startMultipleTokenOrder=function(e,t){try{var r=this;if(e.length>50)throw new Error("Too many orders");return Promise.resolve(r.contract.startMultipleTokenOrder.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.startMultipleTokenOrder,e))})}catch(e){return Promise.reject(e)}},r.createNftWithDatatoken=function(e,t,r){try{var n=this;return Promise.resolve(n.getErcCreationParams(t)).then(function(t){return Promise.resolve(n.contract.createNftWithErc20.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.createNftWithErc20,e,t))})})}catch(e){return Promise.reject(e)}},r.createNftWithDatatokenWithFixedRate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.getFreCreationParams(r)).then(function(r){return Promise.resolve(o.contract.createNftWithErc20WithFixedRate.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(je(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithFixedRate,e,t,r))})})})}catch(e){return Promise.reject(e)}},r.createNftWithDatatokenWithDispenser=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.amountToUnits(null,r.maxBalance,18)).then(function(i){return r.maxBalance=i,Promise.resolve(o.amountToUnits(null,r.maxTokens,18)).then(function(i){return r.maxTokens=i,Promise.resolve(o.contract.createNftWithErc20WithDispenser.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(je(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithDispenser,e,t,r))})})})})}catch(e){return Promise.reject(e)}},r.getErcCreationParams=function(e){try{var t,r,o=function(){var o=[e.minter,e.paymentCollector,e.mpFeeAddress,e.feeToken];e.filesObject&&(e.accessListFactory&&o.push(e.accessListFactory),e.allowAccessList&&o.push(e.allowAccessList),e.denyAccessList&&o.push(e.denyAccessList));var s=[e.name||t,e.symbol||r],u=e.templateIndex;return Promise.resolve(i.amountToUnits(null,e.cap,18)).then(function(t){return Promise.resolve(i.amountToUnits(null,e.feeAmount,a)).then(function(r){return{templateIndex:u,strings:s,addresses:o,uints:[t,r],bytess:e.filesObject?[n.toUtf8Bytes(JSON.stringify(e.filesObject))]:[]}})})},i=this;if(!e.name||!e.symbol){var s=Xe();t=s.name,r=s.symbol}var a=18,u=function(){if(e.feeToken!==Je){var t=Qe(function(){return Promise.resolve(Le(i.signer,e.feeToken)).then(function(e){a=e})},function(e){Te.error("getTokenDecimals error",e)});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(u&&u.then?u.then(o):o())}catch(e){return Promise.reject(e)}},r.getFreCreationParams=function(e){try{var t=this;e.allowedConsumer||(e.allowedConsumer=Je);var r=!1===e.withMint?0:1,n=[e.baseTokenAddress,e.owner,e.marketFeeCollector,e.allowedConsumer],o=e.fixedRateAddress,i=e.datatokenDecimals,s=e.baseTokenDecimals;return Promise.resolve(t.amountToUnits(null,e.fixedRate,e.datatokenDecimals)).then(function(a){return Promise.resolve(t.amountToUnits(null,e.marketFee,e.datatokenDecimals)).then(function(e){return{fixedPriceAddress:o,addresses:n,uints:[s,i,a,e,r]}})})}catch(e){return Promise.reject(e)}},t}(Ke);function tt(e,t,r){if(!e.s){if(r instanceof rt){if(!r.s)return void(r.o=tt.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(tt.bind(null,e,t),tt.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var rt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{tt(n,1,i(this.v))}catch(e){tt(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?tt(n,1,t?t(o):o):r?tt(n,1,r(o)):tt(n,2,o)}catch(e){tt(n,2,e)}},n},e}();function nt(e){return e instanceof rt&&1&e.s}var ot=function(e,t,r,o){try{var i="number"==typeof r,s=new et(t,e,o);return Promise.resolve(s.getCurrentTokenTemplateCount()).then(function(t){var o;function a(e){return o?e:-1}var u=1,c=function(e,t,r){for(var n;;){var o=e();if(nt(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!nt(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!nt(s)){n=2;break}}}var a=new rt,u=tt.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(f)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!nt(s))return void s.then(f).then(void 0,u);if(!(o=e())||nt(o)&&!o.v)return void tt(a,1,i);if(o.then)return void o.then(l).then(void 0,u);nt(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):tt(a,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):tt(a,1,i)}}(function(){return!o&&u<=t},function(){return u++},function(){return Promise.resolve(s.getTokenTemplate(u)).then(function(t){var s=new n.ethers.Contract(t.templateAddress,re.default.abi,e);return i?Promise.resolve(s.getId()).then(function(e){if(t.isActive&&e.toString()===r.toString())return o=1,u}):t.isActive&&t.templateAddress===r.toString()?(o=1,u):void 0})});return c&&c.then?c.then(a):a(c)})}catch(e){return Promise.reject(e)}};function it(){try{if(process.env.ADDRESS_FILE){var e=H.default.readFileSync(process.env.ADDRESS_FILE,"utf8");return JSON.parse(e)}return z.default}catch(e){return z.default}}function st(e){try{var t=it();if(t)for(var r=Object.keys(t),n=0,o=r;n<o.length;n++){var i=o[n];if(t[i].chainId===e)return t[i]}}catch(e){console.error(e)}return null}var at=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ee.default.abi},r.createDatatoken=function(e,t,r,o,i,s,a,u,c,l,f,h,d,m,g,v){try{var p=this;return Promise.resolve(p.getNftPermissions(e,t)).then(function(t){if(!0!==t.deployERC20)throw new Error("Caller is not DatatokenDeployer");if(f||(f=1),!c||!l){var y=Xe();c=y.name,l=y.symbol}var b=p.getContract(e);if(!p.signer.provider)throw new Error("Provider is required but not available");return Promise.resolve(p.signer.provider.getNetwork()).then(function(e){var t=e.chainId;function y(){var e=b.createERC20,t=e.estimateGas,y=[c,l],P=f;return Promise.resolve(p.amountToUnits(null,u,18)).then(function(w){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(E){return Promise.resolve(t.call(e,P,y,[r,o,i,s],[w,E],[])).then(function(e){var t;if(v)return e;var y=[r,o,i,s];d&&(y.push(d.toLowerCase()),y.push(m?m.toLowerCase():Je),y.push(g||Je));var P=[c,l],w=f,E=b.createERC20,S=null==(t=p.config)?void 0:t.gasFeeMultiplier,A=p.getSignerAccordingSdk();return Promise.resolve(p.amountToUnits(null,u,18)).then(function(t){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(r){return Promise.resolve(je(e,A,S,E,w,P,y,[t,r],h?[n.toUtf8Bytes(h)]:[])).then(function(e){return Promise.resolve(e.wait()).then(function(e){var t=ze(e,"TokenCreated");return null==t?void 0:t.args[0]})})})})})})})}var P=st(Number(t)),w=function(){if(h)return Promise.resolve(ot(p.signer,P.ERC721Factory,4,Number(t))).then(function(e){f=e})}();return w&&w.then?w.then(y):y()})})}catch(e){return Promise.reject(e)}},r.addManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.addManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addManager,r))})})}catch(e){return Promise.reject(e)}},r.removeManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.removeManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeManager,r))})})}catch(e){return Promise.reject(e)}},r.addDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToCreateERC20List,r))})})}catch(e){return Promise.reject(e)}},r.removeDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t===r&&!0!==e.deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");return Promise.resolve(i.removeFromCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromCreateERC20List,r))})}var u=!0!==s.manager;return u||t!==r?a(u||t===r&&o.getNftPermissions(e,t)):Promise.resolve(u||t===r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.addMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToMetadataList,r))})})}catch(e){return Promise.reject(e)}},r.removeMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");return Promise.resolve(i.removeFromMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromMetadataList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.addStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addTo725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addTo725StoreList,r))})})}catch(e){return Promise.reject(e)}},r.removeStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.store)throw new Error("Caller is not Manager nor storeUpdater");return Promise.resolve(i.removeFrom725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFrom725StoreList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.cleanPermissions=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(n.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(o.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.cleanPermissions))})})}catch(e){return Promise.reject(e)}},r.transferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.transferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(je(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.transferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},r.safeTransferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.safeTransferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(je(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.safeTransferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},r.setMetadata=function(e,t,r,n,o,i,s,a,u,c){try{var l=this,f=l.getContract(e);return u||(u=[]),Promise.resolve(l.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=n;if(null!=n&&n.includes("/p2p/")){var h,d=n.match(/\/p2p\/([^/]+)/);t=null!=(h=null==d?void 0:d[1])?h:n}return Promise.resolve(f.setMetaData.estimateGas(r,t,o,i,s,a,u)).then(function(e){var n;return c?e:Promise.resolve(je(e,l.signer,null==(n=l.config)?void 0:n.gasFeeMultiplier,f.setMetaData,r,t,o,i,s,a,u))})})}catch(e){return Promise.reject(e)}},r.setMetadataAndTokenURI=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=ye({},r,{metadataProofs:r.metadataProofs||[]});return Promise.resolve(i.setMetaDataAndTokenURI.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(je(e,o.signer,null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setMetaDataAndTokenURI,t))})})}catch(e){return Promise.reject(e)}},r.setMetadataState=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(i.setMetaDataState.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setMetaDataState,r))})})}catch(e){return Promise.reject(e)}},r.setTokenURI=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(o.setTokenURI.estimateGas("1",t)).then(function(e){var i;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,o.setTokenURI,"1",t))})}catch(e){return Promise.reject(e)}},r.getNftOwner=function(e){try{var t=this.getContract(e);return Promise.resolve(t.ownerOf(1))}catch(e){return Promise.reject(e)}},r.getNftPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.getPermissions(t))}catch(e){return Promise.reject(e)}},r.getMetadata=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getMetaData())}catch(e){return Promise.reject(e)}},r.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},r.setData=function(e,t,r,o,i){try{var s=this;return Promise.resolve(s.getNftPermissions(e,t)).then(function(t){if(!0!==t.store)throw new Error("User is not ERC20 store updater");var a=s.getContract(e),u=n.keccak256(r),c=n.hexlify(n.toUtf8Bytes(o));return Promise.resolve(a.setNewData.estimateGas(u,c)).then(function(e){var t;return i?e:Promise.resolve(je(e,s.getSignerAccordingSdk(),null==(t=s.config)?void 0:t.gasFeeMultiplier,a.setNewData,u,c))})})}catch(e){return Promise.reject(e)}},r.getData=function(e,t){try{var r=this.getContract(e),o=n.keccak256(t);return Promise.resolve(r.getData(o)).then(function(e){return e?n.toUtf8String(e):null})}catch(e){return Promise.reject(e)}},r.getTokenURI=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.tokenURI(t))}catch(e){return Promise.reject(e)}},r.isDatatokenDeployed=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isDeployed(t))}catch(e){return Promise.reject(e)}},t}(He),ut=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o)||this).abiEnterprise=void 0,s.nft=void 0,s.abiEnterprise=i||Q.default.abi,s.nft=new at(s.signer,r),s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return X.default.abi},r.approve=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.approve.estimateGas(t,Ie(null,null,r,18))).then(function(e){var s;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.approve,t,Ie(null,null,r,18)))})}catch(e){return Promise.reject(e)}},r.createFixedRate=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!e)throw new Error("User is not Datatoken Deployer");r.allowedConsumer||(r.allowedConsumer=Je);var t=!1===r.withMint?0:1;return Promise.resolve(i.createFixedRate.estimateGas(r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t])).then(function(e){var s;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.createFixedRate,r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t]))})})}catch(e){return Promise.reject(e)}},r.createDispenser=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e);return n.allowedSwapper||(n.allowedSwapper=Je),n.withMint=!1!==n.withMint,Promise.resolve(s.createDispenser.estimateGas(r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper)).then(function(e){var t;return o?e:Promise.resolve(je(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.createDispenser,r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper))})})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getPermissions(e,t)).then(function(a){if(!0!==a.minter)throw new Error("Caller is not Minter");return Promise.resolve(i.getCap(e)).then(function(e){if(new J.default(e).gte(r))return Promise.resolve(s.mint.estimateGas(n||t,Ie(null,null,r,18))).then(function(e){var a;return o?e:Promise.resolve(je(e,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,s.mint,n||t,Ie(null,null,r,18)))});throw new Error("Mint amount exceeds cap available")})})}catch(e){return Promise.reject(e)}},r.addMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addMinter,r))})})}catch(e){return Promise.reject(e)}},r.removeMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removeMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeMinter,r))})})}catch(e){return Promise.reject(e)}},r.addPaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addPaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addPaymentManager,r))})})}catch(e){return Promise.reject(e)}},r.removePaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removePaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removePaymentManager,r))})})}catch(e){return Promise.reject(e)}},r.setPaymentCollector=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getPermissions(e,t)).then(function(s){function a(e){function s(s){function a(e){if(!u&&!c&&!(null==e?void 0:e.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");return Promise.resolve(i.setPaymentCollector.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setPaymentCollector,r))})}var c=e&&s===t;return e&&!c?Promise.resolve(e&&!c&&o.nft.getNftPermissions(e,t)).then(a):a(e&&!c&&o.nft.getNftPermissions(e,t))}return e?Promise.resolve(o.nft.getNftOwner(e)).then(s):s(e)}var u=s.paymentManager;return u?a(!u&&o.getNFTAddress(e)):Promise.resolve(!u&&o.getNFTAddress(e)).then(a)})}catch(e){return Promise.reject(e)}},r.getPaymentCollector=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPaymentCollector())}catch(e){return Promise.reject(e)}},r.transfer=function(e,t,r,n){try{var o=this,i=o.transferWei;return Promise.resolve(Ie(null,null,r,18)).then(function(r){return i.call(o,e,t,r,n)})}catch(e){return Promise.reject(e)}},r.transferWei=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.transfer.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.transfer,t,r))})}catch(e){return Promise.reject(e)}},r.startOrder=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e,s.abi);return o||(o={consumeMarketFeeAddress:Je,consumeMarketFeeToken:Je,consumeMarketFeeAmount:"0"}),Promise.resolve(a.startOrder.estimateGas(t,r,n,o)).then(function(e){var u;return i?e:Promise.resolve(je(e,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,a.startOrder,t,r,n,o))})}catch(e){return Promise.reject(e)}},r.reuseOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.reuseOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.reuseOrder,t,r))})}catch(e){return Promise.reject(e)}},r.buyFromFreAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(o.getFreOrderParams(r)).then(function(e){return Promise.resolve(i.buyFromFreAndOrder.estimateGas(t,e)).then(function(r){var s;return n?r:Promise.resolve(je(r,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromFreAndOrder,t,e))})})}catch(e){return Promise.reject(e)}},r.buyFromDispenserAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(i.buyFromDispenserAndOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromDispenserAndOrder,t,r))})}catch(e){return Promise.reject(e)}},r.setData=function(e,t,r,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e),a=n.hexlify(n.toUtf8Bytes(r));return Promise.resolve(s.setData.estimateGas(a)).then(function(e){var t;return o?e:Promise.resolve(je(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.setData,a))})})}catch(e){return Promise.reject(e)}},r.cleanPermissions=function(e,t,r){try{var n=this,o=n.nft,i=o.getNftOwner;return Promise.resolve(n.getNFTAddress(e)).then(function(s){return Promise.resolve(i.call(o,s)).then(function(o){if(o!==t)throw new Error("Caller is NOT Nft Owner");var i=n.getContract(e);return Promise.resolve(i.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,i.cleanPermissions))})})})}catch(e){return Promise.reject(e)}},r.getPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.permissions(t))}catch(e){return Promise.reject(e)}},r.getCap=function(e){try{var t=this,r=t.getContract(e);return Promise.resolve(r.cap()).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDecimals=function(e){try{var t=this.getContract(e);return Promise.resolve(t.decimals()).then(Number)}catch(e){return Promise.reject(e)}},r.getId=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getSymbol=function(e){try{var t=this.getContract(e);return Promise.resolve(t.symbol())}catch(e){return Promise.reject(e)}},r.getName=function(e){try{var t=this.getContract(e);return Promise.resolve(t.name())}catch(e){return Promise.reject(e)}},r.getNFTAddress=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getERC721Address())}catch(e){return Promise.reject(e)}},r.getFixedRates=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getFixedRates())}catch(e){return Promise.reject(e)}},r.getDispensers=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getDispensers())}catch(e){return Promise.reject(e)}},r.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},r.balance=function(e,t){try{var r=this,n=r.getContract(e);return Promise.resolve(n.balanceOf(t)).then(function(e){return Promise.resolve(r.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.allowance=function(e,t,r,n){void 0===n&&(n=18);try{var o=this,i=o.getContract(e);return Promise.resolve(i.allowance(t,r)).then(function(e){return Promise.resolve(o.unitsToAmount(null,e,n))})}catch(e){return Promise.reject(e)}},r.setPublishingMarketFee=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e);return Promise.resolve(a.getPublishingMarketFee()).then(function(e){if(e[0]!==o)throw new Error("Caller is not the Publishing Market Fee Address");return Promise.resolve(a.setPublishingMarketFee.estimateGas(t,r,n)).then(function(e){var o;return i?e:Promise.resolve(je(e,s.getSignerAccordingSdk(),null==(o=s.config)?void 0:o.gasFeeMultiplier,a.setPublishingMarketFee,t,r,n))})})}catch(e){return Promise.reject(e)}},r.getPublishingMarketFee=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPublishingMarketFee()).then(function(e){return{publishMarketFeeAddress:e[0],publishMarketFeeToken:e[1],publishMarketFeeAmount:e[2].toString()}})}catch(e){return Promise.reject(e)}},r.getFreOrderParams=function(e){try{var t=this,r=e.exchangeId,n=e.exchangeContract;return Promise.resolve(Ie(t.signer,e.baseTokenAddress,e.maxBaseTokenAmount,e.baseTokenDecimals)).then(function(o){return Promise.resolve(Ie(t.signer,e.baseTokenAddress,e.swapMarketFee,e.baseTokenDecimals)).then(function(t){return{exchangeContract:n,exchangeId:r,maxBaseTokenAmount:o,swapMarketFee:t,marketFeeAddress:e.marketFeeAddress}})})}catch(e){return Promise.reject(e)}},t}(He),ct=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,n,o,i)||this).accessList=void 0,s.fileObject=void 0,s.abi=s.getDefaultAbi(),s.fileObject=r,s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ne.default.abi},r.setFileObj=function(e){this.fileObject=e},r.getAllowlistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getAllowListContract())}catch(e){return Promise.reject(e)}},r.getDenylistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getDenyListContract())}catch(e){return Promise.reject(e)}},r.setAllowListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setAllowListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setAllowListContract,t))})})}catch(e){return Promise.reject(e)}},r.setDenyListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setDenyListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setDenyListContract,t))})})}catch(e){return Promise.reject(e)}},r.setFileObject=function(e,t,r){try{var n=this;return Promise.resolve(n.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var o=n.getContract(e);return Promise.resolve(o.setFilesObject.estimateGas(n.fileObject)).then(function(e){var t;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.setFilesObject,n.fileObject))})})}catch(e){return Promise.reject(e)}},r.getFileObject=function(e,t,r,n,o,i,s){try{var a=this.getContract(e,this.getDefaultAbi());return Promise.resolve(a.getFileObject(t,r,n,o,i,s))}catch(e){return Promise.reject(e)}},t}(ut),lt=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return oe.default.abi},r.getTokenUri=function(e){try{return Promise.resolve(this.contract.tokenURI(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getId=function(){try{return Promise.resolve(this.contract.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getName=function(){try{return Promise.resolve(this.contract.name())}catch(e){return Promise.reject(e)}},r.getSymbol=function(){try{return Promise.resolve(this.contract.symbol())}catch(e){return Promise.reject(e)}},r.balance=function(e){try{var t=this;return Promise.resolve(t.contract.balanceOf(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.mint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.mint,e,t))})}catch(e){return Promise.reject(e)}},r.batchMint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.batchMint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(je(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.batchMint,e,t))})}catch(e){return Promise.reject(e)}},r.burn=function(e,t){try{var r=this;return Promise.resolve(r.contract.burn.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.burn,e))})}catch(e){return Promise.reject(e)}},r.transferOwnership=function(e,t){try{var r=this;return Promise.resolve(r.contract.transferOwnership.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(je(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.transferOwnership,e))})}catch(e){return Promise.reject(e)}},r.renounceOwnership=function(e){try{var t=this;return Promise.resolve(t.contract.renounceOwnership.estimateGas()).then(function(r){var n;return e?r:Promise.resolve(je(r,t.getSignerAccordingSdk(),null==(n=t.config)?void 0:n.gasFeeMultiplier,t.contract.renounceOwnership))})}catch(e){return Promise.reject(e)}},t}(Ke),ft=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ie.default.abi},r.deployAccessListContract=function(e,t,r,n,o,i,s){void 0===n&&(n=!1);try{var a=this;if(!e||!t){var u=Xe();e=u.name,t=u.symbol}return Promise.resolve(a.contract.deployAccessListContract.estimateGas(e,t,n,o,i,r)).then(function(u){return s?u:function(s,c){try{var l=Promise.resolve(je(u,a.getSignerAccordingSdk(),null==(f=a.config)?void 0:f.gasFeeMultiplier,a.contract.deployAccessListContract,e,t,n,o,i,r)).then(function(e){if(!e){var t="Tx for deploying new access list was not processed on chain.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return ze(e,"NewAccessList").args[0]})})}catch(e){return c(e)}var f;return l&&l.then?l.then(void 0,c):l}(0,function(e){console.error("Creation of AccessList failed: "+e)})})}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.isSoulbound=function(e){try{return Promise.resolve(this.contract.isSoulBound(e))}catch(e){return Promise.reject(e)}},r.isDeployed=function(e){try{return Promise.resolve(this.contract.isDeployed(e))}catch(e){return Promise.reject(e)}},r.changeTemplateAddress=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Je)throw new Error("Template address cannot be ZERO address");return Promise.resolve(n.contract.changeTemplateAddress.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(je(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.changeTemplateAddress,t))})})}catch(e){return Promise.reject(e)}},t}(Ke);function ht(e,t,r){if(!e.s){if(r instanceof dt){if(!r.s)return void(r.o=ht.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ht.bind(null,e,t),ht.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var dt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ht(n,1,i(this.v))}catch(e){ht(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ht(n,1,t?t(o):o):r?ht(n,1,r(o)):ht(n,2,o)}catch(e){ht(n,2,e)}},n},e}(),mt=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return se.default.abi},r.getFunds=function(e){try{return Promise.resolve(this.contract.getFunds(e))}catch(e){return Promise.reject(e)}},r.getUserFunds=function(e,t){try{return Promise.resolve(this.contract.getUserFunds(e,t))}catch(e){return Promise.reject(e)}},r.getUserTokens=function(e){try{return Promise.resolve(this.contract.getUserTokens(e))}catch(e){return Promise.reject(e)}},r.getLocks=function(e,t,r){try{return Promise.resolve(this.contract.getLocks(e,t,r))}catch(e){return Promise.reject(e)}},r.getAuthorizations=function(e,t,r){try{return Promise.resolve(this.contract.getAuthorizations(e,t,r))}catch(e){return Promise.reject(e)}},r.verifyFundsForEscrowPayment=function(e,t,r,o,i,s,a){try{var u,c=this;return Promise.resolve(null==(u=c.signer.provider)?void 0:u.getBalance(n.getAddress(t))).then(function(u){if(new Z.default(u).isZero())return{isValid:!1,message:"Native token balance is 0. Please add funds"};var l=new ut(c.signer),f=l.allowance;return Promise.resolve(c.signer.getAddress()).then(function(u){return Promise.resolve(f.call(l,e,u,c.contract.target.toString(),a)).then(function(u){return Promise.resolve(c.amountToUnits(e,u,18)).then(function(u){function f(){var u=l.balance;return Promise.resolve(c.signer.getAddress()).then(function(f){return Promise.resolve(u.call(l,e,f)).then(function(u){if(new Z.default(u).isZero())return{isValid:!1,message:"Payment token balance is 0. Please add funds"};var l=c.getAuthorizations;return Promise.resolve(c.signer.getAddress()).then(function(f){return Promise.resolve(l.call(c,e,f,t)).then(function(l){var f=c.getUserFunds;return Promise.resolve(c.signer.getAddress()).then(function(h){return Promise.resolve(f.call(c,h,e)).then(function(f){function h(){var r=function(){if(0===l.length)return Promise.resolve(c.authorize(n.getAddress(e),n.getAddress(t),(Number(o)/2).toString(),i,s)).then(function(){})}();return r&&r.then?r.then(function(){return{isValid:!0,message:""}}):{isValid:!0,message:""}}var d=function(){if(new Z.default(f[0]).isZero()){var t=function(){if(r&&new Z.default(n.parseEther(u)).isLessThanOrEqualTo(new Z.default(n.parseEther(r)))&&new Z.default(n.parseEther(r)).isGreaterThan(new Z.default(o)))return Promise.resolve(c.deposit(e,r,a)).then(function(){});var t=function(){if(new Z.default(n.parseEther(u)).isLessThanOrEqualTo(new Z.default(n.parseEther(o)))){var t=c.deposit;return Promise.resolve(c.unitsToAmount(e,o,a)).then(function(r){return Promise.resolve(t.call(c,e,r,a)).then(function(){})})}return Promise.resolve(c.deposit(e,u,a)).then(function(){})}();return t&&t.then?t.then(function(){}):void 0}();if(t&&t.then)return t.then(function(){})}}();return d&&d.then?d.then(h):h()})})})})})})}var h=function(){if(new Z.default(u).isLessThan(new Z.default(o)))return Promise.resolve(l.approve(n.getAddress(e),n.getAddress(c.contract.target.toString()),o)).then(function(){})}();return h&&h.then?h.then(f):f()})})})})}catch(e){return Promise.reject(e)}},r.deposit=function(e,t,r,n){try{var o=this;return Promise.resolve(o.amountToUnits(e,t,r)).then(function(t){return Promise.resolve(o.contract.deposit.estimateGas(e,t)).then(function(r){var i;return n?r:Promise.resolve(je(r,o.getSignerAccordingSdk(),null==(i=o.config)?void 0:i.gasFeeMultiplier,o.contract.deposit,e,t))})})}catch(e){return Promise.reject(e)}},r.withdraw=function(e,t,r,n){try{var o=this,i=[],s=[];if(e.length!==t.length)throw new Error("Tokens and amounts arrays must have the same length");return Promise.resolve(o.signer.getAddress()).then(function(a){function u(){return Promise.resolve(Promise.all(s.map(function(e,t){return o.amountToUnits(i[t],e,r)}))).then(function(t){return Promise.resolve(o.contract.withdraw.estimateGas(e,t)).then(function(e){var r;return n?e:Promise.resolve(je(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,o.contract.withdraw,i,t))})})}var c,l,f,h,d,m=(c=e,l=function(r){var n=e[r],u=new Z.default(t[r]);return Promise.resolve(o.getUserFunds(a,n)).then(function(e){var o=new Z.default(e[0]);u.isGreaterThan(0)&&u.isLessThanOrEqualTo(o)?(i.push(n),s.push(t[r])):console.log("Insufficient funds for token "+n)})},d=-1,function e(t){try{for(;++d<c.length;)if((t=l(d))&&t.then){if(!((r=t)instanceof dt&&1&r.s))return void t.then(e,h||(h=ht.bind(null,f=new dt,2)));t=t.v}f?ht(f,1,t):f=t}catch(e){ht(f||(f=new dt),2,e)}var r}(),f);return m&&m.then?m.then(u):u()})}catch(e){return Promise.reject(e)}},r.authorize=function(e,t,r,n,o,i,s){try{var a=this,u=a.getAuthorizations;return Promise.resolve(a.signer.getAddress()).then(function(c){return Promise.resolve(u.call(a,e,c,t)).then(function(u){return 0!==u.length?(console.log("Payee "+t+" already authorized"),null):Promise.resolve(a.amountToUnits(e,r,i)).then(function(r){return Promise.resolve(a.amountToUnits(e,n,i)).then(function(n){return Promise.resolve(a.amountToUnits(e,o,i)).then(function(o){return Promise.resolve(a.contract.authorize.estimateGas(e,t,r,n,o)).then(function(i){var u;return s?i:Promise.resolve(je(i,a.getSignerAccordingSdk(),null==(u=a.config)?void 0:u.gasFeeMultiplier,a.contract.authorize,e,t,r,n,o))})})})})})})}catch(e){return Promise.reject(e)}},r.cancelExpiredLocks=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.contract.cancelExpiredLocks.estimateGas(e,t,r,n)).then(function(s){var a;return o?s:Promise.resolve(je(s,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,i.contract.cancelExpiredLocks,e,t,r,n))})}catch(e){return Promise.reject(e)}},t}(Ke),gt=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}be(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ae.default.abi},r.isTokenAllowed=function(e){try{return Promise.resolve(this.contract.isTokenAllowed(e))}catch(e){return Promise.reject(e)}},r.getToken=function(e){try{return Promise.resolve(this.contract.getToken(e))}catch(e){return Promise.reject(e)}},r.calculateFee=function(e,t,r){try{var n=this,o=n.amountToUnits(e,t.toString(),r);return Promise.resolve(n.contract.calculateFee(e,o)).then(function(t){return n.unitsToAmount(e,t,r)})}catch(e){return Promise.reject(e)}},t}(Ke),vt=function(e){try{return Promise.resolve(new Promise(function(t){setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},pt=function(e,t){try{var r=n.ethers.solidityPackedKeccak256(["bytes"],[n.ethers.hexlify(n.ethers.toUtf8Bytes(t))]),o=n.ethers.toBeArray(r);return Promise.resolve(function(t,r){try{var n=Promise.resolve(e.signMessage(o))}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=Number(t.chainId);return function(){if(8996===Number(r))return console.log("Signing message with _legacySignMessage"),Promise.resolve(e._legacySignMessage(o))}()})}))}catch(e){return Promise.reject(e)}};class yt extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}}class bt extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}}class Pt extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}}class wt extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}}class Et extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}}class St extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}}class At extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}}const Tt=Symbol.for("@libp2p/peer-id"),xt=Symbol.for("@libp2p/service-capabilities");function kt(e){if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}class Ct{name;prefix;baseEncode;constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Ot{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,r){this.name=e,this.prefix=t;const n=t.codePointAt(0);if(void 0===n)throw new Error("Invalid prefix character");this.prefixCodePoint=n,this.baseDecode=r}decode(e){if("string"==typeof e){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(e){return Dt(this,e)}}class Ft{decoders;constructor(e){this.decoders=e}or(e){return Dt(this,e)}decode(e){const t=this.decoders[e[0]];if(null!=t)return t.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}function Dt(e,t){return new Ft({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}class jt{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new Ct(e,t,r),this.decoder=new Ot(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}function It({name:e,prefix:t,encode:r,decode:n}){return new jt(e,t,r,n)}function Nt({name:e,prefix:t,alphabet:r}){const{encode:n,decode:o}=function(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(255!==r[s])throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,u=e.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===u;)n++,t++;for(var i=(e.length-t)*c+1>>>0,s=new Uint8Array(i);e[t];){var l=r[e.charCodeAt(t)];if(255===l)return;for(var f=0,h=i-1;(0!==l||f<o)&&-1!==h;h--,f++)s[h]=(l+=a*s[h]>>>0)%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=f,t++}if(" "!==e[t]){for(var d=i-o;d!==i&&0===s[d];)d++;for(var m=new Uint8Array(n+(i-d)),g=n;d!==i;)m[g++]=s[d++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var s=(i-o)*l+1>>>0,c=new Uint8Array(s);o!==i;){for(var f=t[o],h=0,d=s-1;(0!==f||h<n)&&-1!==d;d--,h++)c[d]=(f+=256*c[d]>>>0)%a>>>0,f=f/a>>>0;if(0!==f)throw new Error("Non-zero carry");n=h,o++}for(var m=s-n;m!==s&&0===c[m];)m++;for(var g=u.repeat(r);m<s;++m)g+=e.charAt(c[m]);return g},decodeUnsafe:f,decode:function(e){var r=f(e);if(r)return r;throw new Error(`Non-${t} character`)}}}(r,e);return It({prefix:t,name:e,encode:n,decode:e=>kt(o(e))})}function Lt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){const o=function(e){const t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}(n);return It({prefix:t,name:e,encode:e=>function(e,t,r){const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,a=0;for(let n=0;n<e.length;++n)for(a=a<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(0!==s&&(i+=t[o&a<<r-s]),n)for(;i.length*r&7;)i+="=";return i}(e,n,r),decode:t=>function(e,t,r,n){let o=e.length;for(;"="===e[o-1];)--o;const i=new Uint8Array(o*r/8|0);let s=0,a=0,u=0;for(let c=0;c<o;++c){const o=t[e[c]];if(void 0===o)throw new SyntaxError(`Non-${n} character`);a=a<<r|o,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||255&a<<8-s)throw new SyntaxError("Unexpected end of data");return i}(t,o,r,e)})}const Ut=Nt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Nt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});const Rt=Lt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Lt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Lt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Lt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Lt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Mt=Nt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"});Nt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Bt=Math.pow(2,31),_t=Math.pow(2,7),Gt=Math.pow(2,14),qt=Math.pow(2,21),Vt=Math.pow(2,28),zt=Math.pow(2,35),Ht=Math.pow(2,42),Kt=Math.pow(2,49),Zt=Math.pow(2,56),Jt=Math.pow(2,63),$t={encode:function e(t,r,n){r=r||[];for(var o=n=n||0;t>=Bt;)r[n++]=255&t|128,t/=128;for(;-128&t;)r[n++]=255&t|128,t>>>=7;return r[n]=0|t,e.bytes=n-o+1,r},decode:function e(t,r){var n,o=0,i=0,s=r=r||0,a=t.length;do{if(s>=a)throw e.bytes=0,new RangeError("Could not decode varint");n=t[s++],o+=i<28?(127&n)<<i:(127&n)*Math.pow(2,i),i+=7}while(n>=128);return e.bytes=s-r,o},encodingLength:function(e){return e<_t?1:e<Gt?2:e<qt?3:e<Vt?4:e<zt?5:e<Ht?6:e<Kt?7:e<Zt?8:e<Jt?9:10}};function Wt(e,t=0){return[$t.decode(e,t),$t.decode.bytes]}function Yt(e,t,r=0){return $t.encode(e,t,r),t}function Xt(e){return $t.encodingLength(e)}function Qt(e,t){const r=t.byteLength,n=Xt(e),o=n+Xt(r),i=new Uint8Array(o+r);return Yt(e,i,0),Yt(r,i,n),i.set(t,o),new tr(e,r,t,i)}function er(e){const t=kt(e),[r,n]=Wt(t),[o,i]=Wt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new tr(r,o,s,t)}class tr{code;size;digest;bytes;constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}function rr(e,t){const{bytes:r,version:n}=e;return 0===n?function(e,t,r){const{prefix:n}=r;if(n!==Ut.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);const o=t.get(n);if(null==o){const o=r.encode(e).slice(1);return t.set(n,o),o}return o}(r,or(e),t??Ut.encoder):function(e,t,r){const{prefix:n}=r,o=t.get(n);if(null==o){const o=r.encode(e);return t.set(n,o),o}return o}(r,or(e),t??Rt.encoder)}const nr=new WeakMap;function or(e){const t=nr.get(e);if(null==t){const t=new Map;return nr.set(e,t),t}return t}class ir{code;version;multihash;bytes;"/";constructor(e,t,r,n){this.code=t,this.version=e,this.multihash=r,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{const{code:e,multihash:t}=this;if(e!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ar)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return ir.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{const{code:e,digest:t}=this.multihash,r=Qt(e,t);return ir.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return ir.equals(this,e)}static equals(e,t){return null!=t&&e.code===t.code&&e.version===t.version&&((r=e.multihash)===(n=t.multihash)||r.code===n.code&&r.size===n.size&&n.bytes instanceof Uint8Array&&function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}(r.bytes,n.bytes));var r,n}toString(e){return rr(this,e)}toJSON(){return{"/":rr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(null==e)return null;const t=e;if(t instanceof ir)return t;if(null!=t["/"]&&t["/"]===t.bytes||t.asCID===t){const{version:e,code:r,multihash:n,bytes:o}=t;return new ir(e,r,n,o??ur(e,r,n.bytes))}if(!0===t[cr]){const{version:e,multihash:r,code:n}=t,o=er(r);return ir.create(e,n,o)}return null}static create(e,t,r){if("number"!=typeof t)throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:if(t!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new ir(e,t,r,r.bytes);case 1:{const n=ur(e,t,r.bytes);return new ir(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return ir.create(0,sr,e)}static createV1(e,t){return ir.create(1,e,t)}static decode(e){const[t,r]=ir.decodeFirst(e);if(0!==r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){const t=ir.inspectBytes(e),r=t.size-t.multihashSize,n=kt(e.subarray(r,r+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");const o=n.subarray(t.multihashSize-t.digestSize),i=new tr(t.multihashCode,t.digestSize,o,n);return[0===t.version?ir.createV0(i):ir.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0;const r=()=>{const[r,n]=Wt(e.subarray(t));return t+=n,r};let n=r(),o=sr;if(18===n?(n=0,t=0):o=r(),0!==n&&1!==n)throw new RangeError(`Invalid CID version ${n}`);const i=t,s=r(),a=r(),u=t+a;return{version:n,codec:o,multihashCode:s,digestSize:a,multihashSize:u-i,size:u}}static parse(e,t){const[r,n]=function(e,t){switch(e[0]){case"Q":return[Ut.prefix,(t??Ut).decode(`${Ut.prefix}${e}`)];case Ut.prefix:return[Ut.prefix,(t??Ut).decode(e)];case Rt.prefix:return[Rt.prefix,(t??Rt).decode(e)];case Mt.prefix:return[Mt.prefix,(t??Mt).decode(e)];default:if(null==t)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),o=ir.decode(n);if(0===o.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return or(o).set(r,e),o}}const sr=112,ar=18;function ur(e,t,r){const n=Xt(e),o=n+Xt(t),i=new Uint8Array(o+r.byteLength);return Yt(e,i,0),Yt(t,i,n),i.set(r,o),i}const cr=Symbol.for("@ipld/js-cid/CID"),lr=kt,fr=function(e,t){if(null!=t?.truncate&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Qt(0,lr(e))},hr=Symbol.for("@achingbrain/uint8arraylist");function dr(e,t){if(null==t||t<0)throw new RangeError("index is out of bounds");let r=0;for(const n of e){const e=r+n.byteLength;if(t<e)return{buf:n,index:t-r};r=e}throw new RangeError("index is out of bounds")}function mr(e){return Boolean(e?.[hr])}class gr{bufs;length;[hr]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(const r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else{if(!mr(r))throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");t+=r.byteLength,this.bufs.push(...r.bufs)}this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(const r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else{if(!mr(r))throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");t+=r.byteLength,this.bufs.unshift(...r.bufs)}this.length+=t}get(e){const t=dr(this.bufs,e);return t.buf[t.index]}set(e,t){const r=dr(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r<e.length;r++)this.set(t+r,e[r]);else{if(!mr(e))throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList");for(let r=0;r<e.length;r++)this.set(t+r,e.get(r))}}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength)return this.bufs=[],void(this.length=0);for(;this.bufs.length>0;){if(!(e>=this.bufs[0].byteLength)){this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift()}}}slice(e,t){const{bufs:r,length:n}=this._subList(e,t);return S.concat(r,n)}subarray(e,t){const{bufs:r,length:n}=this._subList(e,t);return 1===r.length?r[0]:S.concat(r,n)}sublist(e,t){const{bufs:r,length:n}=this._subList(e,t),o=new gr;return o.length=n,o.bufs=[...r],o}_subList(e,t){if((e=e??0)<0&&(e=this.length+e),(t=t??this.length)<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(0===e&&t===this.length)return{bufs:this.bufs,length:this.length};const r=[];let n=0;for(let o=0;o<this.bufs.length;o++){const i=this.bufs[o],s=n,a=s+i.byteLength;if(n=a,e>=a)continue;const u=e>=s&&e<a,c=t>s&&t<=a;if(u&&c){if(e===s&&t===a){r.push(i);break}const n=e-s;r.push(i.subarray(n,n+(t-e)));break}if(u){if(0===e){r.push(i);continue}r.push(i.subarray(e-s))}else{if(c){if(t===a){r.push(i);break}r.push(i.subarray(0,t-s));break}r.push(i)}}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!(mr(e)||e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');const r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const n=r.byteLength;if(0===n)throw new TypeError("search must be at least 1 byte long");const o=new Int32Array(256);for(let e=0;e<256;e++)o[e]=-1;for(let e=0;e<n;e++)o[r[e]]=e;const i=o,s=this.byteLength-r.byteLength,a=r.byteLength-1;let u;for(let e=t;e<=s;e+=u){u=0;for(let t=a;t>=0;t--){const n=this.get(e+t);if(r[t]!==n){u=Math.max(1,t-i[n]);break}}if(0===u)return e}return-1}getInt8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){const r=E.allocUnsafe(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){const r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){const n=E.alloc(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,r),this.write(n,e)}getInt32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){const n=E.alloc(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,r),this.write(n,e)}getBigInt64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){const n=E.alloc(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,r),this.write(n,e)}getUint8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){const r=E.allocUnsafe(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){const r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){const n=E.alloc(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,r),this.write(n,e)}getUint32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){const n=E.alloc(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,r),this.write(n,e)}getBigUint64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){const n=E.alloc(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,r),this.write(n,e)}getFloat32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){const n=E.alloc(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,r),this.write(n,e)}getFloat64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){const n=E.alloc(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(null==e)return!1;if(!(e instanceof gr))return!1;if(e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!A.equals(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){const r=new gr;return r.bufs=e,null==t&&(t=e.reduce((e,t)=>e+t.byteLength,0)),r.length=t,r}}const vr=parseInt("11111",2),pr=parseInt("10000000",2),yr=parseInt("01111111",2),br={0:Er,1:Er,2:function(e,t){const r=wr(e,t),n=t.offset,o=t.offset+r,i=[];for(let t=n;t<o;t++)t===n&&0===e[t]||i.push(e[t]);return t.offset+=r,Uint8Array.from(i)},3:function(e,t){const r=wr(e,t),n=e[t.offset];t.offset++;const o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,0!==n)throw new Error("Unused bits in bit string is unimplemented");return o},4:function(e,t){const r=wr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n},5:function(e,t){return t.offset++,null},6:function(e,t){const r=wr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,u=[];for(;t.offset<n;){const r=e[t.offset];if(t.offset++,u.push(127&r),r<128){u.reverse();let e=0;for(let t=0;t<u.length;t++)e+=u[t]<<7*t;a+=`.${e}`,u=[]}}return a},16:Er,22:Er,48:Er};function Pr(e,t={offset:0}){const r=e[t.offset]&vr;if(t.offset++,null!=br[r])return br[r](e,t);throw new Error("No decoder for tag "+r)}function wr(e,t){let r=0;if((e[t.offset]&pr)===pr){const n=e[t.offset]&yr;let o="0x";t.offset++;for(let r=0;r<n;r++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Er(e,t){wr(e,t);const r=[];for(;!(t.offset>=e.byteLength);){const n=Pr(e,t);if(null===n)break;r.push(n)}return r}function Sr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);const t=function(e){let t=e.toString(16);t.length%2==1&&(t="0"+t);const r=new gr;for(let e=0;e<t.length;e+=2)r.append(Uint8Array.from([parseInt(`${t[e]}${t[e+1]}`,16)]));return r}(e.byteLength);return new gr(Uint8Array.from([t.byteLength|pr]),t)}function Ar(e){const t=new gr;return!(128&~e.subarray()[0])&&t.append(Uint8Array.from([0])),t.append(e),new gr(Uint8Array.from([2]),Sr(t),t)}function Tr(e){const t=Uint8Array.from([0]),r=new gr(t,e);return new gr(Uint8Array.from([3]),Sr(r),r)}function xr(e,t=48){const r=new gr;for(const t of e)r.append(t);return new gr(Uint8Array.from([t]),Sr(r),r)}const kr=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Cr=Uint8Array.from([6,5,43,129,4,0,34]),Or=Uint8Array.from([6,5,43,129,4,0,35]),Fr={ext:!0,kty:"EC",crv:"P-256"},Dr={ext:!0,kty:"EC",crv:"P-384"},jr={ext:!0,kty:"EC",crv:"P-521"};function Ir(e){if("P-256"===e)return kr;if("P-384"===e)return Cr;if("P-521"===e)return Or;throw new yt(`Invalid curve ${e}`)}class Nr{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){var e;return null==this._raw&&(this._raw=(e=this.jwk,xr([Ar(Uint8Array.from([1])),xr([Ir(e.crv)],160),xr([Tr(new gr(Uint8Array.from([4]),T.fromString(e.x??"","base64url"),T.fromString(e.y??"","base64url")))],161)]).subarray())),this._raw}toMultihash(){return fr(Cs(this))}toCID(){return ir.createV1(114,this.toMultihash())}toString(){return Ut.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&A.equals(this.raw,e.raw)}async verify(e,t,r){return async function(e,t,r,n){const o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();const i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}(this.jwk,t,e,r)}}function Lr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Ur(e,t=""){if(!Number.isSafeInteger(e)||e<0)throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}function Rr(e,t,r=""){const n=Lr(e),o=e?.length,i=void 0!==t;if(!n||i&&o!==t)throw new Error((r&&`"${r}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(n?`length=${o}`:"type="+typeof e));return e}function Mr(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash must wrapped by utils.createHasher");Ur(e.outputLen),Ur(e.blockLen)}function Br(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function _r(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Gr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function qr(e,t){return e<<32-t|e>>>t}const Vr=/* @__PURE__ */(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),zr=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Hr(e){if(Rr(e),Vr)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=zr[e[r]];return t}function Kr(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Zr(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Vr)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let t=0,o=0;t<r;t++,o+=2){const r=Kr(e.charCodeAt(o)),i=Kr(e.charCodeAt(o+1));if(void 0===r||void 0===i)throw new Error('hex string expected, got non-hex character "'+(e[o]+e[o+1])+'" at index '+o);n[t]=16*r+i}return n}function Jr(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Rr(n),t+=n.length}const r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const o=e[t];r.set(o,n),n+=o.length}return r}function $r(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}function Wr(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const Yr=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Xr(e,t,r){return e&t^e&r^t&r}class Qr{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,r,n){this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=Gr(this.buffer)}update(e){Br(this),Rr(e);const{view:t,buffer:r,blockLen:n}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(n-this.pos,o-i);if(s!==n)r.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=Gr(e);for(;n<=o-i;i+=n)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){Br(this),function(e,t){Rr(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:i}=this;t[i++]=128,_r(this.buffer.subarray(i)),this.padOffset>n-i&&(this.process(r,0),i=0);for(let e=i;e<n;e++)t[e]=0;r.setBigUint64(n-8,BigInt(8*this.length),o),this.process(r,0);const s=Gr(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<u;e++)s.setUint32(4*e,c[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const en=/* @__PURE__ */Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),tn=/* @__PURE__ */Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),rn=/* @__PURE__ */BigInt(2**32-1),nn=/* @__PURE__ */BigInt(32);function on(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>nn&rn)}:{h:0|Number(e>>nn&rn),l:0|Number(e&rn)}}const sn=(e,t,r)=>e>>>r,an=(e,t,r)=>e<<32-r|t>>>r,un=(e,t,r)=>e>>>r|t<<32-r,cn=(e,t,r)=>e<<32-r|t>>>r,ln=(e,t,r)=>e<<64-r|t>>>r-32,fn=(e,t,r)=>e>>>r-32|t<<64-r;function hn(e,t,r,n){const o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:0|o}}const dn=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),mn=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,gn=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),vn=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,pn=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),yn=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0,bn=/* @__PURE__ */Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Pn=/* @__PURE__ */new Uint32Array(64);class wn extends Qr{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:o,F:i,G:s,H:a}=this;return[e,t,r,n,o,i,s,a]}set(e,t,r,n,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let r=0;r<16;r++,t+=4)Pn[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Pn[e-15],r=Pn[e-2],n=qr(t,7)^qr(t,18)^t>>>3,o=qr(r,17)^qr(r,19)^r>>>10;Pn[e]=o+Pn[e-7]+n+Pn[e-16]|0}let{A:r,B:n,C:o,D:i,E:s,F:a,G:u,H:c}=this;for(let e=0;e<64;e++){const t=c+(qr(s,6)^qr(s,11)^qr(s,25))+((l=s)&a^~l&u)+bn[e]+Pn[e]|0,f=(qr(r,2)^qr(r,13)^qr(r,22))+Xr(r,n,o)|0;c=u,u=a,a=s,s=i+t|0,i=o,o=n,n=r,r=t+f|0}var l;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,o,i,s,a,u,c)}roundClean(){_r(Pn)}destroy(){this.set(0,0,0,0,0,0,0,0),_r(this.buffer)}}class En extends wn{A=0|en[0];B=0|en[1];C=0|en[2];D=0|en[3];E=0|en[4];F=0|en[5];G=0|en[6];H=0|en[7];constructor(){super(32)}}const Sn=/* @__PURE__ */(()=>function(e,t=!1){const r=e.length;let n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){const{h:r,l:s}=on(e[i],t);[n[i],o[i]]=[r,s]}return[n,o]}(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))))(),An=/* @__PURE__ */(()=>Sn[0])(),Tn=/* @__PURE__ */(()=>Sn[1])(),xn=/* @__PURE__ */new Uint32Array(80),kn=/* @__PURE__ */new Uint32Array(80);class Cn extends Qr{constructor(e){super(128,e,16,!1)}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:o,Cl:i,Dh:s,Dl:a,Eh:u,El:c,Fh:l,Fl:f,Gh:h,Gl:d,Hh:m,Hl:g}=this;return[e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g]}set(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|m,this.Hl=0|g}process(e,t){for(let r=0;r<16;r++,t+=4)xn[r]=e.getUint32(t),kn[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|xn[e-15],r=0|kn[e-15],n=un(t,r,1)^un(t,r,8)^sn(t,0,7),o=cn(t,r,1)^cn(t,r,8)^an(t,r,7),i=0|xn[e-2],s=0|kn[e-2],a=un(i,s,19)^ln(i,s,61)^sn(i,0,6),u=cn(i,s,19)^fn(i,s,61)^an(i,s,6),c=gn(o,u,kn[e-7],kn[e-16]),l=vn(c,n,a,xn[e-7],xn[e-16]);xn[e]=0|l,kn[e]=0|c}let{Ah:r,Al:n,Bh:o,Bl:i,Ch:s,Cl:a,Dh:u,Dl:c,Eh:l,El:f,Fh:h,Fl:d,Gh:m,Gl:g,Hh:v,Hl:p}=this;for(let e=0;e<80;e++){const t=un(l,f,14)^un(l,f,18)^ln(l,f,41),y=cn(l,f,14)^cn(l,f,18)^fn(l,f,41),b=l&h^~l&m,P=pn(p,y,f&d^~f&g,Tn[e],kn[e]),w=yn(P,v,t,b,An[e],xn[e]),E=0|P,S=un(r,n,28)^ln(r,n,34)^ln(r,n,39),A=cn(r,n,28)^fn(r,n,34)^fn(r,n,39),T=r&o^r&s^o&s,x=n&i^n&a^i&a;v=0|m,p=0|g,m=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=hn(0|u,0|c,0|w,0|E)),u=0|s,c=0|a,s=0|o,a=0|i,o=0|r,i=0|n;const k=dn(E,A,x);r=mn(k,w,S,T),n=0|k}({h:r,l:n}=hn(0|this.Ah,0|this.Al,0|r,0|n)),({h:o,l:i}=hn(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=hn(0|this.Ch,0|this.Cl,0|s,0|a)),({h:u,l:c}=hn(0|this.Dh,0|this.Dl,0|u,0|c)),({h:l,l:f}=hn(0|this.Eh,0|this.El,0|l,0|f)),({h:h,l:d}=hn(0|this.Fh,0|this.Fl,0|h,0|d)),({h:m,l:g}=hn(0|this.Gh,0|this.Gl,0|m,0|g)),({h:v,l:p}=hn(0|this.Hh,0|this.Hl,0|v,0|p)),this.set(r,n,o,i,s,a,u,c,l,f,h,d,m,g,v,p)}roundClean(){_r(xn,kn)}destroy(){_r(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class On extends Cn{Ah=0|tn[0];Al=0|tn[1];Bh=0|tn[2];Bl=0|tn[3];Ch=0|tn[4];Cl=0|tn[5];Dh=0|tn[6];Dl=0|tn[7];Eh=0|tn[8];El=0|tn[9];Fh=0|tn[10];Fl=0|tn[11];Gh=0|tn[12];Gl=0|tn[13];Hh=0|tn[14];Hl=0|tn[15];constructor(){super(64)}}const Fn=/* @__PURE__ */$r(()=>new En
|
|
2
|
-
/* @__PURE__ */,
|
|
3
|
-
/* @__PURE__ */,Yr(3)),jn=/* @__PURE__ */BigInt(0),In=/* @__PURE__ */BigInt(1);function Nn(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e);return e}function Ln(e){if("bigint"==typeof e){if(!Vn(e))throw new Error("positive bigint expected, got "+e)}else Ur(e);return e}function Un(e){const t=Ln(e).toString(16);return 1&t.length?"0"+t:t}function Rn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?jn:BigInt("0x"+e)}function Mn(e){return Rn(Hr(e))}function Bn(e){return Rn(Hr(qn(Rr(e)).reverse()))}function _n(e,t){Ur(t);const r=Zr((e=Ln(e)).toString(16).padStart(2*t,"0"));if(r.length!==t)throw new Error("number too large");return r}function Gn(e,t){return _n(e,t).reverse()}function qn(e){return Uint8Array.from(e)}const Vn=e=>"bigint"==typeof e&&jn<=e;function zn(e,t,r,n){if(!function(e,t,r){return Vn(e)&&Vn(t)&&Vn(r)&&t<=e&&e<r}(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}const Hn=e=>(In<<BigInt(e))-In;function Kn(e,t={},r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");const n=(t,r)=>Object.entries(t).forEach(([t,n])=>function(t,r,n){const o=e[t];if(n&&void 0===o)return;const i=typeof o;if(i!==r||null===o)throw new Error(`param "${t}" is invalid: expected ${r}, got ${i}`)}(t,n,r));n(t,!1),n(r,!0)}function Zn(e){const t=new WeakMap;return(r,...n)=>{const o=t.get(r);if(void 0!==o)return o;const i=e(r,...n);return t.set(r,i),i}}const Jn=/* @__PURE__ */BigInt(0),$n=/* @__PURE__ */BigInt(1),Wn=/* @__PURE__ */BigInt(2),Yn=/* @__PURE__ */BigInt(3),Xn=/* @__PURE__ */BigInt(4),Qn=/* @__PURE__ */BigInt(5),eo=/* @__PURE__ */BigInt(7),to=/* @__PURE__ */BigInt(8),ro=/* @__PURE__ */BigInt(9),no=/* @__PURE__ */BigInt(16);function oo(e,t){const r=e%t;return r>=Jn?r:t+r}function io(e,t,r){let n=e;for(;t-- >Jn;)n*=n,n%=r;return n}function so(e,t){if(e===Jn)throw new Error("invert: expected non-zero number");if(t<=Jn)throw new Error("invert: expected positive modulus, got "+t);let r=oo(e,t),n=t,o=Jn,i=$n;for(;r!==Jn;){const e=n%r,t=o-i*(n/r);n=r,r=e,o=i,i=t}if(n!==$n)throw new Error("invert: does not exist");return oo(o,t)}function ao(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function uo(e,t){const r=e.pow(t,(e.ORDER+$n)/Xn);return ao(e,r,t),r}function co(e,t){const r=(e.ORDER-Qn)/to,n=e.mul(t,Wn),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Wn),o),a=e.mul(i,e.sub(s,e.ONE));return ao(e,a,t),a}function lo(e){if(e<Yn)throw new Error("sqrt is not defined for small field");let t=e-$n,r=0;for(;t%Wn===Jn;)t/=Wn,r++;let n=Wn;const o=vo(e);for(;1===mo(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===r)return uo;let i=o.pow(n,t);const s=(t+$n)/Wn;return function(e,n){if(e.is0(n))return n;if(1!==mo(e,n))throw new Error("Cannot find square root");let o=r,a=e.mul(e.ONE,i),u=e.pow(n,t),c=e.pow(n,s);for(;!e.eql(u,e.ONE);){if(e.is0(u))return e.ZERO;let t=1,r=e.sqr(u);for(;!e.eql(r,e.ONE);)if(t++,r=e.sqr(r),t===o)throw new Error("Cannot find square root");const n=$n<<BigInt(o-t-1),i=e.pow(a,n);o=t,a=e.sqr(i),u=e.mul(u,a),c=e.mul(c,i)}return c}}const fo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ho(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),i=e.inv(o);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),i),n}function mo(e,t){const r=e.pow(t,(e.ORDER-$n)/Wn),n=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),i=e.eql(r,e.neg(e.ONE));if(!n&&!o&&!i)throw new Error("invalid Legendre symbol result");return n?1:o?0:-1}class go{ORDER;BITS;BYTES;isLE;ZERO=Jn;ONE=$n;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=Jn)throw new Error("invalid field: expected ORDER > 0, got "+e);let r;this.isLE=!1,null!=t&&"object"==typeof t&&("number"==typeof t.BITS&&(r=t.BITS),"function"==typeof t.sqrt&&(this.sqrt=t.sqrt),"boolean"==typeof t.isLE&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),"boolean"==typeof t.modFromBytes&&(this._mod=t.modFromBytes));const{nBitLength:n,nByteLength:o}=function(e,t){void 0!==t&&Ur(t);const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}(e,r);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=n,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return oo(e,this.ORDER)}isValid(e){if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return Jn<=e&&e<this.ORDER}is0(e){return e===Jn}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&$n)===$n}neg(e){return oo(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return oo(e*e,this.ORDER)}add(e,t){return oo(e+t,this.ORDER)}sub(e,t){return oo(e-t,this.ORDER)}mul(e,t){return oo(e*t,this.ORDER)}pow(e,t){return function(e,t,r){if(r<Jn)throw new Error("invalid exponent, negatives unsupported");if(r===Jn)return e.ONE;if(r===$n)return t;let n=e.ONE,o=t;for(;r>Jn;)r&$n&&(n=e.mul(n,o)),o=e.sqr(o),r>>=$n;return n}(this,e,t)}div(e,t){return oo(e*so(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return so(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=(t=this.ORDER)%Xn===Yn?uo:t%to===Qn?co:t%no===ro?function(e){const t=vo(e),r=lo(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+eo)/no;return(e,t)=>{let r=e.pow(t,s),a=e.mul(r,n);const u=e.mul(r,o),c=e.mul(r,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(u),t);r=e.cmov(r,a,l),a=e.cmov(c,u,f);const h=e.eql(e.sqr(a),t),d=e.cmov(r,a,h);return ao(e,d,t),d}}(t):lo(t)),this._sqrt(this,e);var t}toBytes(e){return this.isLE?Gn(e,this.BYTES):_n(e,this.BYTES)}fromBytes(e,t=!1){Rr(e);const{_lengths:r,BYTES:n,isLE:o,ORDER:i,_mod:s}=this;if(r){if(!r.includes(e.length)||e.length>n)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);const t=new Uint8Array(n);t.set(e,o?0:t.length-e.length),e=t}if(e.length!==n)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let a=o?Bn(e):Mn(e);if(s&&(a=oo(a,i)),!t&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return ho(this,e)}cmov(e,t,r){return r?t:e}}function vo(e,t={}){return new go(e,t)}function po(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function yo(e){const t=po(e);return t+Math.ceil(t/2)}const bo=/* @__PURE__ */BigInt(0),Po=/* @__PURE__ */BigInt(1);function wo(e,t){const r=t.negate();return e?r:t}function Eo(e,t){const r=ho(e.Fp,t.map(e=>e.Z));return t.map((t,n)=>e.fromAffine(t.toAffine(r[n])))}function So(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ao(e,t){So(e,t);const r=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:Hn(e),maxNumber:r,shiftBy:BigInt(e)}}function To(e,t,r){const{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r;let a=Number(e&o),u=e>>s;a>n&&(a-=i,u+=Po);const c=t*n;return{nextN:u,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const xo=new WeakMap,ko=new WeakMap;function Co(e){return ko.get(e)||1}function Oo(e){if(e!==bo)throw new Error("invalid wNAF")}class Fo{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,r=this.ZERO){let n=e;for(;t>bo;)t&Po&&(r=r.add(n)),n=n.double(),t>>=Po;return r}precomputeWindow(e,t){const{windows:r,windowSize:n}=Ao(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<r;e++){s=i,o.push(s);for(let e=1;e<n;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let n=this.ZERO,o=this.BASE;const i=Ao(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:u,isNeg:c,isNegF:l,offsetF:f}=To(r,e,i);r=s,u?o=o.add(wo(l,t[f])):n=n.add(wo(c,t[a]))}return Oo(r),{p:n,f:o}}wNAFUnsafe(e,t,r,n=this.ZERO){const o=Ao(e,this.bits);for(let e=0;e<o.windows&&r!==bo;e++){const{nextN:i,offset:s,isZero:a,isNeg:u}=To(r,e,o);if(r=i,!a){const e=t[s];n=n.add(u?e.negate():e)}}return Oo(r),n}getPrecomputes(e,t,r){let n=xo.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),xo.set(t,n))),n}cached(e,t,r){const n=Co(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)}unsafe(e,t,r,n){const o=Co(e);return 1===o?this._unsafeLadder(e,t,n):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,n)}createCache(e,t){So(t,this.bits),ko.set(e,t),xo.delete(e)}hasCache(e){return 1!==Co(e)}}function Do(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Kn(e,fo.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return vo(e,{isLE:r})}function jo(e,t,r={},n){if(void 0===n&&(n="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const r=t[e];if(!("bigint"==typeof r&&r>bo))throw new Error(`CURVE.${e} must be positive bigint`)}const o=Do(t.p,r.Fp,n),i=Do(t.n,r.Fn,n),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}function Io(e,t){return function(r){const n=e(r);return{secretKey:n,publicKey:t(n)}}}const No=BigInt(0),Lo=BigInt(1),Uo=BigInt(2),Ro=BigInt(8);function Mo(e,t={}){const r=jo("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r;let i=r.CURVE;const{h:s}=i;Kn(t,{},{uvRatio:"function"});const a=Uo<<BigInt(8*o.BYTES)-Lo,u=e=>n.create(e),c=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:n.sqrt(n.div(e,t))}}catch(e){return{isValid:!1,value:No}}});if(!function(e,t,r,n){const o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(e,t,r=!1){return zn("coordinate "+e,t,r?Lo:No,a),t}function f(e){if(!(e instanceof m))throw new Error("EdwardsPoint expected")}const h=Zn((e,t)=>{const{X:r,Y:o,Z:i}=e,s=e.is0();null==t&&(t=s?Ro:n.inv(i));const a=u(r*t),c=u(o*t),l=n.mul(i,t);if(s)return{x:No,y:Lo};if(l!==Lo)throw new Error("invZ was invalid");return{x:a,y:c}}),d=Zn(e=>{const{a:t,d:r}=i;if(e.is0())throw new Error("bad point: ZERO");const{X:n,Y:o,Z:s,T:a}=e,c=u(n*n),l=u(o*o),f=u(s*s),h=u(f*f),d=u(c*t);if(u(f*u(d+l))!==u(h+u(r*u(c*l))))throw new Error("bad point: equation left != right (1)");if(u(n*o)!==u(s*a))throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(i.Gx,i.Gy,Lo,u(i.Gx*i.Gy));static ZERO=new m(No,Lo,Lo,No);static Fp=n;static Fn=o;X;Y;Z;T;constructor(e,t,r,n){this.X=l("x",e),this.Y=l("y",t),this.Z=l("z",r,!0),this.T=l("t",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){if(e instanceof m)throw new Error("extended point not allowed");const{x:t,y:r}=e||{};return l("x",t),l("y",r),new m(t,r,Lo,u(t*r))}static fromBytes(e,t=!1){const r=n.BYTES,{a:o,d:s}=i;e=qn(Rr(e,r,"point")),Nn(t,"zip215");const l=qn(e),f=e[r-1];l[r-1]=-129&f;const h=Bn(l);zn("point.y",h,No,t?a:n.ORDER);const d=u(h*h),g=u(d-Lo),v=u(s*d-o);let{isValid:p,value:y}=c(g,v);if(!p)throw new Error("bad point: invalid y coordinate");const b=(y&Lo)===Lo,P=!!(128&f);if(!t&&y===No&&P)throw new Error("bad point: x=0 and x_0=1");return P!==b&&(y=u(-y)),m.fromAffine({x:y,y:h})}static fromHex(e,t=!1){return m.fromBytes(Zr(e),t)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return g.createCache(this,e),t||this.multiply(Uo),this}assertValidity(){d(this)}equals(e){f(e);const{X:t,Y:r,Z:n}=this,{X:o,Y:i,Z:s}=e,a=u(t*s),c=u(o*n),l=u(r*s),h=u(i*n);return a===c&&l===h}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.X),this.Y,this.Z,u(-this.T))}double(){const{a:e}=i,{X:t,Y:r,Z:n}=this,o=u(t*t),s=u(r*r),a=u(Uo*u(n*n)),c=u(e*o),l=t+r,f=u(u(l*l)-o-s),h=c+s,d=h-a,g=c-s,v=u(f*d),p=u(h*g),y=u(f*g),b=u(d*h);return new m(v,p,b,y)}add(e){f(e);const{a:t,d:r}=i,{X:n,Y:o,Z:s,T:a}=this,{X:c,Y:l,Z:h,T:d}=e,g=u(n*c),v=u(o*l),p=u(a*r*d),y=u(s*h),b=u((n+o)*(c+l)-g-v),P=y-p,w=y+p,E=u(v-t*g),S=u(b*P),A=u(w*E),T=u(b*E),x=u(P*w);return new m(S,A,x,T)}subtract(e){return this.add(e.negate())}multiply(e){if(!o.isValidNot0(e))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:t,f:r}=g.cached(this,e,e=>Eo(m,e));return Eo(m,[t,r])[0]}multiplyUnsafe(e,t=m.ZERO){if(!o.isValid(e))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return e===No?m.ZERO:this.is0()||e===Lo?this:g.unsafe(this,e,e=>Eo(m,e),t)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return g.unsafe(this,i.n).is0()}toAffine(e){return h(this,e)}clearCofactor(){return s===Lo?this:this.multiplyUnsafe(s)}toBytes(){const{x:e,y:t}=this.toAffine(),r=n.toBytes(t);return r[r.length-1]|=e&Lo?128:0,r}toHex(){return Hr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const g=new Fo(m,o.BITS);return m.BASE.precompute(8),m}const Bo=BigInt(1),_o=BigInt(2),Go=BigInt(5),qo=BigInt(8),Vo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),zo=/* @__PURE__ */(()=>({p:Vo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:qo,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")}))();function Ho(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Ko=/* @__PURE__ */BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zo=/* @__PURE__ */Mo(zo,{uvRatio:function(e,t){const r=Vo,n=oo(t*t*t,r),o=function(e){const t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Vo,s=e*e%i*e%i,a=io(s,_o,i)*s%i,u=io(a,Bo,i)*e%i,c=io(u,Go,i)*u%i,l=io(c,t,i)*c%i,f=io(l,r,i)*l%i,h=io(f,n,i)*f%i,d=io(h,o,i)*h%i,m=io(d,o,i)*h%i,g=io(m,t,i)*c%i;return{pow_p_5_8:io(g,_o,i)*e%i,b2:s}}(e*oo(n*n*t,r)).pow_p_5_8;let i=oo(e*n*o,r);const s=oo(t*i*i,r),a=i,u=oo(i*Ko,r),c=s===e,l=s===oo(-e,r),f=s===oo(-e*Ko,r);return c&&(i=a),(l||f)&&(i=u),(oo(i,r)&$n)===$n&&(i=oo(-i,r)),{isValid:c||l,value:i}}});function Jo(e){return function(e,t,r={}){if("function"!=typeof t)throw new Error('"hash" function param is required');Kn(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||Wr,u=r.adjustScalarBytes||(e=>e),c=r.domain||((e,t,r)=>{if(Nn(r,"phflag"),t.length||r)throw new Error("Contexts/pre-hash are not supported");return e});function l(e){return s.create(Bn(e))}function f(e){const{head:r,prefix:n,scalar:i}=function(e){const r=v.secretKey;Rr(e,v.secretKey,"secretKey");const n=Rr(t(e),2*r,"hashedSecretKey"),o=u(n.slice(0,r));return{head:o,prefix:n.slice(r,2*r),scalar:l(o)}}(e),s=o.multiply(i),a=s.toBytes();return{head:r,prefix:n,scalar:i,point:s,pointBytes:a}}function h(e){return f(e).pointBytes}function d(e=Uint8Array.of(),...r){const o=Jr(...r);return l(t(c(o,Rr(e,void 0,"context"),!!n)))}const m={zip215:!0},g=i.BYTES,v={secretKey:g,publicKey:g,signature:2*g,seed:g};function p(e=a(v.seed)){return Rr(e,v.seed,"seed")}const y={getExtendedPublicKey:f,randomSecretKey:p,isValidSecretKey:function(e){return Lr(e)&&e.length===s.BYTES},isValidPublicKey:function(t,r){try{return!!e.fromBytes(t,r)}catch(e){return!1}},toMontgomery(t){const{y:r}=e.fromBytes(t),n=v.publicKey,o=32===n;if(!o&&57!==n)throw new Error("only defined for 25519 and 448");const s=o?i.div(Lo+r,Lo-r):i.div(r-Lo,r+Lo);return i.toBytes(s)},toMontgomerySecret(e){const r=v.secretKey;Rr(e,r);const n=t(e.subarray(0,r));return u(n).subarray(0,r)}};return Object.freeze({keygen:Io(p,h),getPublicKey:h,sign:function(e,t,r={}){e=Rr(e,void 0,"message"),n&&(e=n(e));const{prefix:i,scalar:a,pointBytes:u}=f(t),c=d(r.context,i,e),l=o.multiply(c).toBytes(),h=d(r.context,l,u,e),m=s.create(c+h*a);if(!s.isValid(m))throw new Error("sign failed: invalid s");return Rr(Jr(l,s.toBytes(m)),v.signature,"result")},verify:function(t,r,i,s=m){const{context:a,zip215:u}=s,c=v.signature;t=Rr(t,c,"signature"),r=Rr(r,void 0,"message"),i=Rr(i,v.publicKey,"publicKey"),void 0!==u&&Nn(u,"zip215"),n&&(r=n(r));const l=c/2,f=t.subarray(0,l),h=Bn(t.subarray(l,c));let g,p,y;try{g=e.fromBytes(i,u),p=e.fromBytes(f,u),y=o.multiplyUnsafe(h)}catch(e){return!1}if(!u&&g.isSmallOrder())return!1;const b=d(a,p.toBytes(),g.toBytes(),r);return p.add(g.multiplyUnsafe(b)).subtract(y).clearCofactor().is0()},utils:y,Point:e,lengths:v})}(Zo,Dn,Object.assign({adjustScalarBytes:Ho},e))}const $o=/* @__PURE__ */Jo({});class Wo extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}}class Yo extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}}var Xo={get(e=globalThis){const t=e.crypto;if(null==t?.subtle)throw new Yo("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};let Qo;const ei=(async()=>{try{return await Xo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function ti(e){return null!=e&&"function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally}class ri{type="Ed25519";raw;constructor(e){this.raw=ni(e,32)}toMultihash(){return fr(Cs(this))}toCID(){return ir.createV1(114,this.toMultihash())}toString(){return Ut.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&A.equals(this.raw,e.raw)}verify(e,t,r){r?.signal?.throwIfAborted();const n=async function(e,t,r){return null==Qo&&(Qo=await ei),Qo?async function(e,t,r){if(e.buffer instanceof ArrayBuffer){const n=await Xo.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Xo.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}(e,t,r):function(e,t,r){return $o.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}(e,t,r)}(this.raw,t,e);return ti(n)?n.then(e=>(r?.signal?.throwIfAborted(),e)):n}}function ni(e,t){if((e=Uint8Array.from(e??[])).length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}const oi=Math.pow(2,7),ii=Math.pow(2,14),si=Math.pow(2,21),ai=Math.pow(2,28),ui=Math.pow(2,35),ci=Math.pow(2,42),li=Math.pow(2,49),fi=128,hi=127;function di(e){if(e<oi)return 1;if(e<ii)return 2;if(e<si)return 3;if(e<ai)return 4;if(e<ui)return 5;if(e<ci)return 6;if(e<li)return 7;if(null!=Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function mi(e,t,r=0){switch(di(e)){case 8:t[r++]=255&e|fi,e/=128;case 7:t[r++]=255&e|fi,e/=128;case 6:t[r++]=255&e|fi,e/=128;case 5:t[r++]=255&e|fi,e/=128;case 4:t[r++]=255&e|fi,e>>>=7;case 3:t[r++]=255&e|fi,e>>>=7;case 2:t[r++]=255&e|fi,e>>>=7;case 1:t[r++]=255&e,e>>>=7;break;default:throw new Error("unreachable")}return t}function gi(e,t){let r=e[t],n=0;if(n+=r&hi,r<fi)return n;if(r=e[t+1],n+=(r&hi)<<7,r<fi)return n;if(r=e[t+2],n+=(r&hi)<<14,r<fi)return n;if(r=e[t+3],n+=(r&hi)<<21,r<fi)return n;if(r=e[t+4],n+=(r&hi)*ai,r<fi)return n;if(r=e[t+5],n+=(r&hi)*ui,r<fi)return n;if(r=e[t+6],n+=(r&hi)*ci,r<fi)return n;if(r=e[t+7],n+=(r&hi)*li,r<fi)return n;throw new RangeError("Could not decode varint")}function vi(e,t,r=0){return null==t&&(t=E.allocUnsafe(di(e))),t instanceof Uint8Array?mi(e,t,r):function(e,t,r=0){switch(di(e)){case 8:t.set(r++,255&e|fi),e/=128;case 7:t.set(r++,255&e|fi),e/=128;case 6:t.set(r++,255&e|fi),e/=128;case 5:t.set(r++,255&e|fi),e/=128;case 4:t.set(r++,255&e|fi),e>>>=7;case 3:t.set(r++,255&e|fi),e>>>=7;case 2:t.set(r++,255&e|fi),e>>>=7;case 1:t.set(r++,255&e),e>>>=7;break;default:throw new Error("unreachable")}return t}(e,t,r)}function pi(e,t=0){return e instanceof Uint8Array?gi(e,t):function(e,t){let r=e.get(t),n=0;if(n+=r&hi,r<fi)return n;if(r=e.get(t+1),n+=(r&hi)<<7,r<fi)return n;if(r=e.get(t+2),n+=(r&hi)<<14,r<fi)return n;if(r=e.get(t+3),n+=(r&hi)<<21,r<fi)return n;if(r=e.get(t+4),n+=(r&hi)*ai,r<fi)return n;if(r=e.get(t+5),n+=(r&hi)*ui,r<fi)return n;if(r=e.get(t+6),n+=(r&hi)*ci,r<fi)return n;if(r=e.get(t+7),n+=(r&hi)*li,r<fi)return n;throw new RangeError("Could not decode varint")}(e,t)}const yi=new Float32Array([-0]),bi=new Uint8Array(yi.buffer);function Pi(e,t,r){yi[0]=e,t[r]=bi[0],t[r+1]=bi[1],t[r+2]=bi[2],t[r+3]=bi[3]}const wi=new Float64Array([-0]),Ei=new Uint8Array(wi.buffer);function Si(e,t,r){wi[0]=e,t[r]=Ei[0],t[r+1]=Ei[1],t[r+2]=Ei[2],t[r+3]=Ei[3],t[r+4]=Ei[4],t[r+5]=Ei[5],t[r+6]=Ei[6],t[r+7]=Ei[7]}const Ai=BigInt(Number.MAX_SAFE_INTEGER),Ti=BigInt(Number.MIN_SAFE_INTEGER);class xi{lo;hi;constructor(e,t){this.lo=0|e,this.hi=0|t}toNumber(e=!1){if(!e&&this.hi>>>31>0){const e=1+~this.lo>>>0;let t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(e+4294967296*t)}return this.lo+4294967296*this.hi}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31!=0){const e=1+~this.lo>>>0;let t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(BigInt(e)+(BigInt(t)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){const e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){const e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){const e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 0===r?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}static fromBigInt(e){if(0n===e)return ki;if(e<Ai&&e>Ti)return this.fromNumber(Number(e));const t=e<0n;t&&(e=-e);let r=e>>32n,n=e-(r<<32n);return t&&(r=0n|~r,n=0n|~n,++n>Ci&&(n=0n,++r>Ci&&(r=0n))),new xi(Number(n),Number(r))}static fromNumber(e){if(0===e)return ki;const t=e<0;t&&(e=-e);let r=e>>>0,n=(e-r)/4294967296>>>0;return t&&(n=~n>>>0,r=~r>>>0,++r>4294967295&&(r=0,++n>4294967295&&(n=0))),new xi(r,n)}static from(e){return"number"==typeof e?xi.fromNumber(e):"bigint"==typeof e?xi.fromBigInt(e):"string"==typeof e?xi.fromBigInt(BigInt(e)):null!=e.low||null!=e.high?new xi(e.low>>>0,e.high>>>0):ki}}const ki=new xi(0,0);ki.toBigInt=function(){return 0n},ki.zzEncode=ki.zzDecode=function(){return this},ki.length=function(){return 1};const Ci=4294967296n;function Oi(e,t,r){const n=r;let o,i;for(let n=0;n<e.length;++n)o=e.charCodeAt(n),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=63&o|128):55296==(64512&o)&&56320==(64512&(i=e.charCodeAt(n+1)))?(o=65536+((1023&o)<<10)+(1023&i),++n,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=63&o|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=63&o|128);return r-n}function Fi(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Di(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}class ji{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Fi(this,10);return e}int32(){return 0|this.uint32()}sint32(){const e=this.uint32();return e>>>1^-(1&e)}bool(){return 0!==this.uint32()}fixed32(){if(this.pos+4>this.len)throw Fi(this,4);return Di(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Fi(this,4);return 0|Di(this.buf,this.pos+=4)}float(){if(this.pos+4>this.len)throw Fi(this,4);const e=(bi[0]=(t=this.buf)[r=this.pos],bi[1]=t[r+1],bi[2]=t[r+2],bi[3]=t[r+3],yi[0]);var t,r;return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Fi(this,4);const e=(Ei[0]=(t=this.buf)[r=this.pos],Ei[1]=t[r+1],Ei[2]=t[r+2],Ei[3]=t[r+3],Ei[4]=t[r+4],Ei[5]=t[r+5],Ei[6]=t[r+6],Ei[7]=t[r+7],wi[0]);var t,r;return this.pos+=8,e}bytes(){const e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw Fi(this,e);return this.pos+=e,t===r?new Uint8Array(0):this.buf.subarray(t,r)}string(){const e=this.bytes();return function(e,t,r){if(r-t<1)return"";let n;const o=[];let i,s=0;for(;t<r;)i=e[t++],i<128?o[s++]=i:i>191&&i<224?o[s++]=(31&i)<<6|63&e[t++]:i>239&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,o[s++]=55296+(i>>10),o[s++]=56320+(1023&i)):o[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],s>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,o)),s=0);return null!=n?(s>0&&n.push(String.fromCharCode.apply(String,o.slice(0,s))),n.join("")):String.fromCharCode.apply(String,o.slice(0,s))}(e,0,e.length)}skip(e){if("number"==typeof e){if(this.pos+e>this.len)throw Fi(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw Fi(this)}while(128&this.buf[this.pos++]);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){const e=new xi(0,0);let t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw Fi(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Fi(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Fi(this,8);const e=Di(this.buf,this.pos+=4),t=Di(this.buf,this.pos+=4);return new xi(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){const e=gi(this.buf,this.pos);return this.pos+=di(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}}function Ii(e,t,r){const n=function(e){return new ji(e instanceof Uint8Array?e:e.subarray())}(e);return t.decode(n,void 0,r)}class Ni{fn;len;next;val;constructor(e,t,r){this.fn=e,this.len=t,this.next=void 0,this.val=r}}function Li(){}class Ui{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}}const Ri=function(){const e=8192;let t,r=e;return function(n){if(n<1||n>4096)return E.allocUnsafe(n);r+n>e&&(t=E.allocUnsafe(e),r=0);const o=t.subarray(r,r+=n);return 7&r&&(r=1+(7|r)),o}}();class Mi{len;head;tail;states;constructor(){this.len=0,this.head=new Ni(Li,0,0),this.tail=this.head,this.states=null}_push(e,t,r){return this.tail=this.tail.next=new Ni(e,t,r),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Gi((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(qi,10,xi.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){const t=xi.fromBigInt(e);return this._push(qi,t.length(),t)}uint64Number(e){return this._push(mi,di(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){const t=xi.fromBigInt(e).zzEncode();return this._push(qi,t.length(),t)}sint64Number(e){const t=xi.fromNumber(e).zzEncode();return this._push(qi,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Bi,1,e?1:0)}fixed32(e){return this._push(Vi,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){const t=xi.fromBigInt(e);return this._push(Vi,4,t.lo)._push(Vi,4,t.hi)}fixed64Number(e){const t=xi.fromNumber(e);return this._push(Vi,4,t.lo)._push(Vi,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Pi,4,e)}double(e){return this._push(Si,8,e)}bytes(e){const t=e.length>>>0;return 0===t?this._push(Bi,1,0):this.uint32(t)._push(zi,t,e)}string(e){const t=function(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(n+1))?(++n,t+=4):t+=3;return t}(e);return 0!==t?this.uint32(t)._push(Oi,t,e):this._push(Bi,1,0)}fork(){return this.states=new Ui(this),this.head=this.tail=new Ni(Li,0,0),this.len=0,this}reset(){return null!=this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ni(Li,0,0),this.len=0),this}ldelim(){const e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),0!==r&&(this.tail.next=e.next,this.tail=t,this.len+=r),this}finish(){let e=this.head.next;const t=(r=this.len,null!=globalThis.Buffer?E.allocUnsafe(r):Ri(r));var r;let n=0;for(;null!=e;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}}function Bi(e,t,r){t[r]=255&e}function _i(e,t,r){for(;e>127;)t[r++]=127&e|128,e>>>=7;t[r]=e}class Gi extends Ni{next;constructor(e,t){super(_i,e,t),this.next=void 0}}function qi(e,t,r){for(;0!==e.hi;)t[r++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=127&e.lo|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Vi(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function zi(e,t,r){t.set(e,r)}function Hi(e,t,r){t.set(e,r)}function Ki(e,t,r){e.length<40?Oi(e,t,r):null!=t.utf8Write?t.utf8Write(e,r):t.set(T.fromString(e),r)}function Zi(e,t){const r=new Mi;return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ji,$i,Wi,Yi,Xi;function Qi(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function es(e,t){return Qi("message",Ji.LENGTH_DELIMITED,e,t)}null!=globalThis.Buffer&&(Mi.prototype.bytes=function(e){const t=e.length>>>0;return this.uint32(t),t>0&&this._push(Hi,t,e),this},Mi.prototype.string=function(e){const t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Ki,t,e),this}),function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"}(Ji||(Ji={})),function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"}($i||($i={})),function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"}(Wi||(Wi={})),function(e){e.codec=()=>function(e){function t(t){if(null==e[t.toString()])throw new Error("Invalid enum value");return e[t]}return Qi("enum",Ji.VARINT,function(e,r){const n=t(e);r.int32(n)},function(e){return t(e.int32())})}(Wi)}($i||($i={})),function(e){let t;e.codec=()=>(null==t&&(t=es((e,t,r={})=>{!1!==r.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),$i.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==r.lengthDelimited&&t.ldelim()},(e,t,r={})=>{const n={},o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:n.Type=$i.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&t)}}return n})),t),e.encode=t=>Zi(t,e.codec()),e.decode=(t,r)=>Ii(t,e.codec(),r)}(Yi||(Yi={})),function(e){let t;e.codec=()=>(null==t&&(t=es((e,t,r={})=>{!1!==r.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),$i.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==r.lengthDelimited&&t.ldelim()},(e,t,r={})=>{const n={},o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:n.Type=$i.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&t)}}return n})),t),e.encode=t=>Zi(t,e.codec()),e.decode=(t,r)=>Ii(t,e.codec(),r)}(Xi||(Xi={}));class ts{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Mr(e),Rr(t,void 0,"key"),this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,n=new Uint8Array(r);n.set(t.length>r?e.create().update(t).digest():t);for(let e=0;e<n.length;e++)n[e]^=54;this.iHash.update(n),this.oHash=e.create();for(let e=0;e<n.length;e++)n[e]^=106;this.oHash.update(n),_r(n)}update(e){return Br(this),this.iHash.update(e),this}digestInto(e){Br(this),Rr(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});const{oHash:t,iHash:r,finished:n,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=n,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const rs=(e,t,r)=>new ts(e,t).update(r).digest();rs.create=(e,t)=>new ts(e,t);const ns=(e,t)=>(e+(e>=0?t:-t)/ls)/t;function os(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function is(e,t){const r={};for(let n of Object.keys(t))r[n]=void 0===e[n]?t[n]:e[n];return Nn(r.lowS,"lowS"),Nn(r.prehash,"prehash"),void 0!==r.format&&os(r.format),r}class ss extends Error{constructor(e=""){super(e)}}const as={Err:ss,_tlv:{encode:(e,t)=>{const{Err:r}=as;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(1&t.length)throw new r("tlv.encode: unpadded data");const n=t.length/2,o=Un(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");const i=n>127?Un(o.length/2|128):"";return Un(e)+i+o+t},decode(e,t){const{Err:r}=as;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const o=t[n++];let i=0;if(128&o){const e=127&o;if(!e)throw new r("tlv.decode(long): indefinite length not supported");if(e>4)throw new r("tlv.decode(long): byte length is too big");const s=t.subarray(n,n+e);if(s.length!==e)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(n+=e,i<128)throw new r("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(n,n+i);if(s.length!==i)throw new r("tlv.decode: wrong value length");return{v:s,l:t.subarray(n+i)}}},_int:{encode(e){const{Err:t}=as;if(e<us)throw new t("integer: negative integers are not allowed");let r=Un(e);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=as;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return Mn(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=as,o=Rr(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=n.decode(2,i),{v:c,l:l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){const{_tlv:t,_int:r}=as,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s));return t.encode(48,n+o)}},us=BigInt(0),cs=BigInt(1),ls=BigInt(2),fs=BigInt(3),hs=BigInt(4);function ds(e,t={}){const r=jo("weierstrass",e,t),{Fp:n,Fn:o}=r;let i=r.CURVE;const{h:s,n:a}=i;Kn(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:u}=t;if(u&&(!n.is0(i.a)||"bigint"!=typeof u.beta||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const c=gs(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,r){const{x:o,y:i}=t.toAffine(),s=n.toBytes(o);return Nn(r,"isCompressed"),r?(l(),Jr(ms(!n.isOdd(i)),s)):Jr(Uint8Array.of(4),s,n.toBytes(i))},h=t.fromBytes||function(e){Rr(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:r}=c,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===r&&4===i){const e=n.BYTES,t=n.fromBytes(s.subarray(0,e)),r=n.fromBytes(s.subarray(e,2*e));if(!m(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${r}`)}{const e=n.fromBytes(s);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let r;try{r=n.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}};function d(e){const t=n.sqr(e),r=n.mul(t,e);return n.add(n.add(r,n.mul(e,i.a)),i.b)}function m(e,t){const r=n.sqr(t),o=d(e);return n.eql(r,o)}if(!m(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=n.mul(n.pow(i.a,fs),hs),v=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(g,v)))throw new Error("bad curve params: a or b");function p(e,t,r=!1){if(!n.isValid(t)||r&&n.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function y(e){if(!(e instanceof S))throw new Error("Weierstrass Point expected")}function b(e){if(!u||!u.basises)throw new Error("no endo");return function(e,t,r){const[[n,o],[i,s]]=t,a=ns(s*e,r),u=ns(-o*e,r);let c=e-a*n-u*i,l=-a*o-u*s;const f=c<us,h=l<us;f&&(c=-c),h&&(l=-l);const d=Hn(Math.ceil(function(e){let t;for(t=0;e>jn;e>>=In,t+=1);return t}(r)/2))+cs;if(c<us||c>=d||l<us||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:c,k2neg:h,k2:l}}(e,u.basises,o.ORDER)}const P=Zn((e,t)=>{const{X:r,Y:o,Z:i}=e;if(n.eql(i,n.ONE))return{x:r,y:o};const s=e.is0();null==t&&(t=s?n.ONE:n.inv(i));const a=n.mul(r,t),u=n.mul(o,t),c=n.mul(i,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),w=Zn(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:o}=e.toAffine();if(!n.isValid(r)||!n.isValid(o))throw new Error("bad point: x or y not field elements");if(!m(r,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(e,t,r,o,i){return r=new S(n.mul(r.X,e),r.Y,r.Z),t=wo(o,t),r=wo(i,r),t.add(r)}class S{static BASE=new S(i.Gx,i.Gy,n.ONE);static ZERO=new S(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(e,t,r){this.X=p("x",e),this.Y=p("y",t,!0),this.Z=p("z",r),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof S)throw new Error("projective point not allowed");return n.is0(t)&&n.is0(r)?S.ZERO:new S(t,r,n.ONE)}static fromBytes(e){const t=S.fromAffine(h(Rr(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return S.fromBytes(Zr(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(fs),this}assertValidity(){w(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){y(e);const{X:t,Y:r,Z:o}=this,{X:i,Y:s,Z:a}=e,u=n.eql(n.mul(t,a),n.mul(i,o)),c=n.eql(n.mul(r,a),n.mul(s,o));return u&&c}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,r=n.mul(t,fs),{X:o,Y:s,Z:a}=this;let u=n.ZERO,c=n.ZERO,l=n.ZERO,f=n.mul(o,o),h=n.mul(s,s),d=n.mul(a,a),m=n.mul(o,s);return m=n.add(m,m),l=n.mul(o,a),l=n.add(l,l),u=n.mul(e,l),c=n.mul(r,d),c=n.add(u,c),u=n.sub(h,c),c=n.add(h,c),c=n.mul(u,c),u=n.mul(m,u),l=n.mul(r,l),d=n.mul(e,d),m=n.sub(f,d),m=n.mul(e,m),m=n.add(m,l),l=n.add(f,f),f=n.add(l,f),f=n.add(f,d),f=n.mul(f,m),c=n.add(c,f),d=n.mul(s,a),d=n.add(d,d),f=n.mul(d,m),u=n.sub(u,f),l=n.mul(d,h),l=n.add(l,l),l=n.add(l,l),new S(u,c,l)}add(e){y(e);const{X:t,Y:r,Z:o}=this,{X:s,Y:a,Z:u}=e;let c=n.ZERO,l=n.ZERO,f=n.ZERO;const h=i.a,d=n.mul(i.b,fs);let m=n.mul(t,s),g=n.mul(r,a),v=n.mul(o,u),p=n.add(t,r),b=n.add(s,a);p=n.mul(p,b),b=n.add(m,g),p=n.sub(p,b),b=n.add(t,o);let P=n.add(s,u);return b=n.mul(b,P),P=n.add(m,v),b=n.sub(b,P),P=n.add(r,o),c=n.add(a,u),P=n.mul(P,c),c=n.add(g,v),P=n.sub(P,c),f=n.mul(h,b),c=n.mul(d,v),f=n.add(c,f),c=n.sub(g,f),f=n.add(g,f),l=n.mul(c,f),g=n.add(m,m),g=n.add(g,m),v=n.mul(h,v),b=n.mul(d,b),g=n.add(g,v),v=n.sub(m,v),v=n.mul(h,v),b=n.add(b,v),m=n.mul(g,b),l=n.add(l,m),m=n.mul(P,b),c=n.mul(p,c),c=n.sub(c,m),m=n.mul(p,g),f=n.mul(P,f),f=n.add(f,m),new S(c,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(S.ZERO)}multiply(e){const{endo:r}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let n,i;const s=e=>T.cached(this,e,e=>Eo(S,e));if(r){const{k1neg:t,k1:o,k2neg:a,k2:u}=b(e),{p:c,f:l}=s(o),{p:f,f:h}=s(u);i=l.add(h),n=E(r.beta,c,f,t,a)}else{const{p:t,f:r}=s(e);n=t,i=r}return Eo(S,[n,i])[0]}multiplyUnsafe(e){const{endo:r}=t,n=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===us||n.is0())return S.ZERO;if(e===cs)return n;if(T.hasCache(this))return this.multiply(e);if(r){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:u}=function(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>bo||n>bo;)r&Po&&(i=i.add(o)),n&Po&&(s=s.add(o)),o=o.double(),r>>=Po,n>>=Po;return{p1:i,p2:s}}(S,n,o,s);return E(r.beta,a,u,t,i)}return T.unsafe(n,e)}toAffine(e){return P(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===cs||(e?e(S,this):T.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===cs?this:e?e(S,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return Nn(e,"isCompressed"),this.assertValidity(),f(S,this,e)}toHex(e=!0){return Hr(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const A=o.BITS,T=new Fo(S,t.endo?Math.ceil(A/2):A);return S.BASE.precompute(8),S}function ms(e){return Uint8Array.of(e?2:3)}function gs(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function vs(e,t,r={}){Mr(t),Kn(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const n=(r=Object.assign({},r)).randomBytes||Wr,o=r.hmac||((e,r)=>rs(t,e,r)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:u}=s,{keygen:c,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:r}=e,n=t.randomBytes||Wr,o=Object.assign(gs(e.Fp,r),{seed:yo(r.ORDER)});function i(e=n(o.seed)){return function(e,t,r=!1){Rr(e);const n=e.length,o=po(t),i=yo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);const s=oo(r?Bn(e):Mn(e),t-$n)+$n;return r?Gn(s,o):_n(s,o)}(Rr(e,o.seed,"seed"),r.ORDER)}function s(t,n=!0){return e.BASE.multiply(r.fromBytes(t)).toBytes(n)}function a(e){const{secretKey:t,publicKey:n,publicKeyUncompressed:i}=o;if(!Lr(e))return;if("_lengths"in r&&r._lengths||t===n)return;const s=Rr(e,void 0,"key").length;return s===n||s===i}const u={isValidSecretKey:function(e){try{const t=r.fromBytes(e);return r.isValidNot0(t)}catch(e){return!1}},isValidPublicKey:function(t,r){const{publicKey:n,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===r&&o!==n||!1===r&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:i},c=Io(i,s);return Object.freeze({getPublicKey:s,getSharedSecret:function(t,n,o=!0){if(!0===a(t))throw new Error("first arg must be private key");if(!1===a(n))throw new Error("second arg must be public key");const i=r.fromBytes(t);return e.fromBytes(n).multiply(i).toBytes(o)},keygen:c,Point:e,utils:u,lengths:o})}(e,r),m={prehash:!0,lowS:"boolean"!=typeof r.lowS||r.lowS,format:"compact",extraEntropy:!1},g=a*ls<i.ORDER;function v(e){return e>a>>cs}function p(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function y(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(e,t){os(t);const r=d.signature;return Rr(e,"compact"===t?r:"recovered"===t?r+1:void 0)}class P{r;s;recovery;constructor(e,t,r){if(this.r=p("r",e),this.s=p("s",t),null!=r){if(y(),![0,1,2,3].includes(r))throw new Error("invalid recovery id");this.recovery=r}Object.freeze(this)}static fromBytes(e,t=m.format){let r;if(b(e,t),"der"===t){const{r:t,s:r}=as.toSig(Rr(e));return new P(t,r)}"recovered"===t&&(r=e[0],t="compact",e=e.subarray(1));const n=d.signature/2,o=e.subarray(0,n),i=e.subarray(n,2*n);return new P(s.fromBytes(o),s.fromBytes(i),r)}static fromHex(e,t){return this.fromBytes(Zr(e),t)}assertRecovery(){const{recovery:e}=this;if(null==e)throw new Error("invalid recovery id: must be present");return e}addRecoveryBit(e){return new P(this.r,this.s,e)}recoverPublicKey(t){const{r:r,s:n}=this,o=this.assertRecovery(),u=2===o||3===o?r+a:r;if(!i.isValid(u))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const c=i.toBytes(u),l=e.fromBytes(Jr(ms(!(1&o)),c)),f=s.inv(u),h=E(Rr(t,void 0,"msgHash")),d=s.create(-h*f),m=s.create(n*f),g=e.BASE.multiplyUnsafe(d).add(l.multiplyUnsafe(m));if(g.is0())throw new Error("invalid recovery: point at infinify");return g.assertValidity(),g}hasHighS(){return v(this.s)}toBytes(e=m.format){if(os(e),"der"===e)return Zr(as.hexFromSig(this));const{r:t,s:r}=this,n=s.toBytes(t),o=s.toBytes(r);return"recovered"===e?(y(),Jr(Uint8Array.of(this.assertRecovery()),n,o)):Jr(n,o)}toHex(e){return Hr(this.toBytes(e))}}const w=r.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=Mn(e),r=8*e.length-u;return r>0?t>>BigInt(r):t},E=r.bits2int_modN||function(e){return s.create(w(e))},S=Hn(u);function A(e){return zn("num < 2^"+u,e,us,S),s.toBytes(e)}function T(e,r){return Rr(e,void 0,"message"),r?Rr(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:c,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(r,i,a={}){const{seed:u,k2sig:c}=function(t,r,o){const{lowS:i,prehash:a,extraEntropy:u}=is(o,m);t=T(t,a);const c=E(t),l=s.fromBytes(r);if(!s.isValidNot0(l))throw new Error("invalid private key");const f=[A(l),A(c)];if(null!=u&&!1!==u){const e=!0===u?n(d.secretKey):u;f.push(Rr(e,void 0,"extraEntropy"))}const h=Jr(...f),p=c;return{seed:h,k2sig:function(t){const r=w(t);if(!s.isValidNot0(r))return;const n=s.inv(r),o=e.BASE.multiply(r).toAffine(),a=s.create(o.x);if(a===us)return;const u=s.create(n*s.create(p+a*l));if(u===us)return;let c=(o.x===a?0:2)|Number(o.y&cs),f=u;return i&&v(u)&&(f=s.neg(u),c^=1),new P(a,f,g?void 0:c)}}}(r,i,a);return function(e,t,r){if(Ur(e,"hashLen"),Ur(t,"qByteLen"),"function"!=typeof r)throw new Error("hmacFn must be a function");const n=e=>new Uint8Array(e),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1);let a=n(e),u=n(e),c=0;const l=()=>{a.fill(1),u.fill(0),c=0},f=(...e)=>r(u,Jr(a,...e)),h=(e=o)=>{u=f(i,e),a=f(),0!==e.length&&(u=f(s,e),a=f())},d=()=>{if(c++>=1e3)throw new Error("drbg: tried max amount of iterations");let e=0;const r=[];for(;e<t;){a=f();const t=a.slice();r.push(t),e+=a.length}return Jr(...r)};return(e,t)=>{let r;for(l(),h(e);!(r=t(d()));)h();return l(),r}}(t.outputLen,s.BYTES,o)(u,c).toBytes(a.format)},verify:function(t,r,n,o={}){const{lowS:i,prehash:a,format:u}=is(o,m);if(n=Rr(n,void 0,"publicKey"),r=T(r,a),!Lr(t))throw new Error("verify expects Uint8Array signature"+(t instanceof P?", use sig.toBytes()":""));b(t,u);try{const o=P.fromBytes(t,u),a=e.fromBytes(n);if(i&&o.hasHighS())return!1;const{r:c,s:l}=o,f=E(r),h=s.inv(l),d=s.create(f*h),m=s.create(c*h),g=e.BASE.multiplyUnsafe(d).add(a.multiplyUnsafe(m));return!g.is0()&&s.create(g.x)===c}catch(e){return!1}},recoverPublicKey:function(e,t,r={}){const{prehash:n}=is(r,m);return t=T(t,n),P.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:P,hash:t})}const ps={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ys={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},bs=/* @__PURE__ */BigInt(2),Ps=vo(ps.p,{sqrt:function(e){const t=ps.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,l=c*c*e%t,f=io(l,r,t)*l%t,h=io(f,r,t)*l%t,d=io(h,bs,t)*c%t,m=io(d,o,t)*d%t,g=io(m,i,t)*m%t,v=io(g,a,t)*g%t,p=io(v,u,t)*v%t,y=io(p,a,t)*g%t,b=io(y,r,t)*l%t,P=io(b,s,t)*m%t,w=io(P,n,t)*c%t,E=io(w,bs,t);if(!Ps.eql(Ps.sqr(E),e))throw new Error("Cannot find square root");return E}}),ws=/* @__PURE__ */vs(/* @__PURE__ */ds(ps,{Fp:Ps,endo:ys}),Fn);function Es({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ss(e,t,r,n,o)}class Ss{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,r,n,o){this.name=e,this.code=t,this.encode=r,this.minDigestLength=n??20,this.maxDigestLength=o}digest(e,t){if(null!=t?.truncate){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(null!=this.maxDigestLength&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?As(r,this.code,t?.truncate):r.then(e=>As(e,this.code,t?.truncate))}throw Error("Unknown type, must be binary type")}}function As(e,t,r){if(null!=r&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Qt(t,e)}function Ts(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}const xs=Es({name:"sha2-256",code:18,encode:Ts("SHA-256")});Es({name:"sha2-512",code:19,encode:Ts("SHA-512")});class ks{type="secp256k1";raw;_key;constructor(e){this._key=function(e){try{return ws.Point.fromBytes(e),e}catch(e){throw new bt(String(e))}}(e),this.raw=function(e){return ws.Point.fromBytes(e).toBytes()}(this._key)}toMultihash(){return fr(Cs(this))}toCID(){return ir.createV1(114,this.toMultihash())}toString(){return Ut.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&A.equals(this.raw,e.raw)}verify(e,t,r){return function(e,t,r,n){const o=xs.digest(r instanceof Uint8Array?r:r.subarray());if(ti(o))return o.then(({digest:r})=>(n?.signal?.throwIfAborted(),ws.verify(t,r,e,{prehash:!1,format:"der"}))).catch(e=>{if("AbortError"===e.name)throw e;throw new Wo(String(e))});try{return n?.signal?.throwIfAborted(),ws.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(e){throw new Wo(String(e))}}(this._key,t,e,r)}}function Cs(e){return Yi.encode({Type:$i[e.type],Data:e.raw})}const Os=Symbol.for("nodejs.util.inspect.custom");class Fs{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tt]=!0;toString(){return null==this.string&&(this.string=Ut.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ir.createV1(114,this.multihash)}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return A.equals(this.multihash.bytes,e);if("string"==typeof e)return this.toString()===e;if(null!=e?.toMultihash()?.bytes)return A.equals(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Os](){return`PeerId(${this.toString()})`}}class Ds extends Fs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class js extends Fs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}}class Is extends Fs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}}class Ns{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=fr(T.fromString(this.url))}[Os](){return`PeerId(${this.url})`}[Tt]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ir.createV1(2336,this.toMultihash())}toJSON(){return this.toString()}equals(e){return null!=e&&(e instanceof Uint8Array&&(e=x.toString(e)),e.toString()===this.toString())}}function Ls(e,t){let r;if("1"===e.charAt(0)||"Q"===e.charAt(0))r=er(Ut.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return function(e){if(null==e?.multihash||null==e.version||1===e.version&&114!==e.code&&2336!==e.code)throw new Pt("Supplied PeerID CID is invalid");if(2336===e.code){const t=x.toString(e.multihash.digest);return new Ns(new URL(t))}return Us(e.multihash)}(ir.parse(e));if(null==t)throw new yt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=er(t.decode(e))}return Us(r)}function Us(e){if(function(e){return e.code===xs.code}(e))return new Ds({multihash:e});if(function(e){return 0===e.code}(e))try{const t=function(e){const{Type:t,Data:r}=Yi.decode(e.digest),n=r??new Uint8Array;switch(t){case $i.Ed25519:return o=ni(o=n,32),new ri(o);case $i.secp256k1:return function(e){return new ks(e)}(n);case $i.ECDSA:return function(e){return function(e){const t=e[1][1][0];let r,n;if(65===t.byteLength)return r=x.toString(t.subarray(1,33),"base64url"),n=x.toString(t.subarray(33),"base64url"),new Nr({...Fr,key_ops:["verify"],x:r,y:n});if(97===t.byteLength)return r=x.toString(t.subarray(1,49),"base64url"),n=x.toString(t.subarray(49),"base64url"),new Nr({...Dr,key_ops:["verify"],x:r,y:n});if(133===t.byteLength)return r=x.toString(t.subarray(1,67),"base64url"),n=x.toString(t.subarray(67),"base64url"),new Nr({...jr,key_ops:["verify"],x:r,y:n});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}(Pr(e))}(n);default:throw new At}var o}(e);if("Ed25519"===t.type)return new js({multihash:e,publicKey:t});if("secp256k1"===t.type)return new Is({multihash:e,publicKey:t})}catch(t){const r=x.toString(e.digest);return new Ns(new URL(r))}throw new wt("Supplied PeerID Multihash is invalid")}function Rs(e,t){var r=C.PublicKey.fromHex(function(e){if("string"==typeof e)return e.startsWith("0x")?e:"0x"+e;var t=e instanceof Uint8Array?e:Array.isArray(e)?Uint8Array.from(e):Uint8Array.from(Object.keys(e).sort(function(e,t){return Number(e)-Number(t)}).map(function(t){return e[Number(t)]}));return"0x"+Buffer.from(t).toString("hex")}(e)),n=C.encrypt(r.toHex(),Buffer.from(t));return Buffer.from(n).toString("hex")}function Ms(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Bs=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getConsumerAddress=function(e){return la(e)},t.getSignature=function(e,t,r){return ca(e,t,r)},t.getAuthorization=function(e){return fa(e)},t.getEndpoints=function(e,t){try{var r=this;return Promise.resolve(Ms(function(){return Promise.resolve(r.getData(e,t)).then(function(e){return Promise.resolve(e.json())})},function(e){throw Te.error("Finding the service endpoints failed:",e),new Error("HTTP request failed calling Provider")}))}catch(e){return Promise.reject(e)}},t.getNodePublicKey=function(e){try{return Promise.resolve(this.getEndpoints(e)).then(function(e){return e.nodePublicKey})}catch(e){return Promise.reject(e)}},t.getEndpointURL=function(e,t){return e?e.find(function(e){return e.serviceName.toLowerCase()===t.toLowerCase()}):null},t.getServiceEndpoints=function(e,t){try{var r=[];for(var n in t.serviceEndpoints){var o={serviceName:n,method:t.serviceEndpoints[n][0],urlPath:e.replace(/\/+$/,"")+"/"+t.serviceEndpoints[n][1].replace(/^\/+/,"")};r.push(o)}return Promise.resolve(r)}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r,n,o){try{var i=function(){function i(){var e=s.getEndpointURL(o,"nonce")?s.getEndpointURL(o,"nonce").urlPath:null;return e?Ms(function(){return Promise.resolve(ue.default(e+"?userAddress="+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return Promise.resolve(e.json()).then(function(e){var t=e.nonce;return t&&null!==t?Number(t):0})})},function(e){throw Te.error(e),new Error(e.message)}):null}var a=function(){if(!o)return Promise.resolve(s.getServiceEndpoints(e,n)).then(function(e){o=e})}();return a&&a.then?a.then(i):i()},s=this,a=function(){if(!n)return Promise.resolve(s.getEndpoints(e)).then(function(e){n=e})}();return Promise.resolve(a&&a.then?a.then(i):i())}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(r)).then(function(o){return Promise.resolve(s.getServiceEndpoints(r,o)).then(function(a){return Promise.resolve(s.getConsumerAddress(n)).then(function(u){return Promise.resolve(s.getNonce(r,u,i,o,a)).then(function(r){var o=(r+1).toString();return Promise.resolve(s.getSignature(n,o,he.ENCRYPT)).then(function(r){var n=(s.getEndpointURL(a,"encrypt")?s.getEndpointURL(a,"encrypt").urlPath:null)+"?chainId="+t;return n?(n+="&nonce="+o,n+="&consumerAddress="+u,n+="&signature="+r,Ms(function(){return Promise.resolve(ue.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/octet-stream"},signal:i})).then(function(e){return Promise.resolve(e.text())})},function(e){throw Te.error(e),new Error("HTTP request failed calling Provider")})):null})})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{var i=this;return Promise.resolve(i.getEndpoints(r)).then(function(s){return Promise.resolve(i.getServiceEndpoints(r,s)).then(function(r){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw Te.error("File info call failed: ",a.status,a.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){for(var r,n=pe(e);!(r=n()).done;)c.push(r.value);return t=1,c})}();return n&&n.then?n.then(r):r(n)}var a,u={did:e,serviceId:t,checksum:n},c=[],l=i.getEndpointURL(r,"fileinfo")?i.getEndpointURL(r,"fileinfo").urlPath:null;if(!l)return null;var f=Ms(function(){return Promise.resolve(ue.default(l,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o})).then(function(e){a=e})},function(e){throw Te.error("File info call failed: "),Te.error(e),new Error(e)});return f&&f.then?f.then(s):s()})})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{var o=this;return Promise.resolve(o.getEndpoints(t)).then(function(i){return Promise.resolve(o.getServiceEndpoints(t,i)).then(function(t){function i(e){var t;function r(e){return t?e:Promise.resolve(s.json()).then(function(e){throw Te.error("File info call failed: ",s.status,s.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=s)&&e.ok)return Promise.resolve(s.json()).then(function(e){for(var r,n=pe(e);!(r=n()).done;)u.push(r.value);return t=1,u})}();return n&&n.then?n.then(r):r(n)}var s,a=ye({},e,{checksum:r}),u=[],c=o.getEndpointURL(t,"fileinfo")?o.getEndpointURL(t,"fileinfo").urlPath:null;if(!c)return null;var l=Ms(function(){return Promise.resolve(ue.default(c,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){s=e})},function(e){throw Te.error("File info call failed: "),Te.error(e),new Error(e)});return l&&l.then?l.then(i):i()})})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){var n;function o(e){var t;return null!=(t=i)&&t.ok?i.json():Promise.resolve(i.json()).then(function(e){throw Te.error("Fetch compute env failed: ",i.status,i.statusText,e),new Error(JSON.stringify(e))})}var i,s=null==(n=r.getEndpointURL(e,"computeEnvironments"))?void 0:n.urlPath;if(!s)return null;var a=Ms(function(){return Promise.resolve(ue.default(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){i=e})},function(e){throw Te.error("Fetch compute env failed: "),Te.error(e),new Error(e)});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(o)).then(function(l){return Promise.resolve(c.getServiceEndpoints(o,l)).then(function(o){function l(e){var t;function r(e){return t?e:Promise.resolve(f.json()).then(function(e){throw Te.error("Provider initialized failed: ",f.status,f.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(200===(null==(e=f)?void 0:e.status))return Promise.resolve(f.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var f,h=c.getEndpointURL(o,"initialize")?c.getEndpointURL(o,"initialize").urlPath:null;if(!h)return null;h+="?documentId="+e,h+="&serviceId="+t,h+="&fileIndex="+r,h+="&consumerAddress="+n,s&&(h+="&userdata="+encodeURI(JSON.stringify(s))),a&&(h+="&environment="+encodeURI(a)),u&&(h+="&validUntil="+u);var d=Ms(function(){return Promise.resolve(ue.default(h,{method:"GET",headers:{"Content-Type":"application/json"},signal:i})).then(function(e){f=e})},function(e){throw Te.error("Provider initialized failed: "),Te.error(e),new Error("Provider initialize failed url: "+h+" ")});return d&&d.then?d.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getEndpoints(i)).then(function(m){return Promise.resolve(d.getServiceEndpoints(i,m)).then(function(g){var v=d.getEndpointURL(g,"initializeCompute")?d.getEndpointURL(g,"initializeCompute").urlPath:null;return v?Promise.resolve(d.getConsumerAddress(s)).then(function(p){return Promise.resolve(d.getNonce(i,p,l,m,g)).then(function(m){function g(){function m(){function e(){var e;function t(t){var r;function n(t){return r?t:Promise.resolve(e.json()).then(function(t){throw Te.error("Initialize compute failed: ",e.status,e.statusText,t),Te.error("Payload was:",JSON.stringify(g)),new Error(JSON.stringify(t))})}var o=function(t){if(null!=(t=e)&&t.ok)return Promise.resolve(e.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var r=Ms(function(){return Promise.resolve(ue.default(v,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json",Authorization:d.getAuthorization(s)},signal:l})).then(function(t){return e=t,function(){if(!e.ok)return Promise.resolve(e.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw Te.error("Initialize compute failed: "),Te.error(e),new Error("ComputeJob cannot be initialized: "+e.message+".")});return r&&r.then?r.then(t):t()}c&&(g.policyServer=c);var t=function(){if(f)return Promise.resolve(d.getNodePublicKey(i)).then(function(e){e&&(g.output=Rs(e,JSON.stringify(f)))})}();return t&&t.then?t.then(e):e()}var g={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:p,signature:y},b=function(){if(h)return Promise.resolve(d.getNodePublicKey(i)).then(function(e){e&&(g.dockerRegistryAuth=Rs(e,JSON.stringify(h)))})}();return b&&b.then?b.then(m):m()}var y,b=(m+1).toString(),P="string"==typeof s,w=function(){if(!P){var t,r=p;return r+=null==(t=e[0])?void 0:t.documentId,r+=b,Promise.resolve(pt(s,r)).then(function(e){y=e})}}();return w&&w.then?w.then(g):g()})}):null})})}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(o)).then(function(c){return Promise.resolve(u.getServiceEndpoints(o,c)).then(function(l){var f=u.getEndpointURL(l,"download")?u.getEndpointURL(l,"download").urlPath:null;return f?Promise.resolve(u.getConsumerAddress(i)).then(function(h){return Promise.resolve(u.getNonce(o,h,null,c,l)).then(function(o){var c=(o+1).toString();return Promise.resolve(u.getSignature(i,c,he.DOWNLOAD)).then(function(o){var i=f;return i+="?fileIndex="+r,i+="&documentId="+e,i+="&transferTxId="+n,i+="&serviceId="+t,i+="&consumerAddress="+h,i+="&nonce="+c,s&&(i+="&policyServer="+encodeURI(JSON.stringify(s))),i+="&signature="+o,a&&(i+="&userdata="+encodeURI(JSON.stringify(a))),i})})}):null})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{var v=this;return Promise.resolve(v.getEndpoints(e)).then(function(p){return Promise.resolve(v.getServiceEndpoints(e,p)).then(function(y){var b=v.getEndpointURL(y,"computeStart")?v.getEndpointURL(y,"computeStart").urlPath:null;return b?Promise.resolve(v.getConsumerAddress(t)).then(function(P){return Promise.resolve(v.getNonce(e,P,d,p,y)).then(function(p){var y=(p+1).toString();return Promise.resolve(v.getSignature(t,y,he.COMPUTE_START)).then(function(p){function w(){function r(){var e;function r(t){var r;function n(t){return r?t:Promise.resolve(e.json()).then(function(t){throw Te.error("Compute start failed: ",e.status,e.statusText,t),Te.error("Payload was:",E),new Error(JSON.stringify(t))})}var o=function(t){if(null!=(t=e)&&t.ok)return Promise.resolve(e.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}h&&(E.policyServer=h),m&&(E.queueMaxWaitTime=m);var n=Ms(function(){return Promise.resolve(ue.default(b,{method:"POST",body:JSON.stringify(E),headers:{"Content-Type":"application/json",Authorization:v.getAuthorization(t)},signal:d})).then(function(t){e=t})},function(e){throw Te.error("Compute start failed:"),Te.error(e),Te.error("Payload was:",E),new Error("HTTP request failed calling Provider")});return n&&n.then?n.then(r):r()}a&&(E.resources=a),c&&(E.metadata=c),l&&(E.additionalViewers=l);var n=function(){if(f)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(E.output=Rs(e,JSON.stringify(f)))})}();return n&&n.then?n.then(r):r()}var E=Object();E.consumerAddress=P,E.signature=p,E.nonce=y,E.environment=r,E.maxJobDuration=i,E.resources=a,E.dataset=n[0],E.datasets=n,E.algorithm=o,E.chainId=u,E.payment={chainId:u,token:s,maxJobDuration:i,resources:a};var S=function(){if(g)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(E.dockerRegistryAuth=Rs(e,JSON.stringify(g)))})}();return S&&S.then?S.then(w):w()})})}):(Te.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getEndpoints(e)).then(function(m){return Promise.resolve(d.getServiceEndpoints(e,m)).then(function(g){var v=d.getEndpointURL(g,"freeCompute")?d.getEndpointURL(g,"freeCompute").urlPath:null;return v?Promise.resolve(d.getConsumerAddress(t)).then(function(p){return Promise.resolve(d.getNonce(e,p,l,m,g)).then(function(m){var g=(m+1).toString();return Promise.resolve(d.getSignature(t,g,he.FREE_COMPUTE_START)).then(function(m){function y(){function r(){var e;function r(t){var r;function n(t){return r?t:Promise.resolve(e.json()).then(function(t){throw Te.error("Compute start failed: ",e.status,e.statusText,t),Te.error("Payload was:",b),new Error(JSON.stringify(t))})}var o=function(t){if(null!=(t=e)&&t.ok)return Promise.resolve(e.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}c&&(b.policyServer=c),f&&(b.queueMaxWaitTime=f);var n=Ms(function(){return Promise.resolve(ue.default(v,{method:"POST",body:JSON.stringify(b),headers:{"Content-Type":"application/json",Authorization:d.getAuthorization(t)},signal:l})).then(function(t){e=t})},function(e){throw Te.error("Compute start failed:"),Te.error(e),Te.error("Payload was:",b),new Error("HTTP request failed calling Provider")});return n&&n.then?n.then(r):r()}var n=function(){if(u)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(b.output=Rs(e,JSON.stringify(u)))})}();return n&&n.then?n.then(r):r()}var b=Object();b.consumerAddress=p,b.signature=m,b.nonce=g,b.environment=r,b.resources=i,b.dataset=n[0],b.datasets=n,b.algorithm=o,s&&(b.metadata=s),a&&(b.additionalViewers=a);var P=function(){if(h)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(b.dockerRegistryAuth=Rs(e,JSON.stringify(h)))})}();return P&&P.then?P.then(y):y()})})}):(Te.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeStreamableLogs")?o.getEndpointURL(a,"computeStreamableLogs").urlPath:null;return u?Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,n,s,a)).then(function(e){function s(){var e;function r(t){var r,n;if(null!=(r=e)&&r.ok||200===(null==(n=e)?void 0:n.status))return e.body;var o=Te.error,i=e.statusText,s=e.status;return Promise.resolve(e.json()).then(function(e){return o.call(Te,"computeStreamableLogs failed: ",s,i,e),null})}var i=Ms(function(){return Promise.resolve(ue.default(u+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o.getAuthorization(t)},signal:n})).then(function(t){e=t})},function(e){throw Te.error("computeStreamableLogs failed:"),Te.error(e),new Error("HTTP request failed calling Provider")});return i&&i.then?i.then(r):r()}var a=(e+1).toString(),l="?consumerAddress="+c+"&jobId="+r,f=function(){if(!i)return Promise.resolve(o.getSignature(t,a,he.COMPUTE_GET_STREAMABLE_LOGS)).then(function(e){l+="&signature="+e,l+="&nonce="+a})}();return f&&f.then?f.then(s):s()})}):(Te.error("Compute start failed: Cannot get proper computeStreamableLogs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this,s="string"==typeof r;return Promise.resolve(i.getEndpoints(t)).then(function(a){return Promise.resolve(i.getServiceEndpoints(t,a)).then(function(u){var c=i.getEndpointURL(u,"computeStop")?i.getEndpointURL(u,"computeStop").urlPath:null;return Promise.resolve(i.getConsumerAddress(r)).then(function(l){return Promise.resolve(i.getNonce(t,l,o,a,u)).then(function(t){var a=(t+1).toString();return Promise.resolve(i.getSignature(r,a,he.COMPUTE_STOP)).then(function(t){function u(e){var t;function r(e){return t?e:Promise.resolve(h.json()).then(function(e){throw Te.error("Compute stop failed: ",h.status,h.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=h)&&e.ok)return Promise.resolve(h.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var f=new URLSearchParams;f.set("consumerAddress",l),f.set("nonce",a),f.set("jobId",e),s||f.set("signature",t),n&&f.set("agreementId",n);var h,d=f.toString();if(!d)return null;var m=Ms(function(){return Promise.resolve(ue.default(c+"?"+d,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(r)},signal:o})).then(function(e){h=e})},function(e){throw Te.error("Compute stop failed:"),Te.error(e),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(u):u()})})})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{var i=this;return Promise.resolve(la(t)).then(function(s){var a=fa(t);return Promise.resolve(i.getEndpoints(e)).then(function(t){return Promise.resolve(i.getServiceEndpoints(e,t)).then(function(e){function t(e){var t;function r(e){var r;if(t)return e;function n(e){return r?e:Promise.resolve(u.json()).then(function(e){throw Te.error("Get compute status failed:",u.status,u.statusText,e),new Error(JSON.stringify(e))})}Te.error("Get compute status failed:",u.status,u.statusText);var o=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,c=i.getEndpointURL(e,"computeStatus")?i.getEndpointURL(e,"computeStatus").urlPath:null,l="?consumerAddress="+s;if(l+=n&&"&agreementId="+n||"",l+=r&&"&jobId="+r||"",!c)return null;var f=Ms(function(){return Promise.resolve(ue.default(c+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:a},signal:o})).then(function(e){u=e})},function(e){throw Te.error("Get compute status failed"),Te.error(e),new Error(e)});return f&&f.then?f.then(t):t()})})})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeResult")?o.getEndpointURL(a,"computeResult").urlPath:null;return Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,null,s,a)).then(function(e){var s=(e+1).toString();return Promise.resolve(o.getSignature(t,s,he.COMPUTE_GET_RESULT)).then(function(e){if(!u)return null;var t=u;return t+="?consumerAddress="+c,t+="&jobId="+r,t+="&index="+n.toString(),i||(t+="&nonce="+s,t+="&signature="+e),t})})})})})}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{return Promise.resolve(this.getComputeResultUrl(e,t,r,n)).then(function(e){if(!e)throw new Error("Could not retrieve compute result URL");return Promise.resolve(ue.default(e,{headers:o>0?{Range:"bytes="+o+"-"}:{}})).then(function(e){if(!e.ok)throw new Error("Failed to fetch compute result: "+e.status);return e.body})})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getEndpoints(t)).then(function(i){return Promise.resolve(n.getServiceEndpoints(t,i)).then(function(s){var a=n.getEndpointURL(s,"generateAuthToken").urlPath||null;return Promise.resolve(n.getNonce(t,o,r,i,s)).then(function(t){var i=(t+1).toString();return Promise.resolve(n.getSignature(e,i,he.CREATE_AUTH_TOKEN)).then(function(e){return Ms(function(){return Promise.resolve(ue.default(a,{method:"POST",body:JSON.stringify({address:o,signature:e,nonce:i}),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to generate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){return null==e?void 0:e.token})})},function(e){throw Te.error("Generate auth token failed:"),Te.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getEndpoints(r)).then(function(s){return Promise.resolve(o.getServiceEndpoints(r,s)).then(function(a){var u=o.getEndpointURL(a,"invalidateAuthToken").urlPath||null;return Promise.resolve(o.getNonce(r,i,n,s,a)).then(function(r){var o=(r+1).toString();return Promise.resolve(pt(e,i+o)).then(function(e){return Ms(function(){return Promise.resolve(ue.default(u,{method:"POST",body:JSON.stringify({address:i,signature:e,token:t,nonce:o}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to invalidate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json())})},function(e){throw Te.error("Generate auth token failed:"),Te.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(Ms(function(){return Promise.resolve(ue.default(e,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){var t,r=function(){if(null!=e&&e.ok)return Promise.resolve(e.json()).then(function(e){if(e&&(e.providerAddress||e.providerAddresses))return t=!0})}();return r&&r.then?r.then(function(e){return!!t&&e}):!!t&&r})},function(e){return Te.error("Error validating provider: "+e.message),!1}))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw Te.error("PolicyServerPassthrough failed: ",i.status,i.statusText,e),Te.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"PolicyServerPassthrough")?n.getEndpointURL(e,"PolicyServerPassthrough").urlPath:null;if(!s)return null;var a=Ms(function(){return Promise.resolve(ue.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw Te.error("PolicyServerPassthrough failed: "),Te.error(e),new Error("PolicyServerPassthrough failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw Te.error("initializePSVerification failed: ",i.status,i.statusText,e),Te.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"initializePSVerification")?n.getEndpointURL(e,"initializePSVerification").urlPath:null;if(!s)return null;var a=Ms(function(){return Promise.resolve(ue.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw Te.error("initializePSVerification failed: "),Te.error(e),new Error("initializePSVerification failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(e)).then(function(l){return Promise.resolve(c.getServiceEndpoints(e,l)).then(function(f){var h=c.getEndpointURL(f,"logs")?c.getEndpointURL(f,"logs").urlPath:null;return h?Promise.resolve(t.getAddress()).then(function(d){return Promise.resolve(c.getNonce(e,d,u,l,f)).then(function(e){var l=(e+1).toString();return Promise.resolve(c.getSignature(t,l,he.GET_LOGS)).then(function(e){function t(e){var t;return null!=(t=c)&&t.ok?c.body:Promise.resolve(c.json()).then(function(e){throw Te.error("Download node logs failed: ",c.status,c.statusText,e),new Error(JSON.stringify(e))})}var c,f=h+"?startTime="+r+"&endTime="+n;o&&(f+="&maxLogs="+o),i&&(f+="&moduleName="+i),s&&(f+="&level="+s),a&&(f+="&page="+a);var m=Ms(function(){return Promise.resolve(ue.default(f,{method:"POST",body:JSON.stringify({signature:e,nonce:l,address:d}),headers:{"Content-Type":"application/json"},signal:u})).then(function(e){c=e})},function(e){throw Te.error("Download node logs failed:"),Te.error(e),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(t):t()})})}):(Te.error("Download node logs failed: Cannot get proper logs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.noZeroX=function(e){return this.zeroXTransformer(e,!1)},t.zeroXTransformer=function(e,t){void 0===e&&(e="");var r=this.inputMatch(e,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(t&&r.valid?"0x":"")+r.output},t.inputMatch=function(e,t,r){if("string"!=typeof e)throw Te.debug("Not input string:"),Te.debug(e),new Error("["+r+"] Expected string, input type: "+typeof e);var n=e.match(t);return n?{valid:!0,output:n[1]}:(Te.warn("["+r+"] Input transformation failed."),{valid:!1,output:e})},t.resolveDdo=function(e,t,r){try{return Promise.resolve(ue.default(e+"/api/aquarius/assets/ddo/"+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return e.ok?e.json():null})}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{var o=this;return Promise.resolve(r.getAddress()).then(function(i){return Promise.resolve(o.getData(e+"/api/services/nonce?userAddress="+i)).then(function(o){return Promise.resolve(o.json()).then(function(o){var s,a=(Number(null!=(s=o.nonce)?s:0)+1).toString();return Promise.resolve(pt(r,i+a+he.VALIDATE_DDO)).then(function(r){return Promise.resolve(ue.default(e+"/api/aquarius/assets/ddo/validate",{method:"POST",body:JSON.stringify({ddo:t,publisherAddress:i,nonce:a,signature:r}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return{valid:!0,hash:e.hash,proof:{validatorAddress:e.publicKey,r:e.r[0],s:e.s[0],v:e.v}}}):null})})})})})}catch(e){return Promise.reject(e)}},t.getData=function(e,t){try{return Promise.resolve(ue.default(e,{method:"GET",headers:{"Content-type":"application/json",Authorization:t}}))}catch(e){return Promise.reject(e)}},e}();class _s extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,_s)}}const Gs=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function qs(e,t,r){"function"==typeof r&&(r={filter:r});const n=function(e,t,r){let n;const o=new Promise((o,i)=>{if(!((r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r}).count>=0)||r.count!==Number.POSITIVE_INFINITY&&!Number.isInteger(r.count))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();const s=[t].flat(),a=[],{addListener:u,removeListener:c}=(e=>{const t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}})(e),l=async(...e)=>{const t=r.multiArgs?e:e[0];if(r.filter)try{if(!await r.filter(t))return}catch(e){return n(),void i(e)}a.push(t),r.count===a.length&&(n(),o(a))},f=(...e)=>{n(),i(r.rejectionMultiArgs?e:e[0])};n=()=>{for(const e of s)c(e,l);for(const e of r.rejectionEvents)s.includes(e)||c(e,f)};for(const e of s)u(e,l);for(const e of r.rejectionEvents)s.includes(e)||u(e,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(a)});if(o.cancel=n,"number"==typeof r.timeout){const e=function(e,t){const{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout:setTimeout,clearTimeout:clearTimeout},signal:s}=t;let a,u;const c=new Promise((t,c)=>{if("number"!=typeof r||1!==Math.sign(r))throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted)return void c(Gs(s));if(s&&(u=()=>{c(Gs(s))},s.addEventListener("abort",u,{once:!0})),e.then(t,c),r===Number.POSITIVE_INFINITY)return;const l=new _s;a=i.setTimeout.call(void 0,()=>{if(n)try{t(n())}catch(e){c(e)}else"function"==typeof e.cancel&&e.cancel(),!1===o?t():o instanceof Error?c(o):(l.message=o??`Promise timed out after ${r} milliseconds`,c(l))},r)}).finally(()=>{c.clear(),u&&s&&s.removeEventListener("abort",u)});return c.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},c}(o,{milliseconds:r.timeout});return e.cancel=()=>{n(),e.clear()},e}return o}(e,t,r={...r,count:1,resolveImmediately:!1}),o=n.then(e=>e[0]);return o.cancel=n.cancel,o}function Vs(e){return e.reason}async function zs(e,t,r){if(null==t)return e;const n=r?.translateError??Vs;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((e,r)=>{o=()=>{r(n(t))},t.addEventListener("abort",o)})])}finally{null!=o&&t.removeEventListener("abort",o)}}class Hs{protocol;components;started;timeout;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;constructor(e,t={}){this.components=e,this.started=!1,this.protocol=`/${t.protocolPrefix??"ipfs"}/ping/1.0.0`,this.timeout=t.timeout??1e4,this.maxInboundStreams=t.maxInboundStreams??2,this.maxOutboundStreams=t.maxOutboundStreams??1,this.runOnLimitedConnection=t.runOnLimitedConnection??!0,this.handlePing=this.handlePing.bind(this)}[Symbol.toStringTag]="@libp2p/ping";[xt]=["@libp2p/ping"];async start(){await this.components.registrar.handle(this.protocol,this.handlePing,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async handlePing(e,t){const r=e.log.newScope("ping");r.trace("ping from %p",t.remotePeer);const n=AbortSignal.timeout(this.timeout);n.addEventListener("abort",()=>{e.abort(new St("Ping timed out"))});const o=Date.now();for await(const t of e){if("open"!==e.status){r("stream status changed to %s",e.status);break}e.send(t)||(r("waiting for stream to drain"),await qs(e,"drain",{rejectionEvents:["close"],signal:n}),r("stream drained"))}r("ping from %p complete in %dms",t.remotePeer,Date.now()-o),await e.close({signal:n})}async ping(e,t={}){const r=function(){if(isNaN(32))throw new yt("random bytes length must be a Number bigger than 0");return Wr(32)}(),n=await this.components.connectionManager.openStream(e,this.protocol,{runOnLimitedConnection:this.runOnLimitedConnection,...t}),o=n.log.newScope("ping");try{const e=Date.now(),o=Promise.withResolvers(),i=new gr,s=a=>{if(i.append(a.data),32===i.byteLength){n.removeEventListener("message",s);const a=Date.now()-e;Promise.all([n.closeRead(t)]).then(()=>{if(!A.equals(r,i.subarray()))throw new Et(`Received wrong ping ack after ${a}ms`);o.resolve(a)}).catch(e=>{n.abort(e),o.reject(e)})}};return n.addEventListener("message",s),n.send(r),await n.close(t),await zs(o.promise,t.signal)}catch(t){throw o.error("error while pinging %o - %e",e,t),n?.abort(t),t}finally{n?.close()}}}function Ks(e={}){return t=>new Hs(t,e)}class Zs extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"}class Js extends Error{static name="UnwrappedError";name="UnwrappedError"}class $s extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"}class Ws extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"}class Ys extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"}function Xs(e){return function(e){return"function"==typeof e?.closeRead}(e)?"writable"!==e.remoteWriteStatus&&0===e.readBufferLength:!!function(e){return"function"==typeof e?.close}(e)&&"open"!==e.status}function Qs(e,t,r){if(!e.s){if(r instanceof ea){if(!r.s)return void(r.o=Qs.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Qs.bind(null,e,t),Qs.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var ea=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Qs(n,1,i(this.v))}catch(e){Qs(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Qs(n,1,t?t(o):o):r?Qs(n,1,r(o)):Qs(n,2,o)}catch(e){Qs(n,2,e)}},n},e}();function ta(e){return e instanceof ea&&1&e.s}function ra(e,t,r){for(var n;;){var o=e();if(ta(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!ta(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!ta(s)){n=2;break}}}var a=new ea,u=Qs.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(f)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!ta(s))return void s.then(f).then(void 0,u);if(!(o=e())||ta(o)&&!o.v)return void Qs(a,1,i);if(o.then)return void o.then(l).then(void 0,u);ta(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):Qs(a,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):Qs(a,1,i)}}function na(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function oa(e,t){try{var r=e()}catch(e){return t(!0,e)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,r)}var ia="/ocean/nodes/1.0.0",sa=1e4,aa=["/dns4/bootstrap1.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP","/dns4/bootstrap2.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4","/dns4/bootstrap3.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U","/dns4/bootstrap4.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom"],ua=/*#__PURE__*/function(){function e(){this.p2pConfig={},this.libp2pNode=null,this.discoveredNodes=new Map}var t=e.prototype;return t.setupP2P=function(e){try{var t=this;return t.p2pConfig=e,t.discoveredNodes.clear(),t.libp2pNode&&(Promise.resolve(t.libp2pNode.stop()).catch(function(){}),t.libp2pNode=null),Promise.resolve(t.getOrCreateLibp2pNode()).then(function(){})}catch(e){return Promise.reject(e)}},t.getMultiaddrFromPeerId=function(e){try{var t,r,n=this,o=function(e){return e.includes("/p2p/")?e:e+"/p2p/"+e};return Promise.resolve(n.getOrCreateLibp2pNode()).then(function(i){var s;function a(t){if(s)return t;throw new Error("No multiaddrs found for peer id "+e)}var u=i.getConnections().find(function(t){return t.remotePeer.toString()===e});if(null!=u&&u.remoteAddr){var c=u.remoteAddr.toString();return o(c)}var l=n.discoveredNodes.get(e);if(l&&l.length>0)return o(l[0]);var f,h=i.services.dht,d=!1,m=!1,g=oa(function(){return na(function(){return t=function(e){var t,r,n,o=2;for("undefined"!=typeof Symbol&&(r=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(r&&null!=(t=e[r]))return t.call(e);if(n&&null!=(t=e[n]))return new ge(t.call(e));r="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}(h.findPeer(Ls(e),{signal:AbortSignal.timeout(2e4)})),ra(function(){function e(e){return!s&&(d=!(r=e).done)}return s?!!e(!s&&t.next()):Promise.resolve(!s&&t.next()).then(e)},function(){return!!(d=!1)},function(){var e=r.value;if(e.type===U.EventTypes.FINAL_PEER&&e.peer.multiaddrs.length>0){var t=e.peer.multiaddrs[0].toString(),n=o(t);return s=1,n}})},function(e){m=!0,f=e})},function(e,r){function n(t){if(s)return t;if(e)throw r;return r}var o=oa(function(){var e=function(){if(d&&null!=t.return)return Promise.resolve(t.return()).then(function(){})}();if(e&&e.then)return e.then(function(){})},function(e,t){if(m)throw f;if(e)throw t;return t});return o&&o.then?o.then(n):n(o)});return g&&g.then?g.then(a):a(g)})}catch(e){return Promise.reject(e)}},t.getDiscoveredNodes=function(){return Array.from(this.discoveredNodes.entries()).map(function(e){return{peerId:e[0],multiaddrs:e[1]}})},t.bufToHex=function(e){var t;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){return e}return"Buffer"===(null==(t=e)?void 0:t.type)&&Array.isArray(e.data)?Buffer.from(e.data).toString():e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString():e},t.getOrCreateLibp2pNode=function(){try{var e,t=this;if(t.libp2pNode)return Promise.resolve(t.libp2pNode);var r=(null!=(e=t.p2pConfig.bootstrapPeers)?e:aa).map(R.multiaddr);return Promise.resolve(O.createLibp2p(ye({addresses:{listen:[]},transports:[j.webSockets()].concat(t.p2pConfig.enableTcp?[I.tcp()]:[]),connectionEncrypters:[F.noise()],streamMuxers:[D.yamux()],peerDiscovery:[].concat(r.length>0?[N.bootstrap({list:r.map(String),timeout:1e4})]:[]),services:{identify:L.identify(),ping:Ks(),dht:U.kadDHT({protocol:"/ocean/nodes/1.0.0/kad/1.0.0",clientMode:!0})},connectionManager:{maxConnections:100},connectionMonitor:{abortConnectionOnPingFailure:!1}},t.p2pConfig.libp2p))).then(function(e){return Promise.resolve(e.start()).then(function(){return e.addEventListener("peer:discovery",function(r){var n,o=r.detail;if(null!=o&&o.id){var i=o.id.toString();t.discoveredNodes.set(i,(null!=(n=o.multiaddrs)?n:[]).map(function(e){return e.toString()})),e.getConnections().length<100&&0===e.getConnections(o.id).length&&e.dial(o.id,{signal:AbortSignal.timeout(1e4)}).catch(function(e){Te.debug("Failed to dial discovered peer "+i+": "+e.message)})}}),t.libp2pNode=e,e})})}catch(e){return Promise.reject(e)}},t.toUint8Array=function(e){return e instanceof Uint8Array?e:e.subarray()},t.getConnection=function(e,t){try{var r,n=function(n){if(r)return n;var i=Ls(e);return Promise.resolve(o.getOrCreateLibp2pNode()).then(function(e){var r,n=e.getConnections(i);if(n.length>0)return n[0];var s=AbortSignal.timeout(null!=(r=o.p2pConfig.dhtLookupTimeout)?r:6e4);return Promise.resolve(e.peerRouting.findPeer(i,{signal:s}).catch(function(){})).then(function(){return e.dial(i,{signal:t})})})},o=this,i=function(){if(e.startsWith("/")){var n=R.multiaddr(e);return Promise.resolve(o.getOrCreateLibp2pNode()).then(function(e){var o=e.dial(n,{signal:t});return r=1,o})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},t.getConsumerAddress=function(e){return la(e)},t.getSignature=function(e,t,r){return ca(e,t,r)},t.getNodePublicKey=function(e){try{return Promise.resolve(this.getEndpoints(e)).then(function(e){return null==e?void 0:e.nodePublicKey})}catch(e){return Promise.reject(e)}},t.getAuthorization=function(e){return fa(e)},t.dialAndStream=function(e,t,r){try{var n,o=this,i=null!=r?r:AbortSignal.timeout(null!=(n=o.p2pConfig.dialTimeout)?n:sa);return Promise.resolve(o.getConnection(e,i)).then(function(e){return Promise.resolve(e.newStream(ia,{signal:i})).then(function(r){var n=function(e,t={}){const r=function(e,t){const r=t?.maxBufferSize??4194304,n=new gr;let o,i=!1;if(s=e,null==s?.addEventListener||null==s?.removeEventListener||null==s?.send||null==s?.push||null==s?.log)throw new yt("Argument should be a Stream or a Multiaddr");var s;const a=e=>{if(n.append(e.data),n.byteLength>r){const e=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${e} > ${r}`))}o?.resolve()};e.addEventListener("message",a);const u=e=>{null!=e.error?o?.reject(e.error):o?.resolve()};e.addEventListener("close",u);const c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);const l={readBuffer:n,async read(t){if(!0===i)throw new Js("Stream was unwrapped");if(Xs(e)){if(0===n.byteLength&&null==t?.bytes)return null;if(null!=t?.bytes&&n.byteLength<t.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,t.bytes),new Zs(`Unexpected EOF - stream closed after reading ${n.byteLength}/${t.bytes} bytes`)}const r=t?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=r){o.resolve();break}if(await zs(o.promise,t?.signal),Xs(e)){if(0===n.byteLength&&null==t?.bytes)return null;break}o=Promise.withResolvers()}const s=t?.bytes??n.byteLength;if(n.byteLength<s){if(Xs(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,s),new Zs(`Unexpected EOF - stream closed while reading ${n.byteLength}/${s} bytes`);return l.read(t)}const a=n.sublist(0,s);return n.consume(s),a},async write(t,r){if(!0===i)throw new Js("Stream was unwrapped");e.send(t)||await qs(e,"drain",{signal:r?.signal,rejectionEvents:["close"]})},unwrap:()=>(i||(i=!0,e.removeEventListener("message",a),e.removeEventListener("close",u),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e)};return l}(e,t);null!=t.maxDataLength&&null==t.maxLengthLength&&(t.maxLengthLength=di(t.maxDataLength));const n=t?.lengthDecoder??pi,o=t?.lengthEncoder??vi;return{async read(o){let i=-1;const s=new gr;for(;;){const e=await r.read({...o,bytes:1});if(null==e)break;s.append(e);try{i=n(s)}catch(e){if(e instanceof RangeError)continue;throw e}if(i<0)throw new $s("Invalid message length");if(null!=t?.maxLengthLength&&s.byteLength>t.maxLengthLength)throw new Ys(`Message length length too long - ${s.byteLength} > ${t.maxLengthLength}`);if(i>-1)break}if(null!=t?.maxDataLength&&i>t.maxDataLength)throw new Ws(`Message length too long - ${i} > ${t.maxDataLength}`);const a=await r.read({...o,bytes:i});if(null==a)throw e.log.error("tried to read %d bytes but the stream closed",i),new Zs(`Unexpected EOF - tried to read ${i} bytes but the stream closed`);if(a.byteLength!==i)throw e.log.error("read %d/%d bytes before the stream closed",a.byteLength,i),new Zs(`Unexpected EOF - read ${a.byteLength}/${i} bytes before the stream closed`);return a},async write(e,t){await r.write(new gr(o(e.byteLength),e),t)},async writeV(e,t){const n=new gr(...e.flatMap(e=>[o(e.byteLength),e]));await r.write(n,t)},unwrap:()=>r.unwrap()}}(r);return Promise.resolve(n.write(T.fromString(JSON.stringify(t)),{signal:i})).then(function(){return Promise.resolve(r.close()).then(function(){return Promise.resolve(n.read({signal:i})).then(function(t){var r=o.toUint8Array(t);return{lp:n,firstBytes:r,connection:e}})})})})})}catch(e){return Promise.reject(e)}},t.sendP2pCommand=function(e,t,r,n,o,i){void 0===i&&(i=0);try{var s,a=this;return Promise.resolve(na(function(){var u=ye({command:t,authorization:n?a.getAuthorization(n):void 0},r);return Promise.resolve(a.dialAndStream(e,u,o)).then(function(u){var c=u.lp,l=u.firstBytes;function f(s){for(var u,c,l,f=0;f<g.length;f++){var h=x.toString(g[f]);try{l=JSON.parse(h)}catch(e){l=g[f]}}var d=l;if("number"==typeof(null==d?void 0:d.httpStatus)&&d.httpStatus>=400)throw new Error("string"==typeof d.error?d.error:JSON.stringify(d.error));var m=null!=(u="string"==typeof l?l:null==d?void 0:d.error)?u:"",v=function(s){if(m.includes("Cannot connect to peer")&&i<(null!=(s=a.p2pConfig.maxRetries)?s:5))return Promise.resolve(new Promise(function(e){var t;return setTimeout(e,null!=(t=a.p2pConfig.retryDelay)?t:1e3)})).then(function(){var s=a.sendP2pCommand(e,t,r,n,o,i+1);return c=1,s})}();return v&&v.then?v.then(function(e){return c?e:l}):c?v:l}if(s=u.connection,!l.length)throw new Error("Gateway node error: no response from peer");var h=x.toString(l);try{var d,m=JSON.parse(h);if("number"==typeof(null==m?void 0:m.httpStatus)&&m.httpStatus>=400)throw new Error(null!=(d=m.error)?d:"Gateway node error: "+m.httpStatus)}catch(e){}if(t===he.COMPUTE_GET_STREAMABLE_LOGS||t===he.COMPUTE_GET_RESULT)return Ee(/*#__PURE__*/Pe().mark(function e(){var t;return Pe().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0;case 1:return e.next=4,ve(c.read({signal:AbortSignal.timeout(sa)}));case 4:return t=e.sent,e.next=7,t instanceof Uint8Array?t:t.subarray();case 7:e.next=1;break;case 9:e.next=15;break;case 11:if(e.prev=11,e.t0=e.catch(0),e.t0 instanceof Zs){e.next=15;break}throw e.t0;case 15:case"end":return e.stop()}},e,null,[[0,11]])}))();var g=[l],v=na(function(){var e=ra(function(){return!0},void 0,function(){var e;return Promise.resolve(c.read({signal:AbortSignal.timeout(null!=(e=a.p2pConfig.dialTimeout)?e:sa)})).then(function(e){g.push(a.toUint8Array(e))})});if(e&&e.then)return e.then(function(){})},function(e){if(!(e instanceof Zs))throw e});return v&&v.then?v.then(f):f()})},function(u){var c,l;function f(e){if(l)return e;throw new Error("P2P command error: "+h)}var h=null!=(c=null==u?void 0:u.message)?c:"",d=function(u){if((h.includes("closed")||h.includes("reset"))&&i<(null!=(u=a.p2pConfig.maxRetries)?u:5)){var c=function(){var s=a.sendP2pCommand(e,t,r,n,o,i+1);return l=1,s},f=na(function(){var e;return Promise.resolve(null==(e=s)?void 0:e.close()).then(function(){})},function(){});return f&&f.then?f.then(c):c()}}();return d&&d.then?d.then(f):f(d)}))}catch(e){return Promise.reject(e)}},t.getEndpoints=function(e){try{var t=this;return Promise.resolve(na(function(){return Promise.resolve(t.sendP2pCommand(e,he.STATUS,{}))},function(e){throw Te.error("P2P getEndpoints (STATUS) failed:",e),e}))}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r){try{var n=this;return Promise.resolve(na(function(){return Promise.resolve(n.sendP2pCommand(e,he.NONCE,{address:t},null,r)).then(function(e){var t,r,n="number"==typeof e?e:null!=(t=null!=(r=null==e?void 0:e.nonce)?r:e)?t:0;return n&&null!==n?Number(n):0})},function(e){throw Te.error("P2P getNonce failed:",e),e}))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getConsumerAddress(n)).then(function(o){return Promise.resolve(s.getNonce(r,o,i)).then(function(a){var u=(a+1).toString();return Promise.resolve(s.getSignature(n,u,he.ENCRYPT)).then(function(a){return Promise.resolve(s.sendP2pCommand(r,he.ENCRYPT,{chainId:t,nonce:u,consumerAddress:o,signature:a,blob:"string"==typeof e?e:JSON.stringify(e)},n,i)).then(function(e){return s.bufToHex(e)})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{return Promise.resolve(this.sendP2pCommand(r,he.FILE_INFO,{did:e,serviceId:t,checksum:n},null,o)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{return Promise.resolve(this.sendP2pCommand(t,he.FILE_INFO,{file:e,type:e.type,checksum:r},null,n)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,he.COMPUTE_GET_ENVIRONMENTS,{},null,t)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c={ddoId:e,serviceId:t,consumerAddress:n};return s&&(c.userdata=s),a&&(c.environment=a),u&&(c.validUntil=u),Promise.resolve(this.sendP2pCommand(o,he.GET_FEES,c,null,i))}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getConsumerAddress(s)).then(function(m){return Promise.resolve(d.getNonce(i,m,l)).then(function(g){function v(){function g(){function e(){return d.sendP2pCommand(i,he.COMPUTE_INITIALIZE,v,s,l)}c&&(v.policyServer=c);var t=function(){if(f)return Promise.resolve(d.getNodePublicKey(i)).then(function(e){e&&(v.output=Rs(e,JSON.stringify(f)))})}();return t&&t.then?t.then(e):e()}var v={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:m,nonce:y,signature:p},b=function(){if(h)return Promise.resolve(d.getNodePublicKey(i)).then(function(e){e&&(v.dockerRegistryAuth=Rs(e,JSON.stringify(h)))})}();return b&&b.then?b.then(g):g()}var p,y=(g+1).toString(),b="string"==typeof s,P=function(){if(!b){var t,r=m;return r+=null==(t=e[0])?void 0:t.documentId,r+=y,Promise.resolve(pt(s,r)).then(function(e){p=e})}}();return P&&P.then?P.then(v):v()})})}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getConsumerAddress(i)).then(function(c){return Promise.resolve(u.getNonce(o,c)).then(function(l){var f=(l+1).toString();return Promise.resolve(u.getSignature(i,f,he.DOWNLOAD)).then(function(l){var h={command:he.DOWNLOAD,authorization:u.getAuthorization(i),fileIndex:r,documentId:e,transferTxId:n,serviceId:t,consumerAddress:c,nonce:f,signature:l};return s&&(h.policyServer=s),a&&(h.userData=a),Promise.resolve(u.dialAndStream(o,h)).then(function(e){var t=e.lp,n=e.firstBytes;function o(e){var t=Buffer.concat(c);return{data:t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),filename:"file"+r}}var i,s=x.toString(n),a=null;try{a=JSON.parse(s)}catch(e){}if(a&&"number"==typeof a.httpStatus&&a.httpStatus>=400)throw new Error(null!=(i=a.error)?i:"P2P download error: "+a.httpStatus);var c=null===a?[Buffer.from(n)]:[],l=na(function(){var e=ra(function(){return!0},void 0,function(){var e;return Promise.resolve(t.read({signal:AbortSignal.timeout(null!=(e=u.p2pConfig.dialTimeout)?e:sa)})).then(function(e){c.push(Buffer.from(u.toUint8Array(e)))})});if(e&&e.then)return e.then(function(){})},function(e){if(!(e instanceof Zs))throw e});return l&&l.then?l.then(o):o()})})})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{var v=this;return Promise.resolve(v.getConsumerAddress(t)).then(function(p){return Promise.resolve(v.getNonce(e,p,d)).then(function(y){var b=(y+1).toString();return Promise.resolve(v.getSignature(t,b,he.COMPUTE_START)).then(function(y){function P(){function r(){return Promise.resolve(v.sendP2pCommand(e,he.COMPUTE_START,w,t,d)).then(function(e){return Array.isArray(e),e})}var n=function(){if(f)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(w.output=Rs(e,JSON.stringify(f)))})}();return n&&n.then?n.then(r):r()}var w={environment:r,dataset:n[0],datasets:n,algorithm:o,maxJobDuration:i,feeToken:s,resources:a,chainId:u,payment:{chainId:u,token:s,maxJobDuration:i,resources:a},consumerAddress:p,nonce:b,signature:y};c&&(w.metadata=c),l&&(w.additionalViewers=l),h&&(w.policyServer=h),m&&(w.queueMaxWaitTime=m);var E=function(){if(g)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(w.dockerRegistryAuth=Rs(e,JSON.stringify(g)))})}();return E&&E.then?E.then(P):P()})})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getConsumerAddress(t)).then(function(m){return Promise.resolve(d.getNonce(e,m,l)).then(function(g){var v=(g+1).toString();return Promise.resolve(d.getSignature(t,v,he.FREE_COMPUTE_START)).then(function(g){function p(){function r(){return Promise.resolve(d.sendP2pCommand(e,he.FREE_COMPUTE_START,y,t,l)).then(function(e){return Array.isArray(e),e})}var n=function(){if(u)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(y.output=Rs(e,JSON.stringify(u)))})}();return n&&n.then?n.then(r):r()}var y={environment:r,dataset:n[0],datasets:n,algorithm:o,resources:i,consumerAddress:m,nonce:v,signature:g};s&&(y.metadata=s),a&&(y.additionalViewers=a),c&&(y.policyServer=c),f&&(y.queueMaxWaitTime=f);var b=function(){if(h)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(y.dockerRegistryAuth=Rs(e,JSON.stringify(h)))})}();return b&&b.then?b.then(p):p()})})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this;return"string"==typeof t?Promise.resolve(o.sendP2pCommand(e,he.COMPUTE_GET_STREAMABLE_LOGS,{jobId:r},t,n)):Promise.resolve(o.getConsumerAddress(t)).then(function(i){return Promise.resolve(o.getNonce(e,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(o.getSignature(t,a,he.COMPUTE_GET_STREAMABLE_LOGS)).then(function(s){return o.sendP2pCommand(e,he.COMPUTE_GET_STREAMABLE_LOGS,{jobId:r,consumerAddress:i,nonce:a,signature:s},t,n)})})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getConsumerAddress(r)).then(function(s){return Promise.resolve(i.getNonce(t,s,o)).then(function(a){var u=(a+1).toString();return Promise.resolve(i.getSignature(r,u,he.COMPUTE_STOP)).then(function(a){var c={jobId:e,consumerAddress:s,nonce:u,signature:a};return n&&(c.agreementId=n),i.sendP2pCommand(t,he.COMPUTE_STOP,c,r,o)})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getConsumerAddress(t)).then(function(s){var a={consumerAddress:s};return r&&(a.jobId=r),n&&(a.agreementId=n),i.sendP2pCommand(e,he.COMPUTE_GET_STATUS,a,t,o)})}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{var i=this;return Promise.resolve(i.getConsumerAddress(t)).then(function(s){function a(){return Promise.resolve(i.dialAndStream(e,u)).then(function(e){var t,r,n=e.lp,o=JSON.parse(x.toString(e.firstBytes));if("number"==typeof(null==o?void 0:o.httpStatus)&&o.httpStatus>=400)throw new Error(null!=(r=o.error)?r:"P2P compute result error: "+o.httpStatus);var s=null!=(t=i.p2pConfig.dialTimeout)?t:sa;return Ee(/*#__PURE__*/Pe().mark(function e(){var t;return Pe().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0;case 1:return e.next=4,ve(n.read({signal:AbortSignal.timeout(s)}));case 4:return t=e.sent,e.next=7,t instanceof Uint8Array?t:t.subarray();case 7:e.next=1;break;case 9:e.next=15;break;case 11:if(e.prev=11,e.t0=e.catch(0),e.t0 instanceof Zs){e.next=15;break}throw e.t0;case 15:case"end":return e.stop()}},e,null,[[0,11]])}))()})}var u={command:he.COMPUTE_GET_RESULT,jobId:r,index:n,offset:o,consumerAddress:s},c=function(){if("string"!=typeof t)return Promise.resolve(i.getNonce(e,s)).then(function(e){var r=(e+1).toString();return u.nonce=r,Promise.resolve(i.getSignature(t,r,he.COMPUTE_GET_RESULT)).then(function(e){u.signature=e})});u.authorization=t}();return c&&c.then?c.then(a):a()})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getConsumerAddress(t)).then(function(i){return Promise.resolve(o.sendP2pCommand(e,he.COMPUTE_GET_RESULT,{jobId:r,index:n,consumerAddress:i},t))})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getNonce(t,o,r)).then(function(i){var s=(i+1).toString();return Promise.resolve(n.getSignature(e,s,he.CREATE_AUTH_TOKEN)).then(function(e){return Promise.resolve(n.sendP2pCommand(t,he.CREATE_AUTH_TOKEN,{address:o,signature:e,nonce:s},null,r)).then(function(e){var t;return null!=(t=null==e?void 0:e.token)?t:e})})})})}catch(e){return Promise.reject(e)}},t.resolveDdo=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,he.GET_DDO,{id:t},null,r))}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{var o=this;return Promise.resolve(r.getAddress()).then(function(i){return Promise.resolve(o.getNonce(e,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(pt(r,i+a+he.VALIDATE_DDO)).then(function(r){return Promise.resolve(o.sendP2pCommand(e,he.VALIDATE_DDO,{ddo:t,publisherAddress:i,nonce:a,signature:r},null,n)).then(function(e){var t,r,n,i;return!e||e.error?null:{valid:!0,hash:o.bufToHex(e.hash),proof:{validatorAddress:o.bufToHex(e.publicKey),r:o.bufToHex(null!=(t=null==(r=e.r)?void 0:r[0])?t:e.r),s:o.bufToHex(null!=(n=null==(i=e.s)?void 0:i[0])?n:e.s),v:e.v}}})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getNonce(r,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(pt(e,i+a)).then(function(e){return o.sendP2pCommand(r,he.INVALIDATE_AUTH_TOKEN,{address:i,signature:e,token:t,nonce:a},null,n)})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){var r=this;return Promise.resolve(na(function(){return Promise.resolve(r.sendP2pCommand(e,he.STATUS,{},null,t)).then(function(e){return!(!e||!(e.address||e.providerAddress||e.providerAddresses))})},function(){return!1}))},t.PolicyServerPassthrough=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,he.POLICY_SERVER_PASSTHROUGH,ye({},t),null,r))}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,he.POLICY_SERVER_PASSTHROUGH,ye({},t),null,r))}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(t.getAddress()).then(function(l){return Promise.resolve(c.getNonce(e,l,u)).then(function(f){var h=(f+1).toString();return Promise.resolve(c.getSignature(t,h,he.GET_LOGS)).then(function(f){var d={startTime:r,endTime:n,signature:f,nonce:h,address:l};return o&&(d.maxLogs=o),i&&(d.moduleName=i),s&&(d.level=s),a&&(d.page=a),c.sendP2pCommand(e,he.GET_LOGS,d,t,u)})})})}catch(e){return Promise.reject(e)}},t.fetchConfig=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,he.FETCH_CONFIG,t))}catch(e){return Promise.reject(e)}},t.pushConfig=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,he.PUSH_CONFIG,t))}catch(e){return Promise.reject(e)}},e}(),ca=function(e,t,r){try{if("string"==typeof e)return Promise.resolve(null);var n=String,o=String;return Promise.resolve(e.getAddress()).then(function(i){var s=n(o(i)+String(t)+String(r));return pt(e,s)})}catch(e){return Promise.reject(e)}},la=function(e){try{return Promise.resolve("string"==typeof e?function(e){try{return ce.default.decode(e,{json:!0})}catch(e){throw new Error("Error decoding JWT")}}(e).address:e.getAddress())}catch(e){return Promise.reject(e)}};function fa(e){return"string"==typeof e?e:void 0}var ha=["/ip4/","/ip6/","/dns4/","/dns6/","/dns/","/dnsaddr/"];function da(e){if(!e)return!1;if(ha.some(function(t){return e.startsWith(t)}))return!0;try{return Ls(e),!0}catch(e){return!1}}var ma=/*#__PURE__*/function(){function e(){this.httpProvider=new Bs,this.p2pProvider=new ua}var t=e.prototype;return t.getImpl=function(e){return da(e)?this.p2pProvider:this.httpProvider},t.getNonce=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(e).getNonce(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{return Promise.resolve(this.getImpl(r).encrypt(e,t,r,n,o,i))}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{return Promise.resolve(this.getImpl(r).checkDidFiles(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{return Promise.resolve(this.getImpl(t).getFileInfo(e,t,r,n))}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{return Promise.resolve(this.getImpl(e).getComputeEnvironments(e,t))}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{return Promise.resolve(this.getImpl(o).initialize(e,t,r,n,o,i,s,a,u))}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{return Promise.resolve(this.getImpl(i).initializeCompute(e,t,r,n,o,i,s,a,u,c,l,f,h))}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{return Promise.resolve(this.getImpl(o).getDownloadUrl(e,t,r,n,o,i,s,a))}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{return Promise.resolve(this.getImpl(e).computeStart(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g))}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{return Promise.resolve(this.getImpl(e).freeComputeStart(e,t,r,n,o,i,s,a,u,c,l,f,h))}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).computeStreamableLogs(e,t,r,n))}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(t).computeStop(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(e).computeStatus(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).getComputeResultUrl(e,t,r,n))}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{return Promise.resolve(this.getImpl(e).getComputeResult(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{return Promise.resolve(this.getImpl(t).generateAuthToken(e,t,r))}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{return Promise.resolve(this.getImpl(r).invalidateAuthToken(e,t,r,n))}catch(e){return Promise.reject(e)}},t.resolveDdo=function(e,t,r){try{return Promise.resolve(this.getImpl(e).resolveDdo(e,t,r))}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).validateDdo(e,t,r,n))}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(this.getImpl(e).isValidProvider(e,t))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{return Promise.resolve(this.getImpl(e).PolicyServerPassthrough(e,t,r))}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{return Promise.resolve(this.getImpl(e).initializePSVerification(e,t,r))}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{return Promise.resolve(this.getImpl(e).downloadNodeLogs(e,t,r,n,o,i,s,a,u))}catch(e){return Promise.reject(e)}},t.setupP2P=function(e){try{return Promise.resolve(this.p2pProvider.setupP2P(e))}catch(e){return Promise.reject(e)}},t.getDiscoveredNodes=function(){return this.p2pProvider.getDiscoveredNodes()},t.getMultiaddrFromPeerId=function(e){try{return Promise.resolve(this.p2pProvider.getMultiaddrFromPeerId(e))}catch(e){return Promise.reject(e)}},t.fetchConfig=function(e,t){try{return Promise.resolve(this.p2pProvider.fetchConfig(e,t))}catch(e){return Promise.reject(e)}},t.pushConfig=function(e,t){try{return Promise.resolve(this.p2pProvider.pushConfig(e,t))}catch(e){return Promise.reject(e)}},e}(),ga=new ma;function va(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function pa(e,t,r){if(!e.s){if(r instanceof ya){if(!r.s)return void(r.o=pa.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(pa.bind(null,e,t),pa.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ya=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{pa(n,1,i(this.v))}catch(e){pa(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?pa(n,1,t?t(o):o):r?pa(n,1,r(o)):pa(n,2,o)}catch(e){pa(n,2,e)}},n},e}();function ba(e){return e instanceof ya&&1&e.s}var Pa=/*#__PURE__*/function(){function e(e){this.aquariusURL=void 0,this.aquariusURL=e}var t=e.prototype;return t.resolve=function(e,t,r){try{var n,o=function(o){if(n)return o;var s=i.aquariusURL+"/api/aquarius/assets/ddo/"+e;return va(function(){return Promise.resolve(ue.default(s,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return Promise.resolve(e.json());throw new Error("HTTP request failed with status "+e.status)})},function(e){throw Te.error(e),new Error("HTTP request failed")})},i=this,s=function(){if(da(i.aquariusURL))return Promise.resolve(ga.resolveDdo(i.aquariusURL,e,t)).then(function(e){if(e)return n=1,e;throw new Error("P2P request failed")})}();return Promise.resolve(s&&s.then?s.then(o):o(s))}catch(e){return Promise.reject(e)}},t.waitForIndexer=function(e,t,r,n,o,i){void 0===n&&(n=3e4),void 0===o&&(o=100);try{var s,a=this,u=0;o>500&&(Te.warn("Max Limit exceeded, defaulting to 500 retries."),o=500);var c=da(a.aquariusURL),l=function(e,t){var r;do{var n=e();if(n&&n.then){if(!ba(n)){r=!0;break}n=n.v}var o=t();if(ba(o)&&(o=o.v),!o)return n}while(!o.then);var i=new ya,s=pa.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;ba(o=t())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=e())&&n.then){if(!ba(n))return void n.then(a).then(void 0,s);n=n.v}}pa(i,1,n)}function u(r){if(r){do{if((n=e())&&n.then){if(!ba(n))return void n.then(a).then(void 0,s);n=n.v}if(ba(r=t())&&(r=r.v),!r)return void pa(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else pa(i,1,n)}}(function(){function o(e){return s?e:Promise.resolve(vt(n)).then(function(){u++})}var l=va(function(){function n(){if(o){var e=w.DDOManager.getDDOClass(o).getAssetFields().indexedMetadata;if(!t)return s=1,o;if(e.event&&e.event.txid===t)return s=1,o}}var o,u=c?Promise.resolve(ga.resolveDdo(a.aquariusURL,e,r)).then(function(e){o=e}):Promise.resolve(ue.default(a.aquariusURL+"/api/aquarius/assets/ddo/"+e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:r})).then(function(e){var t=function(){if(e.ok)return Promise.resolve(e.json()).then(function(e){o=e})}();if(t&&t.then)return t.then(function(){})});return u&&u.then?u.then(n):n()},function(){});return l&&l.then?l.then(o):o(l)},function(){return!s&&u<o});return Promise.resolve(l&&l.then?l.then(function(e){return s?e:null}):s?l:null)}catch(e){return Promise.reject(e)}},t.validate=function(e,t,r,n,o){try{if(da(r))return Promise.resolve(ga.validateDdo(r,e,t,n));var i=r+"/api/aquarius/assets/ddo/validate",s=r+"/api/services/nonce";return Promise.resolve(va(function(){return Promise.resolve(t.getAddress()).then(function(r){return Promise.resolve(ue.default(s+"?userAddress="+r,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o},signal:n})).then(function(o){return Promise.resolve(o.json()).then(function(o){var s=o.nonce;s&&null!==s||(s="0");var a=(Number(s)+1).toString(),u=String,c=String;return Promise.resolve(t.getAddress()).then(function(o){var s=u(c(o)+String(a)+String(he.VALIDATE_DDO));return Promise.resolve(pt(t,s)).then(function(o){return Promise.resolve(ue.default(i,{method:"POST",body:JSON.stringify({ddo:e,publisherAddress:r,nonce:a,signature:o}),headers:{"Content-Type":"application/json",Authorization:fa(t)},signal:n})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error("Metadata validation failed");return{valid:!0,hash:t.hash,proof:{validatorAddress:t.publicKey,r:t.r[0],s:t.s[0],v:t.v}}})})})})})})})},function(e){Te.error("Metadata validation failed",e.message)}))}catch(e){return Promise.reject(e)}},t.getAssetMetadata=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/metadata/"+e;return Promise.resolve(va(function(){return Promise.resolve(ue.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("getAssetMetadata failed: "+e.status+e.statusText)})},function(e){throw Te.error("Error getting metadata: ",e),new Error("Error getting metadata: "+e)}))}catch(e){return Promise.reject(e)}},t.querySearch=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/query";return Promise.resolve(va(function(){return Promise.resolve(ue.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("querySearch failed: "+e.status+e.statusText)})},function(e){throw Te.error("Error querying metadata: ",e),new Error("Error querying metadata: "+e)}))}catch(e){return Promise.reject(e)}},e}(),wa=function(e,t,r,o){try{var i=new n.ethers.Contract(t,De,e);return Promise.resolve(i.allowance(r,o))}catch(e){return Promise.reject(e)}},Ea=function(e,t,r,o,i){try{var s=new n.ethers.Contract(t,De,e);return Promise.resolve(s.allowance(r,o)).then(function(r){return Promise.resolve(Ne(e,t,r,i))})}catch(e){return Promise.reject(e)}},Sa=function(e,t,r,o,i,s,a,u){void 0===a&&(a=!1);try{var c,l=function(r){if(c)return r;var n=null;return Promise.resolve(f.approve.estimateGas(i,s)).then(function(r){if(u)return r;var o=function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){return Promise.resolve(je(r,e,null==t?void 0:t.gasFeeMultiplier,f.approve,i,s)).then(function(e){n=e})},function(e){Te.error("ERROR: Failed to approve spender to spend tokens : "+e.message)});return o&&o.then?o.then(function(){return n}):n})},f=new n.ethers.Contract(o,De,e),h=function(){if(!a)return Promise.resolve(wa(e,o,r,i)).then(function(e){if(new Z.default(e).isGreaterThan(new Z.default(s))){var t=BigInt(e);return c=1,t}})}();return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}},Aa=function(e,t,r,o,i,s,a,u,c){void 0===a&&(a=!1);try{var l,f=function(r){return l?r:Promise.resolve(Ie(e,o,s,u)).then(function(r){return Promise.resolve(h.approve.estimateGas(i,r)).then(function(n){return c?new J.default(n.toString()):Promise.resolve(je(n,e,null==t?void 0:t.gasFeeMultiplier,h.approve,i,r))})})},h=new n.ethers.Contract(o,De,e),d=function(){if(!a)return Promise.resolve(Ea(e,o,r,i)).then(function(e){if(new J.default(e).greaterThanOrEqualTo(new J.default(s))){var t=new J.default(e).toNumber();return l=1,t}})}();return Promise.resolve(d&&d.then?d.then(f):f(d))}catch(e){return Promise.reject(e)}},Ta={datasets:{invalid:"Datasets is not a list, as expected"},algorithm:{serviceId:{missing:"The serviceId key is missing from the algorithm s DDO.",not_found:"The provided serviceId does not exist.",service_not_access_compute:"Service type is neither access, nor compute.",main_service_compute:"If the main service is not compute for this asset when calling initialize endpoint.",compute_services_not_in_same_provider:"Files attached to the compute service are not decrypted by the correct provider. This occurs when both asset and algorithm are requested by their compute service which cannot be decrypted by a single provider as how it is supposed to be."},container:{checksum_prefix:"Container checksum does not start with the prefix sha256:.",mising_entrypoint_image_checksum:"Either entrypoint, either image, or either checksum are missing from the container dictionary from the algorithm s DDO."},documentId:{did_not_found:"The algorithm s DID could not be retrieved from the metadata store, because the algorithm asset does not exist.",missing:"The documentId key is missing from the algorithm s DDO."},transferTxId:{missing:"The transferTxId key is missing from the algorithm s DDO."},missing_meta_documentId:"Either algorithm metadata, or algorithm DID are missing.",did_not_found:"Either algorithm metadata, or algorithm DID are missing.",not_algo:"Either algorithm metadata, or algorithm DID are missing.",in_use_or_not_on_chain:"Either algorithm metadata, or algorithm DID are missing.",meta_oneof_url_rawcode_remote:"Either algorithm metadata, or algorithm DID are missing.",file_unavailable:"One possibility is that the asset could not be retrieved from Aquariuss database. Otherwise, there are issues related to services"},error:{not_trusted_algo_publisher:"The owner of the algorithm's DDO is not a trusted algorithms publishers list.",not_trusted_algo:"The algorithm's DID is not in the asset's trusted algorithms dictionary. ",no_publisherTrustedAlgorithms:"The algorithm's key publisherTrustedAlgorithms does not exist in the algorithm's DDO.",algorithm_file_checksum_mismatch:"filesChecksum from the algorithm's DDO is invalid.",algorithm_container_checksum_mismatch:"The containerChecksum from the algorithm's DDO is invalid.",no_raw_algo_allowed:"The asset does not allow raw algorithms to be run on it.","Asset malformed":"The asset published on chain is malformed, missing some required keys or not compliant with our schemas.","Asset is not consumable.":"Assets metadata status is not in the range of valid status codes for assets. The recognized states for the metadata are defined on our docs.","DID is not a valid algorithm.":"Either the algorithm assets DID is incorrectly typed, either the algorithm timeout expired.","Compute environment does not exist.":"The compute environment provided by the user does not exist, it is not served by our compute-to-data feature. The user can use get_c2d_environments to check the list of available compute environments.","The validUntil value is not correct.":"validUntil value is most probably expired.","Cannot resolve DID":"The dataset DID does not exist in the Metadata store.","Invalid serviceId":"The serviceId of that dataset is not correct.","Unable to get dataset files":"The files of that dataset could not be decrypted or retrieved","cannot decrypt files for this service.":"The files of that dataset could not be decrypted due to the fact that file object, which contains the structure and the type of specific file, is missing from the validation part.","Unsupported type ":"The file object type is not supported by Provider.","malformed file object":"The file object structure is invalid and does not contain the wanted information for the specific file."},order:{fees_not_paid:" Provider fees are not paid."},output:{invalid:"The algorithms validation after the build stage has not been decoded properly as a dictionary."}};function xa(e,t,r){if(!e.s){if(r instanceof ka){if(!r.s)return void(r.o=xa.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(xa.bind(null,e,t),xa.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ka=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{xa(n,1,i(this.v))}catch(e){xa(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?xa(n,1,t?t(o):o):r?xa(n,1,r(o)):xa(n,2,o)}catch(e){xa(n,2,e)}},n},e}();function Ca(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}e.AccessListContract=lt,e.AccesslistFactory=ft,e.Aquarius=Pa,e.Config=function(){this.nodeUri=void 0,this.providerAddress=void 0,this.oceanNodeUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.routerFactoryAddress=void 0,this.datatokensABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.EnterpriseFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.sdk=void 0,this.accessListFactory=void 0,this.escrow=void 0},e.ConfigHelper=Fe,e.DEVELOPMENT_CHAIN_ID=8996,e.Datatoken=ut,e.Datatoken4=ct,e.Dispenser=Ze,e.EnterpriseFeeCollectorContract=gt,e.EscrowContract=mt,e.FEE_HISTORY_NOT_SUPPORTED="Returned error: Method eth_feeHistory not supported.",e.FixedRateExchange=$e,e.GASLIMIT_DEFAULT=1e6,e.KNOWN_CONFIDENTIAL_EVMS=Ce,e.Logger=Ae,e.LoggerInstance=Te,e.MAX_UINT_256="115792089237316195423570985008687907853269984665640564039457584007913129639934",e.Nft=at,e.NftFactory=et,e.OCEAN_P2P_PROTOCOL=ia,e.PROTOCOL_COMMANDS=he,e.Provider=ma,e.ProviderInstance=ga,e.Router=We,e.SmartContract=He,e.SmartContractWithAddress=Ke,e.ZERO_ADDRESS=Je,e.allowance=Ea,e.allowanceWei=wa,e.amountToUnits=Ie,e.approve=Aa,e.approveWei=Sa,e.balance=function(e,t,r,o){try{var i=new n.ethers.Contract(t,De,e);return Promise.resolve(i.balanceOf(r)).then(function(r){return Promise.resolve(Ne(e,t,r,o))})}catch(e){return Promise.reject(e)}},e.calculateActiveTemplateIndex=ot,e.configHelperNetworks=ke,e.createAccessListFactory=function(e,t,r){try{var o=new n.ethers.Contract(e,ie.default.abi,t);return Promise.resolve(t.getAddress()).then(function(e){var t,n=Ca(function(){return Promise.resolve(o.deployAccessListContract("AllowList","ALLOW",!0,e,r||[e],["https://oceanprotocol.com/nft/"])).then(function(e){return function(){if(e&&e.wait)return Promise.resolve(e.wait()).then(function(e){var r=ze(e,"NewAccessList");return t=1,r.args[0]})}()})},function(e){console.log("ERROR createAccessListFactory(): ",e)});return n&&n.then?n.then(function(e){return t?e:null}):t?n:null})}catch(e){return Promise.reject(e)}},e.createAsset=function(e,t,r,o,i,s,a,u,c,l,f,h,d,m,g){void 0===a&&(a=!0);try{var v,p,y=this,b=w.DDOManager.getDDOClass(s),P=b.getAssetFields().indexedMetadata,E=(null==(v=b.getDDOData())||null==(v=v.stats)||null==(v=v.price)?void 0:v.value)||(null==P||null==(p=P.stats[0])||null==(p=p.prices[0])?void 0:p.price),S=b.getDDOFields(),A=S.chainId,T=S.nftAddress,x=b.getDDOFields().services;if("string"!=typeof i&&"number"!=typeof i)throw new Error('Invalid template! Must be a "number" or a "string"');return Promise.resolve(r.provider.getNetwork()).then(function(v){var p=v.chainId;if(A&&A!==Number(p))throw new Error("Chain ID from DDO is different than the configured network.");var P=(new Fe).getConfig(parseInt(String(p)));return Promise.resolve(ot(r,P.nftFactoryAddress,i,Number(p))).then(function(i){if(i<1){if(8996!==Number(p))throw new Error("Invalid template index: "+i);i=1}var v=new at(r,Number(p)),w=new et(P.nftFactoryAddress,r,Number(p));return Promise.resolve(r.getAddress()).then(function(S){var k;function C(e){return k?e:Promise.resolve(O.wait()).then(function(e){var t;function o(e){if(t)return e;function o(){function e(){var e=v.setMetadata,a=T;return Promise.resolve(r.getAddress()).then(function(r){return Promise.resolve(e.call(v,a,r,0,u,"",n.toBeHex(i),t,o)).then(function(){return s.id})})}x[0].datatokenAddress=h,x[0].serviceEndpoint=u;var t,o,i,c=b.makeDid(T=f,A.toString());s=b.updateFields({id:c,nftAddress:T});var d=function(){if(a)return Promise.resolve(ga.encrypt(s,Number(p),u,r,null)).then(function(e){return t=e,Promise.resolve(l.validate(s,r,u)).then(function(e){o=e.hash,i=2})});var e=JSON.stringify(s),c=Buffer.from(e);t=n.hexlify(c),o="0x"+B.createHash("sha256").update(t).digest("hex"),i=0}();return d&&d.then?d.then(e):e()}var i=function(){if("oasis"!==P.sdk)return Promise.resolve(ga.encrypt(j,Number(p),u,r,null)).then(function(e){x[0].files=e});x[0].files=""}();return i&&i.then?i.then(o):o()}var i=ze(e,"NFTCreated"),c=ze(e,"TokenCreated"),f=i.args.newTokenAddress,h=c.args.newTokenAddress;j.datatokenAddress=h,j.nftAddress=f;var d=function(){if("oasis"===P.sdk){var e=new n.ethers.Contract(h,ne.default.abi,r);return Ca(function(){return Promise.resolve(e.setFilesObject(n.toUtf8Bytes(JSON.stringify(j)))).then(function(e){var t=function(){if(e.wait)return Promise.resolve(e.wait()).then(function(){})}();if(t&&t.then)return t.then(function(){})})},function(e){return console.log("Error updating files object with data token and nft addresses: ",e),t=1,null})}}();return d&&d.then?d.then(o):o(d)})}var O,F={name:e,symbol:t,templateIndex:1,tokenURI:"aaa",transferable:!0,owner:S},D={templateIndex:i,cap:"100000",feeAmount:"0",paymentCollector:S,feeToken:c||P.oceanTokenAddress,minter:S,mpFeeAddress:Je},j={nftAddress:"0x0",datatokenAddress:"0x0",files:o};"oasis"===P.sdk&&(D.filesObject=j,D.accessListFactory=f||P.accessListFactory,D.allowAccessList=h,D.denyAccessList=d);var I=Ca(function(){var e=function(){if(!E)return Promise.resolve(w.createNftWithDatatoken(F,D)).then(function(e){O=e});var e=function(){if("0"===E.toString())return Promise.resolve(w.createNftWithDatatokenWithDispenser(F,D,{dispenserAddress:P.dispenserAddress,maxTokens:"1",maxBalance:"100000000",withMint:!0,allowedSwapper:Je})).then(function(e){O=e});var e=m||P.oceanTokenAddress;return Promise.resolve(Le(y.signer,e)).then(function(t){g||(g=t);var r={fixedRateAddress:P.fixedRateExchangeAddress,baseTokenAddress:e,owner:S,marketFeeCollector:S,baseTokenDecimals:g,datatokenDecimals:18,fixedRate:E.toString(),marketFee:"0",allowedConsumer:S,withMint:!0};return Promise.resolve(w.createNftWithDatatokenWithFixedRate(F,D,r)).then(function(e){O=e})})}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})},function(e){return console.log("ERROR creating NFT bundle",e),k=1,null});return I&&I.then?I.then(C):C(I)})})})}catch(e){return Promise.reject(e)}},e.decimals=function(e,t){try{var r=new n.ethers.Contract(t,De,e);return Promise.resolve(r.decimals()).then(Number)}catch(e){return Promise.reject(e)}},e.downloadFile=function(e,t){try{return"string"!=typeof e?Promise.resolve(e):Promise.resolve(fetch(e)).then(function(r){if(!r.ok)throw new Error("Response error.");var n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(r){try{n=e.split("/").pop()}catch(e){n="file"+t}}return Promise.resolve(r.arrayBuffer()).then(function(e){return{data:e,filename:n}})})}catch(e){return Promise.reject(e)}},e.downloadFileBrowser=function(e){var t=new XMLHttpRequest;t.responseType="blob",t.open("GET",e),t.onload=function(){var e=t.getResponseHeader("content-disposition"),r=null==e?void 0:e.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/),n=r&&r[1]?r[1]:"file",o=window.URL.createObjectURL(t.response),i=document.createElement("a");i.href=o,i.setAttribute("download",n),document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(o)},t.send()},e.generateDid=function(e,t){return e=n.getAddress(e),"did:op:"+le.default(e+t.toString(10)).toString()},e.generateDtName=Xe,e.getErrorMessage=function(e){try{var t=JSON.parse(e),r=Object.keys(t)[0];if("error"===r){var n,o=t[r];return(null==(n=Ta[r])?void 0:n[o])||"Provider request failed: "+o}var i=t[r];return t[Object.keys(t)[1]]+" : "+i}catch(t){return Te.error("[getErrorMessage] error: ",t),e}},e.getEventFromTx=ze,e.getFairGasPrice=Ue,e.getHash=function(e){return le.default(e).toString()},e.getNodeEndpointConfig=Oe,e.getOceanArtifactsAddresses=it,e.getOceanArtifactsAddressesByChainId=st,e.getTokenDecimals=Le,e.isDefined=function(e){return null!=e},e.isP2pUri=da,e.minAbi=De,e.orderAsset=function(e,t,r,n,o,i,s,a,u,c,l,f){void 0===u&&(u="0"),void 0===c&&(c=0),void 0===l&&(l=0),void 0===f&&(f=0);try{var h=w.DDOManager.getDDOClass(e),d=h.getAssetFields().datatokens,m=h.getDDOFields(),g=m.chainId,v=m.services;return s||(s={consumeMarketFeeAddress:"0x0000000000000000000000000000000000000000",consumeMarketFeeAmount:"0",consumeMarketFeeToken:"0x0000000000000000000000000000000000000000"}),Promise.resolve(t.provider.getNetwork()).then(function(h){if(g!==Number(h.chainId))throw new Error("Chain ID from DDO is different than the configured network.");if(!d[c].address)throw new Error("The datatoken with index: "+c+" does not exist for the asset with did: "+e.id);if(!v[l].id)throw new Error("There is no service with index: "+l+" defined for the asset with did: "+e.id);return Promise.resolve(n.getId(d[c].address)).then(function(h){return Promise.resolve(n.getFixedRates(d[c].address)).then(function(m){return Promise.resolve(n.getDispensers(d[c].address)).then(function(g){return Promise.resolve(n.getPublishingMarketFee(d[c].address)).then(function(p){function y(e){return a?e:Promise.resolve(w.call(ga,S,E,0,e,o||r.oceanNodeUri)).then(b)}function b(o){function g(o){function a(o){var i,a={consumer:o,serviceIndex:l,_providerFee:y,_consumeMarketFee:s};return function(e,t){var r,n=-1;e:{for(var o=0;o<t.length;o++){var i=t[o][0];if(i){var s=i();if(s&&s.then)break e;if(s===e){n=o;break}}else n=o}if(-1!==n){do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then){r=!0;break e}var c=t[n][2];n++}while(c&&!c());return u}}var l=new ka,f=xa.bind(null,l,2);return(r?u.then(h):s.then(function r(s){for(;;){if(s===e){n=o;break}if(++o===t.length){if(-1!==n)break;return void xa(l,1,u)}if(i=t[o][0]){if((s=i())&&s.then)return void s.then(r).then(void 0,f)}else n=o}do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then)return void u.then(h).then(void 0,f);var c=t[n][2];n++}while(c&&!c());xa(l,1,u)})).then(void 0,f),l;function h(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var o=t[n][1];!o;)n++,o=t[n][1];if((e=o())&&e.then)return void e.then(h).then(void 0,f)}xa(l,1,e)}}(P,[[function(){return"free"},function(){var e=function(e){var t;if(i)return e;function o(e){if(t)return e}var s=function(){if(2===h||4===h)return Promise.resolve(n.buyFromDispenserAndOrder(v[l].datatokenAddress,a,r.dispenserAddress)).then(function(e){return t=1,e})}();return s&&s.then?s.then(o):o(s)},o=function(){if(1===h){var e=new Ze(r.dispenserAddress,t),o=e.dispense,s=d[c].address;return Promise.resolve(t.getAddress()).then(function(t){return Promise.resolve(o.call(e,s,"1",t)).then(function(e){if(!e)throw new Error("Failed to dispense !");return Promise.resolve(e.wait()).then(function(){return Promise.resolve(n.startOrder(d[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return i=1,e})})})})}}();return o&&o.then?o.then(e):e(o)}],[function(){return"fixed"},function(){var o=new $e(r.fixedRateExchangeAddress,t);if(!m[f].id)throw new Error("There is no fixed rate exchange with index: "+l+" for the asset with did: "+e.id);return Promise.resolve(o.getFeesInfo(m[f].id)).then(function(e){return Promise.resolve(o.getExchange(m[f].id)).then(function(i){return Promise.resolve(o.calcBaseInGivenDatatokensOut(e.exchangeId,"1",s.consumeMarketFeeAmount)).then(function(l){var f;function m(e){var o;if(f)return e;function s(e){if(o)return e}var u=function(){if(2===h||4===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(Aa(t,r,e,i.baseToken,d[c].address,g,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to confirm/mine approval transaction!");return Promise.resolve(n.buyFromFreAndOrder(d[c].address,a,v)).then(function(e){return o=1,e})}if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return u&&u.then?u.then(s):s(u)}var g=new J.default(+l.baseTokenAmount||0).add(new J.default(s.consumeMarketFeeAmount||0)).add(new J.default(+p.publishMarketFeeAmount||0)).toString(),v={exchangeContract:r.fixedRateExchangeAddress,exchangeId:e.exchangeId,maxBaseTokenAmount:g,baseTokenAddress:i.baseToken,baseTokenDecimals:parseInt(i.btDecimals)||18,swapMarketFee:u,marketFeeAddress:p.publishMarketFeeAddress},y=function(){if(1===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(Aa(t,r,e,i.baseToken,r.fixedRateExchangeAddress,g,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return Promise.resolve(o.buyDatatokens(i.exchangeId,"1",g,p.publishMarketFeeAddress,u)).then(function(e){return Promise.resolve(e.wait()).then(function(e){if(!e)throw new Error("Failed to buy datatoken from fixed rate!");return Promise.resolve(n.startOrder(d[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return f=1,e})})})}return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return y&&y.then?y.then(m):m(y)})})})}],[void 0,function(){throw new Error("Pricing schema not supported !")}]])}return i?a(i):Promise.resolve(t.getAddress()).then(a)}var y=a||o.providerFee,b=function(){if(y&&y.providerFeeAddress!==Je&&y.providerFeeAmount&&parseInt(y.providerFeeAmount)>0)return function(e,n){try{var o=Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(Sa(t,r,e,y.providerFeeToken,v[0].datatokenAddress,y.providerFeeAmount)).then(function(){})})}catch(e){return n()}return o&&o.then?o.then(void 0,n):o}(0,function(){throw new Error("Failed to approve provider fee token "+y.providerFeeToken)})}();return b&&b.then?b.then(g):g()}var P=m.length>0?"fixed":g.length>0?"free":"NOT_ALLOWED",w=a||ga.initialize,E=a||v[l].id,S=a||e.id;return a?y(b(a)):Promise.resolve(t.getAddress()).then(y)})})})})})}catch(e){return Promise.reject(e)}},e.sendTx=je,e.setContractDefaults=Ve,e.signHash=function(e,t){try{var r=n.getBytes(t);return Promise.resolve(e._legacySignMessage(r)).then(function(e){var t="0x"+(e=e.substr(2)).slice(0,64),r="0x"+e.slice(64,128),n="0x"+e.slice(128,130);return"0x00"===n&&(n="0x1b"),"0x01"===n&&(n="0x1c"),{v:n,r:t,s:r}})}catch(e){return Promise.reject(e)}},e.signRequest=pt,e.sleep=vt,e.transfer=function(e,t,r,o,i,s,a){try{var u=new n.ethers.Contract(r,De,e);return Promise.resolve(Ie(e,r,i,s)).then(function(r){return Promise.resolve(u.transfer.estimateGas(o,r)).then(function(n){return a?n:Promise.resolve(je(n,e,null==t?void 0:t.gasFeeMultiplier,u.transfer,o,r))})})}catch(e){return Promise.reject(e)}},e.unitsToAmount=Ne,e.useOasisSDK=function(e){var t=(new Fe).getConfig(e);return t&&"oasis"===t.sdk}});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@oceanprotocol/contracts/addresses/address.json"),require("fs"),require("ethers"),require("@oasisprotocol/sapphire-paratime"),require("bignumber.js"),require("decimal.js"),require("@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json"),require("@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json"),require("@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json"),require("@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json"),require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json"),require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json"),require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json"),require("@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json"),require("@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json"),require("cross-fetch"),require("@oceanprotocol/ddo-js"),require("@multiformats/multiaddr"),require("jsonwebtoken"),require("eciesjs"),require("libp2p"),require("@chainsafe/libp2p-noise"),require("@chainsafe/libp2p-yamux"),require("@libp2p/websockets"),require("@libp2p/tcp"),require("@libp2p/circuit-relay-v2"),require("@libp2p/bootstrap"),require("@libp2p/identify"),require("@libp2p/kad-dht"),require("crypto-js/sha256.js"),require("crypto")):"function"==typeof define&&define.amd?define(["exports","@oceanprotocol/contracts/addresses/address.json","fs","ethers","@oasisprotocol/sapphire-paratime","bignumber.js","decimal.js","@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json","@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json","@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json","@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json","@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json","@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json","@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json","@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json","@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json","@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json","cross-fetch","@oceanprotocol/ddo-js","@multiformats/multiaddr","jsonwebtoken","eciesjs","libp2p","@chainsafe/libp2p-noise","@chainsafe/libp2p-yamux","@libp2p/websockets","@libp2p/tcp","@libp2p/circuit-relay-v2","@libp2p/bootstrap","@libp2p/identify","@libp2p/kad-dht","crypto-js/sha256.js","crypto"],t):t((e||self).lib={},e.DefaultContractsAddresses,e.fs,e.ethers,e.sapphire,e.BigNumber,e.Decimal,e.DispenserAbi,e.FixedRateExchangeAbi,e.FactoryRouter,e.ERC20Template$1,e.ERC20TemplateEnterprise,e.ERC721Template,e.ERC721Factory,e.ERC20Template,e.ERC20Template4,e.AccessList,e.AccessListFactory,e.Escrow,e.ContractABI,e.crossFetch,e.ddoJs,e.multiaddr,e.jsonwebtoken,e.eciesjs,e.libp2P,e.libp2pNoise,e.libp2pYamux,e.websockets,e.tcp,e.circuitRelayV2,e.bootstrap,e.identify,e.kadDht,e.sha256$2,e.crypto$1)}(this,function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g,v,p,y,b,P,w,E,S,A,T,x,k,C,O,F,D,j,I,L,N){function U(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function R(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var M,_,B=/*#__PURE__*/U(t),G=/*#__PURE__*/U(r),q=/*#__PURE__*/R(o),V=/*#__PURE__*/U(i),z=/*#__PURE__*/U(s),H=/*#__PURE__*/U(a),K=/*#__PURE__*/U(u),$=/*#__PURE__*/U(c),Z=/*#__PURE__*/U(l),J=/*#__PURE__*/U(f),W=/*#__PURE__*/U(h),Y=/*#__PURE__*/U(d),X=/*#__PURE__*/U(m),Q=/*#__PURE__*/U(g),ee=/*#__PURE__*/U(v),te=/*#__PURE__*/U(p),re=/*#__PURE__*/U(y),ne=/*#__PURE__*/U(b),oe=/*#__PURE__*/U(P),ie=/*#__PURE__*/U(S),se=/*#__PURE__*/U(L);e.FileObjectType=void 0,(M=e.FileObjectType||(e.FileObjectType={})).URL="url",M.IPFS="ipfs",M.ARWEAVE="arweave",M.S3="s3",M.FTP="ftp",e.EncryptMethod=void 0,(_=e.EncryptMethod||(e.EncryptMethod={})).AES="AES",_.ECIES="ECIES";var ae,ue={DOWNLOAD:"download",ENCRYPT:"encrypt",ENCRYPT_FILE:"encryptFile",DECRYPT_DDO:"decryptDDO",GET_DDO:"getDDO",QUERY:"query",NONCE:"nonce",STATUS:"status",DETAILED_STATUS:"detailedStatus",FIND_DDO:"findDDO",GET_FEES:"getFees",FILE_INFO:"fileInfo",VALIDATE_DDO:"validateDDO",COMPUTE_GET_ENVIRONMENTS:"getComputeEnvironments",COMPUTE_START:"startCompute",FREE_COMPUTE_START:"freeStartCompute",COMPUTE_STOP:"stopCompute",COMPUTE_GET_STATUS:"getComputeStatus",COMPUTE_GET_STREAMABLE_LOGS:"getComputeStreamableLogs",COMPUTE_GET_RESULT:"getComputeResult",COMPUTE_INITIALIZE:"initializeCompute",STOP_NODE:"stopNode",REINDEX_TX:"reindexTx",REINDEX_CHAIN:"reindexChain",HANDLE_INDEXING_THREAD:"handleIndexingThread",COLLECT_FEES:"collectFees",POLICY_SERVER_PASSTHROUGH:"PolicyServerPassthrough",GET_P2P_PEER:"getP2PPeer",GET_P2P_PEERS:"getP2PPeers",GET_P2P_NETWORK_STATS:"getP2PNetworkStats",FIND_PEER:"findPeer",CREATE_AUTH_TOKEN:"createAuthToken",INVALIDATE_AUTH_TOKEN:"invalidateAuthToken",FETCH_CONFIG:"fetchConfig",PUSH_CONFIG:"pushConfig",GET_LOGS:"getLogs",JOBS:"jobs"};function ce(e,t){this.v=e,this.k=t}function le(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function fe(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:t}})}return fe=function(e){this.s=e,this.n=e.next},fe.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var r=this.s.return;return void 0===r?Promise.resolve({value:e,done:!0}):t(r.apply(this.s,arguments))},throw:function(e){var r=this.s.return;return void 0===r?Promise.reject(e):t(r.apply(this.s,arguments))}},new fe(e)}function he(e){return new ce(e,0)}function de(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return le(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?le(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function me(){return me=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},me.apply(null,arguments)}function ge(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,pe(e,t)}function ve(){ve=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var i=Object.create((t&&t.prototype instanceof p?t:p).prototype),s=new F(n||[]);return o(i,"_invoke",{value:x(e,r,s)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",d="suspendedYield",m="executing",g="completed",v={};function p(){}function y(){}function b(){}var P={};c(P,s,function(){return this});var w=Object.getPrototypeOf,E=w&&w(w(D([])));E&&E!==r&&n.call(E,s)&&(P=E);var S=b.prototype=p.prototype=Object.create(P);function A(e){["next","throw","return"].forEach(function(t){c(e,t,function(e){return this._invoke(t,e)})})}function T(e,t){function r(o,i,s,a){var u=f(e[o],e,i);if("throw"!==u.type){var c=u.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then(function(e){r("next",e,s,a)},function(e){r("throw",e,s,a)}):t.resolve(l).then(function(e){c.value=e,s(c)},function(e){return r("throw",e,s,a)})}a(u.arg)}var i;o(this,"_invoke",{value:function(e,n){function o(){return new t(function(t,o){r(e,n,t,o)})}return i=i?i.then(o,o):o()}})}function x(t,r,n){var o=h;return function(i,s){if(o===m)throw Error("Generator is already running");if(o===g){if("throw"===i)throw s;return{value:e,done:!0}}for(n.method=i,n.arg=s;;){var a=n.delegate;if(a){var u=k(a,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=m;var c=f(t,r,n);if("normal"===c.type){if(o=n.done?g:d,c.arg===v)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=g,n.method="throw",n.arg=c.arg)}}}function k(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=f(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var s=i.arg;return s?s.done?(r[t.resultName]=s.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):s:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function F(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function D(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=b,o(S,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=c(b,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,c(e,u,"GeneratorFunction")),e.prototype=Object.create(S),e},t.awrap=function(e){return{__await:e}},A(T.prototype),c(T.prototype,a,function(){return this}),t.AsyncIterator=T,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var s=new T(l(e,r,n,o),i);return t.isGeneratorFunction(r)?s:s.next().then(function(e){return e.done?e.value:s.next()})},A(S),c(S,u,"Generator"),c(S,s,function(){return this}),c(S,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=D,F.prototype={constructor:F,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return a.type="throw",a.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return o("end");if(s.tryLoc<=this.prev){var u=n.call(s,"catchLoc"),c=n.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return o(s.catchLoc,!0);if(this.prev<s.finallyLoc)return o(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return o(s.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return o(s.finallyLoc)}}}},abrupt:function(e,t){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"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:D(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function pe(e,t){return pe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},pe(e,t)}function ye(e){return function(){return new be(e.apply(this,arguments))}}function be(e){var t,r;function n(t,r){try{var i=e[t](r),s=i.value,a=s instanceof ce;Promise.resolve(a?s.v:s).then(function(r){if(a){var u="return"===t?"return":"next";if(!s.k||r.done)return n(u,r);r=e[u](r).value}o(i.done?"return":"normal",r)},function(e){n("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?n(t.key,t.arg):r=null}this._invoke=function(e,o){return new Promise(function(i,s){var a={key:e,arg:o,resolve:i,reject:s,next:null};r?r=r.next=a:(t=r=a,n(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}be.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},be.prototype.next=function(e){return this._invoke("next",e)},be.prototype.throw=function(e){return this._invoke("throw",e)},be.prototype.return=function(e){return this._invoke("return",e)},e.LogLevel=void 0,(ae=e.LogLevel||(e.LogLevel={}))[ae.None=-1]="None",ae[ae.Error=0]="Error",ae[ae.Warn=1]="Warn",ae[ae.Log=2]="Log",ae[ae.Verbose=3]="Verbose";var Pe=/*#__PURE__*/function(){function t(t){this.logLevel=void 0,this.logLevel=t,this.logLevel=t||e.LogLevel.Error}var r=t.prototype;return r.setLevel=function(e){this.logLevel=e},r.bypass=function(){this.dispatch.apply(this,["log",-Infinity].concat([].slice.call(arguments)))},r.debug=function(){this.dispatch.apply(this,["debug",e.LogLevel.Verbose].concat([].slice.call(arguments)))},r.log=function(){this.dispatch.apply(this,["log",e.LogLevel.Log].concat([].slice.call(arguments)))},r.warn=function(){this.dispatch.apply(this,["warn",e.LogLevel.Warn].concat([].slice.call(arguments)))},r.error=function(){this.dispatch.apply(this,["error",e.LogLevel.Error].concat([].slice.call(arguments)))},r.dispatch=function(e,t){var r;this.logLevel>=t&&(r=console)[e].apply(r,[].slice.call(arguments,2))},t}(),we=new Pe,Ee={chainId:null,network:"unknown",nodeUri:"http://127.0.0.1:8545",oceanNodeUri:"http://127.0.0.1:8001",explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},Se=[me({},Ee),me({},Ee,{chainId:8996,network:"development",oceanNodeUri:"http://127.0.0.1:8001",sdk:"evm"}),me({},Ee,{chainId:11155111,network:"sepolia",nodeUri:"https://sepolia.infura.io/v3",explorerUri:"https://sepolia.etherscan.io",gasFeeMultiplier:1.1,sdk:"evm"}),me({},Ee,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),me({},Ee,{chainId:8453,network:"base",nodeUri:"https://mainnet.base.org",explorerUri:"https://etherscan.io",startBlock:30562198,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),me({},Ee,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6,sdk:"evm"}),me({},Ee,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com",sdk:"evm"}),me({},Ee,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1,sdk:"evm"}),me({},Ee,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05,sdk:"evm"}),me({},Ee,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05,sdk:"evm"}),me({},Ee,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05,sdk:"evm"}),me({},Ee,{chainId:100,network:"gen-x-testnet",nodeUri:"https://rpc.genx.minimal-gaia-x.eu",explorerUri:"https://explorer.genx.minimal-gaia-x.eu/",gasFeeMultiplier:1,sdk:"evm"}),me({},Ee,{chainId:10,network:"optimism",nodeUri:"https://mainnet.optimism.io",explorerUri:"https://optimistic.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),me({},Ee,{chainId:11155420,network:"optimism_sepolia",nodeUri:"https://sepolia.optimism.io",explorerUri:"https://sepolia-optimism.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),me({},Ee,{chainId:23294,network:"oasis_sapphire",nodeUri:"https://sapphire.oasis.io",explorerUri:"https://explorer.oasis.io/mainnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),me({},Ee,{chainId:23295,network:"oasis_sapphire_testnet",nodeUri:"https://testnet.sapphire.oasis.dev",explorerUri:"https://explorer.oasis.io/testnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),me({},Ee,{chainId:32456,network:"pontus-x-devnet",nodeUri:"https://rpc.dev.pontus-x.eu",explorerUri:"https://explorer.dev.pontus-x.eu/testnet/pontusx",sdk:"evm"})],Ae=[23294,23295],Te=function(){return process.env.NODE_ENDPOINT||process.env.NODE_URL?{oceanNodeUri:process.env.NODE_ENDPOINT||process.env.NODE_URL}:{}},xe=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getAddressesFromEnv=function(e,t){var r;if(t&&t[e]){var n=t[e];r=me({nftFactoryAddress:n.ERC721Factory,opfCommunityFeeCollector:n.OPFCommunityFeeCollector,fixedRateExchangeAddress:n.FixedPrice,dispenserAddress:n.Dispenser,oceanTokenAddress:n.Ocean,routerFactoryAddress:n.Router,chainId:n.chainId,startBlock:n.startBlock,accessListFactory:n.AccessListFactory,escrow:n.Escrow,EnterpriseFeeCollector:n.EnterpriseFeeCollector},Te())}else if(B.default[e]){var o=B.default[e];r=me({nftFactoryAddress:o.ERC721Factory,opfCommunityFeeCollector:o.OPFCommunityFeeCollector,fixedRateExchangeAddress:o.FixedPrice,dispenserAddress:o.Dispenser,oceanTokenAddress:o.Ocean,routerFactoryAddress:o.Router,chainId:o.chainId,startBlock:o.startBlock,accessListFactory:o.AccessListFactory,escrow:o.Escrow,EnterpriseFeeCollector:o.EnterpriseFeeCollector},Te())}return r},t.getConfig=function(e,t){var r,n="string"==typeof e?"network":"chainId",o=Se.find(function(t){return t[n]===e});if(!o)return we.error("No config found for given network '"+e+"'"),null;try{r=process.env.ADDRESS_FILE?JSON.parse(G.default.readFileSync(process.env.ADDRESS_FILE,"utf8")):null}catch(e){console.log(e),r=null}var i=this.getAddressesFromEnv(o.network,r);return!i&&Ae.includes(o.chainId)&&(i=this.getAddressesFromEnv(o.network.replace("sapph","saph"),r)),"sdk"in o&&null!==o.sdk||(o.sdk=Ae.includes(o.chainId)?"oasis":"evm"),i&&"accessListFactory"in i&&(o.accessListFactory=i.accessListFactory),o=me({},o,i),me({},o,{nodeUri:t?o.nodeUri+"/"+t:o.nodeUri})},e}(),ke=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],Ce=function(e,t,r,n){try{var o=arguments;return Promise.resolve(t.provider.getNetwork()).then(function(i){var s=i.chainId;return Promise.resolve(t.provider.getFeeData()).then(function(t){var i={};if(t.maxPriorityFeePerGas){var a=t.maxPriorityFeePerGas.toString(),u=t.maxFeePerGas.toString();r>1&&(a=Math.round(Number(t.maxPriorityFeePerGas)*r).toString(),u=Math.round(Number(t.maxFeePerGas)*r).toString()),i={maxPriorityFeePerGas:(Number(s)===Re||Number(s)===Ue)&&Number(a)<Ie?Ie:Number(s)===Me&&Number(a)<Le?Le:Ae.includes(Number(s))&&Number(a)<Ne?Ne:Number(a),maxFeePerGas:(Number(s)===Re||Number(s)===Ue)&&Number(u)<Ie?Ie:Number(s)===Me&&Number(u)<Le?Le:Ae.includes(Number(s))&&Number(u)<Ne?Ne:Number(u)}}else i={gasPrice:t.gasPrice};return i.gasLimit=BigInt(new V.default(e).plus(20000n).toString()),function(e,t){try{var r=Promise.resolve(n.apply(void 0,[].slice.call(o,4).concat([i]))).then(function(e){return Promise.resolve(e.wait()).then(function(){return e})})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){return we.error("Send tx error: ",e),null})})})}catch(e){return Promise.reject(e)}},Oe=function(e,t,r,o){try{var i=function(e){return"0"===e&&(e=18),n.parseUnits(r,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(De(e,t)).then(i))}catch(e){return Promise.reject(e)}},Fe=function(e,t,r,o){try{var i=function(e){return"0"===e&&(e=18),n.formatUnits(r,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(De(e,t)).then(i))}catch(e){return Promise.reject(e)}},De=function(e,t){try{var r=new n.ethers.Contract(t,ke,e);return Promise.resolve(r.decimals())}catch(e){return Promise.reject(e)}},je=function(e,t){try{return Promise.resolve(e.provider.getFeeData()).then(function(e){var r=BigInt(e.gasPrice.toString());return t?(r*BigInt(t)).toString(10):r.toString()})}catch(e){return Promise.reject(e)}},Ie=3e10,Le=4e9,Ne=1e10,Ue=137,Re=80001,Me=11155111;function _e(e,t){return e}function Be(e,t){if(e&&e.logs)return e.logs.filter(function(e){return e instanceof n.EventLog&&e.eventName===t})[0]}var Ge=/*#__PURE__*/function(){function e(e,t,r,n){this.signer=void 0,this.config=void 0,this.abi=void 0,this.signer=e,this.config=r||(new xe).getConfig(t),this.abi=n||this.getDefaultAbi()}var t=e.prototype;return t.getSignerAccordingSdk=function(){return this.config&&"sdk"in this.config&&"oasis"===this.config.sdk?q.wrap(this.signer):this.signer},t.amountToUnits=function(e,t,r){try{return Promise.resolve(Oe(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.unitsToAmount=function(e,t,r){try{return Promise.resolve(Fe(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.getFairGasPrice=function(){try{var e;return Promise.resolve(je(this.signer,null==(e=this.config)?void 0:e.gasFeeMultiplier))}catch(e){return Promise.reject(e)}},t.getContract=function(e,t){if(!e)throw new Error("Contract address is required but not provided");return _e(new n.ethers.Contract(e,new n.ethers.Interface(JSON.stringify(t||this.abi)),this.signer))},e}(),qe=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,r,n,o,i)||this).address=void 0,s.contract=void 0,s.address=t,s.contract=s.getContract(s.address),s}return ge(t,e),t}(Ge),Ve=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return H.default.abi},r.status=function(e){try{var t=this;return Promise.resolve(t.contract.status(e)).then(function(e){if(!e)throw new Error("Np dispenser found for the given datatoken address");var r=e.isMinter,n=e.owner,o=e.active;return Promise.resolve(t.unitsToAmount(null,e.maxTokens,18)).then(function(i){return Promise.resolve(t.unitsToAmount(null,e.maxBalance,18)).then(function(s){return Promise.resolve(t.unitsToAmount(null,e.balance,18)).then(function(t){return{active:o,owner:n,isMinter:r,maxTokens:i,maxBalance:s,balance:t,allowedSwapper:e.allowedSwapper}})})})})}catch(e){return Promise.reject(e)}},r.create=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.contract.create.estimateGas(e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o)).then(function(a){var u;return i?a:Promise.resolve(Ce(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.create,e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.contract.activate.estimateGas(e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18))).then(function(i){var s;return n?i:Promise.resolve(Ce(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.activate,e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18)))})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.contract.deactivate.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.deactivate,e))})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.dispense=function(e,t,r,n){void 0===t&&(t="1");try{var o=this;return Promise.resolve(o.contract.dispense.estimateGas(e,o.amountToUnits(null,t,18),r)).then(function(i){var s;return n?i:Promise.resolve(Ce(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.dispense,e,o.amountToUnits(null,t,18),r))})}catch(e){return Promise.reject(e)}},r.ownerWithdraw=function(e,t){try{var r=this;return Promise.resolve(r.contract.ownerWithdraw.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.ownerWithdraw,e))})}catch(e){return Promise.reject(e)}},r.isDispensable=function(e,t,r,n){void 0===n&&(n="1");try{return Promise.resolve(this.status(e)).then(function(o){return!!o&&!1!==o.active&&Promise.resolve(t.balance(e,r)).then(function(e){return!(new z.default(e).greaterThanOrEqualTo(o.maxBalance)||new z.default(String(n)).greaterThan(o.maxTokens)||!new z.default(o.balance).greaterThanOrEqualTo(n)&&!0!==o.isMinter)})})}catch(e){return Promise.reject(e)}},t}(qe),ze="0x0000000000000000000000000000000000000000",He=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return K.default.abi},r.generateExchangeId=function(e,t){try{return Promise.resolve(this.contract.generateExchangeId(e,t))}catch(e){return Promise.reject(e)}},r.buyDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=ze),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.buyDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(Ce(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.buyDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.sellDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=ze),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.sellDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(Ce(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.sellDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.getNumberOfExchanges=function(){try{return Promise.resolve(this.contract.getNumberOfExchanges()).then(Number)}catch(e){return Promise.reject(e)}},r.setRate=function(e,t,r){try{var n=this,o=n.contract.setRate,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.setRate,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(Ce(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.getRate=function(e){try{var t=this;return Promise.resolve(t.contract.getRate(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDatatokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getDTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.datatoken,r,Number(e.dtDecimals)))})})}catch(e){return Promise.reject(e)}},r.getBasetokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getBTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.baseToken,r,Number(e.btDecimals)))})})}catch(e){return Promise.reject(e)}},r.getAllowedSwapper=function(e){try{return Promise.resolve(this.contract.getAllowedSwapper(e))}catch(e){return Promise.reject(e)}},r.calcBaseInGivenDatatokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseInGivenOutDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e.baseTokenAmount,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.unitsToAmount(o.baseToken,e.publishMarketFeeAmount,Number(o.btDecimals))).then(function(r){return Promise.resolve(n.unitsToAmount(o.baseToken,e.oceanFeeAmount,Number(o.btDecimals))).then(function(i){return Promise.resolve(n.unitsToAmount(o.baseToken,e.consumeMarketFeeAmount,Number(o.btDecimals))).then(function(e){return{baseTokenAmount:t,marketFeeAmount:r,oceanFeeAmount:i,consumeMarketFeeAmount:e}})})})})})})})})}catch(e){return Promise.reject(e)}},r.getAmountBasetokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseOutGivenInDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e[0],Number(o.btDecimals)))})})})})}catch(e){return Promise.reject(e)}},r.getExchange=function(e){try{var t=this;return Promise.resolve(t.contract.getExchange(e)).then(function(r){var n=r.btDecimals.toString(),o=r.dtDecimals.toString(),i=r.allowedSwapper,s=r.exchangeOwner,a=r.withMint,u=r.baseToken,c=r.datatoken,l=r.active;return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtBalance,Number(r.dtDecimals))).then(function(f){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btBalance,Number(r.btDecimals))).then(function(h){return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtSupply,Number(r.dtDecimals))).then(function(d){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btSupply,Number(r.btDecimals))).then(function(m){return Promise.resolve(t.unitsToAmount(null,r.fixedRate,18)).then(function(t){return{active:l,datatoken:c,baseToken:u,withMint:a,exchangeOwner:s,allowedSwapper:i,dtDecimals:o,btDecimals:n,dtBalance:f,btBalance:h,dtSupply:d,btSupply:m,fixedRate:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getFeesInfo=function(e){try{var t=this;return Promise.resolve(t.contract.getFeesInfo(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(n){return Promise.resolve(t.unitsToAmount(null,r.opcFee.toString(),18)).then(function(o){return Promise.resolve(t.unitsToAmount(null,r.marketFee.toString(),18)).then(function(i){var s=r.marketFeeCollector;return Promise.resolve(t.unitsToAmount(n.baseToken,r.marketFeeAvailable,Number(n.btDecimals))).then(function(a){return Promise.resolve(t.unitsToAmount(n.baseToken,r.oceanFeeAvailable,Number(n.btDecimals))).then(function(t){return{opcFee:o,marketFee:i,marketFeeCollector:s,marketFeeAvailable:a,oceanFeeAvailable:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getExchanges=function(){try{return Promise.resolve(this.contract.getExchanges())}catch(e){return Promise.reject(e)}},r.isActive=function(e){try{return Promise.resolve(this.contract.isActive(e))}catch(e){return Promise.reject(e)}},r.activateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!0)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!0))}):null})}catch(e){return Promise.reject(e)}},r.deactivateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!1)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!1))}):null})}catch(e){return Promise.reject(e)}},r.collectBasetokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.baseToken,t,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.contract.collectBT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectBT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectDatatokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.contract.collectDT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectDT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectMarketFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectMarketFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectMarketFee,e))}):null})}catch(e){return Promise.reject(e)}},r.collectOceanFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectOceanFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectOceanFee,e))}):null})}catch(e){return Promise.reject(e)}},r.getOPCCollector=function(){try{return Promise.resolve(this.contract.opcCollector())}catch(e){return Promise.reject(e)}},r.getRouter=function(){try{return Promise.resolve(this.contract.router())}catch(e){return Promise.reject(e)}},r.getExchangeOwner=function(e){try{return Promise.resolve(this.getExchange(e)).then(function(e){return e.exchangeOwner})}catch(e){return Promise.reject(e)}},r.updateMarketFee=function(e,t,r){try{var n=this,o=n.contract.updateMarketFee,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.updateMarketFee,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(Ce(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.updateMarketFeeCollector=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.updateMarketFeeCollector.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.updateMarketFeeCollector,e,t))})}catch(e){return Promise.reject(e)}},t}(qe),Ke=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return $.default.abi},r.buyDatatokenBatch=function(e,t){try{var r=this;return Promise.resolve(r.contract.buyDTBatch.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.buyDTBatch,e))})}catch(e){return Promise.reject(e)}},r.isApprovedToken=function(e){try{return Promise.resolve(this.contract.isApprovedToken(e))}catch(e){return Promise.reject(e)}},r.isFixedPrice=function(e){try{return Promise.resolve(this.contract.isFixedRateContract(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.routerOwner())}catch(e){return Promise.reject(e)}},r.getNFTFactory=function(){try{return Promise.resolve(this.contract.factory())}catch(e){return Promise.reject(e)}},r.addApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.removeApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.addFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.removeFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.addDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.removeDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.getOPCFee=function(e){try{return Promise.resolve(this.contract.getOPCFee(e)).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentOPCFee=function(){try{return Promise.resolve(this.contract.swapOceanFee()).then(Number)}catch(e){return Promise.reject(e)}},r.updateOPCFee=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getOwner()).then(function(a){if(a!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(s.contract.updateOPCFee.estimateGas(t,r,n,o)).then(function(e){var a;return i?e:Promise.resolve(Ce(e,s.getSignerAccordingSdk(),null==(a=s.config)?void 0:a.gasFeeMultiplier,s.contract.updateOPCFee,t,r,n,o))})})}catch(e){return Promise.reject(e)}},t}(qe),$e={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function Ze(e){var t=e||$e,r=Math.floor(Math.random()*t.adjectives.length),n=Math.floor(Math.random()*t.nouns.length),o=Math.floor(100*Math.random()),i=t.adjectives[r].replace(/^\w/,function(e){return e.toUpperCase()}),s=t.nouns[n].replace(/^\w/,function(e){return e.toUpperCase()});return{name:i+" "+s+" Token",symbol:(i.substring(0,3)+s.substring(0,3)).toUpperCase()+"-"+o}}function Je(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var We=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return Y.default.abi},r.createNFT=function(e,t){try{var r=this;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){var n=Ze(),o=n.symbol;e.name=n.name,e.symbol=o}var i=e.templateIndex;return Promise.resolve(r.getCurrentNFTTemplateCount()).then(function(n){if(i>n)throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");return Promise.resolve(r.getNFTTemplate(e.templateIndex)).then(function(n){if(!1===n.isActive)throw new Error("Template is not active");return Promise.resolve(r.contract.deployERC721Contract.estimateGas(e.name,e.symbol,e.templateIndex,ze,ze,e.tokenURI,e.transferable,e.owner)).then(function(n){return t?n:Je(function(){var t;return Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(t=r.config)?void 0:t.gasFeeMultiplier,r.contract.deployERC721Contract,e.name,e.symbol,e.templateIndex,ze,ze,e.tokenURI,e.transferable,e.owner)).then(function(e){if(!e){var t="Tx for deploying new NFT contract does not exist or status is not successful.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return Be(e,"NFTCreated").args[0]})})},function(e){console.error("Creation of NFT failed: "+e)})})})})}catch(e){return Promise.reject(e)}},r.getCurrentNFTCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentTokenCount=function(){try{return Promise.resolve(this.contract.getCurrentTokenCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getCurrentNFTTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentTokenTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},r.getNFTTemplate=function(e){try{var t=this;return Promise.resolve(t.getCurrentNFTTemplateCount()).then(function(r){if(e>r)throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");return Promise.resolve(t.contract.getNFTTemplate(e))})}catch(e){return Promise.reject(e)}},r.getTokenTemplate=function(e){try{return Promise.resolve(this.contract.getTokenTemplate(e))}catch(e){return Promise.reject(e)}},r.checkDatatoken=function(e){try{return Promise.resolve(this.contract.erc20List(e))}catch(e){return Promise.reject(e)}},r.checkNFT=function(e){try{return Promise.resolve(this.contract.erc721List(e))}catch(e){return Promise.reject(e)}},r.addNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===ze)throw new Error("Template cannot be ZERO address");return Promise.resolve(n.contract.add721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.add721TokenTemplate,t))})})}catch(e){return Promise.reject(e)}},r.disableNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.disable721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disable721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},r.reactivateNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.reactivate721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivate721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},r.addTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===ze)throw new Error("Template cannot be address ZERO");return Promise.resolve(n.contract.addTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addTokenTemplate,t))})})}catch(e){return Promise.reject(e)}},r.disableTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!1===e.isActive)throw new Error("Template is already disabled");return Promise.resolve(n.contract.disableTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disableTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},r.reactivateTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!0===e.isActive)throw new Error("Template is already active");return Promise.resolve(n.contract.reactivateTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivateTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},r.startMultipleTokenOrder=function(e,t){try{var r=this;if(e.length>50)throw new Error("Too many orders");return Promise.resolve(r.contract.startMultipleTokenOrder.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.startMultipleTokenOrder,e))})}catch(e){return Promise.reject(e)}},r.createNftWithDatatoken=function(e,t,r){try{var n=this;return Promise.resolve(n.getErcCreationParams(t)).then(function(t){return Promise.resolve(n.contract.createNftWithErc20.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.createNftWithErc20,e,t))})})}catch(e){return Promise.reject(e)}},r.createNftWithDatatokenWithFixedRate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.getFreCreationParams(r)).then(function(r){return Promise.resolve(o.contract.createNftWithErc20WithFixedRate.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(Ce(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithFixedRate,e,t,r))})})})}catch(e){return Promise.reject(e)}},r.createNftWithDatatokenWithDispenser=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.amountToUnits(null,r.maxBalance,18)).then(function(i){return r.maxBalance=i,Promise.resolve(o.amountToUnits(null,r.maxTokens,18)).then(function(i){return r.maxTokens=i,Promise.resolve(o.contract.createNftWithErc20WithDispenser.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(Ce(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithDispenser,e,t,r))})})})})}catch(e){return Promise.reject(e)}},r.getErcCreationParams=function(e){try{var t,r,o=function(){var o=[e.minter,e.paymentCollector,e.mpFeeAddress,e.feeToken];e.filesObject&&(e.accessListFactory&&o.push(e.accessListFactory),e.allowAccessList&&o.push(e.allowAccessList),e.denyAccessList&&o.push(e.denyAccessList));var s=[e.name||t,e.symbol||r],u=e.templateIndex;return Promise.resolve(i.amountToUnits(null,e.cap,18)).then(function(t){return Promise.resolve(i.amountToUnits(null,e.feeAmount,a)).then(function(r){return{templateIndex:u,strings:s,addresses:o,uints:[t,r],bytess:e.filesObject?[n.toUtf8Bytes(JSON.stringify(e.filesObject))]:[]}})})},i=this;if(!e.name||!e.symbol){var s=Ze();t=s.name,r=s.symbol}var a=18,u=function(){if(e.feeToken!==ze){var t=Je(function(){return Promise.resolve(De(i.signer,e.feeToken)).then(function(e){a=e})},function(e){we.error("getTokenDecimals error",e)});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(u&&u.then?u.then(o):o())}catch(e){return Promise.reject(e)}},r.getFreCreationParams=function(e){try{var t=this;e.allowedConsumer||(e.allowedConsumer=ze);var r=!1===e.withMint?0:1,n=[e.baseTokenAddress,e.owner,e.marketFeeCollector,e.allowedConsumer],o=e.fixedRateAddress,i=e.datatokenDecimals,s=e.baseTokenDecimals;return Promise.resolve(t.amountToUnits(null,e.fixedRate,e.datatokenDecimals)).then(function(a){return Promise.resolve(t.amountToUnits(null,e.marketFee,e.datatokenDecimals)).then(function(e){return{fixedPriceAddress:o,addresses:n,uints:[s,i,a,e,r]}})})}catch(e){return Promise.reject(e)}},t}(qe);function Ye(e,t,r){if(!e.s){if(r instanceof Xe){if(!r.s)return void(r.o=Ye.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Ye.bind(null,e,t),Ye.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var Xe=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Ye(n,1,i(this.v))}catch(e){Ye(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ye(n,1,t?t(o):o):r?Ye(n,1,r(o)):Ye(n,2,o)}catch(e){Ye(n,2,e)}},n},e}();function Qe(e){return e instanceof Xe&&1&e.s}var et=function(e,t,r,o){try{var i="number"==typeof r,s=new We(t,e,o);return Promise.resolve(s.getCurrentTokenTemplateCount()).then(function(t){var o;function a(e){return o?e:-1}var u=1,c=function(e,t,r){for(var n;;){var o=e();if(Qe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Qe(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Qe(s)){n=2;break}}}var a=new Xe,u=Ye.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(f)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!Qe(s))return void s.then(f).then(void 0,u);if(!(o=e())||Qe(o)&&!o.v)return void Ye(a,1,i);if(o.then)return void o.then(l).then(void 0,u);Qe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):Ye(a,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):Ye(a,1,i)}}(function(){return!o&&u<=t},function(){return u++},function(){return Promise.resolve(s.getTokenTemplate(u)).then(function(t){var s=new n.ethers.Contract(t.templateAddress,X.default.abi,e);return i?Promise.resolve(s.getId()).then(function(e){if(t.isActive&&e.toString()===r.toString())return o=1,u}):t.isActive&&t.templateAddress===r.toString()?(o=1,u):void 0})});return c&&c.then?c.then(a):a(c)})}catch(e){return Promise.reject(e)}};function tt(){try{if(process.env.ADDRESS_FILE){var e=G.default.readFileSync(process.env.ADDRESS_FILE,"utf8");return JSON.parse(e)}return B.default}catch(e){return B.default}}function rt(e){try{var t=tt();if(t)for(var r=Object.keys(t),n=0,o=r;n<o.length;n++){var i=o[n];if(t[i].chainId===e)return t[i]}}catch(e){console.error(e)}return null}var nt=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return W.default.abi},r.createDatatoken=function(e,t,r,o,i,s,a,u,c,l,f,h,d,m,g,v){try{var p=this;return Promise.resolve(p.getNftPermissions(e,t)).then(function(t){if(!0!==t.deployERC20)throw new Error("Caller is not DatatokenDeployer");if(f||(f=1),!c||!l){var y=Ze();c=y.name,l=y.symbol}var b=p.getContract(e);if(!p.signer.provider)throw new Error("Provider is required but not available");return Promise.resolve(p.signer.provider.getNetwork()).then(function(e){var t=e.chainId;function y(){var e=b.createERC20,t=e.estimateGas,y=[c,l],P=f;return Promise.resolve(p.amountToUnits(null,u,18)).then(function(w){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(E){return Promise.resolve(t.call(e,P,y,[r,o,i,s],[w,E],[])).then(function(e){var t;if(v)return e;var y=[r,o,i,s];d&&(y.push(d.toLowerCase()),y.push(m?m.toLowerCase():ze),y.push(g||ze));var P=[c,l],w=f,E=b.createERC20,S=null==(t=p.config)?void 0:t.gasFeeMultiplier,A=p.getSignerAccordingSdk();return Promise.resolve(p.amountToUnits(null,u,18)).then(function(t){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(r){return Promise.resolve(Ce(e,A,S,E,w,P,y,[t,r],h?[n.toUtf8Bytes(h)]:[])).then(function(e){return Promise.resolve(e.wait()).then(function(e){var t=Be(e,"TokenCreated");return null==t?void 0:t.args[0]})})})})})})})}var P=rt(Number(t)),w=function(){if(h)return Promise.resolve(et(p.signer,P.ERC721Factory,4,Number(t))).then(function(e){f=e})}();return w&&w.then?w.then(y):y()})})}catch(e){return Promise.reject(e)}},r.addManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.addManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addManager,r))})})}catch(e){return Promise.reject(e)}},r.removeManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.removeManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeManager,r))})})}catch(e){return Promise.reject(e)}},r.addDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToCreateERC20List,r))})})}catch(e){return Promise.reject(e)}},r.removeDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t===r&&!0!==e.deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");return Promise.resolve(i.removeFromCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromCreateERC20List,r))})}var u=!0!==s.manager;return u||t!==r?a(u||t===r&&o.getNftPermissions(e,t)):Promise.resolve(u||t===r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.addMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToMetadataList,r))})})}catch(e){return Promise.reject(e)}},r.removeMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");return Promise.resolve(i.removeFromMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromMetadataList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.addStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addTo725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addTo725StoreList,r))})})}catch(e){return Promise.reject(e)}},r.removeStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.store)throw new Error("Caller is not Manager nor storeUpdater");return Promise.resolve(i.removeFrom725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFrom725StoreList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},r.cleanPermissions=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(n.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(o.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.cleanPermissions))})})}catch(e){return Promise.reject(e)}},r.transferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.transferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(Ce(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.transferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},r.safeTransferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.safeTransferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(Ce(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.safeTransferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},r.setMetadata=function(e,t,r,n,o,i,s,a,u,c){try{var l=this,f=l.getContract(e);return u||(u=[]),Promise.resolve(l.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=n;if(null!=n&&n.includes("/p2p/")){var h,d=n.match(/\/p2p\/([^/]+)/);t=null!=(h=null==d?void 0:d[1])?h:n}return Promise.resolve(f.setMetaData.estimateGas(r,t,o,i,s,a,u)).then(function(e){var n;return c?e:Promise.resolve(Ce(e,l.signer,null==(n=l.config)?void 0:n.gasFeeMultiplier,f.setMetaData,r,t,o,i,s,a,u))})})}catch(e){return Promise.reject(e)}},r.setMetadataAndTokenURI=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=me({},r,{metadataProofs:r.metadataProofs||[]});return Promise.resolve(i.setMetaDataAndTokenURI.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(Ce(e,o.signer,null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setMetaDataAndTokenURI,t))})})}catch(e){return Promise.reject(e)}},r.setMetadataState=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(i.setMetaDataState.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setMetaDataState,r))})})}catch(e){return Promise.reject(e)}},r.setTokenURI=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(o.setTokenURI.estimateGas("1",t)).then(function(e){var i;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,o.setTokenURI,"1",t))})}catch(e){return Promise.reject(e)}},r.getNftOwner=function(e){try{var t=this.getContract(e);return Promise.resolve(t.ownerOf(1))}catch(e){return Promise.reject(e)}},r.getNftPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.getPermissions(t))}catch(e){return Promise.reject(e)}},r.getMetadata=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getMetaData())}catch(e){return Promise.reject(e)}},r.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},r.setData=function(e,t,r,o,i){try{var s=this;return Promise.resolve(s.getNftPermissions(e,t)).then(function(t){if(!0!==t.store)throw new Error("User is not ERC20 store updater");var a=s.getContract(e),u=n.keccak256(r),c=n.hexlify(n.toUtf8Bytes(o));return Promise.resolve(a.setNewData.estimateGas(u,c)).then(function(e){var t;return i?e:Promise.resolve(Ce(e,s.getSignerAccordingSdk(),null==(t=s.config)?void 0:t.gasFeeMultiplier,a.setNewData,u,c))})})}catch(e){return Promise.reject(e)}},r.getData=function(e,t){try{var r=this.getContract(e),o=n.keccak256(t);return Promise.resolve(r.getData(o)).then(function(e){return e?n.toUtf8String(e):null})}catch(e){return Promise.reject(e)}},r.getTokenURI=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.tokenURI(t))}catch(e){return Promise.reject(e)}},r.isDatatokenDeployed=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isDeployed(t))}catch(e){return Promise.reject(e)}},t}(Ge),ot=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o)||this).abiEnterprise=void 0,s.nft=void 0,s.abiEnterprise=i||J.default.abi,s.nft=new nt(s.signer,r),s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return Z.default.abi},r.approve=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.approve.estimateGas(t,Oe(null,null,r,18))).then(function(e){var s;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.approve,t,Oe(null,null,r,18)))})}catch(e){return Promise.reject(e)}},r.createFixedRate=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!e)throw new Error("User is not Datatoken Deployer");r.allowedConsumer||(r.allowedConsumer=ze);var t=!1===r.withMint?0:1;return Promise.resolve(i.createFixedRate.estimateGas(r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t])).then(function(e){var s;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.createFixedRate,r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t]))})})}catch(e){return Promise.reject(e)}},r.createDispenser=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e);return n.allowedSwapper||(n.allowedSwapper=ze),n.withMint=!1!==n.withMint,Promise.resolve(s.createDispenser.estimateGas(r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper)).then(function(e){var t;return o?e:Promise.resolve(Ce(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.createDispenser,r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper))})})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getPermissions(e,t)).then(function(a){if(!0!==a.minter)throw new Error("Caller is not Minter");return Promise.resolve(i.getCap(e)).then(function(e){if(new z.default(e).gte(r))return Promise.resolve(s.mint.estimateGas(n||t,Oe(null,null,r,18))).then(function(e){var a;return o?e:Promise.resolve(Ce(e,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,s.mint,n||t,Oe(null,null,r,18)))});throw new Error("Mint amount exceeds cap available")})})}catch(e){return Promise.reject(e)}},r.addMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addMinter,r))})})}catch(e){return Promise.reject(e)}},r.removeMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removeMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeMinter,r))})})}catch(e){return Promise.reject(e)}},r.addPaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addPaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addPaymentManager,r))})})}catch(e){return Promise.reject(e)}},r.removePaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removePaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removePaymentManager,r))})})}catch(e){return Promise.reject(e)}},r.setPaymentCollector=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getPermissions(e,t)).then(function(s){function a(e){function s(s){function a(e){if(!u&&!c&&!(null==e?void 0:e.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");return Promise.resolve(i.setPaymentCollector.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setPaymentCollector,r))})}var c=e&&s===t;return e&&!c?Promise.resolve(e&&!c&&o.nft.getNftPermissions(e,t)).then(a):a(e&&!c&&o.nft.getNftPermissions(e,t))}return e?Promise.resolve(o.nft.getNftOwner(e)).then(s):s(e)}var u=s.paymentManager;return u?a(!u&&o.getNFTAddress(e)):Promise.resolve(!u&&o.getNFTAddress(e)).then(a)})}catch(e){return Promise.reject(e)}},r.getPaymentCollector=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPaymentCollector())}catch(e){return Promise.reject(e)}},r.transfer=function(e,t,r,n){try{var o=this,i=o.transferWei;return Promise.resolve(Oe(null,null,r,18)).then(function(r){return i.call(o,e,t,r,n)})}catch(e){return Promise.reject(e)}},r.transferWei=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.transfer.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.transfer,t,r))})}catch(e){return Promise.reject(e)}},r.startOrder=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e,s.abi);return o||(o={consumeMarketFeeAddress:ze,consumeMarketFeeToken:ze,consumeMarketFeeAmount:"0"}),Promise.resolve(a.startOrder.estimateGas(t,r,n,o)).then(function(e){var u;return i?e:Promise.resolve(Ce(e,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,a.startOrder,t,r,n,o))})}catch(e){return Promise.reject(e)}},r.reuseOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.reuseOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.reuseOrder,t,r))})}catch(e){return Promise.reject(e)}},r.buyFromFreAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(o.getFreOrderParams(r)).then(function(e){return Promise.resolve(i.buyFromFreAndOrder.estimateGas(t,e)).then(function(r){var s;return n?r:Promise.resolve(Ce(r,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromFreAndOrder,t,e))})})}catch(e){return Promise.reject(e)}},r.buyFromDispenserAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(i.buyFromDispenserAndOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromDispenserAndOrder,t,r))})}catch(e){return Promise.reject(e)}},r.setData=function(e,t,r,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e),a=n.hexlify(n.toUtf8Bytes(r));return Promise.resolve(s.setData.estimateGas(a)).then(function(e){var t;return o?e:Promise.resolve(Ce(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.setData,a))})})}catch(e){return Promise.reject(e)}},r.cleanPermissions=function(e,t,r){try{var n=this,o=n.nft,i=o.getNftOwner;return Promise.resolve(n.getNFTAddress(e)).then(function(s){return Promise.resolve(i.call(o,s)).then(function(o){if(o!==t)throw new Error("Caller is NOT Nft Owner");var i=n.getContract(e);return Promise.resolve(i.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,i.cleanPermissions))})})})}catch(e){return Promise.reject(e)}},r.getPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.permissions(t))}catch(e){return Promise.reject(e)}},r.getCap=function(e){try{var t=this,r=t.getContract(e);return Promise.resolve(r.cap()).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDecimals=function(e){try{var t=this.getContract(e);return Promise.resolve(t.decimals()).then(Number)}catch(e){return Promise.reject(e)}},r.getId=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getSymbol=function(e){try{var t=this.getContract(e);return Promise.resolve(t.symbol())}catch(e){return Promise.reject(e)}},r.getName=function(e){try{var t=this.getContract(e);return Promise.resolve(t.name())}catch(e){return Promise.reject(e)}},r.getNFTAddress=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getERC721Address())}catch(e){return Promise.reject(e)}},r.getFixedRates=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getFixedRates())}catch(e){return Promise.reject(e)}},r.getDispensers=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getDispensers())}catch(e){return Promise.reject(e)}},r.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},r.balance=function(e,t){try{var r=this,n=r.getContract(e);return Promise.resolve(n.balanceOf(t)).then(function(e){return Promise.resolve(r.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.allowance=function(e,t,r,n){void 0===n&&(n=18);try{var o=this,i=o.getContract(e);return Promise.resolve(i.allowance(t,r)).then(function(e){return Promise.resolve(o.unitsToAmount(null,e,n))})}catch(e){return Promise.reject(e)}},r.setPublishingMarketFee=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e);return Promise.resolve(a.getPublishingMarketFee()).then(function(e){if(e[0]!==o)throw new Error("Caller is not the Publishing Market Fee Address");return Promise.resolve(a.setPublishingMarketFee.estimateGas(t,r,n)).then(function(e){var o;return i?e:Promise.resolve(Ce(e,s.getSignerAccordingSdk(),null==(o=s.config)?void 0:o.gasFeeMultiplier,a.setPublishingMarketFee,t,r,n))})})}catch(e){return Promise.reject(e)}},r.getPublishingMarketFee=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPublishingMarketFee()).then(function(e){return{publishMarketFeeAddress:e[0],publishMarketFeeToken:e[1],publishMarketFeeAmount:e[2].toString()}})}catch(e){return Promise.reject(e)}},r.getFreOrderParams=function(e){try{var t=this,r=e.exchangeId,n=e.exchangeContract;return Promise.resolve(Oe(t.signer,e.baseTokenAddress,e.maxBaseTokenAmount,e.baseTokenDecimals)).then(function(o){return Promise.resolve(Oe(t.signer,e.baseTokenAddress,e.swapMarketFee,e.baseTokenDecimals)).then(function(t){return{exchangeContract:n,exchangeId:r,maxBaseTokenAmount:o,swapMarketFee:t,marketFeeAddress:e.marketFeeAddress}})})}catch(e){return Promise.reject(e)}},t}(Ge),it=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,n,o,i)||this).accessList=void 0,s.fileObject=void 0,s.abi=s.getDefaultAbi(),s.fileObject=r,s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return Q.default.abi},r.setFileObj=function(e){this.fileObject=e},r.getAllowlistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getAllowListContract())}catch(e){return Promise.reject(e)}},r.getDenylistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getDenyListContract())}catch(e){return Promise.reject(e)}},r.setAllowListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setAllowListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setAllowListContract,t))})})}catch(e){return Promise.reject(e)}},r.setDenyListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setDenyListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setDenyListContract,t))})})}catch(e){return Promise.reject(e)}},r.setFileObject=function(e,t,r){try{var n=this;return Promise.resolve(n.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var o=n.getContract(e);return Promise.resolve(o.setFilesObject.estimateGas(n.fileObject)).then(function(e){var t;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.setFilesObject,n.fileObject))})})}catch(e){return Promise.reject(e)}},r.getFileObject=function(e,t,r,n,o,i,s){try{var a=this.getContract(e,this.getDefaultAbi());return Promise.resolve(a.getFileObject(t,r,n,o,i,s))}catch(e){return Promise.reject(e)}},t}(ot),st=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ee.default.abi},r.getTokenUri=function(e){try{return Promise.resolve(this.contract.tokenURI(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getId=function(){try{return Promise.resolve(this.contract.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getName=function(){try{return Promise.resolve(this.contract.name())}catch(e){return Promise.reject(e)}},r.getSymbol=function(){try{return Promise.resolve(this.contract.symbol())}catch(e){return Promise.reject(e)}},r.balance=function(e){try{var t=this;return Promise.resolve(t.contract.balanceOf(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.mint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.mint,e,t))})}catch(e){return Promise.reject(e)}},r.batchMint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.batchMint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(Ce(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.batchMint,e,t))})}catch(e){return Promise.reject(e)}},r.burn=function(e,t){try{var r=this;return Promise.resolve(r.contract.burn.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.burn,e))})}catch(e){return Promise.reject(e)}},r.transferOwnership=function(e,t){try{var r=this;return Promise.resolve(r.contract.transferOwnership.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(Ce(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.transferOwnership,e))})}catch(e){return Promise.reject(e)}},r.renounceOwnership=function(e){try{var t=this;return Promise.resolve(t.contract.renounceOwnership.estimateGas()).then(function(r){var n;return e?r:Promise.resolve(Ce(r,t.getSignerAccordingSdk(),null==(n=t.config)?void 0:n.gasFeeMultiplier,t.contract.renounceOwnership))})}catch(e){return Promise.reject(e)}},t}(qe),at=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return te.default.abi},r.deployAccessListContract=function(e,t,r,n,o,i,s){void 0===n&&(n=!1);try{var a=this;if(!e||!t){var u=Ze();e=u.name,t=u.symbol}return Promise.resolve(a.contract.deployAccessListContract.estimateGas(e,t,n,o,i,r)).then(function(u){return s?u:function(s,c){try{var l=Promise.resolve(Ce(u,a.getSignerAccordingSdk(),null==(f=a.config)?void 0:f.gasFeeMultiplier,a.contract.deployAccessListContract,e,t,n,o,i,r)).then(function(e){if(!e){var t="Tx for deploying new access list was not processed on chain.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return Be(e,"NewAccessList").args[0]})})}catch(e){return c(e)}var f;return l&&l.then?l.then(void 0,c):l}(0,function(e){console.error("Creation of AccessList failed: "+e)})})}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.isSoulbound=function(e){try{return Promise.resolve(this.contract.isSoulBound(e))}catch(e){return Promise.reject(e)}},r.isDeployed=function(e){try{return Promise.resolve(this.contract.isDeployed(e))}catch(e){return Promise.reject(e)}},r.changeTemplateAddress=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===ze)throw new Error("Template address cannot be ZERO address");return Promise.resolve(n.contract.changeTemplateAddress.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(Ce(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.changeTemplateAddress,t))})})}catch(e){return Promise.reject(e)}},t}(qe);function ut(e,t,r){if(!e.s){if(r instanceof ct){if(!r.s)return void(r.o=ut.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ut.bind(null,e,t),ut.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var ct=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ut(n,1,i(this.v))}catch(e){ut(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ut(n,1,t?t(o):o):r?ut(n,1,r(o)):ut(n,2,o)}catch(e){ut(n,2,e)}},n},e}(),lt=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return re.default.abi},r.getFunds=function(e){try{return Promise.resolve(this.contract.getFunds(e))}catch(e){return Promise.reject(e)}},r.getUserFunds=function(e,t){try{return Promise.resolve(this.contract.getUserFunds(e,t))}catch(e){return Promise.reject(e)}},r.getUserTokens=function(e){try{return Promise.resolve(this.contract.getUserTokens(e))}catch(e){return Promise.reject(e)}},r.getLocks=function(e,t,r){try{return Promise.resolve(this.contract.getLocks(e,t,r))}catch(e){return Promise.reject(e)}},r.getAuthorizations=function(e,t,r){try{return Promise.resolve(this.contract.getAuthorizations(e,t,r))}catch(e){return Promise.reject(e)}},r.verifyFundsForEscrowPayment=function(e,t,r,o,i,s,a){try{var u,c=this;return Promise.resolve(null==(u=c.signer.provider)?void 0:u.getBalance(n.getAddress(t))).then(function(u){if(new V.default(u).isZero())return{isValid:!1,message:"Native token balance is 0. Please add funds"};var l=new ot(c.signer),f=l.allowance;return Promise.resolve(c.signer.getAddress()).then(function(u){return Promise.resolve(f.call(l,e,u,c.contract.target.toString(),a)).then(function(u){return Promise.resolve(c.amountToUnits(e,u,18)).then(function(u){function f(){var u=l.balance;return Promise.resolve(c.signer.getAddress()).then(function(f){return Promise.resolve(u.call(l,e,f)).then(function(u){if(new V.default(u).isZero())return{isValid:!1,message:"Payment token balance is 0. Please add funds"};var l=c.getAuthorizations;return Promise.resolve(c.signer.getAddress()).then(function(f){return Promise.resolve(l.call(c,e,f,t)).then(function(l){var f=c.getUserFunds;return Promise.resolve(c.signer.getAddress()).then(function(h){return Promise.resolve(f.call(c,h,e)).then(function(f){function h(){var r=function(){if(0===l.length)return Promise.resolve(c.authorize(n.getAddress(e),n.getAddress(t),(Number(o)/2).toString(),i,s)).then(function(){})}();return r&&r.then?r.then(function(){return{isValid:!0,message:""}}):{isValid:!0,message:""}}var d=function(){if(new V.default(f[0]).isZero()){var t=function(){if(r&&new V.default(n.parseEther(u)).isLessThanOrEqualTo(new V.default(n.parseEther(r)))&&new V.default(n.parseEther(r)).isGreaterThan(new V.default(o)))return Promise.resolve(c.deposit(e,r,a)).then(function(){});var t=function(){if(new V.default(n.parseEther(u)).isLessThanOrEqualTo(new V.default(n.parseEther(o)))){var t=c.deposit;return Promise.resolve(c.unitsToAmount(e,o,a)).then(function(r){return Promise.resolve(t.call(c,e,r,a)).then(function(){})})}return Promise.resolve(c.deposit(e,u,a)).then(function(){})}();return t&&t.then?t.then(function(){}):void 0}();if(t&&t.then)return t.then(function(){})}}();return d&&d.then?d.then(h):h()})})})})})})}var h=function(){if(new V.default(u).isLessThan(new V.default(o)))return Promise.resolve(l.approve(n.getAddress(e),n.getAddress(c.contract.target.toString()),o)).then(function(){})}();return h&&h.then?h.then(f):f()})})})})}catch(e){return Promise.reject(e)}},r.deposit=function(e,t,r,n){try{var o=this;return Promise.resolve(o.amountToUnits(e,t,r)).then(function(t){return Promise.resolve(o.contract.deposit.estimateGas(e,t)).then(function(r){var i;return n?r:Promise.resolve(Ce(r,o.getSignerAccordingSdk(),null==(i=o.config)?void 0:i.gasFeeMultiplier,o.contract.deposit,e,t))})})}catch(e){return Promise.reject(e)}},r.withdraw=function(e,t,r,n){try{var o=this,i=[],s=[];if(e.length!==t.length)throw new Error("Tokens and amounts arrays must have the same length");return Promise.resolve(o.signer.getAddress()).then(function(a){function u(){return Promise.resolve(Promise.all(s.map(function(e,t){return o.amountToUnits(i[t],e,r)}))).then(function(t){return Promise.resolve(o.contract.withdraw.estimateGas(e,t)).then(function(e){var r;return n?e:Promise.resolve(Ce(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,o.contract.withdraw,i,t))})})}var c,l,f,h,d,m=(c=e,l=function(r){var n=e[r],u=new V.default(t[r]);return Promise.resolve(o.getUserFunds(a,n)).then(function(e){var o=new V.default(e[0]);u.isGreaterThan(0)&&u.isLessThanOrEqualTo(o)?(i.push(n),s.push(t[r])):console.log("Insufficient funds for token "+n)})},d=-1,function e(t){try{for(;++d<c.length;)if((t=l(d))&&t.then){if(!((r=t)instanceof ct&&1&r.s))return void t.then(e,h||(h=ut.bind(null,f=new ct,2)));t=t.v}f?ut(f,1,t):f=t}catch(e){ut(f||(f=new ct),2,e)}var r}(),f);return m&&m.then?m.then(u):u()})}catch(e){return Promise.reject(e)}},r.authorize=function(e,t,r,n,o,i,s){try{var a=this,u=a.getAuthorizations;return Promise.resolve(a.signer.getAddress()).then(function(c){return Promise.resolve(u.call(a,e,c,t)).then(function(u){return 0!==u.length?(console.log("Payee "+t+" already authorized"),null):Promise.resolve(a.amountToUnits(e,r,i)).then(function(r){return Promise.resolve(a.amountToUnits(e,n,i)).then(function(n){return Promise.resolve(a.amountToUnits(e,o,i)).then(function(o){return Promise.resolve(a.contract.authorize.estimateGas(e,t,r,n,o)).then(function(i){var u;return s?i:Promise.resolve(Ce(i,a.getSignerAccordingSdk(),null==(u=a.config)?void 0:u.gasFeeMultiplier,a.contract.authorize,e,t,r,n,o))})})})})})})}catch(e){return Promise.reject(e)}},r.cancelExpiredLocks=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.contract.cancelExpiredLocks.estimateGas(e,t,r,n)).then(function(s){var a;return o?s:Promise.resolve(Ce(s,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,i.contract.cancelExpiredLocks,e,t,r,n))})}catch(e){return Promise.reject(e)}},t}(qe),ft=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}ge(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return ne.default.abi},r.isTokenAllowed=function(e){try{return Promise.resolve(this.contract.isTokenAllowed(e))}catch(e){return Promise.reject(e)}},r.getToken=function(e){try{return Promise.resolve(this.contract.getToken(e))}catch(e){return Promise.reject(e)}},r.calculateFee=function(e,t,r){try{var n=this,o=n.amountToUnits(e,t.toString(),r);return Promise.resolve(n.contract.calculateFee(e,o)).then(function(t){return n.unitsToAmount(e,t,r)})}catch(e){return Promise.reject(e)}},t}(qe),ht=function(e){try{return Promise.resolve(new Promise(function(t){setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},dt=function(e,t){try{var r=n.ethers.solidityPackedKeccak256(["bytes"],[n.ethers.hexlify(n.ethers.toUtf8Bytes(t))]),o=n.ethers.toBeArray(r);return Promise.resolve(function(t,r){try{var n=Promise.resolve(e.signMessage(o))}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=Number(t.chainId);return function(){if(8996===Number(r))return console.log("Signing message with _legacySignMessage"),Promise.resolve(e._legacySignMessage(o))}()})}))}catch(e){return Promise.reject(e)}};class mt extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}}class gt extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}}class vt extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}}class pt extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}}class yt extends Error{static name="ProtocolError";constructor(e="Protocol error"){super(e),this.name="ProtocolError"}}class bt extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}}class Pt extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}}const wt=Symbol.for("@libp2p/peer-id"),Et=Symbol.for("@libp2p/service-capabilities");function St(e){if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}class At{name;prefix;baseEncode;constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Tt{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,r){this.name=e,this.prefix=t;const n=t.codePointAt(0);if(void 0===n)throw new Error("Invalid prefix character");this.prefixCodePoint=n,this.baseDecode=r}decode(e){if("string"==typeof e){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(e){return kt(this,e)}}class xt{decoders;constructor(e){this.decoders=e}or(e){return kt(this,e)}decode(e){const t=this.decoders[e[0]];if(null!=t)return t.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}function kt(e,t){return new xt({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}class Ct{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new At(e,t,r),this.decoder=new Tt(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}function Ot({name:e,prefix:t,encode:r,decode:n}){return new Ct(e,t,r,n)}function Ft({name:e,prefix:t,alphabet:r}){const{encode:n,decode:o}=function(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(255!==r[s])throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,u=e.charAt(0),c=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===u;)n++,t++;for(var i=(e.length-t)*c+1>>>0,s=new Uint8Array(i);e[t];){var l=r[e.charCodeAt(t)];if(255===l)return;for(var f=0,h=i-1;(0!==l||f<o)&&-1!==h;h--,f++)s[h]=(l+=a*s[h]>>>0)%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=f,t++}if(" "!==e[t]){for(var d=i-o;d!==i&&0===s[d];)d++;for(var m=new Uint8Array(n+(i-d)),g=n;d!==i;)m[g++]=s[d++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var s=(i-o)*l+1>>>0,c=new Uint8Array(s);o!==i;){for(var f=t[o],h=0,d=s-1;(0!==f||h<n)&&-1!==d;d--,h++)c[d]=(f+=256*c[d]>>>0)%a>>>0,f=f/a>>>0;if(0!==f)throw new Error("Non-zero carry");n=h,o++}for(var m=s-n;m!==s&&0===c[m];)m++;for(var g=u.repeat(r);m<s;++m)g+=e.charAt(c[m]);return g},decodeUnsafe:f,decode:function(e){var r=f(e);if(r)return r;throw new Error(`Non-${t} character`)}}}(r,e);return Ot({prefix:t,name:e,encode:n,decode:e=>St(o(e))})}function Dt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){const o=function(e){const t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}(n);return Ot({prefix:t,name:e,encode:e=>function(e,t,r){const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,a=0;for(let n=0;n<e.length;++n)for(a=a<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(0!==s&&(i+=t[o&a<<r-s]),n)for(;i.length*r&7;)i+="=";return i}(e,n,r),decode:t=>function(e,t,r,n){let o=e.length;for(;"="===e[o-1];)--o;const i=new Uint8Array(o*r/8|0);let s=0,a=0,u=0;for(let c=0;c<o;++c){const o=t[e[c]];if(void 0===o)throw new SyntaxError(`Non-${n} character`);a=a<<r|o,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||255&a<<8-s)throw new SyntaxError("Unexpected end of data");return i}(t,o,r,e)})}const jt=Ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),It=Ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Lt={__proto__:null,base58btc:jt,base58flickr:It};const Nt=Dt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ut=Dt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rt=Dt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mt=Dt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_t=Dt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bt=Dt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gt=Dt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qt=Dt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vt=Dt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zt={__proto__:null,base32:Nt,base32upper:Ut,base32pad:Rt,base32padupper:Mt,base32hex:_t,base32hexupper:Bt,base32hexpad:Gt,base32hexpadupper:qt,base32z:Vt};const Ht=Ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Kt=Ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $t={__proto__:null,base36:Ht,base36upper:Kt},Zt=Math.pow(2,31),Jt=Math.pow(2,7),Wt=Math.pow(2,14),Yt=Math.pow(2,21),Xt=Math.pow(2,28),Qt=Math.pow(2,35),er=Math.pow(2,42),tr=Math.pow(2,49),rr=Math.pow(2,56),nr=Math.pow(2,63),or={encode:function e(t,r,n){r=r||[];for(var o=n=n||0;t>=Zt;)r[n++]=255&t|128,t/=128;for(;-128&t;)r[n++]=255&t|128,t>>>=7;return r[n]=0|t,e.bytes=n-o+1,r},decode:function e(t,r){var n,o=0,i=0,s=r=r||0,a=t.length;do{if(s>=a)throw e.bytes=0,new RangeError("Could not decode varint");n=t[s++],o+=i<28?(127&n)<<i:(127&n)*Math.pow(2,i),i+=7}while(n>=128);return e.bytes=s-r,o},encodingLength:function(e){return e<Jt?1:e<Wt?2:e<Yt?3:e<Xt?4:e<Qt?5:e<er?6:e<tr?7:e<rr?8:e<nr?9:10}};function ir(e,t=0){return[or.decode(e,t),or.decode.bytes]}function sr(e,t,r=0){return or.encode(e,t,r),t}function ar(e){return or.encodingLength(e)}function ur(e,t){const r=t.byteLength,n=ar(e),o=n+ar(r),i=new Uint8Array(o+r);return sr(e,i,0),sr(r,i,n),i.set(t,o),new lr(e,r,t,i)}function cr(e){const t=St(e),[r,n]=ir(t),[o,i]=ir(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new lr(r,o,s,t)}class lr{code;size;digest;bytes;constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}function fr(e,t){const{bytes:r,version:n}=e;return 0===n?function(e,t,r){const{prefix:n}=r;if(n!==jt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);const o=t.get(n);if(null==o){const o=r.encode(e).slice(1);return t.set(n,o),o}return o}(r,dr(e),t??jt.encoder):function(e,t,r){const{prefix:n}=r,o=t.get(n);if(null==o){const o=r.encode(e);return t.set(n,o),o}return o}(r,dr(e),t??Nt.encoder)}const hr=new WeakMap;function dr(e){const t=hr.get(e);if(null==t){const t=new Map;return hr.set(e,t),t}return t}class mr{code;version;multihash;bytes;"/";constructor(e,t,r,n){this.code=t,this.version=e,this.multihash=r,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{const{code:e,multihash:t}=this;if(e!==gr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==vr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return mr.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{const{code:e,digest:t}=this.multihash,r=ur(e,t);return mr.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return mr.equals(this,e)}static equals(e,t){return null!=t&&e.code===t.code&&e.version===t.version&&((r=e.multihash)===(n=t.multihash)||r.code===n.code&&r.size===n.size&&n.bytes instanceof Uint8Array&&function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}(r.bytes,n.bytes));var r,n}toString(e){return fr(this,e)}toJSON(){return{"/":fr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(null==e)return null;const t=e;if(t instanceof mr)return t;if(null!=t["/"]&&t["/"]===t.bytes||t.asCID===t){const{version:e,code:r,multihash:n,bytes:o}=t;return new mr(e,r,n,o??pr(e,r,n.bytes))}if(!0===t[yr]){const{version:e,multihash:r,code:n}=t,o=cr(r);return mr.create(e,n,o)}return null}static create(e,t,r){if("number"!=typeof t)throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:if(t!==gr)throw new Error(`Version 0 CID must use dag-pb (code: ${gr}) block encoding`);return new mr(e,t,r,r.bytes);case 1:{const n=pr(e,t,r.bytes);return new mr(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return mr.create(0,gr,e)}static createV1(e,t){return mr.create(1,e,t)}static decode(e){const[t,r]=mr.decodeFirst(e);if(0!==r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){const t=mr.inspectBytes(e),r=t.size-t.multihashSize,n=St(e.subarray(r,r+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");const o=n.subarray(t.multihashSize-t.digestSize),i=new lr(t.multihashCode,t.digestSize,o,n);return[0===t.version?mr.createV0(i):mr.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0;const r=()=>{const[r,n]=ir(e.subarray(t));return t+=n,r};let n=r(),o=gr;if(18===n?(n=0,t=0):o=r(),0!==n&&1!==n)throw new RangeError(`Invalid CID version ${n}`);const i=t,s=r(),a=r(),u=t+a;return{version:n,codec:o,multihashCode:s,digestSize:a,multihashSize:u-i,size:u}}static parse(e,t){const[r,n]=function(e,t){switch(e[0]){case"Q":return[jt.prefix,(t??jt).decode(`${jt.prefix}${e}`)];case jt.prefix:return[jt.prefix,(t??jt).decode(e)];case Nt.prefix:return[Nt.prefix,(t??Nt).decode(e)];case Ht.prefix:return[Ht.prefix,(t??Ht).decode(e)];default:if(null==t)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),o=mr.decode(n);if(0===o.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return dr(o).set(r,e),o}}const gr=112,vr=18;function pr(e,t,r){const n=ar(e),o=n+ar(t),i=new Uint8Array(o+r.byteLength);return sr(e,i,0),sr(t,i,n),i.set(r,o),i}const yr=Symbol.for("@ipld/js-cid/CID"),br=St,Pr=function(e,t){if(null!=t?.truncate&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return ur(0,br(e))};function wr(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Er(e=0){return new Uint8Array(e)}function Sr(e=0){return new Uint8Array(e)}function Ar(e,t){null==t&&(t=e.reduce((e,t)=>e+t.length,0));const r=Sr(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}const Tr=Symbol.for("@achingbrain/uint8arraylist");function xr(e,t){if(null==t||t<0)throw new RangeError("index is out of bounds");let r=0;for(const n of e){const e=r+n.byteLength;if(t<e)return{buf:n,index:t-r};r=e}throw new RangeError("index is out of bounds")}function kr(e){return Boolean(e?.[Tr])}class Cr{bufs;length;[Tr]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(const r of e)if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.push(r);else{if(!kr(r))throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");t+=r.byteLength,this.bufs.push(...r.bufs)}this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(const r of e.reverse())if(r instanceof Uint8Array)t+=r.byteLength,this.bufs.unshift(r);else{if(!kr(r))throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");t+=r.byteLength,this.bufs.unshift(...r.bufs)}this.length+=t}get(e){const t=xr(this.bufs,e);return t.buf[t.index]}set(e,t){const r=xr(this.bufs,e);r.buf[r.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let r=0;r<e.length;r++)this.set(t+r,e[r]);else{if(!kr(e))throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList");for(let r=0;r<e.length;r++)this.set(t+r,e.get(r))}}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength)return this.bufs=[],void(this.length=0);for(;this.bufs.length>0;){if(!(e>=this.bufs[0].byteLength)){this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift()}}}slice(e,t){const{bufs:r,length:n}=this._subList(e,t);return Ar(r,n)}subarray(e,t){const{bufs:r,length:n}=this._subList(e,t);return 1===r.length?r[0]:Ar(r,n)}sublist(e,t){const{bufs:r,length:n}=this._subList(e,t),o=new Cr;return o.length=n,o.bufs=[...r],o}_subList(e,t){if((e=e??0)<0&&(e=this.length+e),(t=t??this.length)<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(0===e&&t===this.length)return{bufs:this.bufs,length:this.length};const r=[];let n=0;for(let o=0;o<this.bufs.length;o++){const i=this.bufs[o],s=n,a=s+i.byteLength;if(n=a,e>=a)continue;const u=e>=s&&e<a,c=t>s&&t<=a;if(u&&c){if(e===s&&t===a){r.push(i);break}const n=e-s;r.push(i.subarray(n,n+(t-e)));break}if(u){if(0===e){r.push(i);continue}r.push(i.subarray(e-s))}else{if(c){if(t===a){r.push(i);break}r.push(i.subarray(0,t-s));break}r.push(i)}}return{bufs:r,length:t-e}}indexOf(e,t=0){if(!(kr(e)||e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');const r=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const n=r.byteLength;if(0===n)throw new TypeError("search must be at least 1 byte long");const o=new Int32Array(256);for(let e=0;e<256;e++)o[e]=-1;for(let e=0;e<n;e++)o[r[e]]=e;const i=o,s=this.byteLength-r.byteLength,a=r.byteLength-1;let u;for(let e=t;e<=s;e+=u){u=0;for(let t=a;t>=0;t--){const n=this.get(e+t);if(r[t]!==n){u=Math.max(1,t-i[n]);break}}if(0===u)return e}return-1}getInt8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){const r=Sr(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,t),this.write(r,e)}getInt16(e,t){const r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,t)}setInt16(e,t,r){const n=Er(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,t,r),this.write(n,e)}getInt32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,t)}setInt32(e,t,r){const n=Er(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,t,r),this.write(n,e)}getBigInt64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,t)}setBigInt64(e,t,r){const n=Er(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,t,r),this.write(n,e)}getUint8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){const r=Sr(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,t),this.write(r,e)}getUint16(e,t){const r=this.subarray(e,e+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,t)}setUint16(e,t,r){const n=Er(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,t,r),this.write(n,e)}getUint32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,t)}setUint32(e,t,r){const n=Er(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,t,r),this.write(n,e)}getBigUint64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,t)}setBigUint64(e,t,r){const n=Er(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,t,r),this.write(n,e)}getFloat32(e,t){const r=this.subarray(e,e+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,t)}setFloat32(e,t,r){const n=Er(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,t,r),this.write(n,e)}getFloat64(e,t){const r=this.subarray(e,e+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,t)}setFloat64(e,t,r){const n=Er(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,t,r),this.write(n,e)}equals(e){if(null==e)return!1;if(!(e instanceof Cr))return!1;if(e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!wr(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){const r=new Cr;return r.bufs=e,null==t&&(t=e.reduce((e,t)=>e+t.byteLength,0)),r.length=t,r}}var Or={__proto__:null,base10:Ft({prefix:"9",name:"base10",alphabet:"0123456789"})},Fr={__proto__:null,base16:Dt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),base16upper:Dt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4})},Dr={__proto__:null,base2:Dt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1})};const jr=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Ir=jr.reduce((e,t,r)=>(e[r]=t,e),[]),Lr=jr.reduce((e,t,r)=>{const n=t.codePointAt(0);if(null==n)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);var Nr={__proto__:null,base256emoji:Ot({prefix:"🚀",name:"base256emoji",encode:function(e){return e.reduce((e,t)=>e+Ir[t],"")},decode:function(e){const t=[];for(const r of e){const e=r.codePointAt(0);if(null==e)throw new Error(`Invalid character: ${r}`);const n=Lr[e];if(null==n)throw new Error(`Non-base256emoji character: ${r}`);t.push(n)}return new Uint8Array(t)}})},Ur={__proto__:null,base64:Dt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),base64pad:Dt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),base64url:Dt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),base64urlpad:Dt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6})},Rr={__proto__:null,base8:Dt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3})},Mr={__proto__:null,identity:Ot({prefix:"\0",name:"identity",encode:e=>{return t=e,(new TextDecoder).decode(t);var t},decode:e=>function(e){return(new TextEncoder).encode(e)}(e)})};function _r({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Br(e,t,r,n,o)}new TextEncoder,new TextDecoder;class Br{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,r,n,o){this.name=e,this.code=t,this.encode=r,this.minDigestLength=n??20,this.maxDigestLength=o}digest(e,t){if(null!=t?.truncate){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(null!=this.maxDigestLength&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?Gr(r,this.code,t?.truncate):r.then(e=>Gr(e,this.code,t?.truncate))}throw Error("Unknown type, must be binary type")}}function Gr(e,t,r){if(null!=r&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return ur(t,e)}function qr(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}const Vr=_r({name:"sha2-256",code:18,encode:qr("SHA-256")});_r({name:"sha2-512",code:19,encode:qr("SHA-512")});const zr={...Mr,...Dr,...Rr,...Or,...Fr,...zt,...$t,...Lt,...Ur,...Nr};function Hr(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}const Kr=Hr("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>(new TextEncoder).encode(e.substring(1))),$r=Hr("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{const t=Sr((e=e.substring(1)).length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Zr={utf8:Kr,"utf-8":Kr,hex:zr.base16,latin1:$r,ascii:$r,binary:$r,...zr};function Jr(e,t="utf8"){const r=Zr[t];if(null==r)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Wr(e,t="utf8"){const r=Zr[t];if(null==r)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}const Yr=parseInt("11111",2),Xr=parseInt("10000000",2),Qr=parseInt("01111111",2),en={0:nn,1:nn,2:function(e,t){const r=rn(e,t),n=t.offset,o=t.offset+r,i=[];for(let t=n;t<o;t++)t===n&&0===e[t]||i.push(e[t]);return t.offset+=r,Uint8Array.from(i)},3:function(e,t){const r=rn(e,t),n=e[t.offset];t.offset++;const o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,0!==n)throw new Error("Unused bits in bit string is unimplemented");return o},4:function(e,t){const r=rn(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n},5:function(e,t){return t.offset++,null},6:function(e,t){const r=rn(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,u=[];for(;t.offset<n;){const r=e[t.offset];if(t.offset++,u.push(127&r),r<128){u.reverse();let e=0;for(let t=0;t<u.length;t++)e+=u[t]<<7*t;a+=`.${e}`,u=[]}}return a},16:nn,22:nn,48:nn};function tn(e,t={offset:0}){const r=e[t.offset]&Yr;if(t.offset++,null!=en[r])return en[r](e,t);throw new Error("No decoder for tag "+r)}function rn(e,t){let r=0;if((e[t.offset]&Xr)===Xr){const n=e[t.offset]&Qr;let o="0x";t.offset++;for(let r=0;r<n;r++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function nn(e,t){rn(e,t);const r=[];for(;!(t.offset>=e.byteLength);){const n=tn(e,t);if(null===n)break;r.push(n)}return r}function on(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);const t=function(e){let t=e.toString(16);t.length%2==1&&(t="0"+t);const r=new Cr;for(let e=0;e<t.length;e+=2)r.append(Uint8Array.from([parseInt(`${t[e]}${t[e+1]}`,16)]));return r}(e.byteLength);return new Cr(Uint8Array.from([t.byteLength|Xr]),t)}function sn(e){const t=new Cr;return!(128&~e.subarray()[0])&&t.append(Uint8Array.from([0])),t.append(e),new Cr(Uint8Array.from([2]),on(t),t)}function an(e){const t=Uint8Array.from([0]),r=new Cr(t,e);return new Cr(Uint8Array.from([3]),on(r),r)}function un(e,t=48){const r=new Cr;for(const t of e)r.append(t);return new Cr(Uint8Array.from([t]),on(r),r)}const cn=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ln=Uint8Array.from([6,5,43,129,4,0,34]),fn=Uint8Array.from([6,5,43,129,4,0,35]),hn={ext:!0,kty:"EC",crv:"P-256"},dn={ext:!0,kty:"EC",crv:"P-384"},mn={ext:!0,kty:"EC",crv:"P-521"};function gn(e){if("P-256"===e)return cn;if("P-384"===e)return ln;if("P-521"===e)return fn;throw new mt(`Invalid curve ${e}`)}class vn{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){var e;return null==this._raw&&(this._raw=(e=this.jwk,un([sn(Uint8Array.from([1])),un([gn(e.crv)],160),un([an(new Cr(Uint8Array.from([4]),Jr(e.x??"","base64url"),Jr(e.y??"","base64url")))],161)]).subarray())),this._raw}toMultihash(){return Pr(ia(this))}toCID(){return mr.createV1(114,this.toMultihash())}toString(){return jt.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&wr(this.raw,e.raw)}async verify(e,t,r){return async function(e,t,r,n){const o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();const i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}(this.jwk,t,e,r)}}function pn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function yn(e,t=""){if(!Number.isSafeInteger(e)||e<0)throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}function bn(e,t,r=""){const n=pn(e),o=e?.length,i=void 0!==t;if(!n||i&&o!==t)throw new Error((r&&`"${r}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(n?`length=${o}`:"type="+typeof e));return e}function Pn(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash must wrapped by utils.createHasher");yn(e.outputLen),yn(e.blockLen)}function wn(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function En(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function An(e,t){return e<<32-t|e>>>t}const Tn=/* @__PURE__ */(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),xn=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kn(e){if(bn(e),Tn)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=xn[e[r]];return t}function Cn(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function On(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Tn)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let t=0,o=0;t<r;t++,o+=2){const r=Cn(e.charCodeAt(o)),i=Cn(e.charCodeAt(o+1));if(void 0===r||void 0===i)throw new Error('hex string expected, got non-hex character "'+(e[o]+e[o+1])+'" at index '+o);n[t]=16*r+i}return n}function Fn(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];bn(n),t+=n.length}const r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const o=e[t];r.set(o,n),n+=o.length}return r}function Dn(e,t={}){const r=(t,r)=>e(r).update(t).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=t=>e(t),Object.assign(r,t),Object.freeze(r)}function jn(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const In=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ln(e,t,r){return e&t^e&r^t&r}class Nn{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,r,n){this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=Sn(this.buffer)}update(e){wn(this),bn(e);const{view:t,buffer:r,blockLen:n}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(n-this.pos,o-i);if(s!==n)r.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=Sn(e);for(;n<=o-i;i+=n)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){wn(this),function(e,t){bn(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:i}=this;t[i++]=128,En(this.buffer.subarray(i)),this.padOffset>n-i&&(this.process(r,0),i=0);for(let e=i;e<n;e++)t[e]=0;r.setBigUint64(n-8,BigInt(8*this.length),o),this.process(r,0);const s=Sn(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<u;e++)s.setUint32(4*e,c[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Un=/* @__PURE__ */Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rn=/* @__PURE__ */Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Mn=/* @__PURE__ */BigInt(2**32-1),_n=/* @__PURE__ */BigInt(32);function Bn(e,t=!1){return t?{h:Number(e&Mn),l:Number(e>>_n&Mn)}:{h:0|Number(e>>_n&Mn),l:0|Number(e&Mn)}}const Gn=(e,t,r)=>e>>>r,qn=(e,t,r)=>e<<32-r|t>>>r,Vn=(e,t,r)=>e>>>r|t<<32-r,zn=(e,t,r)=>e<<32-r|t>>>r,Hn=(e,t,r)=>e<<64-r|t>>>r-32,Kn=(e,t,r)=>e>>>r-32|t<<64-r;function $n(e,t,r,n){const o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:0|o}}const Zn=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Jn=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Wn=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Yn=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Xn=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Qn=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0,eo=/* @__PURE__ */Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),to=/* @__PURE__ */new Uint32Array(64);class ro extends Nn{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:r,D:n,E:o,F:i,G:s,H:a}=this;return[e,t,r,n,o,i,s,a]}set(e,t,r,n,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let r=0;r<16;r++,t+=4)to[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=to[e-15],r=to[e-2],n=An(t,7)^An(t,18)^t>>>3,o=An(r,17)^An(r,19)^r>>>10;to[e]=o+to[e-7]+n+to[e-16]|0}let{A:r,B:n,C:o,D:i,E:s,F:a,G:u,H:c}=this;for(let e=0;e<64;e++){const t=c+(An(s,6)^An(s,11)^An(s,25))+((l=s)&a^~l&u)+eo[e]+to[e]|0,f=(An(r,2)^An(r,13)^An(r,22))+Ln(r,n,o)|0;c=u,u=a,a=s,s=i+t|0,i=o,o=n,n=r,r=t+f|0}var l;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,o,i,s,a,u,c)}roundClean(){En(to)}destroy(){this.set(0,0,0,0,0,0,0,0),En(this.buffer)}}class no extends ro{A=0|Un[0];B=0|Un[1];C=0|Un[2];D=0|Un[3];E=0|Un[4];F=0|Un[5];G=0|Un[6];H=0|Un[7];constructor(){super(32)}}const oo=/* @__PURE__ */(()=>function(e,t=!1){const r=e.length;let n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){const{h:r,l:s}=Bn(e[i],t);[n[i],o[i]]=[r,s]}return[n,o]}(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))))(),io=/* @__PURE__ */(()=>oo[0])(),so=/* @__PURE__ */(()=>oo[1])(),ao=/* @__PURE__ */new Uint32Array(80),uo=/* @__PURE__ */new Uint32Array(80);class co extends Nn{constructor(e){super(128,e,16,!1)}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:o,Cl:i,Dh:s,Dl:a,Eh:u,El:c,Fh:l,Fl:f,Gh:h,Gl:d,Hh:m,Hl:g}=this;return[e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g]}set(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|m,this.Hl=0|g}process(e,t){for(let r=0;r<16;r++,t+=4)ao[r]=e.getUint32(t),uo[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|ao[e-15],r=0|uo[e-15],n=Vn(t,r,1)^Vn(t,r,8)^Gn(t,0,7),o=zn(t,r,1)^zn(t,r,8)^qn(t,r,7),i=0|ao[e-2],s=0|uo[e-2],a=Vn(i,s,19)^Hn(i,s,61)^Gn(i,0,6),u=zn(i,s,19)^Kn(i,s,61)^qn(i,s,6),c=Wn(o,u,uo[e-7],uo[e-16]),l=Yn(c,n,a,ao[e-7],ao[e-16]);ao[e]=0|l,uo[e]=0|c}let{Ah:r,Al:n,Bh:o,Bl:i,Ch:s,Cl:a,Dh:u,Dl:c,Eh:l,El:f,Fh:h,Fl:d,Gh:m,Gl:g,Hh:v,Hl:p}=this;for(let e=0;e<80;e++){const t=Vn(l,f,14)^Vn(l,f,18)^Hn(l,f,41),y=zn(l,f,14)^zn(l,f,18)^Kn(l,f,41),b=l&h^~l&m,P=Xn(p,y,f&d^~f&g,so[e],uo[e]),w=Qn(P,v,t,b,io[e],ao[e]),E=0|P,S=Vn(r,n,28)^Hn(r,n,34)^Hn(r,n,39),A=zn(r,n,28)^Kn(r,n,34)^Kn(r,n,39),T=r&o^r&s^o&s,x=n&i^n&a^i&a;v=0|m,p=0|g,m=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=$n(0|u,0|c,0|w,0|E)),u=0|s,c=0|a,s=0|o,a=0|i,o=0|r,i=0|n;const k=Zn(E,A,x);r=Jn(k,w,S,T),n=0|k}({h:r,l:n}=$n(0|this.Ah,0|this.Al,0|r,0|n)),({h:o,l:i}=$n(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=$n(0|this.Ch,0|this.Cl,0|s,0|a)),({h:u,l:c}=$n(0|this.Dh,0|this.Dl,0|u,0|c)),({h:l,l:f}=$n(0|this.Eh,0|this.El,0|l,0|f)),({h:h,l:d}=$n(0|this.Fh,0|this.Fl,0|h,0|d)),({h:m,l:g}=$n(0|this.Gh,0|this.Gl,0|m,0|g)),({h:v,l:p}=$n(0|this.Hh,0|this.Hl,0|v,0|p)),this.set(r,n,o,i,s,a,u,c,l,f,h,d,m,g,v,p)}roundClean(){En(ao,uo)}destroy(){En(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class lo extends co{Ah=0|Rn[0];Al=0|Rn[1];Bh=0|Rn[2];Bl=0|Rn[3];Ch=0|Rn[4];Cl=0|Rn[5];Dh=0|Rn[6];Dl=0|Rn[7];Eh=0|Rn[8];El=0|Rn[9];Fh=0|Rn[10];Fl=0|Rn[11];Gh=0|Rn[12];Gl=0|Rn[13];Hh=0|Rn[14];Hl=0|Rn[15];constructor(){super(64)}}const fo=/* @__PURE__ */Dn(()=>new no
|
|
2
|
+
/* @__PURE__ */,In(1)),ho=/* @__PURE__ */Dn(()=>new lo
|
|
3
|
+
/* @__PURE__ */,In(3)),mo=/* @__PURE__ */BigInt(0),go=/* @__PURE__ */BigInt(1);function vo(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e);return e}function po(e){if("bigint"==typeof e){if(!To(e))throw new Error("positive bigint expected, got "+e)}else yn(e);return e}function yo(e){const t=po(e).toString(16);return 1&t.length?"0"+t:t}function bo(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?mo:BigInt("0x"+e)}function Po(e){return bo(kn(e))}function wo(e){return bo(kn(Ao(bn(e)).reverse()))}function Eo(e,t){yn(t);const r=On((e=po(e)).toString(16).padStart(2*t,"0"));if(r.length!==t)throw new Error("number too large");return r}function So(e,t){return Eo(e,t).reverse()}function Ao(e){return Uint8Array.from(e)}const To=e=>"bigint"==typeof e&&mo<=e;function xo(e,t,r,n){if(!function(e,t,r){return To(e)&&To(t)&&To(r)&&t<=e&&e<r}(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}const ko=e=>(go<<BigInt(e))-go;function Co(e,t={},r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");const n=(t,r)=>Object.entries(t).forEach(([t,n])=>function(t,r,n){const o=e[t];if(n&&void 0===o)return;const i=typeof o;if(i!==r||null===o)throw new Error(`param "${t}" is invalid: expected ${r}, got ${i}`)}(t,n,r));n(t,!1),n(r,!0)}function Oo(e){const t=new WeakMap;return(r,...n)=>{const o=t.get(r);if(void 0!==o)return o;const i=e(r,...n);return t.set(r,i),i}}const Fo=/* @__PURE__ */BigInt(0),Do=/* @__PURE__ */BigInt(1),jo=/* @__PURE__ */BigInt(2),Io=/* @__PURE__ */BigInt(3),Lo=/* @__PURE__ */BigInt(4),No=/* @__PURE__ */BigInt(5),Uo=/* @__PURE__ */BigInt(7),Ro=/* @__PURE__ */BigInt(8),Mo=/* @__PURE__ */BigInt(9),_o=/* @__PURE__ */BigInt(16);function Bo(e,t){const r=e%t;return r>=Fo?r:t+r}function Go(e,t,r){let n=e;for(;t-- >Fo;)n*=n,n%=r;return n}function qo(e,t){if(e===Fo)throw new Error("invert: expected non-zero number");if(t<=Fo)throw new Error("invert: expected positive modulus, got "+t);let r=Bo(e,t),n=t,o=Fo,i=Do;for(;r!==Fo;){const e=n%r,t=o-i*(n/r);n=r,r=e,o=i,i=t}if(n!==Do)throw new Error("invert: does not exist");return Bo(o,t)}function Vo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function zo(e,t){const r=e.pow(t,(e.ORDER+Do)/Lo);return Vo(e,r,t),r}function Ho(e,t){const r=(e.ORDER-No)/Ro,n=e.mul(t,jo),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,jo),o),a=e.mul(i,e.sub(s,e.ONE));return Vo(e,a,t),a}function Ko(e){if(e<Io)throw new Error("sqrt is not defined for small field");let t=e-Do,r=0;for(;t%jo===Fo;)t/=jo,r++;let n=jo;const o=Yo(e);for(;1===Jo(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===r)return zo;let i=o.pow(n,t);const s=(t+Do)/jo;return function(e,n){if(e.is0(n))return n;if(1!==Jo(e,n))throw new Error("Cannot find square root");let o=r,a=e.mul(e.ONE,i),u=e.pow(n,t),c=e.pow(n,s);for(;!e.eql(u,e.ONE);){if(e.is0(u))return e.ZERO;let t=1,r=e.sqr(u);for(;!e.eql(r,e.ONE);)if(t++,r=e.sqr(r),t===o)throw new Error("Cannot find square root");const n=Do<<BigInt(o-t-1),i=e.pow(a,n);o=t,a=e.sqr(i),u=e.mul(u,a),c=e.mul(c,i)}return c}}const $o=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Zo(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),i=e.inv(o);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),i),n}function Jo(e,t){const r=e.pow(t,(e.ORDER-Do)/jo),n=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),i=e.eql(r,e.neg(e.ONE));if(!n&&!o&&!i)throw new Error("invalid Legendre symbol result");return n?1:o?0:-1}class Wo{ORDER;BITS;BYTES;isLE;ZERO=Fo;ONE=Do;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=Fo)throw new Error("invalid field: expected ORDER > 0, got "+e);let r;this.isLE=!1,null!=t&&"object"==typeof t&&("number"==typeof t.BITS&&(r=t.BITS),"function"==typeof t.sqrt&&(this.sqrt=t.sqrt),"boolean"==typeof t.isLE&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),"boolean"==typeof t.modFromBytes&&(this._mod=t.modFromBytes));const{nBitLength:n,nByteLength:o}=function(e,t){void 0!==t&&yn(t);const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}(e,r);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=n,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Bo(e,this.ORDER)}isValid(e){if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return Fo<=e&&e<this.ORDER}is0(e){return e===Fo}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Do)===Do}neg(e){return Bo(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return Bo(e*e,this.ORDER)}add(e,t){return Bo(e+t,this.ORDER)}sub(e,t){return Bo(e-t,this.ORDER)}mul(e,t){return Bo(e*t,this.ORDER)}pow(e,t){return function(e,t,r){if(r<Fo)throw new Error("invalid exponent, negatives unsupported");if(r===Fo)return e.ONE;if(r===Do)return t;let n=e.ONE,o=t;for(;r>Fo;)r&Do&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Do;return n}(this,e,t)}div(e,t){return Bo(e*qo(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return qo(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=(t=this.ORDER)%Lo===Io?zo:t%Ro===No?Ho:t%_o===Mo?function(e){const t=Yo(e),r=Ko(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Uo)/_o;return(e,t)=>{let r=e.pow(t,s),a=e.mul(r,n);const u=e.mul(r,o),c=e.mul(r,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(u),t);r=e.cmov(r,a,l),a=e.cmov(c,u,f);const h=e.eql(e.sqr(a),t),d=e.cmov(r,a,h);return Vo(e,d,t),d}}(t):Ko(t)),this._sqrt(this,e);var t}toBytes(e){return this.isLE?So(e,this.BYTES):Eo(e,this.BYTES)}fromBytes(e,t=!1){bn(e);const{_lengths:r,BYTES:n,isLE:o,ORDER:i,_mod:s}=this;if(r){if(!r.includes(e.length)||e.length>n)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);const t=new Uint8Array(n);t.set(e,o?0:t.length-e.length),e=t}if(e.length!==n)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let a=o?wo(e):Po(e);if(s&&(a=Bo(a,i)),!t&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Zo(this,e)}cmov(e,t,r){return r?t:e}}function Yo(e,t={}){return new Wo(e,t)}function Xo(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Qo(e){const t=Xo(e);return t+Math.ceil(t/2)}const ei=/* @__PURE__ */BigInt(0),ti=/* @__PURE__ */BigInt(1);function ri(e,t){const r=t.negate();return e?r:t}function ni(e,t){const r=Zo(e.Fp,t.map(e=>e.Z));return t.map((t,n)=>e.fromAffine(t.toAffine(r[n])))}function oi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ii(e,t){oi(e,t);const r=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:ko(e),maxNumber:r,shiftBy:BigInt(e)}}function si(e,t,r){const{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r;let a=Number(e&o),u=e>>s;a>n&&(a-=i,u+=ti);const c=t*n;return{nextN:u,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const ai=new WeakMap,ui=new WeakMap;function ci(e){return ui.get(e)||1}function li(e){if(e!==ei)throw new Error("invalid wNAF")}class fi{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,r=this.ZERO){let n=e;for(;t>ei;)t&ti&&(r=r.add(n)),n=n.double(),t>>=ti;return r}precomputeWindow(e,t){const{windows:r,windowSize:n}=ii(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<r;e++){s=i,o.push(s);for(let e=1;e<n;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let n=this.ZERO,o=this.BASE;const i=ii(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:u,isNeg:c,isNegF:l,offsetF:f}=si(r,e,i);r=s,u?o=o.add(ri(l,t[f])):n=n.add(ri(c,t[a]))}return li(r),{p:n,f:o}}wNAFUnsafe(e,t,r,n=this.ZERO){const o=ii(e,this.bits);for(let e=0;e<o.windows&&r!==ei;e++){const{nextN:i,offset:s,isZero:a,isNeg:u}=si(r,e,o);if(r=i,!a){const e=t[s];n=n.add(u?e.negate():e)}}return li(r),n}getPrecomputes(e,t,r){let n=ai.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),ai.set(t,n))),n}cached(e,t,r){const n=ci(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)}unsafe(e,t,r,n){const o=ci(e);return 1===o?this._unsafeLadder(e,t,n):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,n)}createCache(e,t){oi(t,this.bits),ui.set(e,t),ai.delete(e)}hasCache(e){return 1!==ci(e)}}function hi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Co(e,$o.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Yo(e,{isLE:r})}function di(e,t,r={},n){if(void 0===n&&(n="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const r=t[e];if(!("bigint"==typeof r&&r>ei))throw new Error(`CURVE.${e} must be positive bigint`)}const o=hi(t.p,r.Fp,n),i=hi(t.n,r.Fn,n),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}function mi(e,t){return function(r){const n=e(r);return{secretKey:n,publicKey:t(n)}}}const gi=BigInt(0),vi=BigInt(1),pi=BigInt(2),yi=BigInt(8);function bi(e,t={}){const r=di("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r;let i=r.CURVE;const{h:s}=i;Co(t,{},{uvRatio:"function"});const a=pi<<BigInt(8*o.BYTES)-vi,u=e=>n.create(e),c=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:n.sqrt(n.div(e,t))}}catch(e){return{isValid:!1,value:gi}}});if(!function(e,t,r,n){const o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(e,t,r=!1){return xo("coordinate "+e,t,r?vi:gi,a),t}function f(e){if(!(e instanceof m))throw new Error("EdwardsPoint expected")}const h=Oo((e,t)=>{const{X:r,Y:o,Z:i}=e,s=e.is0();null==t&&(t=s?yi:n.inv(i));const a=u(r*t),c=u(o*t),l=n.mul(i,t);if(s)return{x:gi,y:vi};if(l!==vi)throw new Error("invZ was invalid");return{x:a,y:c}}),d=Oo(e=>{const{a:t,d:r}=i;if(e.is0())throw new Error("bad point: ZERO");const{X:n,Y:o,Z:s,T:a}=e,c=u(n*n),l=u(o*o),f=u(s*s),h=u(f*f),d=u(c*t);if(u(f*u(d+l))!==u(h+u(r*u(c*l))))throw new Error("bad point: equation left != right (1)");if(u(n*o)!==u(s*a))throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(i.Gx,i.Gy,vi,u(i.Gx*i.Gy));static ZERO=new m(gi,vi,vi,gi);static Fp=n;static Fn=o;X;Y;Z;T;constructor(e,t,r,n){this.X=l("x",e),this.Y=l("y",t),this.Z=l("z",r,!0),this.T=l("t",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){if(e instanceof m)throw new Error("extended point not allowed");const{x:t,y:r}=e||{};return l("x",t),l("y",r),new m(t,r,vi,u(t*r))}static fromBytes(e,t=!1){const r=n.BYTES,{a:o,d:s}=i;e=Ao(bn(e,r,"point")),vo(t,"zip215");const l=Ao(e),f=e[r-1];l[r-1]=-129&f;const h=wo(l);xo("point.y",h,gi,t?a:n.ORDER);const d=u(h*h),g=u(d-vi),v=u(s*d-o);let{isValid:p,value:y}=c(g,v);if(!p)throw new Error("bad point: invalid y coordinate");const b=(y&vi)===vi,P=!!(128&f);if(!t&&y===gi&&P)throw new Error("bad point: x=0 and x_0=1");return P!==b&&(y=u(-y)),m.fromAffine({x:y,y:h})}static fromHex(e,t=!1){return m.fromBytes(On(e),t)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return g.createCache(this,e),t||this.multiply(pi),this}assertValidity(){d(this)}equals(e){f(e);const{X:t,Y:r,Z:n}=this,{X:o,Y:i,Z:s}=e,a=u(t*s),c=u(o*n),l=u(r*s),h=u(i*n);return a===c&&l===h}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.X),this.Y,this.Z,u(-this.T))}double(){const{a:e}=i,{X:t,Y:r,Z:n}=this,o=u(t*t),s=u(r*r),a=u(pi*u(n*n)),c=u(e*o),l=t+r,f=u(u(l*l)-o-s),h=c+s,d=h-a,g=c-s,v=u(f*d),p=u(h*g),y=u(f*g),b=u(d*h);return new m(v,p,b,y)}add(e){f(e);const{a:t,d:r}=i,{X:n,Y:o,Z:s,T:a}=this,{X:c,Y:l,Z:h,T:d}=e,g=u(n*c),v=u(o*l),p=u(a*r*d),y=u(s*h),b=u((n+o)*(c+l)-g-v),P=y-p,w=y+p,E=u(v-t*g),S=u(b*P),A=u(w*E),T=u(b*E),x=u(P*w);return new m(S,A,x,T)}subtract(e){return this.add(e.negate())}multiply(e){if(!o.isValidNot0(e))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:t,f:r}=g.cached(this,e,e=>ni(m,e));return ni(m,[t,r])[0]}multiplyUnsafe(e,t=m.ZERO){if(!o.isValid(e))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return e===gi?m.ZERO:this.is0()||e===vi?this:g.unsafe(this,e,e=>ni(m,e),t)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return g.unsafe(this,i.n).is0()}toAffine(e){return h(this,e)}clearCofactor(){return s===vi?this:this.multiplyUnsafe(s)}toBytes(){const{x:e,y:t}=this.toAffine(),r=n.toBytes(t);return r[r.length-1]|=e&vi?128:0,r}toHex(){return kn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const g=new fi(m,o.BITS);return m.BASE.precompute(8),m}const Pi=BigInt(1),wi=BigInt(2),Ei=BigInt(5),Si=BigInt(8),Ai=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ti=/* @__PURE__ */(()=>({p:Ai,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Si,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")}))();function xi(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const ki=/* @__PURE__ */BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ci=/* @__PURE__ */bi(Ti,{uvRatio:function(e,t){const r=Ai,n=Bo(t*t*t,r),o=function(e){const t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Ai,s=e*e%i*e%i,a=Go(s,wi,i)*s%i,u=Go(a,Pi,i)*e%i,c=Go(u,Ei,i)*u%i,l=Go(c,t,i)*c%i,f=Go(l,r,i)*l%i,h=Go(f,n,i)*f%i,d=Go(h,o,i)*h%i,m=Go(d,o,i)*h%i,g=Go(m,t,i)*c%i;return{pow_p_5_8:Go(g,wi,i)*e%i,b2:s}}(e*Bo(n*n*t,r)).pow_p_5_8;let i=Bo(e*n*o,r);const s=Bo(t*i*i,r),a=i,u=Bo(i*ki,r),c=s===e,l=s===Bo(-e,r),f=s===Bo(-e*ki,r);return c&&(i=a),(l||f)&&(i=u),(Bo(i,r)&Do)===Do&&(i=Bo(-i,r)),{isValid:c||l,value:i}}});function Oi(e){return function(e,t,r={}){if("function"!=typeof t)throw new Error('"hash" function param is required');Co(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||jn,u=r.adjustScalarBytes||(e=>e),c=r.domain||((e,t,r)=>{if(vo(r,"phflag"),t.length||r)throw new Error("Contexts/pre-hash are not supported");return e});function l(e){return s.create(wo(e))}function f(e){const{head:r,prefix:n,scalar:i}=function(e){const r=v.secretKey;bn(e,v.secretKey,"secretKey");const n=bn(t(e),2*r,"hashedSecretKey"),o=u(n.slice(0,r));return{head:o,prefix:n.slice(r,2*r),scalar:l(o)}}(e),s=o.multiply(i),a=s.toBytes();return{head:r,prefix:n,scalar:i,point:s,pointBytes:a}}function h(e){return f(e).pointBytes}function d(e=Uint8Array.of(),...r){const o=Fn(...r);return l(t(c(o,bn(e,void 0,"context"),!!n)))}const m={zip215:!0},g=i.BYTES,v={secretKey:g,publicKey:g,signature:2*g,seed:g};function p(e=a(v.seed)){return bn(e,v.seed,"seed")}const y={getExtendedPublicKey:f,randomSecretKey:p,isValidSecretKey:function(e){return pn(e)&&e.length===s.BYTES},isValidPublicKey:function(t,r){try{return!!e.fromBytes(t,r)}catch(e){return!1}},toMontgomery(t){const{y:r}=e.fromBytes(t),n=v.publicKey,o=32===n;if(!o&&57!==n)throw new Error("only defined for 25519 and 448");const s=o?i.div(vi+r,vi-r):i.div(r-vi,r+vi);return i.toBytes(s)},toMontgomerySecret(e){const r=v.secretKey;bn(e,r);const n=t(e.subarray(0,r));return u(n).subarray(0,r)}};return Object.freeze({keygen:mi(p,h),getPublicKey:h,sign:function(e,t,r={}){e=bn(e,void 0,"message"),n&&(e=n(e));const{prefix:i,scalar:a,pointBytes:u}=f(t),c=d(r.context,i,e),l=o.multiply(c).toBytes(),h=d(r.context,l,u,e),m=s.create(c+h*a);if(!s.isValid(m))throw new Error("sign failed: invalid s");return bn(Fn(l,s.toBytes(m)),v.signature,"result")},verify:function(t,r,i,s=m){const{context:a,zip215:u}=s,c=v.signature;t=bn(t,c,"signature"),r=bn(r,void 0,"message"),i=bn(i,v.publicKey,"publicKey"),void 0!==u&&vo(u,"zip215"),n&&(r=n(r));const l=c/2,f=t.subarray(0,l),h=wo(t.subarray(l,c));let g,p,y;try{g=e.fromBytes(i,u),p=e.fromBytes(f,u),y=o.multiplyUnsafe(h)}catch(e){return!1}if(!u&&g.isSmallOrder())return!1;const b=d(a,p.toBytes(),g.toBytes(),r);return p.add(g.multiplyUnsafe(b)).subtract(y).clearCofactor().is0()},utils:y,Point:e,lengths:v})}(Ci,ho,Object.assign({adjustScalarBytes:xi},e))}const Fi=/* @__PURE__ */Oi({});class Di extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}}class ji extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}}var Ii={get(e=globalThis){const t=e.crypto;if(null==t?.subtle)throw new ji("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};let Li;const Ni=(async()=>{try{return await Ii.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Ui(e){return null!=e&&"function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally}class Ri{type="Ed25519";raw;constructor(e){this.raw=Mi(e,32)}toMultihash(){return Pr(ia(this))}toCID(){return mr.createV1(114,this.toMultihash())}toString(){return jt.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&wr(this.raw,e.raw)}verify(e,t,r){r?.signal?.throwIfAborted();const n=async function(e,t,r){return null==Li&&(Li=await Ni),Li?async function(e,t,r){if(e.buffer instanceof ArrayBuffer){const n=await Ii.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ii.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}(e,t,r):function(e,t,r){return Fi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}(e,t,r)}(this.raw,t,e);return Ui(n)?n.then(e=>(r?.signal?.throwIfAborted(),e)):n}}function Mi(e,t){if((e=Uint8Array.from(e??[])).length!==t)throw new mt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}const _i=Math.pow(2,7),Bi=Math.pow(2,14),Gi=Math.pow(2,21),qi=Math.pow(2,28),Vi=Math.pow(2,35),zi=Math.pow(2,42),Hi=Math.pow(2,49),Ki=128,$i=127;function Zi(e){if(e<_i)return 1;if(e<Bi)return 2;if(e<Gi)return 3;if(e<qi)return 4;if(e<Vi)return 5;if(e<zi)return 6;if(e<Hi)return 7;if(null!=Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ji(e,t,r=0){switch(Zi(e)){case 8:t[r++]=255&e|Ki,e/=128;case 7:t[r++]=255&e|Ki,e/=128;case 6:t[r++]=255&e|Ki,e/=128;case 5:t[r++]=255&e|Ki,e/=128;case 4:t[r++]=255&e|Ki,e>>>=7;case 3:t[r++]=255&e|Ki,e>>>=7;case 2:t[r++]=255&e|Ki,e>>>=7;case 1:t[r++]=255&e,e>>>=7;break;default:throw new Error("unreachable")}return t}function Wi(e,t){let r=e[t],n=0;if(n+=r&$i,r<Ki)return n;if(r=e[t+1],n+=(r&$i)<<7,r<Ki)return n;if(r=e[t+2],n+=(r&$i)<<14,r<Ki)return n;if(r=e[t+3],n+=(r&$i)<<21,r<Ki)return n;if(r=e[t+4],n+=(r&$i)*qi,r<Ki)return n;if(r=e[t+5],n+=(r&$i)*Vi,r<Ki)return n;if(r=e[t+6],n+=(r&$i)*zi,r<Ki)return n;if(r=e[t+7],n+=(r&$i)*Hi,r<Ki)return n;throw new RangeError("Could not decode varint")}function Yi(e,t,r=0){return null==t&&(t=Sr(Zi(e))),t instanceof Uint8Array?Ji(e,t,r):function(e,t,r=0){switch(Zi(e)){case 8:t.set(r++,255&e|Ki),e/=128;case 7:t.set(r++,255&e|Ki),e/=128;case 6:t.set(r++,255&e|Ki),e/=128;case 5:t.set(r++,255&e|Ki),e/=128;case 4:t.set(r++,255&e|Ki),e>>>=7;case 3:t.set(r++,255&e|Ki),e>>>=7;case 2:t.set(r++,255&e|Ki),e>>>=7;case 1:t.set(r++,255&e),e>>>=7;break;default:throw new Error("unreachable")}return t}(e,t,r)}function Xi(e,t=0){return e instanceof Uint8Array?Wi(e,t):function(e,t){let r=e.get(t),n=0;if(n+=r&$i,r<Ki)return n;if(r=e.get(t+1),n+=(r&$i)<<7,r<Ki)return n;if(r=e.get(t+2),n+=(r&$i)<<14,r<Ki)return n;if(r=e.get(t+3),n+=(r&$i)<<21,r<Ki)return n;if(r=e.get(t+4),n+=(r&$i)*qi,r<Ki)return n;if(r=e.get(t+5),n+=(r&$i)*Vi,r<Ki)return n;if(r=e.get(t+6),n+=(r&$i)*zi,r<Ki)return n;if(r=e.get(t+7),n+=(r&$i)*Hi,r<Ki)return n;throw new RangeError("Could not decode varint")}(e,t)}const Qi=new Float32Array([-0]),es=new Uint8Array(Qi.buffer);function ts(e,t,r){Qi[0]=e,t[r]=es[0],t[r+1]=es[1],t[r+2]=es[2],t[r+3]=es[3]}const rs=new Float64Array([-0]),ns=new Uint8Array(rs.buffer);function os(e,t,r){rs[0]=e,t[r]=ns[0],t[r+1]=ns[1],t[r+2]=ns[2],t[r+3]=ns[3],t[r+4]=ns[4],t[r+5]=ns[5],t[r+6]=ns[6],t[r+7]=ns[7]}const is=BigInt(Number.MAX_SAFE_INTEGER),ss=BigInt(Number.MIN_SAFE_INTEGER);class as{lo;hi;constructor(e,t){this.lo=0|e,this.hi=0|t}toNumber(e=!1){if(!e&&this.hi>>>31>0){const e=1+~this.lo>>>0;let t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(e+4294967296*t)}return this.lo+4294967296*this.hi}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31!=0){const e=1+~this.lo>>>0;let t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(BigInt(e)+(BigInt(t)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){const e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){const e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){const e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 0===r?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}static fromBigInt(e){if(0n===e)return us;if(e<is&&e>ss)return this.fromNumber(Number(e));const t=e<0n;t&&(e=-e);let r=e>>32n,n=e-(r<<32n);return t&&(r=0n|~r,n=0n|~n,++n>cs&&(n=0n,++r>cs&&(r=0n))),new as(Number(n),Number(r))}static fromNumber(e){if(0===e)return us;const t=e<0;t&&(e=-e);let r=e>>>0,n=(e-r)/4294967296>>>0;return t&&(n=~n>>>0,r=~r>>>0,++r>4294967295&&(r=0,++n>4294967295&&(n=0))),new as(r,n)}static from(e){return"number"==typeof e?as.fromNumber(e):"bigint"==typeof e?as.fromBigInt(e):"string"==typeof e?as.fromBigInt(BigInt(e)):null!=e.low||null!=e.high?new as(e.low>>>0,e.high>>>0):us}}const us=new as(0,0);us.toBigInt=function(){return 0n},us.zzEncode=us.zzDecode=function(){return this},us.length=function(){return 1};const cs=4294967296n;function ls(e,t,r){const n=r;let o,i;for(let n=0;n<e.length;++n)o=e.charCodeAt(n),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=63&o|128):55296==(64512&o)&&56320==(64512&(i=e.charCodeAt(n+1)))?(o=65536+((1023&o)<<10)+(1023&i),++n,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=63&o|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=63&o|128);return r-n}function fs(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function hs(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}class ds{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return e;if((this.pos+=5)>this.len)throw this.pos=this.len,fs(this,10);return e}int32(){return 0|this.uint32()}sint32(){const e=this.uint32();return e>>>1^-(1&e)}bool(){return 0!==this.uint32()}fixed32(){if(this.pos+4>this.len)throw fs(this,4);return hs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw fs(this,4);return 0|hs(this.buf,this.pos+=4)}float(){if(this.pos+4>this.len)throw fs(this,4);const e=(es[0]=(t=this.buf)[r=this.pos],es[1]=t[r+1],es[2]=t[r+2],es[3]=t[r+3],Qi[0]);var t,r;return this.pos+=4,e}double(){if(this.pos+8>this.len)throw fs(this,4);const e=(ns[0]=(t=this.buf)[r=this.pos],ns[1]=t[r+1],ns[2]=t[r+2],ns[3]=t[r+3],ns[4]=t[r+4],ns[5]=t[r+5],ns[6]=t[r+6],ns[7]=t[r+7],rs[0]);var t,r;return this.pos+=8,e}bytes(){const e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw fs(this,e);return this.pos+=e,t===r?new Uint8Array(0):this.buf.subarray(t,r)}string(){const e=this.bytes();return function(e,t,r){if(r-t<1)return"";let n;const o=[];let i,s=0;for(;t<r;)i=e[t++],i<128?o[s++]=i:i>191&&i<224?o[s++]=(31&i)<<6|63&e[t++]:i>239&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,o[s++]=55296+(i>>10),o[s++]=56320+(1023&i)):o[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],s>8191&&((n??(n=[])).push(String.fromCharCode.apply(String,o)),s=0);return null!=n?(s>0&&n.push(String.fromCharCode.apply(String,o.slice(0,s))),n.join("")):String.fromCharCode.apply(String,o.slice(0,s))}(e,0,e.length)}skip(e){if("number"==typeof e){if(this.pos+e>this.len)throw fs(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw fs(this)}while(128&this.buf[this.pos++]);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){const e=new as(0,0);let t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw fs(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw fs(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw fs(this,8);const e=hs(this.buf,this.pos+=4),t=hs(this.buf,this.pos+=4);return new as(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){const e=Wi(this.buf,this.pos);return this.pos+=Zi(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}}function ms(e){return new ds(e instanceof Uint8Array?e:e.subarray())}function gs(e,t,r){const n=ms(e);return t.decode(n,void 0,r)}class vs{fn;len;next;val;constructor(e,t,r){this.fn=e,this.len=t,this.next=void 0,this.val=r}}function ps(){}class ys{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}}const bs=function(){const e=8192;let t,r=e;return function(n){if(n<1||n>4096)return Sr(n);r+n>e&&(t=Sr(e),r=0);const o=t.subarray(r,r+=n);return 7&r&&(r=1+(7|r)),o}}();class Ps{len;head;tail;states;constructor(){this.len=0,this.head=new vs(ps,0,0),this.tail=this.head,this.states=null}_push(e,t,r){return this.tail=this.tail.next=new vs(e,t,r),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ss((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(As,10,as.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){const t=as.fromBigInt(e);return this._push(As,t.length(),t)}uint64Number(e){return this._push(Ji,Zi(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){const t=as.fromBigInt(e).zzEncode();return this._push(As,t.length(),t)}sint64Number(e){const t=as.fromNumber(e).zzEncode();return this._push(As,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ws,1,e?1:0)}fixed32(e){return this._push(Ts,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){const t=as.fromBigInt(e);return this._push(Ts,4,t.lo)._push(Ts,4,t.hi)}fixed64Number(e){const t=as.fromNumber(e);return this._push(Ts,4,t.lo)._push(Ts,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(ts,4,e)}double(e){return this._push(os,8,e)}bytes(e){const t=e.length>>>0;return 0===t?this._push(ws,1,0):this.uint32(t)._push(xs,t,e)}string(e){const t=function(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(n+1))?(++n,t+=4):t+=3;return t}(e);return 0!==t?this.uint32(t)._push(ls,t,e):this._push(ws,1,0)}fork(){return this.states=new ys(this),this.head=this.tail=new vs(ps,0,0),this.len=0,this}reset(){return null!=this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new vs(ps,0,0),this.len=0),this}ldelim(){const e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),0!==r&&(this.tail.next=e.next,this.tail=t,this.len+=r),this}finish(){let e=this.head.next;const t=(r=this.len,null!=globalThis.Buffer?Sr(r):bs(r));var r;let n=0;for(;null!=e;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}}function ws(e,t,r){t[r]=255&e}function Es(e,t,r){for(;e>127;)t[r++]=127&e|128,e>>>=7;t[r]=e}class Ss extends vs{next;constructor(e,t){super(Es,e,t),this.next=void 0}}function As(e,t,r){for(;0!==e.hi;)t[r++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=127&e.lo|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ts(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function xs(e,t,r){t.set(e,r)}function ks(e,t,r){t.set(e,r)}function Cs(e,t,r){e.length<40?ls(e,t,r):null!=t.utf8Write?t.utf8Write(e,r):t.set(Jr(e),r)}function Os(e,t){const r=new Ps;return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Fs(e,t,r){const n=ms(e);yield*t.stream(n,void 0,"$",r)}function Ds(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function js(e,t,r){return Ds("message",2,e,t,r)}var Is,Ls,Ns,Us;null!=globalThis.Buffer&&(Ps.prototype.bytes=function(e){const t=e.length>>>0;return this.uint32(t),t>0&&this._push(ks,t,e),this},Ps.prototype.string=function(e){const t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Cs,t,e),this}),function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"}(Is||(Is={})),function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"}(Ls||(Ls={})),function(e){e.codec=()=>function(e){function t(t){if(null==e[t.toString()])throw new Error("Invalid enum value");return e[t]}return Ds("enum",0,function(e,r){const n=t(e);r.int32(n)},function(e){return t(e.int32())},function*(e){const r=e.int32();yield t(r)})}(Ls)}(Is||(Is={})),function(e){let t;e.codec=()=>(null==t&&(t=js((e,t,r={})=>{!1!==r.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),Is.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==r.lengthDelimited&&t.ldelim()},(e,t,r={})=>{const n={},o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:n.Type=Is.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&t)}}return n},function*(e,t,r,n={}){const o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:yield{field:`${r}.Type`,value:Is.codec().decode(e)};break;case 2:yield{field:`${r}.Data`,value:e.bytes()};break;default:e.skipType(7&t)}}})),t),e.encode=function(t){return Os(t,e.codec())},e.decode=function(t,r){return gs(t,e.codec(),r)},e.stream=function(t,r){return Fs(t,e.codec(),r)}}(Ns||(Ns={})),function(e){let t;e.codec=()=>(null==t&&(t=js((e,t,r={})=>{!1!==r.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),Is.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==r.lengthDelimited&&t.ldelim()},(e,t,r={})=>{const n={},o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:n.Type=Is.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&t)}}return n},function*(e,t,r,n={}){const o=null==t?e.len:e.pos+t;for(;e.pos<o;){const t=e.uint32();switch(t>>>3){case 1:yield{field:`${r}.Type`,value:Is.codec().decode(e)};break;case 2:yield{field:`${r}.Data`,value:e.bytes()};break;default:e.skipType(7&t)}}})),t),e.encode=function(t){return Os(t,e.codec())},e.decode=function(t,r){return gs(t,e.codec(),r)},e.stream=function(t,r){return Fs(t,e.codec(),r)}}(Us||(Us={}));class Rs{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Pn(e),bn(t,void 0,"key"),this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,n=new Uint8Array(r);n.set(t.length>r?e.create().update(t).digest():t);for(let e=0;e<n.length;e++)n[e]^=54;this.iHash.update(n),this.oHash=e.create();for(let e=0;e<n.length;e++)n[e]^=106;this.oHash.update(n),En(n)}update(e){return wn(this),this.iHash.update(e),this}digestInto(e){wn(this),bn(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});const{oHash:t,iHash:r,finished:n,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=n,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ms=(e,t,r)=>new Rs(e,t).update(r).digest();Ms.create=(e,t)=>new Rs(e,t);const _s=(e,t)=>(e+(e>=0?t:-t)/Ks)/t;function Bs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Gs(e,t){const r={};for(let n of Object.keys(t))r[n]=void 0===e[n]?t[n]:e[n];return vo(r.lowS,"lowS"),vo(r.prehash,"prehash"),void 0!==r.format&&Bs(r.format),r}class qs extends Error{constructor(e=""){super(e)}}const Vs={Err:qs,_tlv:{encode:(e,t)=>{const{Err:r}=Vs;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(1&t.length)throw new r("tlv.encode: unpadded data");const n=t.length/2,o=yo(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");const i=n>127?yo(o.length/2|128):"";return yo(e)+i+o+t},decode(e,t){const{Err:r}=Vs;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const o=t[n++];let i=0;if(128&o){const e=127&o;if(!e)throw new r("tlv.decode(long): indefinite length not supported");if(e>4)throw new r("tlv.decode(long): byte length is too big");const s=t.subarray(n,n+e);if(s.length!==e)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(n+=e,i<128)throw new r("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(n,n+i);if(s.length!==i)throw new r("tlv.decode: wrong value length");return{v:s,l:t.subarray(n+i)}}},_int:{encode(e){const{Err:t}=Vs;if(e<zs)throw new t("integer: negative integers are not allowed");let r=yo(e);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=Vs;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return Po(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=Vs,o=bn(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=n.decode(2,i),{v:c,l:l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){const{_tlv:t,_int:r}=Vs,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s));return t.encode(48,n+o)}},zs=BigInt(0),Hs=BigInt(1),Ks=BigInt(2),$s=BigInt(3),Zs=BigInt(4);function Js(e,t={}){const r=di("weierstrass",e,t),{Fp:n,Fn:o}=r;let i=r.CURVE;const{h:s,n:a}=i;Co(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:u}=t;if(u&&(!n.is0(i.a)||"bigint"!=typeof u.beta||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const c=Ys(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,r){const{x:o,y:i}=t.toAffine(),s=n.toBytes(o);return vo(r,"isCompressed"),r?(l(),Fn(Ws(!n.isOdd(i)),s)):Fn(Uint8Array.of(4),s,n.toBytes(i))},h=t.fromBytes||function(e){bn(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:r}=c,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===r&&4===i){const e=n.BYTES,t=n.fromBytes(s.subarray(0,e)),r=n.fromBytes(s.subarray(e,2*e));if(!m(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${r}`)}{const e=n.fromBytes(s);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let r;try{r=n.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}};function d(e){const t=n.sqr(e),r=n.mul(t,e);return n.add(n.add(r,n.mul(e,i.a)),i.b)}function m(e,t){const r=n.sqr(t),o=d(e);return n.eql(r,o)}if(!m(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=n.mul(n.pow(i.a,$s),Zs),v=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(g,v)))throw new Error("bad curve params: a or b");function p(e,t,r=!1){if(!n.isValid(t)||r&&n.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function y(e){if(!(e instanceof S))throw new Error("Weierstrass Point expected")}function b(e){if(!u||!u.basises)throw new Error("no endo");return function(e,t,r){const[[n,o],[i,s]]=t,a=_s(s*e,r),u=_s(-o*e,r);let c=e-a*n-u*i,l=-a*o-u*s;const f=c<zs,h=l<zs;f&&(c=-c),h&&(l=-l);const d=ko(Math.ceil(function(e){let t;for(t=0;e>mo;e>>=go,t+=1);return t}(r)/2))+Hs;if(c<zs||c>=d||l<zs||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:c,k2neg:h,k2:l}}(e,u.basises,o.ORDER)}const P=Oo((e,t)=>{const{X:r,Y:o,Z:i}=e;if(n.eql(i,n.ONE))return{x:r,y:o};const s=e.is0();null==t&&(t=s?n.ONE:n.inv(i));const a=n.mul(r,t),u=n.mul(o,t),c=n.mul(i,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),w=Oo(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:o}=e.toAffine();if(!n.isValid(r)||!n.isValid(o))throw new Error("bad point: x or y not field elements");if(!m(r,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(e,t,r,o,i){return r=new S(n.mul(r.X,e),r.Y,r.Z),t=ri(o,t),r=ri(i,r),t.add(r)}class S{static BASE=new S(i.Gx,i.Gy,n.ONE);static ZERO=new S(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(e,t,r){this.X=p("x",e),this.Y=p("y",t,!0),this.Z=p("z",r),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof S)throw new Error("projective point not allowed");return n.is0(t)&&n.is0(r)?S.ZERO:new S(t,r,n.ONE)}static fromBytes(e){const t=S.fromAffine(h(bn(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return S.fromBytes(On(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply($s),this}assertValidity(){w(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){y(e);const{X:t,Y:r,Z:o}=this,{X:i,Y:s,Z:a}=e,u=n.eql(n.mul(t,a),n.mul(i,o)),c=n.eql(n.mul(r,a),n.mul(s,o));return u&&c}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,r=n.mul(t,$s),{X:o,Y:s,Z:a}=this;let u=n.ZERO,c=n.ZERO,l=n.ZERO,f=n.mul(o,o),h=n.mul(s,s),d=n.mul(a,a),m=n.mul(o,s);return m=n.add(m,m),l=n.mul(o,a),l=n.add(l,l),u=n.mul(e,l),c=n.mul(r,d),c=n.add(u,c),u=n.sub(h,c),c=n.add(h,c),c=n.mul(u,c),u=n.mul(m,u),l=n.mul(r,l),d=n.mul(e,d),m=n.sub(f,d),m=n.mul(e,m),m=n.add(m,l),l=n.add(f,f),f=n.add(l,f),f=n.add(f,d),f=n.mul(f,m),c=n.add(c,f),d=n.mul(s,a),d=n.add(d,d),f=n.mul(d,m),u=n.sub(u,f),l=n.mul(d,h),l=n.add(l,l),l=n.add(l,l),new S(u,c,l)}add(e){y(e);const{X:t,Y:r,Z:o}=this,{X:s,Y:a,Z:u}=e;let c=n.ZERO,l=n.ZERO,f=n.ZERO;const h=i.a,d=n.mul(i.b,$s);let m=n.mul(t,s),g=n.mul(r,a),v=n.mul(o,u),p=n.add(t,r),b=n.add(s,a);p=n.mul(p,b),b=n.add(m,g),p=n.sub(p,b),b=n.add(t,o);let P=n.add(s,u);return b=n.mul(b,P),P=n.add(m,v),b=n.sub(b,P),P=n.add(r,o),c=n.add(a,u),P=n.mul(P,c),c=n.add(g,v),P=n.sub(P,c),f=n.mul(h,b),c=n.mul(d,v),f=n.add(c,f),c=n.sub(g,f),f=n.add(g,f),l=n.mul(c,f),g=n.add(m,m),g=n.add(g,m),v=n.mul(h,v),b=n.mul(d,b),g=n.add(g,v),v=n.sub(m,v),v=n.mul(h,v),b=n.add(b,v),m=n.mul(g,b),l=n.add(l,m),m=n.mul(P,b),c=n.mul(p,c),c=n.sub(c,m),m=n.mul(p,g),f=n.mul(P,f),f=n.add(f,m),new S(c,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(S.ZERO)}multiply(e){const{endo:r}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let n,i;const s=e=>T.cached(this,e,e=>ni(S,e));if(r){const{k1neg:t,k1:o,k2neg:a,k2:u}=b(e),{p:c,f:l}=s(o),{p:f,f:h}=s(u);i=l.add(h),n=E(r.beta,c,f,t,a)}else{const{p:t,f:r}=s(e);n=t,i=r}return ni(S,[n,i])[0]}multiplyUnsafe(e){const{endo:r}=t,n=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===zs||n.is0())return S.ZERO;if(e===Hs)return n;if(T.hasCache(this))return this.multiply(e);if(r){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:u}=function(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>ei||n>ei;)r&ti&&(i=i.add(o)),n&ti&&(s=s.add(o)),o=o.double(),r>>=ti,n>>=ti;return{p1:i,p2:s}}(S,n,o,s);return E(r.beta,a,u,t,i)}return T.unsafe(n,e)}toAffine(e){return P(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===Hs||(e?e(S,this):T.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===Hs?this:e?e(S,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return vo(e,"isCompressed"),this.assertValidity(),f(S,this,e)}toHex(e=!0){return kn(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const A=o.BITS,T=new fi(S,t.endo?Math.ceil(A/2):A);return S.BASE.precompute(8),S}function Ws(e){return Uint8Array.of(e?2:3)}function Ys(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Xs(e,t,r={}){Pn(t),Co(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const n=(r=Object.assign({},r)).randomBytes||jn,o=r.hmac||((e,r)=>Ms(t,e,r)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:u}=s,{keygen:c,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:r}=e,n=t.randomBytes||jn,o=Object.assign(Ys(e.Fp,r),{seed:Qo(r.ORDER)});function i(e=n(o.seed)){return function(e,t,r=!1){bn(e);const n=e.length,o=Xo(t),i=Qo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);const s=Bo(r?wo(e):Po(e),t-Do)+Do;return r?So(s,o):Eo(s,o)}(bn(e,o.seed,"seed"),r.ORDER)}function s(t,n=!0){return e.BASE.multiply(r.fromBytes(t)).toBytes(n)}function a(e){const{secretKey:t,publicKey:n,publicKeyUncompressed:i}=o;if(!pn(e))return;if("_lengths"in r&&r._lengths||t===n)return;const s=bn(e,void 0,"key").length;return s===n||s===i}const u={isValidSecretKey:function(e){try{const t=r.fromBytes(e);return r.isValidNot0(t)}catch(e){return!1}},isValidPublicKey:function(t,r){const{publicKey:n,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===r&&o!==n||!1===r&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:i},c=mi(i,s);return Object.freeze({getPublicKey:s,getSharedSecret:function(t,n,o=!0){if(!0===a(t))throw new Error("first arg must be private key");if(!1===a(n))throw new Error("second arg must be public key");const i=r.fromBytes(t);return e.fromBytes(n).multiply(i).toBytes(o)},keygen:c,Point:e,utils:u,lengths:o})}(e,r),m={prehash:!0,lowS:"boolean"!=typeof r.lowS||r.lowS,format:"compact",extraEntropy:!1},g=a*Ks<i.ORDER;function v(e){return e>a>>Hs}function p(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function y(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(e,t){Bs(t);const r=d.signature;return bn(e,"compact"===t?r:"recovered"===t?r+1:void 0)}class P{r;s;recovery;constructor(e,t,r){if(this.r=p("r",e),this.s=p("s",t),null!=r){if(y(),![0,1,2,3].includes(r))throw new Error("invalid recovery id");this.recovery=r}Object.freeze(this)}static fromBytes(e,t=m.format){let r;if(b(e,t),"der"===t){const{r:t,s:r}=Vs.toSig(bn(e));return new P(t,r)}"recovered"===t&&(r=e[0],t="compact",e=e.subarray(1));const n=d.signature/2,o=e.subarray(0,n),i=e.subarray(n,2*n);return new P(s.fromBytes(o),s.fromBytes(i),r)}static fromHex(e,t){return this.fromBytes(On(e),t)}assertRecovery(){const{recovery:e}=this;if(null==e)throw new Error("invalid recovery id: must be present");return e}addRecoveryBit(e){return new P(this.r,this.s,e)}recoverPublicKey(t){const{r:r,s:n}=this,o=this.assertRecovery(),u=2===o||3===o?r+a:r;if(!i.isValid(u))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const c=i.toBytes(u),l=e.fromBytes(Fn(Ws(!(1&o)),c)),f=s.inv(u),h=E(bn(t,void 0,"msgHash")),d=s.create(-h*f),m=s.create(n*f),g=e.BASE.multiplyUnsafe(d).add(l.multiplyUnsafe(m));if(g.is0())throw new Error("invalid recovery: point at infinify");return g.assertValidity(),g}hasHighS(){return v(this.s)}toBytes(e=m.format){if(Bs(e),"der"===e)return On(Vs.hexFromSig(this));const{r:t,s:r}=this,n=s.toBytes(t),o=s.toBytes(r);return"recovered"===e?(y(),Fn(Uint8Array.of(this.assertRecovery()),n,o)):Fn(n,o)}toHex(e){return kn(this.toBytes(e))}}const w=r.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=Po(e),r=8*e.length-u;return r>0?t>>BigInt(r):t},E=r.bits2int_modN||function(e){return s.create(w(e))},S=ko(u);function A(e){return xo("num < 2^"+u,e,zs,S),s.toBytes(e)}function T(e,r){return bn(e,void 0,"message"),r?bn(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:c,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(r,i,a={}){const{seed:u,k2sig:c}=function(t,r,o){const{lowS:i,prehash:a,extraEntropy:u}=Gs(o,m);t=T(t,a);const c=E(t),l=s.fromBytes(r);if(!s.isValidNot0(l))throw new Error("invalid private key");const f=[A(l),A(c)];if(null!=u&&!1!==u){const e=!0===u?n(d.secretKey):u;f.push(bn(e,void 0,"extraEntropy"))}const h=Fn(...f),p=c;return{seed:h,k2sig:function(t){const r=w(t);if(!s.isValidNot0(r))return;const n=s.inv(r),o=e.BASE.multiply(r).toAffine(),a=s.create(o.x);if(a===zs)return;const u=s.create(n*s.create(p+a*l));if(u===zs)return;let c=(o.x===a?0:2)|Number(o.y&Hs),f=u;return i&&v(u)&&(f=s.neg(u),c^=1),new P(a,f,g?void 0:c)}}}(r,i,a);return function(e,t,r){if(yn(e,"hashLen"),yn(t,"qByteLen"),"function"!=typeof r)throw new Error("hmacFn must be a function");const n=e=>new Uint8Array(e),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1);let a=n(e),u=n(e),c=0;const l=()=>{a.fill(1),u.fill(0),c=0},f=(...e)=>r(u,Fn(a,...e)),h=(e=o)=>{u=f(i,e),a=f(),0!==e.length&&(u=f(s,e),a=f())},d=()=>{if(c++>=1e3)throw new Error("drbg: tried max amount of iterations");let e=0;const r=[];for(;e<t;){a=f();const t=a.slice();r.push(t),e+=a.length}return Fn(...r)};return(e,t)=>{let r;for(l(),h(e);!(r=t(d()));)h();return l(),r}}(t.outputLen,s.BYTES,o)(u,c).toBytes(a.format)},verify:function(t,r,n,o={}){const{lowS:i,prehash:a,format:u}=Gs(o,m);if(n=bn(n,void 0,"publicKey"),r=T(r,a),!pn(t))throw new Error("verify expects Uint8Array signature"+(t instanceof P?", use sig.toBytes()":""));b(t,u);try{const o=P.fromBytes(t,u),a=e.fromBytes(n);if(i&&o.hasHighS())return!1;const{r:c,s:l}=o,f=E(r),h=s.inv(l),d=s.create(f*h),m=s.create(c*h),g=e.BASE.multiplyUnsafe(d).add(a.multiplyUnsafe(m));return!g.is0()&&s.create(g.x)===c}catch(e){return!1}},recoverPublicKey:function(e,t,r={}){const{prehash:n}=Gs(r,m);return t=T(t,n),P.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:P,hash:t})}const Qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ea={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},ta=/* @__PURE__ */BigInt(2),ra=Yo(Qs.p,{sqrt:function(e){const t=Qs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,l=c*c*e%t,f=Go(l,r,t)*l%t,h=Go(f,r,t)*l%t,d=Go(h,ta,t)*c%t,m=Go(d,o,t)*d%t,g=Go(m,i,t)*m%t,v=Go(g,a,t)*g%t,p=Go(v,u,t)*v%t,y=Go(p,a,t)*g%t,b=Go(y,r,t)*l%t,P=Go(b,s,t)*m%t,w=Go(P,n,t)*c%t,E=Go(w,ta,t);if(!ra.eql(ra.sqr(E),e))throw new Error("Cannot find square root");return E}}),na=/* @__PURE__ */Xs(/* @__PURE__ */Js(Qs,{Fp:ra,endo:ea}),fo);class oa{type="secp256k1";raw;_key;constructor(e){this._key=function(e){try{return na.Point.fromBytes(e),e}catch(e){throw new gt(String(e))}}(e),this.raw=function(e){return na.Point.fromBytes(e).toBytes()}(this._key)}toMultihash(){return Pr(ia(this))}toCID(){return mr.createV1(114,this.toMultihash())}toString(){return jt.encode(this.toMultihash().bytes).substring(1)}equals(e){return null!=e&&e.raw instanceof Uint8Array&&wr(this.raw,e.raw)}verify(e,t,r){return function(e,t,r,n){const o=Vr.digest(r instanceof Uint8Array?r:r.subarray());if(Ui(o))return o.then(({digest:r})=>(n?.signal?.throwIfAborted(),na.verify(t,r,e,{prehash:!1,format:"der"}))).catch(e=>{if("AbortError"===e.name)throw e;throw new Di(String(e))});try{return n?.signal?.throwIfAborted(),na.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(e){throw new Di(String(e))}}(this._key,t,e,r)}}function ia(e){return Ns.encode({Type:Is[e.type],Data:e.raw})}const sa=Symbol.for("nodejs.util.inspect.custom");class aa{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wt]=!0;toString(){return null==this.string&&(this.string=jt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return mr.createV1(114,this.multihash)}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return wr(this.multihash.bytes,e);if("string"==typeof e)return this.toString()===e;if(null!=e?.toMultihash()?.bytes)return wr(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[sa](){return`PeerId(${this.toString()})`}}class ua extends aa{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class ca extends aa{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}}class la extends aa{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}}class fa{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Pr(Jr(this.url))}[sa](){return`PeerId(${this.url})`}[wt]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return mr.createV1(2336,this.toMultihash())}toJSON(){return this.toString()}equals(e){return null!=e&&(e instanceof Uint8Array&&(e=Wr(e)),e.toString()===this.toString())}}function ha(e,t){let r;if("1"===e.charAt(0)||"Q"===e.charAt(0))r=cr(jt.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return function(e){if(null==e?.multihash||null==e.version||1===e.version&&114!==e.code&&2336!==e.code)throw new vt("Supplied PeerID CID is invalid");if(2336===e.code){const t=Wr(e.multihash.digest);return new fa(new URL(t))}return da(e.multihash)}(mr.parse(e));if(null==t)throw new mt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=cr(t.decode(e))}return da(r)}function da(e){if(function(e){return e.code===Vr.code}(e))return new ua({multihash:e});if(function(e){return 0===e.code}(e))try{const t=function(e){const{Type:t,Data:r}=Ns.decode(e.digest),n=r??new Uint8Array;switch(t){case Is.Ed25519:return o=Mi(o=n,32),new Ri(o);case Is.secp256k1:return function(e){return new oa(e)}(n);case Is.ECDSA:return function(e){return function(e){const t=e[1][1][0];let r,n;if(65===t.byteLength)return r=Wr(t.subarray(1,33),"base64url"),n=Wr(t.subarray(33),"base64url"),new vn({...hn,key_ops:["verify"],x:r,y:n});if(97===t.byteLength)return r=Wr(t.subarray(1,49),"base64url"),n=Wr(t.subarray(49),"base64url"),new vn({...dn,key_ops:["verify"],x:r,y:n});if(133===t.byteLength)return r=Wr(t.subarray(1,67),"base64url"),n=Wr(t.subarray(67),"base64url"),new vn({...mn,key_ops:["verify"],x:r,y:n});throw new mt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}(tn(e))}(n);default:throw new Pt}var o}(e);if("Ed25519"===t.type)return new ca({multihash:e,publicKey:t});if("secp256k1"===t.type)return new la({multihash:e,publicKey:t})}catch(t){const r=Wr(e.digest);return new fa(new URL(r))}throw new pt("Supplied PeerID Multihash is invalid")}function ma(e,t){var r=A.PublicKey.fromHex(function(e){if("string"==typeof e)return e.startsWith("0x")?e:"0x"+e;var t=e instanceof Uint8Array?e:Array.isArray(e)?Uint8Array.from(e):Uint8Array.from(Object.keys(e).sort(function(e,t){return Number(e)-Number(t)}).map(function(t){return e[Number(t)]}));return"0x"+Buffer.from(t).toString("hex")}(e)),n=A.encrypt(r.toHex(),Buffer.from(t));return Buffer.from(n).toString("hex")}function ga(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var va=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getConsumerAddress=function(e){return Ga(e)},t.getSignature=function(e,t,r){return Ba(e,t,r)},t.getAuthorization=function(e){return qa(e)},t.getEndpoints=function(e,t){try{var r=this;return Promise.resolve(ga(function(){return Promise.resolve(r.getData(e,t)).then(function(e){return Promise.resolve(e.json())})},function(e){throw we.error("Finding the service endpoints failed:",e),new Error("HTTP request failed calling Provider")}))}catch(e){return Promise.reject(e)}},t.getNodePublicKey=function(e){try{return Promise.resolve(this.getEndpoints(e)).then(function(e){return e.nodePublicKey})}catch(e){return Promise.reject(e)}},t.getEndpointURL=function(e,t){return e?e.find(function(e){return e.serviceName.toLowerCase()===t.toLowerCase()}):null},t.getServiceEndpoints=function(e,t){try{var r=[];for(var n in t.serviceEndpoints){var o={serviceName:n,method:t.serviceEndpoints[n][0],urlPath:e.replace(/\/+$/,"")+"/"+t.serviceEndpoints[n][1].replace(/^\/+/,"")};r.push(o)}return Promise.resolve(r)}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r,n,o){try{var i=function(){function i(){var e=s.getEndpointURL(o,"nonce")?s.getEndpointURL(o,"nonce").urlPath:null;return e?ga(function(){return Promise.resolve(oe.default(e+"?userAddress="+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return Promise.resolve(e.json()).then(function(e){var t=e.nonce;return t&&null!==t?Number(t):0})})},function(e){throw we.error(e),new Error(e.message)}):null}var a=function(){if(!o)return Promise.resolve(s.getServiceEndpoints(e,n)).then(function(e){o=e})}();return a&&a.then?a.then(i):i()},s=this,a=function(){if(!n)return Promise.resolve(s.getEndpoints(e)).then(function(e){n=e})}();return Promise.resolve(a&&a.then?a.then(i):i())}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(r)).then(function(o){return Promise.resolve(s.getServiceEndpoints(r,o)).then(function(a){return Promise.resolve(s.getConsumerAddress(n)).then(function(u){return Promise.resolve(s.getNonce(r,u,i,o,a)).then(function(r){var o=(r+1).toString();return Promise.resolve(s.getSignature(n,o,ue.ENCRYPT)).then(function(r){var n=(s.getEndpointURL(a,"encrypt")?s.getEndpointURL(a,"encrypt").urlPath:null)+"?chainId="+t;return n?(n+="&nonce="+o,n+="&consumerAddress="+u,n+="&signature="+r,ga(function(){return Promise.resolve(oe.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/octet-stream"},signal:i})).then(function(e){return Promise.resolve(e.text())})},function(e){throw we.error(e),new Error("HTTP request failed calling Provider")})):null})})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{var i=this;return Promise.resolve(i.getEndpoints(r)).then(function(s){return Promise.resolve(i.getServiceEndpoints(r,s)).then(function(r){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw we.error("File info call failed: ",a.status,a.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){for(var r,n=de(e);!(r=n()).done;)c.push(r.value);return t=1,c})}();return n&&n.then?n.then(r):r(n)}var a,u={did:e,serviceId:t,checksum:n},c=[],l=i.getEndpointURL(r,"fileinfo")?i.getEndpointURL(r,"fileinfo").urlPath:null;if(!l)return null;var f=ga(function(){return Promise.resolve(oe.default(l,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o})).then(function(e){a=e})},function(e){throw we.error("File info call failed: "),we.error(e),new Error(e)});return f&&f.then?f.then(s):s()})})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{var o=this;return Promise.resolve(o.getEndpoints(t)).then(function(i){return Promise.resolve(o.getServiceEndpoints(t,i)).then(function(t){function i(e){var t;function r(e){return t?e:Promise.resolve(s.json()).then(function(e){throw we.error("File info call failed: ",s.status,s.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=s)&&e.ok)return Promise.resolve(s.json()).then(function(e){for(var r,n=de(e);!(r=n()).done;)u.push(r.value);return t=1,u})}();return n&&n.then?n.then(r):r(n)}var s,a=me({},e,{checksum:r}),u=[],c=o.getEndpointURL(t,"fileinfo")?o.getEndpointURL(t,"fileinfo").urlPath:null;if(!c)return null;var l=ga(function(){return Promise.resolve(oe.default(c,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){s=e})},function(e){throw we.error("File info call failed: "),we.error(e),new Error(e)});return l&&l.then?l.then(i):i()})})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){var n;function o(e){var t;return null!=(t=i)&&t.ok?i.json():Promise.resolve(i.json()).then(function(e){throw we.error("Fetch compute env failed: ",i.status,i.statusText,e),new Error(JSON.stringify(e))})}var i,s=null==(n=r.getEndpointURL(e,"computeEnvironments"))?void 0:n.urlPath;if(!s)return null;var a=ga(function(){return Promise.resolve(oe.default(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){i=e})},function(e){throw we.error("Fetch compute env failed: "),we.error(e),new Error(e)});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(o)).then(function(l){return Promise.resolve(c.getServiceEndpoints(o,l)).then(function(o){function l(e){var t;function r(e){return t?e:Promise.resolve(f.json()).then(function(e){throw we.error("Provider initialized failed: ",f.status,f.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(200===(null==(e=f)?void 0:e.status))return Promise.resolve(f.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var f,h=c.getEndpointURL(o,"initialize")?c.getEndpointURL(o,"initialize").urlPath:null;if(!h)return null;h+="?documentId="+e,h+="&serviceId="+t,h+="&fileIndex="+r,h+="&consumerAddress="+n,s&&(h+="&userdata="+encodeURI(JSON.stringify(s))),a&&(h+="&environment="+encodeURI(a)),u&&(h+="&validUntil="+u);var d=ga(function(){return Promise.resolve(oe.default(h,{method:"GET",headers:{"Content-Type":"application/json"},signal:i})).then(function(e){f=e})},function(e){throw we.error("Provider initialized failed: "),we.error(e),new Error("Provider initialize failed url: "+h+" ")});return d&&d.then?d.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l){try{var f=this;return Promise.resolve(f.getEndpoints(i)).then(function(h){return Promise.resolve(f.getServiceEndpoints(i,h)).then(function(i){function h(e){var t;function r(e){return t?e:Promise.resolve(m.json()).then(function(e){throw we.error("Initialize compute failed: ",m.status,m.statusText,e),we.error("Payload was:",JSON.stringify(g)),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=m)&&e.ok)return Promise.resolve(m.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d=f.getEndpointURL(i,"initializeCompute")?f.getEndpointURL(i,"initializeCompute").urlPath:null;if(!d)return null;var m,g={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:s};c&&(g.policyServer=c);var v=ga(function(){return Promise.resolve(oe.default(d,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json"},signal:l})).then(function(e){return m=e,function(){if(!m.ok)return Promise.resolve(m.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw we.error("Initialize compute failed: "),we.error(e),new Error("ComputeJob cannot be initialized: "+e.message+".")});return v&&v.then?v.then(h):h()})})}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(o)).then(function(c){return Promise.resolve(u.getServiceEndpoints(o,c)).then(function(l){var f=u.getEndpointURL(l,"download")?u.getEndpointURL(l,"download").urlPath:null;return f?Promise.resolve(u.getConsumerAddress(i)).then(function(h){return Promise.resolve(u.getNonce(o,h,null,c,l)).then(function(o){var c=(o+1).toString();return Promise.resolve(u.getSignature(i,c,ue.DOWNLOAD)).then(function(o){var i=f;return i+="?fileIndex="+r,i+="&documentId="+e,i+="&transferTxId="+n,i+="&serviceId="+t,i+="&consumerAddress="+h,i+="&nonce="+c,s&&(i+="&policyServer="+encodeURI(JSON.stringify(s))),i+="&signature="+o,a&&(i+="&userdata="+encodeURI(JSON.stringify(a))),i})})}):null})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{var v=this;return Promise.resolve(v.getEndpoints(e)).then(function(p){return Promise.resolve(v.getServiceEndpoints(e,p)).then(function(y){var b=v.getEndpointURL(y,"computeStart")?v.getEndpointURL(y,"computeStart").urlPath:null;return b?Promise.resolve(v.getConsumerAddress(t)).then(function(P){return Promise.resolve(v.getNonce(e,P,d,p,y)).then(function(p){var y=(p+1).toString();return Promise.resolve(v.getSignature(t,y,ue.COMPUTE_START)).then(function(p){function w(){function r(){var e;function r(t){var r;function n(t){return r?t:Promise.resolve(e.json()).then(function(t){throw we.error("Compute start failed: ",e.status,e.statusText,t),we.error("Payload was:",E),new Error(JSON.stringify(t))})}var o=function(t){if(null!=(t=e)&&t.ok)return Promise.resolve(e.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}h&&(E.policyServer=h),m&&(E.queueMaxWaitTime=m);var n=ga(function(){return Promise.resolve(oe.default(b,{method:"POST",body:JSON.stringify(E),headers:{"Content-Type":"application/json",Authorization:v.getAuthorization(t)},signal:d})).then(function(t){e=t})},function(e){throw we.error("Compute start failed:"),we.error(e),we.error("Payload was:",E),new Error("HTTP request failed calling Provider")});return n&&n.then?n.then(r):r()}a&&(E.resources=a),c&&(E.metadata=c),l&&(E.additionalViewers=l);var n=function(){if(f)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(E.output=ma(e,JSON.stringify(f)))})}();return n&&n.then?n.then(r):r()}var E=Object();E.consumerAddress=P,E.signature=p,E.nonce=y,E.environment=r,E.maxJobDuration=i,E.resources=a,E.dataset=n[0],E.datasets=n,E.algorithm=o,E.chainId=u,E.payment={chainId:u,token:s,maxJobDuration:i,resources:a};var S=function(){if(g)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(E.dockerRegistryAuth=ma(e,JSON.stringify(g)))})}();return S&&S.then?S.then(w):w()})})}):(we.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getEndpoints(e)).then(function(m){return Promise.resolve(d.getServiceEndpoints(e,m)).then(function(g){var v=d.getEndpointURL(g,"freeCompute")?d.getEndpointURL(g,"freeCompute").urlPath:null;return v?Promise.resolve(d.getConsumerAddress(t)).then(function(p){return Promise.resolve(d.getNonce(e,p,l,m,g)).then(function(m){var g=(m+1).toString();return Promise.resolve(d.getSignature(t,g,ue.FREE_COMPUTE_START)).then(function(m){function y(){function r(){var e;function r(t){var r;function n(t){return r?t:Promise.resolve(e.json()).then(function(t){throw we.error("Compute start failed: ",e.status,e.statusText,t),we.error("Payload was:",b),new Error(JSON.stringify(t))})}var o=function(t){if(null!=(t=e)&&t.ok)return Promise.resolve(e.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}c&&(b.policyServer=c),f&&(b.queueMaxWaitTime=f);var n=ga(function(){return Promise.resolve(oe.default(v,{method:"POST",body:JSON.stringify(b),headers:{"Content-Type":"application/json",Authorization:d.getAuthorization(t)},signal:l})).then(function(t){e=t})},function(e){throw we.error("Compute start failed:"),we.error(e),we.error("Payload was:",b),new Error("HTTP request failed calling Provider")});return n&&n.then?n.then(r):r()}var n=function(){if(u)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(b.output=ma(e,JSON.stringify(u)))})}();return n&&n.then?n.then(r):r()}var b=Object();b.consumerAddress=p,b.signature=m,b.nonce=g,b.environment=r,b.resources=i,b.dataset=n[0],b.datasets=n,b.algorithm=o,s&&(b.metadata=s),a&&(b.additionalViewers=a);var P=function(){if(h)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(b.dockerRegistryAuth=ma(e,JSON.stringify(h)))})}();return P&&P.then?P.then(y):y()})})}):(we.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeStreamableLogs")?o.getEndpointURL(a,"computeStreamableLogs").urlPath:null;return u?Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,n,s,a)).then(function(e){function s(){var e;function r(t){var r,n;if(null!=(r=e)&&r.ok||200===(null==(n=e)?void 0:n.status))return e.body;var o=we.error,i=e.statusText,s=e.status;return Promise.resolve(e.json()).then(function(e){return o.call(we,"computeStreamableLogs failed: ",s,i,e),null})}var i=ga(function(){return Promise.resolve(oe.default(u+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o.getAuthorization(t)},signal:n})).then(function(t){e=t})},function(e){throw we.error("computeStreamableLogs failed:"),we.error(e),new Error("HTTP request failed calling Provider")});return i&&i.then?i.then(r):r()}var a=(e+1).toString(),l="?consumerAddress="+c+"&jobId="+r,f=function(){if(!i)return Promise.resolve(o.getSignature(t,a,ue.COMPUTE_GET_STREAMABLE_LOGS)).then(function(e){l+="&signature="+e,l+="&nonce="+a})}();return f&&f.then?f.then(s):s()})}):(we.error("Compute start failed: Cannot get proper computeStreamableLogs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this,s="string"==typeof r;return Promise.resolve(i.getEndpoints(t)).then(function(a){return Promise.resolve(i.getServiceEndpoints(t,a)).then(function(u){var c=i.getEndpointURL(u,"computeStop")?i.getEndpointURL(u,"computeStop").urlPath:null;return Promise.resolve(i.getConsumerAddress(r)).then(function(l){return Promise.resolve(i.getNonce(t,l,o,a,u)).then(function(t){var a=(t+1).toString();return Promise.resolve(i.getSignature(r,a,ue.COMPUTE_STOP)).then(function(t){function u(e){var t;function r(e){return t?e:Promise.resolve(h.json()).then(function(e){throw we.error("Compute stop failed: ",h.status,h.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=h)&&e.ok)return Promise.resolve(h.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var f=new URLSearchParams;f.set("consumerAddress",l),f.set("nonce",a),f.set("jobId",e),s||f.set("signature",t),n&&f.set("agreementId",n);var h,d=f.toString();if(!d)return null;var m=ga(function(){return Promise.resolve(oe.default(c+"?"+d,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(r)},signal:o})).then(function(e){h=e})},function(e){throw we.error("Compute stop failed:"),we.error(e),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(u):u()})})})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{var i=this;return Promise.resolve(Ga(t)).then(function(s){var a=qa(t);return Promise.resolve(i.getEndpoints(e)).then(function(t){return Promise.resolve(i.getServiceEndpoints(e,t)).then(function(e){function t(e){var t;function r(e){var r;if(t)return e;function n(e){return r?e:Promise.resolve(u.json()).then(function(e){throw we.error("Get compute status failed:",u.status,u.statusText,e),new Error(JSON.stringify(e))})}we.error("Get compute status failed:",u.status,u.statusText);var o=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,c=i.getEndpointURL(e,"computeStatus")?i.getEndpointURL(e,"computeStatus").urlPath:null,l="?consumerAddress="+s;if(l+=n&&"&agreementId="+n||"",l+=r&&"&jobId="+r||"",!c)return null;var f=ga(function(){return Promise.resolve(oe.default(c+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:a},signal:o})).then(function(e){u=e})},function(e){throw we.error("Get compute status failed"),we.error(e),new Error(e)});return f&&f.then?f.then(t):t()})})})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeResult")?o.getEndpointURL(a,"computeResult").urlPath:null;return Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,null,s,a)).then(function(e){var s=(e+1).toString();return Promise.resolve(o.getSignature(t,s,ue.COMPUTE_GET_RESULT)).then(function(e){if(!u)return null;var t=u;return t+="?consumerAddress="+c,t+="&jobId="+r,t+="&index="+n.toString(),i||(t+="&nonce="+s,t+="&signature="+e),t})})})})})}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{return Promise.resolve(this.getComputeResultUrl(e,t,r,n)).then(function(e){if(!e)throw new Error("Could not retrieve compute result URL");return Promise.resolve(oe.default(e,{headers:o>0?{Range:"bytes="+o+"-"}:{}})).then(function(e){if(!e.ok)throw new Error("Failed to fetch compute result: "+e.status);return e.body})})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getEndpoints(t)).then(function(i){return Promise.resolve(n.getServiceEndpoints(t,i)).then(function(s){var a=n.getEndpointURL(s,"generateAuthToken").urlPath||null;return Promise.resolve(n.getNonce(t,o,r,i,s)).then(function(t){var i=(t+1).toString();return Promise.resolve(n.getSignature(e,i,ue.CREATE_AUTH_TOKEN)).then(function(e){return ga(function(){return Promise.resolve(oe.default(a,{method:"POST",body:JSON.stringify({address:o,signature:e,nonce:i}),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to generate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){return null==e?void 0:e.token})})},function(e){throw we.error("Generate auth token failed:"),we.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getEndpoints(r)).then(function(s){return Promise.resolve(o.getServiceEndpoints(r,s)).then(function(a){var u=o.getEndpointURL(a,"invalidateAuthToken").urlPath||null;return Promise.resolve(o.getNonce(r,i,n,s,a)).then(function(r){var o=(r+1).toString();return Promise.resolve(dt(e,i+o)).then(function(e){return ga(function(){return Promise.resolve(oe.default(u,{method:"POST",body:JSON.stringify({address:i,signature:e,token:t,nonce:o}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to invalidate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json())})},function(e){throw we.error("Generate auth token failed:"),we.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(ga(function(){return Promise.resolve(oe.default(e,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){var t,r=function(){if(null!=e&&e.ok)return Promise.resolve(e.json()).then(function(e){if(e&&(e.providerAddress||e.providerAddresses))return t=!0})}();return r&&r.then?r.then(function(e){return!!t&&e}):!!t&&r})},function(e){return we.error("Error validating provider: "+e.message),!1}))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw we.error("PolicyServerPassthrough failed: ",i.status,i.statusText,e),we.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"PolicyServerPassthrough")?n.getEndpointURL(e,"PolicyServerPassthrough").urlPath:null;if(!s)return null;var a=ga(function(){return Promise.resolve(oe.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw we.error("PolicyServerPassthrough failed: "),we.error(e),new Error("PolicyServerPassthrough failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw we.error("initializePSVerification failed: ",i.status,i.statusText,e),we.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"initializePSVerification")?n.getEndpointURL(e,"initializePSVerification").urlPath:null;if(!s)return null;var a=ga(function(){return Promise.resolve(oe.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw we.error("initializePSVerification failed: "),we.error(e),new Error("initializePSVerification failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(e)).then(function(l){return Promise.resolve(c.getServiceEndpoints(e,l)).then(function(f){var h=c.getEndpointURL(f,"logs")?c.getEndpointURL(f,"logs").urlPath:null;return h?Promise.resolve(t.getAddress()).then(function(d){return Promise.resolve(c.getNonce(e,d,u,l,f)).then(function(e){var l=(e+1).toString();return Promise.resolve(c.getSignature(t,l,ue.GET_LOGS)).then(function(e){function t(e){var t;return null!=(t=c)&&t.ok?c.body:Promise.resolve(c.json()).then(function(e){throw we.error("Download node logs failed: ",c.status,c.statusText,e),new Error(JSON.stringify(e))})}var c,f=h+"?startTime="+r+"&endTime="+n;o&&(f+="&maxLogs="+o),i&&(f+="&moduleName="+i),s&&(f+="&level="+s),a&&(f+="&page="+a);var m=ga(function(){return Promise.resolve(oe.default(f,{method:"POST",body:JSON.stringify({signature:e,nonce:l,address:d}),headers:{"Content-Type":"application/json"},signal:u})).then(function(e){c=e})},function(e){throw we.error("Download node logs failed:"),we.error(e),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(t):t()})})}):(we.error("Download node logs failed: Cannot get proper logs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.noZeroX=function(e){return this.zeroXTransformer(e,!1)},t.zeroXTransformer=function(e,t){void 0===e&&(e="");var r=this.inputMatch(e,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(t&&r.valid?"0x":"")+r.output},t.inputMatch=function(e,t,r){if("string"!=typeof e)throw we.debug("Not input string:"),we.debug(e),new Error("["+r+"] Expected string, input type: "+typeof e);var n=e.match(t);return n?{valid:!0,output:n[1]}:(we.warn("["+r+"] Input transformation failed."),{valid:!1,output:e})},t.resolveDdo=function(e,t,r){try{return Promise.resolve(oe.default(e+"/api/aquarius/assets/ddo/"+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return e.ok?e.json():null})}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{var o=this;return Promise.resolve(r.getAddress()).then(function(i){return Promise.resolve(o.getData(e+"/api/services/nonce?userAddress="+i)).then(function(o){return Promise.resolve(o.json()).then(function(o){var s,a=(Number(null!=(s=o.nonce)?s:0)+1).toString();return Promise.resolve(dt(r,i+a+ue.VALIDATE_DDO)).then(function(r){return Promise.resolve(oe.default(e+"/api/aquarius/assets/ddo/validate",{method:"POST",body:JSON.stringify({ddo:t,publisherAddress:i,nonce:a,signature:r}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return{valid:!0,hash:e.hash,proof:{validatorAddress:e.publicKey,r:e.r[0],s:e.s[0],v:e.v}}}):null})})})})})}catch(e){return Promise.reject(e)}},t.getData=function(e,t){try{return Promise.resolve(oe.default(e,{method:"GET",headers:{"Content-type":"application/json",Authorization:t}}))}catch(e){return Promise.reject(e)}},e}();class pa extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,pa)}}const ya=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function ba(e,t,r){"function"==typeof r&&(r={filter:r});const n=function(e,t,r){let n;const o=new Promise((o,i)=>{if(!((r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r}).count>=0)||r.count!==Number.POSITIVE_INFINITY&&!Number.isInteger(r.count))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();const s=[t].flat(),a=[],{addListener:u,removeListener:c}=(e=>{const t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}})(e),l=async(...e)=>{const t=r.multiArgs?e:e[0];if(r.filter)try{if(!await r.filter(t))return}catch(e){return n(),void i(e)}a.push(t),r.count===a.length&&(n(),o(a))},f=(...e)=>{n(),i(r.rejectionMultiArgs?e:e[0])};n=()=>{for(const e of s)c(e,l);for(const e of r.rejectionEvents)s.includes(e)||c(e,f)};for(const e of s)u(e,l);for(const e of r.rejectionEvents)s.includes(e)||u(e,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(a)});if(o.cancel=n,"number"==typeof r.timeout){const e=function(e,t){const{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout:setTimeout,clearTimeout:clearTimeout},signal:s}=t;let a,u;const c=new Promise((t,c)=>{if("number"!=typeof r||1!==Math.sign(r))throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted)return void c(ya(s));if(s&&(u=()=>{c(ya(s))},s.addEventListener("abort",u,{once:!0})),e.then(t,c),r===Number.POSITIVE_INFINITY)return;const l=new pa;a=i.setTimeout.call(void 0,()=>{if(n)try{t(n())}catch(e){c(e)}else"function"==typeof e.cancel&&e.cancel(),!1===o?t():o instanceof Error?c(o):(l.message=o??`Promise timed out after ${r} milliseconds`,c(l))},r)}).finally(()=>{c.clear(),u&&s&&s.removeEventListener("abort",u)});return c.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},c}(o,{milliseconds:r.timeout});return e.cancel=()=>{n(),e.clear()},e}return o}(e,t,r={...r,count:1,resolveImmediately:!1}),o=n.then(e=>e[0]);return o.cancel=n.cancel,o}function Pa(e){return e.reason}async function wa(e,t,r){if(null==t)return e;const n=r?.translateError??Pa;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((e,r)=>{o=()=>{r(n(t))},t.addEventListener("abort",o)})])}finally{null!=o&&t.removeEventListener("abort",o)}}class Ea{protocol;components;started;timeout;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;constructor(e,t={}){this.components=e,this.started=!1,this.protocol=`/${t.protocolPrefix??"ipfs"}/ping/1.0.0`,this.timeout=t.timeout??1e4,this.maxInboundStreams=t.maxInboundStreams??2,this.maxOutboundStreams=t.maxOutboundStreams??1,this.runOnLimitedConnection=t.runOnLimitedConnection??!0,this.handlePing=this.handlePing.bind(this)}[Symbol.toStringTag]="@libp2p/ping";[Et]=["@libp2p/ping"];async start(){await this.components.registrar.handle(this.protocol,this.handlePing,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async handlePing(e,t){const r=e.log.newScope("ping");r.trace("ping from %p",t.remotePeer);const n=AbortSignal.timeout(this.timeout);n.addEventListener("abort",()=>{e.abort(new bt("Ping timed out"))});const o=Date.now();for await(const t of e){if("open"!==e.status){r("stream status changed to %s",e.status);break}e.send(t)||(r("waiting for stream to drain"),await ba(e,"drain",{rejectionEvents:["close"],signal:n}),r("stream drained"))}r("ping from %p complete in %dms",t.remotePeer,Date.now()-o),await e.close({signal:n})}async ping(e,t={}){const r=function(){if(isNaN(32))throw new mt("random bytes length must be a Number bigger than 0");return jn(32)}(),n=await this.components.connectionManager.openStream(e,this.protocol,{runOnLimitedConnection:this.runOnLimitedConnection,...t}),o=n.log.newScope("ping");try{const e=Date.now(),o=Promise.withResolvers(),i=new Cr,s=a=>{if(i.append(a.data),32===i.byteLength){n.removeEventListener("message",s);const a=Date.now()-e;Promise.all([n.closeRead(t)]).then(()=>{if(!wr(r,i.subarray()))throw new yt(`Received wrong ping ack after ${a}ms`);o.resolve(a)}).catch(e=>{n.abort(e),o.reject(e)})}};return n.addEventListener("message",s),n.send(r),await n.close(t),await wa(o.promise,t.signal)}catch(t){throw o.error("error while pinging %o - %e",e,t),n?.abort(t),t}finally{n?.close()}}}function Sa(e={}){return t=>new Ea(t,e)}class Aa extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"}class Ta extends Error{static name="UnwrappedError";name="UnwrappedError"}class xa extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"}class ka extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"}class Ca extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"}function Oa(e){return function(e){return"function"==typeof e?.closeRead}(e)?"writable"!==e.remoteWriteStatus&&0===e.readBufferLength:!!function(e){return"function"==typeof e?.close}(e)&&"open"!==e.status}function Fa(e,t,r){if(!e.s){if(r instanceof Da){if(!r.s)return void(r.o=Fa.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Fa.bind(null,e,t),Fa.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var Da=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Fa(n,1,i(this.v))}catch(e){Fa(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Fa(n,1,t?t(o):o):r?Fa(n,1,r(o)):Fa(n,2,o)}catch(e){Fa(n,2,e)}},n},e}();function ja(e){return e instanceof Da&&1&e.s}function Ia(e,t,r){for(var n;;){var o=e();if(ja(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!ja(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!ja(s)){n=2;break}}}var a=new Da,u=Fa.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(f)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!ja(s))return void s.then(f).then(void 0,u);if(!(o=e())||ja(o)&&!o.v)return void Fa(a,1,i);if(o.then)return void o.then(l).then(void 0,u);ja(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):Fa(a,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):Fa(a,1,i)}}function La(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function Na(e,t){try{var r=e()}catch(e){return t(!0,e)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,r)}var Ua="/ocean/nodes/1.0.0",Ra=1e4,Ma=["/dns4/bootstrap1.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP","/dns4/bootstrap2.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4","/dns4/bootstrap3.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U","/dns4/bootstrap4.oncompute.ai/tcp/9001/ws/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom"],_a=/*#__PURE__*/function(){function e(){this.p2pConfig={},this.libp2pNode=null,this.discoveredNodes=new Map}var t=e.prototype;return t.setupP2P=function(e){try{var t=this;return t.p2pConfig=e,t.discoveredNodes.clear(),t.libp2pNode&&(Promise.resolve(t.libp2pNode.stop()).catch(function(){}),t.libp2pNode=null),Promise.resolve(t.getOrCreateLibp2pNode()).then(function(){})}catch(e){return Promise.reject(e)}},t.getMultiaddrFromPeerId=function(e){try{var t,r,n=this,o=function(e){return e.includes("/p2p/")?e:e+"/p2p/"+e};return Promise.resolve(n.getOrCreateLibp2pNode()).then(function(i){var s;function a(t){if(s)return t;throw new Error("No multiaddrs found for peer id "+e)}var u=i.getConnections().find(function(t){return t.remotePeer.toString()===e});if(null!=u&&u.remoteAddr){var c=u.remoteAddr.toString();return o(c)}var l=n.discoveredNodes.get(e);if(l&&l.length>0)return o(l[0]);var f,h=i.services.dht,d=!1,m=!1,g=Na(function(){return La(function(){return t=function(e){var t,r,n,o=2;for("undefined"!=typeof Symbol&&(r=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(r&&null!=(t=e[r]))return t.call(e);if(n&&null!=(t=e[n]))return new fe(t.call(e));r="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}(h.findPeer(ha(e),{signal:AbortSignal.timeout(2e4)})),Ia(function(){function e(e){return!s&&(d=!(r=e).done)}return s?!!e(!s&&t.next()):Promise.resolve(!s&&t.next()).then(e)},function(){return!!(d=!1)},function(){var e=r.value;if(e.type===I.EventTypes.FINAL_PEER&&e.peer.multiaddrs.length>0){var t=e.peer.multiaddrs[0].toString(),n=o(t);return s=1,n}})},function(e){m=!0,f=e})},function(e,r){function n(t){if(s)return t;if(e)throw r;return r}var o=Na(function(){var e=function(){if(d&&null!=t.return)return Promise.resolve(t.return()).then(function(){})}();if(e&&e.then)return e.then(function(){})},function(e,t){if(m)throw f;if(e)throw t;return t});return o&&o.then?o.then(n):n(o)});return g&&g.then?g.then(a):a(g)})}catch(e){return Promise.reject(e)}},t.getDiscoveredNodes=function(){return Array.from(this.discoveredNodes.entries()).map(function(e){return{peerId:e[0],multiaddrs:e[1]}})},t.bufToHex=function(e){var t;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){return e}return"Buffer"===(null==(t=e)?void 0:t.type)&&Array.isArray(e.data)?Buffer.from(e.data).toString():e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString():e},t.getOrCreateLibp2pNode=function(){try{var e,t=this;if(t.libp2pNode)return Promise.resolve(t.libp2pNode);var r=(null!=(e=t.p2pConfig.bootstrapPeers)?e:Ma).map(E.multiaddr);return Promise.resolve(T.createLibp2p(me({addresses:{listen:[]},transports:[C.webSockets(),F.circuitRelayTransport()].concat(t.p2pConfig.enableTcp?[O.tcp()]:[]),connectionEncrypters:[x.noise()],streamMuxers:[k.yamux()],peerDiscovery:[].concat(r.length>0?[D.bootstrap({list:r.map(String),timeout:1e4})]:[]),services:{identify:j.identify(),ping:Sa(),dht:I.kadDHT({protocol:"/ocean/nodes/1.0.0/kad/1.0.0",clientMode:!0})},connectionManager:{maxConnections:100},connectionMonitor:{abortConnectionOnPingFailure:!1}},t.p2pConfig.libp2p))).then(function(e){return Promise.resolve(e.start()).then(function(){return e.addEventListener("peer:discovery",function(r){var n,o=r.detail;if(null!=o&&o.id){var i=o.id.toString();t.discoveredNodes.set(i,(null!=(n=o.multiaddrs)?n:[]).map(function(e){return e.toString()})),e.getConnections().length<100&&0===e.getConnections(o.id).length&&e.dial(o.id,{signal:AbortSignal.timeout(1e4)}).catch(function(e){we.debug("Failed to dial discovered peer "+i+": "+e.message)})}}),t.libp2pNode=e,e})})}catch(e){return Promise.reject(e)}},t.toUint8Array=function(e){return e instanceof Uint8Array?e:e.subarray()},t.isDialable=function(e){return"undefined"==typeof window||e.toString().includes("/tls/sni")},t.peerIdFromMultiaddr=function(e){var t=e.toString().split("/p2p/");return t.length>1?t[t.length-1]:null},t.getConnection=function(e,t){try{var r=this;return Promise.resolve(r.getOrCreateLibp2pNode()).then(function(n){var o;function i(i){var s;if(o)return i;function a(o){return s?o:(we.debug("[P2P] bare peerId -> dialByPeerId "+e),r.dialByPeerId(n,e,t))}var u=La(function(){function o(o){if(s)return o;var a=r.peerIdFromMultiaddr(i);if(a){we.debug("[P2P] single fallback -> dialByPeerId "+a);var u=r.dialByPeerId(n,a,t);return s=1,u}throw new Error("Cannot dial address: "+e)}var i=E.multiaddr(e),a=function(){if(r.isDialable(i))return we.debug("[P2P] dial single addr: "+i),La(function(){return Promise.resolve(n.dial(i,{signal:t})).then(function(e){return we.debug("[P2P] dial single SUCCESS via "+e.remoteAddr),s=1,e})},function(e){we.debug("[P2P] dial single failed: "+e.message)})}();return a&&a.then?a.then(o):o(a)},function(e){var t;if(null!=(t=e.message)&&t.includes("Cannot dial"))throw e});return u&&u.then?u.then(a):a(u)}var s=function(){if(Array.isArray(e)){var i=function(i){if(o)return i;for(var s,a=de(e);!(s=a()).done;){var u=r.peerIdFromMultiaddr(s.value);if(u){we.debug("[P2P] Not multiaddrs, fallback to peerId: "+u);var c=r.dialByPeerId(n,u,t);return o=1,c}}throw new Error("No valid addresses and no peer ID in multiaddrs")},s=e.filter(function(e){return r.isDialable(e)}),a=function(){if(s.length>0)return we.debug("[P2P] dial array: "+s.length+" dialable addrs"),La(function(){return Promise.resolve(n.dial(s,{signal:t})).then(function(e){return we.debug("[P2P] dial array SUCCESS via "+e.remoteAddr),o=1,e})},function(e){we.debug("[P2P] dial array failed: "+e.message)})}();return a&&a.then?a.then(i):i(a)}}();return s&&s.then?s.then(i):i(s)})}catch(e){return Promise.reject(e)}},t.dialByPeerId=function(e,t,r){try{var n,o=function(o){if(n)return o;function a(){var n;function o(r){return n?r:(we.debug("[P2P] "+t+": last resort dial by peerId"),La(function(){return Promise.resolve(e.dial(s,{signal:AbortSignal.timeout(1e4)})).then(function(e){return we.debug("[P2P] "+t+": peerId dial SUCCESS via "+e.remoteAddr+" (limited="+(null!=e.limits)+")"),e})},function(){throw new Error("Cannot reach peer "+t+". "+(c.length>0?"Found addrs: "+c.map(String).join(", ")+" (none browser-dialable). ":"No addresses found. ")+"Active connections: "+e.getConnections().length+".")}))}var a=c.filter(function(e){return i.isDialable(e)}).map(function(e){var r=e.toString();return r.includes("/p2p/")?e:E.multiaddr(r+"/p2p/"+t)});we.debug("[P2P] "+t+": "+a.length+"/"+c.length+" addrs are dialable");var u=function(){if(a.length>0)return we.debug("[P2P] "+t+": dialing "+a.map(String)),La(function(){return Promise.resolve(e.dial(a,{signal:r})).then(function(e){return we.debug("[P2P] "+t+": SUCCESS via "+e.remoteAddr+" (limited="+(null!=e.limits)+")"),n=1,e})},function(e){we.debug("[P2P] "+t+": direct dial failed: "+e.message)})}();return u&&u.then?u.then(o):o(u)}var u=new Set,c=[],l=function(e){var t=e.toString();u.has(t)||(u.add(t),c.push(e))},f=i.discoveredNodes.get(t);if(f){for(var h,d=de(f);!(h=d()).done;){var m=h.value;try{l(E.multiaddr(m))}catch(e){}}we.debug("[P2P] "+t+": "+f.length+" cached addrs")}var g=c.filter(function(e){return i.isDialable(e)}),v=function(){if(0===g.length){we.debug("[P2P] "+t+": no cached dialable addrs, querying DHT...");var r=La(function(){var r,n=AbortSignal.timeout(null!=(r=i.p2pConfig.dhtLookupTimeout)?r:6e4);return Promise.resolve(e.peerRouting.findPeer(s,{signal:n})).then(function(e){for(var r,n=de(e.multiaddrs);!(r=n()).done;)l(r.value);we.debug("[P2P] "+t+": DHT returned "+e.multiaddrs.length+" addrs")})},function(e){we.debug("[P2P] "+t+": DHT findPeer failed: "+e.message)});if(r&&r.then)return r.then(function(){})}else we.debug("[P2P] "+t+": "+g.length+" cached dialable addrs, skipping DHT")}();return v&&v.then?v.then(a):a()},i=this,s=ha(t),a=e.getConnections(s).filter(function(e){return"open"===e.status});if(a.length>0)return we.debug("[P2P] "+t+": reusing existing connection via "+a[0].remoteAddr),Promise.resolve(a[0]);var u=function(){if(0===e.getConnections().length)return we.debug("[P2P] "+t+": no connections yet, waiting for bootstrap..."),Promise.resolve(ht(3e3)).then(function(){var r=e.getConnections(s);if(r.length>0)return we.debug("[P2P] "+t+": connected during bootstrap wait"),n=1,r[0]})}();return Promise.resolve(u&&u.then?u.then(o):o(u))}catch(e){return Promise.reject(e)}},t.getConsumerAddress=function(e){return Ga(e)},t.getSignature=function(e,t,r){return Ba(e,t,r)},t.getNodePublicKey=function(e){try{return Promise.resolve(this.getEndpoints(e)).then(function(e){return null==e?void 0:e.nodePublicKey})}catch(e){return Promise.reject(e)}},t.getAuthorization=function(e){return qa(e)},t.dialAndStream=function(e,t,r){try{var n,o=this,i=null!=r?r:AbortSignal.timeout(null!=(n=o.p2pConfig.dialTimeout)?n:Ra);return Promise.resolve(o.getConnection(e,i)).then(function(e){return La(function(){return Promise.resolve(e.newStream(Ua,{signal:i,runOnLimitedConnection:!0})).then(function(r){var n=function(e,t={}){const r=function(e,t){const r=t?.maxBufferSize??4194304,n=new Cr;let o,i=!1;if(s=e,null==s?.addEventListener||null==s?.removeEventListener||null==s?.send||null==s?.push||null==s?.log)throw new mt("Argument should be a Stream or a Multiaddr");var s;const a=e=>{if(n.append(e.data),n.byteLength>r){const e=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${e} > ${r}`))}o?.resolve()};e.addEventListener("message",a);const u=e=>{null!=e.error?o?.reject(e.error):o?.resolve()};e.addEventListener("close",u);const c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);const l={readBuffer:n,async read(t){if(!0===i)throw new Ta("Stream was unwrapped");if(Oa(e)){if(0===n.byteLength&&null==t?.bytes)return null;if(null!=t?.bytes&&n.byteLength<t.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,t.bytes),new Aa(`Unexpected EOF - stream closed after reading ${n.byteLength}/${t.bytes} bytes`)}const r=t?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=r){o.resolve();break}if(await wa(o.promise,t?.signal),Oa(e)){if(0===n.byteLength&&null==t?.bytes)return null;break}o=Promise.withResolvers()}const s=t?.bytes??n.byteLength;if(n.byteLength<s){if(Oa(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,s),new Aa(`Unexpected EOF - stream closed while reading ${n.byteLength}/${s} bytes`);return l.read(t)}const a=n.sublist(0,s);return n.consume(s),a},async write(t,r){if(!0===i)throw new Ta("Stream was unwrapped");e.send(t)||await ba(e,"drain",{signal:r?.signal,rejectionEvents:["close"]})},unwrap:()=>(i||(i=!0,e.removeEventListener("message",a),e.removeEventListener("close",u),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e)};return l}(e,t);null!=t.maxDataLength&&null==t.maxLengthLength&&(t.maxLengthLength=Zi(t.maxDataLength));const n=t?.lengthDecoder??Xi,o=t?.lengthEncoder??Yi;return{async read(o){let i=-1;const s=new Cr;for(;;){const e=await r.read({...o,bytes:1});if(null==e)break;s.append(e);try{i=n(s)}catch(e){if(e instanceof RangeError)continue;throw e}if(i<0)throw new xa("Invalid message length");if(null!=t?.maxLengthLength&&s.byteLength>t.maxLengthLength)throw new Ca(`Message length length too long - ${s.byteLength} > ${t.maxLengthLength}`);if(i>-1)break}if(null!=t?.maxDataLength&&i>t.maxDataLength)throw new ka(`Message length too long - ${i} > ${t.maxDataLength}`);const a=await r.read({...o,bytes:i});if(null==a)throw e.log.error("tried to read %d bytes but the stream closed",i),new Aa(`Unexpected EOF - tried to read ${i} bytes but the stream closed`);if(a.byteLength!==i)throw e.log.error("read %d/%d bytes before the stream closed",a.byteLength,i),new Aa(`Unexpected EOF - read ${a.byteLength}/${i} bytes before the stream closed`);return a},async write(e,t){await r.write(new Cr(o(e.byteLength),e),t)},async writeV(e,t){const n=new Cr(...e.flatMap(e=>[o(e.byteLength),e]));await r.write(n,t)},unwrap:()=>r.unwrap()}}(r);return Promise.resolve(n.write((new TextEncoder).encode(JSON.stringify(t)),{signal:i})).then(function(){return Promise.resolve(r.close()).then(function(){return Promise.resolve(n.read({signal:i})).then(function(t){var r=o.toUint8Array(t);return{lp:n,firstBytes:r,connection:e}})})})})},function(t){try{e.abort(new Error("stream failed"))}catch(e){}throw t})})}catch(e){return Promise.reject(e)}},t.sendP2pCommand=function(e,t,r,n,o,i){void 0===i&&(i=0);try{var s=this;return Promise.resolve(La(function(){var a=me({command:t,authorization:n?s.getAuthorization(n):void 0},r);return Promise.resolve(s.dialAndStream(e,a,o)).then(function(a){var u=a.lp,c=a.firstBytes;function l(a){for(var u,c,l,f=0;f<m.length;f++){var h=(new TextDecoder).decode(m[f]);try{l=JSON.parse(h)}catch(e){l=m[f]}}var d=l;if("number"==typeof(null==d?void 0:d.httpStatus)&&d.httpStatus>=400)throw new Error("string"==typeof d.error?d.error:JSON.stringify(d.error));var g=null!=(u="string"==typeof l?l:null==d?void 0:d.error)?u:"",v=function(a){if(g.includes("Cannot connect to peer")&&i<(null!=(a=s.p2pConfig.maxRetries)?a:5))return Promise.resolve(new Promise(function(e){var t;return setTimeout(e,null!=(t=s.p2pConfig.retryDelay)?t:1e3)})).then(function(){var a=s.sendP2pCommand(e,t,r,n,o,i+1);return c=1,a})}();return v&&v.then?v.then(function(e){return c?e:l}):c?v:l}if(!c.length)throw new Error("Gateway node error: no response from peer");var f=(new TextDecoder).decode(c);try{var h,d=JSON.parse(f);if("number"==typeof(null==d?void 0:d.httpStatus)&&d.httpStatus>=400)throw new Error(null!=(h=d.error)?h:"Gateway node error: "+d.httpStatus)}catch(e){}if(t===ue.COMPUTE_GET_STREAMABLE_LOGS||t===ue.COMPUTE_GET_RESULT)return ye(/*#__PURE__*/ve().mark(function e(){var t;return ve().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0;case 1:return e.next=4,he(u.read({signal:AbortSignal.timeout(Ra)}));case 4:return t=e.sent,e.next=7,t instanceof Uint8Array?t:t.subarray();case 7:e.next=1;break;case 9:e.next=15;break;case 11:if(e.prev=11,e.t0=e.catch(0),e.t0 instanceof Aa){e.next=15;break}throw e.t0;case 15:case"end":return e.stop()}},e,null,[[0,11]])}))();var m=[c],g=La(function(){var e=Ia(function(){return!0},void 0,function(){var e;return Promise.resolve(u.read({signal:AbortSignal.timeout(null!=(e=s.p2pConfig.dialTimeout)?e:Ra)})).then(function(e){m.push(s.toUint8Array(e))})});if(e&&e.then)return e.then(function(){})},function(e){if(!(e instanceof Aa))throw e});return g&&g.then?g.then(l):l()})},function(a){var u,c;function l(e){if(c)return e;throw new Error("P2P command error: "+f)}var f=null!=(u=null==a?void 0:a.message)?u:"",h=function(a){if((f.includes("closed")||f.includes("reset"))&&i<(null!=(a=s.p2pConfig.maxRetries)?a:5))return we.debug("[P2P] Stream reset/closed on attempt "+(i+1)+", retrying..."),Promise.resolve(ht(1e3)).then(function(){var a=s.sendP2pCommand(e,t,r,n,o,i+1);return c=1,a})}();return h&&h.then?h.then(l):l(h)}))}catch(e){return Promise.reject(e)}},t.getEndpoints=function(e){try{var t=this;return Promise.resolve(La(function(){return Promise.resolve(t.sendP2pCommand(e,ue.STATUS,{}))},function(e){throw we.error("P2P getEndpoints (STATUS) failed:",e),e}))}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r){try{var n=this;return Promise.resolve(La(function(){return Promise.resolve(n.sendP2pCommand(e,ue.NONCE,{address:t},null,r)).then(function(e){var t,r,n="number"==typeof e?e:null!=(t=null!=(r=null==e?void 0:e.nonce)?r:e)?t:0;return n&&null!==n?Number(n):0})},function(e){throw we.error("P2P getNonce failed:",e),e}))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getConsumerAddress(n)).then(function(o){return Promise.resolve(s.getNonce(r,o,i)).then(function(a){var u=(a+1).toString();return Promise.resolve(s.getSignature(n,u,ue.ENCRYPT)).then(function(a){return Promise.resolve(s.sendP2pCommand(r,ue.ENCRYPT,{chainId:t,nonce:u,consumerAddress:o,signature:a,blob:"string"==typeof e?e:JSON.stringify(e)},n,i)).then(function(e){return s.bufToHex(e)})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{return Promise.resolve(this.sendP2pCommand(r,ue.FILE_INFO,{did:e,serviceId:t,checksum:n},null,o)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{return Promise.resolve(this.sendP2pCommand(t,ue.FILE_INFO,{file:e,type:e.type,checksum:r},null,n)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,ue.COMPUTE_GET_ENVIRONMENTS,{},null,t)).then(function(e){return Array.isArray(e)?e:[e]})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c={ddoId:e,serviceId:t,consumerAddress:n};return s&&(c.userdata=s),a&&(c.environment=a),u&&(c.validUntil=u),Promise.resolve(this.sendP2pCommand(o,ue.GET_FEES,c,null,i))}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l){try{var f={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:s};return c&&(f.policyServer=c),Promise.resolve(this.sendP2pCommand(i,ue.COMPUTE_INITIALIZE,f,null,l))}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getConsumerAddress(i)).then(function(c){return Promise.resolve(u.getNonce(o,c)).then(function(l){var f=(l+1).toString();return Promise.resolve(u.getSignature(i,f,ue.DOWNLOAD)).then(function(l){var h={command:ue.DOWNLOAD,authorization:u.getAuthorization(i),fileIndex:r,documentId:e,transferTxId:n,serviceId:t,consumerAddress:c,nonce:f,signature:l};return s&&(h.policyServer=s),a&&(h.userData=a),Promise.resolve(u.dialAndStream(o,h)).then(function(e){var t=e.lp,n=e.firstBytes;function o(e){var t=Buffer.concat(c);return{data:t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),filename:"file"+r}}var i,s=(new TextDecoder).decode(n),a=null;try{a=JSON.parse(s)}catch(e){}if(a&&"number"==typeof a.httpStatus&&a.httpStatus>=400)throw new Error(null!=(i=a.error)?i:"P2P download error: "+a.httpStatus);var c=null===a?[Buffer.from(n)]:[],l=La(function(){var e=Ia(function(){return!0},void 0,function(){var e;return Promise.resolve(t.read({signal:AbortSignal.timeout(null!=(e=u.p2pConfig.dialTimeout)?e:Ra)})).then(function(e){c.push(Buffer.from(u.toUint8Array(e)))})});if(e&&e.then)return e.then(function(){})},function(e){if(!(e instanceof Aa))throw e});return l&&l.then?l.then(o):o()})})})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{var v=this;return Promise.resolve(v.getConsumerAddress(t)).then(function(p){return Promise.resolve(v.getNonce(e,p,d)).then(function(y){var b=(y+1).toString();return Promise.resolve(v.getSignature(t,b,ue.COMPUTE_START)).then(function(y){function P(){function r(){return Promise.resolve(v.sendP2pCommand(e,ue.COMPUTE_START,w,t,d)).then(function(e){return Array.isArray(e),e})}var n=function(){if(f)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(w.output=ma(e,JSON.stringify(f)))})}();return n&&n.then?n.then(r):r()}var w={environment:r,dataset:n[0],datasets:n,algorithm:o,maxJobDuration:i,feeToken:s,resources:a,chainId:u,payment:{chainId:u,token:s,maxJobDuration:i,resources:a},consumerAddress:p,nonce:b,signature:y};c&&(w.metadata=c),l&&(w.additionalViewers=l),h&&(w.policyServer=h),m&&(w.queueMaxWaitTime=m);var E=function(){if(g)return Promise.resolve(v.getNodePublicKey(e)).then(function(e){e&&(w.dockerRegistryAuth=ma(e,JSON.stringify(g)))})}();return E&&E.then?E.then(P):P()})})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{var d=this;return Promise.resolve(d.getConsumerAddress(t)).then(function(m){return Promise.resolve(d.getNonce(e,m,l)).then(function(g){var v=(g+1).toString();return Promise.resolve(d.getSignature(t,v,ue.FREE_COMPUTE_START)).then(function(g){function p(){function r(){return Promise.resolve(d.sendP2pCommand(e,ue.FREE_COMPUTE_START,y,t,l)).then(function(e){return Array.isArray(e),e})}var n=function(){if(u)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(y.output=ma(e,JSON.stringify(u)))})}();return n&&n.then?n.then(r):r()}var y={environment:r,dataset:n[0],datasets:n,algorithm:o,resources:i,consumerAddress:m,nonce:v,signature:g};s&&(y.metadata=s),a&&(y.additionalViewers=a),c&&(y.policyServer=c),f&&(y.queueMaxWaitTime=f);var b=function(){if(h)return Promise.resolve(d.getNodePublicKey(e)).then(function(e){e&&(y.dockerRegistryAuth=ma(e,JSON.stringify(h)))})}();return b&&b.then?b.then(p):p()})})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this;return"string"==typeof t?Promise.resolve(o.sendP2pCommand(e,ue.COMPUTE_GET_STREAMABLE_LOGS,{jobId:r},t,n)):Promise.resolve(o.getConsumerAddress(t)).then(function(i){return Promise.resolve(o.getNonce(e,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(o.getSignature(t,a,ue.COMPUTE_GET_STREAMABLE_LOGS)).then(function(s){return o.sendP2pCommand(e,ue.COMPUTE_GET_STREAMABLE_LOGS,{jobId:r,consumerAddress:i,nonce:a,signature:s},t,n)})})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getConsumerAddress(r)).then(function(s){return Promise.resolve(i.getNonce(t,s,o)).then(function(a){var u=(a+1).toString();return Promise.resolve(i.getSignature(r,u,ue.COMPUTE_STOP)).then(function(a){var c={jobId:e,consumerAddress:s,nonce:u,signature:a};return n&&(c.agreementId=n),i.sendP2pCommand(t,ue.COMPUTE_STOP,c,r,o)})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getConsumerAddress(t)).then(function(s){var a={consumerAddress:s};return r&&(a.jobId=r),n&&(a.agreementId=n),i.sendP2pCommand(e,ue.COMPUTE_GET_STATUS,a,t,o)})}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{var i=this;return Promise.resolve(i.getConsumerAddress(t)).then(function(s){function a(){return Promise.resolve(i.dialAndStream(e,u)).then(function(e){var t,r,n=e.lp,o=e.firstBytes,s=JSON.parse((new TextDecoder).decode(o));if("number"==typeof(null==s?void 0:s.httpStatus)&&s.httpStatus>=400)throw new Error(null!=(r=s.error)?r:"P2P compute result error: "+s.httpStatus);var a=null!=(t=i.p2pConfig.dialTimeout)?t:Ra;return ye(/*#__PURE__*/ve().mark(function e(){var t;return ve().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0;case 1:return e.next=4,he(n.read({signal:AbortSignal.timeout(a)}));case 4:return t=e.sent,e.next=7,t instanceof Uint8Array?t:t.subarray();case 7:e.next=1;break;case 9:e.next=15;break;case 11:if(e.prev=11,e.t0=e.catch(0),e.t0 instanceof Aa){e.next=15;break}throw e.t0;case 15:case"end":return e.stop()}},e,null,[[0,11]])}))()})}var u={command:ue.COMPUTE_GET_RESULT,jobId:r,index:n,offset:o,consumerAddress:s},c=function(){if("string"!=typeof t)return Promise.resolve(i.getNonce(e,s)).then(function(e){var r=(e+1).toString();return u.nonce=r,Promise.resolve(i.getSignature(t,r,ue.COMPUTE_GET_RESULT)).then(function(e){u.signature=e})});u.authorization=t}();return c&&c.then?c.then(a):a()})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getConsumerAddress(t)).then(function(i){return Promise.resolve(o.sendP2pCommand(e,ue.COMPUTE_GET_RESULT,{jobId:r,index:n,consumerAddress:i},t))})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getNonce(t,o,r)).then(function(i){var s=(i+1).toString();return Promise.resolve(n.getSignature(e,s,ue.CREATE_AUTH_TOKEN)).then(function(e){return Promise.resolve(n.sendP2pCommand(t,ue.CREATE_AUTH_TOKEN,{address:o,signature:e,nonce:s},null,r)).then(function(e){var t;return null!=(t=null==e?void 0:e.token)?t:e})})})})}catch(e){return Promise.reject(e)}},t.resolveDdo=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,ue.GET_DDO,{id:t},null,r))}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{var o=this;return Promise.resolve(r.getAddress()).then(function(i){return Promise.resolve(o.getNonce(e,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(dt(r,i+a+ue.VALIDATE_DDO)).then(function(r){return Promise.resolve(o.sendP2pCommand(e,ue.VALIDATE_DDO,{ddo:t,publisherAddress:i,nonce:a,signature:r},null,n)).then(function(e){var t,r,n,i;return!e||e.error?null:{valid:!0,hash:o.bufToHex(e.hash),proof:{validatorAddress:o.bufToHex(e.publicKey),r:o.bufToHex(null!=(t=null==(r=e.r)?void 0:r[0])?t:e.r),s:o.bufToHex(null!=(n=null==(i=e.s)?void 0:i[0])?n:e.s),v:e.v}}})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getNonce(r,i,n)).then(function(s){var a=(s+1).toString();return Promise.resolve(dt(e,i+a)).then(function(e){return o.sendP2pCommand(r,ue.INVALIDATE_AUTH_TOKEN,{address:i,signature:e,token:t,nonce:a},null,n)})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){var r=this;return Promise.resolve(La(function(){return Promise.resolve(r.sendP2pCommand(e,ue.STATUS,{},null,t)).then(function(e){return!(!e||!(e.address||e.providerAddress||e.providerAddresses))})},function(){return!1}))},t.PolicyServerPassthrough=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,ue.POLICY_SERVER_PASSTHROUGH,me({},t),null,r))}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{return Promise.resolve(this.sendP2pCommand(e,ue.POLICY_SERVER_PASSTHROUGH,me({},t),null,r))}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(t.getAddress()).then(function(l){return Promise.resolve(c.getNonce(e,l,u)).then(function(f){var h=(f+1).toString();return Promise.resolve(c.getSignature(t,h,ue.GET_LOGS)).then(function(f){var d={startTime:r,endTime:n,signature:f,nonce:h,address:l};return o&&(d.maxLogs=o),i&&(d.moduleName=i),s&&(d.level=s),a&&(d.page=a),c.sendP2pCommand(e,ue.GET_LOGS,d,t,u)})})})}catch(e){return Promise.reject(e)}},t.fetchConfig=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,ue.FETCH_CONFIG,t))}catch(e){return Promise.reject(e)}},t.pushConfig=function(e,t){try{return Promise.resolve(this.sendP2pCommand(e,ue.PUSH_CONFIG,t))}catch(e){return Promise.reject(e)}},e}(),Ba=function(e,t,r){try{if("string"==typeof e)return Promise.resolve(null);var n=String,o=String;return Promise.resolve(e.getAddress()).then(function(i){var s=n(o(i)+String(t)+String(r));return dt(e,s)})}catch(e){return Promise.reject(e)}},Ga=function(e){try{return Promise.resolve("string"==typeof e?function(e){try{return ie.default.decode(e,{json:!0})}catch(e){throw new Error("Error decoding JWT")}}(e).address:e.getAddress())}catch(e){return Promise.reject(e)}};function qa(e){return"string"==typeof e?e:void 0}function Va(e){if(Array.isArray(e))return!0;if(!e)return!1;try{return E.multiaddr(e),!0}catch(e){}try{return ha(e),!0}catch(e){return!1}}var za=/*#__PURE__*/function(){function e(){this.httpProvider=new va,this.p2pProvider=new _a}var t=e.prototype;return t.getImpl=function(e){return Array.isArray(e)||Va(e)?this.p2pProvider:this.httpProvider},t.getNonce=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(e).getNonce(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{return Promise.resolve(this.getImpl(r).encrypt(e,t,r,n,o,i))}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{return Promise.resolve(this.getImpl(r).checkDidFiles(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{return Promise.resolve(this.getImpl(t).getFileInfo(e,t,r,n))}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{return Promise.resolve(this.getImpl(e).getComputeEnvironments(e,t))}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{return Promise.resolve(this.getImpl(o).initialize(e,t,r,n,o,i,s,a,u))}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l){try{return Promise.resolve(this.getImpl(i).initializeCompute(e,t,r,n,o,i,s,a,u,c,l))}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{return Promise.resolve(this.getImpl(o).getDownloadUrl(e,t,r,n,o,i,s,a))}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g){try{return Promise.resolve(this.getImpl(e).computeStart(e,t,r,n,o,i,s,a,u,c,l,f,h,d,m,g))}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,f,h){try{return Promise.resolve(this.getImpl(e).freeComputeStart(e,t,r,n,o,i,s,a,u,c,l,f,h))}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).computeStreamableLogs(e,t,r,n))}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(t).computeStop(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o){try{return Promise.resolve(this.getImpl(e).computeStatus(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).getComputeResultUrl(e,t,r,n))}catch(e){return Promise.reject(e)}},t.getComputeResult=function(e,t,r,n,o){void 0===o&&(o=0);try{return Promise.resolve(this.getImpl(e).getComputeResult(e,t,r,n,o))}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{return Promise.resolve(this.getImpl(t).generateAuthToken(e,t,r))}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{return Promise.resolve(this.getImpl(r).invalidateAuthToken(e,t,r,n))}catch(e){return Promise.reject(e)}},t.resolveDdo=function(e,t,r){try{return Promise.resolve(this.getImpl(e).resolveDdo(e,t,r))}catch(e){return Promise.reject(e)}},t.validateDdo=function(e,t,r,n){try{return Promise.resolve(this.getImpl(e).validateDdo(e,t,r,n))}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(this.getImpl(e).isValidProvider(e,t))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{return Promise.resolve(this.getImpl(e).PolicyServerPassthrough(e,t,r))}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{return Promise.resolve(this.getImpl(e).initializePSVerification(e,t,r))}catch(e){return Promise.reject(e)}},t.downloadNodeLogs=function(e,t,r,n,o,i,s,a,u){try{return Promise.resolve(this.getImpl(e).downloadNodeLogs(e,t,r,n,o,i,s,a,u))}catch(e){return Promise.reject(e)}},t.setupP2P=function(e){try{return Promise.resolve(this.p2pProvider.setupP2P(e))}catch(e){return Promise.reject(e)}},t.getDiscoveredNodes=function(){return this.p2pProvider.getDiscoveredNodes()},t.getMultiaddrFromPeerId=function(e){try{return Promise.resolve(this.p2pProvider.getMultiaddrFromPeerId(e))}catch(e){return Promise.reject(e)}},t.fetchConfig=function(e,t){try{return Promise.resolve(this.p2pProvider.fetchConfig(e,t))}catch(e){return Promise.reject(e)}},t.pushConfig=function(e,t){try{return Promise.resolve(this.p2pProvider.pushConfig(e,t))}catch(e){return Promise.reject(e)}},e}(),Ha=new za;function Ka(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function $a(e,t,r){if(!e.s){if(r instanceof Za){if(!r.s)return void(r.o=$a.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then($a.bind(null,e,t),$a.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Za=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{$a(n,1,i(this.v))}catch(e){$a(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?$a(n,1,t?t(o):o):r?$a(n,1,r(o)):$a(n,2,o)}catch(e){$a(n,2,e)}},n},e}();function Ja(e){return e instanceof Za&&1&e.s}var Wa=/*#__PURE__*/function(){function e(e){this.aquariusURL=void 0,this.aquariusURL=e}var t=e.prototype;return t.resolve=function(e,t,r){try{var n,o=function(o){if(n)return o;var s=i.aquariusURL+"/api/aquarius/assets/ddo/"+e;return Ka(function(){return Promise.resolve(oe.default(s,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return Promise.resolve(e.json());throw new Error("HTTP request failed with status "+e.status)})},function(e){throw we.error(e),new Error("HTTP request failed")})},i=this,s=function(){if(Va(i.aquariusURL))return Promise.resolve(Ha.resolveDdo(i.aquariusURL,e,t)).then(function(e){if(e)return n=1,e;throw new Error("P2P request failed")})}();return Promise.resolve(s&&s.then?s.then(o):o(s))}catch(e){return Promise.reject(e)}},t.waitForIndexer=function(e,t,r,n,o,i){void 0===n&&(n=3e4),void 0===o&&(o=100);try{var s,a=this,u=0;o>500&&(we.warn("Max Limit exceeded, defaulting to 500 retries."),o=500);var c=Va(a.aquariusURL),l=function(e,t){var r;do{var n=e();if(n&&n.then){if(!Ja(n)){r=!0;break}n=n.v}var o=t();if(Ja(o)&&(o=o.v),!o)return n}while(!o.then);var i=new Za,s=$a.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;Ja(o=t())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=e())&&n.then){if(!Ja(n))return void n.then(a).then(void 0,s);n=n.v}}$a(i,1,n)}function u(r){if(r){do{if((n=e())&&n.then){if(!Ja(n))return void n.then(a).then(void 0,s);n=n.v}if(Ja(r=t())&&(r=r.v),!r)return void $a(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else $a(i,1,n)}}(function(){function o(e){return s?e:Promise.resolve(ht(n)).then(function(){u++})}var l=Ka(function(){function n(){if(o){var e=w.DDOManager.getDDOClass(o).getAssetFields().indexedMetadata;if(!t)return s=1,o;if(e.event&&e.event.txid===t)return s=1,o}}var o,u=c?Promise.resolve(Ha.resolveDdo(a.aquariusURL,e,r)).then(function(e){o=e}):Promise.resolve(oe.default(a.aquariusURL+"/api/aquarius/assets/ddo/"+e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:r})).then(function(e){var t=function(){if(e.ok)return Promise.resolve(e.json()).then(function(e){o=e})}();if(t&&t.then)return t.then(function(){})});return u&&u.then?u.then(n):n()},function(){});return l&&l.then?l.then(o):o(l)},function(){return!s&&u<o});return Promise.resolve(l&&l.then?l.then(function(e){return s?e:null}):s?l:null)}catch(e){return Promise.reject(e)}},t.validate=function(e,t,r,n,o){try{if(Va(r))return Promise.resolve(Ha.validateDdo(r,e,t,n));var i=r+"/api/aquarius/assets/ddo/validate",s=r+"/api/services/nonce";return Promise.resolve(Ka(function(){return Promise.resolve(t.getAddress()).then(function(r){return Promise.resolve(oe.default(s+"?userAddress="+r,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o},signal:n})).then(function(o){return Promise.resolve(o.json()).then(function(o){var s=o.nonce;s&&null!==s||(s="0");var a=(Number(s)+1).toString(),u=String,c=String;return Promise.resolve(t.getAddress()).then(function(o){var s=u(c(o)+String(a)+String(ue.VALIDATE_DDO));return Promise.resolve(dt(t,s)).then(function(o){return Promise.resolve(oe.default(i,{method:"POST",body:JSON.stringify({ddo:e,publisherAddress:r,nonce:a,signature:o}),headers:{"Content-Type":"application/json",Authorization:qa(t)},signal:n})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error("Metadata validation failed");return{valid:!0,hash:t.hash,proof:{validatorAddress:t.publicKey,r:t.r[0],s:t.s[0],v:t.v}}})})})})})})})},function(e){we.error("Metadata validation failed",e.message)}))}catch(e){return Promise.reject(e)}},t.getAssetMetadata=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/metadata/"+e;return Promise.resolve(Ka(function(){return Promise.resolve(oe.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("getAssetMetadata failed: "+e.status+e.statusText)})},function(e){throw we.error("Error getting metadata: ",e),new Error("Error getting metadata: "+e)}))}catch(e){return Promise.reject(e)}},t.querySearch=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/query";return Promise.resolve(Ka(function(){return Promise.resolve(oe.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("querySearch failed: "+e.status+e.statusText)})},function(e){throw we.error("Error querying metadata: ",e),new Error("Error querying metadata: "+e)}))}catch(e){return Promise.reject(e)}},e}(),Ya=function(e,t,r,o){try{var i=new n.ethers.Contract(t,ke,e);return Promise.resolve(i.allowance(r,o))}catch(e){return Promise.reject(e)}},Xa=function(e,t,r,o,i){try{var s=new n.ethers.Contract(t,ke,e);return Promise.resolve(s.allowance(r,o)).then(function(r){return Promise.resolve(Fe(e,t,r,i))})}catch(e){return Promise.reject(e)}},Qa=function(e,t,r,o,i,s,a,u){void 0===a&&(a=!1);try{var c,l=function(r){if(c)return r;var n=null;return Promise.resolve(f.approve.estimateGas(i,s)).then(function(r){if(u)return r;var o=function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){return Promise.resolve(Ce(r,e,null==t?void 0:t.gasFeeMultiplier,f.approve,i,s)).then(function(e){n=e})},function(e){we.error("ERROR: Failed to approve spender to spend tokens : "+e.message)});return o&&o.then?o.then(function(){return n}):n})},f=new n.ethers.Contract(o,ke,e),h=function(){if(!a)return Promise.resolve(Ya(e,o,r,i)).then(function(e){if(new V.default(e).isGreaterThan(new V.default(s))){var t=BigInt(e);return c=1,t}})}();return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}},eu=function(e,t,r,o,i,s,a,u,c){void 0===a&&(a=!1);try{var l,f=function(r){return l?r:Promise.resolve(Oe(e,o,s,u)).then(function(r){return Promise.resolve(h.approve.estimateGas(i,r)).then(function(n){return c?new z.default(n.toString()):Promise.resolve(Ce(n,e,null==t?void 0:t.gasFeeMultiplier,h.approve,i,r))})})},h=new n.ethers.Contract(o,ke,e),d=function(){if(!a)return Promise.resolve(Xa(e,o,r,i)).then(function(e){if(new z.default(e).greaterThanOrEqualTo(new z.default(s))){var t=new z.default(e).toNumber();return l=1,t}})}();return Promise.resolve(d&&d.then?d.then(f):f(d))}catch(e){return Promise.reject(e)}},tu={datasets:{invalid:"Datasets is not a list, as expected"},algorithm:{serviceId:{missing:"The serviceId key is missing from the algorithm s DDO.",not_found:"The provided serviceId does not exist.",service_not_access_compute:"Service type is neither access, nor compute.",main_service_compute:"If the main service is not compute for this asset when calling initialize endpoint.",compute_services_not_in_same_provider:"Files attached to the compute service are not decrypted by the correct provider. This occurs when both asset and algorithm are requested by their compute service which cannot be decrypted by a single provider as how it is supposed to be."},container:{checksum_prefix:"Container checksum does not start with the prefix sha256:.",mising_entrypoint_image_checksum:"Either entrypoint, either image, or either checksum are missing from the container dictionary from the algorithm s DDO."},documentId:{did_not_found:"The algorithm s DID could not be retrieved from the metadata store, because the algorithm asset does not exist.",missing:"The documentId key is missing from the algorithm s DDO."},transferTxId:{missing:"The transferTxId key is missing from the algorithm s DDO."},missing_meta_documentId:"Either algorithm metadata, or algorithm DID are missing.",did_not_found:"Either algorithm metadata, or algorithm DID are missing.",not_algo:"Either algorithm metadata, or algorithm DID are missing.",in_use_or_not_on_chain:"Either algorithm metadata, or algorithm DID are missing.",meta_oneof_url_rawcode_remote:"Either algorithm metadata, or algorithm DID are missing.",file_unavailable:"One possibility is that the asset could not be retrieved from Aquariuss database. Otherwise, there are issues related to services"},error:{not_trusted_algo_publisher:"The owner of the algorithm's DDO is not a trusted algorithms publishers list.",not_trusted_algo:"The algorithm's DID is not in the asset's trusted algorithms dictionary. ",no_publisherTrustedAlgorithms:"The algorithm's key publisherTrustedAlgorithms does not exist in the algorithm's DDO.",algorithm_file_checksum_mismatch:"filesChecksum from the algorithm's DDO is invalid.",algorithm_container_checksum_mismatch:"The containerChecksum from the algorithm's DDO is invalid.",no_raw_algo_allowed:"The asset does not allow raw algorithms to be run on it.","Asset malformed":"The asset published on chain is malformed, missing some required keys or not compliant with our schemas.","Asset is not consumable.":"Assets metadata status is not in the range of valid status codes for assets. The recognized states for the metadata are defined on our docs.","DID is not a valid algorithm.":"Either the algorithm assets DID is incorrectly typed, either the algorithm timeout expired.","Compute environment does not exist.":"The compute environment provided by the user does not exist, it is not served by our compute-to-data feature. The user can use get_c2d_environments to check the list of available compute environments.","The validUntil value is not correct.":"validUntil value is most probably expired.","Cannot resolve DID":"The dataset DID does not exist in the Metadata store.","Invalid serviceId":"The serviceId of that dataset is not correct.","Unable to get dataset files":"The files of that dataset could not be decrypted or retrieved","cannot decrypt files for this service.":"The files of that dataset could not be decrypted due to the fact that file object, which contains the structure and the type of specific file, is missing from the validation part.","Unsupported type ":"The file object type is not supported by Provider.","malformed file object":"The file object structure is invalid and does not contain the wanted information for the specific file."},order:{fees_not_paid:" Provider fees are not paid."},output:{invalid:"The algorithms validation after the build stage has not been decoded properly as a dictionary."}};function ru(e,t,r){if(!e.s){if(r instanceof nu){if(!r.s)return void(r.o=ru.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ru.bind(null,e,t),ru.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var nu=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ru(n,1,i(this.v))}catch(e){ru(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ru(n,1,t?t(o):o):r?ru(n,1,r(o)):ru(n,2,o)}catch(e){ru(n,2,e)}},n},e}();function ou(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}e.AccessListContract=st,e.AccesslistFactory=at,e.Aquarius=Wa,e.Config=function(){this.nodeUri=void 0,this.providerAddress=void 0,this.oceanNodeUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.routerFactoryAddress=void 0,this.datatokensABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.EnterpriseFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.sdk=void 0,this.accessListFactory=void 0,this.escrow=void 0},e.ConfigHelper=xe,e.DEVELOPMENT_CHAIN_ID=8996,e.Datatoken=ot,e.Datatoken4=it,e.Dispenser=Ve,e.EnterpriseFeeCollectorContract=ft,e.EscrowContract=lt,e.FEE_HISTORY_NOT_SUPPORTED="Returned error: Method eth_feeHistory not supported.",e.FixedRateExchange=He,e.GASLIMIT_DEFAULT=1e6,e.KNOWN_CONFIDENTIAL_EVMS=Ae,e.Logger=Pe,e.LoggerInstance=we,e.MAX_UINT_256="115792089237316195423570985008687907853269984665640564039457584007913129639934",e.Nft=nt,e.NftFactory=We,e.OCEAN_P2P_PROTOCOL=Ua,e.PROTOCOL_COMMANDS=ue,e.Provider=za,e.ProviderInstance=Ha,e.Router=Ke,e.SmartContract=Ge,e.SmartContractWithAddress=qe,e.ZERO_ADDRESS=ze,e.allowance=Xa,e.allowanceWei=Ya,e.amountToUnits=Oe,e.approve=eu,e.approveWei=Qa,e.balance=function(e,t,r,o){try{var i=new n.ethers.Contract(t,ke,e);return Promise.resolve(i.balanceOf(r)).then(function(r){return Promise.resolve(Fe(e,t,r,o))})}catch(e){return Promise.reject(e)}},e.calculateActiveTemplateIndex=et,e.configHelperNetworks=Se,e.createAccessListFactory=function(e,t,r){try{var o=new n.ethers.Contract(e,te.default.abi,t);return Promise.resolve(t.getAddress()).then(function(e){var t,n=ou(function(){return Promise.resolve(o.deployAccessListContract("AllowList","ALLOW",!0,e,r||[e],["https://oceanprotocol.com/nft/"])).then(function(e){return function(){if(e&&e.wait)return Promise.resolve(e.wait()).then(function(e){var r=Be(e,"NewAccessList");return t=1,r.args[0]})}()})},function(e){console.log("ERROR createAccessListFactory(): ",e)});return n&&n.then?n.then(function(e){return t?e:null}):t?n:null})}catch(e){return Promise.reject(e)}},e.createAsset=function(e,t,r,o,i,s,a,u,c,l,f,h,d,m,g){void 0===a&&(a=!0);try{var v,p,y=this,b=w.DDOManager.getDDOClass(s),P=b.getAssetFields().indexedMetadata,E=(null==(v=b.getDDOData())||null==(v=v.stats)||null==(v=v.price)?void 0:v.value)||(null==P||null==(p=P.stats[0])||null==(p=p.prices[0])?void 0:p.price),S=b.getDDOFields(),A=S.chainId,T=S.nftAddress,x=b.getDDOFields().services;if("string"!=typeof i&&"number"!=typeof i)throw new Error('Invalid template! Must be a "number" or a "string"');return Promise.resolve(r.provider.getNetwork()).then(function(v){var p=v.chainId;if(A&&A!==Number(p))throw new Error("Chain ID from DDO is different than the configured network.");var P=(new xe).getConfig(parseInt(String(p)));return Promise.resolve(et(r,P.nftFactoryAddress,i,Number(p))).then(function(i){if(i<1){if(8996!==Number(p))throw new Error("Invalid template index: "+i);i=1}var v=new nt(r,Number(p)),w=new We(P.nftFactoryAddress,r,Number(p));return Promise.resolve(r.getAddress()).then(function(S){var k;function C(e){return k?e:Promise.resolve(O.wait()).then(function(e){var t;function o(e){if(t)return e;function o(){function e(){var e=v.setMetadata,a=T;return Promise.resolve(r.getAddress()).then(function(r){return Promise.resolve(e.call(v,a,r,0,u,"",n.toBeHex(i),t,o)).then(function(){return s.id})})}x[0].datatokenAddress=h,x[0].serviceEndpoint=u;var t,o,i,c=b.makeDid(T=f,A.toString());s=b.updateFields({id:c,nftAddress:T});var d=function(){if(a)return Promise.resolve(Ha.encrypt(s,Number(p),u,r,null)).then(function(e){return t=e,Promise.resolve(l.validate(s,r,u)).then(function(e){o=e.hash,i=2})});var e=JSON.stringify(s),c=Buffer.from(e);t=n.hexlify(c),o="0x"+N.createHash("sha256").update(t).digest("hex"),i=0}();return d&&d.then?d.then(e):e()}var i=function(){if("oasis"!==P.sdk)return Promise.resolve(Ha.encrypt(j,Number(p),u,r,null)).then(function(e){x[0].files=e});x[0].files=""}();return i&&i.then?i.then(o):o()}var i=Be(e,"NFTCreated"),c=Be(e,"TokenCreated"),f=i.args.newTokenAddress,h=c.args.newTokenAddress;j.datatokenAddress=h,j.nftAddress=f;var d=function(){if("oasis"===P.sdk){var e=new n.ethers.Contract(h,Q.default.abi,r);return ou(function(){return Promise.resolve(e.setFilesObject(n.toUtf8Bytes(JSON.stringify(j)))).then(function(e){var t=function(){if(e.wait)return Promise.resolve(e.wait()).then(function(){})}();if(t&&t.then)return t.then(function(){})})},function(e){return console.log("Error updating files object with data token and nft addresses: ",e),t=1,null})}}();return d&&d.then?d.then(o):o(d)})}var O,F={name:e,symbol:t,templateIndex:1,tokenURI:"aaa",transferable:!0,owner:S},D={templateIndex:i,cap:"100000",feeAmount:"0",paymentCollector:S,feeToken:c||P.oceanTokenAddress,minter:S,mpFeeAddress:ze},j={nftAddress:"0x0",datatokenAddress:"0x0",files:o};"oasis"===P.sdk&&(D.filesObject=j,D.accessListFactory=f||P.accessListFactory,D.allowAccessList=h,D.denyAccessList=d);var I=ou(function(){var e=function(){if(!E)return Promise.resolve(w.createNftWithDatatoken(F,D)).then(function(e){O=e});var e=function(){if("0"===E.toString())return Promise.resolve(w.createNftWithDatatokenWithDispenser(F,D,{dispenserAddress:P.dispenserAddress,maxTokens:"1",maxBalance:"100000000",withMint:!0,allowedSwapper:ze})).then(function(e){O=e});var e=m||P.oceanTokenAddress;return Promise.resolve(De(y.signer,e)).then(function(t){g||(g=t);var r={fixedRateAddress:P.fixedRateExchangeAddress,baseTokenAddress:e,owner:S,marketFeeCollector:S,baseTokenDecimals:g,datatokenDecimals:18,fixedRate:E.toString(),marketFee:"0",allowedConsumer:S,withMint:!0};return Promise.resolve(w.createNftWithDatatokenWithFixedRate(F,D,r)).then(function(e){O=e})})}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})},function(e){return console.log("ERROR creating NFT bundle",e),k=1,null});return I&&I.then?I.then(C):C(I)})})})}catch(e){return Promise.reject(e)}},e.decimals=function(e,t){try{var r=new n.ethers.Contract(t,ke,e);return Promise.resolve(r.decimals()).then(Number)}catch(e){return Promise.reject(e)}},e.downloadFile=function(e,t){try{return"string"!=typeof e?Promise.resolve(e):Promise.resolve(fetch(e)).then(function(r){if(!r.ok)throw new Error("Response error.");var n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(r){try{n=e.split("/").pop()}catch(e){n="file"+t}}return Promise.resolve(r.arrayBuffer()).then(function(e){return{data:e,filename:n}})})}catch(e){return Promise.reject(e)}},e.downloadFileBrowser=function(e){var t=new XMLHttpRequest;t.responseType="blob",t.open("GET",e),t.onload=function(){var e=t.getResponseHeader("content-disposition"),r=null==e?void 0:e.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/),n=r&&r[1]?r[1]:"file",o=window.URL.createObjectURL(t.response),i=document.createElement("a");i.href=o,i.setAttribute("download",n),document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(o)},t.send()},e.generateDid=function(e,t){return e=n.getAddress(e),"did:op:"+se.default(e+t.toString(10)).toString()},e.generateDtName=Ze,e.getErrorMessage=function(e){try{var t=JSON.parse(e),r=Object.keys(t)[0];if("error"===r){var n,o=t[r];return(null==(n=tu[r])?void 0:n[o])||"Provider request failed: "+o}var i=t[r];return t[Object.keys(t)[1]]+" : "+i}catch(t){return we.error("[getErrorMessage] error: ",t),e}},e.getEventFromTx=Be,e.getFairGasPrice=je,e.getHash=function(e){return se.default(e).toString()},e.getNodeEndpointConfig=Te,e.getOceanArtifactsAddresses=tt,e.getOceanArtifactsAddressesByChainId=rt,e.getTokenDecimals=De,e.isDefined=function(e){return null!=e},e.isP2pUri=Va,e.minAbi=ke,e.orderAsset=function(e,t,r,n,o,i,s,a,u,c,l,f){void 0===u&&(u="0"),void 0===c&&(c=0),void 0===l&&(l=0),void 0===f&&(f=0);try{var h=w.DDOManager.getDDOClass(e),d=h.getAssetFields().datatokens,m=h.getDDOFields(),g=m.chainId,v=m.services;return s||(s={consumeMarketFeeAddress:"0x0000000000000000000000000000000000000000",consumeMarketFeeAmount:"0",consumeMarketFeeToken:"0x0000000000000000000000000000000000000000"}),Promise.resolve(t.provider.getNetwork()).then(function(h){if(g!==Number(h.chainId))throw new Error("Chain ID from DDO is different than the configured network.");if(!d[c].address)throw new Error("The datatoken with index: "+c+" does not exist for the asset with did: "+e.id);if(!v[l].id)throw new Error("There is no service with index: "+l+" defined for the asset with did: "+e.id);return Promise.resolve(n.getId(d[c].address)).then(function(h){return Promise.resolve(n.getFixedRates(d[c].address)).then(function(m){return Promise.resolve(n.getDispensers(d[c].address)).then(function(g){return Promise.resolve(n.getPublishingMarketFee(d[c].address)).then(function(p){function y(e){return a?e:Promise.resolve(w.call(Ha,S,E,0,e,o||r.oceanNodeUri)).then(b)}function b(o){function g(o){function a(o){var i,a={consumer:o,serviceIndex:l,_providerFee:y,_consumeMarketFee:s};return function(e,t){var r,n=-1;e:{for(var o=0;o<t.length;o++){var i=t[o][0];if(i){var s=i();if(s&&s.then)break e;if(s===e){n=o;break}}else n=o}if(-1!==n){do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then){r=!0;break e}var c=t[n][2];n++}while(c&&!c());return u}}var l=new nu,f=ru.bind(null,l,2);return(r?u.then(h):s.then(function r(s){for(;;){if(s===e){n=o;break}if(++o===t.length){if(-1!==n)break;return void ru(l,1,u)}if(i=t[o][0]){if((s=i())&&s.then)return void s.then(r).then(void 0,f)}else n=o}do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then)return void u.then(h).then(void 0,f);var c=t[n][2];n++}while(c&&!c());ru(l,1,u)})).then(void 0,f),l;function h(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var o=t[n][1];!o;)n++,o=t[n][1];if((e=o())&&e.then)return void e.then(h).then(void 0,f)}ru(l,1,e)}}(P,[[function(){return"free"},function(){var e=function(e){var t;if(i)return e;function o(e){if(t)return e}var s=function(){if(2===h||4===h)return Promise.resolve(n.buyFromDispenserAndOrder(v[l].datatokenAddress,a,r.dispenserAddress)).then(function(e){return t=1,e})}();return s&&s.then?s.then(o):o(s)},o=function(){if(1===h){var e=new Ve(r.dispenserAddress,t),o=e.dispense,s=d[c].address;return Promise.resolve(t.getAddress()).then(function(t){return Promise.resolve(o.call(e,s,"1",t)).then(function(e){if(!e)throw new Error("Failed to dispense !");return Promise.resolve(e.wait()).then(function(){return Promise.resolve(n.startOrder(d[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return i=1,e})})})})}}();return o&&o.then?o.then(e):e(o)}],[function(){return"fixed"},function(){var o=new He(r.fixedRateExchangeAddress,t);if(!m[f].id)throw new Error("There is no fixed rate exchange with index: "+l+" for the asset with did: "+e.id);return Promise.resolve(o.getFeesInfo(m[f].id)).then(function(e){return Promise.resolve(o.getExchange(m[f].id)).then(function(i){return Promise.resolve(o.calcBaseInGivenDatatokensOut(e.exchangeId,"1",s.consumeMarketFeeAmount)).then(function(l){var f;function m(e){var o;if(f)return e;function s(e){if(o)return e}var u=function(){if(2===h||4===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(eu(t,r,e,i.baseToken,d[c].address,g,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to confirm/mine approval transaction!");return Promise.resolve(n.buyFromFreAndOrder(d[c].address,a,v)).then(function(e){return o=1,e})}if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return u&&u.then?u.then(s):s(u)}var g=new z.default(+l.baseTokenAmount||0).add(new z.default(s.consumeMarketFeeAmount||0)).add(new z.default(+p.publishMarketFeeAmount||0)).toString(),v={exchangeContract:r.fixedRateExchangeAddress,exchangeId:e.exchangeId,maxBaseTokenAmount:g,baseTokenAddress:i.baseToken,baseTokenDecimals:parseInt(i.btDecimals)||18,swapMarketFee:u,marketFeeAddress:p.publishMarketFeeAddress},y=function(){if(1===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(eu(t,r,e,i.baseToken,r.fixedRateExchangeAddress,g,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return Promise.resolve(o.buyDatatokens(i.exchangeId,"1",g,p.publishMarketFeeAddress,u)).then(function(e){return Promise.resolve(e.wait()).then(function(e){if(!e)throw new Error("Failed to buy datatoken from fixed rate!");return Promise.resolve(n.startOrder(d[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return f=1,e})})})}return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return y&&y.then?y.then(m):m(y)})})})}],[void 0,function(){throw new Error("Pricing schema not supported !")}]])}return i?a(i):Promise.resolve(t.getAddress()).then(a)}var y=a||o.providerFee,b=function(){if(y&&y.providerFeeAddress!==ze&&y.providerFeeAmount&&parseInt(y.providerFeeAmount)>0)return function(e,n){try{var o=Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(Qa(t,r,e,y.providerFeeToken,v[0].datatokenAddress,y.providerFeeAmount)).then(function(){})})}catch(e){return n()}return o&&o.then?o.then(void 0,n):o}(0,function(){throw new Error("Failed to approve provider fee token "+y.providerFeeToken)})}();return b&&b.then?b.then(g):g()}var P=m.length>0?"fixed":g.length>0?"free":"NOT_ALLOWED",w=a||Ha.initialize,E=a||v[l].id,S=a||e.id;return a?y(b(a)):Promise.resolve(t.getAddress()).then(y)})})})})})}catch(e){return Promise.reject(e)}},e.sendTx=Ce,e.setContractDefaults=_e,e.signHash=function(e,t){try{var r=n.getBytes(t);return Promise.resolve(e._legacySignMessage(r)).then(function(e){var t="0x"+(e=e.substr(2)).slice(0,64),r="0x"+e.slice(64,128),n="0x"+e.slice(128,130);return"0x00"===n&&(n="0x1b"),"0x01"===n&&(n="0x1c"),{v:n,r:t,s:r}})}catch(e){return Promise.reject(e)}},e.signRequest=dt,e.sleep=ht,e.transfer=function(e,t,r,o,i,s,a){try{var u=new n.ethers.Contract(r,ke,e);return Promise.resolve(Oe(e,r,i,s)).then(function(r){return Promise.resolve(u.transfer.estimateGas(o,r)).then(function(n){return a?n:Promise.resolve(Ce(n,e,null==t?void 0:t.gasFeeMultiplier,u.transfer,o,r))})})}catch(e){return Promise.reject(e)}},e.unitsToAmount=Fe,e.useOasisSDK=function(e){var t=(new xe).getConfig(e);return t&&"oasis"===t.sdk}});
|
|
4
4
|
//# sourceMappingURL=lib.umd.js.map
|