From e9c2ca82e03e4882745bde8f46504e9add3e3ef7 Mon Sep 17 00:00:00 2001 From: John Imeobong Date: Sun, 21 Jun 2026 23:23:32 +0000 Subject: [PATCH] Add integration tests for vault client functionality - Implement tests for deposit, task creation, payment release, and withdrawal. - Include checks for available balance adjustments and task state validation. - Utilize Vitest for concurrent test execution and setup. - Ensure proper handling of edge cases, such as double release on completed tasks and insufficient balance for task creation. --- package.json | 3 +- packages/orchestrator/package.json | 3 +- .../{index-BqN1E352.js => index-90giOIxm.js} | 60 +-- packages/orchestrator/public/index.html | 4 +- .../vault-client.integration.test.ts | 351 ++++++++++++++++++ 5 files changed, 387 insertions(+), 34 deletions(-) rename packages/orchestrator/public/assets/{index-BqN1E352.js => index-90giOIxm.js} (76%) create mode 100644 packages/orchestrator/src/__tests__/vault-client.integration.test.ts diff --git a/package.json b/package.json index e9f755a..aaad36a 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "lint": "eslint .", "format": "prettier --write .", "format:check": "prettier --check .", - "test": "vitest run" + "test": "vitest run --excludeTags integration", + "test:integration": "vitest run --tag integration" }, "devDependencies": { "@eslint/js": "^9.39.4", diff --git a/packages/orchestrator/package.json b/packages/orchestrator/package.json index b87c4d9..0ab49c2 100644 --- a/packages/orchestrator/package.json +++ b/packages/orchestrator/package.json @@ -4,7 +4,8 @@ "type": "module", "scripts": { "dev": "npx tsx src/server.ts", - "start": "node dist/server.js" + "start": "node dist/server.js", + "test:integration": "vitest run src/__tests__/*.integration.test.ts --tag integration" }, "dependencies": { "@clevercon/common": "*", diff --git a/packages/orchestrator/public/assets/index-BqN1E352.js b/packages/orchestrator/public/assets/index-90giOIxm.js similarity index 76% rename from packages/orchestrator/public/assets/index-BqN1E352.js rename to packages/orchestrator/public/assets/index-90giOIxm.js index c52415b..6b6568f 100644 --- a/packages/orchestrator/public/assets/index-BqN1E352.js +++ b/packages/orchestrator/public/assets/index-90giOIxm.js @@ -14,7 +14,7 @@ var P6=Object.defineProperty;var G6=(e,t,r)=>t in e?P6(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var gp=Symbol.for("react.transitional.element"),X6=Symbol.for("react.portal"),Z6=Symbol.for("react.fragment"),Q6=Symbol.for("react.strict_mode"),J6=Symbol.for("react.profiler"),W6=Symbol.for("react.consumer"),e5=Symbol.for("react.context"),t5=Symbol.for("react.forward_ref"),r5=Symbol.for("react.suspense"),n5=Symbol.for("react.memo"),Qx=Symbol.for("react.lazy"),a5=Symbol.for("react.activity"),lb=Symbol.iterator;function i5(e){return e===null||typeof e!="object"?null:(e=lb&&e[lb]||e["@@iterator"],typeof e=="function"?e:null)}var Jx={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Wx=Object.assign,ey={};function Ho(e,t,r){this.props=e,this.context=t,this.refs=ey,this.updater=r||Jx}Ho.prototype.isReactComponent={};Ho.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};Ho.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function ty(){}ty.prototype=Ho.prototype;function vp(e,t,r){this.props=e,this.context=t,this.refs=ey,this.updater=r||Jx}var wp=vp.prototype=new ty;wp.constructor=vp;Wx(wp,Ho.prototype);wp.isPureReactComponent=!0;var cb=Array.isArray;function J0(){}var Vt={H:null,A:null,T:null,S:null},ry=Object.prototype.hasOwnProperty;function _p(e,t,r){var n=r.ref;return{$$typeof:gp,type:e,key:t,ref:n!==void 0?n:null,props:r}}function s5(e,t){return _p(e.type,t,e.props)}function Sp(e){return typeof e=="object"&&e!==null&&e.$$typeof===gp}function o5(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(r){return t[r]})}var ub=/\/+/g;function Md(e,t){return typeof e=="object"&&e!==null&&e.key!=null?o5(""+e.key):t.toString(36)}function l5(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:switch(typeof e.status=="string"?e.then(J0,J0):(e.status="pending",e.then(function(t){e.status==="pending"&&(e.status="fulfilled",e.value=t)},function(t){e.status==="pending"&&(e.status="rejected",e.reason=t)})),e.status){case"fulfilled":return e.value;case"rejected":throw e.reason}}throw e}function Vs(e,t,r,n,a){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var s=!1;if(e===null)s=!0;else switch(i){case"bigint":case"string":case"number":s=!0;break;case"object":switch(e.$$typeof){case gp:case X6:s=!0;break;case Qx:return s=e._init,Vs(s(e._payload),t,r,n,a)}}if(s)return a=a(e),s=n===""?"."+Md(e,0):n,cb(a)?(r="",s!=null&&(r=s.replace(ub,"$&/")+"/"),Vs(a,t,r,"",function(h){return h})):a!=null&&(Sp(a)&&(a=s5(a,r+(a.key==null||e&&e.key===a.key?"":(""+a.key).replace(ub,"$&/")+"/")+s)),t.push(a)),1;s=0;var o=n===""?".":n+":";if(cb(e))for(var c=0;ct in e?P6(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */(function(e){function t(S,j){var R=S.length;S.push(j);e:for(;0>>1,d=S[N];if(0>>1;Na(he,R))qa(G,he)?(S[N]=G,S[q]=R,N=q):(S[N]=he,S[ae]=R,N=ae);else if(qa(G,R))S[N]=G,S[q]=R,N=q;else break e}}return j}function a(S,j){var R=S.sortIndex-j.sortIndex;return R!==0?R:S.id-j.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var s=Date,o=s.now();e.unstable_now=function(){return s.now()-o}}var c=[],h=[],p=1,y=null,g=3,v=!1,M=!1,k=!1,K=!1,D=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,z=typeof setImmediate<"u"?setImmediate:null;function L(S){for(var j=r(h);j!==null;){if(j.callback===null)n(h);else if(j.startTime<=S)n(h),j.sortIndex=j.expirationTime,t(c,j);else break;j=r(h)}}function $(S){if(k=!1,L(S),!M)if(r(c)!==null)M=!0,F||(F=!0,u());else{var j=r(h);j!==null&&E($,j.startTime-S)}}var F=!1,V=-1,J=5,Y=-1;function te(){return K?!0:!(e.unstable_now()-YS&&te());){var N=y.callback;if(typeof N=="function"){y.callback=null,g=y.priorityLevel;var d=N(y.expirationTime<=S);if(S=e.unstable_now(),typeof d=="function"){y.callback=d,L(S),j=!0;break t}y===r(c)&&n(c),L(S)}else n(c);y=r(c)}if(y!==null)j=!0;else{var C=r(h);C!==null&&E($,C.startTime-S),j=!1}}break e}finally{y=null,g=R,v=!1}j=void 0}}finally{j?u():F=!1}}}var u;if(typeof z=="function")u=function(){z(x)};else if(typeof MessageChannel<"u"){var f=new MessageChannel,_=f.port2;f.port1.onmessage=x,u=function(){_.postMessage(null)}}else u=function(){D(x,0)};function E(S,j){V=D(function(){S(e.unstable_now())},j)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(S){S.callback=null},e.unstable_forceFrameRate=function(S){0>S||125N?(S.sortIndex=R,t(h,S),r(c)===null&&S===r(h)&&(k?(T(V),V=-1):k=!0,E($,R-N))):(S.sortIndex=d,t(c,S),M||v||(M=!0,F||(F=!0,u()))),S},e.unstable_shouldYield=te,e.unstable_wrapCallback=function(S){var j=g;return function(){var R=g;g=j;try{return S.apply(this,arguments)}finally{g=R}}}})(iy);ay.exports=iy;var f5=ay.exports,sy={exports:{}},Qr={};/** + */(function(e){function t(S,j){var R=S.length;S.push(j);e:for(;0>>1,h=S[N];if(0>>1;Na(he,R))qa(G,he)?(S[N]=G,S[q]=R,N=q):(S[N]=he,S[ae]=R,N=ae);else if(qa(G,R))S[N]=G,S[q]=R,N=q;else break e}}return j}function a(S,j){var R=S.sortIndex-j.sortIndex;return R!==0?R:S.id-j.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var s=Date,o=s.now();e.unstable_now=function(){return s.now()-o}}var c=[],d=[],p=1,y=null,g=3,v=!1,M=!1,z=!1,K=!1,D=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,k=typeof setImmediate<"u"?setImmediate:null;function L(S){for(var j=r(d);j!==null;){if(j.callback===null)n(d);else if(j.startTime<=S)n(d),j.sortIndex=j.expirationTime,t(c,j);else break;j=r(d)}}function $(S){if(z=!1,L(S),!M)if(r(c)!==null)M=!0,F||(F=!0,u());else{var j=r(d);j!==null&&E($,j.startTime-S)}}var F=!1,V=-1,J=5,Y=-1;function ee(){return K?!0:!(e.unstable_now()-YS&&ee());){var N=y.callback;if(typeof N=="function"){y.callback=null,g=y.priorityLevel;var h=N(y.expirationTime<=S);if(S=e.unstable_now(),typeof h=="function"){y.callback=h,L(S),j=!0;break t}y===r(c)&&n(c),L(S)}else n(c);y=r(c)}if(y!==null)j=!0;else{var C=r(d);C!==null&&E($,C.startTime-S),j=!1}}break e}finally{y=null,g=R,v=!1}j=void 0}}finally{j?u():F=!1}}}var u;if(typeof k=="function")u=function(){k(x)};else if(typeof MessageChannel<"u"){var f=new MessageChannel,_=f.port2;f.port1.onmessage=x,u=function(){_.postMessage(null)}}else u=function(){D(x,0)};function E(S,j){V=D(function(){S(e.unstable_now())},j)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(S){S.callback=null},e.unstable_forceFrameRate=function(S){0>S||125N?(S.sortIndex=R,t(d,S),r(c)===null&&S===r(d)&&(z?(T(V),V=-1):z=!0,E($,R-N))):(S.sortIndex=h,t(c,S),M||v||(M=!0,F||(F=!0,u()))),S},e.unstable_shouldYield=ee,e.unstable_wrapCallback=function(S){var j=g;return function(){var R=g;g=j;try{return S.apply(this,arguments)}finally{g=R}}}})(iy);ay.exports=iy;var f5=ay.exports,sy={exports:{}},Qr={};/** * @license React * react-dom.production.js * @@ -38,15 +38,15 @@ var P6=Object.defineProperty;var G6=(e,t,r)=>t in e?P6(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var _r=f5,cy=re,m5=b5;function xe(e){var t="https://react.dev/errors/"+e;if(1eo||(e.current=ah[eo],ah[eo]=null,eo--)}function Kt(e,t){eo++,ah[eo]=e.current,e.current=t}var da=Sa(null),Vl=Sa(null),Ei=Sa(null),Lu=Sa(null);function Hu(e,t){switch(Kt(Ei,t),Kt(Vl,e),Kt(da,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?gm(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=gm(t),e=kg(t,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}Tr(da),Kt(da,e)}function vo(){Tr(da),Tr(Vl),Tr(Ei)}function ih(e){e.memoizedState!==null&&Kt(Lu,e);var t=da.current,r=kg(t,e.type);t!==r&&(Kt(Vl,e),Kt(da,r))}function qu(e){Vl.current===e&&(Tr(da),Tr(Vl)),Lu.current===e&&(Tr(Lu),ic._currentValue=cs)}var Cd,pb;function ns(e){if(Cd===void 0)try{throw Error()}catch(r){var t=r.stack.trim().match(/\n( *(at )?)/);Cd=t&&t[1]||"",pb=-1eo||(e.current=ah[eo],ah[eo]=null,eo--)}function Kt(e,t){eo++,ah[eo]=e.current,e.current=t}var ha=Ea(null),Vl=Ea(null),Ei=Ea(null),Lu=Ea(null);function Hu(e,t){switch(Kt(Ei,t),Kt(Vl,e),Kt(ha,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?gm(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=gm(t),e=kg(t,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}Tr(ha),Kt(ha,e)}function vo(){Tr(ha),Tr(Vl),Tr(Ei)}function ih(e){e.memoizedState!==null&&Kt(Lu,e);var t=ha.current,r=kg(t,e.type);t!==r&&(Kt(Vl,e),Kt(ha,r))}function qu(e){Vl.current===e&&(Tr(ha),Tr(Vl)),Lu.current===e&&(Tr(Lu),ic._currentValue=cs)}var Cd,pb;function ns(e){if(Cd===void 0)try{throw Error()}catch(r){var t=r.stack.trim().match(/\n( *(at )?)/);Cd=t&&t[1]||"",pb=-1)":-1a||c[n]!==h[a]){var p=` +`),d=o.split(` +`);for(a=n=0;na||c[n]!==d[a]){var p=` `+c[n].replace(" at new "," at ");return e.displayName&&p.includes("")&&(p=p.replace("",e.displayName)),p}while(1<=n&&0<=a);break}}}finally{Bd=!1,Error.prepareStackTrace=r}return(r=e?e.displayName||e.name:"")?ns(r):""}function w5(e,t){switch(e.tag){case 26:case 27:case 5:return ns(e.type);case 16:return ns("Lazy");case 13:return e.child!==t&&t!==null?ns("Suspense Fallback"):ns("Suspense");case 19:return ns("SuspenseList");case 0:case 15:return Od(e.type,!1);case 11:return Od(e.type.render,!1);case 1:return Od(e.type,!0);case 31:return ns("Activity");default:return""}}function bb(e){try{var t="",r=null;do t+=w5(e,r),r=e,e=e.return;while(e);return t}catch(n){return` Error generating stack: `+n.message+` -`+n.stack}}var sh=Object.prototype.hasOwnProperty,Np=_r.unstable_scheduleCallback,Rd=_r.unstable_cancelCallback,_5=_r.unstable_shouldYield,S5=_r.unstable_requestPaint,An=_r.unstable_now,E5=_r.unstable_getCurrentPriorityLevel,my=_r.unstable_ImmediatePriority,xy=_r.unstable_UserBlockingPriority,$u=_r.unstable_NormalPriority,A5=_r.unstable_LowPriority,yy=_r.unstable_IdlePriority,N5=_r.log,j5=_r.unstable_setDisableYieldValue,mc=null,Nn=null;function yi(e){if(typeof N5=="function"&&j5(e),Nn&&typeof Nn.setStrictMode=="function")try{Nn.setStrictMode(mc,e)}catch{}}var jn=Math.clz32?Math.clz32:C5,T5=Math.log,M5=Math.LN2;function C5(e){return e>>>=0,e===0?32:31-(T5(e)/M5|0)|0}var Vc=256,Xc=262144,Zc=4194304;function as(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Of(e,t,r){var n=e.pendingLanes;if(n===0)return 0;var a=0,i=e.suspendedLanes,s=e.pingedLanes;e=e.warmLanes;var o=n&134217727;return o!==0?(n=o&~i,n!==0?a=as(n):(s&=o,s!==0?a=as(s):r||(r=o&~e,r!==0&&(a=as(r))))):(o=n&~i,o!==0?a=as(o):s!==0?a=as(s):r||(r=n&~e,r!==0&&(a=as(r)))),a===0?0:t!==0&&t!==a&&!(t&i)&&(i=a&-a,r=t&-t,i>=r||i===32&&(r&4194048)!==0)?t:a}function xc(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function B5(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function gy(){var e=Zc;return Zc<<=1,!(Zc&62914560)&&(Zc=4194304),e}function Ud(e){for(var t=[],r=0;31>r;r++)t.push(e);return t}function yc(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function O5(e,t,r,n,a,i){var s=e.pendingLanes;e.pendingLanes=r,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=r,e.entangledLanes&=r,e.errorRecoveryDisabledLanes&=r,e.shellSuspendCounter=0;var o=e.entanglements,c=e.expirationTimes,h=e.hiddenUpdates;for(r=s&~r;0"u")return null;try{return e.activeElement||e.body}catch{return e.body}}var I5=/[\n"\\]/g;function qn(e){return e.replace(I5,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function ch(e,t,r,n,a,i,s,o){e.name="",s!=null&&typeof s!="function"&&typeof s!="symbol"&&typeof s!="boolean"?e.type=s:e.removeAttribute("type"),t!=null?s==="number"?(t===0&&e.value===""||e.value!=t)&&(e.value=""+In(t)):e.value!==""+In(t)&&(e.value=""+In(t)):s!=="submit"&&s!=="reset"||e.removeAttribute("value"),t!=null?uh(e,s,In(t)):r!=null?uh(e,s,In(r)):n!=null&&e.removeAttribute("value"),a==null&&i!=null&&(e.defaultChecked=!!i),a!=null&&(e.checked=a&&typeof a!="function"&&typeof a!="symbol"),o!=null&&typeof o!="function"&&typeof o!="symbol"&&typeof o!="boolean"?e.name=""+In(o):e.removeAttribute("name")}function Ty(e,t,r,n,a,i,s,o){if(i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"&&(e.type=i),t!=null||r!=null){if(!(i!=="submit"&&i!=="reset"||t!=null)){lh(e);return}r=r!=null?""+In(r):"",t=t!=null?""+In(t):r,o||t===e.value||(e.value=t),e.defaultValue=t}n=n??a,n=typeof n!="function"&&typeof n!="symbol"&&!!n,e.checked=o?e.checked:!!n,e.defaultChecked=!!n,s!=null&&typeof s!="function"&&typeof s!="symbol"&&typeof s!="boolean"&&(e.name=s),lh(e)}function uh(e,t,r){t==="number"&&Fu(e.ownerDocument)===e||e.defaultValue===""+r||(e.defaultValue=""+r)}function po(e,t,r,n){if(e=e.options,t){t={};for(var a=0;a"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),dh=!1;if(Ga)try{var cl={};Object.defineProperty(cl,"passive",{get:function(){dh=!0}}),window.addEventListener("test",cl,cl),window.removeEventListener("test",cl,cl)}catch{dh=!1}var gi=null,Op=null,wu=null;function Ry(){if(wu)return wu;var e,t=Op,r=t.length,n,a="value"in gi?gi.value:gi.textContent,i=a.length;for(e=0;e=Cl),Nb=" ",jb=!1;function ky(e,t){switch(e){case"keyup":return d4.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function zy(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var no=!1;function p4(e,t){switch(e){case"compositionend":return zy(t);case"keypress":return t.which!==32?null:(jb=!0,Nb);case"textInput":return e=t.data,e===Nb&&jb?null:e;default:return null}}function b4(e,t){if(no)return e==="compositionend"||!Up&&ky(e,t)?(e=Ry(),wu=Op=gi=null,no=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:r,offset:t-e};e=n}e:{for(;r;){if(r.nextSibling){r=r.nextSibling;break e}r=r.parentNode}r=void 0}r=Ob(r)}}function Hy(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Hy(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function qy(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Fu(e.document);t instanceof e.HTMLIFrameElement;){try{var r=typeof t.contentWindow.location.href=="string"}catch{r=!1}if(r)e=t.contentWindow;else break;t=Fu(e.document)}return t}function kp(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}var S4=Ga&&"documentMode"in document&&11>=document.documentMode,ao=null,hh=null,Ol=null,ph=!1;function Ub(e,t,r){var n=r.window===r?r.document:r.nodeType===9?r:r.ownerDocument;ph||ao==null||ao!==Fu(n)||(n=ao,"selectionStart"in n&&kp(n)?n={start:n.selectionStart,end:n.selectionEnd}:(n=(n.ownerDocument&&n.ownerDocument.defaultView||window).getSelection(),n={anchorNode:n.anchorNode,anchorOffset:n.anchorOffset,focusNode:n.focusNode,focusOffset:n.focusOffset}),Ol&&Ql(Ol,n)||(Ol=n,n=lf(hh,"onSelect"),0>=s,a-=s,la=1<<32-jn(t)+a|r<J?(Y=V,V=null):Y=V.sibling;var te=g(D,V,z[J],L);if(te===null){V===null&&(V=Y);break}e&&V&&te.alternate===null&&t(D,V),T=i(te,T,J),F===null?$=te:F.sibling=te,F=te,V=Y}if(J===z.length)return r(D,V),vt&&ka(D,J),$;if(V===null){for(;JJ?(Y=V,V=null):Y=V.sibling;var x=g(D,V,te.value,L);if(x===null){V===null&&(V=Y);break}e&&V&&x.alternate===null&&t(D,V),T=i(x,T,J),F===null?$=x:F.sibling=x,F=x,V=Y}if(te.done)return r(D,V),vt&&ka(D,J),$;if(V===null){for(;!te.done;J++,te=z.next())te=y(D,te.value,L),te!==null&&(T=i(te,T,J),F===null?$=te:F.sibling=te,F=te);return vt&&ka(D,J),$}for(V=n(V);!te.done;J++,te=z.next())te=v(V,D,J,te.value,L),te!==null&&(e&&te.alternate!==null&&V.delete(te.key===null?J:te.key),T=i(te,T,J),F===null?$=te:F.sibling=te,F=te);return e&&V.forEach(function(u){return t(D,u)}),vt&&ka(D,J),$}function K(D,T,z,L){if(typeof z=="object"&&z!==null&&z.type===Ws&&z.key===null&&(z=z.props.children),typeof z=="object"&&z!==null){switch(z.$$typeof){case Yc:e:{for(var $=z.key;T!==null;){if(T.key===$){if($=z.type,$===Ws){if(T.tag===7){r(D,T.sibling),L=a(T,z.props.children),L.return=D,D=L;break e}}else if(T.elementType===$||typeof $=="object"&&$!==null&&$.$$typeof===ci&&is($)===T.type){r(D,T.sibling),L=a(T,z.props),fl(L,z),L.return=D,D=L;break e}r(D,T);break}else t(D,T);T=T.sibling}z.type===Ws?(L=us(z.props.children,D.mode,L,z.key),L.return=D,D=L):(L=Su(z.type,z.key,z.props,null,D.mode,L),fl(L,z),L.return=D,D=L)}return s(D);case Sl:e:{for($=z.key;T!==null;){if(T.key===$)if(T.tag===4&&T.stateNode.containerInfo===z.containerInfo&&T.stateNode.implementation===z.implementation){r(D,T.sibling),L=a(T,z.children||[]),L.return=D,D=L;break e}else{r(D,T);break}else t(D,T);T=T.sibling}L=Fd(z,D.mode,L),L.return=D,D=L}return s(D);case ci:return z=is(z),K(D,T,z,L)}if(El(z))return M(D,T,z,L);if(ll(z)){if($=ll(z),typeof $!="function")throw Error(xe(150));return z=$.call(z),k(D,T,z,L)}if(typeof z.then=="function")return K(D,T,eu(z),L);if(z.$$typeof===Da)return K(D,T,Wc(D,z),L);tu(D,z)}return typeof z=="string"&&z!==""||typeof z=="number"||typeof z=="bigint"?(z=""+z,T!==null&&T.tag===6?(r(D,T.sibling),L=a(T,z),L.return=D,D=L):(r(D,T),L=$d(z,D.mode,L),L.return=D,D=L),s(D)):r(D,T)}return function(D,T,z,L){try{ec=0;var $=K(D,T,z,L);return xo=null,$}catch(V){if(V===Ko||V===If)throw V;var F=vn(29,V,null,D.mode);return F.lanes=L,F.return=D,F}finally{}}}var ws=r2(!0),n2=r2(!1),ui=!1;function Kp(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function wh(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ni(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function ji(e,t,r){var n=e.updateQueue;if(n===null)return null;if(n=n.shared,Mt&2){var a=n.pending;return a===null?t.next=t:(t.next=a.next,a.next=t),n.pending=t,t=Pu(e),Vy(e,null,r),t}return Df(e,n,t,r),Pu(e)}function Ul(e,t,r){if(t=t.updateQueue,t!==null&&(t=t.shared,(r&4194048)!==0)){var n=t.lanes;n&=e.pendingLanes,r|=n,t.lanes=r,wy(e,r)}}function Pd(e,t){var r=e.updateQueue,n=e.alternate;if(n!==null&&(n=n.updateQueue,r===n)){var a=null,i=null;if(r=r.firstBaseUpdate,r!==null){do{var s={lane:r.lane,tag:r.tag,payload:r.payload,callback:null,next:null};i===null?a=i=s:i=i.next=s,r=r.next}while(r!==null);i===null?a=i=t:i=i.next=t}else a=i=t;r={baseState:n.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:n.shared,callbacks:n.callbacks},e.updateQueue=r;return}e=r.lastBaseUpdate,e===null?r.firstBaseUpdate=t:e.next=t,r.lastBaseUpdate=t}var _h=!1;function kl(){if(_h){var e=mo;if(e!==null)throw e}}function zl(e,t,r,n){_h=!1;var a=e.updateQueue;ui=!1;var i=a.firstBaseUpdate,s=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,h=c.next;c.next=null,s===null?i=h:s.next=h,s=c;var p=e.alternate;p!==null&&(p=p.updateQueue,o=p.lastBaseUpdate,o!==s&&(o===null?p.firstBaseUpdate=h:o.next=h,p.lastBaseUpdate=c))}if(i!==null){var y=a.baseState;s=0,p=h=c=null,o=i;do{var g=o.lane&-536870913,v=g!==o.lane;if(v?(mt&g)===g:(n&g)===g){g!==0&&g===So&&(_h=!0),p!==null&&(p=p.next={lane:0,tag:o.tag,payload:o.payload,callback:null,next:null});e:{var M=e,k=o;g=t;var K=r;switch(k.tag){case 1:if(M=k.payload,typeof M=="function"){y=M.call(K,y,g);break e}y=M;break e;case 3:M.flags=M.flags&-65537|128;case 0:if(M=k.payload,g=typeof M=="function"?M.call(K,y,g):M,g==null)break e;y=Xt({},y,g);break e;case 2:ui=!0}}g=o.callback,g!==null&&(e.flags|=64,v&&(e.flags|=8192),v=a.callbacks,v===null?a.callbacks=[g]:v.push(g))}else v={lane:g,tag:o.tag,payload:o.payload,callback:o.callback,next:null},p===null?(h=p=v,c=y):p=p.next=v,s|=g;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;v=o,o=v.next,v.next=null,a.lastBaseUpdate=v,a.shared.pending=null}}while(!0);p===null&&(c=y),a.baseState=c,a.firstBaseUpdate=h,a.lastBaseUpdate=p,i===null&&(a.shared.lanes=0),Di|=s,e.lanes=s,e.memoizedState=y}}function a2(e,t){if(typeof e!="function")throw Error(xe(191,e));e.call(t)}function i2(e,t){var r=e.callbacks;if(r!==null)for(e.callbacks=null,e=0;ei?i:8;var s=Ze.T,o={};Ze.T=o,n1(e,!1,t,r);try{var c=a(),h=Ze.S;if(h!==null&&h(o,c),c!==null&&typeof c=="object"&&typeof c.then=="function"){var p=O4(c,n);Dl(e,t,p,Tn(e))}else Dl(e,t,n,Tn(e))}catch(y){Dl(e,t,{then:function(){},status:"rejected",reason:y},Tn())}finally{Ct.p=i,s!==null&&o.types!==null&&(s.types=o.types),Ze.T=s}}function I4(){}function jh(e,t,r,n){if(e.tag!==5)throw Error(xe(476));var a=C2(e).queue;M2(e,a,t,cs,r===null?I4:function(){return B2(e),r(n)})}function C2(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:cs,baseState:cs,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Va,lastRenderedState:cs},next:null};var r={};return t.next={memoizedState:r,baseState:r,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Va,lastRenderedState:r},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function B2(e){var t=C2(e);t.next===null&&(t=e.alternate.memoizedState),Dl(e,t.next.queue,{},Tn())}function r1(){return Dr(ic)}function O2(){return fr().memoizedState}function R2(){return fr().memoizedState}function L4(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var r=Tn();e=Ni(r);var n=ji(t,e,r);n!==null&&(un(n,t,r),Ul(n,t,r)),t={cache:qp()},e.payload=t;return}t=t.return}}function H4(e,t,r){var n=Tn();r={lane:n,revertLane:0,gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},$f(e)?k2(t,r):(r=Dp(e,t,r,n),r!==null&&(un(r,e,n),z2(r,t,n)))}function U2(e,t,r){var n=Tn();Dl(e,t,r,n)}function Dl(e,t,r,n){var a={lane:n,revertLane:0,gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null};if($f(e))k2(t,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var s=t.lastRenderedState,o=i(s,r);if(a.hasEagerState=!0,a.eagerState=o,Mn(o,s))return Df(e,t,a,0),qt===null&&zf(),!1}catch{}finally{}if(r=Dp(e,t,a,n),r!==null)return un(r,e,n),z2(r,t,n),!0}return!1}function n1(e,t,r,n){if(n={lane:2,revertLane:d1(),gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},$f(e)){if(t)throw Error(xe(479))}else t=Dp(e,r,n,2),t!==null&&un(t,e,2)}function $f(e){var t=e.alternate;return e===it||t!==null&&t===it}function k2(e,t){yo=Qu=!0;var r=e.pending;r===null?t.next=t:(t.next=r.next,r.next=t),e.pending=t}function z2(e,t,r){if(r&4194048){var n=t.lanes;n&=e.pendingLanes,r|=n,t.lanes=r,wy(e,r)}}var rc={readContext:Dr,use:Hf,useCallback:sr,useContext:sr,useEffect:sr,useImperativeHandle:sr,useLayoutEffect:sr,useInsertionEffect:sr,useMemo:sr,useReducer:sr,useRef:sr,useState:sr,useDebugValue:sr,useDeferredValue:sr,useTransition:sr,useSyncExternalStore:sr,useId:sr,useHostTransitionStatus:sr,useFormState:sr,useActionState:sr,useOptimistic:sr,useMemoCache:sr,useCacheRefresh:sr};rc.useEffectEvent=sr;var D2={readContext:Dr,use:Hf,useCallback:function(e,t){return Gr().memoizedState=[e,t===void 0?null:t],e},useContext:Dr,useEffect:Xb,useImperativeHandle:function(e,t,r){r=r!=null?r.concat([e]):null,Nu(4194308,4,E2.bind(null,t,e),r)},useLayoutEffect:function(e,t){return Nu(4194308,4,e,t)},useInsertionEffect:function(e,t){Nu(4,2,e,t)},useMemo:function(e,t){var r=Gr();t=t===void 0?null:t;var n=e();if(_s){yi(!0);try{e()}finally{yi(!1)}}return r.memoizedState=[n,t],n},useReducer:function(e,t,r){var n=Gr();if(r!==void 0){var a=r(t);if(_s){yi(!0);try{r(t)}finally{yi(!1)}}}else a=t;return n.memoizedState=n.baseState=a,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:a},n.queue=e,e=e.dispatch=H4.bind(null,it,e),[n.memoizedState,e]},useRef:function(e){var t=Gr();return e={current:e},t.memoizedState=e},useState:function(e){e=Ah(e);var t=e.queue,r=U2.bind(null,it,t);return t.dispatch=r,[e.memoizedState,r]},useDebugValue:e1,useDeferredValue:function(e,t){var r=Gr();return t1(r,e,t)},useTransition:function(){var e=Ah(!1);return e=M2.bind(null,it,e.queue,!0,!1),Gr().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,r){var n=it,a=Gr();if(vt){if(r===void 0)throw Error(xe(407));r=r()}else{if(r=t(),qt===null)throw Error(xe(349));mt&127||u2(n,t,r)}a.memoizedState=r;var i={value:r,getSnapshot:t};return a.queue=i,Xb(d2.bind(null,n,i,e),[e]),n.flags|=2048,Ao(9,{destroy:void 0},f2.bind(null,n,i,r,t),null),r},useId:function(){var e=Gr(),t=qt.identifierPrefix;if(vt){var r=ca,n=la;r=(n&~(1<<32-jn(n)-1)).toString(32)+r,t="_"+t+"R_"+r,r=Ju++,0<\/script>",i=i.removeChild(i.firstChild);break;case"select":i=typeof n.is=="string"?s.createElement("select",{is:n.is}):s.createElement("select"),n.multiple?i.multiple=!0:n.size&&(i.size=n.size);break;default:i=typeof n.is=="string"?s.createElement(a,{is:n.is}):s.createElement(a)}}i[kr]=t,i[fn]=n;e:for(s=t.child;s!==null;){if(s.tag===5||s.tag===6)i.appendChild(s.stateNode);else if(s.tag!==4&&s.tag!==27&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break e;for(;s.sibling===null;){if(s.return===null||s.return===t)break e;s=s.return}s.sibling.return=s.return,s=s.sibling}t.stateNode=i;e:switch(Ir(i,a,n),a){case"button":case"input":case"select":case"textarea":n=!!n.autoFocus;break e;case"img":n=!0;break e;default:n=!1}n&&Ca(t)}}return Gt(t),Wd(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,r),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==n&&Ca(t);else{if(typeof n!="string"&&t.stateNode===null)throw Error(xe(166));if(e=Ei.current,Ks(t)){if(e=t.stateNode,r=t.memoizedProps,n=null,a=zr,a!==null)switch(a.tag){case 27:case 5:n=a.memoizedProps}e[kr]=t,e=!!(e.nodeValue===r||n!==null&&n.suppressHydrationWarning===!0||Ug(e.nodeValue,r)),e||ki(t,!0)}else e=cf(e).createTextNode(n),e[kr]=t,t.stateNode=e}return Gt(t),null;case 31:if(r=t.memoizedState,e===null||e.memoizedState!==null){if(n=Ks(t),r!==null){if(e===null){if(!n)throw Error(xe(318));if(e=t.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(xe(557));e[kr]=t}else gs(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Gt(t),e=!1}else r=Kd(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=r),e=!0;if(!e)return t.flags&256?(gn(t),t):(gn(t),null);if(t.flags&128)throw Error(xe(558))}return Gt(t),null;case 13:if(n=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Ks(t),n!==null&&n.dehydrated!==null){if(e===null){if(!a)throw Error(xe(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(xe(317));a[kr]=t}else gs(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Gt(t),a=!1}else a=Kd(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(gn(t),t):(gn(t),null)}return gn(t),t.flags&128?(t.lanes=r,t):(r=n!==null,e=e!==null&&e.memoizedState!==null,r&&(n=t.child,a=null,n.alternate!==null&&n.alternate.memoizedState!==null&&n.alternate.memoizedState.cachePool!==null&&(a=n.alternate.memoizedState.cachePool.pool),i=null,n.memoizedState!==null&&n.memoizedState.cachePool!==null&&(i=n.memoizedState.cachePool.pool),i!==a&&(n.flags|=2048)),r!==e&&r&&(t.child.flags|=8192),ru(t,t.updateQueue),Gt(t),null);case 4:return vo(),e===null&&h1(t.stateNode.containerInfo),Gt(t),null;case 10:return $a(t.type),Gt(t),null;case 19:if(Tr(ur),n=t.memoizedState,n===null)return Gt(t),null;if(a=(t.flags&128)!==0,i=n.rendering,i===null)if(a)dl(n,!1);else{if(or!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(i=Zu(e),i!==null){for(t.flags|=128,dl(n,!1),e=i.updateQueue,t.updateQueue=e,ru(t,e),t.subtreeFlags=0,e=r,r=t.child;r!==null;)Xy(r,e),r=r.sibling;return Kt(ur,ur.current&1|2),vt&&ka(t,n.treeForkCount),t.child}e=e.sibling}n.tail!==null&&An()>rf&&(t.flags|=128,a=!0,dl(n,!1),t.lanes=4194304)}else{if(!a)if(e=Zu(i),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,ru(t,e),dl(n,!0),n.tail===null&&n.tailMode==="hidden"&&!i.alternate&&!vt)return Gt(t),null}else 2*An()-n.renderingStartTime>rf&&r!==536870912&&(t.flags|=128,a=!0,dl(n,!1),t.lanes=4194304);n.isBackwards?(i.sibling=t.child,t.child=i):(e=n.last,e!==null?e.sibling=i:t.child=i,n.last=i)}return n.tail!==null?(e=n.tail,n.rendering=e,n.tail=e.sibling,n.renderingStartTime=An(),e.sibling=null,r=ur.current,Kt(ur,a?r&1|2:r&1),vt&&ka(t,n.treeForkCount),e):(Gt(t),null);case 22:case 23:return gn(t),Pp(),n=t.memoizedState!==null,e!==null?e.memoizedState!==null!==n&&(t.flags|=8192):n&&(t.flags|=8192),n?r&536870912&&!(t.flags&128)&&(Gt(t),t.subtreeFlags&6&&(t.flags|=8192)):Gt(t),r=t.updateQueue,r!==null&&ru(t,r.retryQueue),r=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(r=e.memoizedState.cachePool.pool),n=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(n=t.memoizedState.cachePool.pool),n!==r&&(t.flags|=2048),e!==null&&Tr(fs),null;case 24:return r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),$a(br),Gt(t),null;case 25:return null;case 30:return null}throw Error(xe(156,t.tag))}function P4(e,t){switch(Hp(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return $a(br),vo(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return qu(t),null;case 31:if(t.memoizedState!==null){if(gn(t),t.alternate===null)throw Error(xe(340));gs()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(gn(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(xe(340));gs()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Tr(ur),null;case 4:return vo(),null;case 10:return $a(t.type),null;case 22:case 23:return gn(t),Pp(),e!==null&&Tr(fs),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return $a(br),null;case 25:return null;default:return null}}function X2(e,t){switch(Hp(t),t.tag){case 3:$a(br),vo();break;case 26:case 27:case 5:qu(t);break;case 4:vo();break;case 31:t.memoizedState!==null&&gn(t);break;case 13:gn(t);break;case 19:Tr(ur);break;case 10:$a(t.type);break;case 22:case 23:gn(t),Pp(),e!==null&&Tr(fs);break;case 24:$a(br)}}function Sc(e,t){try{var r=t.updateQueue,n=r!==null?r.lastEffect:null;if(n!==null){var a=n.next;r=a;do{if((r.tag&e)===e){n=void 0;var i=r.create,s=r.inst;n=i(),s.destroy=n}r=r.next}while(r!==a)}}catch(o){Ut(t,t.return,o)}}function zi(e,t,r){try{var n=t.updateQueue,a=n!==null?n.lastEffect:null;if(a!==null){var i=a.next;n=i;do{if((n.tag&e)===e){var s=n.inst,o=s.destroy;if(o!==void 0){s.destroy=void 0,a=t;var c=r,h=o;try{h()}catch(p){Ut(a,c,p)}}}n=n.next}while(n!==i)}}catch(p){Ut(t,t.return,p)}}function Z2(e){var t=e.updateQueue;if(t!==null){var r=e.stateNode;try{i2(t,r)}catch(n){Ut(e,e.return,n)}}}function Q2(e,t,r){r.props=Ss(e.type,e.memoizedProps),r.state=e.memoizedState;try{r.componentWillUnmount()}catch(n){Ut(e,t,n)}}function Il(e,t){try{var r=e.ref;if(r!==null){switch(e.tag){case 26:case 27:case 5:var n=e.stateNode;break;case 30:n=e.stateNode;break;default:n=e.stateNode}typeof r=="function"?e.refCleanup=r(n):r.current=n}}catch(a){Ut(e,t,a)}}function ua(e,t){var r=e.ref,n=e.refCleanup;if(r!==null)if(typeof n=="function")try{n()}catch(a){Ut(e,t,a)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof r=="function")try{r(null)}catch(a){Ut(e,t,a)}else r.current=null}function J2(e){var t=e.type,r=e.memoizedProps,n=e.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":r.autoFocus&&n.focus();break e;case"img":r.src?n.src=r.src:r.srcSet&&(n.srcset=r.srcSet)}}catch(a){Ut(e,e.return,a)}}function e0(e,t,r){try{var n=e.stateNode;h8(n,e.type,r,t),n[fn]=t}catch(a){Ut(e,e.return,a)}}function W2(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Pi(e.type)||e.tag===4}function t0(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||W2(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Pi(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Oh(e,t,r){var n=e.tag;if(n===5||n===6)e=e.stateNode,t?(r.nodeType===9?r.body:r.nodeName==="HTML"?r.ownerDocument.body:r).insertBefore(e,t):(t=r.nodeType===9?r.body:r.nodeName==="HTML"?r.ownerDocument.body:r,t.appendChild(e),r=r._reactRootContainer,r!=null||t.onclick!==null||(t.onclick=Ia));else if(n!==4&&(n===27&&Pi(e.type)&&(r=e.stateNode,t=null),e=e.child,e!==null))for(Oh(e,t,r),e=e.sibling;e!==null;)Oh(e,t,r),e=e.sibling}function tf(e,t,r){var n=e.tag;if(n===5||n===6)e=e.stateNode,t?r.insertBefore(e,t):r.appendChild(e);else if(n!==4&&(n===27&&Pi(e.type)&&(r=e.stateNode),e=e.child,e!==null))for(tf(e,t,r),e=e.sibling;e!==null;)tf(e,t,r),e=e.sibling}function eg(e){var t=e.stateNode,r=e.memoizedProps;try{for(var n=e.type,a=t.attributes;a.length;)t.removeAttributeNode(a[0]);Ir(t,n,r),t[kr]=e,t[fn]=r}catch(i){Ut(e,e.return,i)}}var za=!1,pr=!1,r0=!1,lm=typeof WeakSet=="function"?WeakSet:Set,Sr=null;function G4(e,t){if(e=e.containerInfo,Lh=hf,e=qy(e),kp(e)){if("selectionStart"in e)var r={start:e.selectionStart,end:e.selectionEnd};else e:{r=(r=e.ownerDocument)&&r.defaultView||window;var n=r.getSelection&&r.getSelection();if(n&&n.rangeCount!==0){r=n.anchorNode;var a=n.anchorOffset,i=n.focusNode;n=n.focusOffset;try{r.nodeType,i.nodeType}catch{r=null;break e}var s=0,o=-1,c=-1,h=0,p=0,y=e,g=null;t:for(;;){for(var v;y!==r||a!==0&&y.nodeType!==3||(o=s+a),y!==i||n!==0&&y.nodeType!==3||(c=s+n),y.nodeType===3&&(s+=y.nodeValue.length),(v=y.firstChild)!==null;)g=y,y=v;for(;;){if(y===e)break t;if(g===r&&++h===a&&(o=s),g===i&&++p===n&&(c=s),(v=y.nextSibling)!==null)break;y=g,g=y.parentNode}y=v}r=o===-1||c===-1?null:{start:o,end:c}}else r=null}r=r||{start:0,end:0}}else r=null;for(Hh={focusedElem:e,selectionRange:r},hf=!1,Sr=t;Sr!==null;)if(t=Sr,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Sr=e;else for(;Sr!==null;){switch(t=Sr,i=t.alternate,e=t.flags,t.tag){case 0:if(e&4&&(e=t.updateQueue,e=e!==null?e.events:null,e!==null))for(r=0;r title"))),Ir(i,n,r),i[kr]=e,Ar(i),n=i;break e;case"link":var s=Tm("link","href",a).get(n+(r.href||""));if(s){for(var o=0;oK&&(s=K,K=k,k=s);var D=Rb(o,k),T=Rb(o,K);if(D&&T&&(v.rangeCount!==1||v.anchorNode!==D.node||v.anchorOffset!==D.offset||v.focusNode!==T.node||v.focusOffset!==T.offset)){var z=y.createRange();z.setStart(D.node,D.offset),v.removeAllRanges(),k>K?(v.addRange(z),v.extend(T.node,T.offset)):(z.setEnd(T.node,T.offset),v.addRange(z))}}}}for(y=[],v=o;v=v.parentNode;)v.nodeType===1&&y.push({element:v,left:v.scrollLeft,top:v.scrollTop});for(typeof o.focus=="function"&&o.focus(),o=0;or?32:r,Ze.T=null,r=kh,kh=null;var i=Mi,s=Fa;if(vr=0,jo=Mi=null,Fa=0,Mt&6)throw Error(xe(331));var o=Mt;if(Mt|=4,fg(i.current),lg(i,i.current,s,r),Mt=o,Ec(0,!1),Nn&&typeof Nn.onPostCommitFiberRoot=="function")try{Nn.onPostCommitFiberRoot(mc,i)}catch{}return!0}finally{Ct.p=a,Ze.T=n,Ng(e,t)}}function dm(e,t,r){t=$n(r,t),t=Mh(e.stateNode,t,2),e=ji(e,t,2),e!==null&&(yc(e,2),Ea(e))}function Ut(e,t,r){if(e.tag===3)dm(e,e,r);else for(;t!==null;){if(t.tag===3){dm(t,e,r);break}else if(t.tag===1){var n=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof n.componentDidCatch=="function"&&(Ti===null||!Ti.has(n))){e=$n(r,e),r=$2(2),n=ji(t,r,2),n!==null&&(F2(r,n,t,e),yc(n,2),Ea(n));break}}t=t.return}}function a0(e,t,r){var n=e.pingCache;if(n===null){n=e.pingCache=new X4;var a=new Set;n.set(t,a)}else a=n.get(t),a===void 0&&(a=new Set,n.set(t,a));a.has(r)||(c1=!0,a.add(r),e=e8.bind(null,e,t,r),t.then(e,e))}function e8(e,t,r){var n=e.pingCache;n!==null&&n.delete(t),e.pingedLanes|=e.suspendedLanes&r,e.warmLanes&=~r,qt===e&&(mt&r)===r&&(or===4||or===3&&(mt&62914560)===mt&&300>An()-Ff?!(Mt&2)&&To(e,0):u1|=r,No===mt&&(No=0)),Ea(e)}function Tg(e,t){t===0&&(t=gy()),e=ks(e,t),e!==null&&(yc(e,t),Ea(e))}function t8(e){var t=e.memoizedState,r=0;t!==null&&(r=t.retryLane),Tg(e,r)}function r8(e,t){var r=0;switch(e.tag){case 31:case 13:var n=e.stateNode,a=e.memoizedState;a!==null&&(r=a.retryLane);break;case 19:n=e.stateNode;break;case 22:n=e.stateNode._retryCache;break;default:throw Error(xe(314))}n!==null&&n.delete(t),Tg(e,r)}function n8(e,t){return Np(e,t)}var sf=null,Zs=null,Dh=!1,of=!1,i0=!1,_i=0;function Ea(e){e!==Zs&&e.next===null&&(Zs===null?sf=Zs=e:Zs=Zs.next=e),of=!0,Dh||(Dh=!0,i8())}function Ec(e,t){if(!i0&&of){i0=!0;do for(var r=!1,n=sf;n!==null;){if(e!==0){var a=n.pendingLanes;if(a===0)var i=0;else{var s=n.suspendedLanes,o=n.pingedLanes;i=(1<<31-jn(42|e)+1)-1,i&=a&~(s&~o),i=i&201326741?i&201326741|1:i?i|2:0}i!==0&&(r=!0,hm(n,i))}else i=mt,i=Of(n,n===qt?i:0,n.cancelPendingCommit!==null||n.timeoutHandle!==-1),!(i&3)||xc(n,i)||(r=!0,hm(n,i));n=n.next}while(r);i0=!1}}function a8(){Mg()}function Mg(){of=Dh=!1;var e=0;_i!==0&&b8()&&(e=_i);for(var t=An(),r=null,n=sf;n!==null;){var a=n.next,i=Cg(n,t);i===0?(n.next=null,r===null?sf=a:r.next=a,a===null&&(Zs=r)):(r=n,(e!==0||i&3)&&(of=!0)),n=a}vr!==0&&vr!==5||Ec(e),_i!==0&&(_i=0)}function Cg(e,t){for(var r=e.suspendedLanes,n=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes&-62914561;0o)break;var p=c.transferSize,y=c.initiatorType;p&&ym(y)&&(c=c.responseEnd,s+=p*(c"u"?null:document;function Lg(e,t,r){var n=Go;if(n&&typeof t=="string"&&t){var a=qn(t);a='link[rel="'+e+'"][href="'+a+'"]',typeof r=="string"&&(a+='[crossorigin="'+r+'"]'),Am.has(a)||(Am.add(a),e={rel:e,crossOrigin:r,href:t},n.querySelector(a)===null&&(t=n.createElement("link"),Ir(t,"link",e),Ar(t),n.head.appendChild(t)))}}function E8(e){ti.D(e),Lg("dns-prefetch",e,null)}function A8(e,t){ti.C(e,t),Lg("preconnect",e,t)}function N8(e,t,r){ti.L(e,t,r);var n=Go;if(n&&e&&t){var a='link[rel="preload"][as="'+qn(t)+'"]';t==="image"&&r&&r.imageSrcSet?(a+='[imagesrcset="'+qn(r.imageSrcSet)+'"]',typeof r.imageSizes=="string"&&(a+='[imagesizes="'+qn(r.imageSizes)+'"]')):a+='[href="'+qn(e)+'"]';var i=a;switch(t){case"style":i=Mo(e);break;case"script":i=Yo(e)}Yn.has(i)||(e=Xt({rel:"preload",href:t==="image"&&r&&r.imageSrcSet?void 0:e,as:t},r),Yn.set(i,e),n.querySelector(a)!==null||t==="style"&&n.querySelector(Ac(i))||t==="script"&&n.querySelector(Nc(i))||(t=n.createElement("link"),Ir(t,"link",e),Ar(t),n.head.appendChild(t)))}}function j8(e,t){ti.m(e,t);var r=Go;if(r&&e){var n=t&&typeof t.as=="string"?t.as:"script",a='link[rel="modulepreload"][as="'+qn(n)+'"][href="'+qn(e)+'"]',i=a;switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":i=Yo(e)}if(!Yn.has(i)&&(e=Xt({rel:"modulepreload",href:e},t),Yn.set(i,e),r.querySelector(a)===null)){switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(r.querySelector(Nc(i)))return}n=r.createElement("link"),Ir(n,"link",e),Ar(n),r.head.appendChild(n)}}}function T8(e,t,r){ti.S(e,t,r);var n=Go;if(n&&e){var a=ho(n).hoistableStyles,i=Mo(e);t=t||"default";var s=a.get(i);if(!s){var o={loading:0,preload:null};if(s=n.querySelector(Ac(i)))o.loading=5;else{e=Xt({rel:"stylesheet",href:e,"data-precedence":t},r),(r=Yn.get(i))&&p1(e,r);var c=s=n.createElement("link");Ar(c),Ir(c,"link",e),c._p=new Promise(function(h,p){c.onload=h,c.onerror=p}),c.addEventListener("load",function(){o.loading|=1}),c.addEventListener("error",function(){o.loading|=2}),o.loading|=4,Cu(s,t,n)}s={type:"stylesheet",instance:s,count:1,state:o},a.set(i,s)}}}function M8(e,t){ti.X(e,t);var r=Go;if(r&&e){var n=ho(r).hoistableScripts,a=Yo(e),i=n.get(a);i||(i=r.querySelector(Nc(a)),i||(e=Xt({src:e,async:!0},t),(t=Yn.get(a))&&b1(e,t),i=r.createElement("script"),Ar(i),Ir(i,"link",e),r.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},n.set(a,i))}}function C8(e,t){ti.M(e,t);var r=Go;if(r&&e){var n=ho(r).hoistableScripts,a=Yo(e),i=n.get(a);i||(i=r.querySelector(Nc(a)),i||(e=Xt({src:e,async:!0,type:"module"},t),(t=Yn.get(a))&&b1(e,t),i=r.createElement("script"),Ar(i),Ir(i,"link",e),r.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},n.set(a,i))}}function Nm(e,t,r,n){var a=(a=Ei.current)?uf(a):null;if(!a)throw Error(xe(446));switch(e){case"meta":case"title":return null;case"style":return typeof r.precedence=="string"&&typeof r.href=="string"?(t=Mo(r.href),r=ho(a).hoistableStyles,n=r.get(t),n||(n={type:"style",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};case"link":if(r.rel==="stylesheet"&&typeof r.href=="string"&&typeof r.precedence=="string"){e=Mo(r.href);var i=ho(a).hoistableStyles,s=i.get(e);if(s||(a=a.ownerDocument||a,s={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},i.set(e,s),(i=a.querySelector(Ac(e)))&&!i._p&&(s.instance=i,s.state.loading=5),Yn.has(e)||(r={rel:"preload",as:"style",href:r.href,crossOrigin:r.crossOrigin,integrity:r.integrity,media:r.media,hrefLang:r.hrefLang,referrerPolicy:r.referrerPolicy},Yn.set(e,r),i||B8(a,e,r,s.state))),t&&n===null)throw Error(xe(528,""));return s}if(t&&n!==null)throw Error(xe(529,""));return null;case"script":return t=r.async,r=r.src,typeof r=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=Yo(r),r=ho(a).hoistableScripts,n=r.get(t),n||(n={type:"script",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};default:throw Error(xe(444,e))}}function Mo(e){return'href="'+qn(e)+'"'}function Ac(e){return'link[rel="stylesheet"]['+e+"]"}function Hg(e){return Xt({},e,{"data-precedence":e.precedence,precedence:null})}function B8(e,t,r,n){e.querySelector('link[rel="preload"][as="style"]['+t+"]")?n.loading=1:(t=e.createElement("link"),n.preload=t,t.addEventListener("load",function(){return n.loading|=1}),t.addEventListener("error",function(){return n.loading|=2}),Ir(t,"link",r),Ar(t),e.head.appendChild(t))}function Yo(e){return'[src="'+qn(e)+'"]'}function Nc(e){return"script[async]"+e}function jm(e,t,r){if(t.count++,t.instance===null)switch(t.type){case"style":var n=e.querySelector('style[data-href~="'+qn(r.href)+'"]');if(n)return t.instance=n,Ar(n),n;var a=Xt({},r,{"data-href":r.href,"data-precedence":r.precedence,href:null,precedence:null});return n=(e.ownerDocument||e).createElement("style"),Ar(n),Ir(n,"style",a),Cu(n,r.precedence,e),t.instance=n;case"stylesheet":a=Mo(r.href);var i=e.querySelector(Ac(a));if(i)return t.state.loading|=4,t.instance=i,Ar(i),i;n=Hg(r),(a=Yn.get(a))&&p1(n,a),i=(e.ownerDocument||e).createElement("link"),Ar(i);var s=i;return s._p=new Promise(function(o,c){s.onload=o,s.onerror=c}),Ir(i,"link",n),t.state.loading|=4,Cu(i,r.precedence,e),t.instance=i;case"script":return i=Yo(r.src),(a=e.querySelector(Nc(i)))?(t.instance=a,Ar(a),a):(n=r,(a=Yn.get(i))&&(n=Xt({},r),b1(n,a)),e=e.ownerDocument||e,a=e.createElement("script"),Ar(a),Ir(a,"link",n),e.head.appendChild(a),t.instance=a);case"void":return null;default:throw Error(xe(443,t.type))}else t.type==="stylesheet"&&!(t.state.loading&4)&&(n=t.instance,t.state.loading|=4,Cu(n,r.precedence,e));return t.instance}function Cu(e,t,r){for(var n=r.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),a=n.length?n[n.length-1]:null,i=a,s=0;s title"):null)}function O8(e,t,r){if(r===1||t.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return e=t.disabled,typeof t.precedence=="string"&&e==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function qg(e){return!(e.type==="stylesheet"&&!(e.state.loading&3))}function R8(e,t,r,n){if(r.type==="stylesheet"&&(typeof n.media!="string"||matchMedia(n.media).matches!==!1)&&!(r.state.loading&4)){if(r.instance===null){var a=Mo(n.href),i=t.querySelector(Ac(a));if(i){t=i._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(e.count++,e=ff.bind(e),t.then(e,e)),r.state.loading|=4,r.instance=i,Ar(i);return}i=t.ownerDocument||t,n=Hg(n),(a=Yn.get(a))&&p1(n,a),i=i.createElement("link"),Ar(i);var s=i;s._p=new Promise(function(o,c){s.onload=o,s.onerror=c}),Ir(i,"link",n),r.instance=i}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(r,t),(t=r.state.preload)&&!(r.state.loading&3)&&(e.count++,r=ff.bind(e),t.addEventListener("load",r),t.addEventListener("error",r))}}var f0=0;function U8(e,t){return e.stylesheets&&e.count===0&&Ou(e,e.stylesheets),0f0?50:800)+t);return e.unsuspend=r,function(){e.unsuspend=null,clearTimeout(n),clearTimeout(a)}}:null}function ff(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Ou(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var df=null;function Ou(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,df=new Map,t.forEach(k8,e),df=null,ff.call(e))}function k8(e,t){if(!(t.state.loading&4)){var r=df.get(e);if(r)var n=r.get(null);else{r=new Map,df.set(e,r);for(var a=e.querySelectorAll("link[data-precedence],style[data-precedence]"),i=0;i"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Xg)}catch(e){console.error(e)}}Xg(),ny.exports=Cf;var F8=ny.exports;/** +`+n.stack}}var sh=Object.prototype.hasOwnProperty,Np=_r.unstable_scheduleCallback,Rd=_r.unstable_cancelCallback,_5=_r.unstable_shouldYield,S5=_r.unstable_requestPaint,An=_r.unstable_now,E5=_r.unstable_getCurrentPriorityLevel,my=_r.unstable_ImmediatePriority,xy=_r.unstable_UserBlockingPriority,$u=_r.unstable_NormalPriority,A5=_r.unstable_LowPriority,yy=_r.unstable_IdlePriority,N5=_r.log,j5=_r.unstable_setDisableYieldValue,mc=null,Nn=null;function yi(e){if(typeof N5=="function"&&j5(e),Nn&&typeof Nn.setStrictMode=="function")try{Nn.setStrictMode(mc,e)}catch{}}var jn=Math.clz32?Math.clz32:C5,T5=Math.log,M5=Math.LN2;function C5(e){return e>>>=0,e===0?32:31-(T5(e)/M5|0)|0}var Vc=256,Xc=262144,Zc=4194304;function as(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Of(e,t,r){var n=e.pendingLanes;if(n===0)return 0;var a=0,i=e.suspendedLanes,s=e.pingedLanes;e=e.warmLanes;var o=n&134217727;return o!==0?(n=o&~i,n!==0?a=as(n):(s&=o,s!==0?a=as(s):r||(r=o&~e,r!==0&&(a=as(r))))):(o=n&~i,o!==0?a=as(o):s!==0?a=as(s):r||(r=n&~e,r!==0&&(a=as(r)))),a===0?0:t!==0&&t!==a&&!(t&i)&&(i=a&-a,r=t&-t,i>=r||i===32&&(r&4194048)!==0)?t:a}function xc(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function B5(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function gy(){var e=Zc;return Zc<<=1,!(Zc&62914560)&&(Zc=4194304),e}function Ud(e){for(var t=[],r=0;31>r;r++)t.push(e);return t}function yc(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function O5(e,t,r,n,a,i){var s=e.pendingLanes;e.pendingLanes=r,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=r,e.entangledLanes&=r,e.errorRecoveryDisabledLanes&=r,e.shellSuspendCounter=0;var o=e.entanglements,c=e.expirationTimes,d=e.hiddenUpdates;for(r=s&~r;0"u")return null;try{return e.activeElement||e.body}catch{return e.body}}var I5=/[\n"\\]/g;function qn(e){return e.replace(I5,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function ch(e,t,r,n,a,i,s,o){e.name="",s!=null&&typeof s!="function"&&typeof s!="symbol"&&typeof s!="boolean"?e.type=s:e.removeAttribute("type"),t!=null?s==="number"?(t===0&&e.value===""||e.value!=t)&&(e.value=""+In(t)):e.value!==""+In(t)&&(e.value=""+In(t)):s!=="submit"&&s!=="reset"||e.removeAttribute("value"),t!=null?uh(e,s,In(t)):r!=null?uh(e,s,In(r)):n!=null&&e.removeAttribute("value"),a==null&&i!=null&&(e.defaultChecked=!!i),a!=null&&(e.checked=a&&typeof a!="function"&&typeof a!="symbol"),o!=null&&typeof o!="function"&&typeof o!="symbol"&&typeof o!="boolean"?e.name=""+In(o):e.removeAttribute("name")}function Ty(e,t,r,n,a,i,s,o){if(i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"&&(e.type=i),t!=null||r!=null){if(!(i!=="submit"&&i!=="reset"||t!=null)){lh(e);return}r=r!=null?""+In(r):"",t=t!=null?""+In(t):r,o||t===e.value||(e.value=t),e.defaultValue=t}n=n??a,n=typeof n!="function"&&typeof n!="symbol"&&!!n,e.checked=o?e.checked:!!n,e.defaultChecked=!!n,s!=null&&typeof s!="function"&&typeof s!="symbol"&&typeof s!="boolean"&&(e.name=s),lh(e)}function uh(e,t,r){t==="number"&&Fu(e.ownerDocument)===e||e.defaultValue===""+r||(e.defaultValue=""+r)}function po(e,t,r,n){if(e=e.options,t){t={};for(var a=0;a"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),dh=!1;if(Ga)try{var cl={};Object.defineProperty(cl,"passive",{get:function(){dh=!0}}),window.addEventListener("test",cl,cl),window.removeEventListener("test",cl,cl)}catch{dh=!1}var gi=null,Op=null,wu=null;function Ry(){if(wu)return wu;var e,t=Op,r=t.length,n,a="value"in gi?gi.value:gi.textContent,i=a.length;for(e=0;e=Cl),Nb=" ",jb=!1;function ky(e,t){switch(e){case"keyup":return d4.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function zy(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var no=!1;function p4(e,t){switch(e){case"compositionend":return zy(t);case"keypress":return t.which!==32?null:(jb=!0,Nb);case"textInput":return e=t.data,e===Nb&&jb?null:e;default:return null}}function b4(e,t){if(no)return e==="compositionend"||!Up&&ky(e,t)?(e=Ry(),wu=Op=gi=null,no=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:r,offset:t-e};e=n}e:{for(;r;){if(r.nextSibling){r=r.nextSibling;break e}r=r.parentNode}r=void 0}r=Ob(r)}}function Hy(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Hy(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function qy(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Fu(e.document);t instanceof e.HTMLIFrameElement;){try{var r=typeof t.contentWindow.location.href=="string"}catch{r=!1}if(r)e=t.contentWindow;else break;t=Fu(e.document)}return t}function kp(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}var S4=Ga&&"documentMode"in document&&11>=document.documentMode,ao=null,hh=null,Ol=null,ph=!1;function Ub(e,t,r){var n=r.window===r?r.document:r.nodeType===9?r:r.ownerDocument;ph||ao==null||ao!==Fu(n)||(n=ao,"selectionStart"in n&&kp(n)?n={start:n.selectionStart,end:n.selectionEnd}:(n=(n.ownerDocument&&n.ownerDocument.defaultView||window).getSelection(),n={anchorNode:n.anchorNode,anchorOffset:n.anchorOffset,focusNode:n.focusNode,focusOffset:n.focusOffset}),Ol&&Ql(Ol,n)||(Ol=n,n=lf(hh,"onSelect"),0>=s,a-=s,ca=1<<32-jn(t)+a|r<J?(Y=V,V=null):Y=V.sibling;var ee=g(D,V,k[J],L);if(ee===null){V===null&&(V=Y);break}e&&V&&ee.alternate===null&&t(D,V),T=i(ee,T,J),F===null?$=ee:F.sibling=ee,F=ee,V=Y}if(J===k.length)return r(D,V),vt&&ka(D,J),$;if(V===null){for(;JJ?(Y=V,V=null):Y=V.sibling;var x=g(D,V,ee.value,L);if(x===null){V===null&&(V=Y);break}e&&V&&x.alternate===null&&t(D,V),T=i(x,T,J),F===null?$=x:F.sibling=x,F=x,V=Y}if(ee.done)return r(D,V),vt&&ka(D,J),$;if(V===null){for(;!ee.done;J++,ee=k.next())ee=y(D,ee.value,L),ee!==null&&(T=i(ee,T,J),F===null?$=ee:F.sibling=ee,F=ee);return vt&&ka(D,J),$}for(V=n(V);!ee.done;J++,ee=k.next())ee=v(V,D,J,ee.value,L),ee!==null&&(e&&ee.alternate!==null&&V.delete(ee.key===null?J:ee.key),T=i(ee,T,J),F===null?$=ee:F.sibling=ee,F=ee);return e&&V.forEach(function(u){return t(D,u)}),vt&&ka(D,J),$}function K(D,T,k,L){if(typeof k=="object"&&k!==null&&k.type===Ws&&k.key===null&&(k=k.props.children),typeof k=="object"&&k!==null){switch(k.$$typeof){case Yc:e:{for(var $=k.key;T!==null;){if(T.key===$){if($=k.type,$===Ws){if(T.tag===7){r(D,T.sibling),L=a(T,k.props.children),L.return=D,D=L;break e}}else if(T.elementType===$||typeof $=="object"&&$!==null&&$.$$typeof===ci&&is($)===T.type){r(D,T.sibling),L=a(T,k.props),fl(L,k),L.return=D,D=L;break e}r(D,T);break}else t(D,T);T=T.sibling}k.type===Ws?(L=us(k.props.children,D.mode,L,k.key),L.return=D,D=L):(L=Su(k.type,k.key,k.props,null,D.mode,L),fl(L,k),L.return=D,D=L)}return s(D);case Sl:e:{for($=k.key;T!==null;){if(T.key===$)if(T.tag===4&&T.stateNode.containerInfo===k.containerInfo&&T.stateNode.implementation===k.implementation){r(D,T.sibling),L=a(T,k.children||[]),L.return=D,D=L;break e}else{r(D,T);break}else t(D,T);T=T.sibling}L=Fd(k,D.mode,L),L.return=D,D=L}return s(D);case ci:return k=is(k),K(D,T,k,L)}if(El(k))return M(D,T,k,L);if(ll(k)){if($=ll(k),typeof $!="function")throw Error(xe(150));return k=$.call(k),z(D,T,k,L)}if(typeof k.then=="function")return K(D,T,eu(k),L);if(k.$$typeof===Da)return K(D,T,Wc(D,k),L);tu(D,k)}return typeof k=="string"&&k!==""||typeof k=="number"||typeof k=="bigint"?(k=""+k,T!==null&&T.tag===6?(r(D,T.sibling),L=a(T,k),L.return=D,D=L):(r(D,T),L=$d(k,D.mode,L),L.return=D,D=L),s(D)):r(D,T)}return function(D,T,k,L){try{ec=0;var $=K(D,T,k,L);return xo=null,$}catch(V){if(V===Ko||V===If)throw V;var F=wn(29,V,null,D.mode);return F.lanes=L,F.return=D,F}finally{}}}var ws=r2(!0),n2=r2(!1),ui=!1;function Kp(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function wh(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ni(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function ji(e,t,r){var n=e.updateQueue;if(n===null)return null;if(n=n.shared,Mt&2){var a=n.pending;return a===null?t.next=t:(t.next=a.next,a.next=t),n.pending=t,t=Pu(e),Vy(e,null,r),t}return Df(e,n,t,r),Pu(e)}function Ul(e,t,r){if(t=t.updateQueue,t!==null&&(t=t.shared,(r&4194048)!==0)){var n=t.lanes;n&=e.pendingLanes,r|=n,t.lanes=r,wy(e,r)}}function Pd(e,t){var r=e.updateQueue,n=e.alternate;if(n!==null&&(n=n.updateQueue,r===n)){var a=null,i=null;if(r=r.firstBaseUpdate,r!==null){do{var s={lane:r.lane,tag:r.tag,payload:r.payload,callback:null,next:null};i===null?a=i=s:i=i.next=s,r=r.next}while(r!==null);i===null?a=i=t:i=i.next=t}else a=i=t;r={baseState:n.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:n.shared,callbacks:n.callbacks},e.updateQueue=r;return}e=r.lastBaseUpdate,e===null?r.firstBaseUpdate=t:e.next=t,r.lastBaseUpdate=t}var _h=!1;function kl(){if(_h){var e=mo;if(e!==null)throw e}}function zl(e,t,r,n){_h=!1;var a=e.updateQueue;ui=!1;var i=a.firstBaseUpdate,s=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,d=c.next;c.next=null,s===null?i=d:s.next=d,s=c;var p=e.alternate;p!==null&&(p=p.updateQueue,o=p.lastBaseUpdate,o!==s&&(o===null?p.firstBaseUpdate=d:o.next=d,p.lastBaseUpdate=c))}if(i!==null){var y=a.baseState;s=0,p=d=c=null,o=i;do{var g=o.lane&-536870913,v=g!==o.lane;if(v?(mt&g)===g:(n&g)===g){g!==0&&g===So&&(_h=!0),p!==null&&(p=p.next={lane:0,tag:o.tag,payload:o.payload,callback:null,next:null});e:{var M=e,z=o;g=t;var K=r;switch(z.tag){case 1:if(M=z.payload,typeof M=="function"){y=M.call(K,y,g);break e}y=M;break e;case 3:M.flags=M.flags&-65537|128;case 0:if(M=z.payload,g=typeof M=="function"?M.call(K,y,g):M,g==null)break e;y=Xt({},y,g);break e;case 2:ui=!0}}g=o.callback,g!==null&&(e.flags|=64,v&&(e.flags|=8192),v=a.callbacks,v===null?a.callbacks=[g]:v.push(g))}else v={lane:g,tag:o.tag,payload:o.payload,callback:o.callback,next:null},p===null?(d=p=v,c=y):p=p.next=v,s|=g;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;v=o,o=v.next,v.next=null,a.lastBaseUpdate=v,a.shared.pending=null}}while(!0);p===null&&(c=y),a.baseState=c,a.firstBaseUpdate=d,a.lastBaseUpdate=p,i===null&&(a.shared.lanes=0),Di|=s,e.lanes=s,e.memoizedState=y}}function a2(e,t){if(typeof e!="function")throw Error(xe(191,e));e.call(t)}function i2(e,t){var r=e.callbacks;if(r!==null)for(e.callbacks=null,e=0;ei?i:8;var s=Ze.T,o={};Ze.T=o,n1(e,!1,t,r);try{var c=a(),d=Ze.S;if(d!==null&&d(o,c),c!==null&&typeof c=="object"&&typeof c.then=="function"){var p=O4(c,n);Dl(e,t,p,Tn(e))}else Dl(e,t,n,Tn(e))}catch(y){Dl(e,t,{then:function(){},status:"rejected",reason:y},Tn())}finally{Ct.p=i,s!==null&&o.types!==null&&(s.types=o.types),Ze.T=s}}function I4(){}function jh(e,t,r,n){if(e.tag!==5)throw Error(xe(476));var a=C2(e).queue;M2(e,a,t,cs,r===null?I4:function(){return B2(e),r(n)})}function C2(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:cs,baseState:cs,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Va,lastRenderedState:cs},next:null};var r={};return t.next={memoizedState:r,baseState:r,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Va,lastRenderedState:r},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function B2(e){var t=C2(e);t.next===null&&(t=e.alternate.memoizedState),Dl(e,t.next.queue,{},Tn())}function r1(){return Dr(ic)}function O2(){return fr().memoizedState}function R2(){return fr().memoizedState}function L4(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var r=Tn();e=Ni(r);var n=ji(t,e,r);n!==null&&(fn(n,t,r),Ul(n,t,r)),t={cache:qp()},e.payload=t;return}t=t.return}}function H4(e,t,r){var n=Tn();r={lane:n,revertLane:0,gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},$f(e)?k2(t,r):(r=Dp(e,t,r,n),r!==null&&(fn(r,e,n),z2(r,t,n)))}function U2(e,t,r){var n=Tn();Dl(e,t,r,n)}function Dl(e,t,r,n){var a={lane:n,revertLane:0,gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null};if($f(e))k2(t,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var s=t.lastRenderedState,o=i(s,r);if(a.hasEagerState=!0,a.eagerState=o,Mn(o,s))return Df(e,t,a,0),qt===null&&zf(),!1}catch{}finally{}if(r=Dp(e,t,a,n),r!==null)return fn(r,e,n),z2(r,t,n),!0}return!1}function n1(e,t,r,n){if(n={lane:2,revertLane:d1(),gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},$f(e)){if(t)throw Error(xe(479))}else t=Dp(e,r,n,2),t!==null&&fn(t,e,2)}function $f(e){var t=e.alternate;return e===it||t!==null&&t===it}function k2(e,t){yo=Qu=!0;var r=e.pending;r===null?t.next=t:(t.next=r.next,r.next=t),e.pending=t}function z2(e,t,r){if(r&4194048){var n=t.lanes;n&=e.pendingLanes,r|=n,t.lanes=r,wy(e,r)}}var rc={readContext:Dr,use:Hf,useCallback:sr,useContext:sr,useEffect:sr,useImperativeHandle:sr,useLayoutEffect:sr,useInsertionEffect:sr,useMemo:sr,useReducer:sr,useRef:sr,useState:sr,useDebugValue:sr,useDeferredValue:sr,useTransition:sr,useSyncExternalStore:sr,useId:sr,useHostTransitionStatus:sr,useFormState:sr,useActionState:sr,useOptimistic:sr,useMemoCache:sr,useCacheRefresh:sr};rc.useEffectEvent=sr;var D2={readContext:Dr,use:Hf,useCallback:function(e,t){return Gr().memoizedState=[e,t===void 0?null:t],e},useContext:Dr,useEffect:Xb,useImperativeHandle:function(e,t,r){r=r!=null?r.concat([e]):null,Nu(4194308,4,E2.bind(null,t,e),r)},useLayoutEffect:function(e,t){return Nu(4194308,4,e,t)},useInsertionEffect:function(e,t){Nu(4,2,e,t)},useMemo:function(e,t){var r=Gr();t=t===void 0?null:t;var n=e();if(_s){yi(!0);try{e()}finally{yi(!1)}}return r.memoizedState=[n,t],n},useReducer:function(e,t,r){var n=Gr();if(r!==void 0){var a=r(t);if(_s){yi(!0);try{r(t)}finally{yi(!1)}}}else a=t;return n.memoizedState=n.baseState=a,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:a},n.queue=e,e=e.dispatch=H4.bind(null,it,e),[n.memoizedState,e]},useRef:function(e){var t=Gr();return e={current:e},t.memoizedState=e},useState:function(e){e=Ah(e);var t=e.queue,r=U2.bind(null,it,t);return t.dispatch=r,[e.memoizedState,r]},useDebugValue:e1,useDeferredValue:function(e,t){var r=Gr();return t1(r,e,t)},useTransition:function(){var e=Ah(!1);return e=M2.bind(null,it,e.queue,!0,!1),Gr().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,r){var n=it,a=Gr();if(vt){if(r===void 0)throw Error(xe(407));r=r()}else{if(r=t(),qt===null)throw Error(xe(349));mt&127||u2(n,t,r)}a.memoizedState=r;var i={value:r,getSnapshot:t};return a.queue=i,Xb(d2.bind(null,n,i,e),[e]),n.flags|=2048,Ao(9,{destroy:void 0},f2.bind(null,n,i,r,t),null),r},useId:function(){var e=Gr(),t=qt.identifierPrefix;if(vt){var r=ua,n=ca;r=(n&~(1<<32-jn(n)-1)).toString(32)+r,t="_"+t+"R_"+r,r=Ju++,0<\/script>",i=i.removeChild(i.firstChild);break;case"select":i=typeof n.is=="string"?s.createElement("select",{is:n.is}):s.createElement("select"),n.multiple?i.multiple=!0:n.size&&(i.size=n.size);break;default:i=typeof n.is=="string"?s.createElement(a,{is:n.is}):s.createElement(a)}}i[kr]=t,i[dn]=n;e:for(s=t.child;s!==null;){if(s.tag===5||s.tag===6)i.appendChild(s.stateNode);else if(s.tag!==4&&s.tag!==27&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break e;for(;s.sibling===null;){if(s.return===null||s.return===t)break e;s=s.return}s.sibling.return=s.return,s=s.sibling}t.stateNode=i;e:switch(Ir(i,a,n),a){case"button":case"input":case"select":case"textarea":n=!!n.autoFocus;break e;case"img":n=!0;break e;default:n=!1}n&&Ca(t)}}return Gt(t),Wd(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,r),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==n&&Ca(t);else{if(typeof n!="string"&&t.stateNode===null)throw Error(xe(166));if(e=Ei.current,Ks(t)){if(e=t.stateNode,r=t.memoizedProps,n=null,a=zr,a!==null)switch(a.tag){case 27:case 5:n=a.memoizedProps}e[kr]=t,e=!!(e.nodeValue===r||n!==null&&n.suppressHydrationWarning===!0||Ug(e.nodeValue,r)),e||ki(t,!0)}else e=cf(e).createTextNode(n),e[kr]=t,t.stateNode=e}return Gt(t),null;case 31:if(r=t.memoizedState,e===null||e.memoizedState!==null){if(n=Ks(t),r!==null){if(e===null){if(!n)throw Error(xe(318));if(e=t.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(xe(557));e[kr]=t}else gs(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Gt(t),e=!1}else r=Kd(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=r),e=!0;if(!e)return t.flags&256?(vn(t),t):(vn(t),null);if(t.flags&128)throw Error(xe(558))}return Gt(t),null;case 13:if(n=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Ks(t),n!==null&&n.dehydrated!==null){if(e===null){if(!a)throw Error(xe(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(xe(317));a[kr]=t}else gs(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Gt(t),a=!1}else a=Kd(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(vn(t),t):(vn(t),null)}return vn(t),t.flags&128?(t.lanes=r,t):(r=n!==null,e=e!==null&&e.memoizedState!==null,r&&(n=t.child,a=null,n.alternate!==null&&n.alternate.memoizedState!==null&&n.alternate.memoizedState.cachePool!==null&&(a=n.alternate.memoizedState.cachePool.pool),i=null,n.memoizedState!==null&&n.memoizedState.cachePool!==null&&(i=n.memoizedState.cachePool.pool),i!==a&&(n.flags|=2048)),r!==e&&r&&(t.child.flags|=8192),ru(t,t.updateQueue),Gt(t),null);case 4:return vo(),e===null&&h1(t.stateNode.containerInfo),Gt(t),null;case 10:return $a(t.type),Gt(t),null;case 19:if(Tr(ur),n=t.memoizedState,n===null)return Gt(t),null;if(a=(t.flags&128)!==0,i=n.rendering,i===null)if(a)dl(n,!1);else{if(or!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(i=Zu(e),i!==null){for(t.flags|=128,dl(n,!1),e=i.updateQueue,t.updateQueue=e,ru(t,e),t.subtreeFlags=0,e=r,r=t.child;r!==null;)Xy(r,e),r=r.sibling;return Kt(ur,ur.current&1|2),vt&&ka(t,n.treeForkCount),t.child}e=e.sibling}n.tail!==null&&An()>rf&&(t.flags|=128,a=!0,dl(n,!1),t.lanes=4194304)}else{if(!a)if(e=Zu(i),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,ru(t,e),dl(n,!0),n.tail===null&&n.tailMode==="hidden"&&!i.alternate&&!vt)return Gt(t),null}else 2*An()-n.renderingStartTime>rf&&r!==536870912&&(t.flags|=128,a=!0,dl(n,!1),t.lanes=4194304);n.isBackwards?(i.sibling=t.child,t.child=i):(e=n.last,e!==null?e.sibling=i:t.child=i,n.last=i)}return n.tail!==null?(e=n.tail,n.rendering=e,n.tail=e.sibling,n.renderingStartTime=An(),e.sibling=null,r=ur.current,Kt(ur,a?r&1|2:r&1),vt&&ka(t,n.treeForkCount),e):(Gt(t),null);case 22:case 23:return vn(t),Pp(),n=t.memoizedState!==null,e!==null?e.memoizedState!==null!==n&&(t.flags|=8192):n&&(t.flags|=8192),n?r&536870912&&!(t.flags&128)&&(Gt(t),t.subtreeFlags&6&&(t.flags|=8192)):Gt(t),r=t.updateQueue,r!==null&&ru(t,r.retryQueue),r=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(r=e.memoizedState.cachePool.pool),n=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(n=t.memoizedState.cachePool.pool),n!==r&&(t.flags|=2048),e!==null&&Tr(fs),null;case 24:return r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),$a(br),Gt(t),null;case 25:return null;case 30:return null}throw Error(xe(156,t.tag))}function P4(e,t){switch(Hp(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return $a(br),vo(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return qu(t),null;case 31:if(t.memoizedState!==null){if(vn(t),t.alternate===null)throw Error(xe(340));gs()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(vn(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(xe(340));gs()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Tr(ur),null;case 4:return vo(),null;case 10:return $a(t.type),null;case 22:case 23:return vn(t),Pp(),e!==null&&Tr(fs),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return $a(br),null;case 25:return null;default:return null}}function X2(e,t){switch(Hp(t),t.tag){case 3:$a(br),vo();break;case 26:case 27:case 5:qu(t);break;case 4:vo();break;case 31:t.memoizedState!==null&&vn(t);break;case 13:vn(t);break;case 19:Tr(ur);break;case 10:$a(t.type);break;case 22:case 23:vn(t),Pp(),e!==null&&Tr(fs);break;case 24:$a(br)}}function Sc(e,t){try{var r=t.updateQueue,n=r!==null?r.lastEffect:null;if(n!==null){var a=n.next;r=a;do{if((r.tag&e)===e){n=void 0;var i=r.create,s=r.inst;n=i(),s.destroy=n}r=r.next}while(r!==a)}}catch(o){Ut(t,t.return,o)}}function zi(e,t,r){try{var n=t.updateQueue,a=n!==null?n.lastEffect:null;if(a!==null){var i=a.next;n=i;do{if((n.tag&e)===e){var s=n.inst,o=s.destroy;if(o!==void 0){s.destroy=void 0,a=t;var c=r,d=o;try{d()}catch(p){Ut(a,c,p)}}}n=n.next}while(n!==i)}}catch(p){Ut(t,t.return,p)}}function Z2(e){var t=e.updateQueue;if(t!==null){var r=e.stateNode;try{i2(t,r)}catch(n){Ut(e,e.return,n)}}}function Q2(e,t,r){r.props=Ss(e.type,e.memoizedProps),r.state=e.memoizedState;try{r.componentWillUnmount()}catch(n){Ut(e,t,n)}}function Il(e,t){try{var r=e.ref;if(r!==null){switch(e.tag){case 26:case 27:case 5:var n=e.stateNode;break;case 30:n=e.stateNode;break;default:n=e.stateNode}typeof r=="function"?e.refCleanup=r(n):r.current=n}}catch(a){Ut(e,t,a)}}function fa(e,t){var r=e.ref,n=e.refCleanup;if(r!==null)if(typeof n=="function")try{n()}catch(a){Ut(e,t,a)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof r=="function")try{r(null)}catch(a){Ut(e,t,a)}else r.current=null}function J2(e){var t=e.type,r=e.memoizedProps,n=e.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":r.autoFocus&&n.focus();break e;case"img":r.src?n.src=r.src:r.srcSet&&(n.srcset=r.srcSet)}}catch(a){Ut(e,e.return,a)}}function e0(e,t,r){try{var n=e.stateNode;h8(n,e.type,r,t),n[dn]=t}catch(a){Ut(e,e.return,a)}}function W2(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Pi(e.type)||e.tag===4}function t0(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||W2(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Pi(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Oh(e,t,r){var n=e.tag;if(n===5||n===6)e=e.stateNode,t?(r.nodeType===9?r.body:r.nodeName==="HTML"?r.ownerDocument.body:r).insertBefore(e,t):(t=r.nodeType===9?r.body:r.nodeName==="HTML"?r.ownerDocument.body:r,t.appendChild(e),r=r._reactRootContainer,r!=null||t.onclick!==null||(t.onclick=Ia));else if(n!==4&&(n===27&&Pi(e.type)&&(r=e.stateNode,t=null),e=e.child,e!==null))for(Oh(e,t,r),e=e.sibling;e!==null;)Oh(e,t,r),e=e.sibling}function tf(e,t,r){var n=e.tag;if(n===5||n===6)e=e.stateNode,t?r.insertBefore(e,t):r.appendChild(e);else if(n!==4&&(n===27&&Pi(e.type)&&(r=e.stateNode),e=e.child,e!==null))for(tf(e,t,r),e=e.sibling;e!==null;)tf(e,t,r),e=e.sibling}function eg(e){var t=e.stateNode,r=e.memoizedProps;try{for(var n=e.type,a=t.attributes;a.length;)t.removeAttributeNode(a[0]);Ir(t,n,r),t[kr]=e,t[dn]=r}catch(i){Ut(e,e.return,i)}}var za=!1,pr=!1,r0=!1,lm=typeof WeakSet=="function"?WeakSet:Set,Sr=null;function G4(e,t){if(e=e.containerInfo,Lh=hf,e=qy(e),kp(e)){if("selectionStart"in e)var r={start:e.selectionStart,end:e.selectionEnd};else e:{r=(r=e.ownerDocument)&&r.defaultView||window;var n=r.getSelection&&r.getSelection();if(n&&n.rangeCount!==0){r=n.anchorNode;var a=n.anchorOffset,i=n.focusNode;n=n.focusOffset;try{r.nodeType,i.nodeType}catch{r=null;break e}var s=0,o=-1,c=-1,d=0,p=0,y=e,g=null;t:for(;;){for(var v;y!==r||a!==0&&y.nodeType!==3||(o=s+a),y!==i||n!==0&&y.nodeType!==3||(c=s+n),y.nodeType===3&&(s+=y.nodeValue.length),(v=y.firstChild)!==null;)g=y,y=v;for(;;){if(y===e)break t;if(g===r&&++d===a&&(o=s),g===i&&++p===n&&(c=s),(v=y.nextSibling)!==null)break;y=g,g=y.parentNode}y=v}r=o===-1||c===-1?null:{start:o,end:c}}else r=null}r=r||{start:0,end:0}}else r=null;for(Hh={focusedElem:e,selectionRange:r},hf=!1,Sr=t;Sr!==null;)if(t=Sr,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Sr=e;else for(;Sr!==null;){switch(t=Sr,i=t.alternate,e=t.flags,t.tag){case 0:if(e&4&&(e=t.updateQueue,e=e!==null?e.events:null,e!==null))for(r=0;r title"))),Ir(i,n,r),i[kr]=e,Ar(i),n=i;break e;case"link":var s=Tm("link","href",a).get(n+(r.href||""));if(s){for(var o=0;oK&&(s=K,K=z,z=s);var D=Rb(o,z),T=Rb(o,K);if(D&&T&&(v.rangeCount!==1||v.anchorNode!==D.node||v.anchorOffset!==D.offset||v.focusNode!==T.node||v.focusOffset!==T.offset)){var k=y.createRange();k.setStart(D.node,D.offset),v.removeAllRanges(),z>K?(v.addRange(k),v.extend(T.node,T.offset)):(k.setEnd(T.node,T.offset),v.addRange(k))}}}}for(y=[],v=o;v=v.parentNode;)v.nodeType===1&&y.push({element:v,left:v.scrollLeft,top:v.scrollTop});for(typeof o.focus=="function"&&o.focus(),o=0;or?32:r,Ze.T=null,r=kh,kh=null;var i=Mi,s=Fa;if(vr=0,jo=Mi=null,Fa=0,Mt&6)throw Error(xe(331));var o=Mt;if(Mt|=4,fg(i.current),lg(i,i.current,s,r),Mt=o,Ec(0,!1),Nn&&typeof Nn.onPostCommitFiberRoot=="function")try{Nn.onPostCommitFiberRoot(mc,i)}catch{}return!0}finally{Ct.p=a,Ze.T=n,Ng(e,t)}}function dm(e,t,r){t=$n(r,t),t=Mh(e.stateNode,t,2),e=ji(e,t,2),e!==null&&(yc(e,2),Aa(e))}function Ut(e,t,r){if(e.tag===3)dm(e,e,r);else for(;t!==null;){if(t.tag===3){dm(t,e,r);break}else if(t.tag===1){var n=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof n.componentDidCatch=="function"&&(Ti===null||!Ti.has(n))){e=$n(r,e),r=$2(2),n=ji(t,r,2),n!==null&&(F2(r,n,t,e),yc(n,2),Aa(n));break}}t=t.return}}function a0(e,t,r){var n=e.pingCache;if(n===null){n=e.pingCache=new X4;var a=new Set;n.set(t,a)}else a=n.get(t),a===void 0&&(a=new Set,n.set(t,a));a.has(r)||(c1=!0,a.add(r),e=e8.bind(null,e,t,r),t.then(e,e))}function e8(e,t,r){var n=e.pingCache;n!==null&&n.delete(t),e.pingedLanes|=e.suspendedLanes&r,e.warmLanes&=~r,qt===e&&(mt&r)===r&&(or===4||or===3&&(mt&62914560)===mt&&300>An()-Ff?!(Mt&2)&&To(e,0):u1|=r,No===mt&&(No=0)),Aa(e)}function Tg(e,t){t===0&&(t=gy()),e=ks(e,t),e!==null&&(yc(e,t),Aa(e))}function t8(e){var t=e.memoizedState,r=0;t!==null&&(r=t.retryLane),Tg(e,r)}function r8(e,t){var r=0;switch(e.tag){case 31:case 13:var n=e.stateNode,a=e.memoizedState;a!==null&&(r=a.retryLane);break;case 19:n=e.stateNode;break;case 22:n=e.stateNode._retryCache;break;default:throw Error(xe(314))}n!==null&&n.delete(t),Tg(e,r)}function n8(e,t){return Np(e,t)}var sf=null,Zs=null,Dh=!1,of=!1,i0=!1,_i=0;function Aa(e){e!==Zs&&e.next===null&&(Zs===null?sf=Zs=e:Zs=Zs.next=e),of=!0,Dh||(Dh=!0,i8())}function Ec(e,t){if(!i0&&of){i0=!0;do for(var r=!1,n=sf;n!==null;){if(e!==0){var a=n.pendingLanes;if(a===0)var i=0;else{var s=n.suspendedLanes,o=n.pingedLanes;i=(1<<31-jn(42|e)+1)-1,i&=a&~(s&~o),i=i&201326741?i&201326741|1:i?i|2:0}i!==0&&(r=!0,hm(n,i))}else i=mt,i=Of(n,n===qt?i:0,n.cancelPendingCommit!==null||n.timeoutHandle!==-1),!(i&3)||xc(n,i)||(r=!0,hm(n,i));n=n.next}while(r);i0=!1}}function a8(){Mg()}function Mg(){of=Dh=!1;var e=0;_i!==0&&b8()&&(e=_i);for(var t=An(),r=null,n=sf;n!==null;){var a=n.next,i=Cg(n,t);i===0?(n.next=null,r===null?sf=a:r.next=a,a===null&&(Zs=r)):(r=n,(e!==0||i&3)&&(of=!0)),n=a}vr!==0&&vr!==5||Ec(e),_i!==0&&(_i=0)}function Cg(e,t){for(var r=e.suspendedLanes,n=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes&-62914561;0o)break;var p=c.transferSize,y=c.initiatorType;p&&ym(y)&&(c=c.responseEnd,s+=p*(c"u"?null:document;function Lg(e,t,r){var n=Go;if(n&&typeof t=="string"&&t){var a=qn(t);a='link[rel="'+e+'"][href="'+a+'"]',typeof r=="string"&&(a+='[crossorigin="'+r+'"]'),Am.has(a)||(Am.add(a),e={rel:e,crossOrigin:r,href:t},n.querySelector(a)===null&&(t=n.createElement("link"),Ir(t,"link",e),Ar(t),n.head.appendChild(t)))}}function E8(e){ti.D(e),Lg("dns-prefetch",e,null)}function A8(e,t){ti.C(e,t),Lg("preconnect",e,t)}function N8(e,t,r){ti.L(e,t,r);var n=Go;if(n&&e&&t){var a='link[rel="preload"][as="'+qn(t)+'"]';t==="image"&&r&&r.imageSrcSet?(a+='[imagesrcset="'+qn(r.imageSrcSet)+'"]',typeof r.imageSizes=="string"&&(a+='[imagesizes="'+qn(r.imageSizes)+'"]')):a+='[href="'+qn(e)+'"]';var i=a;switch(t){case"style":i=Mo(e);break;case"script":i=Yo(e)}Yn.has(i)||(e=Xt({rel:"preload",href:t==="image"&&r&&r.imageSrcSet?void 0:e,as:t},r),Yn.set(i,e),n.querySelector(a)!==null||t==="style"&&n.querySelector(Ac(i))||t==="script"&&n.querySelector(Nc(i))||(t=n.createElement("link"),Ir(t,"link",e),Ar(t),n.head.appendChild(t)))}}function j8(e,t){ti.m(e,t);var r=Go;if(r&&e){var n=t&&typeof t.as=="string"?t.as:"script",a='link[rel="modulepreload"][as="'+qn(n)+'"][href="'+qn(e)+'"]',i=a;switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":i=Yo(e)}if(!Yn.has(i)&&(e=Xt({rel:"modulepreload",href:e},t),Yn.set(i,e),r.querySelector(a)===null)){switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(r.querySelector(Nc(i)))return}n=r.createElement("link"),Ir(n,"link",e),Ar(n),r.head.appendChild(n)}}}function T8(e,t,r){ti.S(e,t,r);var n=Go;if(n&&e){var a=ho(n).hoistableStyles,i=Mo(e);t=t||"default";var s=a.get(i);if(!s){var o={loading:0,preload:null};if(s=n.querySelector(Ac(i)))o.loading=5;else{e=Xt({rel:"stylesheet",href:e,"data-precedence":t},r),(r=Yn.get(i))&&p1(e,r);var c=s=n.createElement("link");Ar(c),Ir(c,"link",e),c._p=new Promise(function(d,p){c.onload=d,c.onerror=p}),c.addEventListener("load",function(){o.loading|=1}),c.addEventListener("error",function(){o.loading|=2}),o.loading|=4,Cu(s,t,n)}s={type:"stylesheet",instance:s,count:1,state:o},a.set(i,s)}}}function M8(e,t){ti.X(e,t);var r=Go;if(r&&e){var n=ho(r).hoistableScripts,a=Yo(e),i=n.get(a);i||(i=r.querySelector(Nc(a)),i||(e=Xt({src:e,async:!0},t),(t=Yn.get(a))&&b1(e,t),i=r.createElement("script"),Ar(i),Ir(i,"link",e),r.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},n.set(a,i))}}function C8(e,t){ti.M(e,t);var r=Go;if(r&&e){var n=ho(r).hoistableScripts,a=Yo(e),i=n.get(a);i||(i=r.querySelector(Nc(a)),i||(e=Xt({src:e,async:!0,type:"module"},t),(t=Yn.get(a))&&b1(e,t),i=r.createElement("script"),Ar(i),Ir(i,"link",e),r.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},n.set(a,i))}}function Nm(e,t,r,n){var a=(a=Ei.current)?uf(a):null;if(!a)throw Error(xe(446));switch(e){case"meta":case"title":return null;case"style":return typeof r.precedence=="string"&&typeof r.href=="string"?(t=Mo(r.href),r=ho(a).hoistableStyles,n=r.get(t),n||(n={type:"style",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};case"link":if(r.rel==="stylesheet"&&typeof r.href=="string"&&typeof r.precedence=="string"){e=Mo(r.href);var i=ho(a).hoistableStyles,s=i.get(e);if(s||(a=a.ownerDocument||a,s={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},i.set(e,s),(i=a.querySelector(Ac(e)))&&!i._p&&(s.instance=i,s.state.loading=5),Yn.has(e)||(r={rel:"preload",as:"style",href:r.href,crossOrigin:r.crossOrigin,integrity:r.integrity,media:r.media,hrefLang:r.hrefLang,referrerPolicy:r.referrerPolicy},Yn.set(e,r),i||B8(a,e,r,s.state))),t&&n===null)throw Error(xe(528,""));return s}if(t&&n!==null)throw Error(xe(529,""));return null;case"script":return t=r.async,r=r.src,typeof r=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=Yo(r),r=ho(a).hoistableScripts,n=r.get(t),n||(n={type:"script",instance:null,count:0,state:null},r.set(t,n)),n):{type:"void",instance:null,count:0,state:null};default:throw Error(xe(444,e))}}function Mo(e){return'href="'+qn(e)+'"'}function Ac(e){return'link[rel="stylesheet"]['+e+"]"}function Hg(e){return Xt({},e,{"data-precedence":e.precedence,precedence:null})}function B8(e,t,r,n){e.querySelector('link[rel="preload"][as="style"]['+t+"]")?n.loading=1:(t=e.createElement("link"),n.preload=t,t.addEventListener("load",function(){return n.loading|=1}),t.addEventListener("error",function(){return n.loading|=2}),Ir(t,"link",r),Ar(t),e.head.appendChild(t))}function Yo(e){return'[src="'+qn(e)+'"]'}function Nc(e){return"script[async]"+e}function jm(e,t,r){if(t.count++,t.instance===null)switch(t.type){case"style":var n=e.querySelector('style[data-href~="'+qn(r.href)+'"]');if(n)return t.instance=n,Ar(n),n;var a=Xt({},r,{"data-href":r.href,"data-precedence":r.precedence,href:null,precedence:null});return n=(e.ownerDocument||e).createElement("style"),Ar(n),Ir(n,"style",a),Cu(n,r.precedence,e),t.instance=n;case"stylesheet":a=Mo(r.href);var i=e.querySelector(Ac(a));if(i)return t.state.loading|=4,t.instance=i,Ar(i),i;n=Hg(r),(a=Yn.get(a))&&p1(n,a),i=(e.ownerDocument||e).createElement("link"),Ar(i);var s=i;return s._p=new Promise(function(o,c){s.onload=o,s.onerror=c}),Ir(i,"link",n),t.state.loading|=4,Cu(i,r.precedence,e),t.instance=i;case"script":return i=Yo(r.src),(a=e.querySelector(Nc(i)))?(t.instance=a,Ar(a),a):(n=r,(a=Yn.get(i))&&(n=Xt({},r),b1(n,a)),e=e.ownerDocument||e,a=e.createElement("script"),Ar(a),Ir(a,"link",n),e.head.appendChild(a),t.instance=a);case"void":return null;default:throw Error(xe(443,t.type))}else t.type==="stylesheet"&&!(t.state.loading&4)&&(n=t.instance,t.state.loading|=4,Cu(n,r.precedence,e));return t.instance}function Cu(e,t,r){for(var n=r.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),a=n.length?n[n.length-1]:null,i=a,s=0;s title"):null)}function O8(e,t,r){if(r===1||t.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return e=t.disabled,typeof t.precedence=="string"&&e==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function qg(e){return!(e.type==="stylesheet"&&!(e.state.loading&3))}function R8(e,t,r,n){if(r.type==="stylesheet"&&(typeof n.media!="string"||matchMedia(n.media).matches!==!1)&&!(r.state.loading&4)){if(r.instance===null){var a=Mo(n.href),i=t.querySelector(Ac(a));if(i){t=i._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(e.count++,e=ff.bind(e),t.then(e,e)),r.state.loading|=4,r.instance=i,Ar(i);return}i=t.ownerDocument||t,n=Hg(n),(a=Yn.get(a))&&p1(n,a),i=i.createElement("link"),Ar(i);var s=i;s._p=new Promise(function(o,c){s.onload=o,s.onerror=c}),Ir(i,"link",n),r.instance=i}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(r,t),(t=r.state.preload)&&!(r.state.loading&3)&&(e.count++,r=ff.bind(e),t.addEventListener("load",r),t.addEventListener("error",r))}}var f0=0;function U8(e,t){return e.stylesheets&&e.count===0&&Ou(e,e.stylesheets),0f0?50:800)+t);return e.unsuspend=r,function(){e.unsuspend=null,clearTimeout(n),clearTimeout(a)}}:null}function ff(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Ou(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var df=null;function Ou(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,df=new Map,t.forEach(k8,e),df=null,ff.call(e))}function k8(e,t){if(!(t.state.loading&4)){var r=df.get(e);if(r)var n=r.get(null);else{r=new Map,df.set(e,r);for(var a=e.querySelectorAll("link[data-precedence],style[data-precedence]"),i=0;i"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Xg)}catch(e){console.error(e)}}Xg(),ny.exports=Cf;var F8=ny.exports;/** * @license lucide-react v0.468.0 - ISC * * This source code is licensed under the ISC license. @@ -61,7 +61,7 @@ Error generating stack: `+n.message+` * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const G8=re.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:r=2,absoluteStrokeWidth:n,className:a="",children:i,iconNode:s,...o},c)=>re.createElement("svg",{ref:c,...P8,width:t,height:t,stroke:e,strokeWidth:n?Number(r)*24/Number(t):r,className:Zg("lucide",a),...o},[...s.map(([h,p])=>re.createElement(h,p)),...Array.isArray(i)?i:[i]]));/** + */const G8=re.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:r=2,absoluteStrokeWidth:n,className:a="",children:i,iconNode:s,...o},c)=>re.createElement("svg",{ref:c,...P8,width:t,height:t,stroke:e,strokeWidth:n?Number(r)*24/Number(t):r,className:Zg("lucide",a),...o},[...s.map(([d,p])=>re.createElement(d,p)),...Array.isArray(i)?i:[i]]));/** * @license lucide-react v0.468.0 - ISC * * This source code is licensed under the ISC license. @@ -141,7 +141,7 @@ Error generating stack: `+n.message+` * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const ha=Ve("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** + */const pa=Ve("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** * @license lucide-react v0.468.0 - ISC * * This source code is licensed under the ISC license. @@ -261,7 +261,7 @@ Error generating stack: `+n.message+` * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const wn=Ve("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/** + */const cn=Ve("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/** * @license lucide-react v0.468.0 - ISC * * This source code is licensed under the ISC license. @@ -306,14 +306,14 @@ Error generating stack: `+n.message+` * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const xa=Ve("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/** + */const ya=Ve("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/** * @license lucide-react v0.468.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const ya=Ve("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);var Wh=function(e,t){return Wh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(r[a]=n[a])},Wh(e,t)};function Jr(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Wh(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function av(e,t,r,n){function a(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function o(p){try{h(n.next(p))}catch(y){s(y)}}function c(p){try{h(n.throw(p))}catch(y){s(y)}}function h(p){p.done?i(p.value):a(p.value).then(o,c)}h((n=n.apply(e,t||[])).next())})}function Xf(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,a,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=o(0),s.throw=o(1),s.return=o(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(h){return function(p){return c([h,p])}}function c(h){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,h[0]&&(r=0)),r;)try{if(n=1,a&&(i=h[0]&2?a.return:h[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,h[1])).done)return i;switch(a=0,i&&(h=[h[0]&2,i.value]),h[0]){case 0:case 1:i=h;break;case 4:return r.label++,{value:h[1],done:!1};case 5:r.label++,a=h[1],h=[0];continue;case 7:h=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(h[0]===6||h[0]===2)){r=0;continue}if(h[0]===3&&(!i||h[1]>i[0]&&h[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Es(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),a,i=[],s;try{for(;(t===void 0||t-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(o){s={error:o}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function As(e,t,r){if(r||arguments.length===2)for(var n=0,a=t.length,i;n1||c(v,k)})},M&&(a[v]=M(a[v])))}function c(v,M){try{h(n[v](M))}catch(k){g(i[0][3],k)}}function h(v){v.value instanceof Pa?Promise.resolve(v.value.v).then(p,y):g(i[0][2],v)}function p(v){c("next",v)}function y(v){c("throw",v)}function g(v,M){v(M),i.shift(),i.length&&c(i[0][0],i[0][1])}}function sv(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof ga=="function"?ga(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(o,c){s=e[i](s),a(o,c,s.done,s.value)})}}function a(i,s,o,c){Promise.resolve(c).then(function(h){i({value:h,done:o})},s)}}function wr(e){return typeof e=="function"}function _1(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var d0=_1(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: + */const ga=Ve("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);var Wh=function(e,t){return Wh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(r[a]=n[a])},Wh(e,t)};function Jr(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Wh(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function av(e,t,r,n){function a(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function o(p){try{d(n.next(p))}catch(y){s(y)}}function c(p){try{d(n.throw(p))}catch(y){s(y)}}function d(p){p.done?i(p.value):a(p.value).then(o,c)}d((n=n.apply(e,t||[])).next())})}function Xf(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,a,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=o(0),s.throw=o(1),s.return=o(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(d){return function(p){return c([d,p])}}function c(d){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,d[0]&&(r=0)),r;)try{if(n=1,a&&(i=d[0]&2?a.return:d[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,d[1])).done)return i;switch(a=0,i&&(d=[d[0]&2,i.value]),d[0]){case 0:case 1:i=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,a=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(d[0]===6||d[0]===2)){r=0;continue}if(d[0]===3&&(!i||d[1]>i[0]&&d[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Es(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),a,i=[],s;try{for(;(t===void 0||t-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(o){s={error:o}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function As(e,t,r){if(r||arguments.length===2)for(var n=0,a=t.length,i;n1||c(v,z)})},M&&(a[v]=M(a[v])))}function c(v,M){try{d(n[v](M))}catch(z){g(i[0][3],z)}}function d(v){v.value instanceof Pa?Promise.resolve(v.value.v).then(p,y):g(i[0][2],v)}function p(v){c("next",v)}function y(v){c("throw",v)}function g(v,M){v(M),i.shift(),i.length&&c(i[0][0],i[0][1])}}function sv(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof va=="function"?va(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(o,c){s=e[i](s),a(o,c,s.done,s.value)})}}function a(i,s,o,c){Promise.resolve(c).then(function(d){i({value:d,done:o})},s)}}function wr(e){return typeof e=="function"}function _1(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var d0=_1(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: `+r.map(function(n,a){return a+1+") "+n.toString()}).join(` - `):"",this.name="UnsubscriptionError",this.errors=r}});function mf(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Bc=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,a,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=ga(s),c=o.next();!c.done;c=o.next()){var h=c.value;h.remove(this)}}catch(k){t={error:k}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}else s.remove(this);var p=this.initialTeardown;if(wr(p))try{p()}catch(k){i=k instanceof d0?k.errors:[k]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var g=ga(y),v=g.next();!v.done;v=g.next()){var M=v.value;try{zm(M)}catch(k){i=i??[],k instanceof d0?i=As(As([],Es(i)),Es(k.errors)):i.push(k)}}}catch(k){n={error:k}}finally{try{v&&!v.done&&(a=g.return)&&a.call(g)}finally{if(n)throw n.error}}}if(i)throw new d0(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)zm(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&mf(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&mf(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),ov=Bc.EMPTY;function lv(e){return e instanceof Bc||e&&"closed"in e&&wr(e.remove)&&wr(e.add)&&wr(e.unsubscribe)}function zm(e){wr(e)?e():e.unsubscribe()}var uw={Promise:void 0},fw={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,a=this,i=a.hasError,s=a.isStopped,o=a.observers;return i||s?ov:(this.currentObservers=null,o.push(r),new Bc(function(){n.currentObservers=null,mf(o,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,a=n.hasError,i=n.thrownError,s=n.isStopped;a?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new Zr;return r.source=this,r},t.create=function(r,n){return new Im(r,n)},t}(Zr),Im=function(e){Jr(t,e);function t(r,n){var a=e.call(this)||this;return a.destination=r,a.source=n,a}return t.prototype.next=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.next)===null||a===void 0||a.call(n,r)},t.prototype.error=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.error)===null||a===void 0||a.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,a;return(a=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&a!==void 0?a:ov},t}(sn),dv=function(e){Jr(t,e);function t(r){var n=e.call(this)||this;return n._value=r,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(r){var n=e.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},t.prototype.getValue=function(){var r=this,n=r.hasError,a=r.thrownError,i=r._value;if(n)throw a;return this._throwIfClosed(),i},t.prototype.next=function(r){e.prototype.next.call(this,this._value=r)},t}(sn),ww={now:function(){return Date.now()}},_w=function(e){Jr(t,e);function t(r,n){return e.call(this)||this}return t.prototype.schedule=function(r,n){return this},t}(Bc),Lm={setInterval:function(e,t){for(var r=[],n=2;n!e),Tl(1)),uu={},Tv=new Map,A1=new sn;A1.asObservable();function Ww(e){Tv.set(e.name,e),A1.next({type:"add",store:e})}function e9(e){Tv.delete(e.name),A1.next({type:"remove",store:e})}let zu=[];function t9(e){zu.push(e)}function qm(e){zu.length&&zu.forEach(t=>e.next(t)),zu=[]}class r9 extends dv{constructor(t){super(t.state),this.storeDef=t,this.initialState=void 0,this.state=void 0,this.batchInProgress=!1,this.events=new sn,this.context={config:this.getConfig(),setEvent:r=>{t9(r)}},this.events$=this.events.asObservable(),this.state=this.getInitialState(t.state),this.initialState=this.getValue(),Ww(this)}get name(){return this.storeDef.name}getInitialState(t){return uu.preStateInit?uu.preStateInit(t,this.name):t}getConfig(){return this.storeDef.config}query(t){return t(this.getValue())}update(...t){const r=this.getValue();let n=t.reduce((a,i)=>(a=i(a,this.context),a),r);uu.preStoreUpdate&&(n=uu.preStoreUpdate(r,n,this.name)),n!==r&&(this.state=n,jv.getValue()?this.batchInProgress||(this.batchInProgress=!0,Jw.subscribe(()=>{super.next(this.state),qm(this.events),this.batchInProgress=!1})):(super.next(this.state),qm(this.events)))}getValue(){return this.state}reset(){this.update(()=>this.initialState)}combine(t){let r=!0;const n={};return new Zr(a=>{for(const[i,s]of Object.entries(t))a.add(s.subscribe(o=>{n[i]=o,r=!0}));return this.subscribe({next(){r&&(a.next({...n}),r=!1)},error(i){a.error(i)},complete(){a.complete()}})})}destroy(){e9(this),this.reset()}next(t){this.update(()=>t)}error(){}complete(){}}function n9(e,...t){const{state:r,config:n}=Qw(...t),{name:a}=e;return new r9({name:a,state:r,config:n})}function a9(e){return typeof e=="function"}function Yi(e,t){return function(r){return{...r,[e]:a9(t)?t(r[e]):t}}}function Vi(e){return bw(Gw(e),Xw())}function i9(e){return{props:e,config:void 0}}var bs=(e=>(e.PUBLIC="Public Global Stellar Network ; September 2015",e.TESTNET="Test SDF Network ; September 2015",e.FUTURENET="Test SDF Future Network ; October 2022",e.SANDBOX="Local Sandbox Stellar Network ; September 2022",e.STANDALONE="Standalone Network ; February 2017",e))(bs||{}),Vo=(e=>(e.HW_WALLET="HW_WALLET",e.HOT_WALLET="HOT_WALLET",e.BRIDGE_WALLET="BRIDGE_WALLET",e.AIR_GAPED_WALLET="AIR_GAPED_WALLET",e))(Vo||{});const yr=n9({name:"state"},i9({allowedWallets:[],hardwareWalletPaths:[]})),s9=yr.pipe(Vi(e=>e.allowedWallets));yr.pipe(Vi(e=>e.selectedNetwork));const o9=yr.pipe(Vi(e=>e.modalTheme)),l9=yr.pipe(Vi(e=>e.buttonTheme)),c9=yr.pipe(Vi(e=>e.activeAddress)),Mv=yr.pipe(Vi(e=>e.horizonUrl));yr.pipe(Vi(e=>e.mnemonicPath));yr.pipe(Vi(e=>e.hardwareWalletPaths));function m0(e){yr.update(Yi("selectedModuleId",e))}function u9(e){if(!Object.values(bs).includes(e))throw new Error(`Wallet network "${e}" is not supported`);yr.update(Yi("selectedNetwork",e))}function f9(e){yr.update(Yi("modalTheme",e))}function d9(e){yr.update(Yi("buttonTheme",e))}function $m(e){yr.update(Yi("allowedWallets",e))}function h9(e){yr.update(Yi("activeAddress",e))}function tp(){yr.update(Yi("activeAddress",void 0))}function p9(e){yr.update(Yi("horizonUrl",e))}class b9{get selectedModule(){const{selectedModuleId:t}=yr.getValue();if(!t)throw{code:-3,message:"Please set the wallet first"};const r=this.modules.find(n=>n.productId===t);if(!r)throw{code:-3,message:"Please set the wallet first"};return r}constructor(t){this.modules=t.modules,t.selectedWalletId&&this.setWallet(t.selectedWalletId),u9(t.network);const r=t.theme||t.modalTheme;r&&f9(r),t.buttonTheme&&d9(t.buttonTheme),this.getSupportedWallets().then(n=>{$m(n)})}async getSupportedWallets(){return Promise.all(this.modules.map(async t=>{const r=new Promise(n=>setTimeout(()=>n(!1),500));return{id:t.productId,name:t.productName,type:t.moduleType,icon:t.productIcon,isAvailable:await Promise.race([r,t.isAvailable()]),isPlatformWrapper:await Promise.race([r,t.isPlatformWrapper?t.isPlatformWrapper():Promise.resolve(!1)]),url:t.productUrl}}))}setWallet(t){const r=this.modules.find(n=>n.productId===t);if(!r)throw new Error(`Wallet id "${t}" is not supported`);m0(r.productId)}async getAddress(t){const{address:r}=await this.selectedModule.getAddress(t);return h9(r),{address:r}}async signTransaction(t,r){return this.selectedModule.signTransaction(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async signAuthEntry(t,r){return this.selectedModule.signAuthEntry(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async signMessage(t,r){return this.selectedModule.signMessage(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async getNetwork(){return this.selectedModule.getNetwork()}async disconnect(){tp()}isButtonCreated(){return!!this.buttonElement}assignButtons(t){const r=typeof t.connectEl=="string"?document.querySelector(t.connectEl):t.connectEl;if(!r)throw new Error("connectEl is not available");if(r.addEventListener("click",()=>{this.openModal({onWalletSelected:a=>{m0(a.id),this.getAddress().then(i=>t.onConnect(i))}}).then()},!1),!t.disconnectEl)return;const n=typeof t.disconnectEl=="string"?document.querySelector(t.disconnectEl):t.disconnectEl;if(!n)throw new Error("disconnectEl is not available");n.addEventListener("click",()=>{t.onDisconnect(),tp(),this.selectedModule.disconnect&&this.selectedModule.disconnect().then()},!1)}async createButton(t){if(this.buttonElement)throw new Error("Stellar Wallets Kit button is already created");this.buttonElement=document.createElement("stellar-wallets-button"),t.buttonText&&this.buttonElement.setAttribute("buttonText",t.buttonText),t.horizonUrl&&p9(t.horizonUrl),t.container.appendChild(this.buttonElement),this.buttonElement.addEventListener("button-clicked",()=>{this.openModal({onWalletSelected:r=>{m0(r.id),this.getAddress().then(n=>t.onConnect(n)).catch(n=>{t.onError&&t.onError(n)})},onClosed:r=>{t.onClosed&&t.onClosed(r)}})},!1),this.buttonElement.addEventListener("disconnect-wallet",()=>{t.onDisconnect(),this.selectedModule.disconnect&&this.selectedModule.disconnect()},!1)}async removeButton(t){if(!this.buttonElement)throw new Error("Stellar Wallets Kit button hasn't been created yet");(t==null?void 0:t.skipDisconnect)!==!0&&this.buttonElement.disconnect(),this.buttonElement.remove(),delete this.buttonElement}async openModal(t){if(this.modalElement&&!this.buttonElement)throw new Error("Stellar Wallets Kit modal is already open");this.modalElement=document.createElement("stellar-wallets-modal");const r=await this.getSupportedWallets();$m(r),this.modalElement.setAttribute("showModal",""),t.modalTitle&&this.modalElement.setAttribute("modalTitle",t.modalTitle),t.notAvailableText&&this.modalElement.setAttribute("notAvailableText",t.notAvailableText),document.body.appendChild(this.modalElement);const n=i=>{t.onWalletSelected(i.detail),this.modalElement.removeEventListener("wallet-selected",n,!1),document.body.removeChild(this.modalElement),this.modalElement=void 0};this.modalElement.addEventListener("wallet-selected",n,!1);const a=i=>{t.onClosed&&t.onClosed(i.detail),this.modalElement.removeEventListener("wallet-selected",n,!1),this.modalElement.removeEventListener("modal-closed",a,!1),document.body.removeChild(this.modalElement),this.modalElement=void 0};this.modalElement.addEventListener("modal-closed",a,!1)}}/** + `):"",this.name="UnsubscriptionError",this.errors=r}});function mf(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Bc=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,a,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=va(s),c=o.next();!c.done;c=o.next()){var d=c.value;d.remove(this)}}catch(z){t={error:z}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}else s.remove(this);var p=this.initialTeardown;if(wr(p))try{p()}catch(z){i=z instanceof d0?z.errors:[z]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var g=va(y),v=g.next();!v.done;v=g.next()){var M=v.value;try{zm(M)}catch(z){i=i??[],z instanceof d0?i=As(As([],Es(i)),Es(z.errors)):i.push(z)}}}catch(z){n={error:z}}finally{try{v&&!v.done&&(a=g.return)&&a.call(g)}finally{if(n)throw n.error}}}if(i)throw new d0(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)zm(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&mf(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&mf(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),ov=Bc.EMPTY;function lv(e){return e instanceof Bc||e&&"closed"in e&&wr(e.remove)&&wr(e.add)&&wr(e.unsubscribe)}function zm(e){wr(e)?e():e.unsubscribe()}var uw={Promise:void 0},fw={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,a=this,i=a.hasError,s=a.isStopped,o=a.observers;return i||s?ov:(this.currentObservers=null,o.push(r),new Bc(function(){n.currentObservers=null,mf(o,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,a=n.hasError,i=n.thrownError,s=n.isStopped;a?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new Zr;return r.source=this,r},t.create=function(r,n){return new Im(r,n)},t}(Zr),Im=function(e){Jr(t,e);function t(r,n){var a=e.call(this)||this;return a.destination=r,a.source=n,a}return t.prototype.next=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.next)===null||a===void 0||a.call(n,r)},t.prototype.error=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.error)===null||a===void 0||a.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,a;return(a=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&a!==void 0?a:ov},t}(sn),dv=function(e){Jr(t,e);function t(r){var n=e.call(this)||this;return n._value=r,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(r){var n=e.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},t.prototype.getValue=function(){var r=this,n=r.hasError,a=r.thrownError,i=r._value;if(n)throw a;return this._throwIfClosed(),i},t.prototype.next=function(r){e.prototype.next.call(this,this._value=r)},t}(sn),ww={now:function(){return Date.now()}},_w=function(e){Jr(t,e);function t(r,n){return e.call(this)||this}return t.prototype.schedule=function(r,n){return this},t}(Bc),Lm={setInterval:function(e,t){for(var r=[],n=2;n!e),Tl(1)),uu={},Tv=new Map,A1=new sn;A1.asObservable();function Ww(e){Tv.set(e.name,e),A1.next({type:"add",store:e})}function e9(e){Tv.delete(e.name),A1.next({type:"remove",store:e})}let zu=[];function t9(e){zu.push(e)}function qm(e){zu.length&&zu.forEach(t=>e.next(t)),zu=[]}class r9 extends dv{constructor(t){super(t.state),this.storeDef=t,this.initialState=void 0,this.state=void 0,this.batchInProgress=!1,this.events=new sn,this.context={config:this.getConfig(),setEvent:r=>{t9(r)}},this.events$=this.events.asObservable(),this.state=this.getInitialState(t.state),this.initialState=this.getValue(),Ww(this)}get name(){return this.storeDef.name}getInitialState(t){return uu.preStateInit?uu.preStateInit(t,this.name):t}getConfig(){return this.storeDef.config}query(t){return t(this.getValue())}update(...t){const r=this.getValue();let n=t.reduce((a,i)=>(a=i(a,this.context),a),r);uu.preStoreUpdate&&(n=uu.preStoreUpdate(r,n,this.name)),n!==r&&(this.state=n,jv.getValue()?this.batchInProgress||(this.batchInProgress=!0,Jw.subscribe(()=>{super.next(this.state),qm(this.events),this.batchInProgress=!1})):(super.next(this.state),qm(this.events)))}getValue(){return this.state}reset(){this.update(()=>this.initialState)}combine(t){let r=!0;const n={};return new Zr(a=>{for(const[i,s]of Object.entries(t))a.add(s.subscribe(o=>{n[i]=o,r=!0}));return this.subscribe({next(){r&&(a.next({...n}),r=!1)},error(i){a.error(i)},complete(){a.complete()}})})}destroy(){e9(this),this.reset()}next(t){this.update(()=>t)}error(){}complete(){}}function n9(e,...t){const{state:r,config:n}=Qw(...t),{name:a}=e;return new r9({name:a,state:r,config:n})}function a9(e){return typeof e=="function"}function Yi(e,t){return function(r){return{...r,[e]:a9(t)?t(r[e]):t}}}function Vi(e){return bw(Gw(e),Xw())}function i9(e){return{props:e,config:void 0}}var bs=(e=>(e.PUBLIC="Public Global Stellar Network ; September 2015",e.TESTNET="Test SDF Network ; September 2015",e.FUTURENET="Test SDF Future Network ; October 2022",e.SANDBOX="Local Sandbox Stellar Network ; September 2022",e.STANDALONE="Standalone Network ; February 2017",e))(bs||{}),Vo=(e=>(e.HW_WALLET="HW_WALLET",e.HOT_WALLET="HOT_WALLET",e.BRIDGE_WALLET="BRIDGE_WALLET",e.AIR_GAPED_WALLET="AIR_GAPED_WALLET",e))(Vo||{});const yr=n9({name:"state"},i9({allowedWallets:[],hardwareWalletPaths:[]})),s9=yr.pipe(Vi(e=>e.allowedWallets));yr.pipe(Vi(e=>e.selectedNetwork));const o9=yr.pipe(Vi(e=>e.modalTheme)),l9=yr.pipe(Vi(e=>e.buttonTheme)),c9=yr.pipe(Vi(e=>e.activeAddress)),Mv=yr.pipe(Vi(e=>e.horizonUrl));yr.pipe(Vi(e=>e.mnemonicPath));yr.pipe(Vi(e=>e.hardwareWalletPaths));function m0(e){yr.update(Yi("selectedModuleId",e))}function u9(e){if(!Object.values(bs).includes(e))throw new Error(`Wallet network "${e}" is not supported`);yr.update(Yi("selectedNetwork",e))}function f9(e){yr.update(Yi("modalTheme",e))}function d9(e){yr.update(Yi("buttonTheme",e))}function $m(e){yr.update(Yi("allowedWallets",e))}function h9(e){yr.update(Yi("activeAddress",e))}function tp(){yr.update(Yi("activeAddress",void 0))}function p9(e){yr.update(Yi("horizonUrl",e))}class b9{get selectedModule(){const{selectedModuleId:t}=yr.getValue();if(!t)throw{code:-3,message:"Please set the wallet first"};const r=this.modules.find(n=>n.productId===t);if(!r)throw{code:-3,message:"Please set the wallet first"};return r}constructor(t){this.modules=t.modules,t.selectedWalletId&&this.setWallet(t.selectedWalletId),u9(t.network);const r=t.theme||t.modalTheme;r&&f9(r),t.buttonTheme&&d9(t.buttonTheme),this.getSupportedWallets().then(n=>{$m(n)})}async getSupportedWallets(){return Promise.all(this.modules.map(async t=>{const r=new Promise(n=>setTimeout(()=>n(!1),500));return{id:t.productId,name:t.productName,type:t.moduleType,icon:t.productIcon,isAvailable:await Promise.race([r,t.isAvailable()]),isPlatformWrapper:await Promise.race([r,t.isPlatformWrapper?t.isPlatformWrapper():Promise.resolve(!1)]),url:t.productUrl}}))}setWallet(t){const r=this.modules.find(n=>n.productId===t);if(!r)throw new Error(`Wallet id "${t}" is not supported`);m0(r.productId)}async getAddress(t){const{address:r}=await this.selectedModule.getAddress(t);return h9(r),{address:r}}async signTransaction(t,r){return this.selectedModule.signTransaction(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async signAuthEntry(t,r){return this.selectedModule.signAuthEntry(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async signMessage(t,r){return this.selectedModule.signMessage(t,{...r,networkPassphrase:(r==null?void 0:r.networkPassphrase)||yr.getValue().selectedNetwork})}async getNetwork(){return this.selectedModule.getNetwork()}async disconnect(){tp()}isButtonCreated(){return!!this.buttonElement}assignButtons(t){const r=typeof t.connectEl=="string"?document.querySelector(t.connectEl):t.connectEl;if(!r)throw new Error("connectEl is not available");if(r.addEventListener("click",()=>{this.openModal({onWalletSelected:a=>{m0(a.id),this.getAddress().then(i=>t.onConnect(i))}}).then()},!1),!t.disconnectEl)return;const n=typeof t.disconnectEl=="string"?document.querySelector(t.disconnectEl):t.disconnectEl;if(!n)throw new Error("disconnectEl is not available");n.addEventListener("click",()=>{t.onDisconnect(),tp(),this.selectedModule.disconnect&&this.selectedModule.disconnect().then()},!1)}async createButton(t){if(this.buttonElement)throw new Error("Stellar Wallets Kit button is already created");this.buttonElement=document.createElement("stellar-wallets-button"),t.buttonText&&this.buttonElement.setAttribute("buttonText",t.buttonText),t.horizonUrl&&p9(t.horizonUrl),t.container.appendChild(this.buttonElement),this.buttonElement.addEventListener("button-clicked",()=>{this.openModal({onWalletSelected:r=>{m0(r.id),this.getAddress().then(n=>t.onConnect(n)).catch(n=>{t.onError&&t.onError(n)})},onClosed:r=>{t.onClosed&&t.onClosed(r)}})},!1),this.buttonElement.addEventListener("disconnect-wallet",()=>{t.onDisconnect(),this.selectedModule.disconnect&&this.selectedModule.disconnect()},!1)}async removeButton(t){if(!this.buttonElement)throw new Error("Stellar Wallets Kit button hasn't been created yet");(t==null?void 0:t.skipDisconnect)!==!0&&this.buttonElement.disconnect(),this.buttonElement.remove(),delete this.buttonElement}async openModal(t){if(this.modalElement&&!this.buttonElement)throw new Error("Stellar Wallets Kit modal is already open");this.modalElement=document.createElement("stellar-wallets-modal");const r=await this.getSupportedWallets();$m(r),this.modalElement.setAttribute("showModal",""),t.modalTitle&&this.modalElement.setAttribute("modalTitle",t.modalTitle),t.notAvailableText&&this.modalElement.setAttribute("notAvailableText",t.notAvailableText),document.body.appendChild(this.modalElement);const n=i=>{t.onWalletSelected(i.detail),this.modalElement.removeEventListener("wallet-selected",n,!1),document.body.removeChild(this.modalElement),this.modalElement=void 0};this.modalElement.addEventListener("wallet-selected",n,!1);const a=i=>{t.onClosed&&t.onClosed(i.detail),this.modalElement.removeEventListener("wallet-selected",n,!1),this.modalElement.removeEventListener("modal-closed",a,!1),document.body.removeChild(this.modalElement),this.modalElement=void 0};this.modalElement.addEventListener("modal-closed",a,!1)}}/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause @@ -321,13 +321,13 @@ Error generating stack: `+n.message+` * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */const{is:y9,defineProperty:g9,getOwnPropertyDescriptor:v9,getOwnPropertyNames:w9,getOwnPropertySymbols:_9,getPrototypeOf:S9}=Object,Ri=globalThis,Pm=Ri.trustedTypes,E9=Pm?Pm.emptyScript:"",x0=Ri.reactiveElementPolyfillSupport,Kl=(e,t)=>e,yf={toAttribute(e,t){switch(t){case Boolean:e=e?E9:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e)}return e},fromAttribute(e,t){let r=e;switch(t){case Boolean:r=e!==null;break;case Number:r=e===null?null:Number(e);break;case Object:case Array:try{r=JSON.parse(e)}catch{r=null}}return r}},T1=(e,t)=>!y9(e,t),Gm={attribute:!0,type:String,converter:yf,reflect:!1,useDefault:!1,hasChanged:T1};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),Ri.litPropertyMetadata??(Ri.litPropertyMetadata=new WeakMap);let Qs=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,r=Gm){if(r.state&&(r.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((r=Object.create(r)).wrapped=!0),this.elementProperties.set(t,r),!r.noAccessor){const n=Symbol(),a=this.getPropertyDescriptor(t,n,r);a!==void 0&&g9(this.prototype,t,a)}}static getPropertyDescriptor(t,r,n){const{get:a,set:i}=v9(this.prototype,t)??{get(){return this[r]},set(s){this[r]=s}};return{get:a,set(s){const o=a==null?void 0:a.call(this);i==null||i.call(this,s),this.requestUpdate(t,o,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Gm}static _$Ei(){if(this.hasOwnProperty(Kl("elementProperties")))return;const t=S9(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(Kl("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Kl("properties"))){const r=this.properties,n=[...w9(r),..._9(r)];for(const a of n)this.createProperty(a,r[a])}const t=this[Symbol.metadata];if(t!==null){const r=litPropertyMetadata.get(t);if(r!==void 0)for(const[n,a]of r)this.elementProperties.set(n,a)}this._$Eh=new Map;for(const[r,n]of this.elementProperties){const a=this._$Eu(r,n);a!==void 0&&this._$Eh.set(a,r)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const r=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const a of n)r.unshift(Km(a))}else t!==void 0&&r.push(Km(t));return r}static _$Eu(t,r){const n=r.attribute;return n===!1?void 0:typeof n=="string"?n:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$ES=new Promise(r=>this.enableUpdating=r),this._$AL=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(r=>r(this))}addController(t){var r;(this._$EO??(this._$EO=new Set)).add(t),this.renderRoot!==void 0&&this.isConnected&&((r=t.hostConnected)==null||r.call(t))}removeController(t){var r;(r=this._$EO)==null||r.delete(t)}_$E_(){const t=new Map,r=this.constructor.elementProperties;for(const n of r.keys())this.hasOwnProperty(n)&&(t.set(n,this[n]),delete this[n]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return x9(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$EO)==null||t.forEach(r=>{var n;return(n=r.hostConnected)==null?void 0:n.call(r)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$EO)==null||t.forEach(r=>{var n;return(n=r.hostDisconnected)==null?void 0:n.call(r)})}attributeChangedCallback(t,r,n){this._$AK(t,n)}_$ET(t,r){var i;const n=this.constructor.elementProperties.get(t),a=this.constructor._$Eu(t,n);if(a!==void 0&&n.reflect===!0){const s=(((i=n.converter)==null?void 0:i.toAttribute)!==void 0?n.converter:yf).toAttribute(r,n.type);this._$Em=t,s==null?this.removeAttribute(a):this.setAttribute(a,s),this._$Em=null}}_$AK(t,r){var i,s;const n=this.constructor,a=n._$Eh.get(t);if(a!==void 0&&this._$Em!==a){const o=n.getPropertyOptions(a),c=typeof o.converter=="function"?{fromAttribute:o.converter}:((i=o.converter)==null?void 0:i.fromAttribute)!==void 0?o.converter:yf;this._$Em=a;const h=c.fromAttribute(r,o.type);this[a]=h??((s=this._$Ej)==null?void 0:s.get(a))??h,this._$Em=null}}requestUpdate(t,r,n,a=!1,i){var s;if(t!==void 0){const o=this.constructor;if(a===!1&&(i=this[t]),n??(n=o.getPropertyOptions(t)),!((n.hasChanged??T1)(i,r)||n.useDefault&&n.reflect&&i===((s=this._$Ej)==null?void 0:s.get(t))&&!this.hasAttribute(o._$Eu(t,n))))return;this.C(t,r,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,r,{useDefault:n,reflect:a,wrapped:i},s){n&&!(this._$Ej??(this._$Ej=new Map)).has(t)&&(this._$Ej.set(t,s??r??this[t]),i!==!0||s!==void 0)||(this._$AL.has(t)||(this.hasUpdated||n||(r=void 0),this._$AL.set(t,r)),a===!0&&this._$Em!==t&&(this._$Eq??(this._$Eq=new Set)).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(r){Promise.reject(r)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var n;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[i,s]of this._$Ep)this[i]=s;this._$Ep=void 0}const a=this.constructor.elementProperties;if(a.size>0)for(const[i,s]of a){const{wrapped:o}=s,c=this[i];o!==!0||this._$AL.has(i)||c===void 0||this.C(i,void 0,s,c)}}let t=!1;const r=this._$AL;try{t=this.shouldUpdate(r),t?(this.willUpdate(r),(n=this._$EO)==null||n.forEach(a=>{var i;return(i=a.hostUpdate)==null?void 0:i.call(a)}),this.update(r)):this._$EM()}catch(a){throw t=!1,this._$EM(),a}t&&this._$AE(r)}willUpdate(t){}_$AE(t){var r;(r=this._$EO)==null||r.forEach(n=>{var a;return(a=n.hostUpdated)==null?void 0:a.call(n)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&(this._$Eq=this._$Eq.forEach(r=>this._$ET(r,this[r]))),this._$EM()}updated(t){}firstUpdated(t){}};Qs.elementStyles=[],Qs.shadowRootOptions={mode:"open"},Qs[Kl("elementProperties")]=new Map,Qs[Kl("finalized")]=new Map,x0==null||x0({ReactiveElement:Qs}),(Ri.reactiveElementVersions??(Ri.reactiveElementVersions=[])).push("2.1.2");/** + */const{is:y9,defineProperty:g9,getOwnPropertyDescriptor:v9,getOwnPropertyNames:w9,getOwnPropertySymbols:_9,getPrototypeOf:S9}=Object,Ri=globalThis,Pm=Ri.trustedTypes,E9=Pm?Pm.emptyScript:"",x0=Ri.reactiveElementPolyfillSupport,Kl=(e,t)=>e,yf={toAttribute(e,t){switch(t){case Boolean:e=e?E9:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e)}return e},fromAttribute(e,t){let r=e;switch(t){case Boolean:r=e!==null;break;case Number:r=e===null?null:Number(e);break;case Object:case Array:try{r=JSON.parse(e)}catch{r=null}}return r}},T1=(e,t)=>!y9(e,t),Gm={attribute:!0,type:String,converter:yf,reflect:!1,useDefault:!1,hasChanged:T1};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),Ri.litPropertyMetadata??(Ri.litPropertyMetadata=new WeakMap);let Qs=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,r=Gm){if(r.state&&(r.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((r=Object.create(r)).wrapped=!0),this.elementProperties.set(t,r),!r.noAccessor){const n=Symbol(),a=this.getPropertyDescriptor(t,n,r);a!==void 0&&g9(this.prototype,t,a)}}static getPropertyDescriptor(t,r,n){const{get:a,set:i}=v9(this.prototype,t)??{get(){return this[r]},set(s){this[r]=s}};return{get:a,set(s){const o=a==null?void 0:a.call(this);i==null||i.call(this,s),this.requestUpdate(t,o,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Gm}static _$Ei(){if(this.hasOwnProperty(Kl("elementProperties")))return;const t=S9(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(Kl("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Kl("properties"))){const r=this.properties,n=[...w9(r),..._9(r)];for(const a of n)this.createProperty(a,r[a])}const t=this[Symbol.metadata];if(t!==null){const r=litPropertyMetadata.get(t);if(r!==void 0)for(const[n,a]of r)this.elementProperties.set(n,a)}this._$Eh=new Map;for(const[r,n]of this.elementProperties){const a=this._$Eu(r,n);a!==void 0&&this._$Eh.set(a,r)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const r=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const a of n)r.unshift(Km(a))}else t!==void 0&&r.push(Km(t));return r}static _$Eu(t,r){const n=r.attribute;return n===!1?void 0:typeof n=="string"?n:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$ES=new Promise(r=>this.enableUpdating=r),this._$AL=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(r=>r(this))}addController(t){var r;(this._$EO??(this._$EO=new Set)).add(t),this.renderRoot!==void 0&&this.isConnected&&((r=t.hostConnected)==null||r.call(t))}removeController(t){var r;(r=this._$EO)==null||r.delete(t)}_$E_(){const t=new Map,r=this.constructor.elementProperties;for(const n of r.keys())this.hasOwnProperty(n)&&(t.set(n,this[n]),delete this[n]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return x9(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$EO)==null||t.forEach(r=>{var n;return(n=r.hostConnected)==null?void 0:n.call(r)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$EO)==null||t.forEach(r=>{var n;return(n=r.hostDisconnected)==null?void 0:n.call(r)})}attributeChangedCallback(t,r,n){this._$AK(t,n)}_$ET(t,r){var i;const n=this.constructor.elementProperties.get(t),a=this.constructor._$Eu(t,n);if(a!==void 0&&n.reflect===!0){const s=(((i=n.converter)==null?void 0:i.toAttribute)!==void 0?n.converter:yf).toAttribute(r,n.type);this._$Em=t,s==null?this.removeAttribute(a):this.setAttribute(a,s),this._$Em=null}}_$AK(t,r){var i,s;const n=this.constructor,a=n._$Eh.get(t);if(a!==void 0&&this._$Em!==a){const o=n.getPropertyOptions(a),c=typeof o.converter=="function"?{fromAttribute:o.converter}:((i=o.converter)==null?void 0:i.fromAttribute)!==void 0?o.converter:yf;this._$Em=a;const d=c.fromAttribute(r,o.type);this[a]=d??((s=this._$Ej)==null?void 0:s.get(a))??d,this._$Em=null}}requestUpdate(t,r,n,a=!1,i){var s;if(t!==void 0){const o=this.constructor;if(a===!1&&(i=this[t]),n??(n=o.getPropertyOptions(t)),!((n.hasChanged??T1)(i,r)||n.useDefault&&n.reflect&&i===((s=this._$Ej)==null?void 0:s.get(t))&&!this.hasAttribute(o._$Eu(t,n))))return;this.C(t,r,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,r,{useDefault:n,reflect:a,wrapped:i},s){n&&!(this._$Ej??(this._$Ej=new Map)).has(t)&&(this._$Ej.set(t,s??r??this[t]),i!==!0||s!==void 0)||(this._$AL.has(t)||(this.hasUpdated||n||(r=void 0),this._$AL.set(t,r)),a===!0&&this._$Em!==t&&(this._$Eq??(this._$Eq=new Set)).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(r){Promise.reject(r)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var n;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[i,s]of this._$Ep)this[i]=s;this._$Ep=void 0}const a=this.constructor.elementProperties;if(a.size>0)for(const[i,s]of a){const{wrapped:o}=s,c=this[i];o!==!0||this._$AL.has(i)||c===void 0||this.C(i,void 0,s,c)}}let t=!1;const r=this._$AL;try{t=this.shouldUpdate(r),t?(this.willUpdate(r),(n=this._$EO)==null||n.forEach(a=>{var i;return(i=a.hostUpdate)==null?void 0:i.call(a)}),this.update(r)):this._$EM()}catch(a){throw t=!1,this._$EM(),a}t&&this._$AE(r)}willUpdate(t){}_$AE(t){var r;(r=this._$EO)==null||r.forEach(n=>{var a;return(a=n.hostUpdated)==null?void 0:a.call(n)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&(this._$Eq=this._$Eq.forEach(r=>this._$ET(r,this[r]))),this._$EM()}updated(t){}firstUpdated(t){}};Qs.elementStyles=[],Qs.shadowRootOptions={mode:"open"},Qs[Kl("elementProperties")]=new Map,Qs[Kl("finalized")]=new Map,x0==null||x0({ReactiveElement:Qs}),(Ri.reactiveElementVersions??(Ri.reactiveElementVersions=[])).push("2.1.2");/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const Pl=globalThis,Ym=e=>e,gf=Pl.trustedTypes,Vm=gf?gf.createPolicy("lit-html",{createHTML:e=>e}):void 0,Bv="$lit$",mi=`lit$${Math.random().toFixed(9).slice(2)}$`,Ov="?"+mi,A9=`<${Ov}>`,Ns=document,lc=()=>Ns.createComment(""),cc=e=>e===null||typeof e!="object"&&typeof e!="function",M1=Array.isArray,N9=e=>M1(e)||typeof(e==null?void 0:e[Symbol.iterator])=="function",y0=`[ \f\r]`,bl=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Xm=/-->/g,Zm=/>/g,Ji=RegExp(`>|${y0}(?:([^\\s"'>=/]+)(${y0}*=${y0}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g"),Qm=/'/g,Jm=/"/g,Rv=/^(?:script|style|textarea|title)$/i,j9=e=>(t,...r)=>({_$litType$:e,strings:t,values:r}),Yr=j9(1),js=Symbol.for("lit-noChange"),Nr=Symbol.for("lit-nothing"),Wm=new WeakMap,ls=Ns.createTreeWalker(Ns,129);function Uv(e,t){if(!M1(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return Vm!==void 0?Vm.createHTML(t):t}const T9=(e,t)=>{const r=e.length-1,n=[];let a,i=t===2?"":t===3?"":"",s=bl;for(let o=0;o"?(s=a??bl,y=-1):p[1]===void 0?y=-2:(y=s.lastIndex-p[2].length,h=p[1],s=p[3]===void 0?Ji:p[3]==='"'?Jm:Qm):s===Jm||s===Qm?s=Ji:s===Xm||s===Zm?s=bl:(s=Ji,a=void 0);const v=s===Ji&&e[o+1].startsWith("/>")?" ":"";i+=s===bl?c+A9:y>=0?(n.push(h),c.slice(0,y)+Bv+c.slice(y)+mi+v):c+mi+(y===-2?o:v)}return[Uv(e,i+(e[r]||"")+(t===2?"":t===3?"":"")),n]};class uc{constructor({strings:t,_$litType$:r},n){let a;this.parts=[];let i=0,s=0;const o=t.length-1,c=this.parts,[h,p]=T9(t,r);if(this.el=uc.createElement(h,n),ls.currentNode=this.el.content,r===2||r===3){const y=this.el.content.firstChild;y.replaceWith(...y.childNodes)}for(;(a=ls.nextNode())!==null&&c.length0){a.textContent=gf?gf.emptyScript:"";for(let v=0;v2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=Nr}_$AI(t,r=this,n,a){const i=this.strings;let s=!1;if(i===void 0)t=Bo(this,t,r,0),s=!cc(t)||t!==this._$AH&&t!==js,s&&(this._$AH=t);else{const o=t;let c,h;for(t=i[0],c=0;c{const n=(r==null?void 0:r.renderBefore)??t;let a=n._$litPart$;if(a===void 0){const i=(r==null?void 0:r.renderBefore)??null;n._$litPart$=a=new Rc(t.insertBefore(lc(),i),i,void 0,r??{})}return a._$AI(e),a};/** +\f\r"'\`<>=]|("|')|))|$)`,"g"),Qm=/'/g,Jm=/"/g,Rv=/^(?:script|style|textarea|title)$/i,j9=e=>(t,...r)=>({_$litType$:e,strings:t,values:r}),Yr=j9(1),js=Symbol.for("lit-noChange"),Nr=Symbol.for("lit-nothing"),Wm=new WeakMap,ls=Ns.createTreeWalker(Ns,129);function Uv(e,t){if(!M1(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return Vm!==void 0?Vm.createHTML(t):t}const T9=(e,t)=>{const r=e.length-1,n=[];let a,i=t===2?"":t===3?"":"",s=bl;for(let o=0;o"?(s=a??bl,y=-1):p[1]===void 0?y=-2:(y=s.lastIndex-p[2].length,d=p[1],s=p[3]===void 0?Ji:p[3]==='"'?Jm:Qm):s===Jm||s===Qm?s=Ji:s===Xm||s===Zm?s=bl:(s=Ji,a=void 0);const v=s===Ji&&e[o+1].startsWith("/>")?" ":"";i+=s===bl?c+A9:y>=0?(n.push(d),c.slice(0,y)+Bv+c.slice(y)+mi+v):c+mi+(y===-2?o:v)}return[Uv(e,i+(e[r]||"")+(t===2?"":t===3?"":"")),n]};class uc{constructor({strings:t,_$litType$:r},n){let a;this.parts=[];let i=0,s=0;const o=t.length-1,c=this.parts,[d,p]=T9(t,r);if(this.el=uc.createElement(d,n),ls.currentNode=this.el.content,r===2||r===3){const y=this.el.content.firstChild;y.replaceWith(...y.childNodes)}for(;(a=ls.nextNode())!==null&&c.length0){a.textContent=gf?gf.emptyScript:"";for(let v=0;v2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=Nr}_$AI(t,r=this,n,a){const i=this.strings;let s=!1;if(i===void 0)t=Bo(this,t,r,0),s=!cc(t)||t!==this._$AH&&t!==js,s&&(this._$AH=t);else{const o=t;let c,d;for(t=i[0],c=0;c{const n=(r==null?void 0:r.renderBefore)??t;let a=n._$litPart$;if(a===void 0){const i=(r==null?void 0:r.renderBefore)??null;n._$litPart$=a=new Rc(t.insertBefore(lc(),i),i,void 0,r??{})}return a._$AI(e),a};/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause @@ -347,13 +347,13 @@ Error generating stack: `+n.message+` * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */const L9={attribute:!0,type:String,converter:yf,reflect:!1,hasChanged:T1},H9=(e=L9,t,r)=>{const{kind:n,metadata:a}=r;let i=globalThis.litPropertyMetadata.get(a);if(i===void 0&&globalThis.litPropertyMetadata.set(a,i=new Map),n==="setter"&&((e=Object.create(e)).wrapped=!0),i.set(r.name,e),n==="accessor"){const{name:s}=r;return{set(o){const c=t.get.call(this);t.set.call(this,o),this.requestUpdate(s,c,e,!0,o)},init(o){return o!==void 0&&this.C(s,void 0,e,o),o}}}if(n==="setter"){const{name:s}=r;return function(o){const c=this[s];t.call(this,o),this.requestUpdate(s,c,e,!0,o)}}throw Error("Unsupported decorator location: "+n)};function Aa(e){return(t,r)=>typeof r=="object"?H9(e,t,r):((n,a,i)=>{const s=a.hasOwnProperty(i);return a.constructor.createProperty(i,n),s?Object.getOwnPropertyDescriptor(a,i):void 0})(e,t,r)}/** + */const L9={attribute:!0,type:String,converter:yf,reflect:!1,hasChanged:T1},H9=(e=L9,t,r)=>{const{kind:n,metadata:a}=r;let i=globalThis.litPropertyMetadata.get(a);if(i===void 0&&globalThis.litPropertyMetadata.set(a,i=new Map),n==="setter"&&((e=Object.create(e)).wrapped=!0),i.set(r.name,e),n==="accessor"){const{name:s}=r;return{set(o){const c=t.get.call(this);t.set.call(this,o),this.requestUpdate(s,c,e,!0,o)},init(o){return o!==void 0&&this.C(s,void 0,e,o),o}}}if(n==="setter"){const{name:s}=r;return function(o){const c=this[s];t.call(this,o),this.requestUpdate(s,c,e,!0,o)}}throw Error("Unsupported decorator location: "+n)};function Na(e){return(t,r)=>typeof r=="object"?H9(e,t,r):((n,a,i)=>{const s=a.hasOwnProperty(i);return a.constructor.createProperty(i,n),s?Object.getOwnPropertyDescriptor(a,i):void 0})(e,t,r)}/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */function Uc(e){return Aa({...e,state:!0,attribute:!1})}function Kr(e){return typeof e=="function"}function B1(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var w0=B1(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: + */function Uc(e){return Na({...e,state:!0,attribute:!1})}function Kr(e){return typeof e=="function"}function B1(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var w0=B1(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: `+r.map(function(n,a){return a+1+") "+n.toString()}).join(` - `):"",this.name="UnsubscriptionError",this.errors=r}});function rp(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Qf=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,a,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=ga(s),c=o.next();!c.done;c=o.next()){var h=c.value;h.remove(this)}}catch(k){t={error:k}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}else s.remove(this);var p=this.initialTeardown;if(Kr(p))try{p()}catch(k){i=k instanceof w0?k.errors:[k]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var g=ga(y),v=g.next();!v.done;v=g.next()){var M=v.value;try{ex(M)}catch(k){i=i??[],k instanceof w0?i=As(As([],Es(i)),Es(k.errors)):i.push(k)}}}catch(k){n={error:k}}finally{try{v&&!v.done&&(a=g.return)&&a.call(g)}finally{if(n)throw n.error}}}if(i)throw new w0(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ex(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&rp(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&rp(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),Dv=Qf.EMPTY;function Iv(e){return e instanceof Qf||e&&"closed"in e&&Kr(e.remove)&&Kr(e.add)&&Kr(e.unsubscribe)}function ex(e){Kr(e)?e():e.unsubscribe()}var q9={Promise:void 0},$9={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,a=this,i=a.hasError,s=a.isStopped,o=a.observers;return i||s?Dv:(this.currentObservers=null,o.push(r),new Qf(function(){n.currentObservers=null,rp(o,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,a=n.hasError,i=n.thrownError,s=n.isStopped;a?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new Li;return r.source=this,r},t.create=function(r,n){return new ax(r,n)},t}(Li),ax=function(e){Jr(t,e);function t(r,n){var a=e.call(this)||this;return a.destination=r,a.source=n,a}return t.prototype.next=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.next)===null||a===void 0||a.call(n,r)},t.prototype.error=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.error)===null||a===void 0||a.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,a;return(a=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&a!==void 0?a:Dv},t}(Hv),e_=function(e){Jr(t,e);function t(r){var n=e.call(this)||this;return n._value=r,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(r){var n=e.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},t.prototype.getValue=function(){var r=this,n=r.hasError,a=r.thrownError,i=r._value;if(n)throw a;return this._throwIfClosed(),i},t.prototype.next=function(r){e.prototype.next.call(this,this._value=r)},t}(Hv),t_=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function r_(e){return Kr(e==null?void 0:e.then)}function n_(e){return Kr(e[R1])}function a_(e){return Symbol.asyncIterator&&Kr(e==null?void 0:e[Symbol.asyncIterator])}function i_(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function s_(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var o_=s_();function l_(e){return Kr(e==null?void 0:e[o_])}function c_(e){return iv(this,arguments,function(){var r,n,a,i;return Xf(this,function(s){switch(s.label){case 0:r=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,Pa(r.read())];case 3:return n=s.sent(),a=n.value,i=n.done,i?[4,Pa(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,Pa(a)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function u_(e){return Kr(e==null?void 0:e.getReader)}function f_(e){if(e instanceof Li)return e;if(e!=null){if(n_(e))return d_(e);if(t_(e))return h_(e);if(r_(e))return p_(e);if(a_(e))return qv(e);if(l_(e))return b_(e);if(u_(e))return m_(e)}throw i_(e)}function d_(e){return new Li(function(t){var r=e[R1]();if(Kr(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function h_(e){return new Li(function(t){for(var r=0;r{this.value=t,this.value$.next(t),this.host.requestUpdate()})}hostDisconnected(){var t;(t=this.sub)==null||t.unsubscribe()}}const v_=Br` + `):"",this.name="UnsubscriptionError",this.errors=r}});function rp(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Qf=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,a,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=va(s),c=o.next();!c.done;c=o.next()){var d=c.value;d.remove(this)}}catch(z){t={error:z}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}else s.remove(this);var p=this.initialTeardown;if(Kr(p))try{p()}catch(z){i=z instanceof w0?z.errors:[z]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var g=va(y),v=g.next();!v.done;v=g.next()){var M=v.value;try{ex(M)}catch(z){i=i??[],z instanceof w0?i=As(As([],Es(i)),Es(z.errors)):i.push(z)}}}catch(z){n={error:z}}finally{try{v&&!v.done&&(a=g.return)&&a.call(g)}finally{if(n)throw n.error}}}if(i)throw new w0(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ex(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&rp(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&rp(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}(),Dv=Qf.EMPTY;function Iv(e){return e instanceof Qf||e&&"closed"in e&&Kr(e.remove)&&Kr(e.add)&&Kr(e.unsubscribe)}function ex(e){Kr(e)?e():e.unsubscribe()}var q9={Promise:void 0},$9={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,a=this,i=a.hasError,s=a.isStopped,o=a.observers;return i||s?Dv:(this.currentObservers=null,o.push(r),new Qf(function(){n.currentObservers=null,rp(o,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,a=n.hasError,i=n.thrownError,s=n.isStopped;a?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new Li;return r.source=this,r},t.create=function(r,n){return new ax(r,n)},t}(Li),ax=function(e){Jr(t,e);function t(r,n){var a=e.call(this)||this;return a.destination=r,a.source=n,a}return t.prototype.next=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.next)===null||a===void 0||a.call(n,r)},t.prototype.error=function(r){var n,a;(a=(n=this.destination)===null||n===void 0?void 0:n.error)===null||a===void 0||a.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,a;return(a=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&a!==void 0?a:Dv},t}(Hv),e_=function(e){Jr(t,e);function t(r){var n=e.call(this)||this;return n._value=r,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(r){var n=e.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},t.prototype.getValue=function(){var r=this,n=r.hasError,a=r.thrownError,i=r._value;if(n)throw a;return this._throwIfClosed(),i},t.prototype.next=function(r){e.prototype.next.call(this,this._value=r)},t}(Hv),t_=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function r_(e){return Kr(e==null?void 0:e.then)}function n_(e){return Kr(e[R1])}function a_(e){return Symbol.asyncIterator&&Kr(e==null?void 0:e[Symbol.asyncIterator])}function i_(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function s_(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var o_=s_();function l_(e){return Kr(e==null?void 0:e[o_])}function c_(e){return iv(this,arguments,function(){var r,n,a,i;return Xf(this,function(s){switch(s.label){case 0:r=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,Pa(r.read())];case 3:return n=s.sent(),a=n.value,i=n.done,i?[4,Pa(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,Pa(a)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function u_(e){return Kr(e==null?void 0:e.getReader)}function f_(e){if(e instanceof Li)return e;if(e!=null){if(n_(e))return d_(e);if(t_(e))return h_(e);if(r_(e))return p_(e);if(a_(e))return qv(e);if(l_(e))return b_(e);if(u_(e))return m_(e)}throw i_(e)}function d_(e){return new Li(function(t){var r=e[R1]();if(Kr(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function h_(e){return new Li(function(t){for(var r=0;r{this.value=t,this.value$.next(t),this.host.requestUpdate()})}hostDisconnected(){var t;(t=this.sub)==null||t.unsubscribe()}}const v_=Br` .dialog-modal { max-height: 90vh; position: fixed; @@ -740,7 +740,7 @@ Error generating stack: `+n.message+` .mb-0 { margin-bottom: 0 !important; } - `,v_,w_,__,E_,A_,S_];Xo([Aa({type:Boolean,reflect:!0})],Hi.prototype,"ignoreShowStatus",2);Xo([Aa({type:Boolean,reflect:!0})],Hi.prototype,"showModal",2);Xo([Uc()],Hi.prototype,"closingModal",2);Xo([Aa({type:String,reflect:!0})],Hi.prototype,"modalTitle",2);Xo([Aa({type:String,reflect:!0})],Hi.prototype,"notAvailableText",2);Hi=Xo([C1("stellar-wallets-modal")],Hi);async function T_(e){const t=await $v(Mv);if(!t)throw new Error("There is no Horizon URL set");const r=new URL(t);return r.pathname=`/accounts/${e}`,(await(await fetch(r)).json()).balances.find(s=>s.asset_type==="native").balance}async function M_(e){if(!e)throw new Error("Text to copy to the clipboard can't be undefined");await navigator.clipboard.writeText(e)}const C_=Br` + `,v_,w_,__,E_,A_,S_];Xo([Na({type:Boolean,reflect:!0})],Hi.prototype,"ignoreShowStatus",2);Xo([Na({type:Boolean,reflect:!0})],Hi.prototype,"showModal",2);Xo([Uc()],Hi.prototype,"closingModal",2);Xo([Na({type:String,reflect:!0})],Hi.prototype,"modalTitle",2);Xo([Na({type:String,reflect:!0})],Hi.prototype,"notAvailableText",2);Hi=Xo([C1("stellar-wallets-modal")],Hi);async function T_(e){const t=await $v(Mv);if(!t)throw new Error("There is no Horizon URL set");const r=new URL(t);return r.pathname=`/accounts/${e}`,(await(await fetch(r)).json()).balances.find(s=>s.asset_type==="native").balance}async function M_(e){if(!e)throw new Error("Text to copy to the clipboard can't be undefined");await navigator.clipboard.writeText(e)}const C_=Br` .btn-container { position: relative; } @@ -991,7 +991,7 @@ Error generating stack: `+n.message+` :host * { box-sizing: border-box; } - `,B_,C_,O_];kc([Aa({type:String,reflect:!0})],Ts.prototype,"buttonText",2);kc([Uc()],Ts.prototype,"showDropdown",2);kc([Uc()],Ts.prototype,"accountBalance",2);kc([Uc()],Ts.prototype,"showCopiedMessage",2);Ts=kc([C1("stellar-wallets-button")],Ts);const k_=Br` + `,B_,C_,O_];kc([Na({type:String,reflect:!0})],Ts.prototype,"buttonText",2);kc([Uc()],Ts.prototype,"showDropdown",2);kc([Uc()],Ts.prototype,"accountBalance",2);kc([Uc()],Ts.prototype,"showCopiedMessage",2);Ts=kc([C1("stellar-wallets-button")],Ts);const k_=Br` .dialog-modal { max-height: 90vh; position: fixed; @@ -1409,34 +1409,34 @@ Error generating stack: `+n.message+` .mb-0 { margin-bottom: 0 !important; } - `,k_,z_,D_,L_,H_,I_];Zo([Aa({type:Boolean,reflect:!0})],qi.prototype,"showModal",2);Zo([Aa({type:Boolean,reflect:!0})],qi.prototype,"loadingAccounts",2);Zo([Uc()],qi.prototype,"closingModal",2);Zo([Aa({type:String,reflect:!0})],qi.prototype,"modalTitle",2);Zo([Aa({type:String,reflect:!0,converter:e=>e?JSON.parse(e):[]})],qi.prototype,"accounts",2);qi=Zo([C1("stellar-accounts-selector")],qi);function np(){const e=new Uint32Array(4);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let t=0;tt.toString(36)).join("")}const Fv={public_key:{title:"View public key",description:"Requests account public key. It's a simple way of authentication for Stellar-based applications. The response ensures that a user owns the corresponding secret key.",implicitFlow:!1,params:{token:{description:"Verification token generated by the application (should be unique or random).",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST a signed token and public key.",type:"string",required:!1},require_existing:{description:"Allow existing Albedo accounts only.",type:"boolean",required:!1}},returns:{pubkey:{description:"User-selected public key.",type:"string"},signed_message:{description:"HEX-encoded authentication message derived from the public key and verification token.",type:"string"},signature:{description:"HEX-encoded ED25519 signature of the authentication message that can be further used to verify user's keypair ownership.",type:"string"}}},sign_message:{title:"Sign text message",description:"Requests arbitrary message signing. Can be used to implement identity/ownership verification.",implicitFlow:!0,params:{message:{description:"Text message to sign.",type:"string",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST a signed message.",type:"string",required:!1}},returns:{pubkey:{description:"User-selected public key.",type:"string"},original_message:{description:"Text message to sign from request.",type:"string"},signed_message:{description:"HEX-encoded message derived from the public key and original message.",type:"string"},message_signature:{description:"HEX-encoded ED25519 signature of the signed message.",type:"string"}}},tx:{title:"Sign transaction",description:"Requests a signature for the transaction. Returns the signed transaction envelope that can be submitted to the network or used for multi-sig coordination.",implicitFlow:!0,params:{xdr:{description:"XDR-encoded transaction envelope to sign.",type:"string",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.",type:"string",required:!1},description:{description:"Optional human-friendly short transaction description provided by developers.",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{xdr:{description:"XDR-encoded transaction envelope from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},pay:{title:"Make payment",description:"Requests a payment from a user. Works with any Stellar asset, supports transaction memo.",implicitFlow:!0,params:{amount:{description:"Requested payment amount.",type:"string",required:!0},destination:{description:"Payment destination address.",type:"string",required:!0},asset_code:{description:"Asset code (skip for XLM).",type:"string",required:!1},asset_issuer:{description:"Asset issuer (skip for XLM).",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon. ",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{amount:{description:"Payment amount from request.",type:"string"},destination:{description:"Payment destination address from request.",type:"string"},asset_code:{description:"Asset code from request.",type:"string"},asset_issuer:{description:"Asset issuer from request.",type:"string"},memo:{description:"Transaction memo from request.",type:"string"},memo_type:{description:"Transaction memo type from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},trust:{title:"Establish trustline",description:"Requests permission to create a trustline to a given Stellar asset. Gradually simplifies the process of creating trustlines for anchors, ICOs, and airdrops.",implicitFlow:!0,params:{asset_code:{description:"Trustline asset code.",type:"string",required:!0},asset_issuer:{description:"Trustline asset issuer address.",type:"string",required:!0},limit:{description:"Trust limit.",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon. ",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{asset_code:{description:"Trustline asset code from request.",type:"string"},asset_issuer:{description:"Trustline asset issuer address from request.",type:"string"},limit:{description:"Trust limit from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},exchange:{title:"Swap tokens",description:"Requests permission to buy tokens on Stellar DEX at market price.",implicitFlow:!1,params:{amount:{description:"The amount of asset to buy.",type:"string",required:!0},max_price:{description:"Maximum price the user willing to pay.",type:"string",required:!0},sell_asset_code:{description:"Asset code of the asset to sell.",type:"string",required:!1},sell_asset_issuer:{description:"Issuer account of the asset to sell.",type:"string",required:!1},buy_asset_code:{description:"Asset code of the asset to buy.",type:"string",required:!1},buy_asset_issuer:{description:"Issuer account of the asset to buy.",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{amount:{description:"The amount of asset to buy from request.",type:"string"},max_price:{description:"Maximum price the user willing to pay from request.",type:"string"},sell_asset_code:{description:"Asset code of the asset to sell from request.",type:"string"},sell_asset_issuer:{description:"Issuer account of the asset to sell from request.",type:"string"},buy_asset_code:{description:"Asset code of the asset to buy from request.",type:"string"},buy_asset_issuer:{description:"Issuer account of the asset to buy from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},implicit_flow:{title:"Implicit permissions",description:'Requests temporary access token for one or more intents that can be used to execute actions without explicit confirmation from the user. In order to be executed implicitly, an implicit flow permissions for a given intent should be granted and "pubkey" parameter set.',implicitFlow:!1,params:{intents:{description:"Requested implicit flow intents.",type:"string|string[]",required:!0},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{granted:{description:"Whether a user granted permissions or not.",type:"boolean"},intents:{description:"Requested implicit flow intents.",type:"string[]"},grants:{description:"Implicit flow intents that have been granted.",type:"string[]"},session:{description:"Unique implicit session id.",type:"string"},valid_until:{description:"Session expiration timestamp.",type:"number"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"}}},manage_account:{title:"Open account settings",description:"Opens account settings window for a given account.",implicitFlow:!1,params:{pubkey:{description:"Specific public key requested by the application.",type:"string",required:!0},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{pubkey:{description:"Public key from intent request.",type:"string"}}},batch:{title:"Intents batch",description:"Requests execution of several tx intents bundled together. This intent is atomic – a user confirms or rejects all bundled requests at once, with the same account and the same Stellar network.",implicitFlow:!0,params:{intents:{description:"Requested tx intents that should be executed together.",type:"object[]",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{intents:{description:"Requested tx intents.",type:"object[]"},results:{description:"Array of results for each requested intent.",type:"object[]"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"}}}},U1={unhandledError:{message:"Unhandled error occurred. If this error persists, please contact Albedo support.",code:-1},externalError:{message:"External error occurred.",code:-2},invalidIntentRequest:{message:"Intent request is invalid.",code:-3},actionRejectedByUser:{message:"Action request was rejected by the user.",code:-4},horizonError:{message:"Transaction failed when submitted to Stellar network.",code:-5},callbackError:{message:"Callback redirect failed.",code:-6}};function k1(e,t=!1){this.windowHandler=e,this.ephemeral=!!t,this.isLoaded=!1,this.pendingRequests={},this.preprocessRequestParams=null,this.onLoaded=new Promise((r,n)=>this.onLoadedCallback=r).then(()=>this),this.messageHandler=this.messageHandler.bind(this),window.addEventListener("message",this.messageHandler,!1)}k1.prototype={isLoaded:!1,protocolVersion:3,markLoaded(){const{onLoadedCallback:e}=this;e&&(this.onLoadedCallback=null,this.isLoaded=!0,e())},messageHandler({data:e}){if(e.albedo)return this.matchProtocolVersion(e.albedo.protocol),this.markLoaded();if(e.albedoIntentResult){const{__reqid:t,...r}=e.albedoIntentResult,n=this.pendingRequests[t];n&&(delete this.pendingRequests[t],n(r),this.ephemeral&&(window.removeEventListener("message",this.messageHandler,!1),this.windowHandler.close()))}},transportCloseHandler(){for(let e in this.pendingRequests)if(this.pendingRequests.hasOwnProperty(e)){const t=this.pendingRequests[e];delete this.pendingRequests[e],t(U1.actionRejectedByUser)}},postMessage(e){const t=np();return new Promise((r,n)=>{this.onLoaded.then(()=>{this.pendingRequests[t]=F_.bind(this,r,n),e=Object.assign({__reqid:t,__albedo_intent_version:this.protocolVersion},e),this.preprocessRequestParams&&(e=this.preprocessRequestParams(e)),this.windowHandler.postMessage(e,"*")})})},matchProtocolVersion(e){const t=e-this.protocolVersion;if(t===0)return;const r=`@albedo-link/intent module protocol version (${this.protocolVersion}) is incompatible with current Albedo protocol version ${e}.`;if(t>0)console.warn(r+" Please update @albedo-link/intent module to avoid possible connection problems.");else if(t<0)throw this.windowHandler.close(),new Error(r)}};function F_(e,t,r){r.error?t(r):e(r)}function K_(e){const t=`${e}/confirm`,r=480,n=600,a=window.screenLeft!==void 0?window.screenLeft:window.screenX,i=window.screenTop!==void 0?window.screenTop:window.screenY,s=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,c=s/2-r/2+a,h=o/2-n/2+i,p=window.open(t,"auth.albedo.link",`height=${n},width=${r},top=${h},left=${c},menubar=0,toolbar=0,location=0,status=0,personalbar=0,scrollbars=0,dependent=1`);return new k1(p,!0).onLoaded}let _0=null;function ix(e){if(!_0){const t=document.createElement("iframe");t.style.border="none",Object.assign(t,{width:"0",height:"0",frameBorder:"0",referrerPolicy:"origin",src:`${e}`}),document.body.appendChild(t),_0=new k1(t.contentWindow)}return _0.onLoaded}function z1({session:e,pubkey:t,grants:r,valid_until:n}){this.key=e,this.pubkey=t,this.grants=r.slice(),this.validUntil=n,Object.freeze(this),Object.freeze(this.grants)}z1.prototype={key:"",pubkey:"",grants:[],validUntil:0,get isExpired(){return this.validUntil-2e3t.indexOf(fc)===0).map(t=>Kv(t.substr(fc.length))).filter(t=>!!t)}function Gv(e){Jf().removeItem(fc+e)}function Gl(e){return Object.assign(new Error,U1.invalidIntentRequest,{ext:e})}function Y_(e,t){try{const{intent:r}=e;if(!r)throw Gl('Parameter "intent" is required.');const n=Fv[r];if(!n)throw Gl(`Unknown intent: "${r}".`);const a=Z_(n,e);return V_(a,t).then(i=>X_(a,i))}catch(r){const{code:n=-1,message:a,ext:i}=r,s={message:a,code:n};return i&&(s.ext=i),Promise.reject(s)}}function V_(e,t){if(e.pubkey){const r=Pv(e.intent,e.pubkey);if(r)return e.session=r.key,ix(t)}return setTimeout(()=>{e.intent==="implicit_flow"&&ix(t)},200),K_(t)}function X_(e,t){return t.postMessage(e).then(r=>(r.intent==="implicit_flow"&&r.granted&&P_(r),r))}function Z_(e,t){if(typeof t!="object")throw Gl("Intent parameters expected.");const{intent:r,pubkey:n}=t,a={intent:r};if(n&&!/^G[0-9A-Z]{55}$/.test(n))throw Gl('Invalid "pubkey" parameter. Stellar account public key expected.');for(const i in e.params){const s=e.params[i],o=t[i];if(o)a[i]=o;else if(s.required)throw Gl(`Parameter "${i}" is required for intent "${r}".`)}return a}function Q_(e=null){e===null&&(e=window.location.search),e[0]==="?"&&(e=e.substr(1));const t={};for(let r of e.split("&")){const[n,a]=r.split("=").map(i=>decodeURIComponent(i));t[n]=a}return t}function J_(e){typeof document>"u"||!document.addEventListener||document.addEventListener("click",function(r){if(r.target.tagName!=="A"||(r.target.href||"").indexOf("web+stellar:")!==0)return;r.preventDefault(),r.stopImmediatePropagation();const{pathname:n,search:a}=new URL(r.target.href);if(!["tx","pay"].includes(n)){alert(`Invalid operation requested: ${n}. It's likely an external application error. Please contact support team of ${window.location.origin}.`);return}const i=Q_(a);e.request(n,i)},!1)}if(typeof window=="object"&&typeof window.fetch!="function")throw new Error("Browser FetchAPI is not available. For legacy browsers support use polyfills such as whatwg-fetch.");function Yv(){}Yv.prototype={frontendUrl:"https://albedo.link",intentInterface:Fv,intentErrors:U1,request(e,t){return Y_(Object.assign(t||{},{intent:e}),this.frontendUrl)},implicitFlow(e){return this.request("implicit_flow",e)},publicKey(e){return e=Object.assign({},e),e.token||(e.token=np()),this.request("public_key",e)},tx(e){return this.request("tx",e)},batch(e){return this.request("batch",e)},pay(e){return this.request("pay",e)},trust(e){return this.request("trust",e)},exchange(e){return this.request("exchange",e)},signMessage(e){return e=Object.assign({},e,{message:W_(e.message)}),this.request("sign_message",e)},manageAccount(e){return this.request("manage_account",e)},generateRandomToken(){return np()},isImplicitSessionAllowed(e,t){return!!Pv(e,t)},listImplicitSessions(){return G_()},forgetImplicitSession(e){Gv(e)}};function W_(e){switch(typeof e){case"string":return e;case"undefined":return""}return JSON.stringify(e)}const dc=new Yv;dc.default=dc;J_(dc);const e7="albedo";class t7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=e7,this.productName="Albedo",this.productUrl="https://albedo.link/",this.productIcon="https://stellar.creit.tech/wallet-icons/albedo.png"}async isAvailable(){return!0}async getAddress(){return dc.publicKey({}).then(t=>({address:t.pubkey})).catch(t=>{throw cn(t)})}async signTransaction(t,r){return dc.tx({xdr:t,pubkey:r==null?void 0:r.address,network:r!=null&&r.networkPassphrase?r.networkPassphrase===bs.PUBLIC?"public":"testnet":void 0}).then(({signed_envelope_xdr:n})=>({signedTxXdr:n,signerAddress:r==null?void 0:r.address})).catch(n=>{throw cn(n)})}async signAuthEntry(){throw{code:-3,message:'Albedo does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Albedo does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Albedo does not support the "getNetwork" function'}}}var Vv={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,()=>(()=>{var r,n,a={d:(x,u)=>{for(var f in u)a.o(u,f)&&!a.o(x,f)&&Object.defineProperty(x,f,{enumerable:!0,get:u[f]})},o:(x,u)=>Object.prototype.hasOwnProperty.call(x,u),r:x=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(x,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(x,"__esModule",{value:!0})}},i={};a.r(i),a.d(i,{WatchWalletChanges:()=>J,addToken:()=>M,default:()=>te,getAddress:()=>v,getNetwork:()=>z,getNetworkDetails:()=>L,isAllowed:()=>$,isBrowser:()=>Y,isConnected:()=>T,requestAccess:()=>V,setAllowed:()=>F,signAuthEntry:()=>D,signMessage:()=>K,signTransaction:()=>k}),function(x){x.CREATE_ACCOUNT="CREATE_ACCOUNT",x.FUND_ACCOUNT="FUND_ACCOUNT",x.ADD_ACCOUNT="ADD_ACCOUNT",x.IMPORT_ACCOUNT="IMPORT_ACCOUNT",x.IMPORT_HARDWARE_WALLET="IMPORT_HARDWARE_WALLET",x.LOAD_ACCOUNT="LOAD_ACCOUNT",x.MAKE_ACCOUNT_ACTIVE="MAKE_ACCOUNT_ACTIVE",x.UPDATE_ACCOUNT_NAME="UPDATE_ACCOUNT_NAME",x.GET_MNEMONIC_PHRASE="GET_MNEMONIC_PHRASE",x.CONFIRM_MNEMONIC_PHRASE="CONFIRM_MNEMONIC_PHRASE",x.CONFIRM_MIGRATED_MNEMONIC_PHRASE="CONFIRM_MIGRATED_MNEMONIC_PHRASE",x.RECOVER_ACCOUNT="RECOVER_ACCOUNT",x.CONFIRM_PASSWORD="CONFIRM_PASSWORD",x.REJECT_ACCESS="REJECT_ACCESS",x.GRANT_ACCESS="GRANT_ACCESS",x.ADD_TOKEN="ADD_TOKEN",x.SIGN_TRANSACTION="SIGN_TRANSACTION",x.SIGN_BLOB="SIGN_BLOB",x.SIGN_AUTH_ENTRY="SIGN_AUTH_ENTRY",x.HANDLE_SIGNED_HW_PAYLOAD="HANDLE_SIGNED_HW_PAYLOAD",x.REJECT_TRANSACTION="REJECT_TRANSACTION",x.SIGN_FREIGHTER_TRANSACTION="SIGN_FREIGHTER_TRANSACTION",x.SIGN_FREIGHTER_SOROBAN_TRANSACTION="SIGN_FREIGHTER_SOROBAN_TRANSACTION",x.ADD_RECENT_ADDRESS="ADD_RECENT_ADDRESS",x.LOAD_RECENT_ADDRESSES="LOAD_RECENT_ADDRESSES",x.LOAD_LAST_USED_ACCOUNT="LOAD_LAST_USED_ACCOUNT",x.SIGN_OUT="SIGN_OUT",x.SHOW_BACKUP_PHRASE="SHOW_BACKUP_PHRASE",x.SAVE_ALLOWLIST="SAVE_ALLOWLIST",x.SAVE_SETTINGS="SAVE_SETTINGS",x.SAVE_EXPERIMENTAL_FEATURES="SAVE_EXPERIMENTAL_FEATURES",x.LOAD_SETTINGS="LOAD_SETTINGS",x.GET_CACHED_ASSET_ICON="GET_CACHED_ASSET_ICON",x.CACHE_ASSET_ICON="CACHE_ASSET_ICON",x.GET_CACHED_ASSET_DOMAIN="GET_CACHED_ASSET_DOMAIN",x.CACHE_ASSET_DOMAIN="CACHE_ASSET_DOMAIN",x.GET_MEMO_REQUIRED_ACCOUNTS="GET_MEMO_REQUIRED_ACCOUNTS",x.ADD_CUSTOM_NETWORK="ADD_CUSTOM_NETWORK",x.CHANGE_NETWORK="CHANGE_NETWORK",x.REMOVE_CUSTOM_NETWORK="REMOVE_CUSTOM_NETWORK",x.EDIT_CUSTOM_NETWORK="EDIT_CUSTOM_NETWORK",x.RESET_EXP_DATA="RESET_EXP_DATA",x.ADD_TOKEN_ID="ADD_TOKEN_ID",x.GET_TOKEN_IDS="GET_TOKEN_IDS",x.REMOVE_TOKEN_ID="REMOVE_TOKEN_ID",x.GET_MIGRATABLE_ACCOUNTS="GET_MIGRATABLE_ACCOUNTS",x.GET_MIGRATED_MNEMONIC_PHRASE="GET_MIGRATED_MNEMONIC_PHRASE",x.MIGRATE_ACCOUNTS="MIGRATE_ACCOUNTS",x.ADD_ASSETS_LIST="ADD_ASSETS_LIST",x.MODIFY_ASSETS_LIST="MODIFY_ASSETS_LIST",x.CHANGE_ASSET_VISIBILITY="CHANGE_ASSET_VISIBILITY",x.GET_HIDDEN_ASSETS="GET_HIDDEN_ASSETS",x.GET_IS_ACCOUNT_MISMATCH="GET_IS_ACCOUNT_MISMATCH"}(r||(r={})),function(x){x.REQUEST_ACCESS="REQUEST_ACCESS",x.REQUEST_PUBLIC_KEY="REQUEST_PUBLIC_KEY",x.SUBMIT_TOKEN="SUBMIT_TOKEN",x.SUBMIT_TRANSACTION="SUBMIT_TRANSACTION",x.SUBMIT_BLOB="SUBMIT_BLOB",x.SUBMIT_AUTH_ENTRY="SUBMIT_AUTH_ENTRY",x.REQUEST_NETWORK="REQUEST_NETWORK",x.REQUEST_NETWORK_DETAILS="REQUEST_NETWORK_DETAILS",x.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS",x.REQUEST_ALLOWED_STATUS="REQUEST_ALLOWED_STATUS",x.SET_ALLOWED_STATUS="SET_ALLOWED_STATUS",x.REQUEST_USER_INFO="REQUEST_USER_INFO"}(n||(n={}));const s=x=>{const u=Date.now()+Math.random();return window.postMessage({source:"FREIGHTER_EXTERNAL_MSG_REQUEST",messageId:u,...x},window.location.origin),new Promise(f=>{let _=0;x.type!==n.REQUEST_CONNECTION_STATUS&&x.type!==n.REQUEST_PUBLIC_KEY||(_=setTimeout(()=>{f({isConnected:!1,publicKey:""}),window.removeEventListener("message",E)},2e3));const E=S=>{var j,R;S.source===window&&((j=S==null?void 0:S.data)===null||j===void 0?void 0:j.source)==="FREIGHTER_EXTERNAL_MSG_RESPONSE"&&((R=S==null?void 0:S.data)===null||R===void 0?void 0:R.messagedId)===u&&(f(S.data),window.removeEventListener("message",E),clearTimeout(_))};window.addEventListener("message",E,!1)})},o={code:-1,message:"Node environment is not supported"},c={code:-1,message:"The wallet encountered an internal error. Please try again or contact the wallet if the problem persists."},h=async()=>{let x;try{x=await s({type:n.REQUEST_ACCESS})}catch(f){console.error(f)}const{publicKey:u}=x||{publicKey:""};return{publicKey:u,error:x==null?void 0:x.apiError}},p=async()=>{let x;try{x=await s({type:n.REQUEST_PUBLIC_KEY})}catch(u){console.error(u)}return{publicKey:(x==null?void 0:x.publicKey)||"",error:x==null?void 0:x.apiError}},y=async()=>{let x;try{x=await s({type:n.REQUEST_NETWORK_DETAILS})}catch(R){console.error(R)}const{networkDetails:u,apiError:f}=x||{networkDetails:{network:"",networkUrl:"",networkPassphrase:"",sorobanRpcUrl:void 0}},{network:_,networkUrl:E,networkPassphrase:S,sorobanRpcUrl:j}=u;return{network:_,networkUrl:E,networkPassphrase:S,sorobanRpcUrl:j,error:f}},g=async()=>{let x;try{x=await s({type:n.REQUEST_ALLOWED_STATUS})}catch(f){console.error(f)}const{isAllowed:u}=x||{isAllowed:!1};return{isAllowed:u,error:x==null?void 0:x.apiError}},v=async()=>{let x="";if(Y){const u=await p();return x=u.publicKey,u.error?{address:x,error:u.error}:{address:x}}return{address:x,error:o}},M=async x=>{if(Y){const u=await(async f=>{let _;try{_=await s({contractId:f.contractId,networkPassphrase:f.networkPassphrase,type:n.SUBMIT_TOKEN})}catch{return{error:c}}return{contractId:_.contractId,error:_==null?void 0:_.apiError}})(x);return u.error?{contractId:"",error:u.error}:{contractId:u.contractId||""}}return{contractId:"",error:o}},k=async(x,u)=>{if(Y){const f=await(async(_,E)=>{let S,j,R,N;typeof E=="object"?(j=E.accountToSign,R=E.networkPassphrase):(S=E,j=void 0);try{N=await s({transactionXdr:_,network:S,networkPassphrase:R,accountToSign:j,type:n.SUBMIT_TRANSACTION})}catch{return{signedTransaction:"",signerAddress:"",error:c}}const{signedTransaction:d,signerAddress:C}=N;return{signedTransaction:d,signerAddress:C,error:N==null?void 0:N.apiError}})(x,u);return f.error?{signedTxXdr:"",signerAddress:"",error:f.error}:{signedTxXdr:f.signedTransaction,signerAddress:f.signerAddress}}return{signedTxXdr:"",signerAddress:"",error:o}},K=async(x,u)=>{if(Y){const{isAllowed:f}=await g();if(!f){const E=await h();if(E.error)return{signedMessage:null,signerAddress:"",error:E.error}}const _=await(async(E,S,j)=>{let R;const N=(j||{}).address;try{R=await s({blob:E,accountToSign:N,apiVersion:"5.0.0",networkPassphrase:j==null?void 0:j.networkPassphrase,type:n.SUBMIT_BLOB})}catch{return{signedMessage:null,signerAddress:"",error:c}}const{signedBlob:d,signerAddress:C}=R;return{signedMessage:d||null,signerAddress:C,error:R==null?void 0:R.apiError}})(x,0,u);return _.error?{signedMessage:null,signerAddress:"",error:_.error}:{signedMessage:_.signedMessage,signerAddress:_.signerAddress}}return{signedMessage:null,signerAddress:"",error:o}},D=async(x,u)=>{if(Y){const{isAllowed:f}=await g();if(!f){const E=await h();if(E.error)return{signedAuthEntry:null,signerAddress:"",error:E.error}}const _=await(async(E,S,j)=>{const R=(j||{}).address;let N;try{N=await s({entryXdr:E,accountToSign:R,apiVersion:"5.0.0",networkPassphrase:j==null?void 0:j.networkPassphrase,type:n.SUBMIT_AUTH_ENTRY})}catch(ae){return console.error(ae),{signedAuthEntry:null,signerAddress:"",error:c}}const{signedAuthEntry:d,signerAddress:C}=N;return{signedAuthEntry:d||null,signerAddress:C,error:N==null?void 0:N.apiError}})(x,0,u);return _.error?{signedAuthEntry:null,signerAddress:"",error:_.error}:{signedAuthEntry:_.signedAuthEntry,signerAddress:_.signerAddress}}return{signedAuthEntry:null,signerAddress:"",error:o}},T=async()=>Y?window.freighter?Promise.resolve({isConnected:window.freighter}):(async()=>{let x={isConnected:!1};try{x=await s({type:n.REQUEST_CONNECTION_STATUS})}catch(u){console.error(u)}return{isConnected:x.isConnected}})():{isConnected:!1,error:o},z=async()=>{if(Y){const x=await(async()=>{let u;try{u=await s({type:n.REQUEST_NETWORK_DETAILS})}catch(_){console.error(_)}const{networkDetails:f}=u||{networkDetails:{network:"",networkPassphrase:""}};return{network:f==null?void 0:f.network,networkPassphrase:f==null?void 0:f.networkPassphrase,error:u==null?void 0:u.apiError}})();return x.error?{network:"",networkPassphrase:"",error:x.error}:{network:x.network,networkPassphrase:x.networkPassphrase}}return{network:"",networkPassphrase:"",error:o}},L=async()=>{if(Y){const x=await y();return x.error?{network:"",networkUrl:"",networkPassphrase:"",error:x.error}:{network:x.network,networkUrl:x.networkUrl,networkPassphrase:x.networkPassphrase,sorobanRpcUrl:x.sorobanRpcUrl}}return{network:"",networkUrl:"",networkPassphrase:"",error:o}},$=async()=>{let x=!1;if(Y){const u=await g();return x=u.isAllowed,u.error?{isAllowed:x,error:u.error}:{isAllowed:x}}return{isAllowed:x,error:o}},F=async()=>{let x=!1;if(Y){const u=await(async()=>{let f;try{f=await s({type:n.SET_ALLOWED_STATUS})}catch(E){console.error(E)}const{isAllowed:_}=f||{isAllowed:!1};return{isAllowed:_,error:f==null?void 0:f.apiError}})();return x=u.isAllowed,u.error?{isAllowed:x,error:u.error}:{isAllowed:x}}return{isAllowed:x,error:o}},V=async()=>{let x="";if(Y){const u=await h();return x=u.publicKey,u.error?{address:x,error:u.error}:{address:x}}return{address:x,error:o}};class J{constructor(u=3e3){this.fetchInfo=async f=>{if(!this.isRunning)return;const _=await p(),E=await y();(_.error||E.error)&&f({address:"",network:"",networkPassphrase:"",error:_.error||E.error}),this.currentAddress===_.publicKey&&this.currentNetwork===E.network&&this.currentNetworkPassphrase===E.networkPassphrase||(this.currentAddress=_.publicKey,this.currentNetwork=E.network,this.currentNetworkPassphrase=E.networkPassphrase,f({address:_.publicKey,network:E.network,networkPassphrase:E.networkPassphrase})),setTimeout(()=>this.fetchInfo(f),this.timeout)},this.timeout=u,this.currentAddress="",this.currentNetwork="",this.currentNetworkPassphrase="",this.isRunning=!1}watch(u){return Y?(this.isRunning=!0,this.fetchInfo(u),{}):{error:o}}stop(){this.isRunning=!1}}const Y=typeof window<"u",te={getAddress:v,addToken:M,signTransaction:k,signMessage:K,signAuthEntry:D,isConnected:T,getNetwork:z,getNetworkDetails:L,isAllowed:$,setAllowed:F,requestAccess:V,WatchWalletChanges:J};return i})())})(Vv);var Wi=Vv.exports,_f={},Wf={};Wf.byteLength=a7;Wf.toByteArray=s7;Wf.fromByteArray=c7;var oa=[],kn=[],r7=typeof Uint8Array<"u"?Uint8Array:Array,S0="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Gs=0,n7=S0.length;Gs0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function a7(e){var t=Xv(e),r=t[0],n=t[1];return(r+n)*3/4-n}function i7(e,t,r){return(t+r)*3/4-r}function s7(e){var t,r=Xv(e),n=r[0],a=r[1],i=new r7(i7(e,n,a)),s=0,o=a>0?n-4:n,c;for(c=0;c>16&255,i[s++]=t>>8&255,i[s++]=t&255;return a===2&&(t=kn[e.charCodeAt(c)]<<2|kn[e.charCodeAt(c+1)]>>4,i[s++]=t&255),a===1&&(t=kn[e.charCodeAt(c)]<<10|kn[e.charCodeAt(c+1)]<<4|kn[e.charCodeAt(c+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function o7(e){return oa[e>>18&63]+oa[e>>12&63]+oa[e>>6&63]+oa[e&63]}function l7(e,t,r){for(var n,a=[],i=t;io?o:s+i));return n===1?(t=e[r-1],a.push(oa[t>>2]+oa[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],a.push(oa[t>>10]+oa[t>>4&63]+oa[t<<2&63]+"=")),a.join("")}var D1={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */D1.read=function(e,t,r,n,a){var i,s,o=a*8-n-1,c=(1<>1,p=-7,y=r?a-1:0,g=r?-1:1,v=e[t+y];for(y+=g,i=v&(1<<-p)-1,v>>=-p,p+=o;p>0;i=i*256+e[t+y],y+=g,p-=8);for(s=i&(1<<-p)-1,i>>=-p,p+=n;p>0;s=s*256+e[t+y],y+=g,p-=8);if(i===0)i=1-h;else{if(i===c)return s?NaN:(v?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-h}return(v?-1:1)*s*Math.pow(2,i-n)};D1.write=function(e,t,r,n,a,i){var s,o,c,h=i*8-a-1,p=(1<>1,g=a===23?Math.pow(2,-24)-Math.pow(2,-77):0,v=n?0:i-1,M=n?1:-1,k=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,s=p):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+y>=1?t+=g/c:t+=g*Math.pow(2,1-y),t*c>=2&&(s++,c/=2),s+y>=p?(o=0,s=p):s+y>=1?(o=(t*c-1)*Math.pow(2,a),s=s+y):(o=t*Math.pow(2,y-1)*Math.pow(2,a),s=0));a>=8;e[r+v]=o&255,v+=M,o/=256,a-=8);for(s=s<0;e[r+v]=s&255,v+=M,s/=256,h-=8);e[r+v-M]|=k*128};/*! + `,k_,z_,D_,L_,H_,I_];Zo([Na({type:Boolean,reflect:!0})],qi.prototype,"showModal",2);Zo([Na({type:Boolean,reflect:!0})],qi.prototype,"loadingAccounts",2);Zo([Uc()],qi.prototype,"closingModal",2);Zo([Na({type:String,reflect:!0})],qi.prototype,"modalTitle",2);Zo([Na({type:String,reflect:!0,converter:e=>e?JSON.parse(e):[]})],qi.prototype,"accounts",2);qi=Zo([C1("stellar-accounts-selector")],qi);function np(){const e=new Uint32Array(4);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let t=0;tt.toString(36)).join("")}const Fv={public_key:{title:"View public key",description:"Requests account public key. It's a simple way of authentication for Stellar-based applications. The response ensures that a user owns the corresponding secret key.",implicitFlow:!1,params:{token:{description:"Verification token generated by the application (should be unique or random).",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST a signed token and public key.",type:"string",required:!1},require_existing:{description:"Allow existing Albedo accounts only.",type:"boolean",required:!1}},returns:{pubkey:{description:"User-selected public key.",type:"string"},signed_message:{description:"HEX-encoded authentication message derived from the public key and verification token.",type:"string"},signature:{description:"HEX-encoded ED25519 signature of the authentication message that can be further used to verify user's keypair ownership.",type:"string"}}},sign_message:{title:"Sign text message",description:"Requests arbitrary message signing. Can be used to implement identity/ownership verification.",implicitFlow:!0,params:{message:{description:"Text message to sign.",type:"string",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST a signed message.",type:"string",required:!1}},returns:{pubkey:{description:"User-selected public key.",type:"string"},original_message:{description:"Text message to sign from request.",type:"string"},signed_message:{description:"HEX-encoded message derived from the public key and original message.",type:"string"},message_signature:{description:"HEX-encoded ED25519 signature of the signed message.",type:"string"}}},tx:{title:"Sign transaction",description:"Requests a signature for the transaction. Returns the signed transaction envelope that can be submitted to the network or used for multi-sig coordination.",implicitFlow:!0,params:{xdr:{description:"XDR-encoded transaction envelope to sign.",type:"string",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.",type:"string",required:!1},description:{description:"Optional human-friendly short transaction description provided by developers.",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{xdr:{description:"XDR-encoded transaction envelope from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},pay:{title:"Make payment",description:"Requests a payment from a user. Works with any Stellar asset, supports transaction memo.",implicitFlow:!0,params:{amount:{description:"Requested payment amount.",type:"string",required:!0},destination:{description:"Payment destination address.",type:"string",required:!0},asset_code:{description:"Asset code (skip for XLM).",type:"string",required:!1},asset_issuer:{description:"Asset issuer (skip for XLM).",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon. ",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{amount:{description:"Payment amount from request.",type:"string"},destination:{description:"Payment destination address from request.",type:"string"},asset_code:{description:"Asset code from request.",type:"string"},asset_issuer:{description:"Asset issuer from request.",type:"string"},memo:{description:"Transaction memo from request.",type:"string"},memo_type:{description:"Transaction memo type from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},trust:{title:"Establish trustline",description:"Requests permission to create a trustline to a given Stellar asset. Gradually simplifies the process of creating trustlines for anchors, ICOs, and airdrops.",implicitFlow:!0,params:{asset_code:{description:"Trustline asset code.",type:"string",required:!0},asset_issuer:{description:"Trustline asset issuer address.",type:"string",required:!0},limit:{description:"Trust limit.",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon. ",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{asset_code:{description:"Trustline asset code from request.",type:"string"},asset_issuer:{description:"Trustline asset issuer address from request.",type:"string"},limit:{description:"Trust limit from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},exchange:{title:"Swap tokens",description:"Requests permission to buy tokens on Stellar DEX at market price.",implicitFlow:!1,params:{amount:{description:"The amount of asset to buy.",type:"string",required:!0},max_price:{description:"Maximum price the user willing to pay.",type:"string",required:!0},sell_asset_code:{description:"Asset code of the asset to sell.",type:"string",required:!1},sell_asset_issuer:{description:"Issuer account of the asset to sell.",type:"string",required:!1},buy_asset_code:{description:"Asset code of the asset to buy.",type:"string",required:!1},buy_asset_issuer:{description:"Issuer account of the asset to buy.",type:"string",required:!1},memo:{description:"Transaction memo (required for exchanges and some anchors).",type:"string",required:!1},memo_type:{description:"Transaction memo type.",type:"string",required:!1},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1},callback:{description:"Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.",type:"string",required:!1},submit:{description:"If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.",type:"boolean",required:!1}},returns:{amount:{description:"The amount of asset to buy from request.",type:"string"},max_price:{description:"Maximum price the user willing to pay from request.",type:"string"},sell_asset_code:{description:"Asset code of the asset to sell from request.",type:"string"},sell_asset_issuer:{description:"Issuer account of the asset to sell from request.",type:"string"},buy_asset_code:{description:"Asset code of the asset to buy from request.",type:"string"},buy_asset_issuer:{description:"Issuer account of the asset to buy from request.",type:"string"},tx_hash:{description:"HEX-encoded transaction hash.",type:"string"},signed_envelope_xdr:{description:"XDR-encoded transaction envelope with new signatures.",type:"string"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"},result:{description:"Optional response from Horizon if the transaction has been submitted automatically.",type:"object"}}},implicit_flow:{title:"Implicit permissions",description:'Requests temporary access token for one or more intents that can be used to execute actions without explicit confirmation from the user. In order to be executed implicitly, an implicit flow permissions for a given intent should be granted and "pubkey" parameter set.',implicitFlow:!1,params:{intents:{description:"Requested implicit flow intents.",type:"string|string[]",required:!0},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{granted:{description:"Whether a user granted permissions or not.",type:"boolean"},intents:{description:"Requested implicit flow intents.",type:"string[]"},grants:{description:"Implicit flow intents that have been granted.",type:"string[]"},session:{description:"Unique implicit session id.",type:"string"},valid_until:{description:"Session expiration timestamp.",type:"number"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"}}},manage_account:{title:"Open account settings",description:"Opens account settings window for a given account.",implicitFlow:!1,params:{pubkey:{description:"Specific public key requested by the application.",type:"string",required:!0},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{pubkey:{description:"Public key from intent request.",type:"string"}}},batch:{title:"Intents batch",description:"Requests execution of several tx intents bundled together. This intent is atomic – a user confirms or rejects all bundled requests at once, with the same account and the same Stellar network.",implicitFlow:!0,params:{intents:{description:"Requested tx intents that should be executed together.",type:"object[]",required:!0},pubkey:{description:"Specific public key requested by the application.",type:"string",required:!1},network:{description:"Stellar network identifier or private network passphrase.",type:"string",required:!1}},returns:{intents:{description:"Requested tx intents.",type:"object[]"},results:{description:"Array of results for each requested intent.",type:"object[]"},pubkey:{description:"User-selected public key.",type:"string"},network:{description:"Stellar network identifier.",type:"string"}}}},U1={unhandledError:{message:"Unhandled error occurred. If this error persists, please contact Albedo support.",code:-1},externalError:{message:"External error occurred.",code:-2},invalidIntentRequest:{message:"Intent request is invalid.",code:-3},actionRejectedByUser:{message:"Action request was rejected by the user.",code:-4},horizonError:{message:"Transaction failed when submitted to Stellar network.",code:-5},callbackError:{message:"Callback redirect failed.",code:-6}};function k1(e,t=!1){this.windowHandler=e,this.ephemeral=!!t,this.isLoaded=!1,this.pendingRequests={},this.preprocessRequestParams=null,this.onLoaded=new Promise((r,n)=>this.onLoadedCallback=r).then(()=>this),this.messageHandler=this.messageHandler.bind(this),window.addEventListener("message",this.messageHandler,!1)}k1.prototype={isLoaded:!1,protocolVersion:3,markLoaded(){const{onLoadedCallback:e}=this;e&&(this.onLoadedCallback=null,this.isLoaded=!0,e())},messageHandler({data:e}){if(e.albedo)return this.matchProtocolVersion(e.albedo.protocol),this.markLoaded();if(e.albedoIntentResult){const{__reqid:t,...r}=e.albedoIntentResult,n=this.pendingRequests[t];n&&(delete this.pendingRequests[t],n(r),this.ephemeral&&(window.removeEventListener("message",this.messageHandler,!1),this.windowHandler.close()))}},transportCloseHandler(){for(let e in this.pendingRequests)if(this.pendingRequests.hasOwnProperty(e)){const t=this.pendingRequests[e];delete this.pendingRequests[e],t(U1.actionRejectedByUser)}},postMessage(e){const t=np();return new Promise((r,n)=>{this.onLoaded.then(()=>{this.pendingRequests[t]=F_.bind(this,r,n),e=Object.assign({__reqid:t,__albedo_intent_version:this.protocolVersion},e),this.preprocessRequestParams&&(e=this.preprocessRequestParams(e)),this.windowHandler.postMessage(e,"*")})})},matchProtocolVersion(e){const t=e-this.protocolVersion;if(t===0)return;const r=`@albedo-link/intent module protocol version (${this.protocolVersion}) is incompatible with current Albedo protocol version ${e}.`;if(t>0)console.warn(r+" Please update @albedo-link/intent module to avoid possible connection problems.");else if(t<0)throw this.windowHandler.close(),new Error(r)}};function F_(e,t,r){r.error?t(r):e(r)}function K_(e){const t=`${e}/confirm`,r=480,n=600,a=window.screenLeft!==void 0?window.screenLeft:window.screenX,i=window.screenTop!==void 0?window.screenTop:window.screenY,s=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,c=s/2-r/2+a,d=o/2-n/2+i,p=window.open(t,"auth.albedo.link",`height=${n},width=${r},top=${d},left=${c},menubar=0,toolbar=0,location=0,status=0,personalbar=0,scrollbars=0,dependent=1`);return new k1(p,!0).onLoaded}let _0=null;function ix(e){if(!_0){const t=document.createElement("iframe");t.style.border="none",Object.assign(t,{width:"0",height:"0",frameBorder:"0",referrerPolicy:"origin",src:`${e}`}),document.body.appendChild(t),_0=new k1(t.contentWindow)}return _0.onLoaded}function z1({session:e,pubkey:t,grants:r,valid_until:n}){this.key=e,this.pubkey=t,this.grants=r.slice(),this.validUntil=n,Object.freeze(this),Object.freeze(this.grants)}z1.prototype={key:"",pubkey:"",grants:[],validUntil:0,get isExpired(){return this.validUntil-2e3t.indexOf(fc)===0).map(t=>Kv(t.substr(fc.length))).filter(t=>!!t)}function Gv(e){Jf().removeItem(fc+e)}function Gl(e){return Object.assign(new Error,U1.invalidIntentRequest,{ext:e})}function Y_(e,t){try{const{intent:r}=e;if(!r)throw Gl('Parameter "intent" is required.');const n=Fv[r];if(!n)throw Gl(`Unknown intent: "${r}".`);const a=Z_(n,e);return V_(a,t).then(i=>X_(a,i))}catch(r){const{code:n=-1,message:a,ext:i}=r,s={message:a,code:n};return i&&(s.ext=i),Promise.reject(s)}}function V_(e,t){if(e.pubkey){const r=Pv(e.intent,e.pubkey);if(r)return e.session=r.key,ix(t)}return setTimeout(()=>{e.intent==="implicit_flow"&&ix(t)},200),K_(t)}function X_(e,t){return t.postMessage(e).then(r=>(r.intent==="implicit_flow"&&r.granted&&P_(r),r))}function Z_(e,t){if(typeof t!="object")throw Gl("Intent parameters expected.");const{intent:r,pubkey:n}=t,a={intent:r};if(n&&!/^G[0-9A-Z]{55}$/.test(n))throw Gl('Invalid "pubkey" parameter. Stellar account public key expected.');for(const i in e.params){const s=e.params[i],o=t[i];if(o)a[i]=o;else if(s.required)throw Gl(`Parameter "${i}" is required for intent "${r}".`)}return a}function Q_(e=null){e===null&&(e=window.location.search),e[0]==="?"&&(e=e.substr(1));const t={};for(let r of e.split("&")){const[n,a]=r.split("=").map(i=>decodeURIComponent(i));t[n]=a}return t}function J_(e){typeof document>"u"||!document.addEventListener||document.addEventListener("click",function(r){if(r.target.tagName!=="A"||(r.target.href||"").indexOf("web+stellar:")!==0)return;r.preventDefault(),r.stopImmediatePropagation();const{pathname:n,search:a}=new URL(r.target.href);if(!["tx","pay"].includes(n)){alert(`Invalid operation requested: ${n}. It's likely an external application error. Please contact support team of ${window.location.origin}.`);return}const i=Q_(a);e.request(n,i)},!1)}if(typeof window=="object"&&typeof window.fetch!="function")throw new Error("Browser FetchAPI is not available. For legacy browsers support use polyfills such as whatwg-fetch.");function Yv(){}Yv.prototype={frontendUrl:"https://albedo.link",intentInterface:Fv,intentErrors:U1,request(e,t){return Y_(Object.assign(t||{},{intent:e}),this.frontendUrl)},implicitFlow(e){return this.request("implicit_flow",e)},publicKey(e){return e=Object.assign({},e),e.token||(e.token=np()),this.request("public_key",e)},tx(e){return this.request("tx",e)},batch(e){return this.request("batch",e)},pay(e){return this.request("pay",e)},trust(e){return this.request("trust",e)},exchange(e){return this.request("exchange",e)},signMessage(e){return e=Object.assign({},e,{message:W_(e.message)}),this.request("sign_message",e)},manageAccount(e){return this.request("manage_account",e)},generateRandomToken(){return np()},isImplicitSessionAllowed(e,t){return!!Pv(e,t)},listImplicitSessions(){return G_()},forgetImplicitSession(e){Gv(e)}};function W_(e){switch(typeof e){case"string":return e;case"undefined":return""}return JSON.stringify(e)}const dc=new Yv;dc.default=dc;J_(dc);const e7="albedo";class t7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=e7,this.productName="Albedo",this.productUrl="https://albedo.link/",this.productIcon="https://stellar.creit.tech/wallet-icons/albedo.png"}async isAvailable(){return!0}async getAddress(){return dc.publicKey({}).then(t=>({address:t.pubkey})).catch(t=>{throw un(t)})}async signTransaction(t,r){return dc.tx({xdr:t,pubkey:r==null?void 0:r.address,network:r!=null&&r.networkPassphrase?r.networkPassphrase===bs.PUBLIC?"public":"testnet":void 0}).then(({signed_envelope_xdr:n})=>({signedTxXdr:n,signerAddress:r==null?void 0:r.address})).catch(n=>{throw un(n)})}async signAuthEntry(){throw{code:-3,message:'Albedo does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Albedo does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Albedo does not support the "getNetwork" function'}}}var Vv={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,()=>(()=>{var r,n,a={d:(x,u)=>{for(var f in u)a.o(u,f)&&!a.o(x,f)&&Object.defineProperty(x,f,{enumerable:!0,get:u[f]})},o:(x,u)=>Object.prototype.hasOwnProperty.call(x,u),r:x=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(x,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(x,"__esModule",{value:!0})}},i={};a.r(i),a.d(i,{WatchWalletChanges:()=>J,addToken:()=>M,default:()=>ee,getAddress:()=>v,getNetwork:()=>k,getNetworkDetails:()=>L,isAllowed:()=>$,isBrowser:()=>Y,isConnected:()=>T,requestAccess:()=>V,setAllowed:()=>F,signAuthEntry:()=>D,signMessage:()=>K,signTransaction:()=>z}),function(x){x.CREATE_ACCOUNT="CREATE_ACCOUNT",x.FUND_ACCOUNT="FUND_ACCOUNT",x.ADD_ACCOUNT="ADD_ACCOUNT",x.IMPORT_ACCOUNT="IMPORT_ACCOUNT",x.IMPORT_HARDWARE_WALLET="IMPORT_HARDWARE_WALLET",x.LOAD_ACCOUNT="LOAD_ACCOUNT",x.MAKE_ACCOUNT_ACTIVE="MAKE_ACCOUNT_ACTIVE",x.UPDATE_ACCOUNT_NAME="UPDATE_ACCOUNT_NAME",x.GET_MNEMONIC_PHRASE="GET_MNEMONIC_PHRASE",x.CONFIRM_MNEMONIC_PHRASE="CONFIRM_MNEMONIC_PHRASE",x.CONFIRM_MIGRATED_MNEMONIC_PHRASE="CONFIRM_MIGRATED_MNEMONIC_PHRASE",x.RECOVER_ACCOUNT="RECOVER_ACCOUNT",x.CONFIRM_PASSWORD="CONFIRM_PASSWORD",x.REJECT_ACCESS="REJECT_ACCESS",x.GRANT_ACCESS="GRANT_ACCESS",x.ADD_TOKEN="ADD_TOKEN",x.SIGN_TRANSACTION="SIGN_TRANSACTION",x.SIGN_BLOB="SIGN_BLOB",x.SIGN_AUTH_ENTRY="SIGN_AUTH_ENTRY",x.HANDLE_SIGNED_HW_PAYLOAD="HANDLE_SIGNED_HW_PAYLOAD",x.REJECT_TRANSACTION="REJECT_TRANSACTION",x.SIGN_FREIGHTER_TRANSACTION="SIGN_FREIGHTER_TRANSACTION",x.SIGN_FREIGHTER_SOROBAN_TRANSACTION="SIGN_FREIGHTER_SOROBAN_TRANSACTION",x.ADD_RECENT_ADDRESS="ADD_RECENT_ADDRESS",x.LOAD_RECENT_ADDRESSES="LOAD_RECENT_ADDRESSES",x.LOAD_LAST_USED_ACCOUNT="LOAD_LAST_USED_ACCOUNT",x.SIGN_OUT="SIGN_OUT",x.SHOW_BACKUP_PHRASE="SHOW_BACKUP_PHRASE",x.SAVE_ALLOWLIST="SAVE_ALLOWLIST",x.SAVE_SETTINGS="SAVE_SETTINGS",x.SAVE_EXPERIMENTAL_FEATURES="SAVE_EXPERIMENTAL_FEATURES",x.LOAD_SETTINGS="LOAD_SETTINGS",x.GET_CACHED_ASSET_ICON="GET_CACHED_ASSET_ICON",x.CACHE_ASSET_ICON="CACHE_ASSET_ICON",x.GET_CACHED_ASSET_DOMAIN="GET_CACHED_ASSET_DOMAIN",x.CACHE_ASSET_DOMAIN="CACHE_ASSET_DOMAIN",x.GET_MEMO_REQUIRED_ACCOUNTS="GET_MEMO_REQUIRED_ACCOUNTS",x.ADD_CUSTOM_NETWORK="ADD_CUSTOM_NETWORK",x.CHANGE_NETWORK="CHANGE_NETWORK",x.REMOVE_CUSTOM_NETWORK="REMOVE_CUSTOM_NETWORK",x.EDIT_CUSTOM_NETWORK="EDIT_CUSTOM_NETWORK",x.RESET_EXP_DATA="RESET_EXP_DATA",x.ADD_TOKEN_ID="ADD_TOKEN_ID",x.GET_TOKEN_IDS="GET_TOKEN_IDS",x.REMOVE_TOKEN_ID="REMOVE_TOKEN_ID",x.GET_MIGRATABLE_ACCOUNTS="GET_MIGRATABLE_ACCOUNTS",x.GET_MIGRATED_MNEMONIC_PHRASE="GET_MIGRATED_MNEMONIC_PHRASE",x.MIGRATE_ACCOUNTS="MIGRATE_ACCOUNTS",x.ADD_ASSETS_LIST="ADD_ASSETS_LIST",x.MODIFY_ASSETS_LIST="MODIFY_ASSETS_LIST",x.CHANGE_ASSET_VISIBILITY="CHANGE_ASSET_VISIBILITY",x.GET_HIDDEN_ASSETS="GET_HIDDEN_ASSETS",x.GET_IS_ACCOUNT_MISMATCH="GET_IS_ACCOUNT_MISMATCH"}(r||(r={})),function(x){x.REQUEST_ACCESS="REQUEST_ACCESS",x.REQUEST_PUBLIC_KEY="REQUEST_PUBLIC_KEY",x.SUBMIT_TOKEN="SUBMIT_TOKEN",x.SUBMIT_TRANSACTION="SUBMIT_TRANSACTION",x.SUBMIT_BLOB="SUBMIT_BLOB",x.SUBMIT_AUTH_ENTRY="SUBMIT_AUTH_ENTRY",x.REQUEST_NETWORK="REQUEST_NETWORK",x.REQUEST_NETWORK_DETAILS="REQUEST_NETWORK_DETAILS",x.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS",x.REQUEST_ALLOWED_STATUS="REQUEST_ALLOWED_STATUS",x.SET_ALLOWED_STATUS="SET_ALLOWED_STATUS",x.REQUEST_USER_INFO="REQUEST_USER_INFO"}(n||(n={}));const s=x=>{const u=Date.now()+Math.random();return window.postMessage({source:"FREIGHTER_EXTERNAL_MSG_REQUEST",messageId:u,...x},window.location.origin),new Promise(f=>{let _=0;x.type!==n.REQUEST_CONNECTION_STATUS&&x.type!==n.REQUEST_PUBLIC_KEY||(_=setTimeout(()=>{f({isConnected:!1,publicKey:""}),window.removeEventListener("message",E)},2e3));const E=S=>{var j,R;S.source===window&&((j=S==null?void 0:S.data)===null||j===void 0?void 0:j.source)==="FREIGHTER_EXTERNAL_MSG_RESPONSE"&&((R=S==null?void 0:S.data)===null||R===void 0?void 0:R.messagedId)===u&&(f(S.data),window.removeEventListener("message",E),clearTimeout(_))};window.addEventListener("message",E,!1)})},o={code:-1,message:"Node environment is not supported"},c={code:-1,message:"The wallet encountered an internal error. Please try again or contact the wallet if the problem persists."},d=async()=>{let x;try{x=await s({type:n.REQUEST_ACCESS})}catch(f){console.error(f)}const{publicKey:u}=x||{publicKey:""};return{publicKey:u,error:x==null?void 0:x.apiError}},p=async()=>{let x;try{x=await s({type:n.REQUEST_PUBLIC_KEY})}catch(u){console.error(u)}return{publicKey:(x==null?void 0:x.publicKey)||"",error:x==null?void 0:x.apiError}},y=async()=>{let x;try{x=await s({type:n.REQUEST_NETWORK_DETAILS})}catch(R){console.error(R)}const{networkDetails:u,apiError:f}=x||{networkDetails:{network:"",networkUrl:"",networkPassphrase:"",sorobanRpcUrl:void 0}},{network:_,networkUrl:E,networkPassphrase:S,sorobanRpcUrl:j}=u;return{network:_,networkUrl:E,networkPassphrase:S,sorobanRpcUrl:j,error:f}},g=async()=>{let x;try{x=await s({type:n.REQUEST_ALLOWED_STATUS})}catch(f){console.error(f)}const{isAllowed:u}=x||{isAllowed:!1};return{isAllowed:u,error:x==null?void 0:x.apiError}},v=async()=>{let x="";if(Y){const u=await p();return x=u.publicKey,u.error?{address:x,error:u.error}:{address:x}}return{address:x,error:o}},M=async x=>{if(Y){const u=await(async f=>{let _;try{_=await s({contractId:f.contractId,networkPassphrase:f.networkPassphrase,type:n.SUBMIT_TOKEN})}catch{return{error:c}}return{contractId:_.contractId,error:_==null?void 0:_.apiError}})(x);return u.error?{contractId:"",error:u.error}:{contractId:u.contractId||""}}return{contractId:"",error:o}},z=async(x,u)=>{if(Y){const f=await(async(_,E)=>{let S,j,R,N;typeof E=="object"?(j=E.accountToSign,R=E.networkPassphrase):(S=E,j=void 0);try{N=await s({transactionXdr:_,network:S,networkPassphrase:R,accountToSign:j,type:n.SUBMIT_TRANSACTION})}catch{return{signedTransaction:"",signerAddress:"",error:c}}const{signedTransaction:h,signerAddress:C}=N;return{signedTransaction:h,signerAddress:C,error:N==null?void 0:N.apiError}})(x,u);return f.error?{signedTxXdr:"",signerAddress:"",error:f.error}:{signedTxXdr:f.signedTransaction,signerAddress:f.signerAddress}}return{signedTxXdr:"",signerAddress:"",error:o}},K=async(x,u)=>{if(Y){const{isAllowed:f}=await g();if(!f){const E=await d();if(E.error)return{signedMessage:null,signerAddress:"",error:E.error}}const _=await(async(E,S,j)=>{let R;const N=(j||{}).address;try{R=await s({blob:E,accountToSign:N,apiVersion:"5.0.0",networkPassphrase:j==null?void 0:j.networkPassphrase,type:n.SUBMIT_BLOB})}catch{return{signedMessage:null,signerAddress:"",error:c}}const{signedBlob:h,signerAddress:C}=R;return{signedMessage:h||null,signerAddress:C,error:R==null?void 0:R.apiError}})(x,0,u);return _.error?{signedMessage:null,signerAddress:"",error:_.error}:{signedMessage:_.signedMessage,signerAddress:_.signerAddress}}return{signedMessage:null,signerAddress:"",error:o}},D=async(x,u)=>{if(Y){const{isAllowed:f}=await g();if(!f){const E=await d();if(E.error)return{signedAuthEntry:null,signerAddress:"",error:E.error}}const _=await(async(E,S,j)=>{const R=(j||{}).address;let N;try{N=await s({entryXdr:E,accountToSign:R,apiVersion:"5.0.0",networkPassphrase:j==null?void 0:j.networkPassphrase,type:n.SUBMIT_AUTH_ENTRY})}catch(ae){return console.error(ae),{signedAuthEntry:null,signerAddress:"",error:c}}const{signedAuthEntry:h,signerAddress:C}=N;return{signedAuthEntry:h||null,signerAddress:C,error:N==null?void 0:N.apiError}})(x,0,u);return _.error?{signedAuthEntry:null,signerAddress:"",error:_.error}:{signedAuthEntry:_.signedAuthEntry,signerAddress:_.signerAddress}}return{signedAuthEntry:null,signerAddress:"",error:o}},T=async()=>Y?window.freighter?Promise.resolve({isConnected:window.freighter}):(async()=>{let x={isConnected:!1};try{x=await s({type:n.REQUEST_CONNECTION_STATUS})}catch(u){console.error(u)}return{isConnected:x.isConnected}})():{isConnected:!1,error:o},k=async()=>{if(Y){const x=await(async()=>{let u;try{u=await s({type:n.REQUEST_NETWORK_DETAILS})}catch(_){console.error(_)}const{networkDetails:f}=u||{networkDetails:{network:"",networkPassphrase:""}};return{network:f==null?void 0:f.network,networkPassphrase:f==null?void 0:f.networkPassphrase,error:u==null?void 0:u.apiError}})();return x.error?{network:"",networkPassphrase:"",error:x.error}:{network:x.network,networkPassphrase:x.networkPassphrase}}return{network:"",networkPassphrase:"",error:o}},L=async()=>{if(Y){const x=await y();return x.error?{network:"",networkUrl:"",networkPassphrase:"",error:x.error}:{network:x.network,networkUrl:x.networkUrl,networkPassphrase:x.networkPassphrase,sorobanRpcUrl:x.sorobanRpcUrl}}return{network:"",networkUrl:"",networkPassphrase:"",error:o}},$=async()=>{let x=!1;if(Y){const u=await g();return x=u.isAllowed,u.error?{isAllowed:x,error:u.error}:{isAllowed:x}}return{isAllowed:x,error:o}},F=async()=>{let x=!1;if(Y){const u=await(async()=>{let f;try{f=await s({type:n.SET_ALLOWED_STATUS})}catch(E){console.error(E)}const{isAllowed:_}=f||{isAllowed:!1};return{isAllowed:_,error:f==null?void 0:f.apiError}})();return x=u.isAllowed,u.error?{isAllowed:x,error:u.error}:{isAllowed:x}}return{isAllowed:x,error:o}},V=async()=>{let x="";if(Y){const u=await d();return x=u.publicKey,u.error?{address:x,error:u.error}:{address:x}}return{address:x,error:o}};class J{constructor(u=3e3){this.fetchInfo=async f=>{if(!this.isRunning)return;const _=await p(),E=await y();(_.error||E.error)&&f({address:"",network:"",networkPassphrase:"",error:_.error||E.error}),this.currentAddress===_.publicKey&&this.currentNetwork===E.network&&this.currentNetworkPassphrase===E.networkPassphrase||(this.currentAddress=_.publicKey,this.currentNetwork=E.network,this.currentNetworkPassphrase=E.networkPassphrase,f({address:_.publicKey,network:E.network,networkPassphrase:E.networkPassphrase})),setTimeout(()=>this.fetchInfo(f),this.timeout)},this.timeout=u,this.currentAddress="",this.currentNetwork="",this.currentNetworkPassphrase="",this.isRunning=!1}watch(u){return Y?(this.isRunning=!0,this.fetchInfo(u),{}):{error:o}}stop(){this.isRunning=!1}}const Y=typeof window<"u",ee={getAddress:v,addToken:M,signTransaction:z,signMessage:K,signAuthEntry:D,isConnected:T,getNetwork:k,getNetworkDetails:L,isAllowed:$,setAllowed:F,requestAccess:V,WatchWalletChanges:J};return i})())})(Vv);var Wi=Vv.exports,_f={},Wf={};Wf.byteLength=a7;Wf.toByteArray=s7;Wf.fromByteArray=c7;var la=[],kn=[],r7=typeof Uint8Array<"u"?Uint8Array:Array,S0="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Gs=0,n7=S0.length;Gs0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function a7(e){var t=Xv(e),r=t[0],n=t[1];return(r+n)*3/4-n}function i7(e,t,r){return(t+r)*3/4-r}function s7(e){var t,r=Xv(e),n=r[0],a=r[1],i=new r7(i7(e,n,a)),s=0,o=a>0?n-4:n,c;for(c=0;c>16&255,i[s++]=t>>8&255,i[s++]=t&255;return a===2&&(t=kn[e.charCodeAt(c)]<<2|kn[e.charCodeAt(c+1)]>>4,i[s++]=t&255),a===1&&(t=kn[e.charCodeAt(c)]<<10|kn[e.charCodeAt(c+1)]<<4|kn[e.charCodeAt(c+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function o7(e){return la[e>>18&63]+la[e>>12&63]+la[e>>6&63]+la[e&63]}function l7(e,t,r){for(var n,a=[],i=t;io?o:s+i));return n===1?(t=e[r-1],a.push(la[t>>2]+la[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],a.push(la[t>>10]+la[t>>4&63]+la[t<<2&63]+"=")),a.join("")}var D1={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */D1.read=function(e,t,r,n,a){var i,s,o=a*8-n-1,c=(1<>1,p=-7,y=r?a-1:0,g=r?-1:1,v=e[t+y];for(y+=g,i=v&(1<<-p)-1,v>>=-p,p+=o;p>0;i=i*256+e[t+y],y+=g,p-=8);for(s=i&(1<<-p)-1,i>>=-p,p+=n;p>0;s=s*256+e[t+y],y+=g,p-=8);if(i===0)i=1-d;else{if(i===c)return s?NaN:(v?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-d}return(v?-1:1)*s*Math.pow(2,i-n)};D1.write=function(e,t,r,n,a,i){var s,o,c,d=i*8-a-1,p=(1<>1,g=a===23?Math.pow(2,-24)-Math.pow(2,-77):0,v=n?0:i-1,M=n?1:-1,z=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,s=p):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+y>=1?t+=g/c:t+=g*Math.pow(2,1-y),t*c>=2&&(s++,c/=2),s+y>=p?(o=0,s=p):s+y>=1?(o=(t*c-1)*Math.pow(2,a),s=s+y):(o=t*Math.pow(2,y-1)*Math.pow(2,a),s=0));a>=8;e[r+v]=o&255,v+=M,o/=256,a-=8);for(s=s<0;e[r+v]=s&255,v+=M,s/=256,d-=8);e[r+v-M]|=z*128};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT - */(function(e){const t=Wf,r=D1,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=T,e.INSPECT_MAX_BYTES=50;const a=2147483647;e.kMaxLength=a,o.TYPED_ARRAY_SUPPORT=i(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function i(){try{const B=new Uint8Array(1),m={foo:function(){return 42}};return Object.setPrototypeOf(m,Uint8Array.prototype),Object.setPrototypeOf(B,m),B.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function s(B){if(B>a)throw new RangeError('The value "'+B+'" is invalid for option "size"');const m=new Uint8Array(B);return Object.setPrototypeOf(m,o.prototype),m}function o(B,m,w){if(typeof B=="number"){if(typeof m=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return y(B)}return c(B,m,w)}o.poolSize=8192;function c(B,m,w){if(typeof B=="string")return g(B,m);if(ArrayBuffer.isView(B))return M(B);if(B==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof B);if(Le(B,ArrayBuffer)||B&&Le(B.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Le(B,SharedArrayBuffer)||B&&Le(B.buffer,SharedArrayBuffer)))return k(B,m,w);if(typeof B=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const H=B.valueOf&&B.valueOf();if(H!=null&&H!==B)return o.from(H,m,w);const X=K(B);if(X)return X;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof B[Symbol.toPrimitive]=="function")return o.from(B[Symbol.toPrimitive]("string"),m,w);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof B)}o.from=function(B,m,w){return c(B,m,w)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function h(B){if(typeof B!="number")throw new TypeError('"size" argument must be of type number');if(B<0)throw new RangeError('The value "'+B+'" is invalid for option "size"')}function p(B,m,w){return h(B),B<=0?s(B):m!==void 0?typeof w=="string"?s(B).fill(m,w):s(B).fill(m):s(B)}o.alloc=function(B,m,w){return p(B,m,w)};function y(B){return h(B),s(B<0?0:D(B)|0)}o.allocUnsafe=function(B){return y(B)},o.allocUnsafeSlow=function(B){return y(B)};function g(B,m){if((typeof m!="string"||m==="")&&(m="utf8"),!o.isEncoding(m))throw new TypeError("Unknown encoding: "+m);const w=z(B,m)|0;let H=s(w);const X=H.write(B,m);return X!==w&&(H=H.slice(0,X)),H}function v(B){const m=B.length<0?0:D(B.length)|0,w=s(m);for(let H=0;H=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return B|0}function T(B){return+B!=B&&(B=0),o.alloc(+B)}o.isBuffer=function(m){return m!=null&&m._isBuffer===!0&&m!==o.prototype},o.compare=function(m,w){if(Le(m,Uint8Array)&&(m=o.from(m,m.offset,m.byteLength)),Le(w,Uint8Array)&&(w=o.from(w,w.offset,w.byteLength)),!o.isBuffer(m)||!o.isBuffer(w))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(m===w)return 0;let H=m.length,X=w.length;for(let ne=0,ce=Math.min(H,X);neX.length?(o.isBuffer(ce)||(ce=o.from(ce)),ce.copy(X,ne)):Uint8Array.prototype.set.call(X,ce,ne);else if(o.isBuffer(ce))ce.copy(X,ne);else throw new TypeError('"list" argument must be an Array of Buffers');ne+=ce.length}return X};function z(B,m){if(o.isBuffer(B))return B.length;if(ArrayBuffer.isView(B)||Le(B,ArrayBuffer))return B.byteLength;if(typeof B!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof B);const w=B.length,H=arguments.length>2&&arguments[2]===!0;if(!H&&w===0)return 0;let X=!1;for(;;)switch(m){case"ascii":case"latin1":case"binary":return w;case"utf8":case"utf-8":return Ce(B).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w*2;case"hex":return w>>>1;case"base64":return ct(B).length;default:if(X)return H?-1:Ce(B).length;m=(""+m).toLowerCase(),X=!0}}o.byteLength=z;function L(B,m,w){let H=!1;if((m===void 0||m<0)&&(m=0),m>this.length||((w===void 0||w>this.length)&&(w=this.length),w<=0)||(w>>>=0,m>>>=0,w<=m))return"";for(B||(B="utf8");;)switch(B){case"hex":return N(this,m,w);case"utf8":case"utf-8":return _(this,m,w);case"ascii":return j(this,m,w);case"latin1":case"binary":return R(this,m,w);case"base64":return f(this,m,w);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return d(this,m,w);default:if(H)throw new TypeError("Unknown encoding: "+B);B=(B+"").toLowerCase(),H=!0}}o.prototype._isBuffer=!0;function $(B,m,w){const H=B[m];B[m]=B[w],B[w]=H}o.prototype.swap16=function(){const m=this.length;if(m%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let w=0;ww&&(m+=" ... "),""},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(m,w,H,X,ne){if(Le(m,Uint8Array)&&(m=o.from(m,m.offset,m.byteLength)),!o.isBuffer(m))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof m);if(w===void 0&&(w=0),H===void 0&&(H=m?m.length:0),X===void 0&&(X=0),ne===void 0&&(ne=this.length),w<0||H>m.length||X<0||ne>this.length)throw new RangeError("out of range index");if(X>=ne&&w>=H)return 0;if(X>=ne)return-1;if(w>=H)return 1;if(w>>>=0,H>>>=0,X>>>=0,ne>>>=0,this===m)return 0;let ce=ne-X,ze=H-w;const jt=Math.min(ce,ze),$e=this.slice(X,ne),Xe=m.slice(w,H);for(let pt=0;pt2147483647?w=2147483647:w<-2147483648&&(w=-2147483648),w=+w,gt(w)&&(w=X?0:B.length-1),w<0&&(w=B.length+w),w>=B.length){if(X)return-1;w=B.length-1}else if(w<0)if(X)w=0;else return-1;if(typeof m=="string"&&(m=o.from(m,H)),o.isBuffer(m))return m.length===0?-1:V(B,m,w,H,X);if(typeof m=="number")return m=m&255,typeof Uint8Array.prototype.indexOf=="function"?X?Uint8Array.prototype.indexOf.call(B,m,w):Uint8Array.prototype.lastIndexOf.call(B,m,w):V(B,[m],w,H,X);throw new TypeError("val must be string, number or Buffer")}function V(B,m,w,H,X){let ne=1,ce=B.length,ze=m.length;if(H!==void 0&&(H=String(H).toLowerCase(),H==="ucs2"||H==="ucs-2"||H==="utf16le"||H==="utf-16le")){if(B.length<2||m.length<2)return-1;ne=2,ce/=2,ze/=2,w/=2}function jt(Xe,pt){return ne===1?Xe[pt]:Xe.readUInt16BE(pt*ne)}let $e;if(X){let Xe=-1;for($e=w;$ece&&(w=ce-ze),$e=w;$e>=0;$e--){let Xe=!0;for(let pt=0;ptX&&(H=X)):H=X;const ne=m.length;H>ne/2&&(H=ne/2);let ce;for(ce=0;ce>>0,isFinite(H)?(H=H>>>0,X===void 0&&(X="utf8")):(X=H,H=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ne=this.length-w;if((H===void 0||H>ne)&&(H=ne),m.length>0&&(H<0||w<0)||w>this.length)throw new RangeError("Attempt to write outside buffer bounds");X||(X="utf8");let ce=!1;for(;;)switch(X){case"hex":return J(this,m,w,H);case"utf8":case"utf-8":return Y(this,m,w,H);case"ascii":case"latin1":case"binary":return te(this,m,w,H);case"base64":return x(this,m,w,H);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u(this,m,w,H);default:if(ce)throw new TypeError("Unknown encoding: "+X);X=(""+X).toLowerCase(),ce=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function f(B,m,w){return m===0&&w===B.length?t.fromByteArray(B):t.fromByteArray(B.slice(m,w))}function _(B,m,w){w=Math.min(B.length,w);const H=[];let X=m;for(;X239?4:ne>223?3:ne>191?2:1;if(X+ze<=w){let jt,$e,Xe,pt;switch(ze){case 1:ne<128&&(ce=ne);break;case 2:jt=B[X+1],(jt&192)===128&&(pt=(ne&31)<<6|jt&63,pt>127&&(ce=pt));break;case 3:jt=B[X+1],$e=B[X+2],(jt&192)===128&&($e&192)===128&&(pt=(ne&15)<<12|(jt&63)<<6|$e&63,pt>2047&&(pt<55296||pt>57343)&&(ce=pt));break;case 4:jt=B[X+1],$e=B[X+2],Xe=B[X+3],(jt&192)===128&&($e&192)===128&&(Xe&192)===128&&(pt=(ne&15)<<18|(jt&63)<<12|($e&63)<<6|Xe&63,pt>65535&&pt<1114112&&(ce=pt))}}ce===null?(ce=65533,ze=1):ce>65535&&(ce-=65536,H.push(ce>>>10&1023|55296),ce=56320|ce&1023),H.push(ce),X+=ze}return S(H)}const E=4096;function S(B){const m=B.length;if(m<=E)return String.fromCharCode.apply(String,B);let w="",H=0;for(;HH)&&(w=H);let X="";for(let ne=m;neH&&(m=H),w<0?(w+=H,w<0&&(w=0)):w>H&&(w=H),ww)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(m,w,H){m=m>>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m],ne=1,ce=0;for(;++ce>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m+--w],ne=1;for(;w>0&&(ne*=256);)X+=this[m+--w]*ne;return X},o.prototype.readUint8=o.prototype.readUInt8=function(m,w){return m=m>>>0,w||C(m,1,this.length),this[m]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(m,w){return m=m>>>0,w||C(m,2,this.length),this[m]|this[m+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(m,w){return m=m>>>0,w||C(m,2,this.length),this[m]<<8|this[m+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(m,w){return m=m>>>0,w||C(m,4,this.length),(this[m]|this[m+1]<<8|this[m+2]<<16)+this[m+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]*16777216+(this[m+1]<<16|this[m+2]<<8|this[m+3])},o.prototype.readBigUInt64LE=et(function(m){m=m>>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=w+this[++m]*2**8+this[++m]*2**16+this[++m]*2**24,ne=this[++m]+this[++m]*2**8+this[++m]*2**16+H*2**24;return BigInt(X)+(BigInt(ne)<>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=w*2**24+this[++m]*2**16+this[++m]*2**8+this[++m],ne=this[++m]*2**24+this[++m]*2**16+this[++m]*2**8+H;return(BigInt(X)<>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m],ne=1,ce=0;for(;++ce=ne&&(X-=Math.pow(2,8*w)),X},o.prototype.readIntBE=function(m,w,H){m=m>>>0,w=w>>>0,H||C(m,w,this.length);let X=w,ne=1,ce=this[m+--X];for(;X>0&&(ne*=256);)ce+=this[m+--X]*ne;return ne*=128,ce>=ne&&(ce-=Math.pow(2,8*w)),ce},o.prototype.readInt8=function(m,w){return m=m>>>0,w||C(m,1,this.length),this[m]&128?(255-this[m]+1)*-1:this[m]},o.prototype.readInt16LE=function(m,w){m=m>>>0,w||C(m,2,this.length);const H=this[m]|this[m+1]<<8;return H&32768?H|4294901760:H},o.prototype.readInt16BE=function(m,w){m=m>>>0,w||C(m,2,this.length);const H=this[m+1]|this[m]<<8;return H&32768?H|4294901760:H},o.prototype.readInt32LE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]|this[m+1]<<8|this[m+2]<<16|this[m+3]<<24},o.prototype.readInt32BE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]<<24|this[m+1]<<16|this[m+2]<<8|this[m+3]},o.prototype.readBigInt64LE=et(function(m){m=m>>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=this[m+4]+this[m+5]*2**8+this[m+6]*2**16+(H<<24);return(BigInt(X)<>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=(w<<24)+this[++m]*2**16+this[++m]*2**8+this[++m];return(BigInt(X)<>>0,w||C(m,4,this.length),r.read(this,m,!0,23,4)},o.prototype.readFloatBE=function(m,w){return m=m>>>0,w||C(m,4,this.length),r.read(this,m,!1,23,4)},o.prototype.readDoubleLE=function(m,w){return m=m>>>0,w||C(m,8,this.length),r.read(this,m,!0,52,8)},o.prototype.readDoubleBE=function(m,w){return m=m>>>0,w||C(m,8,this.length),r.read(this,m,!1,52,8)};function ae(B,m,w,H,X,ne){if(!o.isBuffer(B))throw new TypeError('"buffer" argument must be a Buffer instance');if(m>X||mB.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(m,w,H,X){if(m=+m,w=w>>>0,H=H>>>0,!X){const ze=Math.pow(2,8*H)-1;ae(this,m,w,H,ze,0)}let ne=1,ce=0;for(this[w]=m&255;++ce>>0,H=H>>>0,!X){const ze=Math.pow(2,8*H)-1;ae(this,m,w,H,ze,0)}let ne=H-1,ce=1;for(this[w+ne]=m&255;--ne>=0&&(ce*=256);)this[w+ne]=m/ce&255;return w+H},o.prototype.writeUint8=o.prototype.writeUInt8=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,1,255,0),this[w]=m&255,w+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,65535,0),this[w]=m&255,this[w+1]=m>>>8,w+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,65535,0),this[w]=m>>>8,this[w+1]=m&255,w+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,4294967295,0),this[w+3]=m>>>24,this[w+2]=m>>>16,this[w+1]=m>>>8,this[w]=m&255,w+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,4294967295,0),this[w]=m>>>24,this[w+1]=m>>>16,this[w+2]=m>>>8,this[w+3]=m&255,w+4};function he(B,m,w,H,X){fe(m,H,X,B,w,7);let ne=Number(m&BigInt(4294967295));B[w++]=ne,ne=ne>>8,B[w++]=ne,ne=ne>>8,B[w++]=ne,ne=ne>>8,B[w++]=ne;let ce=Number(m>>BigInt(32)&BigInt(4294967295));return B[w++]=ce,ce=ce>>8,B[w++]=ce,ce=ce>>8,B[w++]=ce,ce=ce>>8,B[w++]=ce,w}function q(B,m,w,H,X){fe(m,H,X,B,w,7);let ne=Number(m&BigInt(4294967295));B[w+7]=ne,ne=ne>>8,B[w+6]=ne,ne=ne>>8,B[w+5]=ne,ne=ne>>8,B[w+4]=ne;let ce=Number(m>>BigInt(32)&BigInt(4294967295));return B[w+3]=ce,ce=ce>>8,B[w+2]=ce,ce=ce>>8,B[w+1]=ce,ce=ce>>8,B[w]=ce,w+8}o.prototype.writeBigUInt64LE=et(function(m,w=0){return he(this,m,w,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=et(function(m,w=0){return q(this,m,w,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(m,w,H,X){if(m=+m,w=w>>>0,!X){const jt=Math.pow(2,8*H-1);ae(this,m,w,H,jt-1,-jt)}let ne=0,ce=1,ze=0;for(this[w]=m&255;++ne>0)-ze&255;return w+H},o.prototype.writeIntBE=function(m,w,H,X){if(m=+m,w=w>>>0,!X){const jt=Math.pow(2,8*H-1);ae(this,m,w,H,jt-1,-jt)}let ne=H-1,ce=1,ze=0;for(this[w+ne]=m&255;--ne>=0&&(ce*=256);)m<0&&ze===0&&this[w+ne+1]!==0&&(ze=1),this[w+ne]=(m/ce>>0)-ze&255;return w+H},o.prototype.writeInt8=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,1,127,-128),m<0&&(m=255+m+1),this[w]=m&255,w+1},o.prototype.writeInt16LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,32767,-32768),this[w]=m&255,this[w+1]=m>>>8,w+2},o.prototype.writeInt16BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,32767,-32768),this[w]=m>>>8,this[w+1]=m&255,w+2},o.prototype.writeInt32LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,2147483647,-2147483648),this[w]=m&255,this[w+1]=m>>>8,this[w+2]=m>>>16,this[w+3]=m>>>24,w+4},o.prototype.writeInt32BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,2147483647,-2147483648),m<0&&(m=4294967295+m+1),this[w]=m>>>24,this[w+1]=m>>>16,this[w+2]=m>>>8,this[w+3]=m&255,w+4},o.prototype.writeBigInt64LE=et(function(m,w=0){return he(this,m,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=et(function(m,w=0){return q(this,m,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(B,m,w,H,X,ne){if(w+H>B.length)throw new RangeError("Index out of range");if(w<0)throw new RangeError("Index out of range")}function W(B,m,w,H,X){return m=+m,w=w>>>0,X||G(B,m,w,4),r.write(B,m,w,H,23,4),w+4}o.prototype.writeFloatLE=function(m,w,H){return W(this,m,w,!0,H)},o.prototype.writeFloatBE=function(m,w,H){return W(this,m,w,!1,H)};function be(B,m,w,H,X){return m=+m,w=w>>>0,X||G(B,m,w,8),r.write(B,m,w,H,52,8),w+8}o.prototype.writeDoubleLE=function(m,w,H){return be(this,m,w,!0,H)},o.prototype.writeDoubleBE=function(m,w,H){return be(this,m,w,!1,H)},o.prototype.copy=function(m,w,H,X){if(!o.isBuffer(m))throw new TypeError("argument should be a Buffer");if(H||(H=0),!X&&X!==0&&(X=this.length),w>=m.length&&(w=m.length),w||(w=0),X>0&&X=this.length)throw new RangeError("Index out of range");if(X<0)throw new RangeError("sourceEnd out of bounds");X>this.length&&(X=this.length),m.length-w>>0,H=H===void 0?this.length:H>>>0,m||(m=0);let ne;if(typeof m=="number")for(ne=w;ne2**32?X=le(String(w)):typeof w=="bigint"&&(X=String(w),(w>BigInt(2)**BigInt(32)||w<-(BigInt(2)**BigInt(32)))&&(X=le(X)),X+="n"),H+=` It must be ${m}. Received ${X}`,H},RangeError);function le(B){let m="",w=B.length;const H=B[0]==="-"?1:0;for(;w>=H+4;w-=3)m=`_${B.slice(w-3,w)}${m}`;return`${B.slice(0,w)}${m}`}function Se(B,m,w){ie(m,"offset"),(B[m]===void 0||B[m+w]===void 0)&&pe(m,B.length-(w+1))}function fe(B,m,w,H,X,ne){if(B>w||B= 0${ce} and < 2${ce} ** ${(ne+1)*8}${ce}`:ze=`>= -(2${ce} ** ${(ne+1)*8-1}${ce}) and < 2 ** ${(ne+1)*8-1}${ce}`,new ue.ERR_OUT_OF_RANGE("value",ze,B)}Se(H,X,ne)}function ie(B,m){if(typeof B!="number")throw new ue.ERR_INVALID_ARG_TYPE(m,"number",B)}function pe(B,m,w){throw Math.floor(B)!==B?(ie(B,w),new ue.ERR_OUT_OF_RANGE("offset","an integer",B)):m<0?new ue.ERR_BUFFER_OUT_OF_BOUNDS:new ue.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${m}`,B)}const me=/[^+/0-9A-Za-z-_]/g;function ye(B){if(B=B.split("=")[0],B=B.trim().replace(me,""),B.length<2)return"";for(;B.length%4!==0;)B=B+"=";return B}function Ce(B,m){m=m||1/0;let w;const H=B.length;let X=null;const ne=[];for(let ce=0;ce55295&&w<57344){if(!X){if(w>56319){(m-=3)>-1&&ne.push(239,191,189);continue}else if(ce+1===H){(m-=3)>-1&&ne.push(239,191,189);continue}X=w;continue}if(w<56320){(m-=3)>-1&&ne.push(239,191,189),X=w;continue}w=(X-55296<<10|w-56320)+65536}else X&&(m-=3)>-1&&ne.push(239,191,189);if(X=null,w<128){if((m-=1)<0)break;ne.push(w)}else if(w<2048){if((m-=2)<0)break;ne.push(w>>6|192,w&63|128)}else if(w<65536){if((m-=3)<0)break;ne.push(w>>12|224,w>>6&63|128,w&63|128)}else if(w<1114112){if((m-=4)<0)break;ne.push(w>>18|240,w>>12&63|128,w>>6&63|128,w&63|128)}else throw new Error("Invalid code point")}return ne}function je(B){const m=[];for(let w=0;w>8,X=w%256,ne.push(X),ne.push(H);return ne}function ct(B){return t.toByteArray(ye(B))}function He(B,m,w,H){let X;for(X=0;X=m.length||X>=B.length);++X)m[X+w]=B[X];return X}function Le(B,m){return B instanceof m||B!=null&&B.constructor!=null&&B.constructor.name!=null&&B.constructor.name===m.name}function gt(B){return B!==B}const rt=function(){const B="0123456789abcdef",m=new Array(256);for(let w=0;w<16;++w){const H=w*16;for(let X=0;X<16;++X)m[H+X]=B[w]+B[X]}return m}();function et(B){return typeof BigInt>"u"?dr:B}function dr(){throw new Error("BigInt not supported")}})(_f);const u7="freighter";class f7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=u7,this.productName="Freighter",this.productUrl="https://freighter.app",this.productIcon="https://stellar.creit.tech/wallet-icons/freighter.png"}async runChecks(){if(!await this.isAvailable())throw new Error("Freighter is not connected")}async isAvailable(){var t,r;return((t=window.stellar)==null?void 0:t.provider)==="freighter"&&((r=window.stellar)==null?void 0:r.platform)==="mobile"?!1:Wi.isConnected().then(({isConnected:n,error:a})=>!a&&n).catch(()=>!1)}async getAddress(t){return this.runChecks().then(async()=>t!=null&&t.skipRequestAccess?!0:Wi.requestAccess()).then(()=>Wi.getAddress()).then(({address:r,error:n})=>{if(n)throw n;if(!r)throw{code:-3,message:"Getting the address is not allowed, please request access first."};return{address:r}}).catch(r=>{throw cn(r)})}async signTransaction(t,r){return this.runChecks().then(async()=>{const{signedTxXdr:n,signerAddress:a,error:i}=await Wi.signTransaction(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i)throw i;return{signedTxXdr:n,signerAddress:a}}).catch(n=>{throw cn(n)})}async signAuthEntry(t,r){return this.runChecks().then(async()=>{const{signedAuthEntry:n,signerAddress:a,error:i}=await Wi.signAuthEntry(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i||!n)throw i;return{signedAuthEntry:_f.Buffer.from(n).toString("base64"),signerAddress:a}}).catch(n=>{throw cn(n)})}async signMessage(t,r){return this.runChecks().then(async()=>{const{signedMessage:n,signerAddress:a,error:i}=await Wi.signMessage(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i||!n)throw i;return{signedMessage:typeof n=="string"?n:_f.Buffer.from(n).toString("base64"),signerAddress:a}}).catch(n=>{throw cn(n)})}async getNetwork(){return this.runChecks().then(async()=>{const{network:t,networkPassphrase:r,error:n}=await Wi.getNetwork();if(n)throw n;return{network:t,networkPassphrase:r}}).catch(t=>{throw cn(t)})}}var Zv={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,()=>(()=>{var r,n,a,i={d:(M,k)=>{for(var K in k)i.o(k,K)&&!i.o(M,K)&&Object.defineProperty(M,K,{enumerable:!0,get:k[K]})},o:(M,k)=>Object.prototype.hasOwnProperty.call(M,k),r:M=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(M,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{default:()=>v,getPublicKey:()=>h,isBrowser:()=>g,isConnected:()=>y,signTransaction:()=>p}),function(M){M.LOAD_STATE="LOAD_STATE",M.LOGIN="LOGIN",M.LOGOUT="LOGOUT",M.SIGN_TRANSACTION="SIGN_TRANSACTION",M.REJECT_TRANSACTION="REJECT_TRANSACTION",M.GRANT_ACCESS="GRANT_ACCESS",M.REJECT_ACCESS="REJECT_ACCESS"}(r||(r={})),function(M){M.REQUEST_ACCESS="REQUEST_ACCESS",M.SIGN_TRANSACTION="SUBMIT_TRANSACTION",M.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS"}(n||(n={})),function(M){M.pending="pending",M.signed="signed",M.rejected="rejected"}(a||(a={}));const o="LOBSTR_CONNECTION_KEY",c=M=>{const k=Date.now()+Math.random();return window.postMessage({source:"LOBSTR_EXTERNAL_MSG_REQUEST",messageId:k,...M},window.location.origin),new Promise(K=>{let D=0;M.type===n.REQUEST_CONNECTION_STATUS&&(D=setTimeout(()=>{K({isConnected:!1}),window.removeEventListener("message",T)},2e3));const T=z=>{var L,$;z.source===window&&((L=z==null?void 0:z.data)===null||L===void 0?void 0:L.source)==="LOBSTR_EXTERNAL_MSG_RESPONSE"&&(($=z==null?void 0:z.data)===null||$===void 0?void 0:$.messagedId)===k&&(K(z.data),window.removeEventListener("message",T),clearTimeout(D))};window.addEventListener("message",T,!1)})},h=async()=>{if(!g)return"";const{publicKey:M,connectionKey:k}=await(async()=>{let K={publicKey:"",error:"",connectionKey:""};try{K=await c({type:n.REQUEST_ACCESS})}catch(L){console.error(L)}const{publicKey:D,connectionKey:T,error:z}=K;if(z)throw z;return{publicKey:D,connectionKey:T}})();return(K=>{var D;(D=window==null?void 0:window.sessionStorage)===null||D===void 0||D.setItem(o,K)})(k),M},p=async M=>{if(!g)return"";const k=((K=window==null?void 0:window.sessionStorage)===null||K===void 0?void 0:K.getItem(o))||"";var K;return await(async(D,T)=>{let z={signedTransaction:"",error:""};try{z=await c({transactionXdr:D,connectionKey:T,type:n.SIGN_TRANSACTION})}catch(F){throw console.error(F),F}const{signedTransaction:L,error:$}=z;if($)throw $;return L})(M,k)},y=async()=>!!g&&(window.lobstrSignerExtension?window.lobstrSignerExtension:await(async()=>{let M={isConnected:!1};try{M=await c({type:n.REQUEST_CONNECTION_STATUS})}catch(k){console.error(k)}return M.isConnected})()),g=typeof window<"u",v={getPublicKey:h,signTransaction:p,isConnected:y};return s})())})(Zv);var ml=Zv.exports;const d7="lobstr";class h7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=d7,this.productName="LOBSTR",this.productUrl="https://lobstr.co",this.productIcon="https://stellar.creit.tech/wallet-icons/lobstr.png"}async isAvailable(){return ml.isConnected()}async getAddress(){return(async()=>{if(!await ml.isConnected())throw new Error("Lobstr is not connected")})().then(()=>ml.getPublicKey()).then(r=>({address:r})).catch(r=>{throw cn(r)})}async signTransaction(t,r){return(async()=>{if(!await ml.isConnected())throw new Error("Lobstr is not connected");r!=null&&r.address&&console.warn("Lobstr doesn't allow specifying what public key should sign the transaction, we skip the value"),r!=null&&r.networkPassphrase&&console.warn("Lobstr doesn't allow specifying the network that should be used, we skip the value")})().then(()=>ml.signTransaction(t)).then(a=>({signedTxXdr:a})).catch(a=>{throw cn(a)})}async signAuthEntry(){throw{code:-3,message:'Lobstr does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Lobstr does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Lobstr does not support the "getNetwork" function'}}}const p7="rabet";class b7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=p7,this.productName="Rabet",this.productUrl="https://rabet.io/",this.productIcon="https://stellar.creit.tech/wallet-icons/rabet.png"}isAvailable(){return new Promise(t=>{setTimeout(()=>{t(typeof window<"u"&&!!window.rabet)},100)})}async getAddress(){return(async()=>{if(!await this.isAvailable())throw new Error("Rabet is not installed")})().then(()=>window.rabet.connect()).then(({publicKey:r})=>({address:r})).catch(r=>{throw cn(r)})}async signTransaction(t,r){const n=async()=>{if(!await this.isAvailable())throw new Error("Rabet is not installed");if(r!=null&&r.address&&r.networkPassphrase!==bs.PUBLIC&&r.networkPassphrase!==bs.TESTNET)throw new Error(`Rabet doesn't support the network: ${r.networkPassphrase}`);r!=null&&r.address&&console.warn("Rabet doesn't allow specifying the network that should be used, we skip the value")},a=async()=>window.rabet.sign(t,(r==null?void 0:r.networkPassphrase)===bs.PUBLIC?"mainnet":"testnet");return n().then(a).then(i=>({signedTxXdr:i==null?void 0:i.xdr})).catch(i=>{throw cn(i)})}async signAuthEntry(){throw{code:-3,message:'Rabet does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Rabet does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Rabet does not support the "getNetwork" function'}}}function m7(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Qv={exports:{}};const x7={},y7=Object.freeze(Object.defineProperty({__proto__:null,default:x7},Symbol.toStringTag,{value:"Module"})),hc=Yx(y7);(function(e){(function(t){var r=function(A){var U,O=new Float64Array(16);if(A)for(U=0;U>24&255,A[U+1]=O>>16&255,A[U+2]=O>>8&255,A[U+3]=O&255,A[U+4]=b>>24&255,A[U+5]=b>>16&255,A[U+6]=b>>8&255,A[U+7]=b&255}function k(A,U,O,b,I){var Z,ee=0;for(Z=0;Z>>8)-1}function K(A,U,O,b){return k(A,U,O,b,16)}function D(A,U,O,b){return k(A,U,O,b,32)}function T(A,U,O,b){for(var I=b[0]&255|(b[1]&255)<<8|(b[2]&255)<<16|(b[3]&255)<<24,Z=O[0]&255|(O[1]&255)<<8|(O[2]&255)<<16|(O[3]&255)<<24,ee=O[4]&255|(O[5]&255)<<8|(O[6]&255)<<16|(O[7]&255)<<24,de=O[8]&255|(O[9]&255)<<8|(O[10]&255)<<16|(O[11]&255)<<24,we=O[12]&255|(O[13]&255)<<8|(O[14]&255)<<16|(O[15]&255)<<24,ke=b[4]&255|(b[5]&255)<<8|(b[6]&255)<<16|(b[7]&255)<<24,Ne=U[0]&255|(U[1]&255)<<8|(U[2]&255)<<16|(U[3]&255)<<24,ft=U[4]&255|(U[5]&255)<<8|(U[6]&255)<<16|(U[7]&255)<<24,Be=U[8]&255|(U[9]&255)<<8|(U[10]&255)<<16|(U[11]&255)<<24,Fe=U[12]&255|(U[13]&255)<<8|(U[14]&255)<<16|(U[15]&255)<<24,Ke=b[8]&255|(b[9]&255)<<8|(b[10]&255)<<16|(b[11]&255)<<24,Je=O[16]&255|(O[17]&255)<<8|(O[18]&255)<<16|(O[19]&255)<<24,Qe=O[20]&255|(O[21]&255)<<8|(O[22]&255)<<16|(O[23]&255)<<24,Pe=O[24]&255|(O[25]&255)<<8|(O[26]&255)<<16|(O[27]&255)<<24,Ye=O[28]&255|(O[29]&255)<<8|(O[30]&255)<<16|(O[31]&255)<<24,Ge=b[12]&255|(b[13]&255)<<8|(b[14]&255)<<16|(b[15]&255)<<24,Oe=I,De=Z,Me=ee,Re=de,Ue=we,Ae=ke,se=Ne,oe=ft,_e=Be,ge=Fe,ve=Ke,Ee=Je,qe=Qe,nt=Pe,st=Ye,at=Ge,P,ut=0;ut<20;ut+=2)P=Oe+qe|0,Ue^=P<<7|P>>>25,P=Ue+Oe|0,_e^=P<<9|P>>>23,P=_e+Ue|0,qe^=P<<13|P>>>19,P=qe+_e|0,Oe^=P<<18|P>>>14,P=Ae+De|0,ge^=P<<7|P>>>25,P=ge+Ae|0,nt^=P<<9|P>>>23,P=nt+ge|0,De^=P<<13|P>>>19,P=De+nt|0,Ae^=P<<18|P>>>14,P=ve+se|0,st^=P<<7|P>>>25,P=st+ve|0,Me^=P<<9|P>>>23,P=Me+st|0,se^=P<<13|P>>>19,P=se+Me|0,ve^=P<<18|P>>>14,P=at+Ee|0,Re^=P<<7|P>>>25,P=Re+at|0,oe^=P<<9|P>>>23,P=oe+Re|0,Ee^=P<<13|P>>>19,P=Ee+oe|0,at^=P<<18|P>>>14,P=Oe+Re|0,De^=P<<7|P>>>25,P=De+Oe|0,Me^=P<<9|P>>>23,P=Me+De|0,Re^=P<<13|P>>>19,P=Re+Me|0,Oe^=P<<18|P>>>14,P=Ae+Ue|0,se^=P<<7|P>>>25,P=se+Ae|0,oe^=P<<9|P>>>23,P=oe+se|0,Ue^=P<<13|P>>>19,P=Ue+oe|0,Ae^=P<<18|P>>>14,P=ve+ge|0,Ee^=P<<7|P>>>25,P=Ee+ve|0,_e^=P<<9|P>>>23,P=_e+Ee|0,ge^=P<<13|P>>>19,P=ge+_e|0,ve^=P<<18|P>>>14,P=at+st|0,qe^=P<<7|P>>>25,P=qe+at|0,nt^=P<<9|P>>>23,P=nt+qe|0,st^=P<<13|P>>>19,P=st+nt|0,at^=P<<18|P>>>14;Oe=Oe+I|0,De=De+Z|0,Me=Me+ee|0,Re=Re+de|0,Ue=Ue+we|0,Ae=Ae+ke|0,se=se+Ne|0,oe=oe+ft|0,_e=_e+Be|0,ge=ge+Fe|0,ve=ve+Ke|0,Ee=Ee+Je|0,qe=qe+Qe|0,nt=nt+Pe|0,st=st+Ye|0,at=at+Ge|0,A[0]=Oe>>>0&255,A[1]=Oe>>>8&255,A[2]=Oe>>>16&255,A[3]=Oe>>>24&255,A[4]=De>>>0&255,A[5]=De>>>8&255,A[6]=De>>>16&255,A[7]=De>>>24&255,A[8]=Me>>>0&255,A[9]=Me>>>8&255,A[10]=Me>>>16&255,A[11]=Me>>>24&255,A[12]=Re>>>0&255,A[13]=Re>>>8&255,A[14]=Re>>>16&255,A[15]=Re>>>24&255,A[16]=Ue>>>0&255,A[17]=Ue>>>8&255,A[18]=Ue>>>16&255,A[19]=Ue>>>24&255,A[20]=Ae>>>0&255,A[21]=Ae>>>8&255,A[22]=Ae>>>16&255,A[23]=Ae>>>24&255,A[24]=se>>>0&255,A[25]=se>>>8&255,A[26]=se>>>16&255,A[27]=se>>>24&255,A[28]=oe>>>0&255,A[29]=oe>>>8&255,A[30]=oe>>>16&255,A[31]=oe>>>24&255,A[32]=_e>>>0&255,A[33]=_e>>>8&255,A[34]=_e>>>16&255,A[35]=_e>>>24&255,A[36]=ge>>>0&255,A[37]=ge>>>8&255,A[38]=ge>>>16&255,A[39]=ge>>>24&255,A[40]=ve>>>0&255,A[41]=ve>>>8&255,A[42]=ve>>>16&255,A[43]=ve>>>24&255,A[44]=Ee>>>0&255,A[45]=Ee>>>8&255,A[46]=Ee>>>16&255,A[47]=Ee>>>24&255,A[48]=qe>>>0&255,A[49]=qe>>>8&255,A[50]=qe>>>16&255,A[51]=qe>>>24&255,A[52]=nt>>>0&255,A[53]=nt>>>8&255,A[54]=nt>>>16&255,A[55]=nt>>>24&255,A[56]=st>>>0&255,A[57]=st>>>8&255,A[58]=st>>>16&255,A[59]=st>>>24&255,A[60]=at>>>0&255,A[61]=at>>>8&255,A[62]=at>>>16&255,A[63]=at>>>24&255}function z(A,U,O,b){for(var I=b[0]&255|(b[1]&255)<<8|(b[2]&255)<<16|(b[3]&255)<<24,Z=O[0]&255|(O[1]&255)<<8|(O[2]&255)<<16|(O[3]&255)<<24,ee=O[4]&255|(O[5]&255)<<8|(O[6]&255)<<16|(O[7]&255)<<24,de=O[8]&255|(O[9]&255)<<8|(O[10]&255)<<16|(O[11]&255)<<24,we=O[12]&255|(O[13]&255)<<8|(O[14]&255)<<16|(O[15]&255)<<24,ke=b[4]&255|(b[5]&255)<<8|(b[6]&255)<<16|(b[7]&255)<<24,Ne=U[0]&255|(U[1]&255)<<8|(U[2]&255)<<16|(U[3]&255)<<24,ft=U[4]&255|(U[5]&255)<<8|(U[6]&255)<<16|(U[7]&255)<<24,Be=U[8]&255|(U[9]&255)<<8|(U[10]&255)<<16|(U[11]&255)<<24,Fe=U[12]&255|(U[13]&255)<<8|(U[14]&255)<<16|(U[15]&255)<<24,Ke=b[8]&255|(b[9]&255)<<8|(b[10]&255)<<16|(b[11]&255)<<24,Je=O[16]&255|(O[17]&255)<<8|(O[18]&255)<<16|(O[19]&255)<<24,Qe=O[20]&255|(O[21]&255)<<8|(O[22]&255)<<16|(O[23]&255)<<24,Pe=O[24]&255|(O[25]&255)<<8|(O[26]&255)<<16|(O[27]&255)<<24,Ye=O[28]&255|(O[29]&255)<<8|(O[30]&255)<<16|(O[31]&255)<<24,Ge=b[12]&255|(b[13]&255)<<8|(b[14]&255)<<16|(b[15]&255)<<24,Oe=I,De=Z,Me=ee,Re=de,Ue=we,Ae=ke,se=Ne,oe=ft,_e=Be,ge=Fe,ve=Ke,Ee=Je,qe=Qe,nt=Pe,st=Ye,at=Ge,P,ut=0;ut<20;ut+=2)P=Oe+qe|0,Ue^=P<<7|P>>>25,P=Ue+Oe|0,_e^=P<<9|P>>>23,P=_e+Ue|0,qe^=P<<13|P>>>19,P=qe+_e|0,Oe^=P<<18|P>>>14,P=Ae+De|0,ge^=P<<7|P>>>25,P=ge+Ae|0,nt^=P<<9|P>>>23,P=nt+ge|0,De^=P<<13|P>>>19,P=De+nt|0,Ae^=P<<18|P>>>14,P=ve+se|0,st^=P<<7|P>>>25,P=st+ve|0,Me^=P<<9|P>>>23,P=Me+st|0,se^=P<<13|P>>>19,P=se+Me|0,ve^=P<<18|P>>>14,P=at+Ee|0,Re^=P<<7|P>>>25,P=Re+at|0,oe^=P<<9|P>>>23,P=oe+Re|0,Ee^=P<<13|P>>>19,P=Ee+oe|0,at^=P<<18|P>>>14,P=Oe+Re|0,De^=P<<7|P>>>25,P=De+Oe|0,Me^=P<<9|P>>>23,P=Me+De|0,Re^=P<<13|P>>>19,P=Re+Me|0,Oe^=P<<18|P>>>14,P=Ae+Ue|0,se^=P<<7|P>>>25,P=se+Ae|0,oe^=P<<9|P>>>23,P=oe+se|0,Ue^=P<<13|P>>>19,P=Ue+oe|0,Ae^=P<<18|P>>>14,P=ve+ge|0,Ee^=P<<7|P>>>25,P=Ee+ve|0,_e^=P<<9|P>>>23,P=_e+Ee|0,ge^=P<<13|P>>>19,P=ge+_e|0,ve^=P<<18|P>>>14,P=at+st|0,qe^=P<<7|P>>>25,P=qe+at|0,nt^=P<<9|P>>>23,P=nt+qe|0,st^=P<<13|P>>>19,P=st+nt|0,at^=P<<18|P>>>14;A[0]=Oe>>>0&255,A[1]=Oe>>>8&255,A[2]=Oe>>>16&255,A[3]=Oe>>>24&255,A[4]=Ae>>>0&255,A[5]=Ae>>>8&255,A[6]=Ae>>>16&255,A[7]=Ae>>>24&255,A[8]=ve>>>0&255,A[9]=ve>>>8&255,A[10]=ve>>>16&255,A[11]=ve>>>24&255,A[12]=at>>>0&255,A[13]=at>>>8&255,A[14]=at>>>16&255,A[15]=at>>>24&255,A[16]=se>>>0&255,A[17]=se>>>8&255,A[18]=se>>>16&255,A[19]=se>>>24&255,A[20]=oe>>>0&255,A[21]=oe>>>8&255,A[22]=oe>>>16&255,A[23]=oe>>>24&255,A[24]=_e>>>0&255,A[25]=_e>>>8&255,A[26]=_e>>>16&255,A[27]=_e>>>24&255,A[28]=ge>>>0&255,A[29]=ge>>>8&255,A[30]=ge>>>16&255,A[31]=ge>>>24&255}function L(A,U,O,b){T(A,U,O,b)}function $(A,U,O,b){z(A,U,O,b)}var F=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function V(A,U,O,b,I,Z,ee){var de=new Uint8Array(16),we=new Uint8Array(64),ke,Ne;for(Ne=0;Ne<16;Ne++)de[Ne]=0;for(Ne=0;Ne<8;Ne++)de[Ne]=Z[Ne];for(;I>=64;){for(L(we,de,ee,F),Ne=0;Ne<64;Ne++)A[U+Ne]=O[b+Ne]^we[Ne];for(ke=1,Ne=8;Ne<16;Ne++)ke=ke+(de[Ne]&255)|0,de[Ne]=ke&255,ke>>>=8;I-=64,U+=64,b+=64}if(I>0)for(L(we,de,ee,F),Ne=0;Ne=64;){for(L(ee,Z,I,F),we=0;we<64;we++)A[U+we]=ee[we];for(de=1,we=8;we<16;we++)de=de+(Z[we]&255)|0,Z[we]=de&255,de>>>=8;O-=64,U+=64}if(O>0)for(L(ee,Z,I,F),we=0;we>>13|O<<3)&8191,b=A[4]&255|(A[5]&255)<<8,this.r[2]=(O>>>10|b<<6)&7939,I=A[6]&255|(A[7]&255)<<8,this.r[3]=(b>>>7|I<<9)&8191,Z=A[8]&255|(A[9]&255)<<8,this.r[4]=(I>>>4|Z<<12)&255,this.r[5]=Z>>>1&8190,ee=A[10]&255|(A[11]&255)<<8,this.r[6]=(Z>>>14|ee<<2)&8191,de=A[12]&255|(A[13]&255)<<8,this.r[7]=(ee>>>11|de<<5)&8065,we=A[14]&255|(A[15]&255)<<8,this.r[8]=(de>>>8|we<<8)&8191,this.r[9]=we>>>5&127,this.pad[0]=A[16]&255|(A[17]&255)<<8,this.pad[1]=A[18]&255|(A[19]&255)<<8,this.pad[2]=A[20]&255|(A[21]&255)<<8,this.pad[3]=A[22]&255|(A[23]&255)<<8,this.pad[4]=A[24]&255|(A[25]&255)<<8,this.pad[5]=A[26]&255|(A[27]&255)<<8,this.pad[6]=A[28]&255|(A[29]&255)<<8,this.pad[7]=A[30]&255|(A[31]&255)<<8};x.prototype.blocks=function(A,U,O){for(var b=this.fin?0:2048,I,Z,ee,de,we,ke,Ne,ft,Be,Fe,Ke,Je,Qe,Pe,Ye,Ge,Oe,De,Me,Re=this.h[0],Ue=this.h[1],Ae=this.h[2],se=this.h[3],oe=this.h[4],_e=this.h[5],ge=this.h[6],ve=this.h[7],Ee=this.h[8],qe=this.h[9],nt=this.r[0],st=this.r[1],at=this.r[2],P=this.r[3],ut=this.r[4],At=this.r[5],Nt=this.r[6],ot=this.r[7],_t=this.r[8],St=this.r[9];O>=16;)I=A[U+0]&255|(A[U+1]&255)<<8,Re+=I&8191,Z=A[U+2]&255|(A[U+3]&255)<<8,Ue+=(I>>>13|Z<<3)&8191,ee=A[U+4]&255|(A[U+5]&255)<<8,Ae+=(Z>>>10|ee<<6)&8191,de=A[U+6]&255|(A[U+7]&255)<<8,se+=(ee>>>7|de<<9)&8191,we=A[U+8]&255|(A[U+9]&255)<<8,oe+=(de>>>4|we<<12)&8191,_e+=we>>>1&8191,ke=A[U+10]&255|(A[U+11]&255)<<8,ge+=(we>>>14|ke<<2)&8191,Ne=A[U+12]&255|(A[U+13]&255)<<8,ve+=(ke>>>11|Ne<<5)&8191,ft=A[U+14]&255|(A[U+15]&255)<<8,Ee+=(Ne>>>8|ft<<8)&8191,qe+=ft>>>5|b,Be=0,Fe=Be,Fe+=Re*nt,Fe+=Ue*(5*St),Fe+=Ae*(5*_t),Fe+=se*(5*ot),Fe+=oe*(5*Nt),Be=Fe>>>13,Fe&=8191,Fe+=_e*(5*At),Fe+=ge*(5*ut),Fe+=ve*(5*P),Fe+=Ee*(5*at),Fe+=qe*(5*st),Be+=Fe>>>13,Fe&=8191,Ke=Be,Ke+=Re*st,Ke+=Ue*nt,Ke+=Ae*(5*St),Ke+=se*(5*_t),Ke+=oe*(5*ot),Be=Ke>>>13,Ke&=8191,Ke+=_e*(5*Nt),Ke+=ge*(5*At),Ke+=ve*(5*ut),Ke+=Ee*(5*P),Ke+=qe*(5*at),Be+=Ke>>>13,Ke&=8191,Je=Be,Je+=Re*at,Je+=Ue*st,Je+=Ae*nt,Je+=se*(5*St),Je+=oe*(5*_t),Be=Je>>>13,Je&=8191,Je+=_e*(5*ot),Je+=ge*(5*Nt),Je+=ve*(5*At),Je+=Ee*(5*ut),Je+=qe*(5*P),Be+=Je>>>13,Je&=8191,Qe=Be,Qe+=Re*P,Qe+=Ue*at,Qe+=Ae*st,Qe+=se*nt,Qe+=oe*(5*St),Be=Qe>>>13,Qe&=8191,Qe+=_e*(5*_t),Qe+=ge*(5*ot),Qe+=ve*(5*Nt),Qe+=Ee*(5*At),Qe+=qe*(5*ut),Be+=Qe>>>13,Qe&=8191,Pe=Be,Pe+=Re*ut,Pe+=Ue*P,Pe+=Ae*at,Pe+=se*st,Pe+=oe*nt,Be=Pe>>>13,Pe&=8191,Pe+=_e*(5*St),Pe+=ge*(5*_t),Pe+=ve*(5*ot),Pe+=Ee*(5*Nt),Pe+=qe*(5*At),Be+=Pe>>>13,Pe&=8191,Ye=Be,Ye+=Re*At,Ye+=Ue*ut,Ye+=Ae*P,Ye+=se*at,Ye+=oe*st,Be=Ye>>>13,Ye&=8191,Ye+=_e*nt,Ye+=ge*(5*St),Ye+=ve*(5*_t),Ye+=Ee*(5*ot),Ye+=qe*(5*Nt),Be+=Ye>>>13,Ye&=8191,Ge=Be,Ge+=Re*Nt,Ge+=Ue*At,Ge+=Ae*ut,Ge+=se*P,Ge+=oe*at,Be=Ge>>>13,Ge&=8191,Ge+=_e*st,Ge+=ge*nt,Ge+=ve*(5*St),Ge+=Ee*(5*_t),Ge+=qe*(5*ot),Be+=Ge>>>13,Ge&=8191,Oe=Be,Oe+=Re*ot,Oe+=Ue*Nt,Oe+=Ae*At,Oe+=se*ut,Oe+=oe*P,Be=Oe>>>13,Oe&=8191,Oe+=_e*at,Oe+=ge*st,Oe+=ve*nt,Oe+=Ee*(5*St),Oe+=qe*(5*_t),Be+=Oe>>>13,Oe&=8191,De=Be,De+=Re*_t,De+=Ue*ot,De+=Ae*Nt,De+=se*At,De+=oe*ut,Be=De>>>13,De&=8191,De+=_e*P,De+=ge*at,De+=ve*st,De+=Ee*nt,De+=qe*(5*St),Be+=De>>>13,De&=8191,Me=Be,Me+=Re*St,Me+=Ue*_t,Me+=Ae*ot,Me+=se*Nt,Me+=oe*At,Be=Me>>>13,Me&=8191,Me+=_e*ut,Me+=ge*P,Me+=ve*at,Me+=Ee*st,Me+=qe*nt,Be+=Me>>>13,Me&=8191,Be=(Be<<2)+Be|0,Be=Be+Fe|0,Fe=Be&8191,Be=Be>>>13,Ke+=Be,Re=Fe,Ue=Ke,Ae=Je,se=Qe,oe=Pe,_e=Ye,ge=Ge,ve=Oe,Ee=De,qe=Me,U+=16,O-=16;this.h[0]=Re,this.h[1]=Ue,this.h[2]=Ae,this.h[3]=se,this.h[4]=oe,this.h[5]=_e,this.h[6]=ge,this.h[7]=ve,this.h[8]=Ee,this.h[9]=qe},x.prototype.finish=function(A,U){var O=new Uint16Array(10),b,I,Z,ee;if(this.leftover){for(ee=this.leftover,this.buffer[ee++]=1;ee<16;ee++)this.buffer[ee]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(b=this.h[1]>>>13,this.h[1]&=8191,ee=2;ee<10;ee++)this.h[ee]+=b,b=this.h[ee]>>>13,this.h[ee]&=8191;for(this.h[0]+=b*5,b=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=b,b=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=b,O[0]=this.h[0]+5,b=O[0]>>>13,O[0]&=8191,ee=1;ee<10;ee++)O[ee]=this.h[ee]+b,b=O[ee]>>>13,O[ee]&=8191;for(O[9]-=8192,I=(b^1)-1,ee=0;ee<10;ee++)O[ee]&=I;for(I=~I,ee=0;ee<10;ee++)this.h[ee]=this.h[ee]&I|O[ee];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,Z=this.h[0]+this.pad[0],this.h[0]=Z&65535,ee=1;ee<8;ee++)Z=(this.h[ee]+this.pad[ee]|0)+(Z>>>16)|0,this.h[ee]=Z&65535;A[U+0]=this.h[0]>>>0&255,A[U+1]=this.h[0]>>>8&255,A[U+2]=this.h[1]>>>0&255,A[U+3]=this.h[1]>>>8&255,A[U+4]=this.h[2]>>>0&255,A[U+5]=this.h[2]>>>8&255,A[U+6]=this.h[3]>>>0&255,A[U+7]=this.h[3]>>>8&255,A[U+8]=this.h[4]>>>0&255,A[U+9]=this.h[4]>>>8&255,A[U+10]=this.h[5]>>>0&255,A[U+11]=this.h[5]>>>8&255,A[U+12]=this.h[6]>>>0&255,A[U+13]=this.h[6]>>>8&255,A[U+14]=this.h[7]>>>0&255,A[U+15]=this.h[7]>>>8&255},x.prototype.update=function(A,U,O){var b,I;if(this.leftover){for(I=16-this.leftover,I>O&&(I=O),b=0;b=16&&(I=O-O%16,this.blocks(A,U,I),U+=I,O-=I),O){for(b=0;b>16&1),Z[O-1]&=65535;Z[15]=ee[15]-32767-(Z[14]>>16&1),I=Z[15]>>16&1,Z[14]&=65535,R(ee,Z,1-I)}for(O=0;O<16;O++)A[2*O]=ee[O]&255,A[2*O+1]=ee[O]>>8}function d(A,U){var O=new Uint8Array(32),b=new Uint8Array(32);return N(O,A),N(b,U),D(O,0,b,0)}function C(A){var U=new Uint8Array(32);return N(U,A),U[0]&1}function ae(A,U){var O;for(O=0;O<16;O++)A[O]=U[2*O]+(U[2*O+1]<<8);A[15]&=32767}function he(A,U,O){for(var b=0;b<16;b++)A[b]=U[b]+O[b]}function q(A,U,O){for(var b=0;b<16;b++)A[b]=U[b]-O[b]}function G(A,U,O){var b,I,Z=0,ee=0,de=0,we=0,ke=0,Ne=0,ft=0,Be=0,Fe=0,Ke=0,Je=0,Qe=0,Pe=0,Ye=0,Ge=0,Oe=0,De=0,Me=0,Re=0,Ue=0,Ae=0,se=0,oe=0,_e=0,ge=0,ve=0,Ee=0,qe=0,nt=0,st=0,at=0,P=O[0],ut=O[1],At=O[2],Nt=O[3],ot=O[4],_t=O[5],St=O[6],cr=O[7],Ot=O[8],nr=O[9],ar=O[10],ir=O[11],gr=O[12],Hr=O[13],qr=O[14],$r=O[15];b=U[0],Z+=b*P,ee+=b*ut,de+=b*At,we+=b*Nt,ke+=b*ot,Ne+=b*_t,ft+=b*St,Be+=b*cr,Fe+=b*Ot,Ke+=b*nr,Je+=b*ar,Qe+=b*ir,Pe+=b*gr,Ye+=b*Hr,Ge+=b*qr,Oe+=b*$r,b=U[1],ee+=b*P,de+=b*ut,we+=b*At,ke+=b*Nt,Ne+=b*ot,ft+=b*_t,Be+=b*St,Fe+=b*cr,Ke+=b*Ot,Je+=b*nr,Qe+=b*ar,Pe+=b*ir,Ye+=b*gr,Ge+=b*Hr,Oe+=b*qr,De+=b*$r,b=U[2],de+=b*P,we+=b*ut,ke+=b*At,Ne+=b*Nt,ft+=b*ot,Be+=b*_t,Fe+=b*St,Ke+=b*cr,Je+=b*Ot,Qe+=b*nr,Pe+=b*ar,Ye+=b*ir,Ge+=b*gr,Oe+=b*Hr,De+=b*qr,Me+=b*$r,b=U[3],we+=b*P,ke+=b*ut,Ne+=b*At,ft+=b*Nt,Be+=b*ot,Fe+=b*_t,Ke+=b*St,Je+=b*cr,Qe+=b*Ot,Pe+=b*nr,Ye+=b*ar,Ge+=b*ir,Oe+=b*gr,De+=b*Hr,Me+=b*qr,Re+=b*$r,b=U[4],ke+=b*P,Ne+=b*ut,ft+=b*At,Be+=b*Nt,Fe+=b*ot,Ke+=b*_t,Je+=b*St,Qe+=b*cr,Pe+=b*Ot,Ye+=b*nr,Ge+=b*ar,Oe+=b*ir,De+=b*gr,Me+=b*Hr,Re+=b*qr,Ue+=b*$r,b=U[5],Ne+=b*P,ft+=b*ut,Be+=b*At,Fe+=b*Nt,Ke+=b*ot,Je+=b*_t,Qe+=b*St,Pe+=b*cr,Ye+=b*Ot,Ge+=b*nr,Oe+=b*ar,De+=b*ir,Me+=b*gr,Re+=b*Hr,Ue+=b*qr,Ae+=b*$r,b=U[6],ft+=b*P,Be+=b*ut,Fe+=b*At,Ke+=b*Nt,Je+=b*ot,Qe+=b*_t,Pe+=b*St,Ye+=b*cr,Ge+=b*Ot,Oe+=b*nr,De+=b*ar,Me+=b*ir,Re+=b*gr,Ue+=b*Hr,Ae+=b*qr,se+=b*$r,b=U[7],Be+=b*P,Fe+=b*ut,Ke+=b*At,Je+=b*Nt,Qe+=b*ot,Pe+=b*_t,Ye+=b*St,Ge+=b*cr,Oe+=b*Ot,De+=b*nr,Me+=b*ar,Re+=b*ir,Ue+=b*gr,Ae+=b*Hr,se+=b*qr,oe+=b*$r,b=U[8],Fe+=b*P,Ke+=b*ut,Je+=b*At,Qe+=b*Nt,Pe+=b*ot,Ye+=b*_t,Ge+=b*St,Oe+=b*cr,De+=b*Ot,Me+=b*nr,Re+=b*ar,Ue+=b*ir,Ae+=b*gr,se+=b*Hr,oe+=b*qr,_e+=b*$r,b=U[9],Ke+=b*P,Je+=b*ut,Qe+=b*At,Pe+=b*Nt,Ye+=b*ot,Ge+=b*_t,Oe+=b*St,De+=b*cr,Me+=b*Ot,Re+=b*nr,Ue+=b*ar,Ae+=b*ir,se+=b*gr,oe+=b*Hr,_e+=b*qr,ge+=b*$r,b=U[10],Je+=b*P,Qe+=b*ut,Pe+=b*At,Ye+=b*Nt,Ge+=b*ot,Oe+=b*_t,De+=b*St,Me+=b*cr,Re+=b*Ot,Ue+=b*nr,Ae+=b*ar,se+=b*ir,oe+=b*gr,_e+=b*Hr,ge+=b*qr,ve+=b*$r,b=U[11],Qe+=b*P,Pe+=b*ut,Ye+=b*At,Ge+=b*Nt,Oe+=b*ot,De+=b*_t,Me+=b*St,Re+=b*cr,Ue+=b*Ot,Ae+=b*nr,se+=b*ar,oe+=b*ir,_e+=b*gr,ge+=b*Hr,ve+=b*qr,Ee+=b*$r,b=U[12],Pe+=b*P,Ye+=b*ut,Ge+=b*At,Oe+=b*Nt,De+=b*ot,Me+=b*_t,Re+=b*St,Ue+=b*cr,Ae+=b*Ot,se+=b*nr,oe+=b*ar,_e+=b*ir,ge+=b*gr,ve+=b*Hr,Ee+=b*qr,qe+=b*$r,b=U[13],Ye+=b*P,Ge+=b*ut,Oe+=b*At,De+=b*Nt,Me+=b*ot,Re+=b*_t,Ue+=b*St,Ae+=b*cr,se+=b*Ot,oe+=b*nr,_e+=b*ar,ge+=b*ir,ve+=b*gr,Ee+=b*Hr,qe+=b*qr,nt+=b*$r,b=U[14],Ge+=b*P,Oe+=b*ut,De+=b*At,Me+=b*Nt,Re+=b*ot,Ue+=b*_t,Ae+=b*St,se+=b*cr,oe+=b*Ot,_e+=b*nr,ge+=b*ar,ve+=b*ir,Ee+=b*gr,qe+=b*Hr,nt+=b*qr,st+=b*$r,b=U[15],Oe+=b*P,De+=b*ut,Me+=b*At,Re+=b*Nt,Ue+=b*ot,Ae+=b*_t,se+=b*St,oe+=b*cr,_e+=b*Ot,ge+=b*nr,ve+=b*ar,Ee+=b*ir,qe+=b*gr,nt+=b*Hr,st+=b*qr,at+=b*$r,Z+=38*De,ee+=38*Me,de+=38*Re,we+=38*Ue,ke+=38*Ae,Ne+=38*se,ft+=38*oe,Be+=38*_e,Fe+=38*ge,Ke+=38*ve,Je+=38*Ee,Qe+=38*qe,Pe+=38*nt,Ye+=38*st,Ge+=38*at,I=1,b=Z+I+65535,I=Math.floor(b/65536),Z=b-I*65536,b=ee+I+65535,I=Math.floor(b/65536),ee=b-I*65536,b=de+I+65535,I=Math.floor(b/65536),de=b-I*65536,b=we+I+65535,I=Math.floor(b/65536),we=b-I*65536,b=ke+I+65535,I=Math.floor(b/65536),ke=b-I*65536,b=Ne+I+65535,I=Math.floor(b/65536),Ne=b-I*65536,b=ft+I+65535,I=Math.floor(b/65536),ft=b-I*65536,b=Be+I+65535,I=Math.floor(b/65536),Be=b-I*65536,b=Fe+I+65535,I=Math.floor(b/65536),Fe=b-I*65536,b=Ke+I+65535,I=Math.floor(b/65536),Ke=b-I*65536,b=Je+I+65535,I=Math.floor(b/65536),Je=b-I*65536,b=Qe+I+65535,I=Math.floor(b/65536),Qe=b-I*65536,b=Pe+I+65535,I=Math.floor(b/65536),Pe=b-I*65536,b=Ye+I+65535,I=Math.floor(b/65536),Ye=b-I*65536,b=Ge+I+65535,I=Math.floor(b/65536),Ge=b-I*65536,b=Oe+I+65535,I=Math.floor(b/65536),Oe=b-I*65536,Z+=I-1+37*(I-1),I=1,b=Z+I+65535,I=Math.floor(b/65536),Z=b-I*65536,b=ee+I+65535,I=Math.floor(b/65536),ee=b-I*65536,b=de+I+65535,I=Math.floor(b/65536),de=b-I*65536,b=we+I+65535,I=Math.floor(b/65536),we=b-I*65536,b=ke+I+65535,I=Math.floor(b/65536),ke=b-I*65536,b=Ne+I+65535,I=Math.floor(b/65536),Ne=b-I*65536,b=ft+I+65535,I=Math.floor(b/65536),ft=b-I*65536,b=Be+I+65535,I=Math.floor(b/65536),Be=b-I*65536,b=Fe+I+65535,I=Math.floor(b/65536),Fe=b-I*65536,b=Ke+I+65535,I=Math.floor(b/65536),Ke=b-I*65536,b=Je+I+65535,I=Math.floor(b/65536),Je=b-I*65536,b=Qe+I+65535,I=Math.floor(b/65536),Qe=b-I*65536,b=Pe+I+65535,I=Math.floor(b/65536),Pe=b-I*65536,b=Ye+I+65535,I=Math.floor(b/65536),Ye=b-I*65536,b=Ge+I+65535,I=Math.floor(b/65536),Ge=b-I*65536,b=Oe+I+65535,I=Math.floor(b/65536),Oe=b-I*65536,Z+=I-1+37*(I-1),A[0]=Z,A[1]=ee,A[2]=de,A[3]=we,A[4]=ke,A[5]=Ne,A[6]=ft,A[7]=Be,A[8]=Fe,A[9]=Ke,A[10]=Je,A[11]=Qe,A[12]=Pe,A[13]=Ye,A[14]=Ge,A[15]=Oe}function W(A,U){G(A,U,U)}function be(A,U){var O=r(),b;for(b=0;b<16;b++)O[b]=U[b];for(b=253;b>=0;b--)W(O,O),b!==2&&b!==4&&G(O,O,U);for(b=0;b<16;b++)A[b]=O[b]}function ue(A,U){var O=r(),b;for(b=0;b<16;b++)O[b]=U[b];for(b=250;b>=0;b--)W(O,O),b!==1&&G(O,O,U);for(b=0;b<16;b++)A[b]=O[b]}function Q(A,U,O){var b=new Uint8Array(32),I=new Float64Array(80),Z,ee,de=r(),we=r(),ke=r(),Ne=r(),ft=r(),Be=r();for(ee=0;ee<31;ee++)b[ee]=U[ee];for(b[31]=U[31]&127|64,b[0]&=248,ae(I,O),ee=0;ee<16;ee++)we[ee]=I[ee],Ne[ee]=de[ee]=ke[ee]=0;for(de[0]=Ne[0]=1,ee=254;ee>=0;--ee)Z=b[ee>>>3]>>>(ee&7)&1,R(de,we,Z),R(ke,Ne,Z),he(ft,de,ke),q(de,de,ke),he(ke,we,Ne),q(we,we,Ne),W(Ne,ft),W(Be,de),G(de,ke,de),G(ke,we,ft),he(ft,de,ke),q(de,de,ke),W(we,de),q(ke,Ne,Be),G(de,ke,c),he(de,de,Ne),G(ke,ke,de),G(de,Ne,Be),G(Ne,we,I),W(we,ft),R(de,we,Z),R(ke,Ne,Z);for(ee=0;ee<16;ee++)I[ee+16]=de[ee],I[ee+32]=ke[ee],I[ee+48]=we[ee],I[ee+64]=Ne[ee];var Fe=I.subarray(32),Ke=I.subarray(16);return be(Fe,Fe),G(Ke,Ke,Fe),N(A,Ke),0}function le(A,U){return Q(A,U,i)}function Se(A,U){return n(U,32),le(A,U)}function fe(A,U,O){var b=new Uint8Array(32);return Q(b,O,U),$(A,a,b,F)}var ie=_,pe=E;function me(A,U,O,b,I,Z){var ee=new Uint8Array(32);return fe(ee,I,Z),ie(A,U,O,b,ee)}function ye(A,U,O,b,I,Z){var ee=new Uint8Array(32);return fe(ee,I,Z),pe(A,U,O,b,ee)}var Ce=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function je(A,U,O,b){for(var I=new Int32Array(16),Z=new Int32Array(16),ee,de,we,ke,Ne,ft,Be,Fe,Ke,Je,Qe,Pe,Ye,Ge,Oe,De,Me,Re,Ue,Ae,se,oe,_e,ge,ve,Ee,qe=A[0],nt=A[1],st=A[2],at=A[3],P=A[4],ut=A[5],At=A[6],Nt=A[7],ot=U[0],_t=U[1],St=U[2],cr=U[3],Ot=U[4],nr=U[5],ar=U[6],ir=U[7],gr=0;b>=128;){for(Ue=0;Ue<16;Ue++)Ae=8*Ue+gr,I[Ue]=O[Ae+0]<<24|O[Ae+1]<<16|O[Ae+2]<<8|O[Ae+3],Z[Ue]=O[Ae+4]<<24|O[Ae+5]<<16|O[Ae+6]<<8|O[Ae+7];for(Ue=0;Ue<80;Ue++)if(ee=qe,de=nt,we=st,ke=at,Ne=P,ft=ut,Be=At,Fe=Nt,Ke=ot,Je=_t,Qe=St,Pe=cr,Ye=Ot,Ge=nr,Oe=ar,De=ir,se=Nt,oe=ir,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=(P>>>14|Ot<<18)^(P>>>18|Ot<<14)^(Ot>>>9|P<<23),oe=(Ot>>>14|P<<18)^(Ot>>>18|P<<14)^(P>>>9|Ot<<23),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=P&ut^~P&At,oe=Ot&nr^~Ot&ar,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=Ce[Ue*2],oe=Ce[Ue*2+1],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=I[Ue%16],oe=Z[Ue%16],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,Me=ve&65535|Ee<<16,Re=_e&65535|ge<<16,se=Me,oe=Re,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=(qe>>>28|ot<<4)^(ot>>>2|qe<<30)^(ot>>>7|qe<<25),oe=(ot>>>28|qe<<4)^(qe>>>2|ot<<30)^(qe>>>7|ot<<25),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=qe&nt^qe&st^nt&st,oe=ot&_t^ot&St^_t&St,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,Fe=ve&65535|Ee<<16,De=_e&65535|ge<<16,se=ke,oe=Pe,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=Me,oe=Re,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,ke=ve&65535|Ee<<16,Pe=_e&65535|ge<<16,nt=ee,st=de,at=we,P=ke,ut=Ne,At=ft,Nt=Be,qe=Fe,_t=Ke,St=Je,cr=Qe,Ot=Pe,nr=Ye,ar=Ge,ir=Oe,ot=De,Ue%16===15)for(Ae=0;Ae<16;Ae++)se=I[Ae],oe=Z[Ae],_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=I[(Ae+9)%16],oe=Z[(Ae+9)%16],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,Me=I[(Ae+1)%16],Re=Z[(Ae+1)%16],se=(Me>>>1|Re<<31)^(Me>>>8|Re<<24)^Me>>>7,oe=(Re>>>1|Me<<31)^(Re>>>8|Me<<24)^(Re>>>7|Me<<25),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,Me=I[(Ae+14)%16],Re=Z[(Ae+14)%16],se=(Me>>>19|Re<<13)^(Re>>>29|Me<<3)^Me>>>6,oe=(Re>>>19|Me<<13)^(Me>>>29|Re<<3)^(Re>>>6|Me<<26),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,I[Ae]=ve&65535|Ee<<16,Z[Ae]=_e&65535|ge<<16;se=qe,oe=ot,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[0],oe=U[0],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[0]=qe=ve&65535|Ee<<16,U[0]=ot=_e&65535|ge<<16,se=nt,oe=_t,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[1],oe=U[1],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[1]=nt=ve&65535|Ee<<16,U[1]=_t=_e&65535|ge<<16,se=st,oe=St,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[2],oe=U[2],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[2]=st=ve&65535|Ee<<16,U[2]=St=_e&65535|ge<<16,se=at,oe=cr,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[3],oe=U[3],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[3]=at=ve&65535|Ee<<16,U[3]=cr=_e&65535|ge<<16,se=P,oe=Ot,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[4],oe=U[4],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[4]=P=ve&65535|Ee<<16,U[4]=Ot=_e&65535|ge<<16,se=ut,oe=nr,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[5],oe=U[5],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[5]=ut=ve&65535|Ee<<16,U[5]=nr=_e&65535|ge<<16,se=At,oe=ar,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[6],oe=U[6],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[6]=At=ve&65535|Ee<<16,U[6]=ar=_e&65535|ge<<16,se=Nt,oe=ir,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[7],oe=U[7],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[7]=Nt=ve&65535|Ee<<16,U[7]=ir=_e&65535|ge<<16,gr+=128,b-=128}return b}function Te(A,U,O){var b=new Int32Array(8),I=new Int32Array(8),Z=new Uint8Array(256),ee,de=O;for(b[0]=1779033703,b[1]=3144134277,b[2]=1013904242,b[3]=2773480762,b[4]=1359893119,b[5]=2600822924,b[6]=528734635,b[7]=1541459225,I[0]=4089235720,I[1]=2227873595,I[2]=4271175723,I[3]=1595750129,I[4]=2917565137,I[5]=725511199,I[6]=4215389547,I[7]=327033209,je(b,I,U,O),O%=128,ee=0;ee=0;--I)b=O[I/8|0]>>(I&7)&1,He(A,U,b),ct(U,A),ct(A,A),He(A,U,b)}function rt(A,U){var O=[r(),r(),r(),r()];S(O[0],y),S(O[1],g),S(O[2],o),G(O[3],y,g),gt(A,O,U)}function et(A,U,O){var b=new Uint8Array(64),I=[r(),r(),r(),r()],Z;for(O||n(U,32),Te(b,U,32),b[0]&=248,b[31]&=127,b[31]|=64,rt(I,b),Le(A,I),Z=0;Z<32;Z++)U[Z+32]=A[Z];return 0}var dr=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function B(A,U){var O,b,I,Z;for(b=63;b>=32;--b){for(O=0,I=b-32,Z=b-12;I>4)*dr[I],O=U[I]>>8,U[I]&=255;for(I=0;I<32;I++)U[I]-=O*dr[I];for(b=0;b<32;b++)U[b+1]+=U[b]>>8,A[b]=U[b]&255}function m(A){var U=new Float64Array(64),O;for(O=0;O<64;O++)U[O]=A[O];for(O=0;O<64;O++)A[O]=0;B(A,U)}function w(A,U,O,b){var I=new Uint8Array(64),Z=new Uint8Array(64),ee=new Uint8Array(64),de,we,ke=new Float64Array(64),Ne=[r(),r(),r(),r()];Te(I,b,32),I[0]&=248,I[31]&=127,I[31]|=64;var ft=O+64;for(de=0;de>7&&q(A[0],s,A[0]),G(A[3],A[0],A[1]),0)}function X(A,U,O,b){var I,Z=new Uint8Array(32),ee=new Uint8Array(64),de=[r(),r(),r(),r()],we=[r(),r(),r(),r()];if(O<64||H(we,b))return-1;for(I=0;I=0},t.sign.keyPair=function(){var A=new Uint8Array(kt),U=new Uint8Array(Lt);return et(A,U),{publicKey:A,secretKey:U}},t.sign.keyPair.fromSecretKey=function(A){if(wt(A),A.length!==Lt)throw new Error("bad secret key size");for(var U=new Uint8Array(kt),O=0;O"u"?typeof Buffer.from<"u"?(t.encodeBase64=function(n){return Buffer.from(n).toString("base64")},t.decodeBase64=function(n){return r(n),new Uint8Array(Array.prototype.slice.call(Buffer.from(n,"base64"),0))}):(t.encodeBase64=function(n){return new Buffer(n).toString("base64")},t.decodeBase64=function(n){return r(n),new Uint8Array(Array.prototype.slice.call(new Buffer(n,"base64"),0))}):(t.encodeBase64=function(n){var a,i=[],s=n.length;for(a=0;a(e.XBULL_CONNECT="XBULL_CONNECT",e.XBULL_GET_PUBLIC_KEY="XBULL_GET_PUBLIC_KEY",e.XBULL_SIGN_XDR="XBULL_SIGN_XDR",e.XBULL_GET_NETWORK="XBULL_GET_NETWORK",e.XBULL_SIGN_MESSAGE="XBULL_SIGN_MESSAGE",e.XBULL_INITIAL_RESPONSE="XBULL_INITIAL_RESPONSE",e.XBULL_CONNECT_RESPONSE="XBULL_CONNECT_RESPONSE",e.XBULL_SIGN="XBULL_SIGN",e.XBULL_SIGN_RESPONSE="XBULL_SIGN_RESPONSE",e.XBULL_SIGN_MESSAGE_RESPONSE="XBULL_SIGN_MESSAGE_RESPONSE",e))(xn||{});function E0(e){return!!e.error}let A0=class{constructor(){this.isConnected=!1}sendEventToContentScript(t,r,n){return new Promise(a=>{const i=s=>{s.source!==window||!s.data||s.origin!==window.origin||s.data.eventId===n&&(a(s),window.removeEventListener("message",i,!1))};window.addEventListener("message",i,!1),window.webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify({type:t,eventId:n,detail:r}))})}async enableConnection(){const t={origin:window.origin,host:window.location.host,permissions:{canRequestPublicKey:!0,canRequestSign:!0}},r=await this.sendEventToContentScript(xn.XBULL_CONNECT,t,crypto.randomUUID()),{detail:n}=r.data;if(!n||n.error)throw{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"};this.isConnected=!0}async getAddress(){try{await this.enableConnection()}catch(a){return{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.message)||"Unexpected error"}}}const t={origin:window.origin,host:window.location.host},r=await this.sendEventToContentScript(xn.XBULL_GET_PUBLIC_KEY,t,crypto.randomUUID()),{detail:n}=r.data;return!n||n.error?{error:{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"}}:{address:n.payload}}async signTransaction(t){var i,s,o,c;if((i=t.opts)!=null&&i.submit||(s=t.opts)!=null&&s.submitUrl)return{error:{code:-1,message:"Parameters `submit` and `submitUrl` are not supported"}};try{await this.enableConnection()}catch(h){return{error:{code:(h==null?void 0:h.code)||-1,message:(h==null?void 0:h.message)||"Unexpected error"}}}const r={origin:window.origin,host:window.location.host,network:(o=t.opts)==null?void 0:o.networkPassphrase,publicKey:(c=t.opts)==null?void 0:c.address,xdr:t.xdr,xdrType:"Transaction"},n=await this.sendEventToContentScript(xn.XBULL_SIGN_XDR,r,crypto.randomUUID()),{detail:a}=n.data;return!a||a.error?{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.errorMessage)||"Unexpected error"}}:{signedTxXdr:a.payload.signedXdr,signerAddress:a.payload.signerAddress}}async signMessage(t,r){if(!t)return{error:{code:-1,message:"The message must be defined."}};try{await this.enableConnection()}catch(s){return{error:{code:(s==null?void 0:s.code)||-1,message:(s==null?void 0:s.message)||"Unexpected error"}}}const n={origin:window.origin,host:window.location.host,message:t,publicKey:r==null?void 0:r.address,network:r==null?void 0:r.networkPassphrase},a=await this.sendEventToContentScript(xn.XBULL_SIGN_MESSAGE,n,crypto.randomUUID()),{detail:i}=a.data;return!i||i.error?{error:{code:(i==null?void 0:i.code)||-1,message:(i==null?void 0:i.errorMessage)||"Unexpected error"}}:{signedMessage:i.payload.signedMessage,signerAddress:i.payload.signerAddress}}async getNetwork(){try{await this.enableConnection()}catch(a){return{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.message)||"Unexpected error"}}}const t={origin:window.origin,host:window.location.host},r=await this.sendEventToContentScript(xn.XBULL_GET_NETWORK,t,crypto.randomUUID()),{detail:n}=r.data;return!n||n.error?{error:{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"}}:{network:n.payload.network,networkPassphrase:n.payload.networkPassphrase}}};class N0{constructor(t){this.closeCurrentPromises$=new sn,this.closeObservables$=new sn,this.initialResponse$=new sn,this.initialResponseCompleted$=new sn,this.connectResponse$=new sn,this.connectResult$=new sn,this.signResponse$=new sn,this.signResult$=new sn,this.signMessageResponse$=new sn,this.signMessageResult$=new sn,this.closeCurrentPromisesSubscription=Yw(1e3,1e3).pipe(bn(this.closeObservables$)).subscribe(()=>{var i;(i=this.target)!=null&&i.closed&&this.closeCurrentPromises$.next()}),this.onInititalResponseSubscription=this.initialResponse$.pipe(bn(this.closeObservables$)).subscribe(i=>{const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:i.data.publicKey});JSON.parse(s).providedSession===this.session()&&(this.targetPublicKey=i.data.publicKey,this.initialResponseCompleted$.next())}),this.onConnectResponseSubscription=this.connectResponse$.pipe(bn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.connectResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.connectResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.connectResult$.next({success:!0,publicKey:o.publicKey})}),this.onSignResponseSubscription=this.signResponse$.pipe(bn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.signResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.signResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.signResult$.next({success:!0,xdr:o.xdr})}),this.onSignMessageResponseSubscription=this.signMessageResponse$.pipe(bn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.signMessageResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.signMessageResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.signMessageResult$.next({success:!0,...o})}),this.preferredTarget=(t==null?void 0:t.preferredTarget)||"extension",this.walletUrl=(t==null?void 0:t.url)||"https://wallet.xbull.app/connect";const r=xl.box.keyPair(),n=Un.encodeBase64(xl.randomBytes(24));this.encryptForReceiver=i=>{const s=xl.randomBytes(24),o=xl.box(Un.decodeUTF8(i.data),s,i.receiverPublicKey,r.secretKey);return{message:Un.encodeBase64(o),oneTimeCode:Un.encodeBase64(s)}},this.decryptFromReceiver=i=>{const s=xl.box.open(Un.decodeBase64(i.payload),Un.decodeBase64(i.oneTimeCode),Un.decodeBase64(i.senderPublicKey),r.secretKey);if(!s)throw new Error("Decrypted message is null");return Un.encodeUTF8(s)},this.publicKey=()=>r.publicKey,this.session=()=>n.slice();const a=i=>{switch(i.data.type){case xn.XBULL_INITIAL_RESPONSE:this.initialResponse$.next(i);break;case xn.XBULL_CONNECT_RESPONSE:this.connectResponse$.next(i);break;case xn.XBULL_SIGN_RESPONSE:this.signResponse$.next(i);break;case xn.XBULL_SIGN_MESSAGE_RESPONSE:this.signMessageResponse$.next(i)}};window.addEventListener("message",a),this.closeObservables$.asObservable().pipe(Tl(1)).subscribe(()=>{window.removeEventListener("message",a)})}openWallet(){return this.target&&!this.target.closed&&(this.target.close(),this.target=null,this.closeCurrentPromises$.next()),this.target=window.open(`${this.walletUrl}?public=${encodeURIComponent(Un.encodeBase64(this.publicKey()))}&session=${encodeURIComponent(this.session())}`,"xBull_Wallet_app","width=380,height=640,left=100,top=100"),cu(this.initialResponseCompleted$.pipe(bn(this.closeCurrentPromises$)).pipe(bn(this.closeObservables$)))}closeWallet(){var t;this.target&&((t=this.target)==null||t.close(),this.target=null)}async connect(t={canRequestPublicKey:!0,canRequestSign:!0}){var n,a;const r=(a=(n=window==null?void 0:window.webkit)==null?void 0:n.messageHandlers)!=null&&a.cordova_iab?new A0:window.xBullSDK;if(r&&this.preferredTarget==="extension"){const i=await r.getAddress();if(E0(i))throw i.error;return i.address}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");const{message:i,oneTimeCode:s}=this.encryptForReceiver({data:JSON.stringify(t),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:xn.XBULL_CONNECT,message:i,oneTimeCode:s};this.target.postMessage(o,"*");const c=this.connectResult$.asObservable().pipe(b0(h=>h.success?(this.closeWallet(),h0(h.publicKey)):(this.closeWallet(),p0(()=>new Error(h.message))))).pipe(Tl(1)).pipe(bn(this.closeCurrentPromises$)).pipe(bn(this.closeObservables$));return cu(c)}}async sign(t){var n,a;const r=(a=(n=window==null?void 0:window.webkit)==null?void 0:n.messageHandlers)!=null&&a.cordova_iab?new A0:window.xBullSDK;if(r&&this.preferredTarget==="extension"){const i=await r.signTransaction({xdr:t.xdr,opts:{networkPassphrase:t.network,address:t.publicKey}});if(E0(i))throw i.error;return i.signedTxXdr}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");if(typeof t.xdr!="string")throw new Error("XDR provided needs to be a string value");const{message:i,oneTimeCode:s}=this.encryptForReceiver({data:JSON.stringify(t),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:xn.XBULL_SIGN,message:i,oneTimeCode:s};this.target.postMessage(o,"*");const c=this.signResult$.asObservable().pipe(b0(h=>h.success?(this.closeWallet(),h0(h.xdr)):(this.closeWallet(),p0(()=>new Error(h.message))))).pipe(Tl(1)).pipe(bn(this.closeCurrentPromises$)).pipe(bn(this.closeObservables$));return cu(c)}}async signMessage(t,r){var a,i;const n=(i=(a=window==null?void 0:window.webkit)==null?void 0:a.messageHandlers)!=null&&i.cordova_iab?new A0:window.xBullSDK;if(n&&this.preferredTarget==="extension"){const s=await n.signMessage(t,r);if(E0(s))throw s.error;return s}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");if(typeof t!="string")throw new Error("XDR provided needs to be a string value");const s=this.encryptForReceiver({data:JSON.stringify({message:t,opts:r}),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:xn.XBULL_SIGN_MESSAGE,message:s.message,oneTimeCode:s.oneTimeCode};this.target.postMessage(o,"*");const c=this.signMessageResult$.asObservable().pipe(b0(h=>h.success?(this.closeWallet(),h0({signedMessage:h.signedMessage,signerAddress:h.signerAddress})):(this.closeWallet(),p0(()=>new Error(h.message))))).pipe(Tl(1)).pipe(bn(this.closeCurrentPromises$)).pipe(bn(this.closeObservables$));return cu(c)}}closeConnections(){this.closeObservables$.next(),this.closeCurrentPromises$.next(),this.closeObservables$.complete(),this.closeCurrentPromises$.complete()}}const g7="xbull";class v7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=g7,this.productName="xBull",this.productUrl="https://xbull.app",this.productIcon="https://stellar.creit.tech/wallet-icons/xbull.png"}async isAvailable(){return!0}async getAddress(){try{const t=new N0,r=await t.connect();return t.closeConnections(),{address:r}}catch(t){throw cn(t)}}async signTransaction(t,r){try{const n=new N0,a=await n.sign({xdr:t,publicKey:r==null?void 0:r.address,network:r==null?void 0:r.networkPassphrase});return n.closeConnections(),{signedTxXdr:a,signerAddress:r==null?void 0:r.address}}catch(n){throw cn(n)}}async signAuthEntry(){throw{code:-3,message:'xBull does not support the "signAuthEntry" function'}}async signMessage(t,r){try{const n=new N0,a=await n.signMessage(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});return n.closeConnections(),a}catch(n){throw cn(n)}}async getNetwork(){throw{code:-3,message:'xBull does not support the "getNetwork" function'}}}var w7={},Wv={},Oo={},ed={},Qo={};Qo.__esModule=!0;Qo.integers=void 0;Qo.integers=["u8","u16","u32","u64","u128","i8","i16","i32","i64","i128","f32","f64"];var Ms={};Ms.__esModule=!0;Ms.DecodeBuffer=Ms.EncodeBuffer=void 0;var _7=function(){function e(){this.offset=0,this.buffer_size=256,this.buffer=new ArrayBuffer(this.buffer_size),this.view=new DataView(this.buffer)}return e.prototype.resize_if_necessary=function(t){if(this.buffer_size-this.offsetthis.buffer.byteLength)throw new Error("Error in schema, the buffer is smaller than expected")},e.prototype.consume_value=function(t){var r=t.substring(1),n=parseInt(r)/8;this.assert_enough_buffer(n);var a=t[0]==="f"?"getFloat".concat(r):t[0]==="i"?"getInt".concat(r):"getUint".concat(r),i=this.view[a](this.offset,!0);return this.offset+=n,i},e.prototype.consume_bytes=function(t){this.assert_enough_buffer(t);var r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r},e}();Ms.DecodeBuffer=S7;var Ur={},E7=Ie&&Ie.__extends||function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,a){n.__proto__=a}||function(n,a){for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(n[i]=a[i])},e(t,r)};return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");e(t,r);function n(){this.constructor=t}t.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}();Ur.__esModule=!0;Ur.validate_schema=Ur.ErrorSchema=Ur.expect_enum=Ur.expect_same_size=Ur.expect_bigint=Ur.expect_type=Ur.isArrayLike=void 0;var A7=Qo;function N7(e){return Array.isArray(e)||!!e&&typeof e=="object"&&"length"in e&&typeof e.length=="number"&&(e.length===0||e.length>0&&e.length-1 in e)}Ur.isArrayLike=N7;function j7(e,t,r){if(typeof e!==t)throw new Error("Expected ".concat(t," not ").concat(typeof e,"(").concat(e,") at ").concat(r.join(".")))}Ur.expect_type=j7;function T7(e,t){var r=["number","string","bigint","boolean"].includes(typeof e),n=typeof e=="object"&&e!==null&&"toString"in e;if(!r&&!n)throw new Error("Expected bigint, number, boolean or string not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}Ur.expect_bigint=T7;function M7(e,t,r){if(e!==t)throw new Error("Array length ".concat(e," does not match schema length ").concat(t," at ").concat(r.join(".")))}Ur.expect_same_size=M7;function C7(e,t){if(typeof e!="object"||e===null)throw new Error("Expected object not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}Ur.expect_enum=C7;var sx=A7.integers.concat(["bool","string"]),ox=["option","enum","array","set","map","struct"],Cs=function(e){E7(t,e);function t(r,n){var a="Invalid schema: ".concat(JSON.stringify(r)," expected ").concat(n);return e.call(this,a)||this}return t}(Error);Ur.ErrorSchema=Cs;function $i(e){if(!(typeof e=="string"&&sx.includes(e))){if(e&&typeof e=="object"){var t=Object.keys(e);if(t.length===1&&ox.includes(t[0])){var r=t[0];if(r==="option")return $i(e[r]);if(r==="enum")return B7(e[r]);if(r==="array")return O7(e[r]);if(r==="set")return $i(e[r]);if(r==="map")return R7(e[r]);if(r==="struct")return U7(e[r])}}throw new Cs(e,ox.join(", ")+" or "+sx.join(", "))}}Ur.validate_schema=$i;function B7(e){if(!Array.isArray(e))throw new Cs(e,"Array");for(var t=0,r=e;t>BigInt(8);this.encoded.store_bytes(new Uint8Array(a))},e.prototype.encode_string=function(t){this.checkTypes&&Jn.expect_type(t,"string",this.fieldPath);for(var r=t,n=[],a=0;a>6,128|i&63):i<55296||i>=57344?n.push(224|i>>12,128|i>>6&63,128|i&63):(a++,i=65536+((i&1023)<<10|r.charCodeAt(a)&1023),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}this.encoded.store_value(n.length,"u32"),this.encoded.store_bytes(new Uint8Array(n))},e.prototype.encode_boolean=function(t){this.checkTypes&&Jn.expect_type(t,"boolean",this.fieldPath),this.encoded.store_value(t?1:0,"u8")},e.prototype.encode_option=function(t,r){t==null?this.encoded.store_value(0,"u8"):(this.encoded.store_value(1,"u8"),this.encode_value(t,r.option))},e.prototype.encode_enum=function(t,r){this.checkTypes&&Jn.expect_enum(t,this.fieldPath);for(var n=Object.keys(t)[0],a=0;a0},e.prototype.decode_option=function(t){var r=this.buffer.consume_value("u8");if(r===1)return this.decode_value(t.option);if(r!==0)throw new Error("Invalid option ".concat(r));return null},e.prototype.decode_enum=function(t){var r,n=this.buffer.consume_value("u8");if(n>t.enum.length)throw new Error("Enum option ".concat(n," is not available"));var a=t.enum[n].struct,i=Object.keys(a)[0];return r={},r[i]=this.decode_value(a[i]),r},e.prototype.decode_array=function(t){for(var r=[],n=t.array.len?t.array.len:this.decode_integer("u32"),a=0;aa)throw new RangeError('The value "'+B+'" is invalid for option "size"');const m=new Uint8Array(B);return Object.setPrototypeOf(m,o.prototype),m}function o(B,m,w){if(typeof B=="number"){if(typeof m=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return y(B)}return c(B,m,w)}o.poolSize=8192;function c(B,m,w){if(typeof B=="string")return g(B,m);if(ArrayBuffer.isView(B))return M(B);if(B==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof B);if(Le(B,ArrayBuffer)||B&&Le(B.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Le(B,SharedArrayBuffer)||B&&Le(B.buffer,SharedArrayBuffer)))return z(B,m,w);if(typeof B=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const H=B.valueOf&&B.valueOf();if(H!=null&&H!==B)return o.from(H,m,w);const X=K(B);if(X)return X;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof B[Symbol.toPrimitive]=="function")return o.from(B[Symbol.toPrimitive]("string"),m,w);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof B)}o.from=function(B,m,w){return c(B,m,w)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function d(B){if(typeof B!="number")throw new TypeError('"size" argument must be of type number');if(B<0)throw new RangeError('The value "'+B+'" is invalid for option "size"')}function p(B,m,w){return d(B),B<=0?s(B):m!==void 0?typeof w=="string"?s(B).fill(m,w):s(B).fill(m):s(B)}o.alloc=function(B,m,w){return p(B,m,w)};function y(B){return d(B),s(B<0?0:D(B)|0)}o.allocUnsafe=function(B){return y(B)},o.allocUnsafeSlow=function(B){return y(B)};function g(B,m){if((typeof m!="string"||m==="")&&(m="utf8"),!o.isEncoding(m))throw new TypeError("Unknown encoding: "+m);const w=k(B,m)|0;let H=s(w);const X=H.write(B,m);return X!==w&&(H=H.slice(0,X)),H}function v(B){const m=B.length<0?0:D(B.length)|0,w=s(m);for(let H=0;H=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return B|0}function T(B){return+B!=B&&(B=0),o.alloc(+B)}o.isBuffer=function(m){return m!=null&&m._isBuffer===!0&&m!==o.prototype},o.compare=function(m,w){if(Le(m,Uint8Array)&&(m=o.from(m,m.offset,m.byteLength)),Le(w,Uint8Array)&&(w=o.from(w,w.offset,w.byteLength)),!o.isBuffer(m)||!o.isBuffer(w))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(m===w)return 0;let H=m.length,X=w.length;for(let ne=0,ce=Math.min(H,X);neX.length?(o.isBuffer(ce)||(ce=o.from(ce)),ce.copy(X,ne)):Uint8Array.prototype.set.call(X,ce,ne);else if(o.isBuffer(ce))ce.copy(X,ne);else throw new TypeError('"list" argument must be an Array of Buffers');ne+=ce.length}return X};function k(B,m){if(o.isBuffer(B))return B.length;if(ArrayBuffer.isView(B)||Le(B,ArrayBuffer))return B.byteLength;if(typeof B!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof B);const w=B.length,H=arguments.length>2&&arguments[2]===!0;if(!H&&w===0)return 0;let X=!1;for(;;)switch(m){case"ascii":case"latin1":case"binary":return w;case"utf8":case"utf-8":return Ce(B).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w*2;case"hex":return w>>>1;case"base64":return ct(B).length;default:if(X)return H?-1:Ce(B).length;m=(""+m).toLowerCase(),X=!0}}o.byteLength=k;function L(B,m,w){let H=!1;if((m===void 0||m<0)&&(m=0),m>this.length||((w===void 0||w>this.length)&&(w=this.length),w<=0)||(w>>>=0,m>>>=0,w<=m))return"";for(B||(B="utf8");;)switch(B){case"hex":return N(this,m,w);case"utf8":case"utf-8":return _(this,m,w);case"ascii":return j(this,m,w);case"latin1":case"binary":return R(this,m,w);case"base64":return f(this,m,w);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return h(this,m,w);default:if(H)throw new TypeError("Unknown encoding: "+B);B=(B+"").toLowerCase(),H=!0}}o.prototype._isBuffer=!0;function $(B,m,w){const H=B[m];B[m]=B[w],B[w]=H}o.prototype.swap16=function(){const m=this.length;if(m%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let w=0;ww&&(m+=" ... "),""},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(m,w,H,X,ne){if(Le(m,Uint8Array)&&(m=o.from(m,m.offset,m.byteLength)),!o.isBuffer(m))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof m);if(w===void 0&&(w=0),H===void 0&&(H=m?m.length:0),X===void 0&&(X=0),ne===void 0&&(ne=this.length),w<0||H>m.length||X<0||ne>this.length)throw new RangeError("out of range index");if(X>=ne&&w>=H)return 0;if(X>=ne)return-1;if(w>=H)return 1;if(w>>>=0,H>>>=0,X>>>=0,ne>>>=0,this===m)return 0;let ce=ne-X,ze=H-w;const jt=Math.min(ce,ze),$e=this.slice(X,ne),Xe=m.slice(w,H);for(let pt=0;pt2147483647?w=2147483647:w<-2147483648&&(w=-2147483648),w=+w,gt(w)&&(w=X?0:B.length-1),w<0&&(w=B.length+w),w>=B.length){if(X)return-1;w=B.length-1}else if(w<0)if(X)w=0;else return-1;if(typeof m=="string"&&(m=o.from(m,H)),o.isBuffer(m))return m.length===0?-1:V(B,m,w,H,X);if(typeof m=="number")return m=m&255,typeof Uint8Array.prototype.indexOf=="function"?X?Uint8Array.prototype.indexOf.call(B,m,w):Uint8Array.prototype.lastIndexOf.call(B,m,w):V(B,[m],w,H,X);throw new TypeError("val must be string, number or Buffer")}function V(B,m,w,H,X){let ne=1,ce=B.length,ze=m.length;if(H!==void 0&&(H=String(H).toLowerCase(),H==="ucs2"||H==="ucs-2"||H==="utf16le"||H==="utf-16le")){if(B.length<2||m.length<2)return-1;ne=2,ce/=2,ze/=2,w/=2}function jt(Xe,pt){return ne===1?Xe[pt]:Xe.readUInt16BE(pt*ne)}let $e;if(X){let Xe=-1;for($e=w;$ece&&(w=ce-ze),$e=w;$e>=0;$e--){let Xe=!0;for(let pt=0;ptX&&(H=X)):H=X;const ne=m.length;H>ne/2&&(H=ne/2);let ce;for(ce=0;ce>>0,isFinite(H)?(H=H>>>0,X===void 0&&(X="utf8")):(X=H,H=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ne=this.length-w;if((H===void 0||H>ne)&&(H=ne),m.length>0&&(H<0||w<0)||w>this.length)throw new RangeError("Attempt to write outside buffer bounds");X||(X="utf8");let ce=!1;for(;;)switch(X){case"hex":return J(this,m,w,H);case"utf8":case"utf-8":return Y(this,m,w,H);case"ascii":case"latin1":case"binary":return ee(this,m,w,H);case"base64":return x(this,m,w,H);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u(this,m,w,H);default:if(ce)throw new TypeError("Unknown encoding: "+X);X=(""+X).toLowerCase(),ce=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function f(B,m,w){return m===0&&w===B.length?t.fromByteArray(B):t.fromByteArray(B.slice(m,w))}function _(B,m,w){w=Math.min(B.length,w);const H=[];let X=m;for(;X239?4:ne>223?3:ne>191?2:1;if(X+ze<=w){let jt,$e,Xe,pt;switch(ze){case 1:ne<128&&(ce=ne);break;case 2:jt=B[X+1],(jt&192)===128&&(pt=(ne&31)<<6|jt&63,pt>127&&(ce=pt));break;case 3:jt=B[X+1],$e=B[X+2],(jt&192)===128&&($e&192)===128&&(pt=(ne&15)<<12|(jt&63)<<6|$e&63,pt>2047&&(pt<55296||pt>57343)&&(ce=pt));break;case 4:jt=B[X+1],$e=B[X+2],Xe=B[X+3],(jt&192)===128&&($e&192)===128&&(Xe&192)===128&&(pt=(ne&15)<<18|(jt&63)<<12|($e&63)<<6|Xe&63,pt>65535&&pt<1114112&&(ce=pt))}}ce===null?(ce=65533,ze=1):ce>65535&&(ce-=65536,H.push(ce>>>10&1023|55296),ce=56320|ce&1023),H.push(ce),X+=ze}return S(H)}const E=4096;function S(B){const m=B.length;if(m<=E)return String.fromCharCode.apply(String,B);let w="",H=0;for(;HH)&&(w=H);let X="";for(let ne=m;neH&&(m=H),w<0?(w+=H,w<0&&(w=0)):w>H&&(w=H),ww)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(m,w,H){m=m>>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m],ne=1,ce=0;for(;++ce>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m+--w],ne=1;for(;w>0&&(ne*=256);)X+=this[m+--w]*ne;return X},o.prototype.readUint8=o.prototype.readUInt8=function(m,w){return m=m>>>0,w||C(m,1,this.length),this[m]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(m,w){return m=m>>>0,w||C(m,2,this.length),this[m]|this[m+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(m,w){return m=m>>>0,w||C(m,2,this.length),this[m]<<8|this[m+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(m,w){return m=m>>>0,w||C(m,4,this.length),(this[m]|this[m+1]<<8|this[m+2]<<16)+this[m+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]*16777216+(this[m+1]<<16|this[m+2]<<8|this[m+3])},o.prototype.readBigUInt64LE=et(function(m){m=m>>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=w+this[++m]*2**8+this[++m]*2**16+this[++m]*2**24,ne=this[++m]+this[++m]*2**8+this[++m]*2**16+H*2**24;return BigInt(X)+(BigInt(ne)<>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=w*2**24+this[++m]*2**16+this[++m]*2**8+this[++m],ne=this[++m]*2**24+this[++m]*2**16+this[++m]*2**8+H;return(BigInt(X)<>>0,w=w>>>0,H||C(m,w,this.length);let X=this[m],ne=1,ce=0;for(;++ce=ne&&(X-=Math.pow(2,8*w)),X},o.prototype.readIntBE=function(m,w,H){m=m>>>0,w=w>>>0,H||C(m,w,this.length);let X=w,ne=1,ce=this[m+--X];for(;X>0&&(ne*=256);)ce+=this[m+--X]*ne;return ne*=128,ce>=ne&&(ce-=Math.pow(2,8*w)),ce},o.prototype.readInt8=function(m,w){return m=m>>>0,w||C(m,1,this.length),this[m]&128?(255-this[m]+1)*-1:this[m]},o.prototype.readInt16LE=function(m,w){m=m>>>0,w||C(m,2,this.length);const H=this[m]|this[m+1]<<8;return H&32768?H|4294901760:H},o.prototype.readInt16BE=function(m,w){m=m>>>0,w||C(m,2,this.length);const H=this[m+1]|this[m]<<8;return H&32768?H|4294901760:H},o.prototype.readInt32LE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]|this[m+1]<<8|this[m+2]<<16|this[m+3]<<24},o.prototype.readInt32BE=function(m,w){return m=m>>>0,w||C(m,4,this.length),this[m]<<24|this[m+1]<<16|this[m+2]<<8|this[m+3]},o.prototype.readBigInt64LE=et(function(m){m=m>>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=this[m+4]+this[m+5]*2**8+this[m+6]*2**16+(H<<24);return(BigInt(X)<>>0,ie(m,"offset");const w=this[m],H=this[m+7];(w===void 0||H===void 0)&&pe(m,this.length-8);const X=(w<<24)+this[++m]*2**16+this[++m]*2**8+this[++m];return(BigInt(X)<>>0,w||C(m,4,this.length),r.read(this,m,!0,23,4)},o.prototype.readFloatBE=function(m,w){return m=m>>>0,w||C(m,4,this.length),r.read(this,m,!1,23,4)},o.prototype.readDoubleLE=function(m,w){return m=m>>>0,w||C(m,8,this.length),r.read(this,m,!0,52,8)},o.prototype.readDoubleBE=function(m,w){return m=m>>>0,w||C(m,8,this.length),r.read(this,m,!1,52,8)};function ae(B,m,w,H,X,ne){if(!o.isBuffer(B))throw new TypeError('"buffer" argument must be a Buffer instance');if(m>X||mB.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(m,w,H,X){if(m=+m,w=w>>>0,H=H>>>0,!X){const ze=Math.pow(2,8*H)-1;ae(this,m,w,H,ze,0)}let ne=1,ce=0;for(this[w]=m&255;++ce>>0,H=H>>>0,!X){const ze=Math.pow(2,8*H)-1;ae(this,m,w,H,ze,0)}let ne=H-1,ce=1;for(this[w+ne]=m&255;--ne>=0&&(ce*=256);)this[w+ne]=m/ce&255;return w+H},o.prototype.writeUint8=o.prototype.writeUInt8=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,1,255,0),this[w]=m&255,w+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,65535,0),this[w]=m&255,this[w+1]=m>>>8,w+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,65535,0),this[w]=m>>>8,this[w+1]=m&255,w+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,4294967295,0),this[w+3]=m>>>24,this[w+2]=m>>>16,this[w+1]=m>>>8,this[w]=m&255,w+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,4294967295,0),this[w]=m>>>24,this[w+1]=m>>>16,this[w+2]=m>>>8,this[w+3]=m&255,w+4};function he(B,m,w,H,X){fe(m,H,X,B,w,7);let ne=Number(m&BigInt(4294967295));B[w++]=ne,ne=ne>>8,B[w++]=ne,ne=ne>>8,B[w++]=ne,ne=ne>>8,B[w++]=ne;let ce=Number(m>>BigInt(32)&BigInt(4294967295));return B[w++]=ce,ce=ce>>8,B[w++]=ce,ce=ce>>8,B[w++]=ce,ce=ce>>8,B[w++]=ce,w}function q(B,m,w,H,X){fe(m,H,X,B,w,7);let ne=Number(m&BigInt(4294967295));B[w+7]=ne,ne=ne>>8,B[w+6]=ne,ne=ne>>8,B[w+5]=ne,ne=ne>>8,B[w+4]=ne;let ce=Number(m>>BigInt(32)&BigInt(4294967295));return B[w+3]=ce,ce=ce>>8,B[w+2]=ce,ce=ce>>8,B[w+1]=ce,ce=ce>>8,B[w]=ce,w+8}o.prototype.writeBigUInt64LE=et(function(m,w=0){return he(this,m,w,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=et(function(m,w=0){return q(this,m,w,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(m,w,H,X){if(m=+m,w=w>>>0,!X){const jt=Math.pow(2,8*H-1);ae(this,m,w,H,jt-1,-jt)}let ne=0,ce=1,ze=0;for(this[w]=m&255;++ne>0)-ze&255;return w+H},o.prototype.writeIntBE=function(m,w,H,X){if(m=+m,w=w>>>0,!X){const jt=Math.pow(2,8*H-1);ae(this,m,w,H,jt-1,-jt)}let ne=H-1,ce=1,ze=0;for(this[w+ne]=m&255;--ne>=0&&(ce*=256);)m<0&&ze===0&&this[w+ne+1]!==0&&(ze=1),this[w+ne]=(m/ce>>0)-ze&255;return w+H},o.prototype.writeInt8=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,1,127,-128),m<0&&(m=255+m+1),this[w]=m&255,w+1},o.prototype.writeInt16LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,32767,-32768),this[w]=m&255,this[w+1]=m>>>8,w+2},o.prototype.writeInt16BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,2,32767,-32768),this[w]=m>>>8,this[w+1]=m&255,w+2},o.prototype.writeInt32LE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,2147483647,-2147483648),this[w]=m&255,this[w+1]=m>>>8,this[w+2]=m>>>16,this[w+3]=m>>>24,w+4},o.prototype.writeInt32BE=function(m,w,H){return m=+m,w=w>>>0,H||ae(this,m,w,4,2147483647,-2147483648),m<0&&(m=4294967295+m+1),this[w]=m>>>24,this[w+1]=m>>>16,this[w+2]=m>>>8,this[w+3]=m&255,w+4},o.prototype.writeBigInt64LE=et(function(m,w=0){return he(this,m,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=et(function(m,w=0){return q(this,m,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(B,m,w,H,X,ne){if(w+H>B.length)throw new RangeError("Index out of range");if(w<0)throw new RangeError("Index out of range")}function W(B,m,w,H,X){return m=+m,w=w>>>0,X||G(B,m,w,4),r.write(B,m,w,H,23,4),w+4}o.prototype.writeFloatLE=function(m,w,H){return W(this,m,w,!0,H)},o.prototype.writeFloatBE=function(m,w,H){return W(this,m,w,!1,H)};function be(B,m,w,H,X){return m=+m,w=w>>>0,X||G(B,m,w,8),r.write(B,m,w,H,52,8),w+8}o.prototype.writeDoubleLE=function(m,w,H){return be(this,m,w,!0,H)},o.prototype.writeDoubleBE=function(m,w,H){return be(this,m,w,!1,H)},o.prototype.copy=function(m,w,H,X){if(!o.isBuffer(m))throw new TypeError("argument should be a Buffer");if(H||(H=0),!X&&X!==0&&(X=this.length),w>=m.length&&(w=m.length),w||(w=0),X>0&&X=this.length)throw new RangeError("Index out of range");if(X<0)throw new RangeError("sourceEnd out of bounds");X>this.length&&(X=this.length),m.length-w>>0,H=H===void 0?this.length:H>>>0,m||(m=0);let ne;if(typeof m=="number")for(ne=w;ne2**32?X=le(String(w)):typeof w=="bigint"&&(X=String(w),(w>BigInt(2)**BigInt(32)||w<-(BigInt(2)**BigInt(32)))&&(X=le(X)),X+="n"),H+=` It must be ${m}. Received ${X}`,H},RangeError);function le(B){let m="",w=B.length;const H=B[0]==="-"?1:0;for(;w>=H+4;w-=3)m=`_${B.slice(w-3,w)}${m}`;return`${B.slice(0,w)}${m}`}function Se(B,m,w){ie(m,"offset"),(B[m]===void 0||B[m+w]===void 0)&&pe(m,B.length-(w+1))}function fe(B,m,w,H,X,ne){if(B>w||B= 0${ce} and < 2${ce} ** ${(ne+1)*8}${ce}`:ze=`>= -(2${ce} ** ${(ne+1)*8-1}${ce}) and < 2 ** ${(ne+1)*8-1}${ce}`,new ue.ERR_OUT_OF_RANGE("value",ze,B)}Se(H,X,ne)}function ie(B,m){if(typeof B!="number")throw new ue.ERR_INVALID_ARG_TYPE(m,"number",B)}function pe(B,m,w){throw Math.floor(B)!==B?(ie(B,w),new ue.ERR_OUT_OF_RANGE("offset","an integer",B)):m<0?new ue.ERR_BUFFER_OUT_OF_BOUNDS:new ue.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${m}`,B)}const me=/[^+/0-9A-Za-z-_]/g;function ye(B){if(B=B.split("=")[0],B=B.trim().replace(me,""),B.length<2)return"";for(;B.length%4!==0;)B=B+"=";return B}function Ce(B,m){m=m||1/0;let w;const H=B.length;let X=null;const ne=[];for(let ce=0;ce55295&&w<57344){if(!X){if(w>56319){(m-=3)>-1&&ne.push(239,191,189);continue}else if(ce+1===H){(m-=3)>-1&&ne.push(239,191,189);continue}X=w;continue}if(w<56320){(m-=3)>-1&&ne.push(239,191,189),X=w;continue}w=(X-55296<<10|w-56320)+65536}else X&&(m-=3)>-1&&ne.push(239,191,189);if(X=null,w<128){if((m-=1)<0)break;ne.push(w)}else if(w<2048){if((m-=2)<0)break;ne.push(w>>6|192,w&63|128)}else if(w<65536){if((m-=3)<0)break;ne.push(w>>12|224,w>>6&63|128,w&63|128)}else if(w<1114112){if((m-=4)<0)break;ne.push(w>>18|240,w>>12&63|128,w>>6&63|128,w&63|128)}else throw new Error("Invalid code point")}return ne}function je(B){const m=[];for(let w=0;w>8,X=w%256,ne.push(X),ne.push(H);return ne}function ct(B){return t.toByteArray(ye(B))}function He(B,m,w,H){let X;for(X=0;X=m.length||X>=B.length);++X)m[X+w]=B[X];return X}function Le(B,m){return B instanceof m||B!=null&&B.constructor!=null&&B.constructor.name!=null&&B.constructor.name===m.name}function gt(B){return B!==B}const rt=function(){const B="0123456789abcdef",m=new Array(256);for(let w=0;w<16;++w){const H=w*16;for(let X=0;X<16;++X)m[H+X]=B[w]+B[X]}return m}();function et(B){return typeof BigInt>"u"?dr:B}function dr(){throw new Error("BigInt not supported")}})(_f);const u7="freighter";class f7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=u7,this.productName="Freighter",this.productUrl="https://freighter.app",this.productIcon="https://stellar.creit.tech/wallet-icons/freighter.png"}async runChecks(){if(!await this.isAvailable())throw new Error("Freighter is not connected")}async isAvailable(){var t,r;return((t=window.stellar)==null?void 0:t.provider)==="freighter"&&((r=window.stellar)==null?void 0:r.platform)==="mobile"?!1:Wi.isConnected().then(({isConnected:n,error:a})=>!a&&n).catch(()=>!1)}async getAddress(t){return this.runChecks().then(async()=>t!=null&&t.skipRequestAccess?!0:Wi.requestAccess()).then(()=>Wi.getAddress()).then(({address:r,error:n})=>{if(n)throw n;if(!r)throw{code:-3,message:"Getting the address is not allowed, please request access first."};return{address:r}}).catch(r=>{throw un(r)})}async signTransaction(t,r){return this.runChecks().then(async()=>{const{signedTxXdr:n,signerAddress:a,error:i}=await Wi.signTransaction(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i)throw i;return{signedTxXdr:n,signerAddress:a}}).catch(n=>{throw un(n)})}async signAuthEntry(t,r){return this.runChecks().then(async()=>{const{signedAuthEntry:n,signerAddress:a,error:i}=await Wi.signAuthEntry(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i||!n)throw i;return{signedAuthEntry:_f.Buffer.from(n).toString("base64"),signerAddress:a}}).catch(n=>{throw un(n)})}async signMessage(t,r){return this.runChecks().then(async()=>{const{signedMessage:n,signerAddress:a,error:i}=await Wi.signMessage(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});if(i||!n)throw i;return{signedMessage:typeof n=="string"?n:_f.Buffer.from(n).toString("base64"),signerAddress:a}}).catch(n=>{throw un(n)})}async getNetwork(){return this.runChecks().then(async()=>{const{network:t,networkPassphrase:r,error:n}=await Wi.getNetwork();if(n)throw n;return{network:t,networkPassphrase:r}}).catch(t=>{throw un(t)})}}var Zv={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,()=>(()=>{var r,n,a,i={d:(M,z)=>{for(var K in z)i.o(z,K)&&!i.o(M,K)&&Object.defineProperty(M,K,{enumerable:!0,get:z[K]})},o:(M,z)=>Object.prototype.hasOwnProperty.call(M,z),r:M=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(M,"__esModule",{value:!0})}},s={};i.r(s),i.d(s,{default:()=>v,getPublicKey:()=>d,isBrowser:()=>g,isConnected:()=>y,signTransaction:()=>p}),function(M){M.LOAD_STATE="LOAD_STATE",M.LOGIN="LOGIN",M.LOGOUT="LOGOUT",M.SIGN_TRANSACTION="SIGN_TRANSACTION",M.REJECT_TRANSACTION="REJECT_TRANSACTION",M.GRANT_ACCESS="GRANT_ACCESS",M.REJECT_ACCESS="REJECT_ACCESS"}(r||(r={})),function(M){M.REQUEST_ACCESS="REQUEST_ACCESS",M.SIGN_TRANSACTION="SUBMIT_TRANSACTION",M.REQUEST_CONNECTION_STATUS="REQUEST_CONNECTION_STATUS"}(n||(n={})),function(M){M.pending="pending",M.signed="signed",M.rejected="rejected"}(a||(a={}));const o="LOBSTR_CONNECTION_KEY",c=M=>{const z=Date.now()+Math.random();return window.postMessage({source:"LOBSTR_EXTERNAL_MSG_REQUEST",messageId:z,...M},window.location.origin),new Promise(K=>{let D=0;M.type===n.REQUEST_CONNECTION_STATUS&&(D=setTimeout(()=>{K({isConnected:!1}),window.removeEventListener("message",T)},2e3));const T=k=>{var L,$;k.source===window&&((L=k==null?void 0:k.data)===null||L===void 0?void 0:L.source)==="LOBSTR_EXTERNAL_MSG_RESPONSE"&&(($=k==null?void 0:k.data)===null||$===void 0?void 0:$.messagedId)===z&&(K(k.data),window.removeEventListener("message",T),clearTimeout(D))};window.addEventListener("message",T,!1)})},d=async()=>{if(!g)return"";const{publicKey:M,connectionKey:z}=await(async()=>{let K={publicKey:"",error:"",connectionKey:""};try{K=await c({type:n.REQUEST_ACCESS})}catch(L){console.error(L)}const{publicKey:D,connectionKey:T,error:k}=K;if(k)throw k;return{publicKey:D,connectionKey:T}})();return(K=>{var D;(D=window==null?void 0:window.sessionStorage)===null||D===void 0||D.setItem(o,K)})(z),M},p=async M=>{if(!g)return"";const z=((K=window==null?void 0:window.sessionStorage)===null||K===void 0?void 0:K.getItem(o))||"";var K;return await(async(D,T)=>{let k={signedTransaction:"",error:""};try{k=await c({transactionXdr:D,connectionKey:T,type:n.SIGN_TRANSACTION})}catch(F){throw console.error(F),F}const{signedTransaction:L,error:$}=k;if($)throw $;return L})(M,z)},y=async()=>!!g&&(window.lobstrSignerExtension?window.lobstrSignerExtension:await(async()=>{let M={isConnected:!1};try{M=await c({type:n.REQUEST_CONNECTION_STATUS})}catch(z){console.error(z)}return M.isConnected})()),g=typeof window<"u",v={getPublicKey:d,signTransaction:p,isConnected:y};return s})())})(Zv);var ml=Zv.exports;const d7="lobstr";class h7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=d7,this.productName="LOBSTR",this.productUrl="https://lobstr.co",this.productIcon="https://stellar.creit.tech/wallet-icons/lobstr.png"}async isAvailable(){return ml.isConnected()}async getAddress(){return(async()=>{if(!await ml.isConnected())throw new Error("Lobstr is not connected")})().then(()=>ml.getPublicKey()).then(r=>({address:r})).catch(r=>{throw un(r)})}async signTransaction(t,r){return(async()=>{if(!await ml.isConnected())throw new Error("Lobstr is not connected");r!=null&&r.address&&console.warn("Lobstr doesn't allow specifying what public key should sign the transaction, we skip the value"),r!=null&&r.networkPassphrase&&console.warn("Lobstr doesn't allow specifying the network that should be used, we skip the value")})().then(()=>ml.signTransaction(t)).then(a=>({signedTxXdr:a})).catch(a=>{throw un(a)})}async signAuthEntry(){throw{code:-3,message:'Lobstr does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Lobstr does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Lobstr does not support the "getNetwork" function'}}}const p7="rabet";class b7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=p7,this.productName="Rabet",this.productUrl="https://rabet.io/",this.productIcon="https://stellar.creit.tech/wallet-icons/rabet.png"}isAvailable(){return new Promise(t=>{setTimeout(()=>{t(typeof window<"u"&&!!window.rabet)},100)})}async getAddress(){return(async()=>{if(!await this.isAvailable())throw new Error("Rabet is not installed")})().then(()=>window.rabet.connect()).then(({publicKey:r})=>({address:r})).catch(r=>{throw un(r)})}async signTransaction(t,r){const n=async()=>{if(!await this.isAvailable())throw new Error("Rabet is not installed");if(r!=null&&r.address&&r.networkPassphrase!==bs.PUBLIC&&r.networkPassphrase!==bs.TESTNET)throw new Error(`Rabet doesn't support the network: ${r.networkPassphrase}`);r!=null&&r.address&&console.warn("Rabet doesn't allow specifying the network that should be used, we skip the value")},a=async()=>window.rabet.sign(t,(r==null?void 0:r.networkPassphrase)===bs.PUBLIC?"mainnet":"testnet");return n().then(a).then(i=>({signedTxXdr:i==null?void 0:i.xdr})).catch(i=>{throw un(i)})}async signAuthEntry(){throw{code:-3,message:'Rabet does not support the "signAuthEntry" function'}}async signMessage(){throw{code:-3,message:'Rabet does not support the "signMessage" function'}}async getNetwork(){throw{code:-3,message:'Rabet does not support the "getNetwork" function'}}}function m7(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Qv={exports:{}};const x7={},y7=Object.freeze(Object.defineProperty({__proto__:null,default:x7},Symbol.toStringTag,{value:"Module"})),hc=Yx(y7);(function(e){(function(t){var r=function(A){var U,O=new Float64Array(16);if(A)for(U=0;U>24&255,A[U+1]=O>>16&255,A[U+2]=O>>8&255,A[U+3]=O&255,A[U+4]=b>>24&255,A[U+5]=b>>16&255,A[U+6]=b>>8&255,A[U+7]=b&255}function z(A,U,O,b,I){var Z,te=0;for(Z=0;Z>>8)-1}function K(A,U,O,b){return z(A,U,O,b,16)}function D(A,U,O,b){return z(A,U,O,b,32)}function T(A,U,O,b){for(var I=b[0]&255|(b[1]&255)<<8|(b[2]&255)<<16|(b[3]&255)<<24,Z=O[0]&255|(O[1]&255)<<8|(O[2]&255)<<16|(O[3]&255)<<24,te=O[4]&255|(O[5]&255)<<8|(O[6]&255)<<16|(O[7]&255)<<24,de=O[8]&255|(O[9]&255)<<8|(O[10]&255)<<16|(O[11]&255)<<24,we=O[12]&255|(O[13]&255)<<8|(O[14]&255)<<16|(O[15]&255)<<24,ke=b[4]&255|(b[5]&255)<<8|(b[6]&255)<<16|(b[7]&255)<<24,Ne=U[0]&255|(U[1]&255)<<8|(U[2]&255)<<16|(U[3]&255)<<24,ft=U[4]&255|(U[5]&255)<<8|(U[6]&255)<<16|(U[7]&255)<<24,Be=U[8]&255|(U[9]&255)<<8|(U[10]&255)<<16|(U[11]&255)<<24,Fe=U[12]&255|(U[13]&255)<<8|(U[14]&255)<<16|(U[15]&255)<<24,Ke=b[8]&255|(b[9]&255)<<8|(b[10]&255)<<16|(b[11]&255)<<24,Je=O[16]&255|(O[17]&255)<<8|(O[18]&255)<<16|(O[19]&255)<<24,Qe=O[20]&255|(O[21]&255)<<8|(O[22]&255)<<16|(O[23]&255)<<24,Pe=O[24]&255|(O[25]&255)<<8|(O[26]&255)<<16|(O[27]&255)<<24,Ye=O[28]&255|(O[29]&255)<<8|(O[30]&255)<<16|(O[31]&255)<<24,Ge=b[12]&255|(b[13]&255)<<8|(b[14]&255)<<16|(b[15]&255)<<24,Oe=I,De=Z,Me=te,Re=de,Ue=we,Ae=ke,se=Ne,oe=ft,_e=Be,ge=Fe,ve=Ke,Ee=Je,qe=Qe,nt=Pe,st=Ye,at=Ge,P,ut=0;ut<20;ut+=2)P=Oe+qe|0,Ue^=P<<7|P>>>25,P=Ue+Oe|0,_e^=P<<9|P>>>23,P=_e+Ue|0,qe^=P<<13|P>>>19,P=qe+_e|0,Oe^=P<<18|P>>>14,P=Ae+De|0,ge^=P<<7|P>>>25,P=ge+Ae|0,nt^=P<<9|P>>>23,P=nt+ge|0,De^=P<<13|P>>>19,P=De+nt|0,Ae^=P<<18|P>>>14,P=ve+se|0,st^=P<<7|P>>>25,P=st+ve|0,Me^=P<<9|P>>>23,P=Me+st|0,se^=P<<13|P>>>19,P=se+Me|0,ve^=P<<18|P>>>14,P=at+Ee|0,Re^=P<<7|P>>>25,P=Re+at|0,oe^=P<<9|P>>>23,P=oe+Re|0,Ee^=P<<13|P>>>19,P=Ee+oe|0,at^=P<<18|P>>>14,P=Oe+Re|0,De^=P<<7|P>>>25,P=De+Oe|0,Me^=P<<9|P>>>23,P=Me+De|0,Re^=P<<13|P>>>19,P=Re+Me|0,Oe^=P<<18|P>>>14,P=Ae+Ue|0,se^=P<<7|P>>>25,P=se+Ae|0,oe^=P<<9|P>>>23,P=oe+se|0,Ue^=P<<13|P>>>19,P=Ue+oe|0,Ae^=P<<18|P>>>14,P=ve+ge|0,Ee^=P<<7|P>>>25,P=Ee+ve|0,_e^=P<<9|P>>>23,P=_e+Ee|0,ge^=P<<13|P>>>19,P=ge+_e|0,ve^=P<<18|P>>>14,P=at+st|0,qe^=P<<7|P>>>25,P=qe+at|0,nt^=P<<9|P>>>23,P=nt+qe|0,st^=P<<13|P>>>19,P=st+nt|0,at^=P<<18|P>>>14;Oe=Oe+I|0,De=De+Z|0,Me=Me+te|0,Re=Re+de|0,Ue=Ue+we|0,Ae=Ae+ke|0,se=se+Ne|0,oe=oe+ft|0,_e=_e+Be|0,ge=ge+Fe|0,ve=ve+Ke|0,Ee=Ee+Je|0,qe=qe+Qe|0,nt=nt+Pe|0,st=st+Ye|0,at=at+Ge|0,A[0]=Oe>>>0&255,A[1]=Oe>>>8&255,A[2]=Oe>>>16&255,A[3]=Oe>>>24&255,A[4]=De>>>0&255,A[5]=De>>>8&255,A[6]=De>>>16&255,A[7]=De>>>24&255,A[8]=Me>>>0&255,A[9]=Me>>>8&255,A[10]=Me>>>16&255,A[11]=Me>>>24&255,A[12]=Re>>>0&255,A[13]=Re>>>8&255,A[14]=Re>>>16&255,A[15]=Re>>>24&255,A[16]=Ue>>>0&255,A[17]=Ue>>>8&255,A[18]=Ue>>>16&255,A[19]=Ue>>>24&255,A[20]=Ae>>>0&255,A[21]=Ae>>>8&255,A[22]=Ae>>>16&255,A[23]=Ae>>>24&255,A[24]=se>>>0&255,A[25]=se>>>8&255,A[26]=se>>>16&255,A[27]=se>>>24&255,A[28]=oe>>>0&255,A[29]=oe>>>8&255,A[30]=oe>>>16&255,A[31]=oe>>>24&255,A[32]=_e>>>0&255,A[33]=_e>>>8&255,A[34]=_e>>>16&255,A[35]=_e>>>24&255,A[36]=ge>>>0&255,A[37]=ge>>>8&255,A[38]=ge>>>16&255,A[39]=ge>>>24&255,A[40]=ve>>>0&255,A[41]=ve>>>8&255,A[42]=ve>>>16&255,A[43]=ve>>>24&255,A[44]=Ee>>>0&255,A[45]=Ee>>>8&255,A[46]=Ee>>>16&255,A[47]=Ee>>>24&255,A[48]=qe>>>0&255,A[49]=qe>>>8&255,A[50]=qe>>>16&255,A[51]=qe>>>24&255,A[52]=nt>>>0&255,A[53]=nt>>>8&255,A[54]=nt>>>16&255,A[55]=nt>>>24&255,A[56]=st>>>0&255,A[57]=st>>>8&255,A[58]=st>>>16&255,A[59]=st>>>24&255,A[60]=at>>>0&255,A[61]=at>>>8&255,A[62]=at>>>16&255,A[63]=at>>>24&255}function k(A,U,O,b){for(var I=b[0]&255|(b[1]&255)<<8|(b[2]&255)<<16|(b[3]&255)<<24,Z=O[0]&255|(O[1]&255)<<8|(O[2]&255)<<16|(O[3]&255)<<24,te=O[4]&255|(O[5]&255)<<8|(O[6]&255)<<16|(O[7]&255)<<24,de=O[8]&255|(O[9]&255)<<8|(O[10]&255)<<16|(O[11]&255)<<24,we=O[12]&255|(O[13]&255)<<8|(O[14]&255)<<16|(O[15]&255)<<24,ke=b[4]&255|(b[5]&255)<<8|(b[6]&255)<<16|(b[7]&255)<<24,Ne=U[0]&255|(U[1]&255)<<8|(U[2]&255)<<16|(U[3]&255)<<24,ft=U[4]&255|(U[5]&255)<<8|(U[6]&255)<<16|(U[7]&255)<<24,Be=U[8]&255|(U[9]&255)<<8|(U[10]&255)<<16|(U[11]&255)<<24,Fe=U[12]&255|(U[13]&255)<<8|(U[14]&255)<<16|(U[15]&255)<<24,Ke=b[8]&255|(b[9]&255)<<8|(b[10]&255)<<16|(b[11]&255)<<24,Je=O[16]&255|(O[17]&255)<<8|(O[18]&255)<<16|(O[19]&255)<<24,Qe=O[20]&255|(O[21]&255)<<8|(O[22]&255)<<16|(O[23]&255)<<24,Pe=O[24]&255|(O[25]&255)<<8|(O[26]&255)<<16|(O[27]&255)<<24,Ye=O[28]&255|(O[29]&255)<<8|(O[30]&255)<<16|(O[31]&255)<<24,Ge=b[12]&255|(b[13]&255)<<8|(b[14]&255)<<16|(b[15]&255)<<24,Oe=I,De=Z,Me=te,Re=de,Ue=we,Ae=ke,se=Ne,oe=ft,_e=Be,ge=Fe,ve=Ke,Ee=Je,qe=Qe,nt=Pe,st=Ye,at=Ge,P,ut=0;ut<20;ut+=2)P=Oe+qe|0,Ue^=P<<7|P>>>25,P=Ue+Oe|0,_e^=P<<9|P>>>23,P=_e+Ue|0,qe^=P<<13|P>>>19,P=qe+_e|0,Oe^=P<<18|P>>>14,P=Ae+De|0,ge^=P<<7|P>>>25,P=ge+Ae|0,nt^=P<<9|P>>>23,P=nt+ge|0,De^=P<<13|P>>>19,P=De+nt|0,Ae^=P<<18|P>>>14,P=ve+se|0,st^=P<<7|P>>>25,P=st+ve|0,Me^=P<<9|P>>>23,P=Me+st|0,se^=P<<13|P>>>19,P=se+Me|0,ve^=P<<18|P>>>14,P=at+Ee|0,Re^=P<<7|P>>>25,P=Re+at|0,oe^=P<<9|P>>>23,P=oe+Re|0,Ee^=P<<13|P>>>19,P=Ee+oe|0,at^=P<<18|P>>>14,P=Oe+Re|0,De^=P<<7|P>>>25,P=De+Oe|0,Me^=P<<9|P>>>23,P=Me+De|0,Re^=P<<13|P>>>19,P=Re+Me|0,Oe^=P<<18|P>>>14,P=Ae+Ue|0,se^=P<<7|P>>>25,P=se+Ae|0,oe^=P<<9|P>>>23,P=oe+se|0,Ue^=P<<13|P>>>19,P=Ue+oe|0,Ae^=P<<18|P>>>14,P=ve+ge|0,Ee^=P<<7|P>>>25,P=Ee+ve|0,_e^=P<<9|P>>>23,P=_e+Ee|0,ge^=P<<13|P>>>19,P=ge+_e|0,ve^=P<<18|P>>>14,P=at+st|0,qe^=P<<7|P>>>25,P=qe+at|0,nt^=P<<9|P>>>23,P=nt+qe|0,st^=P<<13|P>>>19,P=st+nt|0,at^=P<<18|P>>>14;A[0]=Oe>>>0&255,A[1]=Oe>>>8&255,A[2]=Oe>>>16&255,A[3]=Oe>>>24&255,A[4]=Ae>>>0&255,A[5]=Ae>>>8&255,A[6]=Ae>>>16&255,A[7]=Ae>>>24&255,A[8]=ve>>>0&255,A[9]=ve>>>8&255,A[10]=ve>>>16&255,A[11]=ve>>>24&255,A[12]=at>>>0&255,A[13]=at>>>8&255,A[14]=at>>>16&255,A[15]=at>>>24&255,A[16]=se>>>0&255,A[17]=se>>>8&255,A[18]=se>>>16&255,A[19]=se>>>24&255,A[20]=oe>>>0&255,A[21]=oe>>>8&255,A[22]=oe>>>16&255,A[23]=oe>>>24&255,A[24]=_e>>>0&255,A[25]=_e>>>8&255,A[26]=_e>>>16&255,A[27]=_e>>>24&255,A[28]=ge>>>0&255,A[29]=ge>>>8&255,A[30]=ge>>>16&255,A[31]=ge>>>24&255}function L(A,U,O,b){T(A,U,O,b)}function $(A,U,O,b){k(A,U,O,b)}var F=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function V(A,U,O,b,I,Z,te){var de=new Uint8Array(16),we=new Uint8Array(64),ke,Ne;for(Ne=0;Ne<16;Ne++)de[Ne]=0;for(Ne=0;Ne<8;Ne++)de[Ne]=Z[Ne];for(;I>=64;){for(L(we,de,te,F),Ne=0;Ne<64;Ne++)A[U+Ne]=O[b+Ne]^we[Ne];for(ke=1,Ne=8;Ne<16;Ne++)ke=ke+(de[Ne]&255)|0,de[Ne]=ke&255,ke>>>=8;I-=64,U+=64,b+=64}if(I>0)for(L(we,de,te,F),Ne=0;Ne=64;){for(L(te,Z,I,F),we=0;we<64;we++)A[U+we]=te[we];for(de=1,we=8;we<16;we++)de=de+(Z[we]&255)|0,Z[we]=de&255,de>>>=8;O-=64,U+=64}if(O>0)for(L(te,Z,I,F),we=0;we>>13|O<<3)&8191,b=A[4]&255|(A[5]&255)<<8,this.r[2]=(O>>>10|b<<6)&7939,I=A[6]&255|(A[7]&255)<<8,this.r[3]=(b>>>7|I<<9)&8191,Z=A[8]&255|(A[9]&255)<<8,this.r[4]=(I>>>4|Z<<12)&255,this.r[5]=Z>>>1&8190,te=A[10]&255|(A[11]&255)<<8,this.r[6]=(Z>>>14|te<<2)&8191,de=A[12]&255|(A[13]&255)<<8,this.r[7]=(te>>>11|de<<5)&8065,we=A[14]&255|(A[15]&255)<<8,this.r[8]=(de>>>8|we<<8)&8191,this.r[9]=we>>>5&127,this.pad[0]=A[16]&255|(A[17]&255)<<8,this.pad[1]=A[18]&255|(A[19]&255)<<8,this.pad[2]=A[20]&255|(A[21]&255)<<8,this.pad[3]=A[22]&255|(A[23]&255)<<8,this.pad[4]=A[24]&255|(A[25]&255)<<8,this.pad[5]=A[26]&255|(A[27]&255)<<8,this.pad[6]=A[28]&255|(A[29]&255)<<8,this.pad[7]=A[30]&255|(A[31]&255)<<8};x.prototype.blocks=function(A,U,O){for(var b=this.fin?0:2048,I,Z,te,de,we,ke,Ne,ft,Be,Fe,Ke,Je,Qe,Pe,Ye,Ge,Oe,De,Me,Re=this.h[0],Ue=this.h[1],Ae=this.h[2],se=this.h[3],oe=this.h[4],_e=this.h[5],ge=this.h[6],ve=this.h[7],Ee=this.h[8],qe=this.h[9],nt=this.r[0],st=this.r[1],at=this.r[2],P=this.r[3],ut=this.r[4],At=this.r[5],Nt=this.r[6],ot=this.r[7],_t=this.r[8],St=this.r[9];O>=16;)I=A[U+0]&255|(A[U+1]&255)<<8,Re+=I&8191,Z=A[U+2]&255|(A[U+3]&255)<<8,Ue+=(I>>>13|Z<<3)&8191,te=A[U+4]&255|(A[U+5]&255)<<8,Ae+=(Z>>>10|te<<6)&8191,de=A[U+6]&255|(A[U+7]&255)<<8,se+=(te>>>7|de<<9)&8191,we=A[U+8]&255|(A[U+9]&255)<<8,oe+=(de>>>4|we<<12)&8191,_e+=we>>>1&8191,ke=A[U+10]&255|(A[U+11]&255)<<8,ge+=(we>>>14|ke<<2)&8191,Ne=A[U+12]&255|(A[U+13]&255)<<8,ve+=(ke>>>11|Ne<<5)&8191,ft=A[U+14]&255|(A[U+15]&255)<<8,Ee+=(Ne>>>8|ft<<8)&8191,qe+=ft>>>5|b,Be=0,Fe=Be,Fe+=Re*nt,Fe+=Ue*(5*St),Fe+=Ae*(5*_t),Fe+=se*(5*ot),Fe+=oe*(5*Nt),Be=Fe>>>13,Fe&=8191,Fe+=_e*(5*At),Fe+=ge*(5*ut),Fe+=ve*(5*P),Fe+=Ee*(5*at),Fe+=qe*(5*st),Be+=Fe>>>13,Fe&=8191,Ke=Be,Ke+=Re*st,Ke+=Ue*nt,Ke+=Ae*(5*St),Ke+=se*(5*_t),Ke+=oe*(5*ot),Be=Ke>>>13,Ke&=8191,Ke+=_e*(5*Nt),Ke+=ge*(5*At),Ke+=ve*(5*ut),Ke+=Ee*(5*P),Ke+=qe*(5*at),Be+=Ke>>>13,Ke&=8191,Je=Be,Je+=Re*at,Je+=Ue*st,Je+=Ae*nt,Je+=se*(5*St),Je+=oe*(5*_t),Be=Je>>>13,Je&=8191,Je+=_e*(5*ot),Je+=ge*(5*Nt),Je+=ve*(5*At),Je+=Ee*(5*ut),Je+=qe*(5*P),Be+=Je>>>13,Je&=8191,Qe=Be,Qe+=Re*P,Qe+=Ue*at,Qe+=Ae*st,Qe+=se*nt,Qe+=oe*(5*St),Be=Qe>>>13,Qe&=8191,Qe+=_e*(5*_t),Qe+=ge*(5*ot),Qe+=ve*(5*Nt),Qe+=Ee*(5*At),Qe+=qe*(5*ut),Be+=Qe>>>13,Qe&=8191,Pe=Be,Pe+=Re*ut,Pe+=Ue*P,Pe+=Ae*at,Pe+=se*st,Pe+=oe*nt,Be=Pe>>>13,Pe&=8191,Pe+=_e*(5*St),Pe+=ge*(5*_t),Pe+=ve*(5*ot),Pe+=Ee*(5*Nt),Pe+=qe*(5*At),Be+=Pe>>>13,Pe&=8191,Ye=Be,Ye+=Re*At,Ye+=Ue*ut,Ye+=Ae*P,Ye+=se*at,Ye+=oe*st,Be=Ye>>>13,Ye&=8191,Ye+=_e*nt,Ye+=ge*(5*St),Ye+=ve*(5*_t),Ye+=Ee*(5*ot),Ye+=qe*(5*Nt),Be+=Ye>>>13,Ye&=8191,Ge=Be,Ge+=Re*Nt,Ge+=Ue*At,Ge+=Ae*ut,Ge+=se*P,Ge+=oe*at,Be=Ge>>>13,Ge&=8191,Ge+=_e*st,Ge+=ge*nt,Ge+=ve*(5*St),Ge+=Ee*(5*_t),Ge+=qe*(5*ot),Be+=Ge>>>13,Ge&=8191,Oe=Be,Oe+=Re*ot,Oe+=Ue*Nt,Oe+=Ae*At,Oe+=se*ut,Oe+=oe*P,Be=Oe>>>13,Oe&=8191,Oe+=_e*at,Oe+=ge*st,Oe+=ve*nt,Oe+=Ee*(5*St),Oe+=qe*(5*_t),Be+=Oe>>>13,Oe&=8191,De=Be,De+=Re*_t,De+=Ue*ot,De+=Ae*Nt,De+=se*At,De+=oe*ut,Be=De>>>13,De&=8191,De+=_e*P,De+=ge*at,De+=ve*st,De+=Ee*nt,De+=qe*(5*St),Be+=De>>>13,De&=8191,Me=Be,Me+=Re*St,Me+=Ue*_t,Me+=Ae*ot,Me+=se*Nt,Me+=oe*At,Be=Me>>>13,Me&=8191,Me+=_e*ut,Me+=ge*P,Me+=ve*at,Me+=Ee*st,Me+=qe*nt,Be+=Me>>>13,Me&=8191,Be=(Be<<2)+Be|0,Be=Be+Fe|0,Fe=Be&8191,Be=Be>>>13,Ke+=Be,Re=Fe,Ue=Ke,Ae=Je,se=Qe,oe=Pe,_e=Ye,ge=Ge,ve=Oe,Ee=De,qe=Me,U+=16,O-=16;this.h[0]=Re,this.h[1]=Ue,this.h[2]=Ae,this.h[3]=se,this.h[4]=oe,this.h[5]=_e,this.h[6]=ge,this.h[7]=ve,this.h[8]=Ee,this.h[9]=qe},x.prototype.finish=function(A,U){var O=new Uint16Array(10),b,I,Z,te;if(this.leftover){for(te=this.leftover,this.buffer[te++]=1;te<16;te++)this.buffer[te]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(b=this.h[1]>>>13,this.h[1]&=8191,te=2;te<10;te++)this.h[te]+=b,b=this.h[te]>>>13,this.h[te]&=8191;for(this.h[0]+=b*5,b=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=b,b=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=b,O[0]=this.h[0]+5,b=O[0]>>>13,O[0]&=8191,te=1;te<10;te++)O[te]=this.h[te]+b,b=O[te]>>>13,O[te]&=8191;for(O[9]-=8192,I=(b^1)-1,te=0;te<10;te++)O[te]&=I;for(I=~I,te=0;te<10;te++)this.h[te]=this.h[te]&I|O[te];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,Z=this.h[0]+this.pad[0],this.h[0]=Z&65535,te=1;te<8;te++)Z=(this.h[te]+this.pad[te]|0)+(Z>>>16)|0,this.h[te]=Z&65535;A[U+0]=this.h[0]>>>0&255,A[U+1]=this.h[0]>>>8&255,A[U+2]=this.h[1]>>>0&255,A[U+3]=this.h[1]>>>8&255,A[U+4]=this.h[2]>>>0&255,A[U+5]=this.h[2]>>>8&255,A[U+6]=this.h[3]>>>0&255,A[U+7]=this.h[3]>>>8&255,A[U+8]=this.h[4]>>>0&255,A[U+9]=this.h[4]>>>8&255,A[U+10]=this.h[5]>>>0&255,A[U+11]=this.h[5]>>>8&255,A[U+12]=this.h[6]>>>0&255,A[U+13]=this.h[6]>>>8&255,A[U+14]=this.h[7]>>>0&255,A[U+15]=this.h[7]>>>8&255},x.prototype.update=function(A,U,O){var b,I;if(this.leftover){for(I=16-this.leftover,I>O&&(I=O),b=0;b=16&&(I=O-O%16,this.blocks(A,U,I),U+=I,O-=I),O){for(b=0;b>16&1),Z[O-1]&=65535;Z[15]=te[15]-32767-(Z[14]>>16&1),I=Z[15]>>16&1,Z[14]&=65535,R(te,Z,1-I)}for(O=0;O<16;O++)A[2*O]=te[O]&255,A[2*O+1]=te[O]>>8}function h(A,U){var O=new Uint8Array(32),b=new Uint8Array(32);return N(O,A),N(b,U),D(O,0,b,0)}function C(A){var U=new Uint8Array(32);return N(U,A),U[0]&1}function ae(A,U){var O;for(O=0;O<16;O++)A[O]=U[2*O]+(U[2*O+1]<<8);A[15]&=32767}function he(A,U,O){for(var b=0;b<16;b++)A[b]=U[b]+O[b]}function q(A,U,O){for(var b=0;b<16;b++)A[b]=U[b]-O[b]}function G(A,U,O){var b,I,Z=0,te=0,de=0,we=0,ke=0,Ne=0,ft=0,Be=0,Fe=0,Ke=0,Je=0,Qe=0,Pe=0,Ye=0,Ge=0,Oe=0,De=0,Me=0,Re=0,Ue=0,Ae=0,se=0,oe=0,_e=0,ge=0,ve=0,Ee=0,qe=0,nt=0,st=0,at=0,P=O[0],ut=O[1],At=O[2],Nt=O[3],ot=O[4],_t=O[5],St=O[6],cr=O[7],Ot=O[8],nr=O[9],ar=O[10],ir=O[11],gr=O[12],Hr=O[13],qr=O[14],$r=O[15];b=U[0],Z+=b*P,te+=b*ut,de+=b*At,we+=b*Nt,ke+=b*ot,Ne+=b*_t,ft+=b*St,Be+=b*cr,Fe+=b*Ot,Ke+=b*nr,Je+=b*ar,Qe+=b*ir,Pe+=b*gr,Ye+=b*Hr,Ge+=b*qr,Oe+=b*$r,b=U[1],te+=b*P,de+=b*ut,we+=b*At,ke+=b*Nt,Ne+=b*ot,ft+=b*_t,Be+=b*St,Fe+=b*cr,Ke+=b*Ot,Je+=b*nr,Qe+=b*ar,Pe+=b*ir,Ye+=b*gr,Ge+=b*Hr,Oe+=b*qr,De+=b*$r,b=U[2],de+=b*P,we+=b*ut,ke+=b*At,Ne+=b*Nt,ft+=b*ot,Be+=b*_t,Fe+=b*St,Ke+=b*cr,Je+=b*Ot,Qe+=b*nr,Pe+=b*ar,Ye+=b*ir,Ge+=b*gr,Oe+=b*Hr,De+=b*qr,Me+=b*$r,b=U[3],we+=b*P,ke+=b*ut,Ne+=b*At,ft+=b*Nt,Be+=b*ot,Fe+=b*_t,Ke+=b*St,Je+=b*cr,Qe+=b*Ot,Pe+=b*nr,Ye+=b*ar,Ge+=b*ir,Oe+=b*gr,De+=b*Hr,Me+=b*qr,Re+=b*$r,b=U[4],ke+=b*P,Ne+=b*ut,ft+=b*At,Be+=b*Nt,Fe+=b*ot,Ke+=b*_t,Je+=b*St,Qe+=b*cr,Pe+=b*Ot,Ye+=b*nr,Ge+=b*ar,Oe+=b*ir,De+=b*gr,Me+=b*Hr,Re+=b*qr,Ue+=b*$r,b=U[5],Ne+=b*P,ft+=b*ut,Be+=b*At,Fe+=b*Nt,Ke+=b*ot,Je+=b*_t,Qe+=b*St,Pe+=b*cr,Ye+=b*Ot,Ge+=b*nr,Oe+=b*ar,De+=b*ir,Me+=b*gr,Re+=b*Hr,Ue+=b*qr,Ae+=b*$r,b=U[6],ft+=b*P,Be+=b*ut,Fe+=b*At,Ke+=b*Nt,Je+=b*ot,Qe+=b*_t,Pe+=b*St,Ye+=b*cr,Ge+=b*Ot,Oe+=b*nr,De+=b*ar,Me+=b*ir,Re+=b*gr,Ue+=b*Hr,Ae+=b*qr,se+=b*$r,b=U[7],Be+=b*P,Fe+=b*ut,Ke+=b*At,Je+=b*Nt,Qe+=b*ot,Pe+=b*_t,Ye+=b*St,Ge+=b*cr,Oe+=b*Ot,De+=b*nr,Me+=b*ar,Re+=b*ir,Ue+=b*gr,Ae+=b*Hr,se+=b*qr,oe+=b*$r,b=U[8],Fe+=b*P,Ke+=b*ut,Je+=b*At,Qe+=b*Nt,Pe+=b*ot,Ye+=b*_t,Ge+=b*St,Oe+=b*cr,De+=b*Ot,Me+=b*nr,Re+=b*ar,Ue+=b*ir,Ae+=b*gr,se+=b*Hr,oe+=b*qr,_e+=b*$r,b=U[9],Ke+=b*P,Je+=b*ut,Qe+=b*At,Pe+=b*Nt,Ye+=b*ot,Ge+=b*_t,Oe+=b*St,De+=b*cr,Me+=b*Ot,Re+=b*nr,Ue+=b*ar,Ae+=b*ir,se+=b*gr,oe+=b*Hr,_e+=b*qr,ge+=b*$r,b=U[10],Je+=b*P,Qe+=b*ut,Pe+=b*At,Ye+=b*Nt,Ge+=b*ot,Oe+=b*_t,De+=b*St,Me+=b*cr,Re+=b*Ot,Ue+=b*nr,Ae+=b*ar,se+=b*ir,oe+=b*gr,_e+=b*Hr,ge+=b*qr,ve+=b*$r,b=U[11],Qe+=b*P,Pe+=b*ut,Ye+=b*At,Ge+=b*Nt,Oe+=b*ot,De+=b*_t,Me+=b*St,Re+=b*cr,Ue+=b*Ot,Ae+=b*nr,se+=b*ar,oe+=b*ir,_e+=b*gr,ge+=b*Hr,ve+=b*qr,Ee+=b*$r,b=U[12],Pe+=b*P,Ye+=b*ut,Ge+=b*At,Oe+=b*Nt,De+=b*ot,Me+=b*_t,Re+=b*St,Ue+=b*cr,Ae+=b*Ot,se+=b*nr,oe+=b*ar,_e+=b*ir,ge+=b*gr,ve+=b*Hr,Ee+=b*qr,qe+=b*$r,b=U[13],Ye+=b*P,Ge+=b*ut,Oe+=b*At,De+=b*Nt,Me+=b*ot,Re+=b*_t,Ue+=b*St,Ae+=b*cr,se+=b*Ot,oe+=b*nr,_e+=b*ar,ge+=b*ir,ve+=b*gr,Ee+=b*Hr,qe+=b*qr,nt+=b*$r,b=U[14],Ge+=b*P,Oe+=b*ut,De+=b*At,Me+=b*Nt,Re+=b*ot,Ue+=b*_t,Ae+=b*St,se+=b*cr,oe+=b*Ot,_e+=b*nr,ge+=b*ar,ve+=b*ir,Ee+=b*gr,qe+=b*Hr,nt+=b*qr,st+=b*$r,b=U[15],Oe+=b*P,De+=b*ut,Me+=b*At,Re+=b*Nt,Ue+=b*ot,Ae+=b*_t,se+=b*St,oe+=b*cr,_e+=b*Ot,ge+=b*nr,ve+=b*ar,Ee+=b*ir,qe+=b*gr,nt+=b*Hr,st+=b*qr,at+=b*$r,Z+=38*De,te+=38*Me,de+=38*Re,we+=38*Ue,ke+=38*Ae,Ne+=38*se,ft+=38*oe,Be+=38*_e,Fe+=38*ge,Ke+=38*ve,Je+=38*Ee,Qe+=38*qe,Pe+=38*nt,Ye+=38*st,Ge+=38*at,I=1,b=Z+I+65535,I=Math.floor(b/65536),Z=b-I*65536,b=te+I+65535,I=Math.floor(b/65536),te=b-I*65536,b=de+I+65535,I=Math.floor(b/65536),de=b-I*65536,b=we+I+65535,I=Math.floor(b/65536),we=b-I*65536,b=ke+I+65535,I=Math.floor(b/65536),ke=b-I*65536,b=Ne+I+65535,I=Math.floor(b/65536),Ne=b-I*65536,b=ft+I+65535,I=Math.floor(b/65536),ft=b-I*65536,b=Be+I+65535,I=Math.floor(b/65536),Be=b-I*65536,b=Fe+I+65535,I=Math.floor(b/65536),Fe=b-I*65536,b=Ke+I+65535,I=Math.floor(b/65536),Ke=b-I*65536,b=Je+I+65535,I=Math.floor(b/65536),Je=b-I*65536,b=Qe+I+65535,I=Math.floor(b/65536),Qe=b-I*65536,b=Pe+I+65535,I=Math.floor(b/65536),Pe=b-I*65536,b=Ye+I+65535,I=Math.floor(b/65536),Ye=b-I*65536,b=Ge+I+65535,I=Math.floor(b/65536),Ge=b-I*65536,b=Oe+I+65535,I=Math.floor(b/65536),Oe=b-I*65536,Z+=I-1+37*(I-1),I=1,b=Z+I+65535,I=Math.floor(b/65536),Z=b-I*65536,b=te+I+65535,I=Math.floor(b/65536),te=b-I*65536,b=de+I+65535,I=Math.floor(b/65536),de=b-I*65536,b=we+I+65535,I=Math.floor(b/65536),we=b-I*65536,b=ke+I+65535,I=Math.floor(b/65536),ke=b-I*65536,b=Ne+I+65535,I=Math.floor(b/65536),Ne=b-I*65536,b=ft+I+65535,I=Math.floor(b/65536),ft=b-I*65536,b=Be+I+65535,I=Math.floor(b/65536),Be=b-I*65536,b=Fe+I+65535,I=Math.floor(b/65536),Fe=b-I*65536,b=Ke+I+65535,I=Math.floor(b/65536),Ke=b-I*65536,b=Je+I+65535,I=Math.floor(b/65536),Je=b-I*65536,b=Qe+I+65535,I=Math.floor(b/65536),Qe=b-I*65536,b=Pe+I+65535,I=Math.floor(b/65536),Pe=b-I*65536,b=Ye+I+65535,I=Math.floor(b/65536),Ye=b-I*65536,b=Ge+I+65535,I=Math.floor(b/65536),Ge=b-I*65536,b=Oe+I+65535,I=Math.floor(b/65536),Oe=b-I*65536,Z+=I-1+37*(I-1),A[0]=Z,A[1]=te,A[2]=de,A[3]=we,A[4]=ke,A[5]=Ne,A[6]=ft,A[7]=Be,A[8]=Fe,A[9]=Ke,A[10]=Je,A[11]=Qe,A[12]=Pe,A[13]=Ye,A[14]=Ge,A[15]=Oe}function W(A,U){G(A,U,U)}function be(A,U){var O=r(),b;for(b=0;b<16;b++)O[b]=U[b];for(b=253;b>=0;b--)W(O,O),b!==2&&b!==4&&G(O,O,U);for(b=0;b<16;b++)A[b]=O[b]}function ue(A,U){var O=r(),b;for(b=0;b<16;b++)O[b]=U[b];for(b=250;b>=0;b--)W(O,O),b!==1&&G(O,O,U);for(b=0;b<16;b++)A[b]=O[b]}function Q(A,U,O){var b=new Uint8Array(32),I=new Float64Array(80),Z,te,de=r(),we=r(),ke=r(),Ne=r(),ft=r(),Be=r();for(te=0;te<31;te++)b[te]=U[te];for(b[31]=U[31]&127|64,b[0]&=248,ae(I,O),te=0;te<16;te++)we[te]=I[te],Ne[te]=de[te]=ke[te]=0;for(de[0]=Ne[0]=1,te=254;te>=0;--te)Z=b[te>>>3]>>>(te&7)&1,R(de,we,Z),R(ke,Ne,Z),he(ft,de,ke),q(de,de,ke),he(ke,we,Ne),q(we,we,Ne),W(Ne,ft),W(Be,de),G(de,ke,de),G(ke,we,ft),he(ft,de,ke),q(de,de,ke),W(we,de),q(ke,Ne,Be),G(de,ke,c),he(de,de,Ne),G(ke,ke,de),G(de,Ne,Be),G(Ne,we,I),W(we,ft),R(de,we,Z),R(ke,Ne,Z);for(te=0;te<16;te++)I[te+16]=de[te],I[te+32]=ke[te],I[te+48]=we[te],I[te+64]=Ne[te];var Fe=I.subarray(32),Ke=I.subarray(16);return be(Fe,Fe),G(Ke,Ke,Fe),N(A,Ke),0}function le(A,U){return Q(A,U,i)}function Se(A,U){return n(U,32),le(A,U)}function fe(A,U,O){var b=new Uint8Array(32);return Q(b,O,U),$(A,a,b,F)}var ie=_,pe=E;function me(A,U,O,b,I,Z){var te=new Uint8Array(32);return fe(te,I,Z),ie(A,U,O,b,te)}function ye(A,U,O,b,I,Z){var te=new Uint8Array(32);return fe(te,I,Z),pe(A,U,O,b,te)}var Ce=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function je(A,U,O,b){for(var I=new Int32Array(16),Z=new Int32Array(16),te,de,we,ke,Ne,ft,Be,Fe,Ke,Je,Qe,Pe,Ye,Ge,Oe,De,Me,Re,Ue,Ae,se,oe,_e,ge,ve,Ee,qe=A[0],nt=A[1],st=A[2],at=A[3],P=A[4],ut=A[5],At=A[6],Nt=A[7],ot=U[0],_t=U[1],St=U[2],cr=U[3],Ot=U[4],nr=U[5],ar=U[6],ir=U[7],gr=0;b>=128;){for(Ue=0;Ue<16;Ue++)Ae=8*Ue+gr,I[Ue]=O[Ae+0]<<24|O[Ae+1]<<16|O[Ae+2]<<8|O[Ae+3],Z[Ue]=O[Ae+4]<<24|O[Ae+5]<<16|O[Ae+6]<<8|O[Ae+7];for(Ue=0;Ue<80;Ue++)if(te=qe,de=nt,we=st,ke=at,Ne=P,ft=ut,Be=At,Fe=Nt,Ke=ot,Je=_t,Qe=St,Pe=cr,Ye=Ot,Ge=nr,Oe=ar,De=ir,se=Nt,oe=ir,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=(P>>>14|Ot<<18)^(P>>>18|Ot<<14)^(Ot>>>9|P<<23),oe=(Ot>>>14|P<<18)^(Ot>>>18|P<<14)^(P>>>9|Ot<<23),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=P&ut^~P&At,oe=Ot&nr^~Ot&ar,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=Ce[Ue*2],oe=Ce[Ue*2+1],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=I[Ue%16],oe=Z[Ue%16],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,Me=ve&65535|Ee<<16,Re=_e&65535|ge<<16,se=Me,oe=Re,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=(qe>>>28|ot<<4)^(ot>>>2|qe<<30)^(ot>>>7|qe<<25),oe=(ot>>>28|qe<<4)^(qe>>>2|ot<<30)^(qe>>>7|ot<<25),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,se=qe&nt^qe&st^nt&st,oe=ot&_t^ot&St^_t&St,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,Fe=ve&65535|Ee<<16,De=_e&65535|ge<<16,se=ke,oe=Pe,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=Me,oe=Re,_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,ke=ve&65535|Ee<<16,Pe=_e&65535|ge<<16,nt=te,st=de,at=we,P=ke,ut=Ne,At=ft,Nt=Be,qe=Fe,_t=Ke,St=Je,cr=Qe,Ot=Pe,nr=Ye,ar=Ge,ir=Oe,ot=De,Ue%16===15)for(Ae=0;Ae<16;Ae++)se=I[Ae],oe=Z[Ae],_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=I[(Ae+9)%16],oe=Z[(Ae+9)%16],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,Me=I[(Ae+1)%16],Re=Z[(Ae+1)%16],se=(Me>>>1|Re<<31)^(Me>>>8|Re<<24)^Me>>>7,oe=(Re>>>1|Me<<31)^(Re>>>8|Me<<24)^(Re>>>7|Me<<25),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,Me=I[(Ae+14)%16],Re=Z[(Ae+14)%16],se=(Me>>>19|Re<<13)^(Re>>>29|Me<<3)^Me>>>6,oe=(Re>>>19|Me<<13)^(Me>>>29|Re<<3)^(Re>>>6|Me<<26),_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,I[Ae]=ve&65535|Ee<<16,Z[Ae]=_e&65535|ge<<16;se=qe,oe=ot,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[0],oe=U[0],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[0]=qe=ve&65535|Ee<<16,U[0]=ot=_e&65535|ge<<16,se=nt,oe=_t,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[1],oe=U[1],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[1]=nt=ve&65535|Ee<<16,U[1]=_t=_e&65535|ge<<16,se=st,oe=St,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[2],oe=U[2],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[2]=st=ve&65535|Ee<<16,U[2]=St=_e&65535|ge<<16,se=at,oe=cr,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[3],oe=U[3],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[3]=at=ve&65535|Ee<<16,U[3]=cr=_e&65535|ge<<16,se=P,oe=Ot,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[4],oe=U[4],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[4]=P=ve&65535|Ee<<16,U[4]=Ot=_e&65535|ge<<16,se=ut,oe=nr,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[5],oe=U[5],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[5]=ut=ve&65535|Ee<<16,U[5]=nr=_e&65535|ge<<16,se=At,oe=ar,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[6],oe=U[6],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[6]=At=ve&65535|Ee<<16,U[6]=ar=_e&65535|ge<<16,se=Nt,oe=ir,_e=oe&65535,ge=oe>>>16,ve=se&65535,Ee=se>>>16,se=A[7],oe=U[7],_e+=oe&65535,ge+=oe>>>16,ve+=se&65535,Ee+=se>>>16,ge+=_e>>>16,ve+=ge>>>16,Ee+=ve>>>16,A[7]=Nt=ve&65535|Ee<<16,U[7]=ir=_e&65535|ge<<16,gr+=128,b-=128}return b}function Te(A,U,O){var b=new Int32Array(8),I=new Int32Array(8),Z=new Uint8Array(256),te,de=O;for(b[0]=1779033703,b[1]=3144134277,b[2]=1013904242,b[3]=2773480762,b[4]=1359893119,b[5]=2600822924,b[6]=528734635,b[7]=1541459225,I[0]=4089235720,I[1]=2227873595,I[2]=4271175723,I[3]=1595750129,I[4]=2917565137,I[5]=725511199,I[6]=4215389547,I[7]=327033209,je(b,I,U,O),O%=128,te=0;te=0;--I)b=O[I/8|0]>>(I&7)&1,He(A,U,b),ct(U,A),ct(A,A),He(A,U,b)}function rt(A,U){var O=[r(),r(),r(),r()];S(O[0],y),S(O[1],g),S(O[2],o),G(O[3],y,g),gt(A,O,U)}function et(A,U,O){var b=new Uint8Array(64),I=[r(),r(),r(),r()],Z;for(O||n(U,32),Te(b,U,32),b[0]&=248,b[31]&=127,b[31]|=64,rt(I,b),Le(A,I),Z=0;Z<32;Z++)U[Z+32]=A[Z];return 0}var dr=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function B(A,U){var O,b,I,Z;for(b=63;b>=32;--b){for(O=0,I=b-32,Z=b-12;I>4)*dr[I],O=U[I]>>8,U[I]&=255;for(I=0;I<32;I++)U[I]-=O*dr[I];for(b=0;b<32;b++)U[b+1]+=U[b]>>8,A[b]=U[b]&255}function m(A){var U=new Float64Array(64),O;for(O=0;O<64;O++)U[O]=A[O];for(O=0;O<64;O++)A[O]=0;B(A,U)}function w(A,U,O,b){var I=new Uint8Array(64),Z=new Uint8Array(64),te=new Uint8Array(64),de,we,ke=new Float64Array(64),Ne=[r(),r(),r(),r()];Te(I,b,32),I[0]&=248,I[31]&=127,I[31]|=64;var ft=O+64;for(de=0;de>7&&q(A[0],s,A[0]),G(A[3],A[0],A[1]),0)}function X(A,U,O,b){var I,Z=new Uint8Array(32),te=new Uint8Array(64),de=[r(),r(),r(),r()],we=[r(),r(),r(),r()];if(O<64||H(we,b))return-1;for(I=0;I=0},t.sign.keyPair=function(){var A=new Uint8Array(kt),U=new Uint8Array(Lt);return et(A,U),{publicKey:A,secretKey:U}},t.sign.keyPair.fromSecretKey=function(A){if(wt(A),A.length!==Lt)throw new Error("bad secret key size");for(var U=new Uint8Array(kt),O=0;O"u"?typeof Buffer.from<"u"?(t.encodeBase64=function(n){return Buffer.from(n).toString("base64")},t.decodeBase64=function(n){return r(n),new Uint8Array(Array.prototype.slice.call(Buffer.from(n,"base64"),0))}):(t.encodeBase64=function(n){return new Buffer(n).toString("base64")},t.decodeBase64=function(n){return r(n),new Uint8Array(Array.prototype.slice.call(new Buffer(n,"base64"),0))}):(t.encodeBase64=function(n){var a,i=[],s=n.length;for(a=0;a(e.XBULL_CONNECT="XBULL_CONNECT",e.XBULL_GET_PUBLIC_KEY="XBULL_GET_PUBLIC_KEY",e.XBULL_SIGN_XDR="XBULL_SIGN_XDR",e.XBULL_GET_NETWORK="XBULL_GET_NETWORK",e.XBULL_SIGN_MESSAGE="XBULL_SIGN_MESSAGE",e.XBULL_INITIAL_RESPONSE="XBULL_INITIAL_RESPONSE",e.XBULL_CONNECT_RESPONSE="XBULL_CONNECT_RESPONSE",e.XBULL_SIGN="XBULL_SIGN",e.XBULL_SIGN_RESPONSE="XBULL_SIGN_RESPONSE",e.XBULL_SIGN_MESSAGE_RESPONSE="XBULL_SIGN_MESSAGE_RESPONSE",e))(yn||{});function E0(e){return!!e.error}let A0=class{constructor(){this.isConnected=!1}sendEventToContentScript(t,r,n){return new Promise(a=>{const i=s=>{s.source!==window||!s.data||s.origin!==window.origin||s.data.eventId===n&&(a(s),window.removeEventListener("message",i,!1))};window.addEventListener("message",i,!1),window.webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify({type:t,eventId:n,detail:r}))})}async enableConnection(){const t={origin:window.origin,host:window.location.host,permissions:{canRequestPublicKey:!0,canRequestSign:!0}},r=await this.sendEventToContentScript(yn.XBULL_CONNECT,t,crypto.randomUUID()),{detail:n}=r.data;if(!n||n.error)throw{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"};this.isConnected=!0}async getAddress(){try{await this.enableConnection()}catch(a){return{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.message)||"Unexpected error"}}}const t={origin:window.origin,host:window.location.host},r=await this.sendEventToContentScript(yn.XBULL_GET_PUBLIC_KEY,t,crypto.randomUUID()),{detail:n}=r.data;return!n||n.error?{error:{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"}}:{address:n.payload}}async signTransaction(t){var i,s,o,c;if((i=t.opts)!=null&&i.submit||(s=t.opts)!=null&&s.submitUrl)return{error:{code:-1,message:"Parameters `submit` and `submitUrl` are not supported"}};try{await this.enableConnection()}catch(d){return{error:{code:(d==null?void 0:d.code)||-1,message:(d==null?void 0:d.message)||"Unexpected error"}}}const r={origin:window.origin,host:window.location.host,network:(o=t.opts)==null?void 0:o.networkPassphrase,publicKey:(c=t.opts)==null?void 0:c.address,xdr:t.xdr,xdrType:"Transaction"},n=await this.sendEventToContentScript(yn.XBULL_SIGN_XDR,r,crypto.randomUUID()),{detail:a}=n.data;return!a||a.error?{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.errorMessage)||"Unexpected error"}}:{signedTxXdr:a.payload.signedXdr,signerAddress:a.payload.signerAddress}}async signMessage(t,r){if(!t)return{error:{code:-1,message:"The message must be defined."}};try{await this.enableConnection()}catch(s){return{error:{code:(s==null?void 0:s.code)||-1,message:(s==null?void 0:s.message)||"Unexpected error"}}}const n={origin:window.origin,host:window.location.host,message:t,publicKey:r==null?void 0:r.address,network:r==null?void 0:r.networkPassphrase},a=await this.sendEventToContentScript(yn.XBULL_SIGN_MESSAGE,n,crypto.randomUUID()),{detail:i}=a.data;return!i||i.error?{error:{code:(i==null?void 0:i.code)||-1,message:(i==null?void 0:i.errorMessage)||"Unexpected error"}}:{signedMessage:i.payload.signedMessage,signerAddress:i.payload.signerAddress}}async getNetwork(){try{await this.enableConnection()}catch(a){return{error:{code:(a==null?void 0:a.code)||-1,message:(a==null?void 0:a.message)||"Unexpected error"}}}const t={origin:window.origin,host:window.location.host},r=await this.sendEventToContentScript(yn.XBULL_GET_NETWORK,t,crypto.randomUUID()),{detail:n}=r.data;return!n||n.error?{error:{code:(n==null?void 0:n.code)||-1,message:(n==null?void 0:n.errorMessage)||"Unexpected error"}}:{network:n.payload.network,networkPassphrase:n.payload.networkPassphrase}}};class N0{constructor(t){this.closeCurrentPromises$=new sn,this.closeObservables$=new sn,this.initialResponse$=new sn,this.initialResponseCompleted$=new sn,this.connectResponse$=new sn,this.connectResult$=new sn,this.signResponse$=new sn,this.signResult$=new sn,this.signMessageResponse$=new sn,this.signMessageResult$=new sn,this.closeCurrentPromisesSubscription=Yw(1e3,1e3).pipe(mn(this.closeObservables$)).subscribe(()=>{var i;(i=this.target)!=null&&i.closed&&this.closeCurrentPromises$.next()}),this.onInititalResponseSubscription=this.initialResponse$.pipe(mn(this.closeObservables$)).subscribe(i=>{const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:i.data.publicKey});JSON.parse(s).providedSession===this.session()&&(this.targetPublicKey=i.data.publicKey,this.initialResponseCompleted$.next())}),this.onConnectResponseSubscription=this.connectResponse$.pipe(mn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.connectResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.connectResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.connectResult$.next({success:!0,publicKey:o.publicKey})}),this.onSignResponseSubscription=this.signResponse$.pipe(mn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.signResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.signResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.signResult$.next({success:!0,xdr:o.xdr})}),this.onSignMessageResponseSubscription=this.signMessageResponse$.pipe(mn(this.closeObservables$)).subscribe(i=>{if(!this.targetPublicKey)return void this.signMessageResult$.next({success:!1,message:"Wallet encryption public key is not provided, request rejected."});if(!i.data.success)return void this.signMessageResult$.next({success:!1,message:"Request rejected from the wallet"});const s=this.decryptFromReceiver({oneTimeCode:i.data.oneTimeCode,payload:i.data.message,senderPublicKey:this.targetPublicKey}),o=JSON.parse(s);this.signMessageResult$.next({success:!0,...o})}),this.preferredTarget=(t==null?void 0:t.preferredTarget)||"extension",this.walletUrl=(t==null?void 0:t.url)||"https://wallet.xbull.app/connect";const r=xl.box.keyPair(),n=Un.encodeBase64(xl.randomBytes(24));this.encryptForReceiver=i=>{const s=xl.randomBytes(24),o=xl.box(Un.decodeUTF8(i.data),s,i.receiverPublicKey,r.secretKey);return{message:Un.encodeBase64(o),oneTimeCode:Un.encodeBase64(s)}},this.decryptFromReceiver=i=>{const s=xl.box.open(Un.decodeBase64(i.payload),Un.decodeBase64(i.oneTimeCode),Un.decodeBase64(i.senderPublicKey),r.secretKey);if(!s)throw new Error("Decrypted message is null");return Un.encodeUTF8(s)},this.publicKey=()=>r.publicKey,this.session=()=>n.slice();const a=i=>{switch(i.data.type){case yn.XBULL_INITIAL_RESPONSE:this.initialResponse$.next(i);break;case yn.XBULL_CONNECT_RESPONSE:this.connectResponse$.next(i);break;case yn.XBULL_SIGN_RESPONSE:this.signResponse$.next(i);break;case yn.XBULL_SIGN_MESSAGE_RESPONSE:this.signMessageResponse$.next(i)}};window.addEventListener("message",a),this.closeObservables$.asObservable().pipe(Tl(1)).subscribe(()=>{window.removeEventListener("message",a)})}openWallet(){return this.target&&!this.target.closed&&(this.target.close(),this.target=null,this.closeCurrentPromises$.next()),this.target=window.open(`${this.walletUrl}?public=${encodeURIComponent(Un.encodeBase64(this.publicKey()))}&session=${encodeURIComponent(this.session())}`,"xBull_Wallet_app","width=380,height=640,left=100,top=100"),cu(this.initialResponseCompleted$.pipe(mn(this.closeCurrentPromises$)).pipe(mn(this.closeObservables$)))}closeWallet(){var t;this.target&&((t=this.target)==null||t.close(),this.target=null)}async connect(t={canRequestPublicKey:!0,canRequestSign:!0}){var n,a;const r=(a=(n=window==null?void 0:window.webkit)==null?void 0:n.messageHandlers)!=null&&a.cordova_iab?new A0:window.xBullSDK;if(r&&this.preferredTarget==="extension"){const i=await r.getAddress();if(E0(i))throw i.error;return i.address}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");const{message:i,oneTimeCode:s}=this.encryptForReceiver({data:JSON.stringify(t),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:yn.XBULL_CONNECT,message:i,oneTimeCode:s};this.target.postMessage(o,"*");const c=this.connectResult$.asObservable().pipe(b0(d=>d.success?(this.closeWallet(),h0(d.publicKey)):(this.closeWallet(),p0(()=>new Error(d.message))))).pipe(Tl(1)).pipe(mn(this.closeCurrentPromises$)).pipe(mn(this.closeObservables$));return cu(c)}}async sign(t){var n,a;const r=(a=(n=window==null?void 0:window.webkit)==null?void 0:n.messageHandlers)!=null&&a.cordova_iab?new A0:window.xBullSDK;if(r&&this.preferredTarget==="extension"){const i=await r.signTransaction({xdr:t.xdr,opts:{networkPassphrase:t.network,address:t.publicKey}});if(E0(i))throw i.error;return i.signedTxXdr}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");if(typeof t.xdr!="string")throw new Error("XDR provided needs to be a string value");const{message:i,oneTimeCode:s}=this.encryptForReceiver({data:JSON.stringify(t),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:yn.XBULL_SIGN,message:i,oneTimeCode:s};this.target.postMessage(o,"*");const c=this.signResult$.asObservable().pipe(b0(d=>d.success?(this.closeWallet(),h0(d.xdr)):(this.closeWallet(),p0(()=>new Error(d.message))))).pipe(Tl(1)).pipe(mn(this.closeCurrentPromises$)).pipe(mn(this.closeObservables$));return cu(c)}}async signMessage(t,r){var a,i;const n=(i=(a=window==null?void 0:window.webkit)==null?void 0:a.messageHandlers)!=null&&i.cordova_iab?new A0:window.xBullSDK;if(n&&this.preferredTarget==="extension"){const s=await n.signMessage(t,r);if(E0(s))throw s.error;return s}{if(await this.openWallet(),!this.target||!this.targetPublicKey)throw new Error("xBull Wallet is not open, we can't connect with it");if(typeof t!="string")throw new Error("XDR provided needs to be a string value");const s=this.encryptForReceiver({data:JSON.stringify({message:t,opts:r}),receiverPublicKey:Un.decodeBase64(this.targetPublicKey)}),o={type:yn.XBULL_SIGN_MESSAGE,message:s.message,oneTimeCode:s.oneTimeCode};this.target.postMessage(o,"*");const c=this.signMessageResult$.asObservable().pipe(b0(d=>d.success?(this.closeWallet(),h0({signedMessage:d.signedMessage,signerAddress:d.signerAddress})):(this.closeWallet(),p0(()=>new Error(d.message))))).pipe(Tl(1)).pipe(mn(this.closeCurrentPromises$)).pipe(mn(this.closeObservables$));return cu(c)}}closeConnections(){this.closeObservables$.next(),this.closeCurrentPromises$.next(),this.closeObservables$.complete(),this.closeCurrentPromises$.complete()}}const g7="xbull";class v7{constructor(){this.moduleType=Vo.HOT_WALLET,this.productId=g7,this.productName="xBull",this.productUrl="https://xbull.app",this.productIcon="https://stellar.creit.tech/wallet-icons/xbull.png"}async isAvailable(){return!0}async getAddress(){try{const t=new N0,r=await t.connect();return t.closeConnections(),{address:r}}catch(t){throw un(t)}}async signTransaction(t,r){try{const n=new N0,a=await n.sign({xdr:t,publicKey:r==null?void 0:r.address,network:r==null?void 0:r.networkPassphrase});return n.closeConnections(),{signedTxXdr:a,signerAddress:r==null?void 0:r.address}}catch(n){throw un(n)}}async signAuthEntry(){throw{code:-3,message:'xBull does not support the "signAuthEntry" function'}}async signMessage(t,r){try{const n=new N0,a=await n.signMessage(t,{address:r==null?void 0:r.address,networkPassphrase:r==null?void 0:r.networkPassphrase});return n.closeConnections(),a}catch(n){throw un(n)}}async getNetwork(){throw{code:-3,message:'xBull does not support the "getNetwork" function'}}}var w7={},Wv={},Oo={},ed={},Qo={};Qo.__esModule=!0;Qo.integers=void 0;Qo.integers=["u8","u16","u32","u64","u128","i8","i16","i32","i64","i128","f32","f64"];var Ms={};Ms.__esModule=!0;Ms.DecodeBuffer=Ms.EncodeBuffer=void 0;var _7=function(){function e(){this.offset=0,this.buffer_size=256,this.buffer=new ArrayBuffer(this.buffer_size),this.view=new DataView(this.buffer)}return e.prototype.resize_if_necessary=function(t){if(this.buffer_size-this.offsetthis.buffer.byteLength)throw new Error("Error in schema, the buffer is smaller than expected")},e.prototype.consume_value=function(t){var r=t.substring(1),n=parseInt(r)/8;this.assert_enough_buffer(n);var a=t[0]==="f"?"getFloat".concat(r):t[0]==="i"?"getInt".concat(r):"getUint".concat(r),i=this.view[a](this.offset,!0);return this.offset+=n,i},e.prototype.consume_bytes=function(t){this.assert_enough_buffer(t);var r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r},e}();Ms.DecodeBuffer=S7;var Ur={},E7=Ie&&Ie.__extends||function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,a){n.__proto__=a}||function(n,a){for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(n[i]=a[i])},e(t,r)};return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");e(t,r);function n(){this.constructor=t}t.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}();Ur.__esModule=!0;Ur.validate_schema=Ur.ErrorSchema=Ur.expect_enum=Ur.expect_same_size=Ur.expect_bigint=Ur.expect_type=Ur.isArrayLike=void 0;var A7=Qo;function N7(e){return Array.isArray(e)||!!e&&typeof e=="object"&&"length"in e&&typeof e.length=="number"&&(e.length===0||e.length>0&&e.length-1 in e)}Ur.isArrayLike=N7;function j7(e,t,r){if(typeof e!==t)throw new Error("Expected ".concat(t," not ").concat(typeof e,"(").concat(e,") at ").concat(r.join(".")))}Ur.expect_type=j7;function T7(e,t){var r=["number","string","bigint","boolean"].includes(typeof e),n=typeof e=="object"&&e!==null&&"toString"in e;if(!r&&!n)throw new Error("Expected bigint, number, boolean or string not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}Ur.expect_bigint=T7;function M7(e,t,r){if(e!==t)throw new Error("Array length ".concat(e," does not match schema length ").concat(t," at ").concat(r.join(".")))}Ur.expect_same_size=M7;function C7(e,t){if(typeof e!="object"||e===null)throw new Error("Expected object not ".concat(typeof e,"(").concat(e,") at ").concat(t.join(".")))}Ur.expect_enum=C7;var sx=A7.integers.concat(["bool","string"]),ox=["option","enum","array","set","map","struct"],Cs=function(e){E7(t,e);function t(r,n){var a="Invalid schema: ".concat(JSON.stringify(r)," expected ").concat(n);return e.call(this,a)||this}return t}(Error);Ur.ErrorSchema=Cs;function $i(e){if(!(typeof e=="string"&&sx.includes(e))){if(e&&typeof e=="object"){var t=Object.keys(e);if(t.length===1&&ox.includes(t[0])){var r=t[0];if(r==="option")return $i(e[r]);if(r==="enum")return B7(e[r]);if(r==="array")return O7(e[r]);if(r==="set")return $i(e[r]);if(r==="map")return R7(e[r]);if(r==="struct")return U7(e[r])}}throw new Cs(e,ox.join(", ")+" or "+sx.join(", "))}}Ur.validate_schema=$i;function B7(e){if(!Array.isArray(e))throw new Cs(e,"Array");for(var t=0,r=e;t>BigInt(8);this.encoded.store_bytes(new Uint8Array(a))},e.prototype.encode_string=function(t){this.checkTypes&&Jn.expect_type(t,"string",this.fieldPath);for(var r=t,n=[],a=0;a>6,128|i&63):i<55296||i>=57344?n.push(224|i>>12,128|i>>6&63,128|i&63):(a++,i=65536+((i&1023)<<10|r.charCodeAt(a)&1023),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}this.encoded.store_value(n.length,"u32"),this.encoded.store_bytes(new Uint8Array(n))},e.prototype.encode_boolean=function(t){this.checkTypes&&Jn.expect_type(t,"boolean",this.fieldPath),this.encoded.store_value(t?1:0,"u8")},e.prototype.encode_option=function(t,r){t==null?this.encoded.store_value(0,"u8"):(this.encoded.store_value(1,"u8"),this.encode_value(t,r.option))},e.prototype.encode_enum=function(t,r){this.checkTypes&&Jn.expect_enum(t,this.fieldPath);for(var n=Object.keys(t)[0],a=0;a0},e.prototype.decode_option=function(t){var r=this.buffer.consume_value("u8");if(r===1)return this.decode_value(t.option);if(r!==0)throw new Error("Invalid option ".concat(r));return null},e.prototype.decode_enum=function(t){var r,n=this.buffer.consume_value("u8");if(n>t.enum.length)throw new Error("Enum option ".concat(n," is not available"));var a=t.enum[n].struct,i=Object.keys(a)[0];return r={},r[i]=this.decode_value(a[i]),r},e.prototype.decode_array=function(t){for(var r=[],n=t.array.len?t.array.len:this.decode_integer("u32"),a=0;a>>2]|=F[te]<>>2]|=Y<>>2]|=(192|Y>>>6)<>>2]|=(128|Y&63)<=57344?(f[x>>>2]|=(224|Y>>>12)<>>2]|=(128|Y>>>6&63)<>>2]|=(128|Y&63)<>>2]|=(240|Y>>>18)<>>2]|=(128|Y>>>12&63)<>>2]|=(128|Y>>>6&63)<>>2]|=(128|Y&63)<=64?(this.block=f[16],this.start=x-64,this.hash(),this.hashed=!0):this.start=x}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},z.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var F=this.blocks,V=this.lastByteIndex;F[16]=this.block,F[V>>>2]|=h[V&3],this.block=F[16],V>=56&&(this.hashed||this.hash(),F[0]=this.block,F[16]=F[1]=F[2]=F[3]=F[4]=F[5]=F[6]=F[7]=F[8]=F[9]=F[10]=F[11]=F[12]=F[13]=F[14]=F[15]=0),F[14]=this.hBytes<<3|this.bytes>>>29,F[15]=this.bytes<<3,this.hash()}},z.prototype.hash=function(){var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,te=this.h4,x=this.h5,u=this.h6,f=this.h7,_=this.blocks,E,S,j,R,N,d,C,ae,he,q,G;for(E=16;E<64;++E)N=_[E-15],S=(N>>>7|N<<25)^(N>>>18|N<<14)^N>>>3,N=_[E-2],j=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10,_[E]=_[E-16]+S+_[E-7]+j<<0;for(G=V&J,E=0;E<64;E+=4)this.first?(this.is224?(ae=300032,N=_[0]-1413257819,f=N-150054599<<0,Y=N+24177077<<0):(ae=704751109,N=_[0]-210244248,f=N-1521486534<<0,Y=N+143694565<<0),this.first=!1):(S=(F>>>2|F<<30)^(F>>>13|F<<19)^(F>>>22|F<<10),j=(te>>>6|te<<26)^(te>>>11|te<<21)^(te>>>25|te<<7),ae=F&V,R=ae^F&J^G,C=te&x^~te&u,N=f+j+C+y[E]+_[E],d=S+R,f=Y+N<<0,Y=N+d<<0),S=(Y>>>2|Y<<30)^(Y>>>13|Y<<19)^(Y>>>22|Y<<10),j=(f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7),he=Y&F,R=he^Y&V^ae,C=f&te^~f&x,N=u+j+C+y[E+1]+_[E+1],d=S+R,u=J+N<<0,J=N+d<<0,S=(J>>>2|J<<30)^(J>>>13|J<<19)^(J>>>22|J<<10),j=(u>>>6|u<<26)^(u>>>11|u<<21)^(u>>>25|u<<7),q=J&Y,R=q^J&F^he,C=u&f^~u&te,N=x+j+C+y[E+2]+_[E+2],d=S+R,x=V+N<<0,V=N+d<<0,S=(V>>>2|V<<30)^(V>>>13|V<<19)^(V>>>22|V<<10),j=(x>>>6|x<<26)^(x>>>11|x<<21)^(x>>>25|x<<7),G=V&J,R=G^V&Y^q,C=x&u^~x&f,N=te+j+C+y[E+3]+_[E+3],d=S+R,te=F+N<<0,F=N+d<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+F<<0,this.h1=this.h1+V<<0,this.h2=this.h2+J<<0,this.h3=this.h3+Y<<0,this.h4=this.h4+te<<0,this.h5=this.h5+x<<0,this.h6=this.h6+u<<0,this.h7=this.h7+f<<0},z.prototype.hex=function(){this.finalize();var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,te=this.h4,x=this.h5,u=this.h6,f=this.h7,_=c[F>>>28&15]+c[F>>>24&15]+c[F>>>20&15]+c[F>>>16&15]+c[F>>>12&15]+c[F>>>8&15]+c[F>>>4&15]+c[F&15]+c[V>>>28&15]+c[V>>>24&15]+c[V>>>20&15]+c[V>>>16&15]+c[V>>>12&15]+c[V>>>8&15]+c[V>>>4&15]+c[V&15]+c[J>>>28&15]+c[J>>>24&15]+c[J>>>20&15]+c[J>>>16&15]+c[J>>>12&15]+c[J>>>8&15]+c[J>>>4&15]+c[J&15]+c[Y>>>28&15]+c[Y>>>24&15]+c[Y>>>20&15]+c[Y>>>16&15]+c[Y>>>12&15]+c[Y>>>8&15]+c[Y>>>4&15]+c[Y&15]+c[te>>>28&15]+c[te>>>24&15]+c[te>>>20&15]+c[te>>>16&15]+c[te>>>12&15]+c[te>>>8&15]+c[te>>>4&15]+c[te&15]+c[x>>>28&15]+c[x>>>24&15]+c[x>>>20&15]+c[x>>>16&15]+c[x>>>12&15]+c[x>>>8&15]+c[x>>>4&15]+c[x&15]+c[u>>>28&15]+c[u>>>24&15]+c[u>>>20&15]+c[u>>>16&15]+c[u>>>12&15]+c[u>>>8&15]+c[u>>>4&15]+c[u&15];return this.is224||(_+=c[f>>>28&15]+c[f>>>24&15]+c[f>>>20&15]+c[f>>>16&15]+c[f>>>12&15]+c[f>>>8&15]+c[f>>>4&15]+c[f&15]),_},z.prototype.toString=z.prototype.hex,z.prototype.digest=function(){this.finalize();var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,te=this.h4,x=this.h5,u=this.h6,f=this.h7,_=[F>>>24&255,F>>>16&255,F>>>8&255,F&255,V>>>24&255,V>>>16&255,V>>>8&255,V&255,J>>>24&255,J>>>16&255,J>>>8&255,J&255,Y>>>24&255,Y>>>16&255,Y>>>8&255,Y&255,te>>>24&255,te>>>16&255,te>>>8&255,te&255,x>>>24&255,x>>>16&255,x>>>8&255,x&255,u>>>24&255,u>>>16&255,u>>>8&255,u&255];return this.is224||_.push(f>>>24&255,f>>>16&255,f>>>8&255,f&255),_},z.prototype.array=z.prototype.digest,z.prototype.arrayBuffer=function(){this.finalize();var F=new ArrayBuffer(this.is224?28:32),V=new DataView(F);return V.setUint32(0,this.h0),V.setUint32(4,this.h1),V.setUint32(8,this.h2),V.setUint32(12,this.h3),V.setUint32(16,this.h4),V.setUint32(20,this.h5),V.setUint32(24,this.h6),this.is224||V.setUint32(28,this.h7),F};function L(F,V,J){var Y,te=typeof F;if(te==="string"){var x=[],u=F.length,f=0,_;for(Y=0;Y>>6,x[f++]=128|_&63):_<55296||_>=57344?(x[f++]=224|_>>>12,x[f++]=128|_>>>6&63,x[f++]=128|_&63):(_=65536+((_&1023)<<10|F.charCodeAt(++Y)&1023),x[f++]=240|_>>>18,x[f++]=128|_>>>12&63,x[f++]=128|_>>>6&63,x[f++]=128|_&63);F=x}else if(te==="object"){if(F===null)throw new Error(t);if(o&&F.constructor===ArrayBuffer)F=new Uint8Array(F);else if(!Array.isArray(F)&&(!o||!ArrayBuffer.isView(F)))throw new Error(t)}else throw new Error(t);F.length>64&&(F=new z(V,!0).update(F).array());var E=[],S=[];for(Y=0;Y<64;++Y){var j=F[Y]||0;E[Y]=92^j,S[Y]=54^j}z.call(this,V,J),this.update(S),this.oKeyPad=E,this.inner=!0,this.sharedMemory=J}L.prototype=new z,L.prototype.finalize=function(){if(z.prototype.finalize.call(this),this.inner){this.inner=!1;var F=this.array();z.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(F),z.prototype.finalize.call(this)}};var $=k();$.sha256=$,$.sha224=k(!0),$.sha256.hmac=T(),$.sha224.hmac=T(!0),s?e.exports=$:(n.sha256=$.sha256,n.sha224=$.sha224)})()})(t3);var Q7=t3.exports,r3={},Ja={};Object.defineProperty(Ja,"__esModule",{value:!0});Ja.KeySize=Ja.KeyType=void 0;var lx;(function(e){e[e.ED25519=0]="ED25519",e[e.SECP256K1=1]="SECP256K1"})(lx||(Ja.KeyType=lx={}));Ja.KeySize={SECRET_KEY:32,ED25519_PUBLIC_KEY:32,SECP256k1_PUBLIC_KEY:64};var rd={},Jo={};Object.defineProperty(Jo,"__esModule",{value:!0});Jo.KeyPairBase=void 0;class J7{}Jo.KeyPairBase=J7;var zc={},Wo={},nd={};Object.defineProperty(nd,"__esModule",{value:!0});nd.DEFAULT_FUNCTION_CALL_GAS=void 0;nd.DEFAULT_FUNCTION_CALL_GAS=30000000000000n;var I1={},Dc={};const W7="Exceeded the maximum amount of gas allowed to burn per contract",eS="Method name is empty",tS="Wasmer compilation error: {{msg}}",rS="Smart contract panicked: {{panic_msg}}",nS="Error creating Wasm memory",aS="Exceeded the prepaid gas",iS="Method name is not valid UTF8 string",sS="String encoding is bad UTF-16 sequence",oS="WebAssembly trap: {{msg}}",lS="Gas instrumentation failed or contract has denied instructions.",cS="{{promise_idx}} does not correspond to existing promises",uS="Accessed invalid promise result index: {{result_idx}}",fS="Error happened while deserializing the module",dS="Contract method is not found",hS="Accessed invalid register id: {{register_id}}",pS="VM Logic returned an invalid receipt index: {{receipt_index}}",bS="Method name is empty in contract call",mS="Returning joint promise is currently prohibited",xS="Stack instrumentation failed",yS="Cannot find contract code for account {{account_id}}",gS="Invalid method signature",vS="Integer overflow happened during contract execution",wS="MemoryAccessViolation",_S="Iterator index {{iterator_index}} does not exist",SS="Iterator {{iterator_index}} was invalidated after its creation by performing a mutable operation on trie",ES="VM Logic returned an invalid account id",AS="Error happened while serializing the module",NS="Actions can only be appended to non-joint promise.",jS="Internal memory declaration has been found in the module",TS="Error happened during instantiation",MS="{{method_name}} is not allowed in view calls",CS="VM Logic returned an invalid method name",BS="String encoding is bad UTF-8 sequence",OS="Exceeded the account balance",RS="Wasm contract link error: {{msg}}",US="VM Logic provided an invalid public key",kS="Actor {{actor_id}} doesn't have permission to account {{account_id}} to complete the action",zS="The account {{account_id}} wouldn't have enough balance to cover storage, required to have {{amount}} yoctoNEAR more",DS="Wrong AccessKey used for transaction: transaction is sent to receiver_id={{tx_receiver}}, but is signed with function call access key that restricted to only use with receiver_id={{ak_receiver}}. Either change receiver_id in your transaction or switch to use a FullAccessKey.",IS="Transaction gas or balance cost is too high",LS="Transaction is not signed with the given public key",HS=`Signer "{{account_id}}" doesn't have access key with the given public_key {{public_key}}`,qS="Sender {{signer_id}} does not have enough balance {{#formatNear}}{{balance}}{{/formatNear}} for operation costing {{#formatNear}}{{cost}}{{/formatNear}}",$S="Access Key {account_id}:{public_key} does not have enough balance {{#formatNear}}{{allowance}}{{/formatNear}} for transaction costing {{#formatNear}}{{cost}}{{/formatNear}}",FS="Transaction has expired",KS="Account {{account_id}} is staking and can not be deleted",PS="Signer {{signer_id}} does not exist",GS="Account {{account_id}} tried to stake {{#formatNear}}{{stake}}{{/formatNear}}, but has staked {{#formatNear}}{{locked}}{{/formatNear}} and only has {{#formatNear}}{{balance}}{{/formatNear}}",YS="The public key {{public_key}} is already used for an existing access key",VS="Invalid signer account ID {{signer_id}} according to requirements",XS="The new account_id {{account_id}} can't be created by {{predecessor_id}}",ZS="The transaction contains more then one action, but it was signed with an access key which allows transaction to apply only one specific action. To apply more then one actions TX must be signed with a full access key",QS="Account {{account_id}} is not yet staked, but tried to unstake",JS="Transaction nonce {{tx_nonce}} must be larger than nonce of the used access key {{ak_nonce}}",WS="Can't create a new account {{account_id}}, because it already exists",eE="Transaction parent block hash doesn't belong to the current chain",tE="Can't complete the action because account {{account_id}} doesn't exist",rE="Can't complete the action because access key {{public_key}} doesn't exist",nE="Transaction method name {{method_name}} isn't allowed by the access key",aE="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover the rent",iE="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover it's storage",sE="Invalid receiver account ID {{receiver_id}} according to requirements",oE="Account {{account_id}} tries to remove an access key that doesn't exist",lE="Timeout exceeded",cE="Connection closed",uE="Shard {{shard_id}} rejected the transaction due to congestion level {{congestion_level}}, try again later",fE="Shard {{shard_id}} rejected the transaction because it missed {{missed_chunks}} chunks and needs to recover before accepting new transactions, try again later",dE={GasLimitExceeded:W7,MethodEmptyName:eS,WasmerCompileError:tS,GuestPanic:rS,Memory:nS,GasExceeded:aS,MethodUTF8Error:iS,BadUTF16:sS,WasmTrap:oS,GasInstrumentation:lS,InvalidPromiseIndex:cS,InvalidPromiseResultIndex:uS,Deserialization:fS,MethodNotFound:dS,InvalidRegisterId:hS,InvalidReceiptIndex:pS,EmptyMethodName:bS,CannotReturnJointPromise:mS,StackHeightInstrumentation:xS,CodeDoesNotExist:yS,MethodInvalidSignature:gS,IntegerOverflow:vS,MemoryAccessViolation:wS,InvalidIteratorIndex:_S,IteratorWasInvalidated:SS,InvalidAccountId:ES,Serialization:AS,CannotAppendActionToJointPromise:NS,InternalMemoryDeclared:jS,Instantiate:TS,ProhibitedInView:MS,InvalidMethodName:CS,BadUTF8:BS,BalanceExceeded:OS,LinkError:RS,InvalidPublicKey:US,ActorNoPermission:kS,LackBalanceForState:zS,ReceiverMismatch:DS,CostOverflow:IS,InvalidSignature:LS,AccessKeyNotFound:HS,NotEnoughBalance:qS,NotEnoughAllowance:$S,Expired:FS,DeleteAccountStaking:KS,SignerDoesNotExist:PS,TriesToStake:GS,AddKeyAlreadyExists:YS,InvalidSigner:VS,CreateAccountNotAllowed:XS,RequiresFullAccess:ZS,TriesToUnstake:QS,InvalidNonce:JS,AccountAlreadyExists:WS,InvalidChain:eE,AccountDoesNotExist:tE,AccessKeyDoesNotExist:rE,MethodNameMismatch:nE,DeleteAccountHasRent:aE,DeleteAccountHasEnoughBalance:iE,InvalidReceiver:sE,DeleteKeyDoesNotExist:oE,Timeout:lE,Closed:cE,ShardCongested:uE,ShardStuck:fE};var hE=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Dc,"__esModule",{value:!0});Dc.ErrorMessages=void 0;const pE=hE(dE);Dc.ErrorMessages=pE.default;var Kn={},n3={},ad={};Object.defineProperty(ad,"__esModule",{value:!0});ad.Assignable=void 0;class bE{constructor(t){Object.keys(t).map(r=>{this[r]=t[r]})}}ad.Assignable=bE;var id={};Object.defineProperty(id,"__esModule",{value:!0});id.Enum=void 0;let mE=class{constructor(t){if(Object.keys(t).length!==1)throw new Error("Enum can only take single value");Object.keys(t).map(r=>{this[r]=t[r]})}};id.Enum=mE;var fa={};Object.defineProperty(fa,"__esModule",{value:!0});fa.ErrorContext=fa.TypedError=fa.ArgumentTypeError=fa.PositionalArgsError=void 0;class xE extends Error{constructor(){super("Contract method calls expect named arguments wrapped in object, e.g. { argName1: argValue1, argName2: argValue2 }")}}fa.PositionalArgsError=xE;class yE extends Error{constructor(t,r,n){super(`Expected ${r} for '${t}' argument, but got '${JSON.stringify(n)}'`)}}fa.ArgumentTypeError=yE;class gE extends Error{constructor(r,n,a){super(r);Bt(this,"type");Bt(this,"context");this.type=n||"UntypedError",this.context=a}}fa.TypedError=gE;class vE{constructor(t){Bt(this,"transactionHash");this.transactionHash=t}}fa.ErrorContext=vE;var a3={},sd={};Object.defineProperty(sd,"__esModule",{value:!0});sd.IdType=void 0;var cx;(function(e){e.Transaction="transaction",e.Receipt="receipt"})(cx||(sd.IdType=cx={}));var Ro={};Object.defineProperty(Ro,"__esModule",{value:!0});Ro.FinalExecutionStatusBasic=Ro.ExecutionStatusBasic=void 0;var ux;(function(e){e.Unknown="Unknown",e.Pending="Pending",e.Failure="Failure"})(ux||(Ro.ExecutionStatusBasic=ux={}));var fx;(function(e){e.NotStarted="NotStarted",e.Started="Started",e.Failure="Failure"})(fx||(Ro.FinalExecutionStatusBasic=fx={}));(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.FinalExecutionStatusBasic=e.ExecutionStatusBasic=e.IdType=void 0;var t=sd;Object.defineProperty(e,"IdType",{enumerable:!0,get:function(){return t.IdType}});var r=Ro;Object.defineProperty(e,"ExecutionStatusBasic",{enumerable:!0,get:function(){return r.ExecutionStatusBasic}}),Object.defineProperty(e,"FinalExecutionStatusBasic",{enumerable:!0,get:function(){return r.FinalExecutionStatusBasic}})})(a3);(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(n,a,i,s){s===void 0&&(s=i);var o=Object.getOwnPropertyDescriptor(a,i);(!o||("get"in o?!a.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(n,s,o)}:function(n,a,i,s){s===void 0&&(s=i),n[s]=a[i]}),r=Ie&&Ie.__exportStar||function(n,a){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(a,i)&&t(a,n,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(ad,e),r(id,e),r(fa,e),r(a3,e)})(n3);var i3={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,function(){/*! + */(function(e){(function(){var t="input is invalid type",r=typeof window=="object",n=r?window:{};n.JS_SHA256_NO_WINDOW&&(r=!1);var a=!r&&typeof self=="object",i=!n.JS_SHA256_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node&&process.type!="renderer";i?n=Ie:a&&(n=self);var s=!n.JS_SHA256_NO_COMMON_JS&&!0&&e.exports,o=!n.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",c="0123456789abcdef".split(""),d=[-2147483648,8388608,32768,128],p=[24,16,8,0],y=[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],g=["hex","array","digest","arrayBuffer"],v=[];(n.JS_SHA256_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(F){return Object.prototype.toString.call(F)==="[object Array]"}),o&&(n.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(F){return typeof F=="object"&&F.buffer&&F.buffer.constructor===ArrayBuffer});var M=function(F,V){return function(J){return new k(V,!0).update(J)[F]()}},z=function(F){var V=M("hex",F);i&&(V=K(V,F)),V.create=function(){return new k(F)},V.update=function(ee){return V.create().update(ee)};for(var J=0;J>>2]|=F[ee]<>>2]|=Y<>>2]|=(192|Y>>>6)<>>2]|=(128|Y&63)<=57344?(f[x>>>2]|=(224|Y>>>12)<>>2]|=(128|Y>>>6&63)<>>2]|=(128|Y&63)<>>2]|=(240|Y>>>18)<>>2]|=(128|Y>>>12&63)<>>2]|=(128|Y>>>6&63)<>>2]|=(128|Y&63)<=64?(this.block=f[16],this.start=x-64,this.hash(),this.hashed=!0):this.start=x}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},k.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var F=this.blocks,V=this.lastByteIndex;F[16]=this.block,F[V>>>2]|=d[V&3],this.block=F[16],V>=56&&(this.hashed||this.hash(),F[0]=this.block,F[16]=F[1]=F[2]=F[3]=F[4]=F[5]=F[6]=F[7]=F[8]=F[9]=F[10]=F[11]=F[12]=F[13]=F[14]=F[15]=0),F[14]=this.hBytes<<3|this.bytes>>>29,F[15]=this.bytes<<3,this.hash()}},k.prototype.hash=function(){var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,ee=this.h4,x=this.h5,u=this.h6,f=this.h7,_=this.blocks,E,S,j,R,N,h,C,ae,he,q,G;for(E=16;E<64;++E)N=_[E-15],S=(N>>>7|N<<25)^(N>>>18|N<<14)^N>>>3,N=_[E-2],j=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10,_[E]=_[E-16]+S+_[E-7]+j<<0;for(G=V&J,E=0;E<64;E+=4)this.first?(this.is224?(ae=300032,N=_[0]-1413257819,f=N-150054599<<0,Y=N+24177077<<0):(ae=704751109,N=_[0]-210244248,f=N-1521486534<<0,Y=N+143694565<<0),this.first=!1):(S=(F>>>2|F<<30)^(F>>>13|F<<19)^(F>>>22|F<<10),j=(ee>>>6|ee<<26)^(ee>>>11|ee<<21)^(ee>>>25|ee<<7),ae=F&V,R=ae^F&J^G,C=ee&x^~ee&u,N=f+j+C+y[E]+_[E],h=S+R,f=Y+N<<0,Y=N+h<<0),S=(Y>>>2|Y<<30)^(Y>>>13|Y<<19)^(Y>>>22|Y<<10),j=(f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7),he=Y&F,R=he^Y&V^ae,C=f&ee^~f&x,N=u+j+C+y[E+1]+_[E+1],h=S+R,u=J+N<<0,J=N+h<<0,S=(J>>>2|J<<30)^(J>>>13|J<<19)^(J>>>22|J<<10),j=(u>>>6|u<<26)^(u>>>11|u<<21)^(u>>>25|u<<7),q=J&Y,R=q^J&F^he,C=u&f^~u&ee,N=x+j+C+y[E+2]+_[E+2],h=S+R,x=V+N<<0,V=N+h<<0,S=(V>>>2|V<<30)^(V>>>13|V<<19)^(V>>>22|V<<10),j=(x>>>6|x<<26)^(x>>>11|x<<21)^(x>>>25|x<<7),G=V&J,R=G^V&Y^q,C=x&u^~x&f,N=ee+j+C+y[E+3]+_[E+3],h=S+R,ee=F+N<<0,F=N+h<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+F<<0,this.h1=this.h1+V<<0,this.h2=this.h2+J<<0,this.h3=this.h3+Y<<0,this.h4=this.h4+ee<<0,this.h5=this.h5+x<<0,this.h6=this.h6+u<<0,this.h7=this.h7+f<<0},k.prototype.hex=function(){this.finalize();var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,ee=this.h4,x=this.h5,u=this.h6,f=this.h7,_=c[F>>>28&15]+c[F>>>24&15]+c[F>>>20&15]+c[F>>>16&15]+c[F>>>12&15]+c[F>>>8&15]+c[F>>>4&15]+c[F&15]+c[V>>>28&15]+c[V>>>24&15]+c[V>>>20&15]+c[V>>>16&15]+c[V>>>12&15]+c[V>>>8&15]+c[V>>>4&15]+c[V&15]+c[J>>>28&15]+c[J>>>24&15]+c[J>>>20&15]+c[J>>>16&15]+c[J>>>12&15]+c[J>>>8&15]+c[J>>>4&15]+c[J&15]+c[Y>>>28&15]+c[Y>>>24&15]+c[Y>>>20&15]+c[Y>>>16&15]+c[Y>>>12&15]+c[Y>>>8&15]+c[Y>>>4&15]+c[Y&15]+c[ee>>>28&15]+c[ee>>>24&15]+c[ee>>>20&15]+c[ee>>>16&15]+c[ee>>>12&15]+c[ee>>>8&15]+c[ee>>>4&15]+c[ee&15]+c[x>>>28&15]+c[x>>>24&15]+c[x>>>20&15]+c[x>>>16&15]+c[x>>>12&15]+c[x>>>8&15]+c[x>>>4&15]+c[x&15]+c[u>>>28&15]+c[u>>>24&15]+c[u>>>20&15]+c[u>>>16&15]+c[u>>>12&15]+c[u>>>8&15]+c[u>>>4&15]+c[u&15];return this.is224||(_+=c[f>>>28&15]+c[f>>>24&15]+c[f>>>20&15]+c[f>>>16&15]+c[f>>>12&15]+c[f>>>8&15]+c[f>>>4&15]+c[f&15]),_},k.prototype.toString=k.prototype.hex,k.prototype.digest=function(){this.finalize();var F=this.h0,V=this.h1,J=this.h2,Y=this.h3,ee=this.h4,x=this.h5,u=this.h6,f=this.h7,_=[F>>>24&255,F>>>16&255,F>>>8&255,F&255,V>>>24&255,V>>>16&255,V>>>8&255,V&255,J>>>24&255,J>>>16&255,J>>>8&255,J&255,Y>>>24&255,Y>>>16&255,Y>>>8&255,Y&255,ee>>>24&255,ee>>>16&255,ee>>>8&255,ee&255,x>>>24&255,x>>>16&255,x>>>8&255,x&255,u>>>24&255,u>>>16&255,u>>>8&255,u&255];return this.is224||_.push(f>>>24&255,f>>>16&255,f>>>8&255,f&255),_},k.prototype.array=k.prototype.digest,k.prototype.arrayBuffer=function(){this.finalize();var F=new ArrayBuffer(this.is224?28:32),V=new DataView(F);return V.setUint32(0,this.h0),V.setUint32(4,this.h1),V.setUint32(8,this.h2),V.setUint32(12,this.h3),V.setUint32(16,this.h4),V.setUint32(20,this.h5),V.setUint32(24,this.h6),this.is224||V.setUint32(28,this.h7),F};function L(F,V,J){var Y,ee=typeof F;if(ee==="string"){var x=[],u=F.length,f=0,_;for(Y=0;Y>>6,x[f++]=128|_&63):_<55296||_>=57344?(x[f++]=224|_>>>12,x[f++]=128|_>>>6&63,x[f++]=128|_&63):(_=65536+((_&1023)<<10|F.charCodeAt(++Y)&1023),x[f++]=240|_>>>18,x[f++]=128|_>>>12&63,x[f++]=128|_>>>6&63,x[f++]=128|_&63);F=x}else if(ee==="object"){if(F===null)throw new Error(t);if(o&&F.constructor===ArrayBuffer)F=new Uint8Array(F);else if(!Array.isArray(F)&&(!o||!ArrayBuffer.isView(F)))throw new Error(t)}else throw new Error(t);F.length>64&&(F=new k(V,!0).update(F).array());var E=[],S=[];for(Y=0;Y<64;++Y){var j=F[Y]||0;E[Y]=92^j,S[Y]=54^j}k.call(this,V,J),this.update(S),this.oKeyPad=E,this.inner=!0,this.sharedMemory=J}L.prototype=new k,L.prototype.finalize=function(){if(k.prototype.finalize.call(this),this.inner){this.inner=!1;var F=this.array();k.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(F),k.prototype.finalize.call(this)}};var $=z();$.sha256=$,$.sha224=z(!0),$.sha256.hmac=T(),$.sha224.hmac=T(!0),s?e.exports=$:(n.sha256=$.sha256,n.sha224=$.sha224)})()})(t3);var Q7=t3.exports,r3={},Ja={};Object.defineProperty(Ja,"__esModule",{value:!0});Ja.KeySize=Ja.KeyType=void 0;var lx;(function(e){e[e.ED25519=0]="ED25519",e[e.SECP256K1=1]="SECP256K1"})(lx||(Ja.KeyType=lx={}));Ja.KeySize={SECRET_KEY:32,ED25519_PUBLIC_KEY:32,SECP256k1_PUBLIC_KEY:64};var rd={},Jo={};Object.defineProperty(Jo,"__esModule",{value:!0});Jo.KeyPairBase=void 0;class J7{}Jo.KeyPairBase=J7;var zc={},Wo={},nd={};Object.defineProperty(nd,"__esModule",{value:!0});nd.DEFAULT_FUNCTION_CALL_GAS=void 0;nd.DEFAULT_FUNCTION_CALL_GAS=30000000000000n;var I1={},Dc={};const W7="Exceeded the maximum amount of gas allowed to burn per contract",eS="Method name is empty",tS="Wasmer compilation error: {{msg}}",rS="Smart contract panicked: {{panic_msg}}",nS="Error creating Wasm memory",aS="Exceeded the prepaid gas",iS="Method name is not valid UTF8 string",sS="String encoding is bad UTF-16 sequence",oS="WebAssembly trap: {{msg}}",lS="Gas instrumentation failed or contract has denied instructions.",cS="{{promise_idx}} does not correspond to existing promises",uS="Accessed invalid promise result index: {{result_idx}}",fS="Error happened while deserializing the module",dS="Contract method is not found",hS="Accessed invalid register id: {{register_id}}",pS="VM Logic returned an invalid receipt index: {{receipt_index}}",bS="Method name is empty in contract call",mS="Returning joint promise is currently prohibited",xS="Stack instrumentation failed",yS="Cannot find contract code for account {{account_id}}",gS="Invalid method signature",vS="Integer overflow happened during contract execution",wS="MemoryAccessViolation",_S="Iterator index {{iterator_index}} does not exist",SS="Iterator {{iterator_index}} was invalidated after its creation by performing a mutable operation on trie",ES="VM Logic returned an invalid account id",AS="Error happened while serializing the module",NS="Actions can only be appended to non-joint promise.",jS="Internal memory declaration has been found in the module",TS="Error happened during instantiation",MS="{{method_name}} is not allowed in view calls",CS="VM Logic returned an invalid method name",BS="String encoding is bad UTF-8 sequence",OS="Exceeded the account balance",RS="Wasm contract link error: {{msg}}",US="VM Logic provided an invalid public key",kS="Actor {{actor_id}} doesn't have permission to account {{account_id}} to complete the action",zS="The account {{account_id}} wouldn't have enough balance to cover storage, required to have {{amount}} yoctoNEAR more",DS="Wrong AccessKey used for transaction: transaction is sent to receiver_id={{tx_receiver}}, but is signed with function call access key that restricted to only use with receiver_id={{ak_receiver}}. Either change receiver_id in your transaction or switch to use a FullAccessKey.",IS="Transaction gas or balance cost is too high",LS="Transaction is not signed with the given public key",HS=`Signer "{{account_id}}" doesn't have access key with the given public_key {{public_key}}`,qS="Sender {{signer_id}} does not have enough balance {{#formatNear}}{{balance}}{{/formatNear}} for operation costing {{#formatNear}}{{cost}}{{/formatNear}}",$S="Access Key {account_id}:{public_key} does not have enough balance {{#formatNear}}{{allowance}}{{/formatNear}} for transaction costing {{#formatNear}}{{cost}}{{/formatNear}}",FS="Transaction has expired",KS="Account {{account_id}} is staking and can not be deleted",PS="Signer {{signer_id}} does not exist",GS="Account {{account_id}} tried to stake {{#formatNear}}{{stake}}{{/formatNear}}, but has staked {{#formatNear}}{{locked}}{{/formatNear}} and only has {{#formatNear}}{{balance}}{{/formatNear}}",YS="The public key {{public_key}} is already used for an existing access key",VS="Invalid signer account ID {{signer_id}} according to requirements",XS="The new account_id {{account_id}} can't be created by {{predecessor_id}}",ZS="The transaction contains more then one action, but it was signed with an access key which allows transaction to apply only one specific action. To apply more then one actions TX must be signed with a full access key",QS="Account {{account_id}} is not yet staked, but tried to unstake",JS="Transaction nonce {{tx_nonce}} must be larger than nonce of the used access key {{ak_nonce}}",WS="Can't create a new account {{account_id}}, because it already exists",eE="Transaction parent block hash doesn't belong to the current chain",tE="Can't complete the action because account {{account_id}} doesn't exist",rE="Can't complete the action because access key {{public_key}} doesn't exist",nE="Transaction method name {{method_name}} isn't allowed by the access key",aE="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover the rent",iE="Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover it's storage",sE="Invalid receiver account ID {{receiver_id}} according to requirements",oE="Account {{account_id}} tries to remove an access key that doesn't exist",lE="Timeout exceeded",cE="Connection closed",uE="Shard {{shard_id}} rejected the transaction due to congestion level {{congestion_level}}, try again later",fE="Shard {{shard_id}} rejected the transaction because it missed {{missed_chunks}} chunks and needs to recover before accepting new transactions, try again later",dE={GasLimitExceeded:W7,MethodEmptyName:eS,WasmerCompileError:tS,GuestPanic:rS,Memory:nS,GasExceeded:aS,MethodUTF8Error:iS,BadUTF16:sS,WasmTrap:oS,GasInstrumentation:lS,InvalidPromiseIndex:cS,InvalidPromiseResultIndex:uS,Deserialization:fS,MethodNotFound:dS,InvalidRegisterId:hS,InvalidReceiptIndex:pS,EmptyMethodName:bS,CannotReturnJointPromise:mS,StackHeightInstrumentation:xS,CodeDoesNotExist:yS,MethodInvalidSignature:gS,IntegerOverflow:vS,MemoryAccessViolation:wS,InvalidIteratorIndex:_S,IteratorWasInvalidated:SS,InvalidAccountId:ES,Serialization:AS,CannotAppendActionToJointPromise:NS,InternalMemoryDeclared:jS,Instantiate:TS,ProhibitedInView:MS,InvalidMethodName:CS,BadUTF8:BS,BalanceExceeded:OS,LinkError:RS,InvalidPublicKey:US,ActorNoPermission:kS,LackBalanceForState:zS,ReceiverMismatch:DS,CostOverflow:IS,InvalidSignature:LS,AccessKeyNotFound:HS,NotEnoughBalance:qS,NotEnoughAllowance:$S,Expired:FS,DeleteAccountStaking:KS,SignerDoesNotExist:PS,TriesToStake:GS,AddKeyAlreadyExists:YS,InvalidSigner:VS,CreateAccountNotAllowed:XS,RequiresFullAccess:ZS,TriesToUnstake:QS,InvalidNonce:JS,AccountAlreadyExists:WS,InvalidChain:eE,AccountDoesNotExist:tE,AccessKeyDoesNotExist:rE,MethodNameMismatch:nE,DeleteAccountHasRent:aE,DeleteAccountHasEnoughBalance:iE,InvalidReceiver:sE,DeleteKeyDoesNotExist:oE,Timeout:lE,Closed:cE,ShardCongested:uE,ShardStuck:fE};var hE=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Dc,"__esModule",{value:!0});Dc.ErrorMessages=void 0;const pE=hE(dE);Dc.ErrorMessages=pE.default;var Kn={},n3={},ad={};Object.defineProperty(ad,"__esModule",{value:!0});ad.Assignable=void 0;class bE{constructor(t){Object.keys(t).map(r=>{this[r]=t[r]})}}ad.Assignable=bE;var id={};Object.defineProperty(id,"__esModule",{value:!0});id.Enum=void 0;let mE=class{constructor(t){if(Object.keys(t).length!==1)throw new Error("Enum can only take single value");Object.keys(t).map(r=>{this[r]=t[r]})}};id.Enum=mE;var da={};Object.defineProperty(da,"__esModule",{value:!0});da.ErrorContext=da.TypedError=da.ArgumentTypeError=da.PositionalArgsError=void 0;class xE extends Error{constructor(){super("Contract method calls expect named arguments wrapped in object, e.g. { argName1: argValue1, argName2: argValue2 }")}}da.PositionalArgsError=xE;class yE extends Error{constructor(t,r,n){super(`Expected ${r} for '${t}' argument, but got '${JSON.stringify(n)}'`)}}da.ArgumentTypeError=yE;class gE extends Error{constructor(r,n,a){super(r);Bt(this,"type");Bt(this,"context");this.type=n||"UntypedError",this.context=a}}da.TypedError=gE;class vE{constructor(t){Bt(this,"transactionHash");this.transactionHash=t}}da.ErrorContext=vE;var a3={},sd={};Object.defineProperty(sd,"__esModule",{value:!0});sd.IdType=void 0;var cx;(function(e){e.Transaction="transaction",e.Receipt="receipt"})(cx||(sd.IdType=cx={}));var Ro={};Object.defineProperty(Ro,"__esModule",{value:!0});Ro.FinalExecutionStatusBasic=Ro.ExecutionStatusBasic=void 0;var ux;(function(e){e.Unknown="Unknown",e.Pending="Pending",e.Failure="Failure"})(ux||(Ro.ExecutionStatusBasic=ux={}));var fx;(function(e){e.NotStarted="NotStarted",e.Started="Started",e.Failure="Failure"})(fx||(Ro.FinalExecutionStatusBasic=fx={}));(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.FinalExecutionStatusBasic=e.ExecutionStatusBasic=e.IdType=void 0;var t=sd;Object.defineProperty(e,"IdType",{enumerable:!0,get:function(){return t.IdType}});var r=Ro;Object.defineProperty(e,"ExecutionStatusBasic",{enumerable:!0,get:function(){return r.ExecutionStatusBasic}}),Object.defineProperty(e,"FinalExecutionStatusBasic",{enumerable:!0,get:function(){return r.FinalExecutionStatusBasic}})})(a3);(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(n,a,i,s){s===void 0&&(s=i);var o=Object.getOwnPropertyDescriptor(a,i);(!o||("get"in o?!a.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(n,s,o)}:function(n,a,i,s){s===void 0&&(s=i),n[s]=a[i]}),r=Ie&&Ie.__exportStar||function(n,a){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(a,i)&&t(a,n,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(ad,e),r(id,e),r(da,e),r(a3,e)})(n3);var i3={exports:{}};(function(e,t){(function(r,n){e.exports=n()})(Ie,function(){/*! * mustache.js - Logic-less {{mustache}} templates with JavaScript * http://github.com/janl/mustache.js - */var r=Object.prototype.toString,n=Array.isArray||function(f){return r.call(f)==="[object Array]"};function a(u){return typeof u=="function"}function i(u){return n(u)?"array":typeof u}function s(u){return u.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function o(u,f){return u!=null&&typeof u=="object"&&f in u}function c(u,f){return u!=null&&typeof u!="object"&&u.hasOwnProperty&&u.hasOwnProperty(f)}var h=RegExp.prototype.test;function p(u,f){return h.call(u,f)}var y=/\S/;function g(u){return!p(y,u)}var v={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function M(u){return String(u).replace(/[&<>"'`=\/]/g,function(_){return v[_]})}var k=/\s*/,K=/\s+/,D=/\s*=/,T=/\s*\}/,z=/#|\^|\/|>|\{|&|=|!/;function L(u,f){if(!u)return[];var _=!1,E=[],S=[],j=[],R=!1,N=!1,d="",C=0;function ae(){if(R&&!N)for(;j.length;)delete S[j.pop()];else j=[];R=!1,N=!1}var he,q,G;function W(ye){if(typeof ye=="string"&&(ye=ye.split(K,2)),!n(ye)||ye.length!==2)throw new Error("Invalid tags: "+ye);he=new RegExp(s(ye[0])+"\\s*"),q=new RegExp("\\s*"+s(ye[1])),G=new RegExp("\\s*"+s("}"+ye[1]))}W(f||te.tags);for(var be=new V(u),ue,Q,le,Se,fe,ie;!be.eos();){if(ue=be.pos,le=be.scanUntil(he),le)for(var pe=0,me=le.length;pe"?fe=[Q,le,ue,be.pos,d,C,_]:fe=[Q,le,ue,be.pos],C++,S.push(fe),Q==="#"||Q==="^")E.push(fe);else if(Q==="/"){if(ie=E.pop(),!ie)throw new Error('Unopened section "'+le+'" at '+ue);if(ie[1]!==le)throw new Error('Unclosed section "'+ie[1]+'" at '+ue)}else Q==="name"||Q==="{"||Q==="&"?N=!0:Q==="="&&W(le)}if(ae(),ie=E.pop(),ie)throw new Error('Unclosed section "'+ie[1]+'" at '+be.pos);return F($(S))}function $(u){for(var f=[],_,E,S=0,j=u.length;S0?E[E.length-1][4]:f;break;default:_.push(S)}return f}function V(u){this.string=u,this.tail=u,this.pos=0}V.prototype.eos=function(){return this.tail===""},V.prototype.scan=function(f){var _=this.tail.match(f);if(!_||_.index!==0)return"";var E=_[0];return this.tail=this.tail.substring(E.length),this.pos+=E.length,E},V.prototype.scanUntil=function(f){var _=this.tail.search(f),E;switch(_){case-1:E=this.tail,this.tail="";break;case 0:E="";break;default:E=this.tail.substring(0,_),this.tail=this.tail.substring(_)}return this.pos+=E.length,E};function J(u,f){this.view=u,this.cache={".":this.view},this.parent=f}J.prototype.push=function(f){return new J(f,this)},J.prototype.lookup=function(f){var _=this.cache,E;if(_.hasOwnProperty(f))E=_[f];else{for(var S=this,j,R,N,d=!1;S;){if(f.indexOf(".")>0)for(j=S.view,R=f.split("."),N=0;j!=null&&N"?C=this.renderPartial(N,_,E,j):d==="&"?C=this.unescapedValue(N,_):d==="name"?C=this.escapedValue(N,_):d==="text"&&(C=this.rawValue(N)),C!==void 0&&(R+=C);return R},Y.prototype.renderSection=function(f,_,E,S){var j=this,R="",N=_.lookup(f[1]);function d(he){return j.render(he,_,E)}if(N){if(n(N))for(var C=0,ae=N.length;C":">",'"':""","'":"'","/":"/","`":"`","=":"="};function M(u){return String(u).replace(/[&<>"'`=\/]/g,function(_){return v[_]})}var z=/\s*/,K=/\s+/,D=/\s*=/,T=/\s*\}/,k=/#|\^|\/|>|\{|&|=|!/;function L(u,f){if(!u)return[];var _=!1,E=[],S=[],j=[],R=!1,N=!1,h="",C=0;function ae(){if(R&&!N)for(;j.length;)delete S[j.pop()];else j=[];R=!1,N=!1}var he,q,G;function W(ye){if(typeof ye=="string"&&(ye=ye.split(K,2)),!n(ye)||ye.length!==2)throw new Error("Invalid tags: "+ye);he=new RegExp(s(ye[0])+"\\s*"),q=new RegExp("\\s*"+s(ye[1])),G=new RegExp("\\s*"+s("}"+ye[1]))}W(f||ee.tags);for(var be=new V(u),ue,Q,le,Se,fe,ie;!be.eos();){if(ue=be.pos,le=be.scanUntil(he),le)for(var pe=0,me=le.length;pe"?fe=[Q,le,ue,be.pos,h,C,_]:fe=[Q,le,ue,be.pos],C++,S.push(fe),Q==="#"||Q==="^")E.push(fe);else if(Q==="/"){if(ie=E.pop(),!ie)throw new Error('Unopened section "'+le+'" at '+ue);if(ie[1]!==le)throw new Error('Unclosed section "'+ie[1]+'" at '+ue)}else Q==="name"||Q==="{"||Q==="&"?N=!0:Q==="="&&W(le)}if(ae(),ie=E.pop(),ie)throw new Error('Unclosed section "'+ie[1]+'" at '+be.pos);return F($(S))}function $(u){for(var f=[],_,E,S=0,j=u.length;S0?E[E.length-1][4]:f;break;default:_.push(S)}return f}function V(u){this.string=u,this.tail=u,this.pos=0}V.prototype.eos=function(){return this.tail===""},V.prototype.scan=function(f){var _=this.tail.match(f);if(!_||_.index!==0)return"";var E=_[0];return this.tail=this.tail.substring(E.length),this.pos+=E.length,E},V.prototype.scanUntil=function(f){var _=this.tail.search(f),E;switch(_){case-1:E=this.tail,this.tail="";break;case 0:E="";break;default:E=this.tail.substring(0,_),this.tail=this.tail.substring(_)}return this.pos+=E.length,E};function J(u,f){this.view=u,this.cache={".":this.view},this.parent=f}J.prototype.push=function(f){return new J(f,this)},J.prototype.lookup=function(f){var _=this.cache,E;if(_.hasOwnProperty(f))E=_[f];else{for(var S=this,j,R,N,h=!1;S;){if(f.indexOf(".")>0)for(j=S.view,R=f.split("."),N=0;j!=null&&N"?C=this.renderPartial(N,_,E,j):h==="&"?C=this.unescapedValue(N,_):h==="name"?C=this.escapedValue(N,_):h==="text"&&(C=this.rawValue(N)),C!==void 0&&(R+=C);return R},Y.prototype.renderSection=function(f,_,E,S){var j=this,R="",N=_.lookup(f[1]);function h(he){return j.render(he,_,E)}if(N){if(n(N))for(var C=0,ae=N.length;C0||!E)&&(j[R]=S+j[R]);return j.join(` -`)},Y.prototype.renderPartial=function(f,_,E,S){if(E){var j=a(E)?E(f[1]):E[f[1]];if(j!=null){var R=f[6],N=f[5],d=f[4],C=j;return N==0&&d&&(C=this.indentPartial(j,d,R)),this.renderTokens(this.parse(C,S),_,E,C)}}},Y.prototype.unescapedValue=function(f,_){var E=_.lookup(f[1]);if(E!=null)return E},Y.prototype.escapedValue=function(f,_){var E=_.lookup(f[1]);if(E!=null)return te.escape(E)},Y.prototype.rawValue=function(f){return f[1]};var te={name:"mustache.js",version:"4.0.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(u){x.templateCache=u},get templateCache(){return x.templateCache}},x=new Y;return te.clearCache=function(){return x.clearCache()},te.parse=function(f,_){return x.parse(f,_)},te.render=function(f,_,E,S){if(typeof f!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+i(f)+'" was given as the first argument for mustache#render(template, view, partials)');return x.render(f,_,E,S)},te.escape=M,te.Scanner=V,te.Context=J,te.Writer=Y,te})})(i3);var wE=i3.exports,L1={},s3={};(function(e){/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.bytes=e.stringToBytes=e.str=e.bytesToString=e.hex=e.utf8=e.bech32m=e.bech32=e.base58check=e.createBase58check=e.base58xmr=e.base58xrp=e.base58flickr=e.base58=e.base64urlnopad=e.base64url=e.base64nopad=e.base64=e.base32crockford=e.base32hexnopad=e.base32hex=e.base32nopad=e.base32=e.base16=e.utils=void 0;function t(q){return q instanceof Uint8Array||ArrayBuffer.isView(q)&&q.constructor.name==="Uint8Array"}function r(q,...G){if(!t(q))throw new Error("Uint8Array expected");if(G.length>0&&!G.includes(q.length))throw new Error("Uint8Array expected of length "+G+", got length="+q.length)}function n(q,G){return Array.isArray(G)?G.length===0?!0:q?G.every(W=>typeof W=="string"):G.every(W=>Number.isSafeInteger(W)):!1}function a(q){if(typeof q!="function")throw new Error("function expected");return!0}function i(q,G){if(typeof G!="string")throw new Error(`${q}: string expected`);return!0}function s(q){if(!Number.isSafeInteger(q))throw new Error(`invalid integer: ${q}`)}function o(q){if(!Array.isArray(q))throw new Error("array expected")}function c(q,G){if(!n(!0,G))throw new Error(`${q}: array of strings expected`)}function h(q,G){if(!n(!1,G))throw new Error(`${q}: array of numbers expected`)}function p(...q){const G=Q=>Q,W=(Q,le)=>Se=>Q(le(Se)),be=q.map(Q=>Q.encode).reduceRight(W,G),ue=q.map(Q=>Q.decode).reduce(W,G);return{encode:be,decode:ue}}function y(q){const G=typeof q=="string"?q.split(""):q,W=G.length;c("alphabet",G);const be=new Map(G.map((ue,Q)=>[ue,Q]));return{encode:ue=>(o(ue),ue.map(Q=>{if(!Number.isSafeInteger(Q)||Q<0||Q>=W)throw new Error(`alphabet.encode: digit index outside alphabet "${Q}". Allowed: ${q}`);return G[Q]})),decode:ue=>(o(ue),ue.map(Q=>{i("alphabet.decode",Q);const le=be.get(Q);if(le===void 0)throw new Error(`Unknown letter: "${Q}". Allowed: ${q}`);return le}))}}function g(q=""){return i("join",q),{encode:G=>(c("join.decode",G),G.join(q)),decode:G=>(i("join.decode",G),G.split(q))}}function v(q,G="="){return s(q),i("padding",G),{encode(W){for(c("padding.encode",W);W.length*q%8;)W.push(G);return W},decode(W){c("padding.decode",W);let be=W.length;if(be*q%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;be>0&&W[be-1]===G;be--)if((be-1)*q%8===0)throw new Error("padding: invalid, string has too much padding");return W.slice(0,be)}}}function M(q){return a(q),{encode:G=>G,decode:G=>q(G)}}function k(q,G,W){if(G<2)throw new Error(`convertRadix: invalid from=${G}, base cannot be less than 2`);if(W<2)throw new Error(`convertRadix: invalid to=${W}, base cannot be less than 2`);if(o(q),!q.length)return[];let be=0;const ue=[],Q=Array.from(q,Se=>{if(s(Se),Se<0||Se>=G)throw new Error(`invalid integer: ${Se}`);return Se}),le=Q.length;for(;;){let Se=0,fe=!0;for(let ie=be;ieG===0?q:K(G,q%G),D=(q,G)=>q+(G-K(q,G)),T=(()=>{let q=[];for(let G=0;G<40;G++)q.push(2**G);return q})();function z(q,G,W,be){if(o(q),G<=0||G>32)throw new Error(`convertRadix2: wrong from=${G}`);if(W<=0||W>32)throw new Error(`convertRadix2: wrong to=${W}`);if(D(G,W)>32)throw new Error(`convertRadix2: carry overflow from=${G} to=${W} carryBits=${D(G,W)}`);let ue=0,Q=0;const le=T[G],Se=T[W]-1,fe=[];for(const ie of q){if(s(ie),ie>=le)throw new Error(`convertRadix2: invalid data word=${ie} from=${G}`);if(ue=ue<32)throw new Error(`convertRadix2: carry overflow pos=${Q} from=${G}`);for(Q+=G;Q>=W;Q-=W)fe.push((ue>>Q-W&Se)>>>0);const pe=T[Q];if(pe===void 0)throw new Error("invalid carry");ue&=pe-1}if(ue=ue<=G)throw new Error("Excess padding");if(!be&&ue>0)throw new Error(`Non-zero padding: ${ue}`);return be&&Q>0&&fe.push(ue>>>0),fe}function L(q){s(q);const G=2**8;return{encode:W=>{if(!t(W))throw new Error("radix.encode input should be Uint8Array");return k(Array.from(W),G,q)},decode:W=>(h("radix.decode",W),Uint8Array.from(k(W,q,G)))}}function $(q,G=!1){if(s(q),q<=0||q>32)throw new Error("radix2: bits should be in (0..32]");if(D(8,q)>32||D(q,8)>32)throw new Error("radix2: carry overflow");return{encode:W=>{if(!t(W))throw new Error("radix2.encode input should be Uint8Array");return z(Array.from(W),8,q,!G)},decode:W=>(h("radix2.decode",W),Uint8Array.from(z(W,q,8,G)))}}function F(q){return a(q),function(...G){try{return q.apply(null,G)}catch{}}}function V(q,G){return s(q),a(G),{encode(W){if(!t(W))throw new Error("checksum.encode: input should be Uint8Array");const be=G(W).slice(0,q),ue=new Uint8Array(W.length+q);return ue.set(W),ue.set(be,W.length),ue},decode(W){if(!t(W))throw new Error("checksum.decode: input should be Uint8Array");const be=W.slice(0,-q),ue=W.slice(-q),Q=G(be).slice(0,q);for(let le=0;leq.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const J=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Y=(q,G)=>{i("base64",q);const W=G?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,be=G?"base64url":"base64";if(q.length>0&&!W.test(q))throw new Error("invalid base64");return Uint8Array.fromBase64(q,{alphabet:be,lastChunkHandling:"strict"})};e.base64=J?{encode(q){return r(q),q.toBase64()},decode(q){return Y(q,!1)}}:p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),v(6),g("")),e.base64nopad=p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),g("")),e.base64url=J?{encode(q){return r(q),q.toBase64({alphabet:"base64url"})},decode(q){return Y(q,!0)}}:p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),v(6),g("")),e.base64urlnopad=p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),g(""));const te=q=>p(L(58),y(q),g(""));e.base58=te("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),e.base58flickr=te("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),e.base58xrp=te("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const x=[0,2,3,5,6,7,9,10,11];e.base58xmr={encode(q){let G="";for(let W=0;Wp(V(4,G=>q(q(G))),e.base58);e.createBase58check=u,e.base58check=e.createBase58check;const f=p(y("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),g("")),_=[996825010,642813549,513874426,1027748829,705979059];function E(q){const G=q>>25;let W=(q&33554431)<<5;for(let be=0;be<_.length;be++)(G>>be&1)===1&&(W^=_[be]);return W}function S(q,G,W=1){const be=q.length;let ue=1;for(let Q=0;Q126)throw new Error(`Invalid prefix (${q})`);ue=E(ue)^le>>5}ue=E(ue);for(let Q=0;QCe)throw new TypeError(`Length ${Te} exceeds limit ${Ce}`);const ct=me.toLowerCase(),He=S(ct,ye,G);return`${ct}1${f.encode(ye)}${He}`}function Se(me,ye=90){i("bech32.decode input",me);const Ce=me.length;if(Ce<8||ye!==!1&&Ce>ye)throw new TypeError(`invalid string length: ${Ce} (${me}). Expected (8..${ye})`);const je=me.toLowerCase();if(me!==je&&me!==me.toUpperCase())throw new Error("String must be lowercase or uppercase");const Te=je.lastIndexOf("1");if(Te===0||Te===-1)throw new Error('Letter "1" must be present between prefix and data only');const ct=je.slice(0,Te),He=je.slice(Te+1);if(He.length<6)throw new Error("Data must be at least 6 characters long");const Le=f.decode(He).slice(0,-6),gt=S(ct,Le,G);if(!He.endsWith(gt))throw new Error(`Invalid checksum in ${me}: expected "${gt}"`);return{prefix:ct,words:Le}}const fe=F(Se);function ie(me){const{prefix:ye,words:Ce}=Se(me,!1);return{prefix:ye,words:Ce,bytes:be(Ce)}}function pe(me,ye){return le(me,ue(ye))}return{encode:le,decode:Se,encodeFromBytes:pe,decodeToBytes:ie,decodeUnsafe:fe,fromWords:be,fromWordsUnsafe:Q,toWords:ue}}e.bech32=j("bech32"),e.bech32m=j("bech32m"),e.utf8={encode:q=>new TextDecoder().decode(q),decode:q=>new TextEncoder().encode(q)};const R=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",N={encode(q){return r(q),q.toHex()},decode(q){return i("hex",q),Uint8Array.fromHex(q)}};e.hex=R?N:p($(4),y("0123456789abcdef"),g(""),M(q=>{if(typeof q!="string"||q.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof q} with length ${q.length}`);return q.toLowerCase()}));const d={utf8:e.utf8,hex:e.hex,base16:e.base16,base32:e.base32,base64:e.base64,base64url:e.base64url,base58:e.base58,base58xmr:e.base58xmr},C="Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr",ae=(q,G)=>{if(typeof q!="string"||!d.hasOwnProperty(q))throw new TypeError(C);if(!t(G))throw new TypeError("bytesToString() expects Uint8Array");return d[q].encode(G)};e.bytesToString=ae,e.str=e.bytesToString;const he=(q,G)=>{if(!d.hasOwnProperty(q))throw new TypeError(C);if(typeof G!="string")throw new TypeError("stringToBytes() expects string");return d[q].decode(G)};e.stringToBytes=he,e.bytes=e.stringToBytes})(s3);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.baseDecode=e.baseEncode=e.parseNearAmount=e.formatNearAmount=e.NEAR_NOMINATION=e.NEAR_NOMINATION_EXP=void 0;const t=s3;e.NEAR_NOMINATION_EXP=24,e.NEAR_NOMINATION=10n**BigInt(e.NEAR_NOMINATION_EXP);const r=[],n=10n;for(let g=0,v=5n;g0&&(M+=r[D])}g=M.toString();const k=g.substring(0,g.length-e.NEAR_NOMINATION_EXP)||"0",K=g.substring(g.length-e.NEAR_NOMINATION_EXP).padStart(e.NEAR_NOMINATION_EXP,"0").substring(0,v);return o(`${h(k)}.${K}`)}e.formatNearAmount=a;function i(g){if(!g)return null;g=s(g);const v=g.split("."),M=v[0],k=v[1]||"";if(v.length>2||k.length>e.NEAR_NOMINATION_EXP)throw new Error(`Cannot parse '${g}' as NEAR amount`);return c(M+k.padEnd(e.NEAR_NOMINATION_EXP,"0"))}e.parseNearAmount=i;function s(g){return g.replace(/,/g,"").trim()}function o(g){return g.replace(/\.?0*$/,"")}function c(g){return g=g.replace(/^0+/,""),g===""?"0":g}function h(g){const v=/(-?\d+)(\d{3})/;for(;v.test(g);)g=g.replace(v,"$1,$2");return g}function p(g){if(typeof g=="string"){const v=[];for(let M=0;M(e,t)=>(0,NE.formatNearAmount)(t(e))};class H1 extends EE.TypedError{}Kn.ServerError=H1;class ME extends H1{constructor(){super(...arguments);Bt(this,"transaction_outcome")}}function l3(e){const t={},r=u3(e,jE.default.schema,t,""),n=new H1(c3(r,t),r);return Object.assign(n,t),n}Kn.parseRpcError=l3;function CE(e){const t=l3(e.status.Failure),r=new ME;return Object.assign(r,t),r.type=t.type,r.message=t.message,r.transaction_outcome=e.transaction_outcome,r}Kn.parseResultError=CE;function c3(e,t){return typeof dx.ErrorMessages[e]=="string"?AE.default.render(dx.ErrorMessages[e],{...t,...TE}):JSON.stringify(t)}Kn.formatError=c3;function u3(e,t,r,n){let a,i,s;for(const o in t){if(OE(e[o]))return e[o];if(j0(e[o]))a=e[o],i=t[o],s=o;else if(j0(e.kind)&&j0(e.kind[o]))a=e.kind[o],i=t[o],s=o;else continue}if(a&&i){for(const o of Object.keys(i.props))r[o]=a[o];return u3(a,t,r,s)}else return r.kind=e,n}function BE(e,t){switch(!0){case/^account .*? does not exist while viewing$/.test(e):return"AccountDoesNotExist";case/^Account .*? doesn't exist$/.test(e):return"AccountDoesNotExist";case/^access key .*? does not exist while viewing$/.test(e):return"AccessKeyDoesNotExist";case/wasm execution failed with error: FunctionCallError\(CompilationError\(CodeDoesNotExist/.test(e):return"CodeDoesNotExist";case/wasm execution failed with error: CompilationError\(CodeDoesNotExist/.test(e):return"CodeDoesNotExist";case/wasm execution failed with error: FunctionCallError\(MethodResolveError\(MethodNotFound/.test(e):return"MethodNotFound";case/wasm execution failed with error: MethodResolveError\(MethodNotFound/.test(e):return"MethodNotFound";case/Transaction nonce \d+ must be larger than nonce of the used access key \d+/.test(e):return"InvalidNonce";default:return t}}Kn.getErrorTypeFromErrorMessage=BE;function j0(e){return Object.prototype.toString.call(e)==="[object Object]"}function OE(e){return Object.prototype.toString.call(e)==="[object String]"}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseRpcError=e.parseResultError=e.getErrorTypeFromErrorMessage=e.formatError=e.ServerError=e.ErrorMessages=void 0;var t=Dc;Object.defineProperty(e,"ErrorMessages",{enumerable:!0,get:function(){return t.ErrorMessages}});var r=Kn;Object.defineProperty(e,"ServerError",{enumerable:!0,get:function(){return r.ServerError}}),Object.defineProperty(e,"formatError",{enumerable:!0,get:function(){return r.formatError}}),Object.defineProperty(e,"getErrorTypeFromErrorMessage",{enumerable:!0,get:function(){return r.getErrorTypeFromErrorMessage}}),Object.defineProperty(e,"parseResultError",{enumerable:!0,get:function(){return r.parseResultError}}),Object.defineProperty(e,"parseRpcError",{enumerable:!0,get:function(){return r.parseRpcError}})})(I1);var Uo={},q1={},Ic={};Object.defineProperty(Ic,"__esModule",{value:!0});Ic.ConsoleLogger=void 0;class RE{constructor(t){Bt(this,"logLevels");Bt(this,"isLevelEnabled",t=>this.logLevels.includes(t));this.logLevels=t}print(t,r,...n){switch(t){case"error":case"fatal":return console.error(r,...n);case"warn":return console.warn(r,...n);case"log":return console.log(r,...n);case"debug":case"verbose":return console.debug(r,...n)}}verbose(t,...r){this.isLevelEnabled("verbose")&&this.print("verbose",t,...r)}debug(t,...r){this.isLevelEnabled("debug")&&this.print("debug",t,...r)}log(t,...r){this.isLevelEnabled("log")&&this.print("log",t,...r)}warn(t,...r){this.isLevelEnabled("warn")&&this.print("warn",t,...r)}error(t,...r){this.isLevelEnabled("error")&&this.print("error",t,...r)}fatal(t,...r){this.isLevelEnabled("fatal")&&this.print("fatal",t,...r)}}Ic.ConsoleLogger=RE;var od={};Object.defineProperty(od,"__esModule",{value:!0});od.Logger=void 0;const UE=Ic,kE=["verbose","debug","log","warn","error","fatal"],zE=new UE.ConsoleLogger(kE),Yl=class Yl{static error(t,...r){var n;(n=this.instanceRef)==null||n.error(t,...r)}static log(t,...r){var n;(n=this.instanceRef)==null||n.log(t,...r)}static warn(t,...r){var n;(n=this.instanceRef)==null||n.warn(t,...r)}static debug(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.debug)==null||a.call(n,t,...r)}static verbose(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.verbose)==null||a.call(n,t,...r)}static fatal(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.fatal)==null||a.call(n,t,...r)}};Bt(Yl,"instanceRef",zE),Bt(Yl,"overrideLogger",t=>{Yl.instanceRef=t});let ap=Yl;od.Logger=ap;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Logger=e.ConsoleLogger=void 0;var t=Ic;Object.defineProperty(e,"ConsoleLogger",{enumerable:!0,get:function(){return t.ConsoleLogger}});var r=od;Object.defineProperty(e,"Logger",{enumerable:!0,get:function(){return r.Logger}})})(q1);Object.defineProperty(Uo,"__esModule",{value:!0});Uo.printTxOutcomeLogs=Uo.printTxOutcomeLogsAndFailures=void 0;const DE=I1,ip=q1;function IE({contractId:e,outcome:t}){const r=[t.transaction_outcome,...t.receipts_outcome].reduce((n,a)=>{const i=typeof a.outcome.status=="object"&&typeof a.outcome.status.Failure=="object";return a.outcome.logs.length||i?n.concat({receiptIds:a.outcome.receipt_ids,logs:a.outcome.logs,failure:typeof a.outcome.status=="object"&&a.outcome.status.Failure!==void 0?(0,DE.parseRpcError)(a.outcome.status.Failure):null}):n},[]);for(const n of r)ip.Logger.log(`Receipt${n.receiptIds.length>1?"s":""}: ${n.receiptIds.join(", ")}`),f3({contractId:e,logs:n.logs,prefix:" "}),n.failure&&ip.Logger.warn(` Failure [${e}]: ${n.failure}`)}Uo.printTxOutcomeLogsAndFailures=IE;function f3({contractId:e,logs:t,prefix:r=""}){for(const n of t)ip.Logger.log(`${r}Log [${e}]: ${n}`)}Uo.printTxOutcomeLogs=f3;var ld={};Object.defineProperty(ld,"__esModule",{value:!0});ld.getTransactionLastResult=void 0;function LE(e){if(typeof e.status=="object"&&typeof e.status.SuccessValue=="string"){const t=Buffer.from(e.status.SuccessValue,"base64").toString();try{return JSON.parse(t)}catch{return t}}return null}ld.getTransactionLastResult=LE;var ko={};/*! +`)},Y.prototype.renderPartial=function(f,_,E,S){if(E){var j=a(E)?E(f[1]):E[f[1]];if(j!=null){var R=f[6],N=f[5],h=f[4],C=j;return N==0&&h&&(C=this.indentPartial(j,h,R)),this.renderTokens(this.parse(C,S),_,E,C)}}},Y.prototype.unescapedValue=function(f,_){var E=_.lookup(f[1]);if(E!=null)return E},Y.prototype.escapedValue=function(f,_){var E=_.lookup(f[1]);if(E!=null)return ee.escape(E)},Y.prototype.rawValue=function(f){return f[1]};var ee={name:"mustache.js",version:"4.0.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(u){x.templateCache=u},get templateCache(){return x.templateCache}},x=new Y;return ee.clearCache=function(){return x.clearCache()},ee.parse=function(f,_){return x.parse(f,_)},ee.render=function(f,_,E,S){if(typeof f!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+i(f)+'" was given as the first argument for mustache#render(template, view, partials)');return x.render(f,_,E,S)},ee.escape=M,ee.Scanner=V,ee.Context=J,ee.Writer=Y,ee})})(i3);var wE=i3.exports,L1={},s3={};(function(e){/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.bytes=e.stringToBytes=e.str=e.bytesToString=e.hex=e.utf8=e.bech32m=e.bech32=e.base58check=e.createBase58check=e.base58xmr=e.base58xrp=e.base58flickr=e.base58=e.base64urlnopad=e.base64url=e.base64nopad=e.base64=e.base32crockford=e.base32hexnopad=e.base32hex=e.base32nopad=e.base32=e.base16=e.utils=void 0;function t(q){return q instanceof Uint8Array||ArrayBuffer.isView(q)&&q.constructor.name==="Uint8Array"}function r(q,...G){if(!t(q))throw new Error("Uint8Array expected");if(G.length>0&&!G.includes(q.length))throw new Error("Uint8Array expected of length "+G+", got length="+q.length)}function n(q,G){return Array.isArray(G)?G.length===0?!0:q?G.every(W=>typeof W=="string"):G.every(W=>Number.isSafeInteger(W)):!1}function a(q){if(typeof q!="function")throw new Error("function expected");return!0}function i(q,G){if(typeof G!="string")throw new Error(`${q}: string expected`);return!0}function s(q){if(!Number.isSafeInteger(q))throw new Error(`invalid integer: ${q}`)}function o(q){if(!Array.isArray(q))throw new Error("array expected")}function c(q,G){if(!n(!0,G))throw new Error(`${q}: array of strings expected`)}function d(q,G){if(!n(!1,G))throw new Error(`${q}: array of numbers expected`)}function p(...q){const G=Q=>Q,W=(Q,le)=>Se=>Q(le(Se)),be=q.map(Q=>Q.encode).reduceRight(W,G),ue=q.map(Q=>Q.decode).reduce(W,G);return{encode:be,decode:ue}}function y(q){const G=typeof q=="string"?q.split(""):q,W=G.length;c("alphabet",G);const be=new Map(G.map((ue,Q)=>[ue,Q]));return{encode:ue=>(o(ue),ue.map(Q=>{if(!Number.isSafeInteger(Q)||Q<0||Q>=W)throw new Error(`alphabet.encode: digit index outside alphabet "${Q}". Allowed: ${q}`);return G[Q]})),decode:ue=>(o(ue),ue.map(Q=>{i("alphabet.decode",Q);const le=be.get(Q);if(le===void 0)throw new Error(`Unknown letter: "${Q}". Allowed: ${q}`);return le}))}}function g(q=""){return i("join",q),{encode:G=>(c("join.decode",G),G.join(q)),decode:G=>(i("join.decode",G),G.split(q))}}function v(q,G="="){return s(q),i("padding",G),{encode(W){for(c("padding.encode",W);W.length*q%8;)W.push(G);return W},decode(W){c("padding.decode",W);let be=W.length;if(be*q%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;be>0&&W[be-1]===G;be--)if((be-1)*q%8===0)throw new Error("padding: invalid, string has too much padding");return W.slice(0,be)}}}function M(q){return a(q),{encode:G=>G,decode:G=>q(G)}}function z(q,G,W){if(G<2)throw new Error(`convertRadix: invalid from=${G}, base cannot be less than 2`);if(W<2)throw new Error(`convertRadix: invalid to=${W}, base cannot be less than 2`);if(o(q),!q.length)return[];let be=0;const ue=[],Q=Array.from(q,Se=>{if(s(Se),Se<0||Se>=G)throw new Error(`invalid integer: ${Se}`);return Se}),le=Q.length;for(;;){let Se=0,fe=!0;for(let ie=be;ieG===0?q:K(G,q%G),D=(q,G)=>q+(G-K(q,G)),T=(()=>{let q=[];for(let G=0;G<40;G++)q.push(2**G);return q})();function k(q,G,W,be){if(o(q),G<=0||G>32)throw new Error(`convertRadix2: wrong from=${G}`);if(W<=0||W>32)throw new Error(`convertRadix2: wrong to=${W}`);if(D(G,W)>32)throw new Error(`convertRadix2: carry overflow from=${G} to=${W} carryBits=${D(G,W)}`);let ue=0,Q=0;const le=T[G],Se=T[W]-1,fe=[];for(const ie of q){if(s(ie),ie>=le)throw new Error(`convertRadix2: invalid data word=${ie} from=${G}`);if(ue=ue<32)throw new Error(`convertRadix2: carry overflow pos=${Q} from=${G}`);for(Q+=G;Q>=W;Q-=W)fe.push((ue>>Q-W&Se)>>>0);const pe=T[Q];if(pe===void 0)throw new Error("invalid carry");ue&=pe-1}if(ue=ue<=G)throw new Error("Excess padding");if(!be&&ue>0)throw new Error(`Non-zero padding: ${ue}`);return be&&Q>0&&fe.push(ue>>>0),fe}function L(q){s(q);const G=2**8;return{encode:W=>{if(!t(W))throw new Error("radix.encode input should be Uint8Array");return z(Array.from(W),G,q)},decode:W=>(d("radix.decode",W),Uint8Array.from(z(W,q,G)))}}function $(q,G=!1){if(s(q),q<=0||q>32)throw new Error("radix2: bits should be in (0..32]");if(D(8,q)>32||D(q,8)>32)throw new Error("radix2: carry overflow");return{encode:W=>{if(!t(W))throw new Error("radix2.encode input should be Uint8Array");return k(Array.from(W),8,q,!G)},decode:W=>(d("radix2.decode",W),Uint8Array.from(k(W,q,8,G)))}}function F(q){return a(q),function(...G){try{return q.apply(null,G)}catch{}}}function V(q,G){return s(q),a(G),{encode(W){if(!t(W))throw new Error("checksum.encode: input should be Uint8Array");const be=G(W).slice(0,q),ue=new Uint8Array(W.length+q);return ue.set(W),ue.set(be,W.length),ue},decode(W){if(!t(W))throw new Error("checksum.decode: input should be Uint8Array");const be=W.slice(0,-q),ue=W.slice(-q),Q=G(be).slice(0,q);for(let le=0;leq.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const J=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Y=(q,G)=>{i("base64",q);const W=G?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,be=G?"base64url":"base64";if(q.length>0&&!W.test(q))throw new Error("invalid base64");return Uint8Array.fromBase64(q,{alphabet:be,lastChunkHandling:"strict"})};e.base64=J?{encode(q){return r(q),q.toBase64()},decode(q){return Y(q,!1)}}:p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),v(6),g("")),e.base64nopad=p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),g("")),e.base64url=J?{encode(q){return r(q),q.toBase64({alphabet:"base64url"})},decode(q){return Y(q,!0)}}:p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),v(6),g("")),e.base64urlnopad=p($(6),y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),g(""));const ee=q=>p(L(58),y(q),g(""));e.base58=ee("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),e.base58flickr=ee("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),e.base58xrp=ee("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const x=[0,2,3,5,6,7,9,10,11];e.base58xmr={encode(q){let G="";for(let W=0;Wp(V(4,G=>q(q(G))),e.base58);e.createBase58check=u,e.base58check=e.createBase58check;const f=p(y("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),g("")),_=[996825010,642813549,513874426,1027748829,705979059];function E(q){const G=q>>25;let W=(q&33554431)<<5;for(let be=0;be<_.length;be++)(G>>be&1)===1&&(W^=_[be]);return W}function S(q,G,W=1){const be=q.length;let ue=1;for(let Q=0;Q126)throw new Error(`Invalid prefix (${q})`);ue=E(ue)^le>>5}ue=E(ue);for(let Q=0;QCe)throw new TypeError(`Length ${Te} exceeds limit ${Ce}`);const ct=me.toLowerCase(),He=S(ct,ye,G);return`${ct}1${f.encode(ye)}${He}`}function Se(me,ye=90){i("bech32.decode input",me);const Ce=me.length;if(Ce<8||ye!==!1&&Ce>ye)throw new TypeError(`invalid string length: ${Ce} (${me}). Expected (8..${ye})`);const je=me.toLowerCase();if(me!==je&&me!==me.toUpperCase())throw new Error("String must be lowercase or uppercase");const Te=je.lastIndexOf("1");if(Te===0||Te===-1)throw new Error('Letter "1" must be present between prefix and data only');const ct=je.slice(0,Te),He=je.slice(Te+1);if(He.length<6)throw new Error("Data must be at least 6 characters long");const Le=f.decode(He).slice(0,-6),gt=S(ct,Le,G);if(!He.endsWith(gt))throw new Error(`Invalid checksum in ${me}: expected "${gt}"`);return{prefix:ct,words:Le}}const fe=F(Se);function ie(me){const{prefix:ye,words:Ce}=Se(me,!1);return{prefix:ye,words:Ce,bytes:be(Ce)}}function pe(me,ye){return le(me,ue(ye))}return{encode:le,decode:Se,encodeFromBytes:pe,decodeToBytes:ie,decodeUnsafe:fe,fromWords:be,fromWordsUnsafe:Q,toWords:ue}}e.bech32=j("bech32"),e.bech32m=j("bech32m"),e.utf8={encode:q=>new TextDecoder().decode(q),decode:q=>new TextEncoder().encode(q)};const R=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",N={encode(q){return r(q),q.toHex()},decode(q){return i("hex",q),Uint8Array.fromHex(q)}};e.hex=R?N:p($(4),y("0123456789abcdef"),g(""),M(q=>{if(typeof q!="string"||q.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof q} with length ${q.length}`);return q.toLowerCase()}));const h={utf8:e.utf8,hex:e.hex,base16:e.base16,base32:e.base32,base64:e.base64,base64url:e.base64url,base58:e.base58,base58xmr:e.base58xmr},C="Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr",ae=(q,G)=>{if(typeof q!="string"||!h.hasOwnProperty(q))throw new TypeError(C);if(!t(G))throw new TypeError("bytesToString() expects Uint8Array");return h[q].encode(G)};e.bytesToString=ae,e.str=e.bytesToString;const he=(q,G)=>{if(!h.hasOwnProperty(q))throw new TypeError(C);if(typeof G!="string")throw new TypeError("stringToBytes() expects string");return h[q].decode(G)};e.stringToBytes=he,e.bytes=e.stringToBytes})(s3);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.baseDecode=e.baseEncode=e.parseNearAmount=e.formatNearAmount=e.NEAR_NOMINATION=e.NEAR_NOMINATION_EXP=void 0;const t=s3;e.NEAR_NOMINATION_EXP=24,e.NEAR_NOMINATION=10n**BigInt(e.NEAR_NOMINATION_EXP);const r=[],n=10n;for(let g=0,v=5n;g0&&(M+=r[D])}g=M.toString();const z=g.substring(0,g.length-e.NEAR_NOMINATION_EXP)||"0",K=g.substring(g.length-e.NEAR_NOMINATION_EXP).padStart(e.NEAR_NOMINATION_EXP,"0").substring(0,v);return o(`${d(z)}.${K}`)}e.formatNearAmount=a;function i(g){if(!g)return null;g=s(g);const v=g.split("."),M=v[0],z=v[1]||"";if(v.length>2||z.length>e.NEAR_NOMINATION_EXP)throw new Error(`Cannot parse '${g}' as NEAR amount`);return c(M+z.padEnd(e.NEAR_NOMINATION_EXP,"0"))}e.parseNearAmount=i;function s(g){return g.replace(/,/g,"").trim()}function o(g){return g.replace(/\.?0*$/,"")}function c(g){return g=g.replace(/^0+/,""),g===""?"0":g}function d(g){const v=/(-?\d+)(\d{3})/;for(;v.test(g);)g=g.replace(v,"$1,$2");return g}function p(g){if(typeof g=="string"){const v=[];for(let M=0;M(e,t)=>(0,NE.formatNearAmount)(t(e))};class H1 extends EE.TypedError{}Kn.ServerError=H1;class ME extends H1{constructor(){super(...arguments);Bt(this,"transaction_outcome")}}function l3(e){const t={},r=u3(e,jE.default.schema,t,""),n=new H1(c3(r,t),r);return Object.assign(n,t),n}Kn.parseRpcError=l3;function CE(e){const t=l3(e.status.Failure),r=new ME;return Object.assign(r,t),r.type=t.type,r.message=t.message,r.transaction_outcome=e.transaction_outcome,r}Kn.parseResultError=CE;function c3(e,t){return typeof dx.ErrorMessages[e]=="string"?AE.default.render(dx.ErrorMessages[e],{...t,...TE}):JSON.stringify(t)}Kn.formatError=c3;function u3(e,t,r,n){let a,i,s;for(const o in t){if(OE(e[o]))return e[o];if(j0(e[o]))a=e[o],i=t[o],s=o;else if(j0(e.kind)&&j0(e.kind[o]))a=e.kind[o],i=t[o],s=o;else continue}if(a&&i){for(const o of Object.keys(i.props))r[o]=a[o];return u3(a,t,r,s)}else return r.kind=e,n}function BE(e,t){switch(!0){case/^account .*? does not exist while viewing$/.test(e):return"AccountDoesNotExist";case/^Account .*? doesn't exist$/.test(e):return"AccountDoesNotExist";case/^access key .*? does not exist while viewing$/.test(e):return"AccessKeyDoesNotExist";case/wasm execution failed with error: FunctionCallError\(CompilationError\(CodeDoesNotExist/.test(e):return"CodeDoesNotExist";case/wasm execution failed with error: CompilationError\(CodeDoesNotExist/.test(e):return"CodeDoesNotExist";case/wasm execution failed with error: FunctionCallError\(MethodResolveError\(MethodNotFound/.test(e):return"MethodNotFound";case/wasm execution failed with error: MethodResolveError\(MethodNotFound/.test(e):return"MethodNotFound";case/Transaction nonce \d+ must be larger than nonce of the used access key \d+/.test(e):return"InvalidNonce";default:return t}}Kn.getErrorTypeFromErrorMessage=BE;function j0(e){return Object.prototype.toString.call(e)==="[object Object]"}function OE(e){return Object.prototype.toString.call(e)==="[object String]"}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseRpcError=e.parseResultError=e.getErrorTypeFromErrorMessage=e.formatError=e.ServerError=e.ErrorMessages=void 0;var t=Dc;Object.defineProperty(e,"ErrorMessages",{enumerable:!0,get:function(){return t.ErrorMessages}});var r=Kn;Object.defineProperty(e,"ServerError",{enumerable:!0,get:function(){return r.ServerError}}),Object.defineProperty(e,"formatError",{enumerable:!0,get:function(){return r.formatError}}),Object.defineProperty(e,"getErrorTypeFromErrorMessage",{enumerable:!0,get:function(){return r.getErrorTypeFromErrorMessage}}),Object.defineProperty(e,"parseResultError",{enumerable:!0,get:function(){return r.parseResultError}}),Object.defineProperty(e,"parseRpcError",{enumerable:!0,get:function(){return r.parseRpcError}})})(I1);var Uo={},q1={},Ic={};Object.defineProperty(Ic,"__esModule",{value:!0});Ic.ConsoleLogger=void 0;class RE{constructor(t){Bt(this,"logLevels");Bt(this,"isLevelEnabled",t=>this.logLevels.includes(t));this.logLevels=t}print(t,r,...n){switch(t){case"error":case"fatal":return console.error(r,...n);case"warn":return console.warn(r,...n);case"log":return console.log(r,...n);case"debug":case"verbose":return console.debug(r,...n)}}verbose(t,...r){this.isLevelEnabled("verbose")&&this.print("verbose",t,...r)}debug(t,...r){this.isLevelEnabled("debug")&&this.print("debug",t,...r)}log(t,...r){this.isLevelEnabled("log")&&this.print("log",t,...r)}warn(t,...r){this.isLevelEnabled("warn")&&this.print("warn",t,...r)}error(t,...r){this.isLevelEnabled("error")&&this.print("error",t,...r)}fatal(t,...r){this.isLevelEnabled("fatal")&&this.print("fatal",t,...r)}}Ic.ConsoleLogger=RE;var od={};Object.defineProperty(od,"__esModule",{value:!0});od.Logger=void 0;const UE=Ic,kE=["verbose","debug","log","warn","error","fatal"],zE=new UE.ConsoleLogger(kE),Yl=class Yl{static error(t,...r){var n;(n=this.instanceRef)==null||n.error(t,...r)}static log(t,...r){var n;(n=this.instanceRef)==null||n.log(t,...r)}static warn(t,...r){var n;(n=this.instanceRef)==null||n.warn(t,...r)}static debug(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.debug)==null||a.call(n,t,...r)}static verbose(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.verbose)==null||a.call(n,t,...r)}static fatal(t,...r){var n,a;(a=(n=this.instanceRef)==null?void 0:n.fatal)==null||a.call(n,t,...r)}};Bt(Yl,"instanceRef",zE),Bt(Yl,"overrideLogger",t=>{Yl.instanceRef=t});let ap=Yl;od.Logger=ap;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Logger=e.ConsoleLogger=void 0;var t=Ic;Object.defineProperty(e,"ConsoleLogger",{enumerable:!0,get:function(){return t.ConsoleLogger}});var r=od;Object.defineProperty(e,"Logger",{enumerable:!0,get:function(){return r.Logger}})})(q1);Object.defineProperty(Uo,"__esModule",{value:!0});Uo.printTxOutcomeLogs=Uo.printTxOutcomeLogsAndFailures=void 0;const DE=I1,ip=q1;function IE({contractId:e,outcome:t}){const r=[t.transaction_outcome,...t.receipts_outcome].reduce((n,a)=>{const i=typeof a.outcome.status=="object"&&typeof a.outcome.status.Failure=="object";return a.outcome.logs.length||i?n.concat({receiptIds:a.outcome.receipt_ids,logs:a.outcome.logs,failure:typeof a.outcome.status=="object"&&a.outcome.status.Failure!==void 0?(0,DE.parseRpcError)(a.outcome.status.Failure):null}):n},[]);for(const n of r)ip.Logger.log(`Receipt${n.receiptIds.length>1?"s":""}: ${n.receiptIds.join(", ")}`),f3({contractId:e,logs:n.logs,prefix:" "}),n.failure&&ip.Logger.warn(` Failure [${e}]: ${n.failure}`)}Uo.printTxOutcomeLogsAndFailures=IE;function f3({contractId:e,logs:t,prefix:r=""}){for(const n of t)ip.Logger.log(`${r}Log [${e}]: ${n}`)}Uo.printTxOutcomeLogs=f3;var ld={};Object.defineProperty(ld,"__esModule",{value:!0});ld.getTransactionLastResult=void 0;function LE(e){if(typeof e.status=="object"&&typeof e.status.SuccessValue=="string"){const t=Buffer.from(e.status.SuccessValue,"base64").toString();try{return JSON.parse(t)}catch{return t}}return null}ld.getTransactionLastResult=LE;var ko={};/*! * depd * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed - */var HE=qE;function qE(e){if(!e)throw new TypeError("argument namespace is required");function t(r){}return t._file=void 0,t._ignored=!0,t._namespace=e,t._traced=!1,t._warned=Object.create(null),t.function=$E,t.property=FE,t}function $E(e,t){if(typeof e!="function")throw new TypeError("argument fn must be a function");return e}function FE(e,t,r){if(!e||typeof e!="object"&&typeof e!="function")throw new TypeError("argument obj must be object");var n=Object.getOwnPropertyDescriptor(e,t);if(!n)throw new TypeError("must call property on owner object");if(!n.configurable)throw new TypeError("property must be configurable")}var Lc={};Object.defineProperty(Lc,"__esModule",{value:!0});Lc.sortBigIntAsc=void 0;function KE(e,t){return et?1:0}Lc.sortBigIntAsc=KE;var PE=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ko,"__esModule",{value:!0});ko.diffEpochValidators=ko.findSeatPrice=void 0;const GE=PE(HE),d3=Lc;function YE(e,t,r,n){return n&&n<49?VE(e,t):(r||((0,GE.default)("findSeatPrice(validators, maxNumberOfSeats)")("`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead"),r=[1,6250]),XE(e,t,r))}ko.findSeatPrice=YE;function VE(e,t){const r=e.map(o=>BigInt(o.stake)).sort(d3.sortBigIntAsc),n=BigInt(t),a=r.reduce((o,c)=>o+c);if(a=n){i=o,c=!0;break}c||(s=o)}return i}function XE(e,t,r){if(r.length!=2)throw Error("minimumStakeRatio should have 2 elements");const n=e.map(i=>BigInt(i.stake)).sort(d3.sortBigIntAsc),a=n.reduce((i,s)=>i+s);return e.lengthr.set(a.account_id,a));const n=new Set(t.map(a=>a.account_id));return{newValidators:t.filter(a=>!r.has(a.account_id)),removedValidators:e.filter(a=>!n.has(a.account_id)),changedValidators:t.filter(a=>r.has(a.account_id)&&r.get(a.account_id).stake!=a.stake).map(a=>({current:r.get(a.account_id),next:a}))}}ko.diffEpochValidators=ZE;(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(n,a,i,s){s===void 0&&(s=i);var o=Object.getOwnPropertyDescriptor(a,i);(!o||("get"in o?!a.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(n,s,o)}:function(n,a,i,s){s===void 0&&(s=i),n[s]=a[i]}),r=Ie&&Ie.__exportStar||function(n,a){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(a,i)&&t(a,n,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(nd,e),r(I1,e),r(L1,e),r(Uo,e),r(ld,e),r(ko,e),r(q1,e),r(Lc,e)})(Wo);var $1={},Er={},Is={},Xi={};Object.defineProperty(Xi,"__esModule",{value:!0});Xi.anumber=sp;Xi.abytes=h3;Xi.ahash=JE;Xi.aexists=WE;Xi.aoutput=eA;function sp(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function QE(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function h3(e,...t){if(!QE(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function JE(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");sp(e.outputLen),sp(e.blockLen)}function WE(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 eA(e,t){h3(e);const r=t.outputLen;if(e.length>>u}function c(x,u){return x<>>32-u>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function h(x){return x<<24&4278190080|x<<8&16711680|x>>>8&65280|x>>>24&255}e.byteSwapIfBE=e.isLE?x=>x:x=>h(x);function p(x){for(let u=0;uu.toString(16).padStart(2,"0"));function g(x){(0,r.abytes)(x);let u="";for(let f=0;f=v._0&&x<=v._9)return x-v._0;if(x>=v.A&&x<=v.F)return x-(v.A-10);if(x>=v.a&&x<=v.f)return x-(v.a-10)}function k(x){if(typeof x!="string")throw new Error("hex string expected, got "+typeof x);const u=x.length,f=u/2;if(u%2)throw new Error("hex string expected, got unpadded hex of length "+u);const _=new Uint8Array(f);for(let E=0,S=0;E{};e.nextTick=K;async function D(x,u,f){let _=Date.now();for(let E=0;E=0&&Sx().update(z(_)).digest(),f=x();return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=()=>x(),u}function J(x){const u=(_,E)=>x(E).update(z(_)).digest(),f=x({});return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=_=>x(_),u}function Y(x){const u=(_,E)=>x(E).update(z(_)).digest(),f=x({});return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=_=>x(_),u}function te(x=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(x));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(x);throw new Error("crypto.getRandomValues must be defined")}})(cd);Object.defineProperty(Is,"__esModule",{value:!0});Is.HashMD=void 0;Is.setBigUint64=p3;Is.Chi=tA;Is.Maj=rA;const T0=Xi,yl=cd;function p3(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const a=BigInt(32),i=BigInt(4294967295),s=Number(r>>a&i),o=Number(r&i),c=n?4:0,h=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+h,o,n)}function tA(e,t,r){return e&t^~e&r}function rA(e,t,r){return e&t^e&r^t&r}class nA extends yl.Hash{constructor(t,r,n,a){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=a,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,yl.createView)(this.buffer)}update(t){(0,T0.aexists)(this);const{view:r,buffer:n,blockLen:a}=this;t=(0,yl.toBytes)(t);const i=t.length;for(let s=0;sa-s&&(this.process(n,0),s=0);for(let y=s;yp.length)throw new Error("_sha2: outputLen bigger than state");for(let y=0;y>op&du)}:{h:Number(e>>op&du)|0,l:Number(e&du)|0}}function b3(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let a=0;aBigInt(e>>>0)<>>0);We.toBig=m3;const x3=(e,t,r)=>e>>>r;We.shrSH=x3;const y3=(e,t,r)=>e<<32-r|t>>>r;We.shrSL=y3;const g3=(e,t,r)=>e>>>r|t<<32-r;We.rotrSH=g3;const v3=(e,t,r)=>e<<32-r|t>>>r;We.rotrSL=v3;const w3=(e,t,r)=>e<<64-r|t>>>r-32;We.rotrBH=w3;const _3=(e,t,r)=>e>>>r-32|t<<64-r;We.rotrBL=_3;const S3=(e,t)=>t;We.rotr32H=S3;const E3=(e,t)=>e;We.rotr32L=E3;const A3=(e,t,r)=>e<>>32-r;We.rotlSH=A3;const N3=(e,t,r)=>t<>>32-r;We.rotlSL=N3;const j3=(e,t,r)=>t<>>64-r;We.rotlBH=j3;const T3=(e,t,r)=>e<>>64-r;We.rotlBL=T3;function M3(e,t,r,n){const a=(t>>>0)+(n>>>0);return{h:e+r+(a/2**32|0)|0,l:a|0}}const C3=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0);We.add3L=C3;const B3=(e,t,r,n)=>t+r+n+(e/2**32|0)|0;We.add3H=B3;const O3=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0);We.add4L=O3;const R3=(e,t,r,n,a)=>t+r+n+a+(e/2**32|0)|0;We.add4H=R3;const U3=(e,t,r,n,a)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(a>>>0);We.add5L=U3;const k3=(e,t,r,n,a,i)=>t+r+n+a+i+(e/2**32|0)|0;We.add5H=k3;const aA={fromBig:F1,split:b3,toBig:m3,shrSH:x3,shrSL:y3,rotrSH:g3,rotrSL:v3,rotrBH:w3,rotrBL:_3,rotr32H:S3,rotr32L:E3,rotlSH:A3,rotlSL:N3,rotlBH:j3,rotlBL:T3,add:M3,add3L:C3,add3H:B3,add4L:O3,add4H:R3,add5H:k3,add5L:U3};We.default=aA;Object.defineProperty(Er,"__esModule",{value:!0});Er.sha384=Er.sha512_256=Er.sha512_224=Er.sha512=Er.SHA384=Er.SHA512_256=Er.SHA512_224=Er.SHA512=void 0;const iA=Is,lt=We,fd=cd,[sA,oA]=lt.default.split(["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))),ai=new Uint32Array(80),ii=new Uint32Array(80);let Hc=class extends iA.HashMD{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:r,Bh:n,Bl:a,Ch:i,Cl:s,Dh:o,Dl:c,Eh:h,El:p,Fh:y,Fl:g,Gh:v,Gl:M,Hh:k,Hl:K}=this;return[t,r,n,a,i,s,o,c,h,p,y,g,v,M,k,K]}set(t,r,n,a,i,s,o,c,h,p,y,g,v,M,k,K){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=a|0,this.Ch=i|0,this.Cl=s|0,this.Dh=o|0,this.Dl=c|0,this.Eh=h|0,this.El=p|0,this.Fh=y|0,this.Fl=g|0,this.Gh=v|0,this.Gl=M|0,this.Hh=k|0,this.Hl=K|0}process(t,r){for(let z=0;z<16;z++,r+=4)ai[z]=t.getUint32(r),ii[z]=t.getUint32(r+=4);for(let z=16;z<80;z++){const L=ai[z-15]|0,$=ii[z-15]|0,F=lt.default.rotrSH(L,$,1)^lt.default.rotrSH(L,$,8)^lt.default.shrSH(L,$,7),V=lt.default.rotrSL(L,$,1)^lt.default.rotrSL(L,$,8)^lt.default.shrSL(L,$,7),J=ai[z-2]|0,Y=ii[z-2]|0,te=lt.default.rotrSH(J,Y,19)^lt.default.rotrBH(J,Y,61)^lt.default.shrSH(J,Y,6),x=lt.default.rotrSL(J,Y,19)^lt.default.rotrBL(J,Y,61)^lt.default.shrSL(J,Y,6),u=lt.default.add4L(V,x,ii[z-7],ii[z-16]),f=lt.default.add4H(u,F,te,ai[z-7],ai[z-16]);ai[z]=f|0,ii[z]=u|0}let{Ah:n,Al:a,Bh:i,Bl:s,Ch:o,Cl:c,Dh:h,Dl:p,Eh:y,El:g,Fh:v,Fl:M,Gh:k,Gl:K,Hh:D,Hl:T}=this;for(let z=0;z<80;z++){const L=lt.default.rotrSH(y,g,14)^lt.default.rotrSH(y,g,18)^lt.default.rotrBH(y,g,41),$=lt.default.rotrSL(y,g,14)^lt.default.rotrSL(y,g,18)^lt.default.rotrBL(y,g,41),F=y&v^~y&k,V=g&M^~g&K,J=lt.default.add5L(T,$,V,oA[z],ii[z]),Y=lt.default.add5H(J,D,L,F,sA[z],ai[z]),te=J|0,x=lt.default.rotrSH(n,a,28)^lt.default.rotrBH(n,a,34)^lt.default.rotrBH(n,a,39),u=lt.default.rotrSL(n,a,28)^lt.default.rotrBL(n,a,34)^lt.default.rotrBL(n,a,39),f=n&i^n&o^i&o,_=a&s^a&c^s&c;D=k|0,T=K|0,k=v|0,K=M|0,v=y|0,M=g|0,{h:y,l:g}=lt.default.add(h|0,p|0,Y|0,te|0),h=o|0,p=c|0,o=i|0,c=s|0,i=n|0,s=a|0;const E=lt.default.add3L(te,u,_);n=lt.default.add3H(E,Y,x,f),a=E|0}({h:n,l:a}=lt.default.add(this.Ah|0,this.Al|0,n|0,a|0)),{h:i,l:s}=lt.default.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:o,l:c}=lt.default.add(this.Ch|0,this.Cl|0,o|0,c|0),{h,l:p}=lt.default.add(this.Dh|0,this.Dl|0,h|0,p|0),{h:y,l:g}=lt.default.add(this.Eh|0,this.El|0,y|0,g|0),{h:v,l:M}=lt.default.add(this.Fh|0,this.Fl|0,v|0,M|0),{h:k,l:K}=lt.default.add(this.Gh|0,this.Gl|0,k|0,K|0),{h:D,l:T}=lt.default.add(this.Hh|0,this.Hl|0,D|0,T|0),this.set(n,a,i,s,o,c,h,p,y,g,v,M,k,K,D,T)}roundClean(){ai.fill(0),ii.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Er.SHA512=Hc;class z3 extends Hc{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}Er.SHA512_224=z3;class D3 extends Hc{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}Er.SHA512_256=D3;let I3=class extends Hc{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}};Er.SHA384=I3;Er.sha512=(0,fd.wrapConstructor)(()=>new Hc);Er.sha512_224=(0,fd.wrapConstructor)(()=>new z3);Er.sha512_256=(0,fd.wrapConstructor)(()=>new D3);Er.sha384=(0,fd.wrapConstructor)(()=>new I3);var Ls={},It={},xt={};/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(xt,"__esModule",{value:!0});xt.notImplemented=xt.bitMask=void 0;xt.isBytes=pd;xt.abytes=bd;xt.abool=cA;xt.bytesToHex=K1;xt.numberToHexUnpadded=L3;xt.hexToNumber=P1;xt.hexToBytes=md;xt.bytesToNumberBE=fA;xt.bytesToNumberLE=dA;xt.numberToBytesBE=H3;xt.numberToBytesLE=hA;xt.numberToVarBytesBE=pA;xt.ensureBytes=bA;xt.concatBytes=q3;xt.equalBytes=mA;xt.utf8ToBytes=xA;xt.inRange=$3;xt.aInRange=yA;xt.bitLen=gA;xt.bitGet=vA;xt.bitSet=wA;xt.createHmacDrbg=SA;xt.validateObject=AA;xt.memoized=jA;const dd=BigInt(0),hd=BigInt(1),lA=BigInt(2);function pd(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function bd(e){if(!pd(e))throw new Error("Uint8Array expected")}function cA(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}const uA=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function K1(e){bd(e);let t="";for(let r=0;r=Ra._0&&e<=Ra._9)return e-Ra._0;if(e>=Ra.A&&e<=Ra.F)return e-(Ra.A-10);if(e>=Ra.a&&e<=Ra.f)return e-(Ra.a-10)}function md(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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 a=0,i=0;atypeof e=="bigint"&&dd<=e;function $3(e,t,r){return M0(e)&&M0(t)&&M0(r)&&t<=e&&edd;e>>=hd,t+=1);return t}function vA(e,t){return e>>BigInt(t)&hd}function wA(e,t,r){return e|(r?hd:dd)<(lA<new Uint8Array(e),px=e=>Uint8Array.from(e);function SA(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=C0(e),a=C0(e),i=0;const s=()=>{n.fill(1),a.fill(0),i=0},o=(...y)=>r(a,n,...y),c=(y=C0())=>{a=o(px([0]),y),n=o(),y.length!==0&&(a=o(px([1]),y),n=o())},h=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let y=0;const g=[];for(;y{s(),c(y);let v;for(;!(v=g(h()));)c();return s(),v}}const EA={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||pd(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function AA(e,t,r={}){const n=(a,i,s)=>{const o=EA[i];if(typeof o!="function")throw new Error("invalid validator function");const c=e[a];if(!(s&&c===void 0)&&!o(c,e))throw new Error("param "+String(a)+" is invalid. Expected "+i+", got "+c)};for(const[a,i]of Object.entries(t))n(a,i,!1);for(const[a,i]of Object.entries(r))n(a,i,!0);return e}const NA=()=>{throw new Error("not implemented")};xt.notImplemented=NA;function jA(e){const t=new WeakMap;return(r,...n)=>{const a=t.get(r);if(a!==void 0)return a;const i=e(r,...n);return t.set(r,i),i}}Object.defineProperty(It,"__esModule",{value:!0});It.isNegativeLE=void 0;It.mod=yn;It.pow=F3;It.pow2=MA;It.invert=Sf;It.tonelliShanks=K3;It.FpSqrt=P3;It.validateField=OA;It.FpPow=G3;It.FpInvertBatch=Y3;It.FpDiv=RA;It.FpLegendre=V3;It.FpIsSquare=UA;It.nLength=G1;It.Field=kA;It.FpSqrtOdd=zA;It.FpSqrtEven=DA;It.hashToPrivateScalar=IA;It.getFieldBytesLength=Y1;It.getMinHashLength=X3;It.mapHashToField=LA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _n=xt,jr=BigInt(0),Ft=BigInt(1),xi=BigInt(2),TA=BigInt(3),lp=BigInt(4),bx=BigInt(5),mx=BigInt(8);function yn(e,t){const r=e%t;return r>=jr?r:t+r}function F3(e,t,r){if(tjr;)t&Ft&&(n=n*e%r),e=e*e%r,t>>=Ft;return n}function MA(e,t,r){let n=e;for(;t-- >jr;)n*=n,n%=r;return n}function Sf(e,t){if(e===jr)throw new Error("invert: expected non-zero number");if(t<=jr)throw new Error("invert: expected positive modulus, got "+t);let r=yn(e,t),n=t,a=jr,i=Ft;for(;r!==jr;){const o=n/r,c=n%r,h=a-i*o;n=r,r=c,a=i,i=h}if(n!==Ft)throw new Error("invert: does not exist");return yn(a,t)}function K3(e){const t=(e-Ft)/xi;let r,n,a;for(r=e-Ft,n=0;r%xi===jr;r/=xi,n++);for(a=xi;a1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const s=(e+Ft)/lp;return function(c,h){const p=c.pow(h,s);if(!c.eql(c.sqr(p),h))throw new Error("Cannot find square root");return p}}const i=(r+Ft)/xi;return function(o,c){if(o.pow(c,t)===o.neg(o.ONE))throw new Error("Cannot find square root");let h=n,p=o.pow(o.mul(o.ONE,a),r),y=o.pow(c,i),g=o.pow(c,r);for(;!o.eql(g,o.ONE);){if(o.eql(g,o.ZERO))return o.ZERO;let v=1;for(let k=o.sqr(g);v(yn(e,t)&Ft)===Ft;It.isNegativeLE=CA;const BA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function OA(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=BA.reduce((n,a)=>(n[a]="function",n),t);return(0,_n.validateObject)(e,r)}function G3(e,t,r){if(rjr;)r&Ft&&(n=e.mul(n,a)),a=e.sqr(a),r>>=Ft;return n}function Y3(e,t){const r=new Array(t.length),n=t.reduce((i,s,o)=>e.is0(s)?i:(r[o]=i,e.mul(i,s)),e.ONE),a=e.inv(n);return t.reduceRight((i,s,o)=>e.is0(s)?i:(r[o]=e.mul(i,r[o]),e.mul(i,s)),a),r}function RA(e,t,r){return e.mul(t,typeof r=="bigint"?Sf(r,e.ORDER):e.inv(r))}function V3(e){const t=(e-Ft)/xi;return(r,n)=>r.pow(n,t)}function UA(e){const t=V3(e.ORDER);return r=>{const n=t(e,r);return e.eql(n,e.ZERO)||e.eql(n,e.ONE)}}function G1(e,t){const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function kA(e,t,r=!1,n={}){if(e<=jr)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:a,nByteLength:i}=G1(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s;const o=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:i,MASK:(0,_n.bitMask)(a),ZERO:jr,ONE:Ft,create:c=>yn(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return jr<=c&&cc===jr,isOdd:c=>(c&Ft)===Ft,neg:c=>yn(-c,e),eql:(c,h)=>c===h,sqr:c=>yn(c*c,e),add:(c,h)=>yn(c+h,e),sub:(c,h)=>yn(c-h,e),mul:(c,h)=>yn(c*h,e),pow:(c,h)=>G3(o,c,h),div:(c,h)=>yn(c*Sf(h,e),e),sqrN:c=>c*c,addN:(c,h)=>c+h,subN:(c,h)=>c-h,mulN:(c,h)=>c*h,inv:c=>Sf(c,e),sqrt:n.sqrt||(c=>(s||(s=P3(e)),s(o,c))),invertBatch:c=>Y3(o,c),cmov:(c,h,p)=>p?h:c,toBytes:c=>r?(0,_n.numberToBytesLE)(c,i):(0,_n.numberToBytesBE)(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?(0,_n.bytesToNumberLE)(c):(0,_n.bytesToNumberBE)(c)}});return Object.freeze(o)}function zA(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?r:e.neg(r)}function DA(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?e.neg(r):r}function IA(e,t,r=!1){e=(0,_n.ensureBytes)("privateHash",e);const n=e.length,a=G1(t).nByteLength+8;if(a<24||n1024)throw new Error("hashToPrivateScalar: expected "+a+"-1024 bytes of input, got "+n);const i=r?(0,_n.bytesToNumberLE)(e):(0,_n.bytesToNumberBE)(e);return yn(i,t-Ft)+Ft}function Y1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function X3(e){const t=Y1(e);return t+Math.ceil(t/2)}function LA(e,t,r=!1){const n=e.length,a=Y1(t),i=X3(t);if(n<16||n1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);const s=r?(0,_n.bytesToNumberLE)(e):(0,_n.bytesToNumberBE)(e),o=yn(s,t-Ft)+Ft;return r?(0,_n.numberToBytesLE)(o,a):(0,_n.numberToBytesBE)(o,a)}Object.defineProperty(Ls,"__esModule",{value:!0});Ls.wNAF=HA;Ls.pippenger=qA;Ls.precomputeMSMUnsafe=$A;Ls.validateBasic=FA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const xx=It,Z3=xt,yx=BigInt(0),hu=BigInt(1);function B0(e,t){const r=t.negate();return e?r:t}function V1(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function O0(e,t){V1(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Q3(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function J3(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}const R0=new WeakMap,W3=new WeakMap;function U0(e){return W3.get(e)||1}function HA(e,t){return{constTimeNegate:B0,hasPrecomputes(r){return U0(r)!==1},unsafeLadder(r,n,a=e.ZERO){let i=r;for(;n>yx;)n&hu&&(a=a.add(i)),i=i.double(),n>>=hu;return a},precomputeWindow(r,n){const{windows:a,windowSize:i}=O0(n,t),s=[];let o=r,c=o;for(let h=0;h>=y,M>s&&(M-=p,a+=hu);const k=v,K=v+Math.abs(M)-1,D=g%2!==0,T=M<0;M===0?c=c.add(B0(D,n[k])):o=o.add(B0(T,n[K]))}return{p:o,f:c}},wNAFUnsafe(r,n,a,i=e.ZERO){const{windows:s,windowSize:o}=O0(r,t),c=BigInt(2**r-1),h=2**r,p=BigInt(r);for(let y=0;y>=p,v>o&&(v-=h,a+=hu),v===0)continue;let M=n[g+Math.abs(v)-1];v<0&&(M=M.negate()),i=i.add(M)}return i},getPrecomputes(r,n,a){let i=R0.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&R0.set(n,a(i))),i},wNAFCached(r,n,a){const i=U0(r);return this.wNAF(i,this.getPrecomputes(i,r,a),n)},wNAFCachedUnsafe(r,n,a,i){const s=U0(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,a),n,i)},setWindowSize(r,n){V1(n,t),W3.set(r,n),R0.delete(r)}}}function qA(e,t,r,n){if(Q3(r,e),J3(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const a=e.ZERO,i=(0,Z3.bitLen)(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,o=(1<=0;y-=s){c.fill(a);for(let v=0;v>BigInt(y)&BigInt(o));c[k]=c[k].add(r[v])}let g=a;for(let v=c.length-1,M=a;v>0;v--)M=M.add(c[v]),g=g.add(M);if(p=p.add(g),y!==0)for(let v=0;v{const p=[];for(let y=0,g=h;y{if(J3(h,t),h.length>r.length)throw new Error("array of scalars must be smaller than array of points");let p=a;for(let y=0;y>g&o);k&&(p=p.add(c[v][k-1]))}}return p}}function FA(e){return(0,xx.validateField)(e.Fp),(0,Z3.validateObject)(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,xx.nLength)(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var X1={};Object.defineProperty(X1,"__esModule",{value:!0});X1.twistedEdwards=YA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const cp=Ls,gx=It,nn=xt,tn=xt,Wn=BigInt(0),rn=BigInt(1),pu=BigInt(2),KA=BigInt(8),PA={zip215:!0};function GA(e){const t=(0,cp.validateBasic)(e);return nn.validateObject(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function YA(e){const t=GA(e),{Fp:r,n,prehash:a,hash:i,randomBytes:s,nByteLength:o,h:c}=t,h=pu<{try{return{isValid:!0,value:r.sqrt(S*r.inv(j))}}catch{return{isValid:!1,value:Wn}}}),v=t.adjustScalarBytes||(S=>S),M=t.domain||((S,j,R)=>{if((0,tn.abool)("phflag",R),j.length||R)throw new Error("Contexts/pre-hash are not supported");return S});function k(S,j){nn.aInRange("coordinate "+S,j,Wn,h)}function K(S){if(!(S instanceof z))throw new Error("ExtendedPoint expected")}const D=(0,tn.memoized)((S,j)=>{const{ex:R,ey:N,ez:d}=S,C=S.is0();j==null&&(j=C?KA:r.inv(d));const ae=p(R*j),he=p(N*j),q=p(d*j);if(C)return{x:Wn,y:rn};if(q!==rn)throw new Error("invZ was invalid");return{x:ae,y:he}}),T=(0,tn.memoized)(S=>{const{a:j,d:R}=t;if(S.is0())throw new Error("bad point: ZERO");const{ex:N,ey:d,ez:C,et:ae}=S,he=p(N*N),q=p(d*d),G=p(C*C),W=p(G*G),be=p(he*j),ue=p(G*p(be+q)),Q=p(W+p(R*p(he*q)));if(ue!==Q)throw new Error("bad point: equation left != right (1)");const le=p(N*d),Se=p(C*ae);if(le!==Se)throw new Error("bad point: equation left != right (2)");return!0});class z{constructor(j,R,N,d){this.ex=j,this.ey=R,this.ez=N,this.et=d,k("x",j),k("y",R),k("z",N),k("t",d),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(j){if(j instanceof z)throw new Error("extended point not allowed");const{x:R,y:N}=j||{};return k("x",R),k("y",N),new z(R,N,rn,p(R*N))}static normalizeZ(j){const R=r.invertBatch(j.map(N=>N.ez));return j.map((N,d)=>N.toAffine(R[d])).map(z.fromAffine)}static msm(j,R){return(0,cp.pippenger)(z,y,j,R)}_setWindowSize(j){F.setWindowSize(this,j)}assertValidity(){T(this)}equals(j){K(j);const{ex:R,ey:N,ez:d}=this,{ex:C,ey:ae,ez:he}=j,q=p(R*he),G=p(C*d),W=p(N*he),be=p(ae*d);return q===G&&W===be}is0(){return this.equals(z.ZERO)}negate(){return new z(p(-this.ex),this.ey,this.ez,p(-this.et))}double(){const{a:j}=t,{ex:R,ey:N,ez:d}=this,C=p(R*R),ae=p(N*N),he=p(pu*p(d*d)),q=p(j*C),G=R+N,W=p(p(G*G)-C-ae),be=q+ae,ue=be-he,Q=q-ae,le=p(W*ue),Se=p(be*Q),fe=p(W*Q),ie=p(ue*be);return new z(le,Se,ie,fe)}add(j){K(j);const{a:R,d:N}=t,{ex:d,ey:C,ez:ae,et:he}=this,{ex:q,ey:G,ez:W,et:be}=j;if(R===BigInt(-1)){const ct=p((C-d)*(G+q)),He=p((C+d)*(G-q)),Le=p(He-ct);if(Le===Wn)return this.double();const gt=p(ae*pu*be),rt=p(he*pu*W),et=rt+gt,dr=He+ct,B=rt-gt,m=p(et*Le),w=p(dr*B),H=p(et*B),X=p(Le*dr);return new z(m,w,X,H)}const ue=p(d*q),Q=p(C*G),le=p(he*N*be),Se=p(ae*W),fe=p((d+C)*(q+G)-ue-Q),ie=Se-le,pe=Se+le,me=p(Q-R*ue),ye=p(fe*ie),Ce=p(pe*me),je=p(fe*me),Te=p(ie*pe);return new z(ye,Ce,Te,je)}subtract(j){return this.add(j.negate())}wNAF(j){return F.wNAFCached(this,j,z.normalizeZ)}multiply(j){const R=j;nn.aInRange("scalar",R,rn,n);const{p:N,f:d}=this.wNAF(R);return z.normalizeZ([N,d])[0]}multiplyUnsafe(j,R=z.ZERO){const N=j;return nn.aInRange("scalar",N,Wn,n),N===Wn?$:this.is0()||N===rn?this:F.wNAFCachedUnsafe(this,N,z.normalizeZ,R)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return F.unsafeLadder(this,n).is0()}toAffine(j){return D(this,j)}clearCofactor(){const{h:j}=t;return j===rn?this:this.multiplyUnsafe(j)}static fromHex(j,R=!1){const{d:N,a:d}=t,C=r.BYTES;j=(0,tn.ensureBytes)("pointHex",j,C),(0,tn.abool)("zip215",R);const ae=j.slice(),he=j[C-1];ae[C-1]=he&-129;const q=nn.bytesToNumberLE(ae),G=R?h:r.ORDER;nn.aInRange("pointHex.y",q,Wn,G);const W=p(q*q),be=p(W-rn),ue=p(N*W-d);let{isValid:Q,value:le}=g(be,ue);if(!Q)throw new Error("Point.fromHex: invalid y coordinate");const Se=(le&rn)===rn,fe=(he&128)!==0;if(!R&&le===Wn&&fe)throw new Error("Point.fromHex: x=0 and x_0=1");return fe!==Se&&(le=p(-le)),z.fromAffine({x:le,y:q})}static fromPrivateKey(j){return Y(j).point}toRawBytes(){const{x:j,y:R}=this.toAffine(),N=nn.numberToBytesLE(R,r.BYTES);return N[N.length-1]|=j&rn?128:0,N}toHex(){return nn.bytesToHex(this.toRawBytes())}}z.BASE=new z(t.Gx,t.Gy,rn,p(t.Gx*t.Gy)),z.ZERO=new z(Wn,rn,rn,Wn);const{BASE:L,ZERO:$}=z,F=(0,cp.wNAF)(z,o*8);function V(S){return(0,gx.mod)(S,n)}function J(S){return V(nn.bytesToNumberLE(S))}function Y(S){const j=r.BYTES;S=(0,tn.ensureBytes)("private key",S,j);const R=(0,tn.ensureBytes)("hashed private key",i(S),2*j),N=v(R.slice(0,j)),d=R.slice(j,2*j),C=J(N),ae=L.multiply(C),he=ae.toRawBytes();return{head:N,prefix:d,scalar:C,point:ae,pointBytes:he}}function te(S){return Y(S).pointBytes}function x(S=new Uint8Array,...j){const R=nn.concatBytes(...j);return J(i(M(R,(0,tn.ensureBytes)("context",S),!!a)))}function u(S,j,R={}){S=(0,tn.ensureBytes)("message",S),a&&(S=a(S));const{prefix:N,scalar:d,pointBytes:C}=Y(j),ae=x(R.context,N,S),he=L.multiply(ae).toRawBytes(),q=x(R.context,he,C,S),G=V(ae+q*d);nn.aInRange("signature.s",G,Wn,n);const W=nn.concatBytes(he,nn.numberToBytesLE(G,r.BYTES));return(0,tn.ensureBytes)("result",W,r.BYTES*2)}const f=PA;function _(S,j,R,N=f){const{context:d,zip215:C}=N,ae=r.BYTES;S=(0,tn.ensureBytes)("signature",S,2*ae),j=(0,tn.ensureBytes)("message",j),R=(0,tn.ensureBytes)("publicKey",R,ae),C!==void 0&&(0,tn.abool)("zip215",C),a&&(j=a(j));const he=nn.bytesToNumberLE(S.slice(ae,2*ae));let q,G,W;try{q=z.fromHex(R,C),G=z.fromHex(S.slice(0,ae),C),W=L.multiplyUnsafe(he)}catch{return!1}if(!C&&q.isSmallOrder())return!1;const be=x(d,G.toRawBytes(),q.toRawBytes(),j);return G.add(q.multiplyUnsafe(be)).subtract(W).clearCofactor().equals(z.ZERO)}return L._setWindowSize(8),{CURVE:t,getPublicKey:te,sign:u,verify:_,ExtendedPoint:z,utils:{getExtendedPublicKey:Y,randomPrivateKey:()=>s(r.BYTES),precompute(S=8,j=z.BASE){return j._setWindowSize(S),j.multiply(BigInt(3)),j}}}}var Hs={};Object.defineProperty(Hs,"__esModule",{value:!0});Hs.expand_message_xmd=e6;Hs.expand_message_xof=t6;Hs.hash_to_field=up;Hs.isogenyMap=QA;Hs.createHasher=JA;const VA=It,Fr=xt,XA=Fr.bytesToNumberBE;function fi(e,t){if(pc(e),pc(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function ZA(e,t){const r=new Uint8Array(e.length);for(let n=0;n255&&(t=n((0,Fr.concatBytes)((0,Fr.utf8ToBytes)("H2C-OVERSIZE-DST-"),t)));const{outputLen:a,blockLen:i}=n,s=Math.ceil(r/a);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");const o=(0,Fr.concatBytes)(t,fi(t.length,1)),c=fi(0,i),h=fi(r,2),p=new Array(s),y=n((0,Fr.concatBytes)(c,e,h,fi(0,1),o));p[0]=n((0,Fr.concatBytes)(y,fi(1,1),o));for(let v=1;v<=s;v++){const M=[ZA(y,p[v-1]),fi(v+1,1),o];p[v]=n((0,Fr.concatBytes)(...M))}return(0,Fr.concatBytes)(...p).slice(0,r)}function t6(e,t,r,n,a){if((0,Fr.abytes)(e),(0,Fr.abytes)(t),pc(r),t.length>255){const i=Math.ceil(2*n/8);t=a.create({dkLen:i}).update((0,Fr.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(t).digest()}if(r>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return a.create({dkLen:r}).update(e).update(fi(r,2)).update(t).update(fi(t.length,1)).digest()}function up(e,t,r){(0,Fr.validateObject)(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:n,k:a,m:i,hash:s,expand:o,DST:c}=r;(0,Fr.abytes)(e),pc(t);const h=typeof c=="string"?(0,Fr.utf8ToBytes)(c):c,p=n.toString(2).length,y=Math.ceil((p+a)/8),g=t*i*y;let v;if(o==="xmd")v=e6(e,h,g,s);else if(o==="xof")v=t6(e,h,g,a,s);else if(o==="_internal_pass")v=e;else throw new Error('expand must be "xmd" or "xof"');const M=new Array(t);for(let k=0;kArray.from(n).reverse());return(n,a)=>{const[i,s,o,c]=r.map(h=>h.reduce((p,y)=>e.add(e.mul(p,n),y)));return n=e.div(i,s),a=e.mul(a,e.div(o,c)),{x:n,y:a}}}function JA(e,t,r){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(n,a){const i=up(n,2,{...r,DST:r.DST,...a}),s=e.fromAffine(t(i[0])),o=e.fromAffine(t(i[1])),c=s.add(o).clearCofactor();return c.assertValidity(),c},encodeToCurve(n,a){const i=up(n,1,{...r,DST:r.encodeDST,...a}),s=e.fromAffine(t(i[0])).clearCofactor();return s.assertValidity(),s},mapToCurve(n){if(!Array.isArray(n))throw new Error("mapToCurve: expected array of bigints");for(const i of n)if(typeof i!="bigint")throw new Error("mapToCurve: expected array of bigints");const a=e.fromAffine(t(n)).clearCofactor();return a.assertValidity(),a}}}var Z1={};Object.defineProperty(Z1,"__esModule",{value:!0});Z1.montgomery=eN;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const vx=It,li=xt,Ys=BigInt(0),k0=BigInt(1);function WA(e){return(0,li.validateObject)(e,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...e})}function eN(e){const t=WA(e),{P:r}=t,n=T=>(0,vx.mod)(T,r),a=t.montgomeryBits,i=Math.ceil(a/8),s=t.nByteLength,o=t.adjustScalarBytes||(T=>T),c=t.powPminus2||(T=>(0,vx.pow)(T,r-BigInt(2),r));function h(T,z,L){const $=n(T*(z-L));return z=n(z-$),L=n(L+$),[z,L]}const p=(t.a-BigInt(2))/BigInt(4);function y(T,z){(0,li.aInRange)("u",T,Ys,r),(0,li.aInRange)("scalar",z,Ys,r);const L=z,$=T;let F=k0,V=Ys,J=T,Y=k0,te=Ys,x;for(let f=BigInt(a-1);f>=Ys;f--){const _=L>>f&k0;te^=_,x=h(te,F,J),F=x[0],J=x[1],x=h(te,V,Y),V=x[0],Y=x[1],te=_;const E=F+V,S=n(E*E),j=F-V,R=n(j*j),N=S-R,d=J+Y,C=J-Y,ae=n(C*E),he=n(d*j),q=ae+he,G=ae-he;J=n(q*q),Y=n($*n(G*G)),F=n(S*R),V=n(N*(S+n(p*N)))}x=h(te,F,J),F=x[0],J=x[1],x=h(te,V,Y),V=x[0],Y=x[1];const u=c(V);return n(F*u)}function g(T){return(0,li.numberToBytesLE)(n(T),i)}function v(T){const z=(0,li.ensureBytes)("u coordinate",T,i);return s===32&&(z[31]&=127),(0,li.bytesToNumberLE)(z)}function M(T){const z=(0,li.ensureBytes)("scalar",T),L=z.length;if(L!==i&&L!==s){let $=""+i+" or "+s;throw new Error("invalid scalar, expected "+$+" bytes, got "+L)}return(0,li.bytesToNumberLE)(o(z))}function k(T,z){const L=v(z),$=M(T),F=y(L,$);if(F===Ys)throw new Error("invalid private or public key received");return g(F)}const K=g(t.Gu);function D(T){return k(T,K)}return{scalarMult:k,scalarMultBase:D,getSharedSecret:(T,z)=>k(T,z),getPublicKey:T=>D(T),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:K}}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hash_to_ristretto255=e.hashToRistretto255=e.RistrettoPoint=e.encodeToCurve=e.hashToCurve=e.edwardsToMontgomery=e.x25519=e.ed25519ph=e.ed25519ctx=e.ed25519=e.ED25519_TORSION_SUBGROUP=void 0,e.edwardsToMontgomeryPub=V,e.edwardsToMontgomeryPriv=J;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Er,r=cd,n=Ls,a=X1,i=Hs,s=It,o=Z1,c=xt,h=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),p=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),y=BigInt(0),g=BigInt(1),v=BigInt(2),M=BigInt(3),k=BigInt(5),K=BigInt(8);function D(ue){const Q=BigInt(10),le=BigInt(20),Se=BigInt(40),fe=BigInt(80),ie=h,me=ue*ue%ie*ue%ie,ye=(0,s.pow2)(me,v,ie)*me%ie,Ce=(0,s.pow2)(ye,g,ie)*ue%ie,je=(0,s.pow2)(Ce,k,ie)*Ce%ie,Te=(0,s.pow2)(je,Q,ie)*je%ie,ct=(0,s.pow2)(Te,le,ie)*Te%ie,He=(0,s.pow2)(ct,Se,ie)*ct%ie,Le=(0,s.pow2)(He,fe,ie)*He%ie,gt=(0,s.pow2)(Le,fe,ie)*He%ie,rt=(0,s.pow2)(gt,Q,ie)*je%ie;return{pow_p_5_8:(0,s.pow2)(rt,v,ie)*ue%ie,b2:me}}function T(ue){return ue[0]&=248,ue[31]&=127,ue[31]|=64,ue}function z(ue,Q){const le=h,Se=(0,s.mod)(Q*Q*Q,le),fe=(0,s.mod)(Se*Se*Q,le),ie=D(ue*fe).pow_p_5_8;let pe=(0,s.mod)(ue*Se*ie,le);const me=(0,s.mod)(Q*pe*pe,le),ye=pe,Ce=(0,s.mod)(pe*p,le),je=me===ue,Te=me===(0,s.mod)(-ue,le),ct=me===(0,s.mod)(-ue*p,le);return je&&(pe=ye),(Te||ct)&&(pe=Ce),(0,s.isNegativeLE)(pe,le)&&(pe=(0,s.mod)(-pe,le)),{isValid:je||Te,value:pe}}e.ED25519_TORSION_SUBGROUP=["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"];const L=(0,s.Field)(h,void 0,!0),$={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:L,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:K,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:t.sha512,randomBytes:r.randomBytes,adjustScalarBytes:T,uvRatio:z};e.ed25519=(0,a.twistedEdwards)($);function F(ue,Q,le){if(Q.length>255)throw new Error("Context is too big");return(0,r.concatBytes)((0,r.utf8ToBytes)("SigEd25519 no Ed25519 collisions"),new Uint8Array([le?1:0,Q.length]),Q,ue)}e.ed25519ctx=(0,a.twistedEdwards)({...$,domain:F}),e.ed25519ph=(0,a.twistedEdwards)(Object.assign({},$,{domain:F,prehash:t.sha512})),e.x25519=(0,o.montgomery)({P:h,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:ue=>{const Q=h,{pow_p_5_8:le,b2:Se}=D(ue);return(0,s.mod)((0,s.pow2)(le,M,Q)*Se,Q)},adjustScalarBytes:T,randomBytes:r.randomBytes});function V(ue){const{y:Q}=e.ed25519.ExtendedPoint.fromHex(ue),le=BigInt(1);return L.toBytes(L.create((le+Q)*L.inv(le-Q)))}e.edwardsToMontgomery=V;function J(ue){const Q=$.hash(ue.subarray(0,32));return $.adjustScalarBytes(Q).subarray(0,32)}const Y=(L.ORDER+M)/K,te=L.pow(v,Y),x=L.sqrt(L.neg(L.ONE));function u(ue){const Q=(L.ORDER-k)/K,le=BigInt(486662);let Se=L.sqr(ue);Se=L.mul(Se,v);let fe=L.add(Se,L.ONE),ie=L.neg(le),pe=L.sqr(fe),me=L.mul(pe,fe),ye=L.mul(Se,le);ye=L.mul(ye,ie),ye=L.add(ye,pe),ye=L.mul(ye,ie);let Ce=L.sqr(me);pe=L.sqr(Ce),Ce=L.mul(Ce,me),Ce=L.mul(Ce,ye),pe=L.mul(pe,Ce);let je=L.pow(pe,Q);je=L.mul(je,Ce);let Te=L.mul(je,x);pe=L.sqr(je),pe=L.mul(pe,me);let ct=L.eql(pe,ye),He=L.cmov(Te,je,ct),Le=L.mul(ie,Se),gt=L.mul(je,ue);gt=L.mul(gt,te);let rt=L.mul(gt,x),et=L.mul(ye,Se);pe=L.sqr(gt),pe=L.mul(pe,me);let dr=L.eql(pe,et),B=L.cmov(rt,gt,dr);pe=L.sqr(He),pe=L.mul(pe,me);let m=L.eql(pe,ye),w=L.cmov(Le,ie,m),H=L.cmov(B,He,m),X=L.isOdd(H);return H=L.cmov(H,L.neg(H),m!==X),{xMn:w,xMd:fe,yMn:H,yMd:g}}const f=(0,s.FpSqrtEven)(L,L.neg(BigInt(486664)));function _(ue){const{xMn:Q,xMd:le,yMn:Se,yMd:fe}=u(ue);let ie=L.mul(Q,fe);ie=L.mul(ie,f);let pe=L.mul(le,Se),me=L.sub(Q,le),ye=L.add(Q,le),Ce=L.mul(pe,ye),je=L.eql(Ce,L.ZERO);ie=L.cmov(ie,L.ZERO,je),pe=L.cmov(pe,L.ONE,je),me=L.cmov(me,L.ONE,je),ye=L.cmov(ye,L.ONE,je);const Te=L.invertBatch([pe,ye]);return{x:L.mul(ie,Te[0]),y:L.mul(me,Te[1])}}const E=(0,i.createHasher)(e.ed25519.ExtendedPoint,ue=>_(ue[0]),{DST:"edwards25519_XMD:SHA-512_ELL2_RO_",encodeDST:"edwards25519_XMD:SHA-512_ELL2_NU_",p:L.ORDER,m:1,k:128,expand:"xmd",hash:t.sha512});e.hashToCurve=E.hashToCurve,e.encodeToCurve=E.encodeToCurve;function S(ue){if(!(ue instanceof W))throw new Error("RistrettoPoint expected")}const j=p,R=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),N=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),d=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),C=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ae=ue=>z(g,ue),he=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),q=ue=>e.ed25519.CURVE.Fp.create((0,c.bytesToNumberLE)(ue)&he);function G(ue){const{d:Q}=e.ed25519.CURVE,le=e.ed25519.CURVE.Fp.ORDER,Se=e.ed25519.CURVE.Fp.create,fe=Se(j*ue*ue),ie=Se((fe+g)*d);let pe=BigInt(-1);const me=Se((pe-Q*fe)*Se(fe+Q));let{isValid:ye,value:Ce}=z(ie,me),je=Se(Ce*ue);(0,s.isNegativeLE)(je,le)||(je=Se(-je)),ye||(Ce=je),ye||(pe=fe);const Te=Se(pe*(fe-g)*C-me),ct=Ce*Ce,He=Se((Ce+Ce)*me),Le=Se(Te*R),gt=Se(g-ct),rt=Se(g+ct);return new e.ed25519.ExtendedPoint(Se(He*rt),Se(gt*Le),Se(Le*rt),Se(He*gt))}class W{constructor(Q){this.ep=Q}static fromAffine(Q){return new W(e.ed25519.ExtendedPoint.fromAffine(Q))}static hashToCurve(Q){Q=(0,c.ensureBytes)("ristrettoHash",Q,64);const le=q(Q.slice(0,32)),Se=G(le),fe=q(Q.slice(32,64)),ie=G(fe);return new W(Se.add(ie))}static fromHex(Q){Q=(0,c.ensureBytes)("ristrettoHex",Q,32);const{a:le,d:Se}=e.ed25519.CURVE,fe=e.ed25519.CURVE.Fp.ORDER,ie=e.ed25519.CURVE.Fp.create,pe="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",me=q(Q);if(!(0,c.equalBytes)((0,c.numberToBytesLE)(me,32),Q)||(0,s.isNegativeLE)(me,fe))throw new Error(pe);const ye=ie(me*me),Ce=ie(g+le*ye),je=ie(g-le*ye),Te=ie(Ce*Ce),ct=ie(je*je),He=ie(le*Se*Te-ct),{isValid:Le,value:gt}=ae(ie(He*ct)),rt=ie(gt*je),et=ie(gt*rt*He);let dr=ie((me+me)*rt);(0,s.isNegativeLE)(dr,fe)&&(dr=ie(-dr));const B=ie(Ce*et),m=ie(dr*B);if(!Le||(0,s.isNegativeLE)(m,fe)||B===y)throw new Error(pe);return new W(new e.ed25519.ExtendedPoint(dr,B,g,m))}static msm(Q,le){const Se=(0,s.Field)(e.ed25519.CURVE.n,e.ed25519.CURVE.nBitLength);return(0,n.pippenger)(W,Se,Q,le)}toRawBytes(){let{ex:Q,ey:le,ez:Se,et:fe}=this.ep;const ie=e.ed25519.CURVE.Fp.ORDER,pe=e.ed25519.CURVE.Fp.create,me=pe(pe(Se+le)*pe(Se-le)),ye=pe(Q*le),Ce=pe(ye*ye),{value:je}=ae(pe(me*Ce)),Te=pe(je*me),ct=pe(je*ye),He=pe(Te*ct*fe);let Le;if((0,s.isNegativeLE)(fe*He,ie)){let rt=pe(le*j),et=pe(Q*j);Q=rt,le=et,Le=pe(Te*N)}else Le=ct;(0,s.isNegativeLE)(Q*He,ie)&&(le=pe(-le));let gt=pe((Se-le)*Le);return(0,s.isNegativeLE)(gt,ie)&&(gt=pe(-gt)),(0,c.numberToBytesLE)(gt,32)}toHex(){return(0,c.bytesToHex)(this.toRawBytes())}toString(){return this.toHex()}equals(Q){S(Q);const{ex:le,ey:Se}=this.ep,{ex:fe,ey:ie}=Q.ep,pe=e.ed25519.CURVE.Fp.create,me=pe(le*ie)===pe(Se*fe),ye=pe(Se*ie)===pe(le*fe);return me||ye}add(Q){return S(Q),new W(this.ep.add(Q.ep))}subtract(Q){return S(Q),new W(this.ep.subtract(Q.ep))}multiply(Q){return new W(this.ep.multiply(Q))}multiplyUnsafe(Q){return new W(this.ep.multiplyUnsafe(Q))}double(){return new W(this.ep.double())}negate(){return new W(this.ep.negate())}}e.RistrettoPoint=(W.BASE||(W.BASE=new W(e.ed25519.ExtendedPoint.BASE)),W.ZERO||(W.ZERO=new W(e.ed25519.ExtendedPoint.ZERO)),W);const be=(ue,Q)=>{const le=Q.DST,Se=typeof le=="string"?(0,r.utf8ToBytes)(le):le,fe=(0,i.expand_message_xmd)(ue,Se,64,t.sha512);return W.hashToCurve(fe)};e.hashToRistretto255=be,e.hash_to_ristretto255=e.hashToRistretto255})($1);var fp={exports:{}},dp={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh */(function(e,t){var r=_f,n=r.Buffer;function a(s,o){for(var c in s)o[c]=s[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(a(r,t),t.Buffer=i);function i(s,o,c){return n(s,o,c)}i.prototype=Object.create(n.prototype),a(n,i),i.from=function(s,o,c){if(typeof s=="number")throw new TypeError("Argument must not be a number");return n(s,o,c)},i.alloc=function(s,o,c){if(typeof s!="number")throw new TypeError("Argument must be a number");var h=n(s);return o!==void 0?typeof c=="string"?h.fill(o,c):h.fill(o):h.fill(0),h},i.allocUnsafe=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return n(s)},i.allocUnsafeSlow=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(s)}})(dp,dp.exports);var tN=dp.exports,z0=65536,rN=4294967295;function nN(){throw new Error(`Secure random number generation is not supported by this browser. -Use Chrome, Firefox or Internet Explorer 11`)}var aN=tN.Buffer,Ef=Ie.crypto||Ie.msCrypto;Ef&&Ef.getRandomValues?fp.exports=iN:fp.exports=nN;function iN(e,t){if(e>rN)throw new RangeError("requested too many random bytes");var r=aN.allocUnsafe(e);if(e>0)if(e>z0)for(var n=0;nnew Uint8Array(r),t){return typeof e=="function"&&(e=e(t)),Et("output",e,t),e}function Js(e){return Object.prototype.toString.call(e).slice(8,-1)}var sN=e=>({contextRandomize(t){switch(Dn(t===null||t instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),t!==null&&Et("seed",t,32),e.contextRandomize(t)){case 1:throw new Error(Tt.CONTEXT_RANDOMIZE_UNKNOW)}},privateKeyVerify(t){return Et("private key",t,32),e.privateKeyVerify(t)===0},privateKeyNegate(t){switch(Et("private key",t,32),e.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(Tt.IMPOSSIBLE_CASE)}},privateKeyTweakAdd(t,r){switch(Et("private key",t,32),Et("tweak",r,32),e.privateKeyTweakAdd(t,r)){case 0:return t;case 1:throw new Error(Tt.TWEAK_ADD)}},privateKeyTweakMul(t,r){switch(Et("private key",t,32),Et("tweak",r,32),e.privateKeyTweakMul(t,r)){case 0:return t;case 1:throw new Error(Tt.TWEAK_MUL)}},publicKeyVerify(t){return Et("public key",t,[33,65]),e.publicKeyVerify(t)===0},publicKeyCreate(t,r=!0,n){switch(Et("private key",t,32),es(r),n=ea(n,r?33:65),e.publicKeyCreate(n,t)){case 0:return n;case 1:throw new Error(Tt.SECKEY_INVALID);case 2:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyConvert(t,r=!0,n){switch(Et("public key",t,[33,65]),es(r),n=ea(n,r?33:65),e.publicKeyConvert(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyNegate(t,r=!0,n){switch(Et("public key",t,[33,65]),es(r),n=ea(n,r?33:65),e.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE);case 3:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyCombine(t,r=!0,n){Dn(Array.isArray(t),"Expected public keys to be an Array"),Dn(t.length>0,"Expected public keys array will have more than zero items");for(const a of t)Et("public key",a,[33,65]);switch(es(r),n=ea(n,r?33:65),e.publicKeyCombine(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.PUBKEY_COMBINE);case 3:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyTweakAdd(t,r,n=!0,a){switch(Et("public key",t,[33,65]),Et("tweak",r,32),es(n),a=ea(a,n?33:65),e.publicKeyTweakAdd(a,t,r)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.TWEAK_ADD)}},publicKeyTweakMul(t,r,n=!0,a){switch(Et("public key",t,[33,65]),Et("tweak",r,32),es(n),a=ea(a,n?33:65),e.publicKeyTweakMul(a,t,r)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.TWEAK_MUL)}},signatureNormalize(t){switch(Et("signature",t,64),e.signatureNormalize(t)){case 0:return t;case 1:throw new Error(Tt.SIG_PARSE)}},signatureExport(t,r){Et("signature",t,64),r=ea(r,72);const n={output:r,outputlen:72};switch(e.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},signatureImport(t,r){switch(Et("signature",t),r=ea(r,64),e.signatureImport(r,t)){case 0:return r;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdsaSign(t,r,n={},a){Et("message",t,32),Et("private key",r,32),Dn(Js(n)==="Object","Expected options to be an Object"),n.data!==void 0&&Et("options.data",n.data),n.noncefn!==void 0&&Dn(Js(n.noncefn)==="Function","Expected options.noncefn to be a Function"),a=ea(a,64);const i={signature:a,recid:null};switch(e.ecdsaSign(i,t,r,n.data,n.noncefn)){case 0:return i;case 1:throw new Error(Tt.SIGN);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdsaVerify(t,r,n){switch(Et("signature",t,64),Et("message",r,32),Et("public key",n,[33,65]),e.ecdsaVerify(t,r,n)){case 0:return!0;case 3:return!1;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.PUBKEY_PARSE)}},ecdsaRecover(t,r,n,a=!0,i){switch(Et("signature",t,64),Dn(Js(r)==="Number"&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),Et("message",n,32),es(a),i=ea(i,a?33:65),e.ecdsaRecover(i,t,r,n)){case 0:return i;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.RECOVER);case 3:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdh(t,r,n={},a){switch(Et("public key",t,[33,65]),Et("private key",r,32),Dn(Js(n)==="Object","Expected options to be an Object"),n.data!==void 0&&Et("options.data",n.data),n.hashfn!==void 0?(Dn(Js(n.hashfn)==="Function","Expected options.hashfn to be a Function"),n.xbuf!==void 0&&Et("options.xbuf",n.xbuf,32),n.ybuf!==void 0&&Et("options.ybuf",n.ybuf,32),Et("output",a)):a=ea(a,32),e.ecdh(a,t,r,n.data,n.hashfn,n.xbuf,n.ybuf)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.ECDH)}}}),n6={};const oN="6.6.1",lN={version:oN};var Bn={},Q1={exports:{}};Q1.exports;(function(e){(function(t,r){function n(x,u){if(!x)throw new Error(u||"Assertion failed")}function a(x,u){x.super_=u;var f=function(){};f.prototype=u.prototype,x.prototype=new f,x.prototype.constructor=x}function i(x,u,f){if(i.isBN(x))return x;this.negative=0,this.words=null,this.length=0,this.red=null,x!==null&&((u==="le"||u==="be")&&(f=u,u=10),this._init(x||0,u||10,f||"be"))}typeof t=="object"?t.exports=i:r.BN=i,i.BN=i,i.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=hc.Buffer}catch{}i.isBN=function(u){return u instanceof i?!0:u!==null&&typeof u=="object"&&u.constructor.wordSize===i.wordSize&&Array.isArray(u.words)},i.max=function(u,f){return u.cmp(f)>0?u:f},i.min=function(u,f){return u.cmp(f)<0?u:f},i.prototype._init=function(u,f,_){if(typeof u=="number")return this._initNumber(u,f,_);if(typeof u=="object")return this._initArray(u,f,_);f==="hex"&&(f=16),n(f===(f|0)&&f>=2&&f<=36),u=u.toString().replace(/\s+/g,"");var E=0;u[0]==="-"&&(E++,this.negative=1),E=0;E-=3)j=u[E]|u[E-1]<<8|u[E-2]<<16,this.words[S]|=j<>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);else if(_==="le")for(E=0,S=0;E>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);return this.strip()};function o(x,u){var f=x.charCodeAt(u);return f>=65&&f<=70?f-55:f>=97&&f<=102?f-87:f-48&15}function c(x,u,f){var _=o(x,f);return f-1>=u&&(_|=o(x,f-1)<<4),_}i.prototype._parseHex=function(u,f,_){this.length=Math.ceil((u.length-f)/6),this.words=new Array(this.length);for(var E=0;E=f;E-=2)R=c(u,f,E)<=18?(S-=18,j+=1,this.words[j]|=R>>>26):S+=8;else{var N=u.length-f;for(E=N%2===0?f+1:f;E=18?(S-=18,j+=1,this.words[j]|=R>>>26):S+=8}this.strip()};function h(x,u,f,_){for(var E=0,S=Math.min(x.length,f),j=u;j=49?E+=R-49+10:R>=17?E+=R-17+10:E+=R}return E}i.prototype._parseBase=function(u,f,_){this.words=[0],this.length=1;for(var E=0,S=1;S<=67108863;S*=f)E++;E--,S=S/f|0;for(var j=u.length-_,R=j%E,N=Math.min(j,j-R)+_,d=0,C=_;C1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?""};var p=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],y=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],g=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(u,f){u=u||10,f=f|0||1;var _;if(u===16||u==="hex"){_="";for(var E=0,S=0,j=0;j>>24-E&16777215,E+=2,E>=26&&(E-=26,j--),S!==0||j!==this.length-1?_=p[6-N.length]+N+_:_=N+_}for(S!==0&&(_=S.toString(16)+_);_.length%f!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}if(u===(u|0)&&u>=2&&u<=36){var d=y[u],C=g[u];_="";var ae=this.clone();for(ae.negative=0;!ae.isZero();){var he=ae.modn(C).toString(u);ae=ae.idivn(C),ae.isZero()?_=he+_:_=p[d-he.length]+he+_}for(this.isZero()&&(_="0"+_);_.length%f!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}n(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var u=this.words[0];return this.length===2?u+=this.words[1]*67108864:this.length===3&&this.words[2]===1?u+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-u:u},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(u,f){return n(typeof s<"u"),this.toArrayLike(s,u,f)},i.prototype.toArray=function(u,f){return this.toArrayLike(Array,u,f)},i.prototype.toArrayLike=function(u,f,_){var E=this.byteLength(),S=_||Math.max(1,E);n(E<=S,"byte array longer than desired length"),n(S>0,"Requested array length <= 0"),this.strip();var j=f==="le",R=new u(S),N,d,C=this.clone();if(j){for(d=0;!C.isZero();d++)N=C.andln(255),C.iushrn(8),R[d]=N;for(;d=4096&&(_+=13,f>>>=13),f>=64&&(_+=7,f>>>=7),f>=8&&(_+=4,f>>>=4),f>=2&&(_+=2,f>>>=2),_+f},i.prototype._zeroBits=function(u){if(u===0)return 26;var f=u,_=0;return f&8191||(_+=13,f>>>=13),f&127||(_+=7,f>>>=7),f&15||(_+=4,f>>>=4),f&3||(_+=2,f>>>=2),f&1||_++,_},i.prototype.bitLength=function(){var u=this.words[this.length-1],f=this._countBits(u);return(this.length-1)*26+f};function v(x){for(var u=new Array(x.bitLength()),f=0;f>>E}return u}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var u=0,f=0;fu.length?this.clone().ior(u):u.clone().ior(this)},i.prototype.uor=function(u){return this.length>u.length?this.clone().iuor(u):u.clone().iuor(this)},i.prototype.iuand=function(u){var f;this.length>u.length?f=u:f=this;for(var _=0;_u.length?this.clone().iand(u):u.clone().iand(this)},i.prototype.uand=function(u){return this.length>u.length?this.clone().iuand(u):u.clone().iuand(this)},i.prototype.iuxor=function(u){var f,_;this.length>u.length?(f=this,_=u):(f=u,_=this);for(var E=0;E<_.length;E++)this.words[E]=f.words[E]^_.words[E];if(this!==f)for(;Eu.length?this.clone().ixor(u):u.clone().ixor(this)},i.prototype.uxor=function(u){return this.length>u.length?this.clone().iuxor(u):u.clone().iuxor(this)},i.prototype.inotn=function(u){n(typeof u=="number"&&u>=0);var f=Math.ceil(u/26)|0,_=u%26;this._expand(f),_>0&&f--;for(var E=0;E0&&(this.words[E]=~this.words[E]&67108863>>26-_),this.strip()},i.prototype.notn=function(u){return this.clone().inotn(u)},i.prototype.setn=function(u,f){n(typeof u=="number"&&u>=0);var _=u/26|0,E=u%26;return this._expand(_+1),f?this.words[_]=this.words[_]|1<u.length?(_=this,E=u):(_=u,E=this);for(var S=0,j=0;j>>26;for(;S!==0&&j<_.length;j++)f=(_.words[j]|0)+S,this.words[j]=f&67108863,S=f>>>26;if(this.length=_.length,S!==0)this.words[this.length]=S,this.length++;else if(_!==this)for(;j<_.length;j++)this.words[j]=_.words[j];return this},i.prototype.add=function(u){var f;return u.negative!==0&&this.negative===0?(u.negative=0,f=this.sub(u),u.negative^=1,f):u.negative===0&&this.negative!==0?(this.negative=0,f=u.sub(this),this.negative=1,f):this.length>u.length?this.clone().iadd(u):u.clone().iadd(this)},i.prototype.isub=function(u){if(u.negative!==0){u.negative=0;var f=this.iadd(u);return u.negative=1,f._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(u),this.negative=1,this._normSign();var _=this.cmp(u);if(_===0)return this.negative=0,this.length=1,this.words[0]=0,this;var E,S;_>0?(E=this,S=u):(E=u,S=this);for(var j=0,R=0;R>26,this.words[R]=f&67108863;for(;j!==0&&R>26,this.words[R]=f&67108863;if(j===0&&R>>26,ae=N&67108863,he=Math.min(d,u.length-1),q=Math.max(0,d-x.length+1);q<=he;q++){var G=d-q|0;E=x.words[G]|0,S=u.words[q]|0,j=E*S+ae,C+=j/67108864|0,ae=j&67108863}f.words[d]=ae|0,N=C|0}return N!==0?f.words[d]=N|0:f.length--,f.strip()}var k=function(u,f,_){var E=u.words,S=f.words,j=_.words,R=0,N,d,C,ae=E[0]|0,he=ae&8191,q=ae>>>13,G=E[1]|0,W=G&8191,be=G>>>13,ue=E[2]|0,Q=ue&8191,le=ue>>>13,Se=E[3]|0,fe=Se&8191,ie=Se>>>13,pe=E[4]|0,me=pe&8191,ye=pe>>>13,Ce=E[5]|0,je=Ce&8191,Te=Ce>>>13,ct=E[6]|0,He=ct&8191,Le=ct>>>13,gt=E[7]|0,rt=gt&8191,et=gt>>>13,dr=E[8]|0,B=dr&8191,m=dr>>>13,w=E[9]|0,H=w&8191,X=w>>>13,ne=S[0]|0,ce=ne&8191,ze=ne>>>13,jt=S[1]|0,$e=jt&8191,Xe=jt>>>13,pt=S[2]|0,$t=pt&8191,Zt=pt>>>13,ol=S[3]|0,tr=ol&8191,rr=ol>>>13,Rn=S[4]|0,kt=Rn&8191,Lt=Rn>>>13,Fs=S[5]|0,Qt=Fs&8191,Wt=Fs>>>13,Pc=S[6]|0,wt=Pc&8191,er=Pc>>>13,A=S[7]|0,U=A&8191,O=A>>>13,b=S[8]|0,I=b&8191,Z=b>>>13,ee=S[9]|0,de=ee&8191,we=ee>>>13;_.negative=u.negative^f.negative,_.length=19,N=Math.imul(he,ce),d=Math.imul(he,ze),d=d+Math.imul(q,ce)|0,C=Math.imul(q,ze);var ke=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(ke>>>26)|0,ke&=67108863,N=Math.imul(W,ce),d=Math.imul(W,ze),d=d+Math.imul(be,ce)|0,C=Math.imul(be,ze),N=N+Math.imul(he,$e)|0,d=d+Math.imul(he,Xe)|0,d=d+Math.imul(q,$e)|0,C=C+Math.imul(q,Xe)|0;var Ne=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,N=Math.imul(Q,ce),d=Math.imul(Q,ze),d=d+Math.imul(le,ce)|0,C=Math.imul(le,ze),N=N+Math.imul(W,$e)|0,d=d+Math.imul(W,Xe)|0,d=d+Math.imul(be,$e)|0,C=C+Math.imul(be,Xe)|0,N=N+Math.imul(he,$t)|0,d=d+Math.imul(he,Zt)|0,d=d+Math.imul(q,$t)|0,C=C+Math.imul(q,Zt)|0;var ft=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(ft>>>26)|0,ft&=67108863,N=Math.imul(fe,ce),d=Math.imul(fe,ze),d=d+Math.imul(ie,ce)|0,C=Math.imul(ie,ze),N=N+Math.imul(Q,$e)|0,d=d+Math.imul(Q,Xe)|0,d=d+Math.imul(le,$e)|0,C=C+Math.imul(le,Xe)|0,N=N+Math.imul(W,$t)|0,d=d+Math.imul(W,Zt)|0,d=d+Math.imul(be,$t)|0,C=C+Math.imul(be,Zt)|0,N=N+Math.imul(he,tr)|0,d=d+Math.imul(he,rr)|0,d=d+Math.imul(q,tr)|0,C=C+Math.imul(q,rr)|0;var Be=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Be>>>26)|0,Be&=67108863,N=Math.imul(me,ce),d=Math.imul(me,ze),d=d+Math.imul(ye,ce)|0,C=Math.imul(ye,ze),N=N+Math.imul(fe,$e)|0,d=d+Math.imul(fe,Xe)|0,d=d+Math.imul(ie,$e)|0,C=C+Math.imul(ie,Xe)|0,N=N+Math.imul(Q,$t)|0,d=d+Math.imul(Q,Zt)|0,d=d+Math.imul(le,$t)|0,C=C+Math.imul(le,Zt)|0,N=N+Math.imul(W,tr)|0,d=d+Math.imul(W,rr)|0,d=d+Math.imul(be,tr)|0,C=C+Math.imul(be,rr)|0,N=N+Math.imul(he,kt)|0,d=d+Math.imul(he,Lt)|0,d=d+Math.imul(q,kt)|0,C=C+Math.imul(q,Lt)|0;var Fe=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,N=Math.imul(je,ce),d=Math.imul(je,ze),d=d+Math.imul(Te,ce)|0,C=Math.imul(Te,ze),N=N+Math.imul(me,$e)|0,d=d+Math.imul(me,Xe)|0,d=d+Math.imul(ye,$e)|0,C=C+Math.imul(ye,Xe)|0,N=N+Math.imul(fe,$t)|0,d=d+Math.imul(fe,Zt)|0,d=d+Math.imul(ie,$t)|0,C=C+Math.imul(ie,Zt)|0,N=N+Math.imul(Q,tr)|0,d=d+Math.imul(Q,rr)|0,d=d+Math.imul(le,tr)|0,C=C+Math.imul(le,rr)|0,N=N+Math.imul(W,kt)|0,d=d+Math.imul(W,Lt)|0,d=d+Math.imul(be,kt)|0,C=C+Math.imul(be,Lt)|0,N=N+Math.imul(he,Qt)|0,d=d+Math.imul(he,Wt)|0,d=d+Math.imul(q,Qt)|0,C=C+Math.imul(q,Wt)|0;var Ke=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,N=Math.imul(He,ce),d=Math.imul(He,ze),d=d+Math.imul(Le,ce)|0,C=Math.imul(Le,ze),N=N+Math.imul(je,$e)|0,d=d+Math.imul(je,Xe)|0,d=d+Math.imul(Te,$e)|0,C=C+Math.imul(Te,Xe)|0,N=N+Math.imul(me,$t)|0,d=d+Math.imul(me,Zt)|0,d=d+Math.imul(ye,$t)|0,C=C+Math.imul(ye,Zt)|0,N=N+Math.imul(fe,tr)|0,d=d+Math.imul(fe,rr)|0,d=d+Math.imul(ie,tr)|0,C=C+Math.imul(ie,rr)|0,N=N+Math.imul(Q,kt)|0,d=d+Math.imul(Q,Lt)|0,d=d+Math.imul(le,kt)|0,C=C+Math.imul(le,Lt)|0,N=N+Math.imul(W,Qt)|0,d=d+Math.imul(W,Wt)|0,d=d+Math.imul(be,Qt)|0,C=C+Math.imul(be,Wt)|0,N=N+Math.imul(he,wt)|0,d=d+Math.imul(he,er)|0,d=d+Math.imul(q,wt)|0,C=C+Math.imul(q,er)|0;var Je=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Je>>>26)|0,Je&=67108863,N=Math.imul(rt,ce),d=Math.imul(rt,ze),d=d+Math.imul(et,ce)|0,C=Math.imul(et,ze),N=N+Math.imul(He,$e)|0,d=d+Math.imul(He,Xe)|0,d=d+Math.imul(Le,$e)|0,C=C+Math.imul(Le,Xe)|0,N=N+Math.imul(je,$t)|0,d=d+Math.imul(je,Zt)|0,d=d+Math.imul(Te,$t)|0,C=C+Math.imul(Te,Zt)|0,N=N+Math.imul(me,tr)|0,d=d+Math.imul(me,rr)|0,d=d+Math.imul(ye,tr)|0,C=C+Math.imul(ye,rr)|0,N=N+Math.imul(fe,kt)|0,d=d+Math.imul(fe,Lt)|0,d=d+Math.imul(ie,kt)|0,C=C+Math.imul(ie,Lt)|0,N=N+Math.imul(Q,Qt)|0,d=d+Math.imul(Q,Wt)|0,d=d+Math.imul(le,Qt)|0,C=C+Math.imul(le,Wt)|0,N=N+Math.imul(W,wt)|0,d=d+Math.imul(W,er)|0,d=d+Math.imul(be,wt)|0,C=C+Math.imul(be,er)|0,N=N+Math.imul(he,U)|0,d=d+Math.imul(he,O)|0,d=d+Math.imul(q,U)|0,C=C+Math.imul(q,O)|0;var Qe=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,N=Math.imul(B,ce),d=Math.imul(B,ze),d=d+Math.imul(m,ce)|0,C=Math.imul(m,ze),N=N+Math.imul(rt,$e)|0,d=d+Math.imul(rt,Xe)|0,d=d+Math.imul(et,$e)|0,C=C+Math.imul(et,Xe)|0,N=N+Math.imul(He,$t)|0,d=d+Math.imul(He,Zt)|0,d=d+Math.imul(Le,$t)|0,C=C+Math.imul(Le,Zt)|0,N=N+Math.imul(je,tr)|0,d=d+Math.imul(je,rr)|0,d=d+Math.imul(Te,tr)|0,C=C+Math.imul(Te,rr)|0,N=N+Math.imul(me,kt)|0,d=d+Math.imul(me,Lt)|0,d=d+Math.imul(ye,kt)|0,C=C+Math.imul(ye,Lt)|0,N=N+Math.imul(fe,Qt)|0,d=d+Math.imul(fe,Wt)|0,d=d+Math.imul(ie,Qt)|0,C=C+Math.imul(ie,Wt)|0,N=N+Math.imul(Q,wt)|0,d=d+Math.imul(Q,er)|0,d=d+Math.imul(le,wt)|0,C=C+Math.imul(le,er)|0,N=N+Math.imul(W,U)|0,d=d+Math.imul(W,O)|0,d=d+Math.imul(be,U)|0,C=C+Math.imul(be,O)|0,N=N+Math.imul(he,I)|0,d=d+Math.imul(he,Z)|0,d=d+Math.imul(q,I)|0,C=C+Math.imul(q,Z)|0;var Pe=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,N=Math.imul(H,ce),d=Math.imul(H,ze),d=d+Math.imul(X,ce)|0,C=Math.imul(X,ze),N=N+Math.imul(B,$e)|0,d=d+Math.imul(B,Xe)|0,d=d+Math.imul(m,$e)|0,C=C+Math.imul(m,Xe)|0,N=N+Math.imul(rt,$t)|0,d=d+Math.imul(rt,Zt)|0,d=d+Math.imul(et,$t)|0,C=C+Math.imul(et,Zt)|0,N=N+Math.imul(He,tr)|0,d=d+Math.imul(He,rr)|0,d=d+Math.imul(Le,tr)|0,C=C+Math.imul(Le,rr)|0,N=N+Math.imul(je,kt)|0,d=d+Math.imul(je,Lt)|0,d=d+Math.imul(Te,kt)|0,C=C+Math.imul(Te,Lt)|0,N=N+Math.imul(me,Qt)|0,d=d+Math.imul(me,Wt)|0,d=d+Math.imul(ye,Qt)|0,C=C+Math.imul(ye,Wt)|0,N=N+Math.imul(fe,wt)|0,d=d+Math.imul(fe,er)|0,d=d+Math.imul(ie,wt)|0,C=C+Math.imul(ie,er)|0,N=N+Math.imul(Q,U)|0,d=d+Math.imul(Q,O)|0,d=d+Math.imul(le,U)|0,C=C+Math.imul(le,O)|0,N=N+Math.imul(W,I)|0,d=d+Math.imul(W,Z)|0,d=d+Math.imul(be,I)|0,C=C+Math.imul(be,Z)|0,N=N+Math.imul(he,de)|0,d=d+Math.imul(he,we)|0,d=d+Math.imul(q,de)|0,C=C+Math.imul(q,we)|0;var Ye=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,N=Math.imul(H,$e),d=Math.imul(H,Xe),d=d+Math.imul(X,$e)|0,C=Math.imul(X,Xe),N=N+Math.imul(B,$t)|0,d=d+Math.imul(B,Zt)|0,d=d+Math.imul(m,$t)|0,C=C+Math.imul(m,Zt)|0,N=N+Math.imul(rt,tr)|0,d=d+Math.imul(rt,rr)|0,d=d+Math.imul(et,tr)|0,C=C+Math.imul(et,rr)|0,N=N+Math.imul(He,kt)|0,d=d+Math.imul(He,Lt)|0,d=d+Math.imul(Le,kt)|0,C=C+Math.imul(Le,Lt)|0,N=N+Math.imul(je,Qt)|0,d=d+Math.imul(je,Wt)|0,d=d+Math.imul(Te,Qt)|0,C=C+Math.imul(Te,Wt)|0,N=N+Math.imul(me,wt)|0,d=d+Math.imul(me,er)|0,d=d+Math.imul(ye,wt)|0,C=C+Math.imul(ye,er)|0,N=N+Math.imul(fe,U)|0,d=d+Math.imul(fe,O)|0,d=d+Math.imul(ie,U)|0,C=C+Math.imul(ie,O)|0,N=N+Math.imul(Q,I)|0,d=d+Math.imul(Q,Z)|0,d=d+Math.imul(le,I)|0,C=C+Math.imul(le,Z)|0,N=N+Math.imul(W,de)|0,d=d+Math.imul(W,we)|0,d=d+Math.imul(be,de)|0,C=C+Math.imul(be,we)|0;var Ge=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,N=Math.imul(H,$t),d=Math.imul(H,Zt),d=d+Math.imul(X,$t)|0,C=Math.imul(X,Zt),N=N+Math.imul(B,tr)|0,d=d+Math.imul(B,rr)|0,d=d+Math.imul(m,tr)|0,C=C+Math.imul(m,rr)|0,N=N+Math.imul(rt,kt)|0,d=d+Math.imul(rt,Lt)|0,d=d+Math.imul(et,kt)|0,C=C+Math.imul(et,Lt)|0,N=N+Math.imul(He,Qt)|0,d=d+Math.imul(He,Wt)|0,d=d+Math.imul(Le,Qt)|0,C=C+Math.imul(Le,Wt)|0,N=N+Math.imul(je,wt)|0,d=d+Math.imul(je,er)|0,d=d+Math.imul(Te,wt)|0,C=C+Math.imul(Te,er)|0,N=N+Math.imul(me,U)|0,d=d+Math.imul(me,O)|0,d=d+Math.imul(ye,U)|0,C=C+Math.imul(ye,O)|0,N=N+Math.imul(fe,I)|0,d=d+Math.imul(fe,Z)|0,d=d+Math.imul(ie,I)|0,C=C+Math.imul(ie,Z)|0,N=N+Math.imul(Q,de)|0,d=d+Math.imul(Q,we)|0,d=d+Math.imul(le,de)|0,C=C+Math.imul(le,we)|0;var Oe=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,N=Math.imul(H,tr),d=Math.imul(H,rr),d=d+Math.imul(X,tr)|0,C=Math.imul(X,rr),N=N+Math.imul(B,kt)|0,d=d+Math.imul(B,Lt)|0,d=d+Math.imul(m,kt)|0,C=C+Math.imul(m,Lt)|0,N=N+Math.imul(rt,Qt)|0,d=d+Math.imul(rt,Wt)|0,d=d+Math.imul(et,Qt)|0,C=C+Math.imul(et,Wt)|0,N=N+Math.imul(He,wt)|0,d=d+Math.imul(He,er)|0,d=d+Math.imul(Le,wt)|0,C=C+Math.imul(Le,er)|0,N=N+Math.imul(je,U)|0,d=d+Math.imul(je,O)|0,d=d+Math.imul(Te,U)|0,C=C+Math.imul(Te,O)|0,N=N+Math.imul(me,I)|0,d=d+Math.imul(me,Z)|0,d=d+Math.imul(ye,I)|0,C=C+Math.imul(ye,Z)|0,N=N+Math.imul(fe,de)|0,d=d+Math.imul(fe,we)|0,d=d+Math.imul(ie,de)|0,C=C+Math.imul(ie,we)|0;var De=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(De>>>26)|0,De&=67108863,N=Math.imul(H,kt),d=Math.imul(H,Lt),d=d+Math.imul(X,kt)|0,C=Math.imul(X,Lt),N=N+Math.imul(B,Qt)|0,d=d+Math.imul(B,Wt)|0,d=d+Math.imul(m,Qt)|0,C=C+Math.imul(m,Wt)|0,N=N+Math.imul(rt,wt)|0,d=d+Math.imul(rt,er)|0,d=d+Math.imul(et,wt)|0,C=C+Math.imul(et,er)|0,N=N+Math.imul(He,U)|0,d=d+Math.imul(He,O)|0,d=d+Math.imul(Le,U)|0,C=C+Math.imul(Le,O)|0,N=N+Math.imul(je,I)|0,d=d+Math.imul(je,Z)|0,d=d+Math.imul(Te,I)|0,C=C+Math.imul(Te,Z)|0,N=N+Math.imul(me,de)|0,d=d+Math.imul(me,we)|0,d=d+Math.imul(ye,de)|0,C=C+Math.imul(ye,we)|0;var Me=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Me>>>26)|0,Me&=67108863,N=Math.imul(H,Qt),d=Math.imul(H,Wt),d=d+Math.imul(X,Qt)|0,C=Math.imul(X,Wt),N=N+Math.imul(B,wt)|0,d=d+Math.imul(B,er)|0,d=d+Math.imul(m,wt)|0,C=C+Math.imul(m,er)|0,N=N+Math.imul(rt,U)|0,d=d+Math.imul(rt,O)|0,d=d+Math.imul(et,U)|0,C=C+Math.imul(et,O)|0,N=N+Math.imul(He,I)|0,d=d+Math.imul(He,Z)|0,d=d+Math.imul(Le,I)|0,C=C+Math.imul(Le,Z)|0,N=N+Math.imul(je,de)|0,d=d+Math.imul(je,we)|0,d=d+Math.imul(Te,de)|0,C=C+Math.imul(Te,we)|0;var Re=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Re>>>26)|0,Re&=67108863,N=Math.imul(H,wt),d=Math.imul(H,er),d=d+Math.imul(X,wt)|0,C=Math.imul(X,er),N=N+Math.imul(B,U)|0,d=d+Math.imul(B,O)|0,d=d+Math.imul(m,U)|0,C=C+Math.imul(m,O)|0,N=N+Math.imul(rt,I)|0,d=d+Math.imul(rt,Z)|0,d=d+Math.imul(et,I)|0,C=C+Math.imul(et,Z)|0,N=N+Math.imul(He,de)|0,d=d+Math.imul(He,we)|0,d=d+Math.imul(Le,de)|0,C=C+Math.imul(Le,we)|0;var Ue=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ue>>>26)|0,Ue&=67108863,N=Math.imul(H,U),d=Math.imul(H,O),d=d+Math.imul(X,U)|0,C=Math.imul(X,O),N=N+Math.imul(B,I)|0,d=d+Math.imul(B,Z)|0,d=d+Math.imul(m,I)|0,C=C+Math.imul(m,Z)|0,N=N+Math.imul(rt,de)|0,d=d+Math.imul(rt,we)|0,d=d+Math.imul(et,de)|0,C=C+Math.imul(et,we)|0;var Ae=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,N=Math.imul(H,I),d=Math.imul(H,Z),d=d+Math.imul(X,I)|0,C=Math.imul(X,Z),N=N+Math.imul(B,de)|0,d=d+Math.imul(B,we)|0,d=d+Math.imul(m,de)|0,C=C+Math.imul(m,we)|0;var se=(R+N|0)+((d&8191)<<13)|0;R=(C+(d>>>13)|0)+(se>>>26)|0,se&=67108863,N=Math.imul(H,de),d=Math.imul(H,we),d=d+Math.imul(X,de)|0,C=Math.imul(X,we);var oe=(R+N|0)+((d&8191)<<13)|0;return R=(C+(d>>>13)|0)+(oe>>>26)|0,oe&=67108863,j[0]=ke,j[1]=Ne,j[2]=ft,j[3]=Be,j[4]=Fe,j[5]=Ke,j[6]=Je,j[7]=Qe,j[8]=Pe,j[9]=Ye,j[10]=Ge,j[11]=Oe,j[12]=De,j[13]=Me,j[14]=Re,j[15]=Ue,j[16]=Ae,j[17]=se,j[18]=oe,R!==0&&(j[19]=R,_.length++),_};Math.imul||(k=M);function K(x,u,f){f.negative=u.negative^x.negative,f.length=x.length+u.length;for(var _=0,E=0,S=0;S>>26)|0,E+=j>>>26,j&=67108863}f.words[S]=R,_=j,j=E}return _!==0?f.words[S]=_:f.length--,f.strip()}function D(x,u,f){var _=new T;return _.mulp(x,u,f)}i.prototype.mulTo=function(u,f){var _,E=this.length+u.length;return this.length===10&&u.length===10?_=k(this,u,f):E<63?_=M(this,u,f):E<1024?_=K(this,u,f):_=D(this,u,f),_};function T(x,u){this.x=x,this.y=u}T.prototype.makeRBT=function(u){for(var f=new Array(u),_=i.prototype._countBits(u)-1,E=0;E>=1;return E},T.prototype.permute=function(u,f,_,E,S,j){for(var R=0;R>>1)S++;return 1<>>13,_[2*j+1]=S&8191,S=S>>>13;for(j=2*f;j>=26,f+=E/67108864|0,f+=S>>>26,this.words[_]=S&67108863}return f!==0&&(this.words[_]=f,this.length++),this.length=u===0?1:this.length,this},i.prototype.muln=function(u){return this.clone().imuln(u)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(u){var f=v(u);if(f.length===0)return new i(1);for(var _=this,E=0;E=0);var f=u%26,_=(u-f)/26,E=67108863>>>26-f<<26-f,S;if(f!==0){var j=0;for(S=0;S>>26-f}j&&(this.words[S]=j,this.length++)}if(_!==0){for(S=this.length-1;S>=0;S--)this.words[S+_]=this.words[S];for(S=0;S<_;S++)this.words[S]=0;this.length+=_}return this.strip()},i.prototype.ishln=function(u){return n(this.negative===0),this.iushln(u)},i.prototype.iushrn=function(u,f,_){n(typeof u=="number"&&u>=0);var E;f?E=(f-f%26)/26:E=0;var S=u%26,j=Math.min((u-S)/26,this.length),R=67108863^67108863>>>S<j)for(this.length-=j,d=0;d=0&&(C!==0||d>=E);d--){var ae=this.words[d]|0;this.words[d]=C<<26-S|ae>>>S,C=ae&R}return N&&C!==0&&(N.words[N.length++]=C),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(u,f,_){return n(this.negative===0),this.iushrn(u,f,_)},i.prototype.shln=function(u){return this.clone().ishln(u)},i.prototype.ushln=function(u){return this.clone().iushln(u)},i.prototype.shrn=function(u){return this.clone().ishrn(u)},i.prototype.ushrn=function(u){return this.clone().iushrn(u)},i.prototype.testn=function(u){n(typeof u=="number"&&u>=0);var f=u%26,_=(u-f)/26,E=1<=0);var f=u%26,_=(u-f)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=_)return this;if(f!==0&&_++,this.length=Math.min(_,this.length),f!==0){var E=67108863^67108863>>>f<=67108864;f++)this.words[f]-=67108864,f===this.length-1?this.words[f+1]=1:this.words[f+1]++;return this.length=Math.max(this.length,f+1),this},i.prototype.isubn=function(u){if(n(typeof u=="number"),n(u<67108864),u<0)return this.iaddn(-u);if(this.negative!==0)return this.negative=0,this.iaddn(u),this.negative=1,this;if(this.words[0]-=u,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var f=0;f>26)-(N/67108864|0),this.words[S+_]=j&67108863}for(;S>26,this.words[S+_]=j&67108863;if(R===0)return this.strip();for(n(R===-1),R=0,S=0;S>26,this.words[S]=j&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(u,f){var _=this.length-u.length,E=this.clone(),S=u,j=S.words[S.length-1]|0,R=this._countBits(j);_=26-R,_!==0&&(S=S.ushln(_),E.iushln(_),j=S.words[S.length-1]|0);var N=E.length-S.length,d;if(f!=="mod"){d=new i(null),d.length=N+1,d.words=new Array(d.length);for(var C=0;C=0;he--){var q=(E.words[S.length+he]|0)*67108864+(E.words[S.length+he-1]|0);for(q=Math.min(q/j|0,67108863),E._ishlnsubmul(S,q,he);E.negative!==0;)q--,E.negative=0,E._ishlnsubmul(S,1,he),E.isZero()||(E.negative^=1);d&&(d.words[he]=q)}return d&&d.strip(),E.strip(),f!=="div"&&_!==0&&E.iushrn(_),{div:d||null,mod:E}},i.prototype.divmod=function(u,f,_){if(n(!u.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var E,S,j;return this.negative!==0&&u.negative===0?(j=this.neg().divmod(u,f),f!=="mod"&&(E=j.div.neg()),f!=="div"&&(S=j.mod.neg(),_&&S.negative!==0&&S.iadd(u)),{div:E,mod:S}):this.negative===0&&u.negative!==0?(j=this.divmod(u.neg(),f),f!=="mod"&&(E=j.div.neg()),{div:E,mod:j.mod}):this.negative&u.negative?(j=this.neg().divmod(u.neg(),f),f!=="div"&&(S=j.mod.neg(),_&&S.negative!==0&&S.isub(u)),{div:j.div,mod:S}):u.length>this.length||this.cmp(u)<0?{div:new i(0),mod:this}:u.length===1?f==="div"?{div:this.divn(u.words[0]),mod:null}:f==="mod"?{div:null,mod:new i(this.modn(u.words[0]))}:{div:this.divn(u.words[0]),mod:new i(this.modn(u.words[0]))}:this._wordDiv(u,f)},i.prototype.div=function(u){return this.divmod(u,"div",!1).div},i.prototype.mod=function(u){return this.divmod(u,"mod",!1).mod},i.prototype.umod=function(u){return this.divmod(u,"mod",!0).mod},i.prototype.divRound=function(u){var f=this.divmod(u);if(f.mod.isZero())return f.div;var _=f.div.negative!==0?f.mod.isub(u):f.mod,E=u.ushrn(1),S=u.andln(1),j=_.cmp(E);return j<0||S===1&&j===0?f.div:f.div.negative!==0?f.div.isubn(1):f.div.iaddn(1)},i.prototype.modn=function(u){n(u<=67108863);for(var f=(1<<26)%u,_=0,E=this.length-1;E>=0;E--)_=(f*_+(this.words[E]|0))%u;return _},i.prototype.idivn=function(u){n(u<=67108863);for(var f=0,_=this.length-1;_>=0;_--){var E=(this.words[_]|0)+f*67108864;this.words[_]=E/u|0,f=E%u}return this.strip()},i.prototype.divn=function(u){return this.clone().idivn(u)},i.prototype.egcd=function(u){n(u.negative===0),n(!u.isZero());var f=this,_=u.clone();f.negative!==0?f=f.umod(u):f=f.clone();for(var E=new i(1),S=new i(0),j=new i(0),R=new i(1),N=0;f.isEven()&&_.isEven();)f.iushrn(1),_.iushrn(1),++N;for(var d=_.clone(),C=f.clone();!f.isZero();){for(var ae=0,he=1;!(f.words[0]&he)&&ae<26;++ae,he<<=1);if(ae>0)for(f.iushrn(ae);ae-- >0;)(E.isOdd()||S.isOdd())&&(E.iadd(d),S.isub(C)),E.iushrn(1),S.iushrn(1);for(var q=0,G=1;!(_.words[0]&G)&&q<26;++q,G<<=1);if(q>0)for(_.iushrn(q);q-- >0;)(j.isOdd()||R.isOdd())&&(j.iadd(d),R.isub(C)),j.iushrn(1),R.iushrn(1);f.cmp(_)>=0?(f.isub(_),E.isub(j),S.isub(R)):(_.isub(f),j.isub(E),R.isub(S))}return{a:j,b:R,gcd:_.iushln(N)}},i.prototype._invmp=function(u){n(u.negative===0),n(!u.isZero());var f=this,_=u.clone();f.negative!==0?f=f.umod(u):f=f.clone();for(var E=new i(1),S=new i(0),j=_.clone();f.cmpn(1)>0&&_.cmpn(1)>0;){for(var R=0,N=1;!(f.words[0]&N)&&R<26;++R,N<<=1);if(R>0)for(f.iushrn(R);R-- >0;)E.isOdd()&&E.iadd(j),E.iushrn(1);for(var d=0,C=1;!(_.words[0]&C)&&d<26;++d,C<<=1);if(d>0)for(_.iushrn(d);d-- >0;)S.isOdd()&&S.iadd(j),S.iushrn(1);f.cmp(_)>=0?(f.isub(_),E.isub(S)):(_.isub(f),S.isub(E))}var ae;return f.cmpn(1)===0?ae=E:ae=S,ae.cmpn(0)<0&&ae.iadd(u),ae},i.prototype.gcd=function(u){if(this.isZero())return u.abs();if(u.isZero())return this.abs();var f=this.clone(),_=u.clone();f.negative=0,_.negative=0;for(var E=0;f.isEven()&&_.isEven();E++)f.iushrn(1),_.iushrn(1);do{for(;f.isEven();)f.iushrn(1);for(;_.isEven();)_.iushrn(1);var S=f.cmp(_);if(S<0){var j=f;f=_,_=j}else if(S===0||_.cmpn(1)===0)break;f.isub(_)}while(!0);return _.iushln(E)},i.prototype.invm=function(u){return this.egcd(u).a.umod(u)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(u){return this.words[0]&u},i.prototype.bincn=function(u){n(typeof u=="number");var f=u%26,_=(u-f)/26,E=1<>>26,R&=67108863,this.words[j]=R}return S!==0&&(this.words[j]=S,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(u){var f=u<0;if(this.negative!==0&&!f)return-1;if(this.negative===0&&f)return 1;this.strip();var _;if(this.length>1)_=1;else{f&&(u=-u),n(u<=67108863,"Number is too big");var E=this.words[0]|0;_=E===u?0:Eu.length)return 1;if(this.length=0;_--){var E=this.words[_]|0,S=u.words[_]|0;if(E!==S){ES&&(f=1);break}}return f},i.prototype.gtn=function(u){return this.cmpn(u)===1},i.prototype.gt=function(u){return this.cmp(u)===1},i.prototype.gten=function(u){return this.cmpn(u)>=0},i.prototype.gte=function(u){return this.cmp(u)>=0},i.prototype.ltn=function(u){return this.cmpn(u)===-1},i.prototype.lt=function(u){return this.cmp(u)===-1},i.prototype.lten=function(u){return this.cmpn(u)<=0},i.prototype.lte=function(u){return this.cmp(u)<=0},i.prototype.eqn=function(u){return this.cmpn(u)===0},i.prototype.eq=function(u){return this.cmp(u)===0},i.red=function(u){return new Y(u)},i.prototype.toRed=function(u){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),u.convertTo(this)._forceRed(u)},i.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(u){return this.red=u,this},i.prototype.forceRed=function(u){return n(!this.red,"Already a number in reduction context"),this._forceRed(u)},i.prototype.redAdd=function(u){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,u)},i.prototype.redIAdd=function(u){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,u)},i.prototype.redSub=function(u){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,u)},i.prototype.redISub=function(u){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,u)},i.prototype.redShl=function(u){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,u)},i.prototype.redMul=function(u){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,u),this.red.mul(this,u)},i.prototype.redIMul=function(u){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,u),this.red.imul(this,u)},i.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(u){return n(this.red&&!u.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,u)};var z={k256:null,p224:null,p192:null,p25519:null};function L(x,u){this.name=x,this.p=new i(u,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}L.prototype._tmp=function(){var u=new i(null);return u.words=new Array(Math.ceil(this.n/13)),u},L.prototype.ireduce=function(u){var f=u,_;do this.split(f,this.tmp),f=this.imulK(f),f=f.iadd(this.tmp),_=f.bitLength();while(_>this.n);var E=_0?f.isub(this.p):f.strip!==void 0?f.strip():f._strip(),f},L.prototype.split=function(u,f){u.iushrn(this.n,0,f)},L.prototype.imulK=function(u){return u.imul(this.k)};function $(){L.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a($,L),$.prototype.split=function(u,f){for(var _=4194303,E=Math.min(u.length,9),S=0;S>>22,j=R}j>>>=22,u.words[S-10]=j,j===0&&u.length>10?u.length-=10:u.length-=9},$.prototype.imulK=function(u){u.words[u.length]=0,u.words[u.length+1]=0,u.length+=2;for(var f=0,_=0;_>>=26,u.words[_]=S,f=E}return f!==0&&(u.words[u.length++]=f),u},i._prime=function(u){if(z[u])return z[u];var f;if(u==="k256")f=new $;else if(u==="p224")f=new F;else if(u==="p192")f=new V;else if(u==="p25519")f=new J;else throw new Error("Unknown prime "+u);return z[u]=f,f};function Y(x){if(typeof x=="string"){var u=i._prime(x);this.m=u.p,this.prime=u}else n(x.gtn(1),"modulus must be greater than 1"),this.m=x,this.prime=null}Y.prototype._verify1=function(u){n(u.negative===0,"red works only with positives"),n(u.red,"red works only with red numbers")},Y.prototype._verify2=function(u,f){n((u.negative|f.negative)===0,"red works only with positives"),n(u.red&&u.red===f.red,"red works only with red numbers")},Y.prototype.imod=function(u){return this.prime?this.prime.ireduce(u)._forceRed(this):u.umod(this.m)._forceRed(this)},Y.prototype.neg=function(u){return u.isZero()?u.clone():this.m.sub(u)._forceRed(this)},Y.prototype.add=function(u,f){this._verify2(u,f);var _=u.add(f);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},Y.prototype.iadd=function(u,f){this._verify2(u,f);var _=u.iadd(f);return _.cmp(this.m)>=0&&_.isub(this.m),_},Y.prototype.sub=function(u,f){this._verify2(u,f);var _=u.sub(f);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},Y.prototype.isub=function(u,f){this._verify2(u,f);var _=u.isub(f);return _.cmpn(0)<0&&_.iadd(this.m),_},Y.prototype.shl=function(u,f){return this._verify1(u),this.imod(u.ushln(f))},Y.prototype.imul=function(u,f){return this._verify2(u,f),this.imod(u.imul(f))},Y.prototype.mul=function(u,f){return this._verify2(u,f),this.imod(u.mul(f))},Y.prototype.isqr=function(u){return this.imul(u,u.clone())},Y.prototype.sqr=function(u){return this.mul(u,u)},Y.prototype.sqrt=function(u){if(u.isZero())return u.clone();var f=this.m.andln(3);if(n(f%2===1),f===3){var _=this.m.add(new i(1)).iushrn(2);return this.pow(u,_)}for(var E=this.m.subn(1),S=0;!E.isZero()&&E.andln(1)===0;)S++,E.iushrn(1);n(!E.isZero());var j=new i(1).toRed(this),R=j.redNeg(),N=this.m.subn(1).iushrn(1),d=this.m.bitLength();for(d=new i(2*d*d).toRed(this);this.pow(d,N).cmp(R)!==0;)d.redIAdd(R);for(var C=this.pow(d,E),ae=this.pow(u,E.addn(1).iushrn(1)),he=this.pow(u,E),q=S;he.cmp(j)!==0;){for(var G=he,W=0;G.cmp(j)!==0;W++)G=G.redSqr();n(W=0;S--){for(var C=f.words[S],ae=d-1;ae>=0;ae--){var he=C>>ae&1;if(j!==E[0]&&(j=this.sqr(j)),he===0&&R===0){N=0;continue}R<<=1,R|=he,N++,!(N!==_&&(S!==0||ae!==0))&&(j=this.mul(j,E[R]),N=0,R=0)}d=26}return j},Y.prototype.convertTo=function(u){var f=u.umod(this.m);return f===u?f.clone():f},Y.prototype.convertFrom=function(u){var f=u.clone();return f.red=null,f},i.mont=function(u){return new te(u)};function te(x){Y.call(this,x),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}a(te,Y),te.prototype.convertTo=function(u){return this.imod(u.ushln(this.shift))},te.prototype.convertFrom=function(u){var f=this.imod(u.mul(this.rinv));return f.red=null,f},te.prototype.imul=function(u,f){if(u.isZero()||f.isZero())return u.words[0]=0,u.length=1,u;var _=u.imul(f),E=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=_.isub(E).iushrn(this.shift),j=S;return S.cmp(this.m)>=0?j=S.isub(this.m):S.cmpn(0)<0&&(j=S.iadd(this.m)),j._forceRed(this)},te.prototype.mul=function(u,f){if(u.isZero()||f.isZero())return new i(0)._forceRed(this);var _=u.mul(f),E=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=_.isub(E).iushrn(this.shift),j=S;return S.cmp(this.m)>=0?j=S.isub(this.m):S.cmpn(0)<0&&(j=S.iadd(this.m)),j._forceRed(this)},te.prototype.invm=function(u){var f=this.imod(u._invmp(this.m).mul(this.r2));return f._forceRed(this)}})(e,Ie)})(Q1);var ri=Q1.exports,qs=a6;function a6(e,t){if(!e)throw new Error(t||"Assertion failed")}a6.equal=function(t,r,n){if(t!=r)throw new Error(n||"Assertion failed: "+t+" != "+r)};var J1={};(function(e){var t=e;function r(i,s){if(Array.isArray(i))return i.slice();if(!i)return[];var o=[];if(typeof i!="string"){for(var c=0;c>8,y=h&255;p?o.push(p,y):o.push(y)}return o}t.toArray=r;function n(i){return i.length===1?"0"+i:i}t.zero2=n;function a(i){for(var s="",o=0;o(k>>1)-1?D=(k>>1)-T:D=T,K.isubn(D)):D=0,v[M]=D,K.iushrn(1)}return v}t.getNAF=i;function s(p,y){var g=[[],[]];p=p.clone(),y=y.clone();for(var v=0,M=0,k;p.cmpn(-v)>0||y.cmpn(-M)>0;){var K=p.andln(3)+v&3,D=y.andln(3)+M&3;K===3&&(K=-1),D===3&&(D=-1);var T;K&1?(k=p.andln(7)+v&7,(k===3||k===5)&&D===2?T=-K:T=K):T=0,g[0].push(T);var z;D&1?(k=y.andln(7)+M&7,(k===3||k===5)&&K===2?z=-D:z=D):z=0,g[1].push(z),2*v===T+1&&(v=1-v),2*M===z+1&&(M=1-M),p.iushrn(1),y.iushrn(1)}return g}t.getJSF=s;function o(p,y,g){var v="_"+y;p.prototype[y]=function(){return this[v]!==void 0?this[v]:this[v]=g.call(this)}}t.cachedProperty=o;function c(p){return typeof p=="string"?t.toArray(p,"hex"):p}t.parseBytes=c;function h(p){return new r(p,"hex","le")}t.intFromLE=h})(Bn);var W1={exports:{}},D0;W1.exports=function(t){return D0||(D0=new Si(null)),D0.generate(t)};function Si(e){this.rand=e}W1.exports.Rand=Si;Si.prototype.generate=function(t){return this._rand(t)};Si.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var r=new Uint8Array(t),n=0;n0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var xd=Zi;Zi.prototype.point=function(){throw new Error("Not implemented")};Zi.prototype.validate=function(){throw new Error("Not implemented")};Zi.prototype._fixedNafMul=function(t,r){Nf(t.precomputed);var n=t._getDoubles(),a=Af(r,1,this._bitLength),i=(1<=o;h--)c=(c<<1)+a[h];s.push(c)}for(var p=this.jpoint(null,null,null),y=this.jpoint(null,null,null),g=i;g>0;g--){for(o=0;o=0;c--){for(var h=0;c>=0&&s[c]===0;c--)h++;if(c>=0&&h++,o=o.dblp(h),c<0)break;var p=s[c];Nf(p!==0),t.type==="affine"?p>0?o=o.mixedAdd(i[p-1>>1]):o=o.mixedAdd(i[-p-1>>1].neg()):p>0?o=o.add(i[p-1>>1]):o=o.add(i[-p-1>>1].neg())}return t.type==="affine"?o.toP():o};Zi.prototype._wnafMulAdd=function(t,r,n,a,i){var s=this._wnafT1,o=this._wnafT2,c=this._wnafT3,h=0,p,y,g;for(p=0;p=1;p-=2){var M=p-1,k=p;if(s[M]!==1||s[k]!==1){c[M]=Af(n[M],s[M],this._bitLength),c[k]=Af(n[k],s[k],this._bitLength),h=Math.max(c[M].length,h),h=Math.max(c[k].length,h);continue}var K=[r[M],null,null,r[k]];r[M].y.cmp(r[k].y)===0?(K[1]=r[M].add(r[k]),K[2]=r[M].toJ().mixedAdd(r[k].neg())):r[M].y.cmp(r[k].y.redNeg())===0?(K[1]=r[M].toJ().mixedAdd(r[k]),K[2]=r[M].add(r[k].neg())):(K[1]=r[M].toJ().mixedAdd(r[k]),K[2]=r[M].toJ().mixedAdd(r[k].neg()));var D=[-3,-1,-5,-7,0,7,5,1,3],T=cN(n[M],n[k]);for(h=Math.max(T[0].length,h),c[M]=new Array(h),c[k]=new Array(h),y=0;y=0;p--){for(var V=0;p>=0;){var J=!0;for(y=0;y=0&&V++,$=$.dblp(V),p<0)break;for(y=0;y0?g=o[y][Y-1>>1]:Y<0&&(g=o[y][-Y-1>>1].neg()),g.type==="affine"?$=$.mixedAdd(g):$=$.add(g))}}for(p=0;p=Math.ceil((t.bitLength()+1)/r.step):!1};Xn.prototype._getDoubles=function(t,r){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var n=[this],a=this,i=0;i=0&&(v=h,M=p),y.negative&&(y=y.neg(),g=g.neg()),v.negative&&(v=v.neg(),M=M.neg()),[{a:y,b:g},{a:v,b:M}]};Zn.prototype._endoSplit=function(t){var r=this.endo.basis,n=r[0],a=r[1],i=a.b.mul(t).divRound(this.n),s=n.b.neg().mul(t).divRound(this.n),o=i.mul(n.a),c=s.mul(a.a),h=i.mul(n.b),p=s.mul(a.b),y=t.sub(o).sub(c),g=h.add(p).neg();return{k1:y,k2:g}};Zn.prototype.pointFromX=function(t,r){t=new lr(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),a=n.redSqrt();if(a.redSqr().redSub(n).cmp(this.zero)!==0)throw new Error("invalid point");var i=a.fromRed().isOdd();return(r&&!i||!r&&i)&&(a=a.redNeg()),this.point(t,a)};Zn.prototype.validate=function(t){if(t.inf)return!0;var r=t.x,n=t.y,a=this.a.redMul(r),i=r.redSqr().redMul(r).redIAdd(a).redIAdd(this.b);return n.redSqr().redISub(i).cmpn(0)===0};Zn.prototype._endoWnafMulAdd=function(t,r,n){for(var a=this._endoWnafT1,i=this._endoWnafT2,s=0;s":""};Or.prototype.isInfinity=function(){return this.inf};Or.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(this.x.cmp(t.x)===0)return this.curve.point(null,null);var r=this.y.redSub(t.y);r.cmpn(0)!==0&&(r=r.redMul(this.x.redSub(t.x).redInvm()));var n=r.redSqr().redISub(this.x).redISub(t.x),a=r.redMul(this.x.redSub(n)).redISub(this.y);return this.curve.point(n,a)};Or.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(t.cmpn(0)===0)return this.curve.point(null,null);var r=this.curve.a,n=this.x.redSqr(),a=t.redInvm(),i=n.redAdd(n).redIAdd(n).redIAdd(r).redMul(a),s=i.redSqr().redISub(this.x.redAdd(this.x)),o=i.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)};Or.prototype.getX=function(){return this.x.fromRed()};Or.prototype.getY=function(){return this.y.fromRed()};Or.prototype.mul=function(t){return t=new lr(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)};Or.prototype.mulAdd=function(t,r,n){var a=[this,r],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(a,i):this.curve._wnafMulAdd(1,a,i,2)};Or.prototype.jmulAdd=function(t,r,n){var a=[this,r],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(a,i,!0):this.curve._wnafMulAdd(1,a,i,2,!0)};Or.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||this.x.cmp(t.x)===0&&this.y.cmp(t.y)===0)};Or.prototype.neg=function(t){if(this.inf)return this;var r=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var n=this.precomputed,a=function(i){return i.neg()};r.precomputed={naf:n.naf&&{wnd:n.naf.wnd,points:n.naf.points.map(a)},doubles:n.doubles&&{step:n.doubles.step,points:n.doubles.points.map(a)}}}return r};Or.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);var t=this.curve.jpoint(this.x,this.y,this.curve.one);return t};function Lr(e,t,r,n){tl.BasePoint.call(this,e,"jacobian"),t===null&&r===null&&n===null?(this.x=this.curve.one,this.y=this.curve.one,this.z=new lr(0)):(this.x=new lr(t,16),this.y=new lr(r,16),this.z=new lr(n,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}tb(Lr,tl.BasePoint);Zn.prototype.jpoint=function(t,r,n){return new Lr(this,t,r,n)};Lr.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),r=t.redSqr(),n=this.x.redMul(r),a=this.y.redMul(r).redMul(t);return this.curve.point(n,a)};Lr.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};Lr.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var r=t.z.redSqr(),n=this.z.redSqr(),a=this.x.redMul(r),i=t.x.redMul(n),s=this.y.redMul(r.redMul(t.z)),o=t.y.redMul(n.redMul(this.z)),c=a.redSub(i),h=s.redSub(o);if(c.cmpn(0)===0)return h.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var p=c.redSqr(),y=p.redMul(c),g=a.redMul(p),v=h.redSqr().redIAdd(y).redISub(g).redISub(g),M=h.redMul(g.redISub(v)).redISub(s.redMul(y)),k=this.z.redMul(t.z).redMul(c);return this.curve.jpoint(v,M,k)};Lr.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var r=this.z.redSqr(),n=this.x,a=t.x.redMul(r),i=this.y,s=t.y.redMul(r).redMul(this.z),o=n.redSub(a),c=i.redSub(s);if(o.cmpn(0)===0)return c.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),p=h.redMul(o),y=n.redMul(h),g=c.redSqr().redIAdd(p).redISub(y).redISub(y),v=c.redMul(y.redISub(g)).redISub(i.redMul(p)),M=this.z.redMul(o);return this.curve.jpoint(g,v,M)};Lr.prototype.dblp=function(t){if(t===0)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var r;if(this.curve.zeroA||this.curve.threeA){var n=this;for(r=0;r=0)return!1;if(n.redIAdd(i),this.x.cmp(n)===0)return!0}};Lr.prototype.inspect=function(){return this.isInfinity()?"":""};Lr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};var fo=ri,s6=yd,gd=xd,hN=Bn;function rl(e){gd.call(this,"mont",e),this.a=new fo(e.a,16).toRed(this.red),this.b=new fo(e.b,16).toRed(this.red),this.i4=new fo(4).toRed(this.red).redInvm(),this.two=new fo(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}s6(rl,gd);var pN=rl;rl.prototype.validate=function(t){var r=t.normalize().x,n=r.redSqr(),a=n.redMul(r).redAdd(n.redMul(this.a)).redAdd(r),i=a.redSqrt();return i.redSqr().cmp(a)===0};function Cr(e,t,r){gd.BasePoint.call(this,e,"projective"),t===null&&r===null?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new fo(t,16),this.z=new fo(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}s6(Cr,gd.BasePoint);rl.prototype.decodePoint=function(t,r){return this.point(hN.toArray(t,r),1)};rl.prototype.point=function(t,r){return new Cr(this,t,r)};rl.prototype.pointFromJSON=function(t){return Cr.fromJSON(this,t)};Cr.prototype.precompute=function(){};Cr.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())};Cr.fromJSON=function(t,r){return new Cr(t,r[0],r[1]||t.one)};Cr.prototype.inspect=function(){return this.isInfinity()?"":""};Cr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};Cr.prototype.dbl=function(){var t=this.x.redAdd(this.z),r=t.redSqr(),n=this.x.redSub(this.z),a=n.redSqr(),i=r.redSub(a),s=r.redMul(a),o=i.redMul(a.redAdd(this.curve.a24.redMul(i)));return this.curve.point(s,o)};Cr.prototype.add=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.diffAdd=function(t,r){var n=this.x.redAdd(this.z),a=this.x.redSub(this.z),i=t.x.redAdd(t.z),s=t.x.redSub(t.z),o=s.redMul(n),c=i.redMul(a),h=r.z.redMul(o.redAdd(c).redSqr()),p=r.x.redMul(o.redISub(c).redSqr());return this.curve.point(h,p)};Cr.prototype.mul=function(t){for(var r=t.clone(),n=this,a=this.curve.point(null,null),i=this,s=[];r.cmpn(0)!==0;r.iushrn(1))s.push(r.andln(1));for(var o=s.length-1;o>=0;o--)s[o]===0?(n=n.diffAdd(a,i),a=a.dbl()):(a=n.diffAdd(a,i),n=n.dbl());return a};Cr.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.eq=function(t){return this.getX().cmp(t.getX())===0};Cr.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this};Cr.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var bN=Bn,Ha=ri,o6=yd,vd=xd,mN=bN.assert;function Na(e){this.twisted=(e.a|0)!==1,this.mOneA=this.twisted&&(e.a|0)===-1,this.extended=this.mOneA,vd.call(this,"edwards",e),this.a=new Ha(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new Ha(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new Ha(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),mN(!this.twisted||this.c.fromRed().cmpn(1)===0),this.oneC=(e.c|0)===1}o6(Na,vd);var xN=Na;Na.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)};Na.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)};Na.prototype.jpoint=function(t,r,n,a){return this.point(t,r,n,a)};Na.prototype.pointFromX=function(t,r){t=new Ha(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr(),a=this.c2.redSub(this.a.redMul(n)),i=this.one.redSub(this.c2.redMul(this.d).redMul(n)),s=a.redMul(i.redInvm()),o=s.redSqrt();if(o.redSqr().redSub(s).cmp(this.zero)!==0)throw new Error("invalid point");var c=o.fromRed().isOdd();return(r&&!c||!r&&c)&&(o=o.redNeg()),this.point(t,o)};Na.prototype.pointFromY=function(t,r){t=new Ha(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr(),a=n.redSub(this.c2),i=n.redMul(this.d).redMul(this.c2).redSub(this.a),s=a.redMul(i.redInvm());if(s.cmp(this.zero)===0){if(r)throw new Error("invalid point");return this.point(this.zero,t)}var o=s.redSqrt();if(o.redSqr().redSub(s).cmp(this.zero)!==0)throw new Error("invalid point");return o.fromRed().isOdd()!==r&&(o=o.redNeg()),this.point(o,t)};Na.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var r=t.x.redSqr(),n=t.y.redSqr(),a=r.redMul(this.a).redAdd(n),i=this.c2.redMul(this.one.redAdd(this.d.redMul(r).redMul(n)));return a.cmp(i)===0};function Pt(e,t,r,n,a){vd.BasePoint.call(this,e,"projective"),t===null&&r===null&&n===null?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new Ha(t,16),this.y=new Ha(r,16),this.z=n?new Ha(n,16):this.curve.one,this.t=a&&new Ha(a,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}o6(Pt,vd.BasePoint);Na.prototype.pointFromJSON=function(t){return Pt.fromJSON(this,t)};Na.prototype.point=function(t,r,n,a){return new Pt(this,t,r,n,a)};Pt.fromJSON=function(t,r){return new Pt(t,r[0],r[1],r[2])};Pt.prototype.inspect=function(){return this.isInfinity()?"":""};Pt.prototype.isInfinity=function(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Pt.prototype._extDbl=function(){var t=this.x.redSqr(),r=this.y.redSqr(),n=this.z.redSqr();n=n.redIAdd(n);var a=this.curve._mulA(t),i=this.x.redAdd(this.y).redSqr().redISub(t).redISub(r),s=a.redAdd(r),o=s.redSub(n),c=a.redSub(r),h=i.redMul(o),p=s.redMul(c),y=i.redMul(c),g=o.redMul(s);return this.curve.point(h,p,g,y)};Pt.prototype._projDbl=function(){var t=this.x.redAdd(this.y).redSqr(),r=this.x.redSqr(),n=this.y.redSqr(),a,i,s,o,c,h;if(this.curve.twisted){o=this.curve._mulA(r);var p=o.redAdd(n);this.zOne?(a=t.redSub(r).redSub(n).redMul(p.redSub(this.curve.two)),i=p.redMul(o.redSub(n)),s=p.redSqr().redSub(p).redSub(p)):(c=this.z.redSqr(),h=p.redSub(c).redISub(c),a=t.redSub(r).redISub(n).redMul(h),i=p.redMul(o.redSub(n)),s=p.redMul(h))}else o=r.redAdd(n),c=this.curve._mulC(this.z).redSqr(),h=o.redSub(c).redSub(c),a=this.curve._mulC(t.redISub(o)).redMul(h),i=this.curve._mulC(o).redMul(r.redISub(n)),s=o.redMul(h);return this.curve.point(a,i,s)};Pt.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()};Pt.prototype._extAdd=function(t){var r=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),n=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),a=this.t.redMul(this.curve.dd).redMul(t.t),i=this.z.redMul(t.z.redAdd(t.z)),s=n.redSub(r),o=i.redSub(a),c=i.redAdd(a),h=n.redAdd(r),p=s.redMul(o),y=c.redMul(h),g=s.redMul(h),v=o.redMul(c);return this.curve.point(p,y,v,g)};Pt.prototype._projAdd=function(t){var r=this.z.redMul(t.z),n=r.redSqr(),a=this.x.redMul(t.x),i=this.y.redMul(t.y),s=this.curve.d.redMul(a).redMul(i),o=n.redSub(s),c=n.redAdd(s),h=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(a).redISub(i),p=r.redMul(o).redMul(h),y,g;return this.curve.twisted?(y=r.redMul(c).redMul(i.redSub(this.curve._mulA(a))),g=o.redMul(c)):(y=r.redMul(c).redMul(i.redSub(a)),g=this.curve._mulC(o).redMul(c)),this.curve.point(p,y,g)};Pt.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)};Pt.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)};Pt.prototype.mulAdd=function(t,r,n){return this.curve._wnafMulAdd(1,[this,r],[t,n],2,!1)};Pt.prototype.jmulAdd=function(t,r,n){return this.curve._wnafMulAdd(1,[this,r],[t,n],2,!0)};Pt.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this};Pt.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Pt.prototype.getX=function(){return this.normalize(),this.x.fromRed()};Pt.prototype.getY=function(){return this.normalize(),this.y.fromRed()};Pt.prototype.eq=function(t){return this===t||this.getX().cmp(t.getX())===0&&this.getY().cmp(t.getY())===0};Pt.prototype.eqXToP=function(t){var r=t.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(r)===0)return!0;for(var n=t.clone(),a=this.curve.redN.redMul(this.z);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(r.redIAdd(a),this.x.cmp(r)===0)return!0}};Pt.prototype.toP=Pt.prototype.normalize;Pt.prototype.mixedAdd=Pt.prototype.add;(function(e){var t=e;t.base=xd,t.short=dN,t.mont=pN,t.edwards=xN})(eb);var wd={},_d={},yt={},yN=qs,gN=yd;yt.inherits=gN;function vN(e,t){return(e.charCodeAt(t)&64512)!==55296||t<0||t+1>=e.length?!1:(e.charCodeAt(t+1)&64512)===56320}function wN(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var r=[];if(typeof e=="string")if(t){if(t==="hex")for(e=e.replace(/[^a-z0-9]+/ig,""),e.length%2!==0&&(e="0"+e),a=0;a>6|192,r[n++]=i&63|128):vN(e,a)?(i=65536+((i&1023)<<10)+(e.charCodeAt(++a)&1023),r[n++]=i>>18|240,r[n++]=i>>12&63|128,r[n++]=i>>6&63|128,r[n++]=i&63|128):(r[n++]=i>>12|224,r[n++]=i>>6&63|128,r[n++]=i&63|128)}else for(a=0;a>>24|e>>>8&65280|e<<8&16711680|(e&255)<<24;return t>>>0}yt.htonl=l6;function SN(e,t){for(var r="",n=0;n>>0}return i}yt.join32=EN;function AN(e,t){for(var r=new Array(e.length*4),n=0,a=0;n>>24,r[a+1]=i>>>16&255,r[a+2]=i>>>8&255,r[a+3]=i&255):(r[a+3]=i>>>24,r[a+2]=i>>>16&255,r[a+1]=i>>>8&255,r[a]=i&255)}return r}yt.split32=AN;function NN(e,t){return e>>>t|e<<32-t}yt.rotr32=NN;function jN(e,t){return e<>>32-t}yt.rotl32=jN;function TN(e,t){return e+t>>>0}yt.sum32=TN;function MN(e,t,r){return e+t+r>>>0}yt.sum32_3=MN;function CN(e,t,r,n){return e+t+r+n>>>0}yt.sum32_4=CN;function BN(e,t,r,n,a){return e+t+r+n+a>>>0}yt.sum32_5=BN;function ON(e,t,r,n){var a=e[t],i=e[t+1],s=n+i>>>0,o=(s>>0,e[t+1]=s}yt.sum64=ON;function RN(e,t,r,n){var a=t+n>>>0,i=(a>>0}yt.sum64_hi=RN;function UN(e,t,r,n){var a=t+n;return a>>>0}yt.sum64_lo=UN;function kN(e,t,r,n,a,i,s,o){var c=0,h=t;h=h+n>>>0,c+=h>>0,c+=h>>0,c+=h>>0}yt.sum64_4_hi=kN;function zN(e,t,r,n,a,i,s,o){var c=t+n+i+o;return c>>>0}yt.sum64_4_lo=zN;function DN(e,t,r,n,a,i,s,o,c,h){var p=0,y=t;y=y+n>>>0,p+=y>>0,p+=y>>0,p+=y>>0,p+=y>>0}yt.sum64_5_hi=DN;function IN(e,t,r,n,a,i,s,o,c,h){var p=t+n+i+o+h;return p>>>0}yt.sum64_5_lo=IN;function LN(e,t,r){var n=t<<32-r|e>>>r;return n>>>0}yt.rotr64_hi=LN;function HN(e,t,r){var n=e<<32-r|t>>>r;return n>>>0}yt.rotr64_lo=HN;function qN(e,t,r){return e>>>r}yt.shr64_hi=qN;function $N(e,t,r){var n=e<<32-r|t>>>r;return n>>>0}yt.shr64_lo=$N;var nl={},_x=yt,FN=qs;function Sd(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}nl.BlockHash=Sd;Sd.prototype.update=function(t,r){if(t=_x.toArray(t,r),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){t=this.pending;var n=t.length%this._delta8;this.pending=t.slice(t.length-n,t.length),this.pending.length===0&&(this.pending=null),t=_x.join32(t,0,t.length-n,this.endian);for(var a=0;a>>24&255,a[i++]=t>>>16&255,a[i++]=t>>>8&255,a[i++]=t&255}else for(a[i++]=t&255,a[i++]=t>>>8&255,a[i++]=t>>>16&255,a[i++]=t>>>24&255,a[i++]=0,a[i++]=0,a[i++]=0,a[i++]=0,s=8;s>>3}ja.g0_256=VN;function XN(e){return pa(e,17)^pa(e,19)^e>>>10}ja.g1_256=XN;var zo=yt,ZN=nl,QN=ja,I0=zo.rotl32,gl=zo.sum32,JN=zo.sum32_5,WN=QN.ft_1,p6=ZN.BlockHash,ej=[1518500249,1859775393,2400959708,3395469782];function va(){if(!(this instanceof va))return new va;p6.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}zo.inherits(va,p6);var tj=va;va.blockSize=512;va.outSize=160;va.hmacStrength=80;va.padLength=64;va.prototype._update=function(t,r){for(var n=this.W,a=0;a<16;a++)n[a]=t[r+a];for(;athis.blockSize&&(t=new this.Hash().update(t).digest()),$j(t.length<=this.blockSize);for(var r=t.length;r=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,r,n)}var Gj=Fi;Fi.prototype._init=function(t,r,n){var a=t.concat(r).concat(n);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(n||[])),this._reseed=1};Fi.prototype.generate=function(t,r,n,a){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");typeof r!="string"&&(a=n,n=r,r=null),n&&(n=ys.toArray(n,a||"hex"),this._update(n));for(var i=[];i.length"};var jf=ri,rb=Bn,Zj=rb.assert;function Ed(e,t){if(e instanceof Ed)return e;this._importDER(e,t)||(Zj(e.r&&e.s,"Signature without r or s"),this.r=new jf(e.r,16),this.s=new jf(e.s,16),e.recoveryParam===void 0?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}var Qj=Ed;function Jj(){this.place=0}function $0(e,t){var r=e[t.place++];if(!(r&128))return r;var n=r&15;if(n===0||n>4||e[t.place]===0)return!1;for(var a=0,i=0,s=t.place;i>>=0;return a<=127?!1:(t.place=s,a)}function jx(e){for(var t=0,r=e.length-1;!e[t]&&!(e[t+1]&128)&&t>>3);for(e.push(r|128);--r;)e.push(t>>>(r<<3)&255);e.push(t)}Ed.prototype.toDER=function(t){var r=this.r.toArray(),n=this.s.toArray();for(r[0]&128&&(r=[0].concat(r)),n[0]&128&&(n=[0].concat(n)),r=jx(r),n=jx(n);!n[0]&&!(n[1]&128);)n=n.slice(1);var a=[2];F0(a,r.length),a=a.concat(r),a.push(2),F0(a,n.length);var i=a.concat(n),s=[48];return F0(s,i.length),s=s.concat(i),rb.encode(s,t)};var na=ri,N6=Gj,Wj=Bn,K0=wd,eT=i6,os=Wj.assert,nb=Xj,Ad=Qj;function Vn(e){if(!(this instanceof Vn))return new Vn(e);typeof e=="string"&&(os(Object.prototype.hasOwnProperty.call(K0,e),"Unknown curve "+e),e=K0[e]),e instanceof K0.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash}var tT=Vn;Vn.prototype.keyPair=function(t){return new nb(this,t)};Vn.prototype.keyFromPrivate=function(t,r){return nb.fromPrivate(this,t,r)};Vn.prototype.keyFromPublic=function(t,r){return nb.fromPublic(this,t,r)};Vn.prototype.genKeyPair=function(t){t||(t={});for(var r=new N6({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||eT(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),n=this.n.byteLength(),a=this.n.sub(new na(2));;){var i=new na(r.generate(n));if(!(i.cmp(a)>0))return i.iaddn(1),this.keyFromPrivate(i)}};Vn.prototype._truncateToN=function(t,r,n){var a;if(na.isBN(t)||typeof t=="number")t=new na(t,16),a=t.byteLength();else if(typeof t=="object")a=t.length,t=new na(t,16);else{var i=t.toString();a=i.length+1>>>1,t=new na(i,16)}typeof n!="number"&&(n=a*8);var s=n-this.n.bitLength();return s>0&&(t=t.ushrn(s)),!r&&t.cmp(this.n)>=0?t.sub(this.n):t};Vn.prototype.sign=function(t,r,n,a){if(typeof n=="object"&&(a=n,n=null),a||(a={}),typeof t!="string"&&typeof t!="number"&&!na.isBN(t)){os(typeof t=="object"&&t&&typeof t.length=="number","Expected message to be an array-like, a hex string, or a BN instance"),os(t.length>>>0===t.length);for(var i=0;i=0)){var v=this.g.mul(g);if(!v.isInfinity()){var M=v.getX(),k=M.umod(this.n);if(k.cmpn(0)!==0){var K=g.invm(this.n).mul(k.mul(r.getPrivate()).iadd(t));if(K=K.umod(this.n),K.cmpn(0)!==0){var D=(v.getY().isOdd()?1:0)|(M.cmp(k)!==0?2:0);return a.canonical&&K.cmp(this.nh)>0&&(K=this.n.sub(K),D^=1),new Ad({r:k,s:K,recoveryParam:D})}}}}}};Vn.prototype.verify=function(t,r,n,a,i){i||(i={}),t=this._truncateToN(t,!1,i.msgBitLength),n=this.keyFromPublic(n,a),r=new Ad(r,"hex");var s=r.r,o=r.s;if(s.cmpn(1)<0||s.cmp(this.n)>=0||o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;var c=o.invm(this.n),h=c.mul(t).umod(this.n),p=c.mul(s).umod(this.n),y;return this.curve._maxwellTrick?(y=this.g.jmulAdd(h,n.getPublic(),p),y.isInfinity()?!1:y.eqXToP(s)):(y=this.g.mulAdd(h,n.getPublic(),p),y.isInfinity()?!1:y.getX().umod(this.n).cmp(s)===0)};Vn.prototype.recoverPubKey=function(e,t,r,n){os((3&r)===r,"The recovery param is more than two bits"),t=new Ad(t,n);var a=this.n,i=new na(e),s=t.r,o=t.s,c=r&1,h=r>>1;if(s.cmp(this.curve.p.umod(this.curve.n))>=0&&h)throw new Error("Unable to find sencond key candinate");h?s=this.curve.pointFromX(s.add(this.curve.n),c):s=this.curve.pointFromX(s,c);var p=t.r.invm(a),y=a.sub(i).mul(p).umod(a),g=o.mul(p).umod(a);return this.g.mulAdd(y,s,g)};Vn.prototype.getKeyRecoveryParam=function(e,t,r,n){if(t=new Ad(t,n),t.recoveryParam!==null)return t.recoveryParam;for(var a=0;a<4;a++){var i;try{i=this.recoverPubKey(e,t,a)}catch{continue}if(i.eq(r))return a}throw new Error("Unable to find valid recovery factor")};var $c=Bn,j6=$c.assert,Tx=$c.parseBytes,sl=$c.cachedProperty;function Mr(e,t){this.eddsa=e,this._secret=Tx(t.secret),e.isPoint(t.pub)?this._pub=t.pub:this._pubBytes=Tx(t.pub)}Mr.fromPublic=function(t,r){return r instanceof Mr?r:new Mr(t,{pub:r})};Mr.fromSecret=function(t,r){return r instanceof Mr?r:new Mr(t,{secret:r})};Mr.prototype.secret=function(){return this._secret};sl(Mr,"pubBytes",function(){return this.eddsa.encodePoint(this.pub())});sl(Mr,"pub",function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())});sl(Mr,"privBytes",function(){var t=this.eddsa,r=this.hash(),n=t.encodingLength-1,a=r.slice(0,t.encodingLength);return a[0]&=248,a[n]&=127,a[n]|=64,a});sl(Mr,"priv",function(){return this.eddsa.decodeInt(this.privBytes())});sl(Mr,"hash",function(){return this.eddsa.hash().update(this.secret()).digest()});sl(Mr,"messagePrefix",function(){return this.hash().slice(this.eddsa.encodingLength)});Mr.prototype.sign=function(t){return j6(this._secret,"KeyPair can only verify"),this.eddsa.sign(t,this)};Mr.prototype.verify=function(t,r){return this.eddsa.verify(t,r,this)};Mr.prototype.getSecret=function(t){return j6(this._secret,"KeyPair is public only"),$c.encode(this.secret(),t)};Mr.prototype.getPublic=function(t){return $c.encode(this.pubBytes(),t)};var rT=Mr,nT=ri,Nd=Bn,Mx=Nd.assert,jd=Nd.cachedProperty,aT=Nd.parseBytes;function $s(e,t){this.eddsa=e,typeof t!="object"&&(t=aT(t)),Array.isArray(t)&&(Mx(t.length===e.encodingLength*2,"Signature has invalid size"),t={R:t.slice(0,e.encodingLength),S:t.slice(e.encodingLength)}),Mx(t.R&&t.S,"Signature without R or S"),e.isPoint(t.R)&&(this._R=t.R),t.S instanceof nT&&(this._S=t.S),this._Rencoded=Array.isArray(t.R)?t.R:t.Rencoded,this._Sencoded=Array.isArray(t.S)?t.S:t.Sencoded}jd($s,"S",function(){return this.eddsa.decodeInt(this.Sencoded())});jd($s,"R",function(){return this.eddsa.decodePoint(this.Rencoded())});jd($s,"Rencoded",function(){return this.eddsa.encodePoint(this.R())});jd($s,"Sencoded",function(){return this.eddsa.encodeInt(this.S())});$s.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())};$s.prototype.toHex=function(){return Nd.encode(this.toBytes(),"hex").toUpperCase()};var iT=$s,sT=_d,oT=wd,Lo=Bn,lT=Lo.assert,T6=Lo.parseBytes,M6=rT,Cx=iT;function hn(e){if(lT(e==="ed25519","only tested with ed25519 so far"),!(this instanceof hn))return new hn(e);e=oT[e].curve,this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=sT.sha512}var cT=hn;hn.prototype.sign=function(t,r){t=T6(t);var n=this.keyFromSecret(r),a=this.hashInt(n.messagePrefix(),t),i=this.g.mul(a),s=this.encodePoint(i),o=this.hashInt(s,n.pubBytes(),t).mul(n.priv()),c=a.add(o).umod(this.curve.n);return this.makeSignature({R:i,S:c,Rencoded:s})};hn.prototype.verify=function(t,r,n){if(t=T6(t),r=this.makeSignature(r),r.S().gte(r.eddsa.curve.n)||r.S().isNeg())return!1;var a=this.keyFromPublic(n),i=this.hashInt(r.Rencoded(),a.pubBytes(),t),s=this.g.mul(r.S()),o=r.R().add(a.pub().mul(i));return o.eq(s)};hn.prototype.hashInt=function(){for(var t=this.hash(),r=0;r=0)return null;r=r.toRed(bt.red);let n=r.redSqr().redIMul(r).redIAdd(bt.b).redSqrt();e===3!==n.isOdd()&&(n=n.redNeg());const a=r.redSqr().redIMul(r);return n.redSqr().redISub(a.redIAdd(bt.b)).isZero()?sa.keyPair({pub:{x:r,y:n}}):null}function dT(e,t,r){let n=new Ht(t),a=new Ht(r);if(n.cmp(bt.p)>=0||a.cmp(bt.p)>=0||(n=n.toRed(bt.red),a=a.toRed(bt.red),(e===6||e===7)&&a.isOdd()!==(e===7)))return null;const i=n.redSqr().redIMul(n);return a.redSqr().redISub(i.redIAdd(bt.b)).isZero()?sa.keyPair({pub:{x:n,y:a}}):null}function oi(e){const t=e[0];switch(t){case 2:case 3:return e.length!==33?null:fT(t,e.subarray(1,33));case 4:case 6:case 7:return e.length!==65?null:dT(t,e.subarray(1,33),e.subarray(33,65));default:return null}}function rs(e,t){const r=t.encode(null,e.length===33);for(let n=0;n=0||(r.iadd(new Ht(e)),r.cmp(bt.n)>=0&&r.isub(bt.n),r.isZero()))return 1;const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},privateKeyTweakMul(e,t){let r=new Ht(t);if(r.cmp(bt.n)>=0||r.isZero())return 1;r.imul(new Ht(e)),r.cmp(bt.n)>=0&&(r=r.umod(bt.n));const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},publicKeyVerify(e){return oi(e)===null?1:0},publicKeyCreate(e,t){const r=new Ht(t);if(r.cmp(bt.n)>=0||r.isZero())return 1;const n=sa.keyFromPrivate(t).getPublic();return rs(e,n),0},publicKeyConvert(e,t){const r=oi(t);if(r===null)return 1;const n=r.getPublic();return rs(e,n),0},publicKeyNegate(e,t){const r=oi(t);if(r===null)return 1;const n=r.getPublic();return n.y=n.y.redNeg(),rs(e,n),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let a=0;a=0)return 2;const a=n.getPublic().add(bt.g.mul(r));return a.isInfinity()?2:(rs(e,a),0)},publicKeyTweakMul(e,t,r){const n=oi(t);if(n===null)return 1;if(r=new Ht(r),r.cmp(bt.n)>=0||r.isZero())return 2;const a=n.getPublic().mul(r);return rs(e,a),0},signatureNormalize(e){const t=new Ht(e.subarray(0,32)),r=new Ht(e.subarray(32,64));return t.cmp(bt.n)>=0||r.cmp(bt.n)>=0?1:(r.cmp(sa.nh)===1&&e.set(bt.n.sub(r).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,t){const r=t.subarray(0,32),n=t.subarray(32,64);if(new Ht(r).cmp(bt.n)>=0||new Ht(n).cmp(bt.n)>=0)return 1;const{output:a}=e;let i=a.subarray(4,37);i[0]=0,i.set(r,1);let s=33,o=0;for(;s>1&&i[o]===0&&!(i[o+1]&128);--s,++o);if(i=i.subarray(o),i[0]&128||s>1&&i[0]===0&&!(i[1]&128))return 1;let c=a.subarray(39,72);c[0]=0,c.set(n,1);let h=33,p=0;for(;h>1&&c[p]===0&&!(c[p+1]&128);--h,++p);return c=c.subarray(p),c[0]&128||h>1&&c[0]===0&&!(c[1]&128)?1:(e.outputlen=6+s+h,a[0]=48,a[1]=e.outputlen-2,a[2]=2,a[3]=i.length,a.set(i,4),a[4+s]=2,a[5+s]=c.length,a.set(c,6+s),0)},signatureImport(e,t){if(t.length<8||t.length>72||t[0]!==48||t[1]!==t.length-2||t[2]!==2)return 1;const r=t[3];if(r===0||5+r>=t.length||t[4+r]!==2)return 1;const n=t[5+r];if(n===0||6+r+n!==t.length||t[4]&128||r>1&&t[4]===0&&!(t[5]&128)||t[r+6]&128||n>1&&t[r+6]===0&&!(t[r+7]&128))return 1;let a=t.subarray(4,4+r);if(a.length===33&&a[0]===0&&(a=a.subarray(1)),a.length>32)return 1;let i=t.subarray(6+r);if(i.length===33&&i[0]===0&&(i=i.slice(1)),i.length>32)throw new Error("S length is too long");let s=new Ht(a);s.cmp(bt.n)>=0&&(s=new Ht(0));let o=new Ht(t.subarray(6+r));return o.cmp(bt.n)>=0&&(o=new Ht(0)),e.set(s.toArrayLike(Uint8Array,"be",32),0),e.set(o.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(e,t,r,n,a){if(a){const o=a;a=c=>{const h=o(t,r,null,n,c);if(!(h instanceof Uint8Array&&h.length===32))throw new Error("This is the way");return new Ht(h)}}const i=new Ht(r);if(i.cmp(bt.n)>=0||i.isZero())return 1;let s;try{s=sa.sign(t,r,{canonical:!0,k:a,pers:n})}catch{return 1}return e.signature.set(s.r.toArrayLike(Uint8Array,"be",32),0),e.signature.set(s.s.toArrayLike(Uint8Array,"be",32),32),e.recid=s.recoveryParam,0},ecdsaVerify(e,t,r){const n={r:e.subarray(0,32),s:e.subarray(32,64)},a=new Ht(n.r),i=new Ht(n.s);if(a.cmp(bt.n)>=0||i.cmp(bt.n)>=0)return 1;if(i.cmp(sa.nh)===1||a.isZero()||i.isZero())return 3;const s=oi(r);if(s===null)return 2;const o=s.getPublic();return sa.verify(t,n,o)?0:3},ecdsaRecover(e,t,r,n){const a={r:t.slice(0,32),s:t.slice(32,64)},i=new Ht(a.r),s=new Ht(a.s);if(i.cmp(bt.n)>=0||s.cmp(bt.n)>=0)return 1;if(i.isZero()||s.isZero())return 2;let o;try{o=sa.recoverPubKey(n,a,r)}catch{return 2}return rs(e,o),0},ecdh(e,t,r,n,a,i,s){const o=oi(t);if(o===null)return 1;const c=new Ht(r);if(c.cmp(bt.n)>=0||c.isZero())return 2;const h=o.getPublic().mul(c);if(a===void 0){const p=h.encode(null,!0),y=sa.hash().update(p).digest();for(let g=0;g<32;++g)e[g]=y[g]}else{i||(i=new Uint8Array(32));const p=h.getX().toArray("be",32);for(let M=0;M<32;++M)i[M]=p[M];s||(s=new Uint8Array(32));const y=h.getY().toArray("be",32);for(let M=0;M<32;++M)s[M]=y[M];const g=a(i,s,n);if(!(g instanceof Uint8Array&&g.length===e.length))return 2;e.set(g)}return 0}},C6=sN(hT),pT=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(el,"__esModule",{value:!0});el.PublicKey=void 0;const Bx=Wo,bT=$1,mT=pT(C6),ln=Ja;function xT(e){switch(e){case ln.KeyType.ED25519:return"ed25519";case ln.KeyType.SECP256K1:return"secp256k1";default:throw new Error(`Unknown key type ${e}`)}}function yT(e){switch(e.toLowerCase()){case"ed25519":return ln.KeyType.ED25519;case"secp256k1":return ln.KeyType.SECP256K1;default:throw new Error(`Unknown key type ${e}`)}}function gT(e){switch(e){case ln.KeyType.ED25519:return"ed25519Key";case ln.KeyType.SECP256K1:return"secp256k1Key";default:throw Error(`unknown type ${e}`)}}class vT{constructor(t){if(Object.keys(t).length!==1)throw new Error("Enum can only take single value");Object.keys(t).map(r=>{this[r]=t[r]})}}class Tf extends vT{constructor(r){const n=gT(r.keyType);super({[n]:r});Bt(this,"enum");Bt(this,"ed25519Key");Bt(this,"secp256k1Key");this[n]=r,this.enum=n}static from(r){return typeof r=="string"?Tf.fromString(r):r}static fromString(r){const n=r.split(":");let a,i;if(n.length===1)a=n[0];else if(n.length===2)a=n[1],i=yT(n[0]);else throw new Error("Invalid encoded key format, must be :");const s=(0,Bx.baseDecode)(a);i||(i=s.length===ln.KeySize.SECP256k1_PUBLIC_KEY?ln.KeyType.SECP256K1:ln.KeyType.ED25519);const o=i===ln.KeyType.ED25519?ln.KeySize.ED25519_PUBLIC_KEY:ln.KeySize.SECP256k1_PUBLIC_KEY;if(s.length!==o)throw new Error(`Invalid public key size (${s.length}), must be ${o}`);return new Tf({keyType:i,data:s})}toString(){const r=(0,Bx.baseEncode)(this.data);return`${xT(this.keyType)}:${r}`}verify(r,n){const a=this.keyType,i=this.data;switch(a){case ln.KeyType.ED25519:return bT.ed25519.verify(n,r,i);case ln.KeyType.SECP256K1:return mT.default.ecdsaVerify(n.subarray(0,64),r,new Uint8Array([4,...i]));default:throw new Error(`Unknown key type: ${a}`)}}get keyPair(){return this.ed25519Key||this.secp256k1Key}get keyType(){return this.keyPair.keyType}get data(){return this.keyPair.data}}el.PublicKey=Tf;var wT=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(zc,"__esModule",{value:!0});zc.KeyPairEd25519=void 0;const mu=Wo,P0=$1,_T=wT(r6),G0=Ja,ST=Jo,ET=el;class ab extends ST.KeyPairBase{constructor(r){super();Bt(this,"publicKey");Bt(this,"secretKey");Bt(this,"extendedSecretKey");const n=(0,mu.baseDecode)(r),a=new Uint8Array(n.slice(0,G0.KeySize.SECRET_KEY)),i=P0.ed25519.getPublicKey(new Uint8Array(a));this.publicKey=new ET.PublicKey({keyType:G0.KeyType.ED25519,data:i}),this.secretKey=(0,mu.baseEncode)(a),this.extendedSecretKey=r}static fromRandom(){const r=(0,_T.default)(G0.KeySize.SECRET_KEY),n=P0.ed25519.getPublicKey(new Uint8Array(r)),a=new Uint8Array([...r,...n]);return new ab((0,mu.baseEncode)(a))}sign(r){return{signature:P0.ed25519.sign(r,(0,mu.baseDecode)(this.secretKey)),publicKey:this.publicKey}}verify(r,n){return this.publicKey.verify(r,n)}toString(){return`ed25519:${this.extendedSecretKey}`}getPublicKey(){return this.publicKey}}zc.KeyPairEd25519=ab;var Fc={},B6=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Fc,"__esModule",{value:!0});Fc.KeyPairSecp256k1=void 0;const xu=Wo,AT=B6(r6),Y0=B6(C6),V0=Ja,NT=Jo,jT=el;class ib extends NT.KeyPairBase{constructor(r){super();Bt(this,"publicKey");Bt(this,"secretKey");Bt(this,"extendedSecretKey");const n=(0,xu.baseDecode)(r),a=new Uint8Array(n.slice(0,V0.KeySize.SECRET_KEY)),i=Y0.default.publicKeyCreate(new Uint8Array(a),!1),s=i.subarray(1,i.length);this.publicKey=new jT.PublicKey({keyType:V0.KeyType.SECP256K1,data:s}),this.secretKey=(0,xu.baseEncode)(a),this.extendedSecretKey=r}static fromRandom(){const r=(0,AT.default)(V0.KeySize.SECRET_KEY),n=Y0.default.publicKeyCreate(new Uint8Array(r),!1),a=n.subarray(1,n.length),i=new Uint8Array([...r,...a]);return new ib((0,xu.baseEncode)(i))}sign(r){const{signature:n,recid:a}=Y0.default.ecdsaSign(r,(0,xu.baseDecode)(this.secretKey));return{signature:new Uint8Array([...n,a]),publicKey:this.publicKey}}verify(r,n){return this.publicKey.verify(r,n)}toString(){return`secp256k1:${this.extendedSecretKey}`}getPublicKey(){return this.publicKey}}Fc.KeyPairSecp256k1=ib;Object.defineProperty(rd,"__esModule",{value:!0});rd.KeyPair=void 0;const TT=Jo,Ox=zc,Rx=Fc;class MT extends TT.KeyPairBase{static fromRandom(t){switch(t.toUpperCase()){case"ED25519":return Ox.KeyPairEd25519.fromRandom();case"SECP256K1":return Rx.KeyPairSecp256k1.fromRandom();default:throw new Error(`Unknown curve ${t}`)}}static fromString(t){const r=t.split(":");if(r.length===2)switch(r[0].toUpperCase()){case"ED25519":return new Ox.KeyPairEd25519(r[1]);case"SECP256K1":return new Rx.KeyPairSecp256k1(r[1]);default:throw new Error(`Unknown curve: ${r[0]}`)}else throw new Error("Invalid encoded key format, must be :")}}rd.KeyPair=MT;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.PublicKey=e.KeyPairSecp256k1=e.KeyPairEd25519=e.KeyPair=e.KeyType=void 0;var t=Ja;Object.defineProperty(e,"KeyType",{enumerable:!0,get:function(){return t.KeyType}});var r=rd;Object.defineProperty(e,"KeyPair",{enumerable:!0,get:function(){return r.KeyPair}});var n=zc;Object.defineProperty(e,"KeyPairEd25519",{enumerable:!0,get:function(){return n.KeyPairEd25519}});var a=Fc;Object.defineProperty(e,"KeyPairSecp256k1",{enumerable:!0,get:function(){return a.KeyPairSecp256k1}});var i=el;Object.defineProperty(e,"PublicKey",{enumerable:!0,get:function(){return i.PublicKey}})})(r3);(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(p,y,g,v){v===void 0&&(v=g);var M=Object.getOwnPropertyDescriptor(y,g);(!M||("get"in M?!y.__esModule:M.writable||M.configurable))&&(M={enumerable:!0,get:function(){return y[g]}}),Object.defineProperty(p,v,M)}:function(p,y,g,v){v===void 0&&(v=g),p[v]=y[g]}),r=Ie&&Ie.__setModuleDefault||(Object.create?function(p,y){Object.defineProperty(p,"default",{enumerable:!0,value:y})}:function(p,y){p.default=y}),n=Ie&&Ie.__importStar||function(p){if(p&&p.__esModule)return p;var y={};if(p!=null)for(var g in p)g!=="default"&&Object.prototype.hasOwnProperty.call(p,g)&&t(y,p,g);return r(y,p),y},a=Ie&&Ie.__importDefault||function(p){return p&&p.__esModule?p:{default:p}};Object.defineProperty(e,"__esModule",{value:!0}),e.authPayloadSchema=e.AuthPayload=void 0,e.verifySignature=h;const i=n(Oo),s=a(Q7),o=r3;class c{constructor({message:y,nonce:g,recipient:v}){Bt(this,"message");Bt(this,"recipient");Bt(this,"nonce");Bt(this,"callbackUrl");Bt(this,"tag");this.tag=2147484061,this.message=y,this.nonce=g,this.recipient=v}}e.AuthPayload=c,e.authPayloadSchema={struct:{tag:"u32",message:"string",nonce:{array:{type:"u8",len:32}},recipient:"string",callbackUrl:{option:"string"}}};function h(p,y){const g=new c(p),v=i.serialize(e.authPayloadSchema,g),M=Uint8Array.from(s.default.sha256.array(v));let k=new Uint8Array(Buffer.from(y.signature,"base64"));return o.PublicKey.from(y.publicKey).verify(M,k)}})(Wv);var O6={};const CT=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function R6(e){return CT.test(e)}function xp(){var e=URL.createObjectURL(new Blob),t=e.toString();return URL.revokeObjectURL(e),t.split(/[:\/]/g).pop().toLowerCase()}xp.valid=R6;const BT=Object.freeze(Object.defineProperty({__proto__:null,default:xp,uuid4:xp,valid:R6},Symbol.toStringTag,{value:"Module"})),U6=Yx(BT);var k6={},z6={exports:{}},D6={exports:{}};(function(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t={rotl:function(r,n){return r<>>32-n},rotr:function(r,n){return r<<32-n|r>>>n},endian:function(r){if(r.constructor==Number)return t.rotl(r,8)&16711935|t.rotl(r,24)&4278255360;for(var n=0;n0;r--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(r){for(var n=[],a=0,i=0;a>>5]|=r[a]<<24-i%32;return n},wordsToBytes:function(r){for(var n=[],a=0;a>>5]>>>24-a%32&255);return n},bytesToHex:function(r){for(var n=[],a=0;a>>4).toString(16)),n.push((r[a]&15).toString(16));return n.join("")},hexToBytes:function(r){for(var n=[],a=0;a>>6*(3-s)&63)):n.push("=");return n.join("")},base64ToBytes:function(r){r=r.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],a=0,i=0;a>>6-i*2);return n}};D6.exports=t})();var OT=D6.exports,yp={utf8:{stringToBytes:function(e){return yp.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(yp.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],r=0;r>5]|=128<<24-o%32,s[(o+64>>>9<<4)+15]=o;for(var M=0;M>>31}var F=(h<<5|h>>>27)+v+(c[L]>>>0)+(L<20?(p&y|~p&g)+1518500249:L<40?(p^y^g)+1859775393:L<60?(p&y|p&g|y&g)-1894007588:(p^y^g)-899497514);v=g,g=y,y=p<<30|p>>>2,p=h,h=F}h+=k,p+=K,y+=D,g+=T,v+=z}return[h,p,y,g,v]},a=function(i,s){var o=e.wordsToBytes(n(i));return s&&s.asBytes?o:s&&s.asString?r.bytesToString(o):e.bytesToHex(o)};a._blocksize=16,a._digestsize=20,z6.exports=a})();var RT=z6.exports;(function(e){var t=Ie&&Ie.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(e,"__esModule",{value:!0}),e.createRequest=e.computeRequestId=e.deleteRequest=e.getResponse=e.proxyApi=void 0;const r=t(RT),n=t(U6),a=Wo;e.proxyApi="https://h4n.app";const i=async h=>{const p=await fetch(`${e.proxyApi}/${h}/response`,{headers:{"content-type":"application/json"},method:"GET"});if(p.ok===!1)throw Error(await p.text());const{data:y}=await p.json();return JSON.parse(y)};e.getResponse=i;const s=async h=>{const p=await fetch(`${e.proxyApi}/${h}`,{headers:{"content-type":"application/json"},method:"DELETE"});if(p.ok===!1)throw Error(await p.text())};e.deleteRequest=s;const o=async h=>{const p=(0,a.baseEncode)(JSON.stringify({...h,_id:(0,n.default)()})),y=(0,r.default)(p);return{requestId:Buffer.from(y,"hex").toString("base64").replaceAll("/","_").replaceAll("-","+").slice(0,13),query:p}};e.computeRequestId=o;const c=async(h,p)=>{const{query:y,requestId:g}=await(0,e.computeRequestId)(h),v=await fetch(`${e.proxyApi}/${g}/request`,{body:JSON.stringify({data:y}),headers:{"content-type":"application/json"},method:"POST",signal:p});if(v.ok===!1)throw Error(await v.text());return g};e.createRequest=c})(k6);(function(e){var t=Ie&&Ie.__importDefault||function(y){return y&&y.__esModule?y:{default:y}};Object.defineProperty(e,"__esModule",{value:!0}),e.getExtension=e.RequestFailed=e.wait=void 0;const r=t(U6),n=Wo,a=k6,i=y=>new Promise(g=>setTimeout(g,y));e.wait=i;class s extends Error{constructor(v){super();Bt(this,"payload");Bt(this,"name","RequestFailed");this.payload=v}}e.RequestFailed=s;const o=()=>typeof window>"u"?null:window.hotExtension;e.getExtension=o;let c;typeof window<"u"&&window.addEventListener("message",y=>{y.data==="hot-close"&&(c==null||c.remove(),c=void 0)});const h=y=>{c==null||c.remove(),c=document.createElement("div");const g=document.createElement("iframe");return c==null||c.appendChild(g),g.src=y,g.allow="usb",g.style.border="none",g.style.borderRadius="16px",g.style.background="#fff",g.style.overflow="hidden",g.style.background="#1D1F20",g.style.border="1px solid #2C3034",g.style.width="375px",g.style.height="560px",g.onclick=v=>v.stopPropagation(),c.style.padding="16px",c.style.zIndex="100000000000000",c.style.position="fixed",c.style.display="flex",c.style.justifyContent="center",c.style.alignItems="center",c.style.top="0",c.style.left="0",c.style.width="100%",c.style.height="100%",c.style.background="rgba(0, 0, 0, 0.1)",c.style.backdropFilter="blur(24px)",c.onclick=()=>{c==null||c.remove(),c=void 0},document.body.appendChild(c),c};class p{constructor(){Bt(this,"walletId","https://t.me/herewalletbot/app");Bt(this,"ancestorOrigins",["http://localhost:1234","https://my.herewallet.app","https://tgapp-dev.herewallet.app","https://tgapp.herewallet.app","https://beta.herewallet.app"]);Bt(this,"connection",new Promise(g=>{if(typeof window>"u"||(window==null?void 0:window.self)===(window==null?void 0:window.top))return g(null);this.injectedRequest("initialized",{}).then(g).catch(()=>g(null))}));Bt(this,"openInHotBrowserUrl",null);Bt(this,"customProvider")}get isInjected(){var g;return typeof window>"u"?!1:window.hotExtension!=null?window.hotExtension.autoRun:this.ancestorOrigins.includes((g=window.location.ancestorOrigins)==null?void 0:g[0])}toggleOpenInHotBrowser(g){this.openInHotBrowserUrl=g}setupEthProvider(g){this.customProvider=g}async injectedRequest(g,v){const M=(0,r.default)();return new Promise((k,K)=>{const D=T=>{if(T.data.id===M)return window==null||window.removeEventListener("message",D),T.data.success?k(T.data.payload):K(T.data.payload)};window==null||window.parent.postMessage({$hot:!0,method:g,request:v,id:M},"*"),window==null||window.addEventListener("message",D)})}subscribe(g,v){return window.hotExtension?window.hotExtension.subscribe(g,v):()=>{}}async request(g,v){var L;if(window.hotExtension!=null)return window.hotExtension.request(g,v);if(this.isInjected)return this.injectedRequest(g,v);const M=(0,r.default)(),k=(L=window==null?void 0:window.Telegram)==null?void 0:L.WebApp,K=await(0,a.createRequest)({inside:!!this.openInHotBrowserUrl||g==="ethereum"&&this.customProvider==null,origin:typeof this.openInHotBrowserUrl=="string"?this.openInHotBrowserUrl:location.href,$hot:!0,method:g,request:v,id:M}),D=`${this.walletId}?startapp=hotconnect-${(0,n.baseEncode)(K)}`;k?k==null||k.openTelegramLink(D):h(`https://hot-labs.org/hot-widget/index.html?hotconnect-${(0,n.baseEncode)(K)}`);const T=async()=>{await(0,e.wait)(3e3);const $=await(0,a.getResponse)(K).catch(()=>null);if($==null)return await T();if($.success)return $.payload;throw new s($.payload)},z=await T();return c==null||c.remove(),z}}e.default=new p})(O6);(function(e){var t=Ie&&Ie.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(e,"__esModule",{value:!0}),e.RequestFailed=e.HOT=e.authPayloadSchema=e.AuthPayload=e.verifySignature=void 0;var r=Wv;Object.defineProperty(e,"verifySignature",{enumerable:!0,get:function(){return r.verifySignature}}),Object.defineProperty(e,"AuthPayload",{enumerable:!0,get:function(){return r.AuthPayload}}),Object.defineProperty(e,"authPayloadSchema",{enumerable:!0,get:function(){return r.authPayloadSchema}});var n=O6;Object.defineProperty(e,"HOT",{enumerable:!0,get:function(){return t(n).default}}),Object.defineProperty(e,"RequestFailed",{enumerable:!0,get:function(){return n.RequestFailed}})})(w7);function cn(e){var t,r,n;return{code:((t=e==null?void 0:e.error)==null?void 0:t.code)||(e==null?void 0:e.code)||-1,message:((r=e==null?void 0:e.error)==null?void 0:r.message)||(e==null?void 0:e.message)||typeof e=="string"&&e||"Unhandled error from the wallet",ext:((n=e==null?void 0:e.error)==null?void 0:n.ext)||(e==null?void 0:e.ext)}}const I6=re.createContext(null),X0="clevercon_pubkey",Z0="clevercon_wallet_id",UT=bs.TESTNET;function Q0(e){return new b9({network:UT,selectedWalletId:e,modules:[new f7,new v7,new t7,new h7,new b7]})}function kT({children:e}){const[t,r]=re.useState(null),[n,a]=re.useState(null),[i,s]=re.useState(!0),o=re.useRef(Q0());re.useEffect(()=>{const g=localStorage.getItem(X0),v=localStorage.getItem(Z0);g&&v&&(o.current=Q0(v),r(g),a(v)),s(!1)},[]);const c=async g=>{s(!0);try{o.current=Q0(g),o.current.setWallet(g);const{address:v}=await o.current.getAddress();if(!v)throw new Error("Could not retrieve public key from wallet.");r(v),a(g),localStorage.setItem(X0,v),localStorage.setItem(Z0,g)}finally{s(!1)}},h=()=>{var g,v;(v=(g=o.current).disconnect)==null||v.call(g).catch(()=>{}),r(null),a(null),localStorage.removeItem(X0),localStorage.removeItem(Z0)},p=async(g,v)=>{const{signedTxXdr:M}=await o.current.signTransaction(g,{networkPassphrase:v});if(!M)throw new Error("Wallet returned no signed XDR.");return M},y=()=>o.current.getSupportedWallets();return l.jsx(I6.Provider,{value:{publicKey:t,isConnected:!!t,isLoading:i,walletId:n,connect:c,disconnect:h,signTransaction:p,getSupportedWallets:y},children:e})}function On(){const e=re.useContext(I6);if(!e)throw new Error("useWallet must be used within WalletProvider");return e}const Td="";async function sb(e){const t=await fetch(`${Td}/api/vault/account/${e}`);if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error??`HTTP ${t.status}`)}return t.json()}async function zT(e,t){const r=await fetch(`${Td}/api/vault/deposit-xdr`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,amount:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Failed to build deposit XDR");return n.xdr}async function DT(e,t){const r=await fetch(`${Td}/api/vault/withdraw-xdr`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,amount:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Failed to build withdraw XDR");return n.xdr}async function kx(e,t){const r=await fetch(`${Td}/api/vault/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({signed_xdr:e,...t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Transaction failed");return n.tx_hash}const IT=["What's the current XLM price and any recent Stellar news?","Analyze Stellar DEX activity and write a market briefing","Get blockchain news, live prices and compile a full report"];function LT({available:e,required:t,orchestratorName:r,onFund:n,onClose:a}){const i=Math.max(0,t-e);return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-sm bg-gray-900 border border-amber-800/50 rounded-2xl shadow-2xl",children:[l.jsx("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-950 border border-amber-800 flex items-center justify-center shrink-0",children:l.jsx(Ka,{size:16,className:"text-amber-400"})}),l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-semibold text-white mb-0.5",children:"Insufficient vault balance"}),l.jsxs("p",{className:"text-xs text-gray-400 leading-relaxed",children:[r," needs ",l.jsxs("span",{className:"text-white font-semibold",children:["$",t.toFixed(2)," USDC"]})," to run this task."]})]}),l.jsx("button",{onClick:a,className:"text-gray-600 hover:text-gray-400 ml-auto shrink-0",children:l.jsx(xa,{size:14})})]})}),l.jsxs("div",{className:"px-5 py-4 space-y-3",children:[l.jsxs("div",{className:"flex justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Your vault balance"}),l.jsxs("span",{className:"text-white font-mono font-semibold",children:["$",e.toFixed(4)," USDC"]})]}),l.jsxs("div",{className:"flex justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Task budget"}),l.jsxs("span",{className:"text-white font-mono font-semibold",children:["$",t.toFixed(4)," USDC"]})]}),l.jsxs("div",{className:"flex justify-between text-xs border-t border-gray-800 pt-3",children:[l.jsx("span",{className:"text-amber-400",children:"Deposit needed"}),l.jsxs("span",{className:"text-amber-400 font-mono font-semibold",children:["$",i.toFixed(4)," USDC"]})]})]}),l.jsxs("div",{className:"px-5 pb-5 flex gap-2",children:[l.jsx("button",{onClick:a,className:"flex-1 px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-700 text-gray-300 text-sm font-medium transition-colors",children:"Cancel"}),l.jsxs("button",{onClick:n,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white text-sm font-semibold transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(Cc,{size:14}),"Fund Vault"]})]})]})})}function HT({onSubmit:e,isRunning:t,orchestratorName:r,onFundVault:n,onBotClick:a}){const{publicKey:i}=On(),[s,o]=re.useState(""),[c,h]=re.useState(""),[p,y]=re.useState(null),[g,v]=re.useState(!1),M=re.useRef(null);re.useEffect(()=>{if(!i)return;const $=()=>sb(i).then(V=>y((V==null?void 0:V.available)??0)).catch(()=>{});$();const F=setInterval($,1e4);return()=>clearInterval(F)},[i]),re.useEffect(()=>{const $=M.current;$&&($.style.height="auto",$.style.height=`${Math.min($.scrollHeight,180)}px`)},[s]);const k=parseFloat(c)||0,K=k>0,D=!K||p===null||p>=k,T=re.useCallback(()=>{if(!(!s.trim()||t||!K)){if(p!==null&&p{$.key==="Enter"&&($.metaKey||$.ctrlKey)&&($.preventDefault(),T())},L=()=>{v(!1),n==null||n()};return l.jsxs(l.Fragment,{children:[g&&l.jsx(LT,{available:p??0,required:k,orchestratorName:r,onFund:L,onClose:()=>v(!1)}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-gray-800/80",children:[l.jsxs("button",{onClick:a,className:"relative shrink-0 group",title:"View agent details",children:[l.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-purple-600 to-purple-800 rounded-xl flex items-center justify-center shadow-lg shadow-purple-900/40 group-hover:from-purple-500 group-hover:to-purple-700 transition-all",children:l.jsx(jc,{size:14,className:"text-white"})}),l.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full border-2 border-gray-900 ${t?"bg-amber-400 animate-pulse":"bg-emerald-400"}`})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs font-semibold text-white leading-none",children:r}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-0.5",children:t?"Working on it…":"Ready for a task"})]}),p!==null&&l.jsxs("div",{className:`text-right shrink-0 ${D?"":"text-amber-400"}`,children:[l.jsxs("p",{className:"text-xs font-mono font-semibold text-gray-300",children:["$",p.toFixed(2)]}),l.jsx("p",{className:"text-xs text-gray-600",children:"vault"})]})]}),l.jsxs("div",{className:"p-4",children:[l.jsxs("p",{className:"text-xs text-gray-500 mb-2.5",children:["What do you want ",l.jsx("span",{className:"text-purple-400 font-medium",children:r})," to do?"]}),l.jsxs("div",{className:"relative",children:[l.jsx("textarea",{ref:M,value:s,onChange:$=>o($.target.value),onKeyDown:z,disabled:t,placeholder:`Ask ${r} anything…`,rows:2,className:"w-full bg-gray-800/80 border border-gray-700/80 rounded-xl px-3.5 py-3 pr-11 text-sm text-gray-200 placeholder-gray-600 resize-none focus:outline-none focus:border-purple-500/70 focus:bg-gray-800 transition-all disabled:opacity-50"}),l.jsx("button",{onClick:T,disabled:!s.trim()||t||!K,title:K?t?`${r} is working on another task`:"Send (⌘+Enter)":"Enter a budget first",className:"absolute bottom-2.5 right-2.5 w-7 h-7 flex items-center justify-center bg-purple-600 hover:bg-purple-500 disabled:bg-gray-700 disabled:text-gray-600 text-white rounded-lg transition-all shadow-sm",children:l.jsx(sw,{size:12})})]}),!s&&!t&&l.jsx("div",{className:"mt-2.5 space-y-1.5",children:IT.map(($,F)=>l.jsxs("button",{onClick:()=>o($),className:"w-full text-left text-xs text-gray-500 hover:text-gray-300 bg-gray-800/50 hover:bg-gray-800 border border-gray-800 hover:border-gray-700 rounded-lg px-3 py-2 transition-all leading-snug",children:[l.jsx(tv,{size:9,className:"inline mr-1.5 text-purple-500"}),$]},F))}),t&&l.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[l.jsx("div",{className:"flex gap-1",children:[0,150,300].map($=>l.jsx("span",{className:"w-1.5 h-1.5 bg-purple-400 rounded-full animate-bounce",style:{animationDelay:`${$}ms`}},$))}),l.jsxs("span",{className:"text-xs text-gray-500",children:[r," is working…"]})]})]}),l.jsxs("div",{className:"px-4 py-3 border-t border-gray-800/80 space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("label",{className:"text-xs text-gray-500",children:"Budget (USDC)"}),p!==null&&l.jsxs("span",{className:`text-xs font-mono ${D?"text-gray-600":"text-amber-400"}`,children:["vault: $",p.toFixed(2)]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:[.25,.5,1,2].map($=>l.jsxs("button",{onClick:()=>h($.toFixed(2)),disabled:t,className:`text-xs rounded-lg py-1.5 transition-all border font-mono disabled:opacity-40 ${c===$.toFixed(2)?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-400 hover:border-gray-600 hover:text-gray-300"}`,children:["$",$.toFixed(2)]},$))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:c,onChange:$=>h($.target.value),placeholder:"0.00",disabled:t,className:`w-full bg-gray-800/80 border rounded-xl pl-6 pr-14 py-2 text-sm font-mono font-semibold focus:outline-none transition-all disabled:opacity-50 ${!D&&K?"border-amber-700/60 text-amber-400 focus:border-amber-600":!K&&c!==""?"border-red-800/60 text-red-400 focus:border-red-600":"border-gray-700/80 text-purple-300 focus:border-purple-500/70"}`}),l.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-600",children:"USDC"})]}),!D&&K&&p!==null&&l.jsxs("p",{className:"text-xs text-amber-500/80",children:["Exceeds vault balance — deposit $",(k-p).toFixed(4)," more."]})]})]})]})}const L6=[{label:"30s",ms:3e4},{label:"5 min",ms:3e5},{label:"15 min",ms:9e5},{label:"30 min",ms:18e5}],H6=[.25,.5,1,2];function qT(e){const t=Math.max(0,e),r=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3);return r>0?`${r}m ${n}s`:`${n}s`}function $T(e){return e<6e4?`${Math.round(e/1e3)}s`:`${Math.round(e/6e4)} min`}function FT({initial:e,isFirst:t,onSave:r,onCancel:n}){const[a,i]=re.useState(e.task),[s,o]=re.useState(e.budget.toFixed(2)),[c,h]=re.useState(e.delay_ms),[p,y]=re.useState(""),[g,v]=re.useState(""),M=parseFloat(s)||0;return l.jsxs("div",{className:"px-3 py-2.5 space-y-2.5 bg-gray-800/60 border border-purple-800/40 rounded-xl",children:[l.jsx("textarea",{rows:2,value:a,onChange:k=>i(k.target.value),autoFocus:!0,className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-lg px-2.5 py-1.5 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors"}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Budget"}),l.jsx("div",{className:"grid grid-cols-4 gap-1 mb-1",children:H6.map(k=>l.jsxs("button",{onClick:()=>o(k.toFixed(2)),className:`text-xs py-1 rounded-lg border transition-all font-mono ${s===k.toFixed(2)?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:["$",k.toFixed(2)]},k))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:s,onChange:k=>o(k.target.value),placeholder:"0.00",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg pl-5 pr-3 py-1 text-xs font-mono font-semibold text-purple-300 outline-none transition-all"})]})]}),!t&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Wait after previous task"}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:L6.map(k=>l.jsx("button",{onClick:()=>{h(k.ms),y(""),v("")},className:`text-xs py-1 rounded-lg border transition-all font-mono ${c===k.ms&&!p&&!g?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:k.label},k.ms))}),l.jsxs("div",{className:"grid grid-cols-2 gap-1.5 mt-1",children:[l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Seconds",value:p,onChange:k=>{y(k.target.value),v("");const K=parseFloat(k.target.value);!isNaN(K)&&K>0&&h(Math.round(K*1e3))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"s"})]}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Minutes",value:g,onChange:k=>{v(k.target.value),y("");const K=parseFloat(k.target.value);!isNaN(K)&&K>0&&h(Math.round(K*6e4))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"m"})]})]})]}),l.jsxs("div",{className:"flex gap-1.5",children:[l.jsxs("button",{onClick:n,className:"flex items-center gap-1 text-xs px-2.5 py-1.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:[l.jsx(Jh,{size:9})," Cancel"]}),l.jsxs("button",{onClick:()=>{a.trim()&&M>0&&r(a.trim(),M,c)},disabled:!a.trim()||M<=0,className:"flex-1 flex items-center justify-center gap-1 text-xs py-1.5 rounded-lg bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(mr,{size:9})," Save"]})]})]})}function KT({items:e,vaultAvailable:t,onAdd:r,onUpdate:n,onRemove:a,onClearDone:i,onRunQueue:s}){const[o,c]=re.useState(!1),[h,p]=re.useState(!1),[y,g]=re.useState(null),[v,M]=re.useState(""),[k,K]=re.useState(""),[D,T]=re.useState(3e5),[z,L]=re.useState(""),[$,F]=re.useState(""),[,V]=re.useState(0);re.useEffect(()=>{const d=setInterval(()=>V(C=>C+1),1e3);return()=>clearInterval(d)},[]);const J=()=>{const d=parseFloat(k)||0;!v.trim()||d<=0||(r(v.trim(),d,D),M(""),K(""),T(3e5),L(""),F(""),c(!1))},Y=e.some(d=>d.status==="done"||d.status==="failed"),te=e.filter(d=>d.status!=="done"&&d.status!=="failed"),x=e.filter(d=>d.status==="queued"),u=te.reduce((d,C)=>d+C.budget,0),f=t!==null&&u>t,_=[];let E=0;for(const d of e)(d.status==="queued"||d.status==="countdown"||d.status==="running")&&(E+=d.budget),_.push(E);const S=parseFloat(k)||0,j=t!==null?Math.max(0,t-u):null,R=j===null||S<=0||S<=j,N=x.length>0&&!e.some(d=>d.status==="running"||d.status==="countdown");return e.length===0&&!o?l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl px-4 py-3 flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[l.jsx(ha,{size:12}),l.jsx("span",{children:"No tasks queued"})]}),l.jsxs("button",{onClick:()=>c(!0),className:"flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 bg-purple-950/40 hover:bg-purple-950/60 border border-purple-900/60 rounded-lg px-2.5 py-1 transition-all",children:[l.jsx(Fl,{size:11})," Schedule"]})]}):l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(ha,{size:13,className:"text-purple-400"}),l.jsx("span",{className:"text-sm font-semibold text-gray-200 flex-1",children:"Queue"}),te.length>0&&l.jsxs("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded ${f?"text-amber-400 bg-amber-950/40":"text-gray-500 bg-gray-800"}`,children:["$",u.toFixed(2)]}),te.length>0&&l.jsx("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded",children:te.length}),Y&&l.jsx("button",{onClick:i,className:"text-xs text-gray-600 hover:text-gray-400 transition-colors",children:"Clear done"}),l.jsx("button",{onClick:()=>c(d=>!d),className:"text-xs text-purple-400 hover:text-purple-300 transition-colors",children:l.jsx(Fl,{size:11})}),l.jsx("button",{onClick:()=>p(d=>!d),className:"text-gray-600 hover:text-gray-400 transition-colors",children:h?l.jsx(Ds,{size:13}):l.jsx(Mc,{size:13})})]}),f&&!h&&l.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-amber-950/30 border-b border-amber-900/30",children:[l.jsx(Ka,{size:10,className:"text-amber-400 shrink-0"}),l.jsxs("p",{className:"text-xs text-amber-400",children:["Pipeline needs ",l.jsxs("span",{className:"font-mono font-semibold",children:["$",u.toFixed(2)]})," but vault has"," ",l.jsxs("span",{className:"font-mono font-semibold",children:["$",t.toFixed(2)]}),"."]})]}),!h&&l.jsxs(l.Fragment,{children:[e.length>0&&l.jsx("div",{className:"px-3 py-3 space-y-0",children:e.map((d,C)=>{const ae=C===0||e.slice(0,C).every(Q=>Q.status==="done"||Q.status==="failed"),he=d.status==="countdown"&&d.scheduled_run_at,q=he?d.scheduled_run_at-Date.now():0,G=he?Math.max(0,Math.min(100,(1-q/d.delay_ms)*100)):0,W=_[C],be=t!==null&&(d.status==="queued"||d.status==="countdown")&&W>t,ue=y===d.id;return l.jsxs("div",{children:[C>0&&!ae&&l.jsxs("div",{className:"flex items-center gap-2 py-1 pl-3",children:[l.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[l.jsx("div",{className:"w-px h-3 bg-gray-700"}),l.jsx("div",{className:"w-px h-3 bg-gray-700"})]}),l.jsxs("span",{className:"text-xs text-gray-700 font-mono",children:["+",$T(d.delay_ms)]})]}),ue?l.jsx(FT,{initial:d,isFirst:ae,onSave:(Q,le,Se)=>{n(d.id,Q,le,Se),g(null)},onCancel:()=>g(null)}):l.jsxs("div",{className:`flex items-start gap-2 rounded-xl p-2.5 transition-colors ${d.status==="running"?"bg-amber-950/30 border border-amber-900/40":d.status==="countdown"?"bg-purple-950/30 border border-purple-900/40":d.status==="done"?"bg-gray-800/30 border border-gray-800/60":d.status==="failed"?"bg-red-950/20 border border-red-900/30":be?"bg-amber-950/15 border border-amber-900/30":"bg-gray-800/40 border border-gray-800/60"}`,children:[l.jsxs("div",{className:"mt-0.5 shrink-0",children:[d.status==="running"&&l.jsx(ya,{size:12,className:"text-amber-400 animate-pulse"}),d.status==="countdown"&&l.jsx(ha,{size:12,className:"text-purple-400"}),d.status==="queued"&&(be?l.jsx(Ka,{size:12,className:"text-amber-500"}):l.jsx("div",{className:"w-3 h-3 rounded-full border-2 border-gray-600"})),d.status==="done"&&l.jsx(mr,{size:12,className:"text-emerald-500"}),d.status==="failed"&&l.jsx(En,{size:12,className:"text-red-500"})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:`text-xs truncate leading-relaxed ${d.status==="done"||d.status==="failed"?"text-gray-600":"text-gray-300"}`,children:d.task}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsxs("span",{className:`text-xs font-mono ${be?"text-amber-600":"text-gray-600"}`,children:["$",d.budget.toFixed(2)]}),ae&&d.status==="queued"&&l.jsx("span",{className:"text-xs text-purple-500 italic",children:"starts first"}),be&&l.jsx("span",{className:"text-xs text-amber-600 italic",children:"may be short"}),he&&q>0&&l.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[l.jsx("div",{className:"flex-1 h-0.5 bg-gray-700 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-purple-500 rounded-full transition-all duration-1000",style:{width:`${G}%`}})}),l.jsx("span",{className:"text-xs font-mono text-purple-400 tabular-nums shrink-0",children:qT(q)})]}),he&&q<=0&&l.jsx("span",{className:"text-xs text-purple-400 italic",children:"starting…"}),d.status==="running"&&l.jsx("span",{className:"text-xs text-amber-400",children:"running now"})]}),d.status==="failed"&&d.failReason&&l.jsx("p",{className:"text-xs text-red-500 mt-1 leading-snug",children:d.failReason})]}),d.status==="queued"&&l.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[l.jsx("button",{onClick:()=>g(d.id),className:"p-1 text-gray-700 hover:text-gray-300 transition-colors",title:"Edit",children:l.jsx(Vf,{size:10})}),l.jsx("button",{onClick:()=>a(d.id),className:"p-1 text-gray-700 hover:text-red-400 transition-colors",children:l.jsx(xa,{size:11})})]})]})]},d.id)})}),N&&l.jsx("div",{className:"px-3 pb-3",children:l.jsxs("button",{onClick:s,className:"w-full flex items-center justify-center gap-2 text-xs font-semibold py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(aw,{size:11}),"Review & Run Queue (",x.length," task",x.length!==1?"s":"",")"]})}),o&&l.jsxs("div",{className:"px-4 pb-4 pt-1 border-t border-gray-800 space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between pt-2",children:[l.jsx("p",{className:"text-xs text-gray-500",children:"Add to queue"}),t!==null&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-mono",children:[l.jsxs("span",{className:"text-gray-600",children:["vault $",t.toFixed(2)]}),u>0&&l.jsxs("span",{className:j!==null&&S>0&&S>j?"text-amber-400":"text-gray-500",children:["· rem $",(j??0).toFixed(2)]})]})]}),l.jsx("textarea",{rows:2,value:v,onChange:d=>M(d.target.value),placeholder:"What should the agent do next?",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-xl px-3 py-2 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors"}),te.length>0&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5",children:"Wait after previous task"}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:L6.map(d=>l.jsx("button",{onClick:()=>{T(d.ms),L(""),F("")},className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${D===d.ms&&!z&&!$?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:d.label},d.ms))}),l.jsxs("div",{className:"grid grid-cols-2 gap-1.5 mt-1.5",children:[l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Seconds",value:z,onChange:d=>{L(d.target.value),F("");const C=parseFloat(d.target.value);!isNaN(C)&&C>0&&T(Math.round(C*1e3))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1.5 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"s"})]}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Minutes",value:$,onChange:d=>{F(d.target.value),L("");const C=parseFloat(d.target.value);!isNaN(C)&&C>0&&T(Math.round(C*6e4))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1.5 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"m"})]})]})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Budget"}),!R&&t!==null&&l.jsxs("span",{className:"text-xs text-amber-500 flex items-center gap-1",children:[l.jsx(Ka,{size:9}),"exceeds remaining $",(j??0).toFixed(2)]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:H6.map(d=>{const C=j===null||d<=j;return l.jsxs("button",{onClick:()=>K(d.toFixed(2)),className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${k===d.toFixed(2)?C?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-amber-900/30 border-amber-700/60 text-amber-300":C?"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300":"bg-gray-800 border-amber-900/40 text-amber-700 hover:text-amber-500"}`,children:["$",d.toFixed(2)]},d)})}),l.jsxs("div",{className:"relative mt-1.5",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:k,onChange:d=>K(d.target.value),placeholder:"0.00",className:`w-full bg-gray-800 border rounded-lg pl-5 pr-3 py-1.5 text-xs font-mono font-semibold focus:outline-none transition-all ${!R&&S>0?"border-amber-700/60 text-amber-400 focus:border-amber-600":"border-gray-700 text-purple-300 focus:border-purple-500/50"}`})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>c(!1),className:"flex-1 text-xs py-2 rounded-xl bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:"Cancel"}),l.jsxs("button",{onClick:J,disabled:!v.trim()||S<=0,className:"flex-1 flex items-center justify-center gap-1.5 text-xs py-2 rounded-xl bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(Fl,{size:11}),!R&&S>0?"Add Anyway":"Add to Queue"]})]})]})]})]})}const PT={task_accepted:{icon:l.jsx(ya,{size:11}),color:"text-purple-400",bg:"bg-purple-950/60 border-purple-900/60"},agents_loaded:{icon:l.jsx(Uu,{size:11}),color:"text-blue-400",bg:"bg-blue-950/60 border-blue-900/60"},agents_scored:{icon:l.jsx(rv,{size:11}),color:"text-violet-400",bg:"bg-violet-950/60 border-violet-900/60"},feasibility_checked:{icon:l.jsx(Xh,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},plan_created:{icon:l.jsx(Xh,{size:11}),color:"text-blue-400",bg:"bg-blue-950/60 border-blue-900/60"},plan_validated:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},plan_approval_required:{icon:l.jsx(ha,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},plan_approved:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},plan_rejected:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},plan_auto_approved:{icon:l.jsx(mr,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},budget_locked:{icon:l.jsx(wn,{size:11}),color:"text-purple-400",bg:"bg-purple-950/60 border-purple-900/60"},budget_released:{icon:l.jsx(wn,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},budget_approved:{icon:l.jsx(wn,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},budget_denied:{icon:l.jsx(wn,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},budget_finalized:{icon:l.jsx(wn,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},task_started:{icon:l.jsx(ya,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},step_started:{icon:l.jsx(ha,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},step_complete:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},step_failed:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},task_complete:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},task_result:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},task_error:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},task_infeasible:{icon:l.jsx(En,{size:11}),color:"text-orange-400",bg:"bg-orange-950/60 border-orange-900/60"}};function GT(e,t){return{task_accepted:"Task Accepted",agents_loaded:"Agents Loaded",agents_scored:"Agents Scored",feasibility_checked:"Feasibility Checked",plan_created:`${t} Created Plan`,plan_validated:"Plan Validated",plan_approval_required:"Plan Approval Required",plan_approved:"Plan Approved",plan_rejected:"Plan Rejected",plan_auto_approved:"Auto-Approved",budget_locked:"Budget Locked",budget_released:"Budget Released",budget_approved:"Budget Approved",budget_denied:"Budget Denied",budget_finalized:"Budget Finalized",task_started:`${t} Started`,step_started:"Step Started",step_complete:"Step Complete",step_failed:"Step Failed",task_complete:"Task Complete",task_result:"Task Result",task_error:"Task Error",task_infeasible:"Task Infeasible"}[e]??e.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function YT(e,t,r){var n,a,i,s,o,c,h,p,y,g,v,M,k,K,D,T,z;if(!t)return{text:""};switch(e){case"agents_loaded":return{text:`${t.count??0} agents available`};case"agents_scored":return{text:`${((n=t.agents)==null?void 0:n.length)??0} scored · top: ${((i=(a=t.agents)==null?void 0:a[0])==null?void 0:i.name)??"?"} (${((o=(s=t.agents)==null?void 0:s[0])==null?void 0:o.score)??0})`};case"feasibility_checked":return{text:`${t.feasible?"Feasible":"Infeasible"} · [${(c=t.needed)==null?void 0:c.slice(0,3).join(", ")}${(((h=t.needed)==null?void 0:h.length)??0)>3?"…":""}]`};case"plan_created":{const L=(t.step_selections??[]).filter($=>{var F;return((F=$.alternatives)==null?void 0:F.length)>0}).slice(0,1).map($=>`${$.agent_name} (${Math.round($.selected_score*100)}) over ${$.alternatives[0].name} (${Math.round($.alternatives[0].score*100)})`);return{text:`${t.steps} steps · $${(p=t.total_estimated_cost)==null?void 0:p.toFixed(3)}${L.length?" · "+L[0]:""}`}}case"plan_approval_required":return{text:`${((y=t.steps)==null?void 0:y.length)??0} steps · $${(g=t.total_estimated_cost)==null?void 0:g.toFixed(3)} — awaiting approval`};case"plan_approved":return{text:`${r} is executing`};case"plan_auto_approved":return{text:"Approved automatically — within budget"};case"plan_rejected":return{text:"Plan was rejected"};case"budget_locked":return{text:`task #${t.contract_task_id} · $${(v=t.budget_usdc)==null?void 0:v.toFixed(2)} locked on-chain`};case"budget_released":return{text:`${t.agent_name} · $${(M=t.amount)==null?void 0:M.toFixed(4)} released`,txHash:t.tx_hash};case"budget_approved":return{text:`${t.agent_name} · $${(k=t.amount)==null?void 0:k.toFixed(3)} approved`};case"budget_denied":return{text:`${t.agent_name} · $${(K=t.amount)==null?void 0:K.toFixed(3)} denied — over budget`};case"budget_finalized":return{text:`task #${t.contract_task_id} · $${(D=t.total_spent)==null?void 0:D.toFixed(4)} spent`};case"task_started":return{text:`${t.step_count??0} steps planned`};case"step_started":return{text:`${t.agent_name}: ${(t.action??"").slice(0,80)}`};case"step_complete":{const L=t.latency_ms?` · ${t.latency_ms}ms`:"";return{text:`${t.agent_name}${L}`,txHash:t.tx_hash}}case"step_failed":return{text:`${t.agent_name}: ${(t.error??"").slice(0,80)}`};case"task_complete":return{text:`${t.status} · $${(T=t.total_cost)==null?void 0:T.toFixed(4)} · ${(t.total_time_ms/1e3).toFixed(1)}s`};case"task_result":return{text:`${t.status} · $${(z=t.total_cost)==null?void 0:z.toFixed(4)} · ${(t.total_time_ms/1e3).toFixed(1)}s`};case"task_error":return{text:(t.error??"").slice(0,100)};default:return{text:JSON.stringify(t).slice(0,80)}}}function VT({events:e,connected:t,onClear:r,orchestratorName:n="Agent"}){const a=re.useRef(null);return re.useEffect(()=>{var i;(i=a.current)==null||i.scrollIntoView({behavior:"smooth"})},[e.length]),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl flex flex-col h-full overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800 shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(Uu,{size:14,className:"text-gray-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Activity Feed"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${t?"bg-emerald-400":"bg-red-500 animate-pulse"}`}),l.jsx("span",{className:"text-xs text-gray-600",children:t?"live":"reconnecting…"})]})]}),e.length>0&&l.jsx("button",{onClick:r,className:"text-xs text-gray-600 hover:text-gray-400 transition-colors px-2 py-1 rounded-lg hover:bg-gray-800",children:"Clear"})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0 px-3 py-3 space-y-1",children:[e.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3 py-12",children:[l.jsx("div",{className:"w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center",children:l.jsx(Uu,{size:18,className:"text-gray-600"})}),l.jsxs("p",{className:"text-xs text-gray-600 text-center",children:["Submit a task to see ",n," in action"]})]}):[...e].reverse().map((i,s)=>{const o=PT[i.event]??{icon:l.jsx(Uu,{size:11}),color:"text-gray-500",bg:"bg-gray-800/60 border-gray-700/60"},c=GT(i.event,n),{text:h,txHash:p}=YT(i.event,i.data,n),y=new Date(i.timestamp).toLocaleTimeString("en",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"});return l.jsxs("div",{className:`flex items-start gap-2.5 px-2.5 py-2 rounded-xl border ${o.bg} transition-all`,children:[l.jsx("span",{className:`mt-0.5 shrink-0 ${o.color}`,children:o.icon}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("span",{className:`text-xs font-semibold ${o.color}`,children:c}),l.jsx("span",{className:"text-xs text-gray-700 font-mono shrink-0 tabular-nums",children:y})]}),(h||p)&&l.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[h&&l.jsx("p",{className:"text-xs text-gray-500 truncate leading-relaxed",children:h}),p&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${p}`,target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-gray-600 hover:text-blue-400 transition-colors",title:"View transaction",children:l.jsx(Xr,{size:9})})]})]})]},s)}),l.jsx("div",{ref:a})]})]})}function XT(e){return e.replace(/^### (.+)$/gm,'

$1

').replace(/^## (.+)$/gm,'

$1

').replace(/^# (.+)$/gm,'

$1

').replace(/\*\*(.+?)\*\*/g,'$1').replace(/\*(.+?)\*/g,'$1').replace(/`([^`]+)`/g,'$1').replace(/^---$/gm,'
').replace(/^\| (.+)$/gm,t=>t.includes("|---")?"":`${t.split("|").filter(Boolean).map(n=>n.trim()).map(n=>`${n}`).join("")}`).replace(/^- (.+)$/gm,'
  • $1
  • ').replace(/^\d+\. (.+)$/gm,'
  • $1
  • ').replace(/\n\n/g,` + */var HE=qE;function qE(e){if(!e)throw new TypeError("argument namespace is required");function t(r){}return t._file=void 0,t._ignored=!0,t._namespace=e,t._traced=!1,t._warned=Object.create(null),t.function=$E,t.property=FE,t}function $E(e,t){if(typeof e!="function")throw new TypeError("argument fn must be a function");return e}function FE(e,t,r){if(!e||typeof e!="object"&&typeof e!="function")throw new TypeError("argument obj must be object");var n=Object.getOwnPropertyDescriptor(e,t);if(!n)throw new TypeError("must call property on owner object");if(!n.configurable)throw new TypeError("property must be configurable")}var Lc={};Object.defineProperty(Lc,"__esModule",{value:!0});Lc.sortBigIntAsc=void 0;function KE(e,t){return et?1:0}Lc.sortBigIntAsc=KE;var PE=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ko,"__esModule",{value:!0});ko.diffEpochValidators=ko.findSeatPrice=void 0;const GE=PE(HE),d3=Lc;function YE(e,t,r,n){return n&&n<49?VE(e,t):(r||((0,GE.default)("findSeatPrice(validators, maxNumberOfSeats)")("`use `findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio)` instead"),r=[1,6250]),XE(e,t,r))}ko.findSeatPrice=YE;function VE(e,t){const r=e.map(o=>BigInt(o.stake)).sort(d3.sortBigIntAsc),n=BigInt(t),a=r.reduce((o,c)=>o+c);if(a=n){i=o,c=!0;break}c||(s=o)}return i}function XE(e,t,r){if(r.length!=2)throw Error("minimumStakeRatio should have 2 elements");const n=e.map(i=>BigInt(i.stake)).sort(d3.sortBigIntAsc),a=n.reduce((i,s)=>i+s);return e.lengthr.set(a.account_id,a));const n=new Set(t.map(a=>a.account_id));return{newValidators:t.filter(a=>!r.has(a.account_id)),removedValidators:e.filter(a=>!n.has(a.account_id)),changedValidators:t.filter(a=>r.has(a.account_id)&&r.get(a.account_id).stake!=a.stake).map(a=>({current:r.get(a.account_id),next:a}))}}ko.diffEpochValidators=ZE;(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(n,a,i,s){s===void 0&&(s=i);var o=Object.getOwnPropertyDescriptor(a,i);(!o||("get"in o?!a.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(n,s,o)}:function(n,a,i,s){s===void 0&&(s=i),n[s]=a[i]}),r=Ie&&Ie.__exportStar||function(n,a){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(a,i)&&t(a,n,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(nd,e),r(I1,e),r(L1,e),r(Uo,e),r(ld,e),r(ko,e),r(q1,e),r(Lc,e)})(Wo);var $1={},Er={},Is={},Xi={};Object.defineProperty(Xi,"__esModule",{value:!0});Xi.anumber=sp;Xi.abytes=h3;Xi.ahash=JE;Xi.aexists=WE;Xi.aoutput=eA;function sp(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function QE(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function h3(e,...t){if(!QE(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function JE(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");sp(e.outputLen),sp(e.blockLen)}function WE(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 eA(e,t){h3(e);const r=t.outputLen;if(e.length>>u}function c(x,u){return x<>>32-u>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function d(x){return x<<24&4278190080|x<<8&16711680|x>>>8&65280|x>>>24&255}e.byteSwapIfBE=e.isLE?x=>x:x=>d(x);function p(x){for(let u=0;uu.toString(16).padStart(2,"0"));function g(x){(0,r.abytes)(x);let u="";for(let f=0;f=v._0&&x<=v._9)return x-v._0;if(x>=v.A&&x<=v.F)return x-(v.A-10);if(x>=v.a&&x<=v.f)return x-(v.a-10)}function z(x){if(typeof x!="string")throw new Error("hex string expected, got "+typeof x);const u=x.length,f=u/2;if(u%2)throw new Error("hex string expected, got unpadded hex of length "+u);const _=new Uint8Array(f);for(let E=0,S=0;E{};e.nextTick=K;async function D(x,u,f){let _=Date.now();for(let E=0;E=0&&Sx().update(k(_)).digest(),f=x();return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=()=>x(),u}function J(x){const u=(_,E)=>x(E).update(k(_)).digest(),f=x({});return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=_=>x(_),u}function Y(x){const u=(_,E)=>x(E).update(k(_)).digest(),f=x({});return u.outputLen=f.outputLen,u.blockLen=f.blockLen,u.create=_=>x(_),u}function ee(x=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(x));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(x);throw new Error("crypto.getRandomValues must be defined")}})(cd);Object.defineProperty(Is,"__esModule",{value:!0});Is.HashMD=void 0;Is.setBigUint64=p3;Is.Chi=tA;Is.Maj=rA;const T0=Xi,yl=cd;function p3(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const a=BigInt(32),i=BigInt(4294967295),s=Number(r>>a&i),o=Number(r&i),c=n?4:0,d=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+d,o,n)}function tA(e,t,r){return e&t^~e&r}function rA(e,t,r){return e&t^e&r^t&r}class nA extends yl.Hash{constructor(t,r,n,a){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=a,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,yl.createView)(this.buffer)}update(t){(0,T0.aexists)(this);const{view:r,buffer:n,blockLen:a}=this;t=(0,yl.toBytes)(t);const i=t.length;for(let s=0;sa-s&&(this.process(n,0),s=0);for(let y=s;yp.length)throw new Error("_sha2: outputLen bigger than state");for(let y=0;y>op&du)}:{h:Number(e>>op&du)|0,l:Number(e&du)|0}}function b3(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let a=0;aBigInt(e>>>0)<>>0);We.toBig=m3;const x3=(e,t,r)=>e>>>r;We.shrSH=x3;const y3=(e,t,r)=>e<<32-r|t>>>r;We.shrSL=y3;const g3=(e,t,r)=>e>>>r|t<<32-r;We.rotrSH=g3;const v3=(e,t,r)=>e<<32-r|t>>>r;We.rotrSL=v3;const w3=(e,t,r)=>e<<64-r|t>>>r-32;We.rotrBH=w3;const _3=(e,t,r)=>e>>>r-32|t<<64-r;We.rotrBL=_3;const S3=(e,t)=>t;We.rotr32H=S3;const E3=(e,t)=>e;We.rotr32L=E3;const A3=(e,t,r)=>e<>>32-r;We.rotlSH=A3;const N3=(e,t,r)=>t<>>32-r;We.rotlSL=N3;const j3=(e,t,r)=>t<>>64-r;We.rotlBH=j3;const T3=(e,t,r)=>e<>>64-r;We.rotlBL=T3;function M3(e,t,r,n){const a=(t>>>0)+(n>>>0);return{h:e+r+(a/2**32|0)|0,l:a|0}}const C3=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0);We.add3L=C3;const B3=(e,t,r,n)=>t+r+n+(e/2**32|0)|0;We.add3H=B3;const O3=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0);We.add4L=O3;const R3=(e,t,r,n,a)=>t+r+n+a+(e/2**32|0)|0;We.add4H=R3;const U3=(e,t,r,n,a)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(a>>>0);We.add5L=U3;const k3=(e,t,r,n,a,i)=>t+r+n+a+i+(e/2**32|0)|0;We.add5H=k3;const aA={fromBig:F1,split:b3,toBig:m3,shrSH:x3,shrSL:y3,rotrSH:g3,rotrSL:v3,rotrBH:w3,rotrBL:_3,rotr32H:S3,rotr32L:E3,rotlSH:A3,rotlSL:N3,rotlBH:j3,rotlBL:T3,add:M3,add3L:C3,add3H:B3,add4L:O3,add4H:R3,add5H:k3,add5L:U3};We.default=aA;Object.defineProperty(Er,"__esModule",{value:!0});Er.sha384=Er.sha512_256=Er.sha512_224=Er.sha512=Er.SHA384=Er.SHA512_256=Er.SHA512_224=Er.SHA512=void 0;const iA=Is,lt=We,fd=cd,[sA,oA]=lt.default.split(["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))),ai=new Uint32Array(80),ii=new Uint32Array(80);let Hc=class extends iA.HashMD{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:r,Bh:n,Bl:a,Ch:i,Cl:s,Dh:o,Dl:c,Eh:d,El:p,Fh:y,Fl:g,Gh:v,Gl:M,Hh:z,Hl:K}=this;return[t,r,n,a,i,s,o,c,d,p,y,g,v,M,z,K]}set(t,r,n,a,i,s,o,c,d,p,y,g,v,M,z,K){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=a|0,this.Ch=i|0,this.Cl=s|0,this.Dh=o|0,this.Dl=c|0,this.Eh=d|0,this.El=p|0,this.Fh=y|0,this.Fl=g|0,this.Gh=v|0,this.Gl=M|0,this.Hh=z|0,this.Hl=K|0}process(t,r){for(let k=0;k<16;k++,r+=4)ai[k]=t.getUint32(r),ii[k]=t.getUint32(r+=4);for(let k=16;k<80;k++){const L=ai[k-15]|0,$=ii[k-15]|0,F=lt.default.rotrSH(L,$,1)^lt.default.rotrSH(L,$,8)^lt.default.shrSH(L,$,7),V=lt.default.rotrSL(L,$,1)^lt.default.rotrSL(L,$,8)^lt.default.shrSL(L,$,7),J=ai[k-2]|0,Y=ii[k-2]|0,ee=lt.default.rotrSH(J,Y,19)^lt.default.rotrBH(J,Y,61)^lt.default.shrSH(J,Y,6),x=lt.default.rotrSL(J,Y,19)^lt.default.rotrBL(J,Y,61)^lt.default.shrSL(J,Y,6),u=lt.default.add4L(V,x,ii[k-7],ii[k-16]),f=lt.default.add4H(u,F,ee,ai[k-7],ai[k-16]);ai[k]=f|0,ii[k]=u|0}let{Ah:n,Al:a,Bh:i,Bl:s,Ch:o,Cl:c,Dh:d,Dl:p,Eh:y,El:g,Fh:v,Fl:M,Gh:z,Gl:K,Hh:D,Hl:T}=this;for(let k=0;k<80;k++){const L=lt.default.rotrSH(y,g,14)^lt.default.rotrSH(y,g,18)^lt.default.rotrBH(y,g,41),$=lt.default.rotrSL(y,g,14)^lt.default.rotrSL(y,g,18)^lt.default.rotrBL(y,g,41),F=y&v^~y&z,V=g&M^~g&K,J=lt.default.add5L(T,$,V,oA[k],ii[k]),Y=lt.default.add5H(J,D,L,F,sA[k],ai[k]),ee=J|0,x=lt.default.rotrSH(n,a,28)^lt.default.rotrBH(n,a,34)^lt.default.rotrBH(n,a,39),u=lt.default.rotrSL(n,a,28)^lt.default.rotrBL(n,a,34)^lt.default.rotrBL(n,a,39),f=n&i^n&o^i&o,_=a&s^a&c^s&c;D=z|0,T=K|0,z=v|0,K=M|0,v=y|0,M=g|0,{h:y,l:g}=lt.default.add(d|0,p|0,Y|0,ee|0),d=o|0,p=c|0,o=i|0,c=s|0,i=n|0,s=a|0;const E=lt.default.add3L(ee,u,_);n=lt.default.add3H(E,Y,x,f),a=E|0}({h:n,l:a}=lt.default.add(this.Ah|0,this.Al|0,n|0,a|0)),{h:i,l:s}=lt.default.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:o,l:c}=lt.default.add(this.Ch|0,this.Cl|0,o|0,c|0),{h:d,l:p}=lt.default.add(this.Dh|0,this.Dl|0,d|0,p|0),{h:y,l:g}=lt.default.add(this.Eh|0,this.El|0,y|0,g|0),{h:v,l:M}=lt.default.add(this.Fh|0,this.Fl|0,v|0,M|0),{h:z,l:K}=lt.default.add(this.Gh|0,this.Gl|0,z|0,K|0),{h:D,l:T}=lt.default.add(this.Hh|0,this.Hl|0,D|0,T|0),this.set(n,a,i,s,o,c,d,p,y,g,v,M,z,K,D,T)}roundClean(){ai.fill(0),ii.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Er.SHA512=Hc;class z3 extends Hc{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}Er.SHA512_224=z3;class D3 extends Hc{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}Er.SHA512_256=D3;let I3=class extends Hc{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}};Er.SHA384=I3;Er.sha512=(0,fd.wrapConstructor)(()=>new Hc);Er.sha512_224=(0,fd.wrapConstructor)(()=>new z3);Er.sha512_256=(0,fd.wrapConstructor)(()=>new D3);Er.sha384=(0,fd.wrapConstructor)(()=>new I3);var Ls={},It={},xt={};/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(xt,"__esModule",{value:!0});xt.notImplemented=xt.bitMask=void 0;xt.isBytes=pd;xt.abytes=bd;xt.abool=cA;xt.bytesToHex=K1;xt.numberToHexUnpadded=L3;xt.hexToNumber=P1;xt.hexToBytes=md;xt.bytesToNumberBE=fA;xt.bytesToNumberLE=dA;xt.numberToBytesBE=H3;xt.numberToBytesLE=hA;xt.numberToVarBytesBE=pA;xt.ensureBytes=bA;xt.concatBytes=q3;xt.equalBytes=mA;xt.utf8ToBytes=xA;xt.inRange=$3;xt.aInRange=yA;xt.bitLen=gA;xt.bitGet=vA;xt.bitSet=wA;xt.createHmacDrbg=SA;xt.validateObject=AA;xt.memoized=jA;const dd=BigInt(0),hd=BigInt(1),lA=BigInt(2);function pd(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function bd(e){if(!pd(e))throw new Error("Uint8Array expected")}function cA(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}const uA=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function K1(e){bd(e);let t="";for(let r=0;r=Ra._0&&e<=Ra._9)return e-Ra._0;if(e>=Ra.A&&e<=Ra.F)return e-(Ra.A-10);if(e>=Ra.a&&e<=Ra.f)return e-(Ra.a-10)}function md(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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 a=0,i=0;atypeof e=="bigint"&&dd<=e;function $3(e,t,r){return M0(e)&&M0(t)&&M0(r)&&t<=e&&edd;e>>=hd,t+=1);return t}function vA(e,t){return e>>BigInt(t)&hd}function wA(e,t,r){return e|(r?hd:dd)<(lA<new Uint8Array(e),px=e=>Uint8Array.from(e);function SA(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=C0(e),a=C0(e),i=0;const s=()=>{n.fill(1),a.fill(0),i=0},o=(...y)=>r(a,n,...y),c=(y=C0())=>{a=o(px([0]),y),n=o(),y.length!==0&&(a=o(px([1]),y),n=o())},d=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let y=0;const g=[];for(;y{s(),c(y);let v;for(;!(v=g(d()));)c();return s(),v}}const EA={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||pd(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function AA(e,t,r={}){const n=(a,i,s)=>{const o=EA[i];if(typeof o!="function")throw new Error("invalid validator function");const c=e[a];if(!(s&&c===void 0)&&!o(c,e))throw new Error("param "+String(a)+" is invalid. Expected "+i+", got "+c)};for(const[a,i]of Object.entries(t))n(a,i,!1);for(const[a,i]of Object.entries(r))n(a,i,!0);return e}const NA=()=>{throw new Error("not implemented")};xt.notImplemented=NA;function jA(e){const t=new WeakMap;return(r,...n)=>{const a=t.get(r);if(a!==void 0)return a;const i=e(r,...n);return t.set(r,i),i}}Object.defineProperty(It,"__esModule",{value:!0});It.isNegativeLE=void 0;It.mod=gn;It.pow=F3;It.pow2=MA;It.invert=Sf;It.tonelliShanks=K3;It.FpSqrt=P3;It.validateField=OA;It.FpPow=G3;It.FpInvertBatch=Y3;It.FpDiv=RA;It.FpLegendre=V3;It.FpIsSquare=UA;It.nLength=G1;It.Field=kA;It.FpSqrtOdd=zA;It.FpSqrtEven=DA;It.hashToPrivateScalar=IA;It.getFieldBytesLength=Y1;It.getMinHashLength=X3;It.mapHashToField=LA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _n=xt,jr=BigInt(0),Ft=BigInt(1),xi=BigInt(2),TA=BigInt(3),lp=BigInt(4),bx=BigInt(5),mx=BigInt(8);function gn(e,t){const r=e%t;return r>=jr?r:t+r}function F3(e,t,r){if(tjr;)t&Ft&&(n=n*e%r),e=e*e%r,t>>=Ft;return n}function MA(e,t,r){let n=e;for(;t-- >jr;)n*=n,n%=r;return n}function Sf(e,t){if(e===jr)throw new Error("invert: expected non-zero number");if(t<=jr)throw new Error("invert: expected positive modulus, got "+t);let r=gn(e,t),n=t,a=jr,i=Ft;for(;r!==jr;){const o=n/r,c=n%r,d=a-i*o;n=r,r=c,a=i,i=d}if(n!==Ft)throw new Error("invert: does not exist");return gn(a,t)}function K3(e){const t=(e-Ft)/xi;let r,n,a;for(r=e-Ft,n=0;r%xi===jr;r/=xi,n++);for(a=xi;a1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const s=(e+Ft)/lp;return function(c,d){const p=c.pow(d,s);if(!c.eql(c.sqr(p),d))throw new Error("Cannot find square root");return p}}const i=(r+Ft)/xi;return function(o,c){if(o.pow(c,t)===o.neg(o.ONE))throw new Error("Cannot find square root");let d=n,p=o.pow(o.mul(o.ONE,a),r),y=o.pow(c,i),g=o.pow(c,r);for(;!o.eql(g,o.ONE);){if(o.eql(g,o.ZERO))return o.ZERO;let v=1;for(let z=o.sqr(g);v(gn(e,t)&Ft)===Ft;It.isNegativeLE=CA;const BA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function OA(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=BA.reduce((n,a)=>(n[a]="function",n),t);return(0,_n.validateObject)(e,r)}function G3(e,t,r){if(rjr;)r&Ft&&(n=e.mul(n,a)),a=e.sqr(a),r>>=Ft;return n}function Y3(e,t){const r=new Array(t.length),n=t.reduce((i,s,o)=>e.is0(s)?i:(r[o]=i,e.mul(i,s)),e.ONE),a=e.inv(n);return t.reduceRight((i,s,o)=>e.is0(s)?i:(r[o]=e.mul(i,r[o]),e.mul(i,s)),a),r}function RA(e,t,r){return e.mul(t,typeof r=="bigint"?Sf(r,e.ORDER):e.inv(r))}function V3(e){const t=(e-Ft)/xi;return(r,n)=>r.pow(n,t)}function UA(e){const t=V3(e.ORDER);return r=>{const n=t(e,r);return e.eql(n,e.ZERO)||e.eql(n,e.ONE)}}function G1(e,t){const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function kA(e,t,r=!1,n={}){if(e<=jr)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:a,nByteLength:i}=G1(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s;const o=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:i,MASK:(0,_n.bitMask)(a),ZERO:jr,ONE:Ft,create:c=>gn(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return jr<=c&&cc===jr,isOdd:c=>(c&Ft)===Ft,neg:c=>gn(-c,e),eql:(c,d)=>c===d,sqr:c=>gn(c*c,e),add:(c,d)=>gn(c+d,e),sub:(c,d)=>gn(c-d,e),mul:(c,d)=>gn(c*d,e),pow:(c,d)=>G3(o,c,d),div:(c,d)=>gn(c*Sf(d,e),e),sqrN:c=>c*c,addN:(c,d)=>c+d,subN:(c,d)=>c-d,mulN:(c,d)=>c*d,inv:c=>Sf(c,e),sqrt:n.sqrt||(c=>(s||(s=P3(e)),s(o,c))),invertBatch:c=>Y3(o,c),cmov:(c,d,p)=>p?d:c,toBytes:c=>r?(0,_n.numberToBytesLE)(c,i):(0,_n.numberToBytesBE)(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?(0,_n.bytesToNumberLE)(c):(0,_n.bytesToNumberBE)(c)}});return Object.freeze(o)}function zA(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?r:e.neg(r)}function DA(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);return e.isOdd(r)?e.neg(r):r}function IA(e,t,r=!1){e=(0,_n.ensureBytes)("privateHash",e);const n=e.length,a=G1(t).nByteLength+8;if(a<24||n1024)throw new Error("hashToPrivateScalar: expected "+a+"-1024 bytes of input, got "+n);const i=r?(0,_n.bytesToNumberLE)(e):(0,_n.bytesToNumberBE)(e);return gn(i,t-Ft)+Ft}function Y1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function X3(e){const t=Y1(e);return t+Math.ceil(t/2)}function LA(e,t,r=!1){const n=e.length,a=Y1(t),i=X3(t);if(n<16||n1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);const s=r?(0,_n.bytesToNumberLE)(e):(0,_n.bytesToNumberBE)(e),o=gn(s,t-Ft)+Ft;return r?(0,_n.numberToBytesLE)(o,a):(0,_n.numberToBytesBE)(o,a)}Object.defineProperty(Ls,"__esModule",{value:!0});Ls.wNAF=HA;Ls.pippenger=qA;Ls.precomputeMSMUnsafe=$A;Ls.validateBasic=FA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const xx=It,Z3=xt,yx=BigInt(0),hu=BigInt(1);function B0(e,t){const r=t.negate();return e?r:t}function V1(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function O0(e,t){V1(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Q3(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function J3(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}const R0=new WeakMap,W3=new WeakMap;function U0(e){return W3.get(e)||1}function HA(e,t){return{constTimeNegate:B0,hasPrecomputes(r){return U0(r)!==1},unsafeLadder(r,n,a=e.ZERO){let i=r;for(;n>yx;)n&hu&&(a=a.add(i)),i=i.double(),n>>=hu;return a},precomputeWindow(r,n){const{windows:a,windowSize:i}=O0(n,t),s=[];let o=r,c=o;for(let d=0;d>=y,M>s&&(M-=p,a+=hu);const z=v,K=v+Math.abs(M)-1,D=g%2!==0,T=M<0;M===0?c=c.add(B0(D,n[z])):o=o.add(B0(T,n[K]))}return{p:o,f:c}},wNAFUnsafe(r,n,a,i=e.ZERO){const{windows:s,windowSize:o}=O0(r,t),c=BigInt(2**r-1),d=2**r,p=BigInt(r);for(let y=0;y>=p,v>o&&(v-=d,a+=hu),v===0)continue;let M=n[g+Math.abs(v)-1];v<0&&(M=M.negate()),i=i.add(M)}return i},getPrecomputes(r,n,a){let i=R0.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&R0.set(n,a(i))),i},wNAFCached(r,n,a){const i=U0(r);return this.wNAF(i,this.getPrecomputes(i,r,a),n)},wNAFCachedUnsafe(r,n,a,i){const s=U0(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,a),n,i)},setWindowSize(r,n){V1(n,t),W3.set(r,n),R0.delete(r)}}}function qA(e,t,r,n){if(Q3(r,e),J3(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const a=e.ZERO,i=(0,Z3.bitLen)(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,o=(1<=0;y-=s){c.fill(a);for(let v=0;v>BigInt(y)&BigInt(o));c[z]=c[z].add(r[v])}let g=a;for(let v=c.length-1,M=a;v>0;v--)M=M.add(c[v]),g=g.add(M);if(p=p.add(g),y!==0)for(let v=0;v{const p=[];for(let y=0,g=d;y{if(J3(d,t),d.length>r.length)throw new Error("array of scalars must be smaller than array of points");let p=a;for(let y=0;y>g&o);z&&(p=p.add(c[v][z-1]))}}return p}}function FA(e){return(0,xx.validateField)(e.Fp),(0,Z3.validateObject)(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,xx.nLength)(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var X1={};Object.defineProperty(X1,"__esModule",{value:!0});X1.twistedEdwards=YA;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const cp=Ls,gx=It,nn=xt,tn=xt,Wn=BigInt(0),rn=BigInt(1),pu=BigInt(2),KA=BigInt(8),PA={zip215:!0};function GA(e){const t=(0,cp.validateBasic)(e);return nn.validateObject(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function YA(e){const t=GA(e),{Fp:r,n,prehash:a,hash:i,randomBytes:s,nByteLength:o,h:c}=t,d=pu<{try{return{isValid:!0,value:r.sqrt(S*r.inv(j))}}catch{return{isValid:!1,value:Wn}}}),v=t.adjustScalarBytes||(S=>S),M=t.domain||((S,j,R)=>{if((0,tn.abool)("phflag",R),j.length||R)throw new Error("Contexts/pre-hash are not supported");return S});function z(S,j){nn.aInRange("coordinate "+S,j,Wn,d)}function K(S){if(!(S instanceof k))throw new Error("ExtendedPoint expected")}const D=(0,tn.memoized)((S,j)=>{const{ex:R,ey:N,ez:h}=S,C=S.is0();j==null&&(j=C?KA:r.inv(h));const ae=p(R*j),he=p(N*j),q=p(h*j);if(C)return{x:Wn,y:rn};if(q!==rn)throw new Error("invZ was invalid");return{x:ae,y:he}}),T=(0,tn.memoized)(S=>{const{a:j,d:R}=t;if(S.is0())throw new Error("bad point: ZERO");const{ex:N,ey:h,ez:C,et:ae}=S,he=p(N*N),q=p(h*h),G=p(C*C),W=p(G*G),be=p(he*j),ue=p(G*p(be+q)),Q=p(W+p(R*p(he*q)));if(ue!==Q)throw new Error("bad point: equation left != right (1)");const le=p(N*h),Se=p(C*ae);if(le!==Se)throw new Error("bad point: equation left != right (2)");return!0});class k{constructor(j,R,N,h){this.ex=j,this.ey=R,this.ez=N,this.et=h,z("x",j),z("y",R),z("z",N),z("t",h),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(j){if(j instanceof k)throw new Error("extended point not allowed");const{x:R,y:N}=j||{};return z("x",R),z("y",N),new k(R,N,rn,p(R*N))}static normalizeZ(j){const R=r.invertBatch(j.map(N=>N.ez));return j.map((N,h)=>N.toAffine(R[h])).map(k.fromAffine)}static msm(j,R){return(0,cp.pippenger)(k,y,j,R)}_setWindowSize(j){F.setWindowSize(this,j)}assertValidity(){T(this)}equals(j){K(j);const{ex:R,ey:N,ez:h}=this,{ex:C,ey:ae,ez:he}=j,q=p(R*he),G=p(C*h),W=p(N*he),be=p(ae*h);return q===G&&W===be}is0(){return this.equals(k.ZERO)}negate(){return new k(p(-this.ex),this.ey,this.ez,p(-this.et))}double(){const{a:j}=t,{ex:R,ey:N,ez:h}=this,C=p(R*R),ae=p(N*N),he=p(pu*p(h*h)),q=p(j*C),G=R+N,W=p(p(G*G)-C-ae),be=q+ae,ue=be-he,Q=q-ae,le=p(W*ue),Se=p(be*Q),fe=p(W*Q),ie=p(ue*be);return new k(le,Se,ie,fe)}add(j){K(j);const{a:R,d:N}=t,{ex:h,ey:C,ez:ae,et:he}=this,{ex:q,ey:G,ez:W,et:be}=j;if(R===BigInt(-1)){const ct=p((C-h)*(G+q)),He=p((C+h)*(G-q)),Le=p(He-ct);if(Le===Wn)return this.double();const gt=p(ae*pu*be),rt=p(he*pu*W),et=rt+gt,dr=He+ct,B=rt-gt,m=p(et*Le),w=p(dr*B),H=p(et*B),X=p(Le*dr);return new k(m,w,X,H)}const ue=p(h*q),Q=p(C*G),le=p(he*N*be),Se=p(ae*W),fe=p((h+C)*(q+G)-ue-Q),ie=Se-le,pe=Se+le,me=p(Q-R*ue),ye=p(fe*ie),Ce=p(pe*me),je=p(fe*me),Te=p(ie*pe);return new k(ye,Ce,Te,je)}subtract(j){return this.add(j.negate())}wNAF(j){return F.wNAFCached(this,j,k.normalizeZ)}multiply(j){const R=j;nn.aInRange("scalar",R,rn,n);const{p:N,f:h}=this.wNAF(R);return k.normalizeZ([N,h])[0]}multiplyUnsafe(j,R=k.ZERO){const N=j;return nn.aInRange("scalar",N,Wn,n),N===Wn?$:this.is0()||N===rn?this:F.wNAFCachedUnsafe(this,N,k.normalizeZ,R)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return F.unsafeLadder(this,n).is0()}toAffine(j){return D(this,j)}clearCofactor(){const{h:j}=t;return j===rn?this:this.multiplyUnsafe(j)}static fromHex(j,R=!1){const{d:N,a:h}=t,C=r.BYTES;j=(0,tn.ensureBytes)("pointHex",j,C),(0,tn.abool)("zip215",R);const ae=j.slice(),he=j[C-1];ae[C-1]=he&-129;const q=nn.bytesToNumberLE(ae),G=R?d:r.ORDER;nn.aInRange("pointHex.y",q,Wn,G);const W=p(q*q),be=p(W-rn),ue=p(N*W-h);let{isValid:Q,value:le}=g(be,ue);if(!Q)throw new Error("Point.fromHex: invalid y coordinate");const Se=(le&rn)===rn,fe=(he&128)!==0;if(!R&&le===Wn&&fe)throw new Error("Point.fromHex: x=0 and x_0=1");return fe!==Se&&(le=p(-le)),k.fromAffine({x:le,y:q})}static fromPrivateKey(j){return Y(j).point}toRawBytes(){const{x:j,y:R}=this.toAffine(),N=nn.numberToBytesLE(R,r.BYTES);return N[N.length-1]|=j&rn?128:0,N}toHex(){return nn.bytesToHex(this.toRawBytes())}}k.BASE=new k(t.Gx,t.Gy,rn,p(t.Gx*t.Gy)),k.ZERO=new k(Wn,rn,rn,Wn);const{BASE:L,ZERO:$}=k,F=(0,cp.wNAF)(k,o*8);function V(S){return(0,gx.mod)(S,n)}function J(S){return V(nn.bytesToNumberLE(S))}function Y(S){const j=r.BYTES;S=(0,tn.ensureBytes)("private key",S,j);const R=(0,tn.ensureBytes)("hashed private key",i(S),2*j),N=v(R.slice(0,j)),h=R.slice(j,2*j),C=J(N),ae=L.multiply(C),he=ae.toRawBytes();return{head:N,prefix:h,scalar:C,point:ae,pointBytes:he}}function ee(S){return Y(S).pointBytes}function x(S=new Uint8Array,...j){const R=nn.concatBytes(...j);return J(i(M(R,(0,tn.ensureBytes)("context",S),!!a)))}function u(S,j,R={}){S=(0,tn.ensureBytes)("message",S),a&&(S=a(S));const{prefix:N,scalar:h,pointBytes:C}=Y(j),ae=x(R.context,N,S),he=L.multiply(ae).toRawBytes(),q=x(R.context,he,C,S),G=V(ae+q*h);nn.aInRange("signature.s",G,Wn,n);const W=nn.concatBytes(he,nn.numberToBytesLE(G,r.BYTES));return(0,tn.ensureBytes)("result",W,r.BYTES*2)}const f=PA;function _(S,j,R,N=f){const{context:h,zip215:C}=N,ae=r.BYTES;S=(0,tn.ensureBytes)("signature",S,2*ae),j=(0,tn.ensureBytes)("message",j),R=(0,tn.ensureBytes)("publicKey",R,ae),C!==void 0&&(0,tn.abool)("zip215",C),a&&(j=a(j));const he=nn.bytesToNumberLE(S.slice(ae,2*ae));let q,G,W;try{q=k.fromHex(R,C),G=k.fromHex(S.slice(0,ae),C),W=L.multiplyUnsafe(he)}catch{return!1}if(!C&&q.isSmallOrder())return!1;const be=x(h,G.toRawBytes(),q.toRawBytes(),j);return G.add(q.multiplyUnsafe(be)).subtract(W).clearCofactor().equals(k.ZERO)}return L._setWindowSize(8),{CURVE:t,getPublicKey:ee,sign:u,verify:_,ExtendedPoint:k,utils:{getExtendedPublicKey:Y,randomPrivateKey:()=>s(r.BYTES),precompute(S=8,j=k.BASE){return j._setWindowSize(S),j.multiply(BigInt(3)),j}}}}var Hs={};Object.defineProperty(Hs,"__esModule",{value:!0});Hs.expand_message_xmd=e6;Hs.expand_message_xof=t6;Hs.hash_to_field=up;Hs.isogenyMap=QA;Hs.createHasher=JA;const VA=It,Fr=xt,XA=Fr.bytesToNumberBE;function fi(e,t){if(pc(e),pc(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function ZA(e,t){const r=new Uint8Array(e.length);for(let n=0;n255&&(t=n((0,Fr.concatBytes)((0,Fr.utf8ToBytes)("H2C-OVERSIZE-DST-"),t)));const{outputLen:a,blockLen:i}=n,s=Math.ceil(r/a);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");const o=(0,Fr.concatBytes)(t,fi(t.length,1)),c=fi(0,i),d=fi(r,2),p=new Array(s),y=n((0,Fr.concatBytes)(c,e,d,fi(0,1),o));p[0]=n((0,Fr.concatBytes)(y,fi(1,1),o));for(let v=1;v<=s;v++){const M=[ZA(y,p[v-1]),fi(v+1,1),o];p[v]=n((0,Fr.concatBytes)(...M))}return(0,Fr.concatBytes)(...p).slice(0,r)}function t6(e,t,r,n,a){if((0,Fr.abytes)(e),(0,Fr.abytes)(t),pc(r),t.length>255){const i=Math.ceil(2*n/8);t=a.create({dkLen:i}).update((0,Fr.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(t).digest()}if(r>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return a.create({dkLen:r}).update(e).update(fi(r,2)).update(t).update(fi(t.length,1)).digest()}function up(e,t,r){(0,Fr.validateObject)(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:n,k:a,m:i,hash:s,expand:o,DST:c}=r;(0,Fr.abytes)(e),pc(t);const d=typeof c=="string"?(0,Fr.utf8ToBytes)(c):c,p=n.toString(2).length,y=Math.ceil((p+a)/8),g=t*i*y;let v;if(o==="xmd")v=e6(e,d,g,s);else if(o==="xof")v=t6(e,d,g,a,s);else if(o==="_internal_pass")v=e;else throw new Error('expand must be "xmd" or "xof"');const M=new Array(t);for(let z=0;zArray.from(n).reverse());return(n,a)=>{const[i,s,o,c]=r.map(d=>d.reduce((p,y)=>e.add(e.mul(p,n),y)));return n=e.div(i,s),a=e.mul(a,e.div(o,c)),{x:n,y:a}}}function JA(e,t,r){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(n,a){const i=up(n,2,{...r,DST:r.DST,...a}),s=e.fromAffine(t(i[0])),o=e.fromAffine(t(i[1])),c=s.add(o).clearCofactor();return c.assertValidity(),c},encodeToCurve(n,a){const i=up(n,1,{...r,DST:r.encodeDST,...a}),s=e.fromAffine(t(i[0])).clearCofactor();return s.assertValidity(),s},mapToCurve(n){if(!Array.isArray(n))throw new Error("mapToCurve: expected array of bigints");for(const i of n)if(typeof i!="bigint")throw new Error("mapToCurve: expected array of bigints");const a=e.fromAffine(t(n)).clearCofactor();return a.assertValidity(),a}}}var Z1={};Object.defineProperty(Z1,"__esModule",{value:!0});Z1.montgomery=eN;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const vx=It,li=xt,Ys=BigInt(0),k0=BigInt(1);function WA(e){return(0,li.validateObject)(e,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...e})}function eN(e){const t=WA(e),{P:r}=t,n=T=>(0,vx.mod)(T,r),a=t.montgomeryBits,i=Math.ceil(a/8),s=t.nByteLength,o=t.adjustScalarBytes||(T=>T),c=t.powPminus2||(T=>(0,vx.pow)(T,r-BigInt(2),r));function d(T,k,L){const $=n(T*(k-L));return k=n(k-$),L=n(L+$),[k,L]}const p=(t.a-BigInt(2))/BigInt(4);function y(T,k){(0,li.aInRange)("u",T,Ys,r),(0,li.aInRange)("scalar",k,Ys,r);const L=k,$=T;let F=k0,V=Ys,J=T,Y=k0,ee=Ys,x;for(let f=BigInt(a-1);f>=Ys;f--){const _=L>>f&k0;ee^=_,x=d(ee,F,J),F=x[0],J=x[1],x=d(ee,V,Y),V=x[0],Y=x[1],ee=_;const E=F+V,S=n(E*E),j=F-V,R=n(j*j),N=S-R,h=J+Y,C=J-Y,ae=n(C*E),he=n(h*j),q=ae+he,G=ae-he;J=n(q*q),Y=n($*n(G*G)),F=n(S*R),V=n(N*(S+n(p*N)))}x=d(ee,F,J),F=x[0],J=x[1],x=d(ee,V,Y),V=x[0],Y=x[1];const u=c(V);return n(F*u)}function g(T){return(0,li.numberToBytesLE)(n(T),i)}function v(T){const k=(0,li.ensureBytes)("u coordinate",T,i);return s===32&&(k[31]&=127),(0,li.bytesToNumberLE)(k)}function M(T){const k=(0,li.ensureBytes)("scalar",T),L=k.length;if(L!==i&&L!==s){let $=""+i+" or "+s;throw new Error("invalid scalar, expected "+$+" bytes, got "+L)}return(0,li.bytesToNumberLE)(o(k))}function z(T,k){const L=v(k),$=M(T),F=y(L,$);if(F===Ys)throw new Error("invalid private or public key received");return g(F)}const K=g(t.Gu);function D(T){return z(T,K)}return{scalarMult:z,scalarMultBase:D,getSharedSecret:(T,k)=>z(T,k),getPublicKey:T=>D(T),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:K}}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hash_to_ristretto255=e.hashToRistretto255=e.RistrettoPoint=e.encodeToCurve=e.hashToCurve=e.edwardsToMontgomery=e.x25519=e.ed25519ph=e.ed25519ctx=e.ed25519=e.ED25519_TORSION_SUBGROUP=void 0,e.edwardsToMontgomeryPub=V,e.edwardsToMontgomeryPriv=J;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Er,r=cd,n=Ls,a=X1,i=Hs,s=It,o=Z1,c=xt,d=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),p=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),y=BigInt(0),g=BigInt(1),v=BigInt(2),M=BigInt(3),z=BigInt(5),K=BigInt(8);function D(ue){const Q=BigInt(10),le=BigInt(20),Se=BigInt(40),fe=BigInt(80),ie=d,me=ue*ue%ie*ue%ie,ye=(0,s.pow2)(me,v,ie)*me%ie,Ce=(0,s.pow2)(ye,g,ie)*ue%ie,je=(0,s.pow2)(Ce,z,ie)*Ce%ie,Te=(0,s.pow2)(je,Q,ie)*je%ie,ct=(0,s.pow2)(Te,le,ie)*Te%ie,He=(0,s.pow2)(ct,Se,ie)*ct%ie,Le=(0,s.pow2)(He,fe,ie)*He%ie,gt=(0,s.pow2)(Le,fe,ie)*He%ie,rt=(0,s.pow2)(gt,Q,ie)*je%ie;return{pow_p_5_8:(0,s.pow2)(rt,v,ie)*ue%ie,b2:me}}function T(ue){return ue[0]&=248,ue[31]&=127,ue[31]|=64,ue}function k(ue,Q){const le=d,Se=(0,s.mod)(Q*Q*Q,le),fe=(0,s.mod)(Se*Se*Q,le),ie=D(ue*fe).pow_p_5_8;let pe=(0,s.mod)(ue*Se*ie,le);const me=(0,s.mod)(Q*pe*pe,le),ye=pe,Ce=(0,s.mod)(pe*p,le),je=me===ue,Te=me===(0,s.mod)(-ue,le),ct=me===(0,s.mod)(-ue*p,le);return je&&(pe=ye),(Te||ct)&&(pe=Ce),(0,s.isNegativeLE)(pe,le)&&(pe=(0,s.mod)(-pe,le)),{isValid:je||Te,value:pe}}e.ED25519_TORSION_SUBGROUP=["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"];const L=(0,s.Field)(d,void 0,!0),$={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:L,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:K,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:t.sha512,randomBytes:r.randomBytes,adjustScalarBytes:T,uvRatio:k};e.ed25519=(0,a.twistedEdwards)($);function F(ue,Q,le){if(Q.length>255)throw new Error("Context is too big");return(0,r.concatBytes)((0,r.utf8ToBytes)("SigEd25519 no Ed25519 collisions"),new Uint8Array([le?1:0,Q.length]),Q,ue)}e.ed25519ctx=(0,a.twistedEdwards)({...$,domain:F}),e.ed25519ph=(0,a.twistedEdwards)(Object.assign({},$,{domain:F,prehash:t.sha512})),e.x25519=(0,o.montgomery)({P:d,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:ue=>{const Q=d,{pow_p_5_8:le,b2:Se}=D(ue);return(0,s.mod)((0,s.pow2)(le,M,Q)*Se,Q)},adjustScalarBytes:T,randomBytes:r.randomBytes});function V(ue){const{y:Q}=e.ed25519.ExtendedPoint.fromHex(ue),le=BigInt(1);return L.toBytes(L.create((le+Q)*L.inv(le-Q)))}e.edwardsToMontgomery=V;function J(ue){const Q=$.hash(ue.subarray(0,32));return $.adjustScalarBytes(Q).subarray(0,32)}const Y=(L.ORDER+M)/K,ee=L.pow(v,Y),x=L.sqrt(L.neg(L.ONE));function u(ue){const Q=(L.ORDER-z)/K,le=BigInt(486662);let Se=L.sqr(ue);Se=L.mul(Se,v);let fe=L.add(Se,L.ONE),ie=L.neg(le),pe=L.sqr(fe),me=L.mul(pe,fe),ye=L.mul(Se,le);ye=L.mul(ye,ie),ye=L.add(ye,pe),ye=L.mul(ye,ie);let Ce=L.sqr(me);pe=L.sqr(Ce),Ce=L.mul(Ce,me),Ce=L.mul(Ce,ye),pe=L.mul(pe,Ce);let je=L.pow(pe,Q);je=L.mul(je,Ce);let Te=L.mul(je,x);pe=L.sqr(je),pe=L.mul(pe,me);let ct=L.eql(pe,ye),He=L.cmov(Te,je,ct),Le=L.mul(ie,Se),gt=L.mul(je,ue);gt=L.mul(gt,ee);let rt=L.mul(gt,x),et=L.mul(ye,Se);pe=L.sqr(gt),pe=L.mul(pe,me);let dr=L.eql(pe,et),B=L.cmov(rt,gt,dr);pe=L.sqr(He),pe=L.mul(pe,me);let m=L.eql(pe,ye),w=L.cmov(Le,ie,m),H=L.cmov(B,He,m),X=L.isOdd(H);return H=L.cmov(H,L.neg(H),m!==X),{xMn:w,xMd:fe,yMn:H,yMd:g}}const f=(0,s.FpSqrtEven)(L,L.neg(BigInt(486664)));function _(ue){const{xMn:Q,xMd:le,yMn:Se,yMd:fe}=u(ue);let ie=L.mul(Q,fe);ie=L.mul(ie,f);let pe=L.mul(le,Se),me=L.sub(Q,le),ye=L.add(Q,le),Ce=L.mul(pe,ye),je=L.eql(Ce,L.ZERO);ie=L.cmov(ie,L.ZERO,je),pe=L.cmov(pe,L.ONE,je),me=L.cmov(me,L.ONE,je),ye=L.cmov(ye,L.ONE,je);const Te=L.invertBatch([pe,ye]);return{x:L.mul(ie,Te[0]),y:L.mul(me,Te[1])}}const E=(0,i.createHasher)(e.ed25519.ExtendedPoint,ue=>_(ue[0]),{DST:"edwards25519_XMD:SHA-512_ELL2_RO_",encodeDST:"edwards25519_XMD:SHA-512_ELL2_NU_",p:L.ORDER,m:1,k:128,expand:"xmd",hash:t.sha512});e.hashToCurve=E.hashToCurve,e.encodeToCurve=E.encodeToCurve;function S(ue){if(!(ue instanceof W))throw new Error("RistrettoPoint expected")}const j=p,R=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),N=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),h=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),C=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ae=ue=>k(g,ue),he=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),q=ue=>e.ed25519.CURVE.Fp.create((0,c.bytesToNumberLE)(ue)&he);function G(ue){const{d:Q}=e.ed25519.CURVE,le=e.ed25519.CURVE.Fp.ORDER,Se=e.ed25519.CURVE.Fp.create,fe=Se(j*ue*ue),ie=Se((fe+g)*h);let pe=BigInt(-1);const me=Se((pe-Q*fe)*Se(fe+Q));let{isValid:ye,value:Ce}=k(ie,me),je=Se(Ce*ue);(0,s.isNegativeLE)(je,le)||(je=Se(-je)),ye||(Ce=je),ye||(pe=fe);const Te=Se(pe*(fe-g)*C-me),ct=Ce*Ce,He=Se((Ce+Ce)*me),Le=Se(Te*R),gt=Se(g-ct),rt=Se(g+ct);return new e.ed25519.ExtendedPoint(Se(He*rt),Se(gt*Le),Se(Le*rt),Se(He*gt))}class W{constructor(Q){this.ep=Q}static fromAffine(Q){return new W(e.ed25519.ExtendedPoint.fromAffine(Q))}static hashToCurve(Q){Q=(0,c.ensureBytes)("ristrettoHash",Q,64);const le=q(Q.slice(0,32)),Se=G(le),fe=q(Q.slice(32,64)),ie=G(fe);return new W(Se.add(ie))}static fromHex(Q){Q=(0,c.ensureBytes)("ristrettoHex",Q,32);const{a:le,d:Se}=e.ed25519.CURVE,fe=e.ed25519.CURVE.Fp.ORDER,ie=e.ed25519.CURVE.Fp.create,pe="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",me=q(Q);if(!(0,c.equalBytes)((0,c.numberToBytesLE)(me,32),Q)||(0,s.isNegativeLE)(me,fe))throw new Error(pe);const ye=ie(me*me),Ce=ie(g+le*ye),je=ie(g-le*ye),Te=ie(Ce*Ce),ct=ie(je*je),He=ie(le*Se*Te-ct),{isValid:Le,value:gt}=ae(ie(He*ct)),rt=ie(gt*je),et=ie(gt*rt*He);let dr=ie((me+me)*rt);(0,s.isNegativeLE)(dr,fe)&&(dr=ie(-dr));const B=ie(Ce*et),m=ie(dr*B);if(!Le||(0,s.isNegativeLE)(m,fe)||B===y)throw new Error(pe);return new W(new e.ed25519.ExtendedPoint(dr,B,g,m))}static msm(Q,le){const Se=(0,s.Field)(e.ed25519.CURVE.n,e.ed25519.CURVE.nBitLength);return(0,n.pippenger)(W,Se,Q,le)}toRawBytes(){let{ex:Q,ey:le,ez:Se,et:fe}=this.ep;const ie=e.ed25519.CURVE.Fp.ORDER,pe=e.ed25519.CURVE.Fp.create,me=pe(pe(Se+le)*pe(Se-le)),ye=pe(Q*le),Ce=pe(ye*ye),{value:je}=ae(pe(me*Ce)),Te=pe(je*me),ct=pe(je*ye),He=pe(Te*ct*fe);let Le;if((0,s.isNegativeLE)(fe*He,ie)){let rt=pe(le*j),et=pe(Q*j);Q=rt,le=et,Le=pe(Te*N)}else Le=ct;(0,s.isNegativeLE)(Q*He,ie)&&(le=pe(-le));let gt=pe((Se-le)*Le);return(0,s.isNegativeLE)(gt,ie)&&(gt=pe(-gt)),(0,c.numberToBytesLE)(gt,32)}toHex(){return(0,c.bytesToHex)(this.toRawBytes())}toString(){return this.toHex()}equals(Q){S(Q);const{ex:le,ey:Se}=this.ep,{ex:fe,ey:ie}=Q.ep,pe=e.ed25519.CURVE.Fp.create,me=pe(le*ie)===pe(Se*fe),ye=pe(Se*ie)===pe(le*fe);return me||ye}add(Q){return S(Q),new W(this.ep.add(Q.ep))}subtract(Q){return S(Q),new W(this.ep.subtract(Q.ep))}multiply(Q){return new W(this.ep.multiply(Q))}multiplyUnsafe(Q){return new W(this.ep.multiplyUnsafe(Q))}double(){return new W(this.ep.double())}negate(){return new W(this.ep.negate())}}e.RistrettoPoint=(W.BASE||(W.BASE=new W(e.ed25519.ExtendedPoint.BASE)),W.ZERO||(W.ZERO=new W(e.ed25519.ExtendedPoint.ZERO)),W);const be=(ue,Q)=>{const le=Q.DST,Se=typeof le=="string"?(0,r.utf8ToBytes)(le):le,fe=(0,i.expand_message_xmd)(ue,Se,64,t.sha512);return W.hashToCurve(fe)};e.hashToRistretto255=be,e.hash_to_ristretto255=e.hashToRistretto255})($1);var fp={exports:{}},dp={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh */(function(e,t){var r=_f,n=r.Buffer;function a(s,o){for(var c in s)o[c]=s[c]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(a(r,t),t.Buffer=i);function i(s,o,c){return n(s,o,c)}i.prototype=Object.create(n.prototype),a(n,i),i.from=function(s,o,c){if(typeof s=="number")throw new TypeError("Argument must not be a number");return n(s,o,c)},i.alloc=function(s,o,c){if(typeof s!="number")throw new TypeError("Argument must be a number");var d=n(s);return o!==void 0?typeof c=="string"?d.fill(o,c):d.fill(o):d.fill(0),d},i.allocUnsafe=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return n(s)},i.allocUnsafeSlow=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(s)}})(dp,dp.exports);var tN=dp.exports,z0=65536,rN=4294967295;function nN(){throw new Error(`Secure random number generation is not supported by this browser. +Use Chrome, Firefox or Internet Explorer 11`)}var aN=tN.Buffer,Ef=Ie.crypto||Ie.msCrypto;Ef&&Ef.getRandomValues?fp.exports=iN:fp.exports=nN;function iN(e,t){if(e>rN)throw new RangeError("requested too many random bytes");var r=aN.allocUnsafe(e);if(e>0)if(e>z0)for(var n=0;nnew Uint8Array(r),t){return typeof e=="function"&&(e=e(t)),Et("output",e,t),e}function Js(e){return Object.prototype.toString.call(e).slice(8,-1)}var sN=e=>({contextRandomize(t){switch(Dn(t===null||t instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),t!==null&&Et("seed",t,32),e.contextRandomize(t)){case 1:throw new Error(Tt.CONTEXT_RANDOMIZE_UNKNOW)}},privateKeyVerify(t){return Et("private key",t,32),e.privateKeyVerify(t)===0},privateKeyNegate(t){switch(Et("private key",t,32),e.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(Tt.IMPOSSIBLE_CASE)}},privateKeyTweakAdd(t,r){switch(Et("private key",t,32),Et("tweak",r,32),e.privateKeyTweakAdd(t,r)){case 0:return t;case 1:throw new Error(Tt.TWEAK_ADD)}},privateKeyTweakMul(t,r){switch(Et("private key",t,32),Et("tweak",r,32),e.privateKeyTweakMul(t,r)){case 0:return t;case 1:throw new Error(Tt.TWEAK_MUL)}},publicKeyVerify(t){return Et("public key",t,[33,65]),e.publicKeyVerify(t)===0},publicKeyCreate(t,r=!0,n){switch(Et("private key",t,32),es(r),n=ea(n,r?33:65),e.publicKeyCreate(n,t)){case 0:return n;case 1:throw new Error(Tt.SECKEY_INVALID);case 2:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyConvert(t,r=!0,n){switch(Et("public key",t,[33,65]),es(r),n=ea(n,r?33:65),e.publicKeyConvert(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyNegate(t,r=!0,n){switch(Et("public key",t,[33,65]),es(r),n=ea(n,r?33:65),e.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE);case 3:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyCombine(t,r=!0,n){Dn(Array.isArray(t),"Expected public keys to be an Array"),Dn(t.length>0,"Expected public keys array will have more than zero items");for(const a of t)Et("public key",a,[33,65]);switch(es(r),n=ea(n,r?33:65),e.publicKeyCombine(n,t)){case 0:return n;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.PUBKEY_COMBINE);case 3:throw new Error(Tt.PUBKEY_SERIALIZE)}},publicKeyTweakAdd(t,r,n=!0,a){switch(Et("public key",t,[33,65]),Et("tweak",r,32),es(n),a=ea(a,n?33:65),e.publicKeyTweakAdd(a,t,r)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.TWEAK_ADD)}},publicKeyTweakMul(t,r,n=!0,a){switch(Et("public key",t,[33,65]),Et("tweak",r,32),es(n),a=ea(a,n?33:65),e.publicKeyTweakMul(a,t,r)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.TWEAK_MUL)}},signatureNormalize(t){switch(Et("signature",t,64),e.signatureNormalize(t)){case 0:return t;case 1:throw new Error(Tt.SIG_PARSE)}},signatureExport(t,r){Et("signature",t,64),r=ea(r,72);const n={output:r,outputlen:72};switch(e.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},signatureImport(t,r){switch(Et("signature",t),r=ea(r,64),e.signatureImport(r,t)){case 0:return r;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdsaSign(t,r,n={},a){Et("message",t,32),Et("private key",r,32),Dn(Js(n)==="Object","Expected options to be an Object"),n.data!==void 0&&Et("options.data",n.data),n.noncefn!==void 0&&Dn(Js(n.noncefn)==="Function","Expected options.noncefn to be a Function"),a=ea(a,64);const i={signature:a,recid:null};switch(e.ecdsaSign(i,t,r,n.data,n.noncefn)){case 0:return i;case 1:throw new Error(Tt.SIGN);case 2:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdsaVerify(t,r,n){switch(Et("signature",t,64),Et("message",r,32),Et("public key",n,[33,65]),e.ecdsaVerify(t,r,n)){case 0:return!0;case 3:return!1;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.PUBKEY_PARSE)}},ecdsaRecover(t,r,n,a=!0,i){switch(Et("signature",t,64),Dn(Js(r)==="Number"&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),Et("message",n,32),es(a),i=ea(i,a?33:65),e.ecdsaRecover(i,t,r,n)){case 0:return i;case 1:throw new Error(Tt.SIG_PARSE);case 2:throw new Error(Tt.RECOVER);case 3:throw new Error(Tt.IMPOSSIBLE_CASE)}},ecdh(t,r,n={},a){switch(Et("public key",t,[33,65]),Et("private key",r,32),Dn(Js(n)==="Object","Expected options to be an Object"),n.data!==void 0&&Et("options.data",n.data),n.hashfn!==void 0?(Dn(Js(n.hashfn)==="Function","Expected options.hashfn to be a Function"),n.xbuf!==void 0&&Et("options.xbuf",n.xbuf,32),n.ybuf!==void 0&&Et("options.ybuf",n.ybuf,32),Et("output",a)):a=ea(a,32),e.ecdh(a,t,r,n.data,n.hashfn,n.xbuf,n.ybuf)){case 0:return a;case 1:throw new Error(Tt.PUBKEY_PARSE);case 2:throw new Error(Tt.ECDH)}}}),n6={};const oN="6.6.1",lN={version:oN};var Bn={},Q1={exports:{}};Q1.exports;(function(e){(function(t,r){function n(x,u){if(!x)throw new Error(u||"Assertion failed")}function a(x,u){x.super_=u;var f=function(){};f.prototype=u.prototype,x.prototype=new f,x.prototype.constructor=x}function i(x,u,f){if(i.isBN(x))return x;this.negative=0,this.words=null,this.length=0,this.red=null,x!==null&&((u==="le"||u==="be")&&(f=u,u=10),this._init(x||0,u||10,f||"be"))}typeof t=="object"?t.exports=i:r.BN=i,i.BN=i,i.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=hc.Buffer}catch{}i.isBN=function(u){return u instanceof i?!0:u!==null&&typeof u=="object"&&u.constructor.wordSize===i.wordSize&&Array.isArray(u.words)},i.max=function(u,f){return u.cmp(f)>0?u:f},i.min=function(u,f){return u.cmp(f)<0?u:f},i.prototype._init=function(u,f,_){if(typeof u=="number")return this._initNumber(u,f,_);if(typeof u=="object")return this._initArray(u,f,_);f==="hex"&&(f=16),n(f===(f|0)&&f>=2&&f<=36),u=u.toString().replace(/\s+/g,"");var E=0;u[0]==="-"&&(E++,this.negative=1),E=0;E-=3)j=u[E]|u[E-1]<<8|u[E-2]<<16,this.words[S]|=j<>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);else if(_==="le")for(E=0,S=0;E>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);return this.strip()};function o(x,u){var f=x.charCodeAt(u);return f>=65&&f<=70?f-55:f>=97&&f<=102?f-87:f-48&15}function c(x,u,f){var _=o(x,f);return f-1>=u&&(_|=o(x,f-1)<<4),_}i.prototype._parseHex=function(u,f,_){this.length=Math.ceil((u.length-f)/6),this.words=new Array(this.length);for(var E=0;E=f;E-=2)R=c(u,f,E)<=18?(S-=18,j+=1,this.words[j]|=R>>>26):S+=8;else{var N=u.length-f;for(E=N%2===0?f+1:f;E=18?(S-=18,j+=1,this.words[j]|=R>>>26):S+=8}this.strip()};function d(x,u,f,_){for(var E=0,S=Math.min(x.length,f),j=u;j=49?E+=R-49+10:R>=17?E+=R-17+10:E+=R}return E}i.prototype._parseBase=function(u,f,_){this.words=[0],this.length=1;for(var E=0,S=1;S<=67108863;S*=f)E++;E--,S=S/f|0;for(var j=u.length-_,R=j%E,N=Math.min(j,j-R)+_,h=0,C=_;C1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?""};var p=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],y=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],g=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(u,f){u=u||10,f=f|0||1;var _;if(u===16||u==="hex"){_="";for(var E=0,S=0,j=0;j>>24-E&16777215,E+=2,E>=26&&(E-=26,j--),S!==0||j!==this.length-1?_=p[6-N.length]+N+_:_=N+_}for(S!==0&&(_=S.toString(16)+_);_.length%f!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}if(u===(u|0)&&u>=2&&u<=36){var h=y[u],C=g[u];_="";var ae=this.clone();for(ae.negative=0;!ae.isZero();){var he=ae.modn(C).toString(u);ae=ae.idivn(C),ae.isZero()?_=he+_:_=p[h-he.length]+he+_}for(this.isZero()&&(_="0"+_);_.length%f!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}n(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var u=this.words[0];return this.length===2?u+=this.words[1]*67108864:this.length===3&&this.words[2]===1?u+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-u:u},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(u,f){return n(typeof s<"u"),this.toArrayLike(s,u,f)},i.prototype.toArray=function(u,f){return this.toArrayLike(Array,u,f)},i.prototype.toArrayLike=function(u,f,_){var E=this.byteLength(),S=_||Math.max(1,E);n(E<=S,"byte array longer than desired length"),n(S>0,"Requested array length <= 0"),this.strip();var j=f==="le",R=new u(S),N,h,C=this.clone();if(j){for(h=0;!C.isZero();h++)N=C.andln(255),C.iushrn(8),R[h]=N;for(;h=4096&&(_+=13,f>>>=13),f>=64&&(_+=7,f>>>=7),f>=8&&(_+=4,f>>>=4),f>=2&&(_+=2,f>>>=2),_+f},i.prototype._zeroBits=function(u){if(u===0)return 26;var f=u,_=0;return f&8191||(_+=13,f>>>=13),f&127||(_+=7,f>>>=7),f&15||(_+=4,f>>>=4),f&3||(_+=2,f>>>=2),f&1||_++,_},i.prototype.bitLength=function(){var u=this.words[this.length-1],f=this._countBits(u);return(this.length-1)*26+f};function v(x){for(var u=new Array(x.bitLength()),f=0;f>>E}return u}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var u=0,f=0;fu.length?this.clone().ior(u):u.clone().ior(this)},i.prototype.uor=function(u){return this.length>u.length?this.clone().iuor(u):u.clone().iuor(this)},i.prototype.iuand=function(u){var f;this.length>u.length?f=u:f=this;for(var _=0;_u.length?this.clone().iand(u):u.clone().iand(this)},i.prototype.uand=function(u){return this.length>u.length?this.clone().iuand(u):u.clone().iuand(this)},i.prototype.iuxor=function(u){var f,_;this.length>u.length?(f=this,_=u):(f=u,_=this);for(var E=0;E<_.length;E++)this.words[E]=f.words[E]^_.words[E];if(this!==f)for(;Eu.length?this.clone().ixor(u):u.clone().ixor(this)},i.prototype.uxor=function(u){return this.length>u.length?this.clone().iuxor(u):u.clone().iuxor(this)},i.prototype.inotn=function(u){n(typeof u=="number"&&u>=0);var f=Math.ceil(u/26)|0,_=u%26;this._expand(f),_>0&&f--;for(var E=0;E0&&(this.words[E]=~this.words[E]&67108863>>26-_),this.strip()},i.prototype.notn=function(u){return this.clone().inotn(u)},i.prototype.setn=function(u,f){n(typeof u=="number"&&u>=0);var _=u/26|0,E=u%26;return this._expand(_+1),f?this.words[_]=this.words[_]|1<u.length?(_=this,E=u):(_=u,E=this);for(var S=0,j=0;j>>26;for(;S!==0&&j<_.length;j++)f=(_.words[j]|0)+S,this.words[j]=f&67108863,S=f>>>26;if(this.length=_.length,S!==0)this.words[this.length]=S,this.length++;else if(_!==this)for(;j<_.length;j++)this.words[j]=_.words[j];return this},i.prototype.add=function(u){var f;return u.negative!==0&&this.negative===0?(u.negative=0,f=this.sub(u),u.negative^=1,f):u.negative===0&&this.negative!==0?(this.negative=0,f=u.sub(this),this.negative=1,f):this.length>u.length?this.clone().iadd(u):u.clone().iadd(this)},i.prototype.isub=function(u){if(u.negative!==0){u.negative=0;var f=this.iadd(u);return u.negative=1,f._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(u),this.negative=1,this._normSign();var _=this.cmp(u);if(_===0)return this.negative=0,this.length=1,this.words[0]=0,this;var E,S;_>0?(E=this,S=u):(E=u,S=this);for(var j=0,R=0;R>26,this.words[R]=f&67108863;for(;j!==0&&R>26,this.words[R]=f&67108863;if(j===0&&R>>26,ae=N&67108863,he=Math.min(h,u.length-1),q=Math.max(0,h-x.length+1);q<=he;q++){var G=h-q|0;E=x.words[G]|0,S=u.words[q]|0,j=E*S+ae,C+=j/67108864|0,ae=j&67108863}f.words[h]=ae|0,N=C|0}return N!==0?f.words[h]=N|0:f.length--,f.strip()}var z=function(u,f,_){var E=u.words,S=f.words,j=_.words,R=0,N,h,C,ae=E[0]|0,he=ae&8191,q=ae>>>13,G=E[1]|0,W=G&8191,be=G>>>13,ue=E[2]|0,Q=ue&8191,le=ue>>>13,Se=E[3]|0,fe=Se&8191,ie=Se>>>13,pe=E[4]|0,me=pe&8191,ye=pe>>>13,Ce=E[5]|0,je=Ce&8191,Te=Ce>>>13,ct=E[6]|0,He=ct&8191,Le=ct>>>13,gt=E[7]|0,rt=gt&8191,et=gt>>>13,dr=E[8]|0,B=dr&8191,m=dr>>>13,w=E[9]|0,H=w&8191,X=w>>>13,ne=S[0]|0,ce=ne&8191,ze=ne>>>13,jt=S[1]|0,$e=jt&8191,Xe=jt>>>13,pt=S[2]|0,$t=pt&8191,Zt=pt>>>13,ol=S[3]|0,tr=ol&8191,rr=ol>>>13,Rn=S[4]|0,kt=Rn&8191,Lt=Rn>>>13,Fs=S[5]|0,Qt=Fs&8191,Wt=Fs>>>13,Pc=S[6]|0,wt=Pc&8191,er=Pc>>>13,A=S[7]|0,U=A&8191,O=A>>>13,b=S[8]|0,I=b&8191,Z=b>>>13,te=S[9]|0,de=te&8191,we=te>>>13;_.negative=u.negative^f.negative,_.length=19,N=Math.imul(he,ce),h=Math.imul(he,ze),h=h+Math.imul(q,ce)|0,C=Math.imul(q,ze);var ke=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(ke>>>26)|0,ke&=67108863,N=Math.imul(W,ce),h=Math.imul(W,ze),h=h+Math.imul(be,ce)|0,C=Math.imul(be,ze),N=N+Math.imul(he,$e)|0,h=h+Math.imul(he,Xe)|0,h=h+Math.imul(q,$e)|0,C=C+Math.imul(q,Xe)|0;var Ne=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,N=Math.imul(Q,ce),h=Math.imul(Q,ze),h=h+Math.imul(le,ce)|0,C=Math.imul(le,ze),N=N+Math.imul(W,$e)|0,h=h+Math.imul(W,Xe)|0,h=h+Math.imul(be,$e)|0,C=C+Math.imul(be,Xe)|0,N=N+Math.imul(he,$t)|0,h=h+Math.imul(he,Zt)|0,h=h+Math.imul(q,$t)|0,C=C+Math.imul(q,Zt)|0;var ft=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(ft>>>26)|0,ft&=67108863,N=Math.imul(fe,ce),h=Math.imul(fe,ze),h=h+Math.imul(ie,ce)|0,C=Math.imul(ie,ze),N=N+Math.imul(Q,$e)|0,h=h+Math.imul(Q,Xe)|0,h=h+Math.imul(le,$e)|0,C=C+Math.imul(le,Xe)|0,N=N+Math.imul(W,$t)|0,h=h+Math.imul(W,Zt)|0,h=h+Math.imul(be,$t)|0,C=C+Math.imul(be,Zt)|0,N=N+Math.imul(he,tr)|0,h=h+Math.imul(he,rr)|0,h=h+Math.imul(q,tr)|0,C=C+Math.imul(q,rr)|0;var Be=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Be>>>26)|0,Be&=67108863,N=Math.imul(me,ce),h=Math.imul(me,ze),h=h+Math.imul(ye,ce)|0,C=Math.imul(ye,ze),N=N+Math.imul(fe,$e)|0,h=h+Math.imul(fe,Xe)|0,h=h+Math.imul(ie,$e)|0,C=C+Math.imul(ie,Xe)|0,N=N+Math.imul(Q,$t)|0,h=h+Math.imul(Q,Zt)|0,h=h+Math.imul(le,$t)|0,C=C+Math.imul(le,Zt)|0,N=N+Math.imul(W,tr)|0,h=h+Math.imul(W,rr)|0,h=h+Math.imul(be,tr)|0,C=C+Math.imul(be,rr)|0,N=N+Math.imul(he,kt)|0,h=h+Math.imul(he,Lt)|0,h=h+Math.imul(q,kt)|0,C=C+Math.imul(q,Lt)|0;var Fe=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,N=Math.imul(je,ce),h=Math.imul(je,ze),h=h+Math.imul(Te,ce)|0,C=Math.imul(Te,ze),N=N+Math.imul(me,$e)|0,h=h+Math.imul(me,Xe)|0,h=h+Math.imul(ye,$e)|0,C=C+Math.imul(ye,Xe)|0,N=N+Math.imul(fe,$t)|0,h=h+Math.imul(fe,Zt)|0,h=h+Math.imul(ie,$t)|0,C=C+Math.imul(ie,Zt)|0,N=N+Math.imul(Q,tr)|0,h=h+Math.imul(Q,rr)|0,h=h+Math.imul(le,tr)|0,C=C+Math.imul(le,rr)|0,N=N+Math.imul(W,kt)|0,h=h+Math.imul(W,Lt)|0,h=h+Math.imul(be,kt)|0,C=C+Math.imul(be,Lt)|0,N=N+Math.imul(he,Qt)|0,h=h+Math.imul(he,Wt)|0,h=h+Math.imul(q,Qt)|0,C=C+Math.imul(q,Wt)|0;var Ke=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,N=Math.imul(He,ce),h=Math.imul(He,ze),h=h+Math.imul(Le,ce)|0,C=Math.imul(Le,ze),N=N+Math.imul(je,$e)|0,h=h+Math.imul(je,Xe)|0,h=h+Math.imul(Te,$e)|0,C=C+Math.imul(Te,Xe)|0,N=N+Math.imul(me,$t)|0,h=h+Math.imul(me,Zt)|0,h=h+Math.imul(ye,$t)|0,C=C+Math.imul(ye,Zt)|0,N=N+Math.imul(fe,tr)|0,h=h+Math.imul(fe,rr)|0,h=h+Math.imul(ie,tr)|0,C=C+Math.imul(ie,rr)|0,N=N+Math.imul(Q,kt)|0,h=h+Math.imul(Q,Lt)|0,h=h+Math.imul(le,kt)|0,C=C+Math.imul(le,Lt)|0,N=N+Math.imul(W,Qt)|0,h=h+Math.imul(W,Wt)|0,h=h+Math.imul(be,Qt)|0,C=C+Math.imul(be,Wt)|0,N=N+Math.imul(he,wt)|0,h=h+Math.imul(he,er)|0,h=h+Math.imul(q,wt)|0,C=C+Math.imul(q,er)|0;var Je=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Je>>>26)|0,Je&=67108863,N=Math.imul(rt,ce),h=Math.imul(rt,ze),h=h+Math.imul(et,ce)|0,C=Math.imul(et,ze),N=N+Math.imul(He,$e)|0,h=h+Math.imul(He,Xe)|0,h=h+Math.imul(Le,$e)|0,C=C+Math.imul(Le,Xe)|0,N=N+Math.imul(je,$t)|0,h=h+Math.imul(je,Zt)|0,h=h+Math.imul(Te,$t)|0,C=C+Math.imul(Te,Zt)|0,N=N+Math.imul(me,tr)|0,h=h+Math.imul(me,rr)|0,h=h+Math.imul(ye,tr)|0,C=C+Math.imul(ye,rr)|0,N=N+Math.imul(fe,kt)|0,h=h+Math.imul(fe,Lt)|0,h=h+Math.imul(ie,kt)|0,C=C+Math.imul(ie,Lt)|0,N=N+Math.imul(Q,Qt)|0,h=h+Math.imul(Q,Wt)|0,h=h+Math.imul(le,Qt)|0,C=C+Math.imul(le,Wt)|0,N=N+Math.imul(W,wt)|0,h=h+Math.imul(W,er)|0,h=h+Math.imul(be,wt)|0,C=C+Math.imul(be,er)|0,N=N+Math.imul(he,U)|0,h=h+Math.imul(he,O)|0,h=h+Math.imul(q,U)|0,C=C+Math.imul(q,O)|0;var Qe=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,N=Math.imul(B,ce),h=Math.imul(B,ze),h=h+Math.imul(m,ce)|0,C=Math.imul(m,ze),N=N+Math.imul(rt,$e)|0,h=h+Math.imul(rt,Xe)|0,h=h+Math.imul(et,$e)|0,C=C+Math.imul(et,Xe)|0,N=N+Math.imul(He,$t)|0,h=h+Math.imul(He,Zt)|0,h=h+Math.imul(Le,$t)|0,C=C+Math.imul(Le,Zt)|0,N=N+Math.imul(je,tr)|0,h=h+Math.imul(je,rr)|0,h=h+Math.imul(Te,tr)|0,C=C+Math.imul(Te,rr)|0,N=N+Math.imul(me,kt)|0,h=h+Math.imul(me,Lt)|0,h=h+Math.imul(ye,kt)|0,C=C+Math.imul(ye,Lt)|0,N=N+Math.imul(fe,Qt)|0,h=h+Math.imul(fe,Wt)|0,h=h+Math.imul(ie,Qt)|0,C=C+Math.imul(ie,Wt)|0,N=N+Math.imul(Q,wt)|0,h=h+Math.imul(Q,er)|0,h=h+Math.imul(le,wt)|0,C=C+Math.imul(le,er)|0,N=N+Math.imul(W,U)|0,h=h+Math.imul(W,O)|0,h=h+Math.imul(be,U)|0,C=C+Math.imul(be,O)|0,N=N+Math.imul(he,I)|0,h=h+Math.imul(he,Z)|0,h=h+Math.imul(q,I)|0,C=C+Math.imul(q,Z)|0;var Pe=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,N=Math.imul(H,ce),h=Math.imul(H,ze),h=h+Math.imul(X,ce)|0,C=Math.imul(X,ze),N=N+Math.imul(B,$e)|0,h=h+Math.imul(B,Xe)|0,h=h+Math.imul(m,$e)|0,C=C+Math.imul(m,Xe)|0,N=N+Math.imul(rt,$t)|0,h=h+Math.imul(rt,Zt)|0,h=h+Math.imul(et,$t)|0,C=C+Math.imul(et,Zt)|0,N=N+Math.imul(He,tr)|0,h=h+Math.imul(He,rr)|0,h=h+Math.imul(Le,tr)|0,C=C+Math.imul(Le,rr)|0,N=N+Math.imul(je,kt)|0,h=h+Math.imul(je,Lt)|0,h=h+Math.imul(Te,kt)|0,C=C+Math.imul(Te,Lt)|0,N=N+Math.imul(me,Qt)|0,h=h+Math.imul(me,Wt)|0,h=h+Math.imul(ye,Qt)|0,C=C+Math.imul(ye,Wt)|0,N=N+Math.imul(fe,wt)|0,h=h+Math.imul(fe,er)|0,h=h+Math.imul(ie,wt)|0,C=C+Math.imul(ie,er)|0,N=N+Math.imul(Q,U)|0,h=h+Math.imul(Q,O)|0,h=h+Math.imul(le,U)|0,C=C+Math.imul(le,O)|0,N=N+Math.imul(W,I)|0,h=h+Math.imul(W,Z)|0,h=h+Math.imul(be,I)|0,C=C+Math.imul(be,Z)|0,N=N+Math.imul(he,de)|0,h=h+Math.imul(he,we)|0,h=h+Math.imul(q,de)|0,C=C+Math.imul(q,we)|0;var Ye=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,N=Math.imul(H,$e),h=Math.imul(H,Xe),h=h+Math.imul(X,$e)|0,C=Math.imul(X,Xe),N=N+Math.imul(B,$t)|0,h=h+Math.imul(B,Zt)|0,h=h+Math.imul(m,$t)|0,C=C+Math.imul(m,Zt)|0,N=N+Math.imul(rt,tr)|0,h=h+Math.imul(rt,rr)|0,h=h+Math.imul(et,tr)|0,C=C+Math.imul(et,rr)|0,N=N+Math.imul(He,kt)|0,h=h+Math.imul(He,Lt)|0,h=h+Math.imul(Le,kt)|0,C=C+Math.imul(Le,Lt)|0,N=N+Math.imul(je,Qt)|0,h=h+Math.imul(je,Wt)|0,h=h+Math.imul(Te,Qt)|0,C=C+Math.imul(Te,Wt)|0,N=N+Math.imul(me,wt)|0,h=h+Math.imul(me,er)|0,h=h+Math.imul(ye,wt)|0,C=C+Math.imul(ye,er)|0,N=N+Math.imul(fe,U)|0,h=h+Math.imul(fe,O)|0,h=h+Math.imul(ie,U)|0,C=C+Math.imul(ie,O)|0,N=N+Math.imul(Q,I)|0,h=h+Math.imul(Q,Z)|0,h=h+Math.imul(le,I)|0,C=C+Math.imul(le,Z)|0,N=N+Math.imul(W,de)|0,h=h+Math.imul(W,we)|0,h=h+Math.imul(be,de)|0,C=C+Math.imul(be,we)|0;var Ge=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,N=Math.imul(H,$t),h=Math.imul(H,Zt),h=h+Math.imul(X,$t)|0,C=Math.imul(X,Zt),N=N+Math.imul(B,tr)|0,h=h+Math.imul(B,rr)|0,h=h+Math.imul(m,tr)|0,C=C+Math.imul(m,rr)|0,N=N+Math.imul(rt,kt)|0,h=h+Math.imul(rt,Lt)|0,h=h+Math.imul(et,kt)|0,C=C+Math.imul(et,Lt)|0,N=N+Math.imul(He,Qt)|0,h=h+Math.imul(He,Wt)|0,h=h+Math.imul(Le,Qt)|0,C=C+Math.imul(Le,Wt)|0,N=N+Math.imul(je,wt)|0,h=h+Math.imul(je,er)|0,h=h+Math.imul(Te,wt)|0,C=C+Math.imul(Te,er)|0,N=N+Math.imul(me,U)|0,h=h+Math.imul(me,O)|0,h=h+Math.imul(ye,U)|0,C=C+Math.imul(ye,O)|0,N=N+Math.imul(fe,I)|0,h=h+Math.imul(fe,Z)|0,h=h+Math.imul(ie,I)|0,C=C+Math.imul(ie,Z)|0,N=N+Math.imul(Q,de)|0,h=h+Math.imul(Q,we)|0,h=h+Math.imul(le,de)|0,C=C+Math.imul(le,we)|0;var Oe=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,N=Math.imul(H,tr),h=Math.imul(H,rr),h=h+Math.imul(X,tr)|0,C=Math.imul(X,rr),N=N+Math.imul(B,kt)|0,h=h+Math.imul(B,Lt)|0,h=h+Math.imul(m,kt)|0,C=C+Math.imul(m,Lt)|0,N=N+Math.imul(rt,Qt)|0,h=h+Math.imul(rt,Wt)|0,h=h+Math.imul(et,Qt)|0,C=C+Math.imul(et,Wt)|0,N=N+Math.imul(He,wt)|0,h=h+Math.imul(He,er)|0,h=h+Math.imul(Le,wt)|0,C=C+Math.imul(Le,er)|0,N=N+Math.imul(je,U)|0,h=h+Math.imul(je,O)|0,h=h+Math.imul(Te,U)|0,C=C+Math.imul(Te,O)|0,N=N+Math.imul(me,I)|0,h=h+Math.imul(me,Z)|0,h=h+Math.imul(ye,I)|0,C=C+Math.imul(ye,Z)|0,N=N+Math.imul(fe,de)|0,h=h+Math.imul(fe,we)|0,h=h+Math.imul(ie,de)|0,C=C+Math.imul(ie,we)|0;var De=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(De>>>26)|0,De&=67108863,N=Math.imul(H,kt),h=Math.imul(H,Lt),h=h+Math.imul(X,kt)|0,C=Math.imul(X,Lt),N=N+Math.imul(B,Qt)|0,h=h+Math.imul(B,Wt)|0,h=h+Math.imul(m,Qt)|0,C=C+Math.imul(m,Wt)|0,N=N+Math.imul(rt,wt)|0,h=h+Math.imul(rt,er)|0,h=h+Math.imul(et,wt)|0,C=C+Math.imul(et,er)|0,N=N+Math.imul(He,U)|0,h=h+Math.imul(He,O)|0,h=h+Math.imul(Le,U)|0,C=C+Math.imul(Le,O)|0,N=N+Math.imul(je,I)|0,h=h+Math.imul(je,Z)|0,h=h+Math.imul(Te,I)|0,C=C+Math.imul(Te,Z)|0,N=N+Math.imul(me,de)|0,h=h+Math.imul(me,we)|0,h=h+Math.imul(ye,de)|0,C=C+Math.imul(ye,we)|0;var Me=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Me>>>26)|0,Me&=67108863,N=Math.imul(H,Qt),h=Math.imul(H,Wt),h=h+Math.imul(X,Qt)|0,C=Math.imul(X,Wt),N=N+Math.imul(B,wt)|0,h=h+Math.imul(B,er)|0,h=h+Math.imul(m,wt)|0,C=C+Math.imul(m,er)|0,N=N+Math.imul(rt,U)|0,h=h+Math.imul(rt,O)|0,h=h+Math.imul(et,U)|0,C=C+Math.imul(et,O)|0,N=N+Math.imul(He,I)|0,h=h+Math.imul(He,Z)|0,h=h+Math.imul(Le,I)|0,C=C+Math.imul(Le,Z)|0,N=N+Math.imul(je,de)|0,h=h+Math.imul(je,we)|0,h=h+Math.imul(Te,de)|0,C=C+Math.imul(Te,we)|0;var Re=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Re>>>26)|0,Re&=67108863,N=Math.imul(H,wt),h=Math.imul(H,er),h=h+Math.imul(X,wt)|0,C=Math.imul(X,er),N=N+Math.imul(B,U)|0,h=h+Math.imul(B,O)|0,h=h+Math.imul(m,U)|0,C=C+Math.imul(m,O)|0,N=N+Math.imul(rt,I)|0,h=h+Math.imul(rt,Z)|0,h=h+Math.imul(et,I)|0,C=C+Math.imul(et,Z)|0,N=N+Math.imul(He,de)|0,h=h+Math.imul(He,we)|0,h=h+Math.imul(Le,de)|0,C=C+Math.imul(Le,we)|0;var Ue=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ue>>>26)|0,Ue&=67108863,N=Math.imul(H,U),h=Math.imul(H,O),h=h+Math.imul(X,U)|0,C=Math.imul(X,O),N=N+Math.imul(B,I)|0,h=h+Math.imul(B,Z)|0,h=h+Math.imul(m,I)|0,C=C+Math.imul(m,Z)|0,N=N+Math.imul(rt,de)|0,h=h+Math.imul(rt,we)|0,h=h+Math.imul(et,de)|0,C=C+Math.imul(et,we)|0;var Ae=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,N=Math.imul(H,I),h=Math.imul(H,Z),h=h+Math.imul(X,I)|0,C=Math.imul(X,Z),N=N+Math.imul(B,de)|0,h=h+Math.imul(B,we)|0,h=h+Math.imul(m,de)|0,C=C+Math.imul(m,we)|0;var se=(R+N|0)+((h&8191)<<13)|0;R=(C+(h>>>13)|0)+(se>>>26)|0,se&=67108863,N=Math.imul(H,de),h=Math.imul(H,we),h=h+Math.imul(X,de)|0,C=Math.imul(X,we);var oe=(R+N|0)+((h&8191)<<13)|0;return R=(C+(h>>>13)|0)+(oe>>>26)|0,oe&=67108863,j[0]=ke,j[1]=Ne,j[2]=ft,j[3]=Be,j[4]=Fe,j[5]=Ke,j[6]=Je,j[7]=Qe,j[8]=Pe,j[9]=Ye,j[10]=Ge,j[11]=Oe,j[12]=De,j[13]=Me,j[14]=Re,j[15]=Ue,j[16]=Ae,j[17]=se,j[18]=oe,R!==0&&(j[19]=R,_.length++),_};Math.imul||(z=M);function K(x,u,f){f.negative=u.negative^x.negative,f.length=x.length+u.length;for(var _=0,E=0,S=0;S>>26)|0,E+=j>>>26,j&=67108863}f.words[S]=R,_=j,j=E}return _!==0?f.words[S]=_:f.length--,f.strip()}function D(x,u,f){var _=new T;return _.mulp(x,u,f)}i.prototype.mulTo=function(u,f){var _,E=this.length+u.length;return this.length===10&&u.length===10?_=z(this,u,f):E<63?_=M(this,u,f):E<1024?_=K(this,u,f):_=D(this,u,f),_};function T(x,u){this.x=x,this.y=u}T.prototype.makeRBT=function(u){for(var f=new Array(u),_=i.prototype._countBits(u)-1,E=0;E>=1;return E},T.prototype.permute=function(u,f,_,E,S,j){for(var R=0;R>>1)S++;return 1<>>13,_[2*j+1]=S&8191,S=S>>>13;for(j=2*f;j>=26,f+=E/67108864|0,f+=S>>>26,this.words[_]=S&67108863}return f!==0&&(this.words[_]=f,this.length++),this.length=u===0?1:this.length,this},i.prototype.muln=function(u){return this.clone().imuln(u)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(u){var f=v(u);if(f.length===0)return new i(1);for(var _=this,E=0;E=0);var f=u%26,_=(u-f)/26,E=67108863>>>26-f<<26-f,S;if(f!==0){var j=0;for(S=0;S>>26-f}j&&(this.words[S]=j,this.length++)}if(_!==0){for(S=this.length-1;S>=0;S--)this.words[S+_]=this.words[S];for(S=0;S<_;S++)this.words[S]=0;this.length+=_}return this.strip()},i.prototype.ishln=function(u){return n(this.negative===0),this.iushln(u)},i.prototype.iushrn=function(u,f,_){n(typeof u=="number"&&u>=0);var E;f?E=(f-f%26)/26:E=0;var S=u%26,j=Math.min((u-S)/26,this.length),R=67108863^67108863>>>S<j)for(this.length-=j,h=0;h=0&&(C!==0||h>=E);h--){var ae=this.words[h]|0;this.words[h]=C<<26-S|ae>>>S,C=ae&R}return N&&C!==0&&(N.words[N.length++]=C),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(u,f,_){return n(this.negative===0),this.iushrn(u,f,_)},i.prototype.shln=function(u){return this.clone().ishln(u)},i.prototype.ushln=function(u){return this.clone().iushln(u)},i.prototype.shrn=function(u){return this.clone().ishrn(u)},i.prototype.ushrn=function(u){return this.clone().iushrn(u)},i.prototype.testn=function(u){n(typeof u=="number"&&u>=0);var f=u%26,_=(u-f)/26,E=1<=0);var f=u%26,_=(u-f)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=_)return this;if(f!==0&&_++,this.length=Math.min(_,this.length),f!==0){var E=67108863^67108863>>>f<=67108864;f++)this.words[f]-=67108864,f===this.length-1?this.words[f+1]=1:this.words[f+1]++;return this.length=Math.max(this.length,f+1),this},i.prototype.isubn=function(u){if(n(typeof u=="number"),n(u<67108864),u<0)return this.iaddn(-u);if(this.negative!==0)return this.negative=0,this.iaddn(u),this.negative=1,this;if(this.words[0]-=u,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var f=0;f>26)-(N/67108864|0),this.words[S+_]=j&67108863}for(;S>26,this.words[S+_]=j&67108863;if(R===0)return this.strip();for(n(R===-1),R=0,S=0;S>26,this.words[S]=j&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(u,f){var _=this.length-u.length,E=this.clone(),S=u,j=S.words[S.length-1]|0,R=this._countBits(j);_=26-R,_!==0&&(S=S.ushln(_),E.iushln(_),j=S.words[S.length-1]|0);var N=E.length-S.length,h;if(f!=="mod"){h=new i(null),h.length=N+1,h.words=new Array(h.length);for(var C=0;C=0;he--){var q=(E.words[S.length+he]|0)*67108864+(E.words[S.length+he-1]|0);for(q=Math.min(q/j|0,67108863),E._ishlnsubmul(S,q,he);E.negative!==0;)q--,E.negative=0,E._ishlnsubmul(S,1,he),E.isZero()||(E.negative^=1);h&&(h.words[he]=q)}return h&&h.strip(),E.strip(),f!=="div"&&_!==0&&E.iushrn(_),{div:h||null,mod:E}},i.prototype.divmod=function(u,f,_){if(n(!u.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var E,S,j;return this.negative!==0&&u.negative===0?(j=this.neg().divmod(u,f),f!=="mod"&&(E=j.div.neg()),f!=="div"&&(S=j.mod.neg(),_&&S.negative!==0&&S.iadd(u)),{div:E,mod:S}):this.negative===0&&u.negative!==0?(j=this.divmod(u.neg(),f),f!=="mod"&&(E=j.div.neg()),{div:E,mod:j.mod}):this.negative&u.negative?(j=this.neg().divmod(u.neg(),f),f!=="div"&&(S=j.mod.neg(),_&&S.negative!==0&&S.isub(u)),{div:j.div,mod:S}):u.length>this.length||this.cmp(u)<0?{div:new i(0),mod:this}:u.length===1?f==="div"?{div:this.divn(u.words[0]),mod:null}:f==="mod"?{div:null,mod:new i(this.modn(u.words[0]))}:{div:this.divn(u.words[0]),mod:new i(this.modn(u.words[0]))}:this._wordDiv(u,f)},i.prototype.div=function(u){return this.divmod(u,"div",!1).div},i.prototype.mod=function(u){return this.divmod(u,"mod",!1).mod},i.prototype.umod=function(u){return this.divmod(u,"mod",!0).mod},i.prototype.divRound=function(u){var f=this.divmod(u);if(f.mod.isZero())return f.div;var _=f.div.negative!==0?f.mod.isub(u):f.mod,E=u.ushrn(1),S=u.andln(1),j=_.cmp(E);return j<0||S===1&&j===0?f.div:f.div.negative!==0?f.div.isubn(1):f.div.iaddn(1)},i.prototype.modn=function(u){n(u<=67108863);for(var f=(1<<26)%u,_=0,E=this.length-1;E>=0;E--)_=(f*_+(this.words[E]|0))%u;return _},i.prototype.idivn=function(u){n(u<=67108863);for(var f=0,_=this.length-1;_>=0;_--){var E=(this.words[_]|0)+f*67108864;this.words[_]=E/u|0,f=E%u}return this.strip()},i.prototype.divn=function(u){return this.clone().idivn(u)},i.prototype.egcd=function(u){n(u.negative===0),n(!u.isZero());var f=this,_=u.clone();f.negative!==0?f=f.umod(u):f=f.clone();for(var E=new i(1),S=new i(0),j=new i(0),R=new i(1),N=0;f.isEven()&&_.isEven();)f.iushrn(1),_.iushrn(1),++N;for(var h=_.clone(),C=f.clone();!f.isZero();){for(var ae=0,he=1;!(f.words[0]&he)&&ae<26;++ae,he<<=1);if(ae>0)for(f.iushrn(ae);ae-- >0;)(E.isOdd()||S.isOdd())&&(E.iadd(h),S.isub(C)),E.iushrn(1),S.iushrn(1);for(var q=0,G=1;!(_.words[0]&G)&&q<26;++q,G<<=1);if(q>0)for(_.iushrn(q);q-- >0;)(j.isOdd()||R.isOdd())&&(j.iadd(h),R.isub(C)),j.iushrn(1),R.iushrn(1);f.cmp(_)>=0?(f.isub(_),E.isub(j),S.isub(R)):(_.isub(f),j.isub(E),R.isub(S))}return{a:j,b:R,gcd:_.iushln(N)}},i.prototype._invmp=function(u){n(u.negative===0),n(!u.isZero());var f=this,_=u.clone();f.negative!==0?f=f.umod(u):f=f.clone();for(var E=new i(1),S=new i(0),j=_.clone();f.cmpn(1)>0&&_.cmpn(1)>0;){for(var R=0,N=1;!(f.words[0]&N)&&R<26;++R,N<<=1);if(R>0)for(f.iushrn(R);R-- >0;)E.isOdd()&&E.iadd(j),E.iushrn(1);for(var h=0,C=1;!(_.words[0]&C)&&h<26;++h,C<<=1);if(h>0)for(_.iushrn(h);h-- >0;)S.isOdd()&&S.iadd(j),S.iushrn(1);f.cmp(_)>=0?(f.isub(_),E.isub(S)):(_.isub(f),S.isub(E))}var ae;return f.cmpn(1)===0?ae=E:ae=S,ae.cmpn(0)<0&&ae.iadd(u),ae},i.prototype.gcd=function(u){if(this.isZero())return u.abs();if(u.isZero())return this.abs();var f=this.clone(),_=u.clone();f.negative=0,_.negative=0;for(var E=0;f.isEven()&&_.isEven();E++)f.iushrn(1),_.iushrn(1);do{for(;f.isEven();)f.iushrn(1);for(;_.isEven();)_.iushrn(1);var S=f.cmp(_);if(S<0){var j=f;f=_,_=j}else if(S===0||_.cmpn(1)===0)break;f.isub(_)}while(!0);return _.iushln(E)},i.prototype.invm=function(u){return this.egcd(u).a.umod(u)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(u){return this.words[0]&u},i.prototype.bincn=function(u){n(typeof u=="number");var f=u%26,_=(u-f)/26,E=1<>>26,R&=67108863,this.words[j]=R}return S!==0&&(this.words[j]=S,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(u){var f=u<0;if(this.negative!==0&&!f)return-1;if(this.negative===0&&f)return 1;this.strip();var _;if(this.length>1)_=1;else{f&&(u=-u),n(u<=67108863,"Number is too big");var E=this.words[0]|0;_=E===u?0:Eu.length)return 1;if(this.length=0;_--){var E=this.words[_]|0,S=u.words[_]|0;if(E!==S){ES&&(f=1);break}}return f},i.prototype.gtn=function(u){return this.cmpn(u)===1},i.prototype.gt=function(u){return this.cmp(u)===1},i.prototype.gten=function(u){return this.cmpn(u)>=0},i.prototype.gte=function(u){return this.cmp(u)>=0},i.prototype.ltn=function(u){return this.cmpn(u)===-1},i.prototype.lt=function(u){return this.cmp(u)===-1},i.prototype.lten=function(u){return this.cmpn(u)<=0},i.prototype.lte=function(u){return this.cmp(u)<=0},i.prototype.eqn=function(u){return this.cmpn(u)===0},i.prototype.eq=function(u){return this.cmp(u)===0},i.red=function(u){return new Y(u)},i.prototype.toRed=function(u){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),u.convertTo(this)._forceRed(u)},i.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(u){return this.red=u,this},i.prototype.forceRed=function(u){return n(!this.red,"Already a number in reduction context"),this._forceRed(u)},i.prototype.redAdd=function(u){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,u)},i.prototype.redIAdd=function(u){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,u)},i.prototype.redSub=function(u){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,u)},i.prototype.redISub=function(u){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,u)},i.prototype.redShl=function(u){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,u)},i.prototype.redMul=function(u){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,u),this.red.mul(this,u)},i.prototype.redIMul=function(u){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,u),this.red.imul(this,u)},i.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(u){return n(this.red&&!u.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,u)};var k={k256:null,p224:null,p192:null,p25519:null};function L(x,u){this.name=x,this.p=new i(u,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}L.prototype._tmp=function(){var u=new i(null);return u.words=new Array(Math.ceil(this.n/13)),u},L.prototype.ireduce=function(u){var f=u,_;do this.split(f,this.tmp),f=this.imulK(f),f=f.iadd(this.tmp),_=f.bitLength();while(_>this.n);var E=_0?f.isub(this.p):f.strip!==void 0?f.strip():f._strip(),f},L.prototype.split=function(u,f){u.iushrn(this.n,0,f)},L.prototype.imulK=function(u){return u.imul(this.k)};function $(){L.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a($,L),$.prototype.split=function(u,f){for(var _=4194303,E=Math.min(u.length,9),S=0;S>>22,j=R}j>>>=22,u.words[S-10]=j,j===0&&u.length>10?u.length-=10:u.length-=9},$.prototype.imulK=function(u){u.words[u.length]=0,u.words[u.length+1]=0,u.length+=2;for(var f=0,_=0;_>>=26,u.words[_]=S,f=E}return f!==0&&(u.words[u.length++]=f),u},i._prime=function(u){if(k[u])return k[u];var f;if(u==="k256")f=new $;else if(u==="p224")f=new F;else if(u==="p192")f=new V;else if(u==="p25519")f=new J;else throw new Error("Unknown prime "+u);return k[u]=f,f};function Y(x){if(typeof x=="string"){var u=i._prime(x);this.m=u.p,this.prime=u}else n(x.gtn(1),"modulus must be greater than 1"),this.m=x,this.prime=null}Y.prototype._verify1=function(u){n(u.negative===0,"red works only with positives"),n(u.red,"red works only with red numbers")},Y.prototype._verify2=function(u,f){n((u.negative|f.negative)===0,"red works only with positives"),n(u.red&&u.red===f.red,"red works only with red numbers")},Y.prototype.imod=function(u){return this.prime?this.prime.ireduce(u)._forceRed(this):u.umod(this.m)._forceRed(this)},Y.prototype.neg=function(u){return u.isZero()?u.clone():this.m.sub(u)._forceRed(this)},Y.prototype.add=function(u,f){this._verify2(u,f);var _=u.add(f);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},Y.prototype.iadd=function(u,f){this._verify2(u,f);var _=u.iadd(f);return _.cmp(this.m)>=0&&_.isub(this.m),_},Y.prototype.sub=function(u,f){this._verify2(u,f);var _=u.sub(f);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},Y.prototype.isub=function(u,f){this._verify2(u,f);var _=u.isub(f);return _.cmpn(0)<0&&_.iadd(this.m),_},Y.prototype.shl=function(u,f){return this._verify1(u),this.imod(u.ushln(f))},Y.prototype.imul=function(u,f){return this._verify2(u,f),this.imod(u.imul(f))},Y.prototype.mul=function(u,f){return this._verify2(u,f),this.imod(u.mul(f))},Y.prototype.isqr=function(u){return this.imul(u,u.clone())},Y.prototype.sqr=function(u){return this.mul(u,u)},Y.prototype.sqrt=function(u){if(u.isZero())return u.clone();var f=this.m.andln(3);if(n(f%2===1),f===3){var _=this.m.add(new i(1)).iushrn(2);return this.pow(u,_)}for(var E=this.m.subn(1),S=0;!E.isZero()&&E.andln(1)===0;)S++,E.iushrn(1);n(!E.isZero());var j=new i(1).toRed(this),R=j.redNeg(),N=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new i(2*h*h).toRed(this);this.pow(h,N).cmp(R)!==0;)h.redIAdd(R);for(var C=this.pow(h,E),ae=this.pow(u,E.addn(1).iushrn(1)),he=this.pow(u,E),q=S;he.cmp(j)!==0;){for(var G=he,W=0;G.cmp(j)!==0;W++)G=G.redSqr();n(W=0;S--){for(var C=f.words[S],ae=h-1;ae>=0;ae--){var he=C>>ae&1;if(j!==E[0]&&(j=this.sqr(j)),he===0&&R===0){N=0;continue}R<<=1,R|=he,N++,!(N!==_&&(S!==0||ae!==0))&&(j=this.mul(j,E[R]),N=0,R=0)}h=26}return j},Y.prototype.convertTo=function(u){var f=u.umod(this.m);return f===u?f.clone():f},Y.prototype.convertFrom=function(u){var f=u.clone();return f.red=null,f},i.mont=function(u){return new ee(u)};function ee(x){Y.call(this,x),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}a(ee,Y),ee.prototype.convertTo=function(u){return this.imod(u.ushln(this.shift))},ee.prototype.convertFrom=function(u){var f=this.imod(u.mul(this.rinv));return f.red=null,f},ee.prototype.imul=function(u,f){if(u.isZero()||f.isZero())return u.words[0]=0,u.length=1,u;var _=u.imul(f),E=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=_.isub(E).iushrn(this.shift),j=S;return S.cmp(this.m)>=0?j=S.isub(this.m):S.cmpn(0)<0&&(j=S.iadd(this.m)),j._forceRed(this)},ee.prototype.mul=function(u,f){if(u.isZero()||f.isZero())return new i(0)._forceRed(this);var _=u.mul(f),E=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=_.isub(E).iushrn(this.shift),j=S;return S.cmp(this.m)>=0?j=S.isub(this.m):S.cmpn(0)<0&&(j=S.iadd(this.m)),j._forceRed(this)},ee.prototype.invm=function(u){var f=this.imod(u._invmp(this.m).mul(this.r2));return f._forceRed(this)}})(e,Ie)})(Q1);var ri=Q1.exports,qs=a6;function a6(e,t){if(!e)throw new Error(t||"Assertion failed")}a6.equal=function(t,r,n){if(t!=r)throw new Error(n||"Assertion failed: "+t+" != "+r)};var J1={};(function(e){var t=e;function r(i,s){if(Array.isArray(i))return i.slice();if(!i)return[];var o=[];if(typeof i!="string"){for(var c=0;c>8,y=d&255;p?o.push(p,y):o.push(y)}return o}t.toArray=r;function n(i){return i.length===1?"0"+i:i}t.zero2=n;function a(i){for(var s="",o=0;o(z>>1)-1?D=(z>>1)-T:D=T,K.isubn(D)):D=0,v[M]=D,K.iushrn(1)}return v}t.getNAF=i;function s(p,y){var g=[[],[]];p=p.clone(),y=y.clone();for(var v=0,M=0,z;p.cmpn(-v)>0||y.cmpn(-M)>0;){var K=p.andln(3)+v&3,D=y.andln(3)+M&3;K===3&&(K=-1),D===3&&(D=-1);var T;K&1?(z=p.andln(7)+v&7,(z===3||z===5)&&D===2?T=-K:T=K):T=0,g[0].push(T);var k;D&1?(z=y.andln(7)+M&7,(z===3||z===5)&&K===2?k=-D:k=D):k=0,g[1].push(k),2*v===T+1&&(v=1-v),2*M===k+1&&(M=1-M),p.iushrn(1),y.iushrn(1)}return g}t.getJSF=s;function o(p,y,g){var v="_"+y;p.prototype[y]=function(){return this[v]!==void 0?this[v]:this[v]=g.call(this)}}t.cachedProperty=o;function c(p){return typeof p=="string"?t.toArray(p,"hex"):p}t.parseBytes=c;function d(p){return new r(p,"hex","le")}t.intFromLE=d})(Bn);var W1={exports:{}},D0;W1.exports=function(t){return D0||(D0=new Si(null)),D0.generate(t)};function Si(e){this.rand=e}W1.exports.Rand=Si;Si.prototype.generate=function(t){return this._rand(t)};Si.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var r=new Uint8Array(t),n=0;n0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var xd=Zi;Zi.prototype.point=function(){throw new Error("Not implemented")};Zi.prototype.validate=function(){throw new Error("Not implemented")};Zi.prototype._fixedNafMul=function(t,r){Nf(t.precomputed);var n=t._getDoubles(),a=Af(r,1,this._bitLength),i=(1<=o;d--)c=(c<<1)+a[d];s.push(c)}for(var p=this.jpoint(null,null,null),y=this.jpoint(null,null,null),g=i;g>0;g--){for(o=0;o=0;c--){for(var d=0;c>=0&&s[c]===0;c--)d++;if(c>=0&&d++,o=o.dblp(d),c<0)break;var p=s[c];Nf(p!==0),t.type==="affine"?p>0?o=o.mixedAdd(i[p-1>>1]):o=o.mixedAdd(i[-p-1>>1].neg()):p>0?o=o.add(i[p-1>>1]):o=o.add(i[-p-1>>1].neg())}return t.type==="affine"?o.toP():o};Zi.prototype._wnafMulAdd=function(t,r,n,a,i){var s=this._wnafT1,o=this._wnafT2,c=this._wnafT3,d=0,p,y,g;for(p=0;p=1;p-=2){var M=p-1,z=p;if(s[M]!==1||s[z]!==1){c[M]=Af(n[M],s[M],this._bitLength),c[z]=Af(n[z],s[z],this._bitLength),d=Math.max(c[M].length,d),d=Math.max(c[z].length,d);continue}var K=[r[M],null,null,r[z]];r[M].y.cmp(r[z].y)===0?(K[1]=r[M].add(r[z]),K[2]=r[M].toJ().mixedAdd(r[z].neg())):r[M].y.cmp(r[z].y.redNeg())===0?(K[1]=r[M].toJ().mixedAdd(r[z]),K[2]=r[M].add(r[z].neg())):(K[1]=r[M].toJ().mixedAdd(r[z]),K[2]=r[M].toJ().mixedAdd(r[z].neg()));var D=[-3,-1,-5,-7,0,7,5,1,3],T=cN(n[M],n[z]);for(d=Math.max(T[0].length,d),c[M]=new Array(d),c[z]=new Array(d),y=0;y=0;p--){for(var V=0;p>=0;){var J=!0;for(y=0;y=0&&V++,$=$.dblp(V),p<0)break;for(y=0;y0?g=o[y][Y-1>>1]:Y<0&&(g=o[y][-Y-1>>1].neg()),g.type==="affine"?$=$.mixedAdd(g):$=$.add(g))}}for(p=0;p=Math.ceil((t.bitLength()+1)/r.step):!1};Xn.prototype._getDoubles=function(t,r){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var n=[this],a=this,i=0;i=0&&(v=d,M=p),y.negative&&(y=y.neg(),g=g.neg()),v.negative&&(v=v.neg(),M=M.neg()),[{a:y,b:g},{a:v,b:M}]};Zn.prototype._endoSplit=function(t){var r=this.endo.basis,n=r[0],a=r[1],i=a.b.mul(t).divRound(this.n),s=n.b.neg().mul(t).divRound(this.n),o=i.mul(n.a),c=s.mul(a.a),d=i.mul(n.b),p=s.mul(a.b),y=t.sub(o).sub(c),g=d.add(p).neg();return{k1:y,k2:g}};Zn.prototype.pointFromX=function(t,r){t=new lr(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),a=n.redSqrt();if(a.redSqr().redSub(n).cmp(this.zero)!==0)throw new Error("invalid point");var i=a.fromRed().isOdd();return(r&&!i||!r&&i)&&(a=a.redNeg()),this.point(t,a)};Zn.prototype.validate=function(t){if(t.inf)return!0;var r=t.x,n=t.y,a=this.a.redMul(r),i=r.redSqr().redMul(r).redIAdd(a).redIAdd(this.b);return n.redSqr().redISub(i).cmpn(0)===0};Zn.prototype._endoWnafMulAdd=function(t,r,n){for(var a=this._endoWnafT1,i=this._endoWnafT2,s=0;s":""};Or.prototype.isInfinity=function(){return this.inf};Or.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(this.x.cmp(t.x)===0)return this.curve.point(null,null);var r=this.y.redSub(t.y);r.cmpn(0)!==0&&(r=r.redMul(this.x.redSub(t.x).redInvm()));var n=r.redSqr().redISub(this.x).redISub(t.x),a=r.redMul(this.x.redSub(n)).redISub(this.y);return this.curve.point(n,a)};Or.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(t.cmpn(0)===0)return this.curve.point(null,null);var r=this.curve.a,n=this.x.redSqr(),a=t.redInvm(),i=n.redAdd(n).redIAdd(n).redIAdd(r).redMul(a),s=i.redSqr().redISub(this.x.redAdd(this.x)),o=i.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)};Or.prototype.getX=function(){return this.x.fromRed()};Or.prototype.getY=function(){return this.y.fromRed()};Or.prototype.mul=function(t){return t=new lr(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)};Or.prototype.mulAdd=function(t,r,n){var a=[this,r],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(a,i):this.curve._wnafMulAdd(1,a,i,2)};Or.prototype.jmulAdd=function(t,r,n){var a=[this,r],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(a,i,!0):this.curve._wnafMulAdd(1,a,i,2,!0)};Or.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||this.x.cmp(t.x)===0&&this.y.cmp(t.y)===0)};Or.prototype.neg=function(t){if(this.inf)return this;var r=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var n=this.precomputed,a=function(i){return i.neg()};r.precomputed={naf:n.naf&&{wnd:n.naf.wnd,points:n.naf.points.map(a)},doubles:n.doubles&&{step:n.doubles.step,points:n.doubles.points.map(a)}}}return r};Or.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);var t=this.curve.jpoint(this.x,this.y,this.curve.one);return t};function Lr(e,t,r,n){tl.BasePoint.call(this,e,"jacobian"),t===null&&r===null&&n===null?(this.x=this.curve.one,this.y=this.curve.one,this.z=new lr(0)):(this.x=new lr(t,16),this.y=new lr(r,16),this.z=new lr(n,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}tb(Lr,tl.BasePoint);Zn.prototype.jpoint=function(t,r,n){return new Lr(this,t,r,n)};Lr.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),r=t.redSqr(),n=this.x.redMul(r),a=this.y.redMul(r).redMul(t);return this.curve.point(n,a)};Lr.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};Lr.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var r=t.z.redSqr(),n=this.z.redSqr(),a=this.x.redMul(r),i=t.x.redMul(n),s=this.y.redMul(r.redMul(t.z)),o=t.y.redMul(n.redMul(this.z)),c=a.redSub(i),d=s.redSub(o);if(c.cmpn(0)===0)return d.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var p=c.redSqr(),y=p.redMul(c),g=a.redMul(p),v=d.redSqr().redIAdd(y).redISub(g).redISub(g),M=d.redMul(g.redISub(v)).redISub(s.redMul(y)),z=this.z.redMul(t.z).redMul(c);return this.curve.jpoint(v,M,z)};Lr.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var r=this.z.redSqr(),n=this.x,a=t.x.redMul(r),i=this.y,s=t.y.redMul(r).redMul(this.z),o=n.redSub(a),c=i.redSub(s);if(o.cmpn(0)===0)return c.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var d=o.redSqr(),p=d.redMul(o),y=n.redMul(d),g=c.redSqr().redIAdd(p).redISub(y).redISub(y),v=c.redMul(y.redISub(g)).redISub(i.redMul(p)),M=this.z.redMul(o);return this.curve.jpoint(g,v,M)};Lr.prototype.dblp=function(t){if(t===0)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var r;if(this.curve.zeroA||this.curve.threeA){var n=this;for(r=0;r=0)return!1;if(n.redIAdd(i),this.x.cmp(n)===0)return!0}};Lr.prototype.inspect=function(){return this.isInfinity()?"":""};Lr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};var fo=ri,s6=yd,gd=xd,hN=Bn;function rl(e){gd.call(this,"mont",e),this.a=new fo(e.a,16).toRed(this.red),this.b=new fo(e.b,16).toRed(this.red),this.i4=new fo(4).toRed(this.red).redInvm(),this.two=new fo(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}s6(rl,gd);var pN=rl;rl.prototype.validate=function(t){var r=t.normalize().x,n=r.redSqr(),a=n.redMul(r).redAdd(n.redMul(this.a)).redAdd(r),i=a.redSqrt();return i.redSqr().cmp(a)===0};function Cr(e,t,r){gd.BasePoint.call(this,e,"projective"),t===null&&r===null?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new fo(t,16),this.z=new fo(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}s6(Cr,gd.BasePoint);rl.prototype.decodePoint=function(t,r){return this.point(hN.toArray(t,r),1)};rl.prototype.point=function(t,r){return new Cr(this,t,r)};rl.prototype.pointFromJSON=function(t){return Cr.fromJSON(this,t)};Cr.prototype.precompute=function(){};Cr.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())};Cr.fromJSON=function(t,r){return new Cr(t,r[0],r[1]||t.one)};Cr.prototype.inspect=function(){return this.isInfinity()?"":""};Cr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};Cr.prototype.dbl=function(){var t=this.x.redAdd(this.z),r=t.redSqr(),n=this.x.redSub(this.z),a=n.redSqr(),i=r.redSub(a),s=r.redMul(a),o=i.redMul(a.redAdd(this.curve.a24.redMul(i)));return this.curve.point(s,o)};Cr.prototype.add=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.diffAdd=function(t,r){var n=this.x.redAdd(this.z),a=this.x.redSub(this.z),i=t.x.redAdd(t.z),s=t.x.redSub(t.z),o=s.redMul(n),c=i.redMul(a),d=r.z.redMul(o.redAdd(c).redSqr()),p=r.x.redMul(o.redISub(c).redSqr());return this.curve.point(d,p)};Cr.prototype.mul=function(t){for(var r=t.clone(),n=this,a=this.curve.point(null,null),i=this,s=[];r.cmpn(0)!==0;r.iushrn(1))s.push(r.andln(1));for(var o=s.length-1;o>=0;o--)s[o]===0?(n=n.diffAdd(a,i),a=a.dbl()):(a=n.diffAdd(a,i),n=n.dbl());return a};Cr.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")};Cr.prototype.eq=function(t){return this.getX().cmp(t.getX())===0};Cr.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this};Cr.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var bN=Bn,Ha=ri,o6=yd,vd=xd,mN=bN.assert;function ja(e){this.twisted=(e.a|0)!==1,this.mOneA=this.twisted&&(e.a|0)===-1,this.extended=this.mOneA,vd.call(this,"edwards",e),this.a=new Ha(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new Ha(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new Ha(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),mN(!this.twisted||this.c.fromRed().cmpn(1)===0),this.oneC=(e.c|0)===1}o6(ja,vd);var xN=ja;ja.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)};ja.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)};ja.prototype.jpoint=function(t,r,n,a){return this.point(t,r,n,a)};ja.prototype.pointFromX=function(t,r){t=new Ha(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr(),a=this.c2.redSub(this.a.redMul(n)),i=this.one.redSub(this.c2.redMul(this.d).redMul(n)),s=a.redMul(i.redInvm()),o=s.redSqrt();if(o.redSqr().redSub(s).cmp(this.zero)!==0)throw new Error("invalid point");var c=o.fromRed().isOdd();return(r&&!c||!r&&c)&&(o=o.redNeg()),this.point(t,o)};ja.prototype.pointFromY=function(t,r){t=new Ha(t,16),t.red||(t=t.toRed(this.red));var n=t.redSqr(),a=n.redSub(this.c2),i=n.redMul(this.d).redMul(this.c2).redSub(this.a),s=a.redMul(i.redInvm());if(s.cmp(this.zero)===0){if(r)throw new Error("invalid point");return this.point(this.zero,t)}var o=s.redSqrt();if(o.redSqr().redSub(s).cmp(this.zero)!==0)throw new Error("invalid point");return o.fromRed().isOdd()!==r&&(o=o.redNeg()),this.point(o,t)};ja.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var r=t.x.redSqr(),n=t.y.redSqr(),a=r.redMul(this.a).redAdd(n),i=this.c2.redMul(this.one.redAdd(this.d.redMul(r).redMul(n)));return a.cmp(i)===0};function Pt(e,t,r,n,a){vd.BasePoint.call(this,e,"projective"),t===null&&r===null&&n===null?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new Ha(t,16),this.y=new Ha(r,16),this.z=n?new Ha(n,16):this.curve.one,this.t=a&&new Ha(a,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}o6(Pt,vd.BasePoint);ja.prototype.pointFromJSON=function(t){return Pt.fromJSON(this,t)};ja.prototype.point=function(t,r,n,a){return new Pt(this,t,r,n,a)};Pt.fromJSON=function(t,r){return new Pt(t,r[0],r[1],r[2])};Pt.prototype.inspect=function(){return this.isInfinity()?"":""};Pt.prototype.isInfinity=function(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Pt.prototype._extDbl=function(){var t=this.x.redSqr(),r=this.y.redSqr(),n=this.z.redSqr();n=n.redIAdd(n);var a=this.curve._mulA(t),i=this.x.redAdd(this.y).redSqr().redISub(t).redISub(r),s=a.redAdd(r),o=s.redSub(n),c=a.redSub(r),d=i.redMul(o),p=s.redMul(c),y=i.redMul(c),g=o.redMul(s);return this.curve.point(d,p,g,y)};Pt.prototype._projDbl=function(){var t=this.x.redAdd(this.y).redSqr(),r=this.x.redSqr(),n=this.y.redSqr(),a,i,s,o,c,d;if(this.curve.twisted){o=this.curve._mulA(r);var p=o.redAdd(n);this.zOne?(a=t.redSub(r).redSub(n).redMul(p.redSub(this.curve.two)),i=p.redMul(o.redSub(n)),s=p.redSqr().redSub(p).redSub(p)):(c=this.z.redSqr(),d=p.redSub(c).redISub(c),a=t.redSub(r).redISub(n).redMul(d),i=p.redMul(o.redSub(n)),s=p.redMul(d))}else o=r.redAdd(n),c=this.curve._mulC(this.z).redSqr(),d=o.redSub(c).redSub(c),a=this.curve._mulC(t.redISub(o)).redMul(d),i=this.curve._mulC(o).redMul(r.redISub(n)),s=o.redMul(d);return this.curve.point(a,i,s)};Pt.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()};Pt.prototype._extAdd=function(t){var r=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),n=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),a=this.t.redMul(this.curve.dd).redMul(t.t),i=this.z.redMul(t.z.redAdd(t.z)),s=n.redSub(r),o=i.redSub(a),c=i.redAdd(a),d=n.redAdd(r),p=s.redMul(o),y=c.redMul(d),g=s.redMul(d),v=o.redMul(c);return this.curve.point(p,y,v,g)};Pt.prototype._projAdd=function(t){var r=this.z.redMul(t.z),n=r.redSqr(),a=this.x.redMul(t.x),i=this.y.redMul(t.y),s=this.curve.d.redMul(a).redMul(i),o=n.redSub(s),c=n.redAdd(s),d=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(a).redISub(i),p=r.redMul(o).redMul(d),y,g;return this.curve.twisted?(y=r.redMul(c).redMul(i.redSub(this.curve._mulA(a))),g=o.redMul(c)):(y=r.redMul(c).redMul(i.redSub(a)),g=this.curve._mulC(o).redMul(c)),this.curve.point(p,y,g)};Pt.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)};Pt.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)};Pt.prototype.mulAdd=function(t,r,n){return this.curve._wnafMulAdd(1,[this,r],[t,n],2,!1)};Pt.prototype.jmulAdd=function(t,r,n){return this.curve._wnafMulAdd(1,[this,r],[t,n],2,!0)};Pt.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this};Pt.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Pt.prototype.getX=function(){return this.normalize(),this.x.fromRed()};Pt.prototype.getY=function(){return this.normalize(),this.y.fromRed()};Pt.prototype.eq=function(t){return this===t||this.getX().cmp(t.getX())===0&&this.getY().cmp(t.getY())===0};Pt.prototype.eqXToP=function(t){var r=t.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(r)===0)return!0;for(var n=t.clone(),a=this.curve.redN.redMul(this.z);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(r.redIAdd(a),this.x.cmp(r)===0)return!0}};Pt.prototype.toP=Pt.prototype.normalize;Pt.prototype.mixedAdd=Pt.prototype.add;(function(e){var t=e;t.base=xd,t.short=dN,t.mont=pN,t.edwards=xN})(eb);var wd={},_d={},yt={},yN=qs,gN=yd;yt.inherits=gN;function vN(e,t){return(e.charCodeAt(t)&64512)!==55296||t<0||t+1>=e.length?!1:(e.charCodeAt(t+1)&64512)===56320}function wN(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var r=[];if(typeof e=="string")if(t){if(t==="hex")for(e=e.replace(/[^a-z0-9]+/ig,""),e.length%2!==0&&(e="0"+e),a=0;a>6|192,r[n++]=i&63|128):vN(e,a)?(i=65536+((i&1023)<<10)+(e.charCodeAt(++a)&1023),r[n++]=i>>18|240,r[n++]=i>>12&63|128,r[n++]=i>>6&63|128,r[n++]=i&63|128):(r[n++]=i>>12|224,r[n++]=i>>6&63|128,r[n++]=i&63|128)}else for(a=0;a>>24|e>>>8&65280|e<<8&16711680|(e&255)<<24;return t>>>0}yt.htonl=l6;function SN(e,t){for(var r="",n=0;n>>0}return i}yt.join32=EN;function AN(e,t){for(var r=new Array(e.length*4),n=0,a=0;n>>24,r[a+1]=i>>>16&255,r[a+2]=i>>>8&255,r[a+3]=i&255):(r[a+3]=i>>>24,r[a+2]=i>>>16&255,r[a+1]=i>>>8&255,r[a]=i&255)}return r}yt.split32=AN;function NN(e,t){return e>>>t|e<<32-t}yt.rotr32=NN;function jN(e,t){return e<>>32-t}yt.rotl32=jN;function TN(e,t){return e+t>>>0}yt.sum32=TN;function MN(e,t,r){return e+t+r>>>0}yt.sum32_3=MN;function CN(e,t,r,n){return e+t+r+n>>>0}yt.sum32_4=CN;function BN(e,t,r,n,a){return e+t+r+n+a>>>0}yt.sum32_5=BN;function ON(e,t,r,n){var a=e[t],i=e[t+1],s=n+i>>>0,o=(s>>0,e[t+1]=s}yt.sum64=ON;function RN(e,t,r,n){var a=t+n>>>0,i=(a>>0}yt.sum64_hi=RN;function UN(e,t,r,n){var a=t+n;return a>>>0}yt.sum64_lo=UN;function kN(e,t,r,n,a,i,s,o){var c=0,d=t;d=d+n>>>0,c+=d>>0,c+=d>>0,c+=d>>0}yt.sum64_4_hi=kN;function zN(e,t,r,n,a,i,s,o){var c=t+n+i+o;return c>>>0}yt.sum64_4_lo=zN;function DN(e,t,r,n,a,i,s,o,c,d){var p=0,y=t;y=y+n>>>0,p+=y>>0,p+=y>>0,p+=y>>0,p+=y>>0}yt.sum64_5_hi=DN;function IN(e,t,r,n,a,i,s,o,c,d){var p=t+n+i+o+d;return p>>>0}yt.sum64_5_lo=IN;function LN(e,t,r){var n=t<<32-r|e>>>r;return n>>>0}yt.rotr64_hi=LN;function HN(e,t,r){var n=e<<32-r|t>>>r;return n>>>0}yt.rotr64_lo=HN;function qN(e,t,r){return e>>>r}yt.shr64_hi=qN;function $N(e,t,r){var n=e<<32-r|t>>>r;return n>>>0}yt.shr64_lo=$N;var nl={},_x=yt,FN=qs;function Sd(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}nl.BlockHash=Sd;Sd.prototype.update=function(t,r){if(t=_x.toArray(t,r),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){t=this.pending;var n=t.length%this._delta8;this.pending=t.slice(t.length-n,t.length),this.pending.length===0&&(this.pending=null),t=_x.join32(t,0,t.length-n,this.endian);for(var a=0;a>>24&255,a[i++]=t>>>16&255,a[i++]=t>>>8&255,a[i++]=t&255}else for(a[i++]=t&255,a[i++]=t>>>8&255,a[i++]=t>>>16&255,a[i++]=t>>>24&255,a[i++]=0,a[i++]=0,a[i++]=0,a[i++]=0,s=8;s>>3}Ta.g0_256=VN;function XN(e){return ba(e,17)^ba(e,19)^e>>>10}Ta.g1_256=XN;var zo=yt,ZN=nl,QN=Ta,I0=zo.rotl32,gl=zo.sum32,JN=zo.sum32_5,WN=QN.ft_1,p6=ZN.BlockHash,ej=[1518500249,1859775393,2400959708,3395469782];function wa(){if(!(this instanceof wa))return new wa;p6.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}zo.inherits(wa,p6);var tj=wa;wa.blockSize=512;wa.outSize=160;wa.hmacStrength=80;wa.padLength=64;wa.prototype._update=function(t,r){for(var n=this.W,a=0;a<16;a++)n[a]=t[r+a];for(;athis.blockSize&&(t=new this.Hash().update(t).digest()),$j(t.length<=this.blockSize);for(var r=t.length;r=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,r,n)}var Gj=Fi;Fi.prototype._init=function(t,r,n){var a=t.concat(r).concat(n);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(n||[])),this._reseed=1};Fi.prototype.generate=function(t,r,n,a){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");typeof r!="string"&&(a=n,n=r,r=null),n&&(n=ys.toArray(n,a||"hex"),this._update(n));for(var i=[];i.length"};var jf=ri,rb=Bn,Zj=rb.assert;function Ed(e,t){if(e instanceof Ed)return e;this._importDER(e,t)||(Zj(e.r&&e.s,"Signature without r or s"),this.r=new jf(e.r,16),this.s=new jf(e.s,16),e.recoveryParam===void 0?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}var Qj=Ed;function Jj(){this.place=0}function $0(e,t){var r=e[t.place++];if(!(r&128))return r;var n=r&15;if(n===0||n>4||e[t.place]===0)return!1;for(var a=0,i=0,s=t.place;i>>=0;return a<=127?!1:(t.place=s,a)}function jx(e){for(var t=0,r=e.length-1;!e[t]&&!(e[t+1]&128)&&t>>3);for(e.push(r|128);--r;)e.push(t>>>(r<<3)&255);e.push(t)}Ed.prototype.toDER=function(t){var r=this.r.toArray(),n=this.s.toArray();for(r[0]&128&&(r=[0].concat(r)),n[0]&128&&(n=[0].concat(n)),r=jx(r),n=jx(n);!n[0]&&!(n[1]&128);)n=n.slice(1);var a=[2];F0(a,r.length),a=a.concat(r),a.push(2),F0(a,n.length);var i=a.concat(n),s=[48];return F0(s,i.length),s=s.concat(i),rb.encode(s,t)};var na=ri,N6=Gj,Wj=Bn,K0=wd,eT=i6,os=Wj.assert,nb=Xj,Ad=Qj;function Vn(e){if(!(this instanceof Vn))return new Vn(e);typeof e=="string"&&(os(Object.prototype.hasOwnProperty.call(K0,e),"Unknown curve "+e),e=K0[e]),e instanceof K0.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash}var tT=Vn;Vn.prototype.keyPair=function(t){return new nb(this,t)};Vn.prototype.keyFromPrivate=function(t,r){return nb.fromPrivate(this,t,r)};Vn.prototype.keyFromPublic=function(t,r){return nb.fromPublic(this,t,r)};Vn.prototype.genKeyPair=function(t){t||(t={});for(var r=new N6({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||eT(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),n=this.n.byteLength(),a=this.n.sub(new na(2));;){var i=new na(r.generate(n));if(!(i.cmp(a)>0))return i.iaddn(1),this.keyFromPrivate(i)}};Vn.prototype._truncateToN=function(t,r,n){var a;if(na.isBN(t)||typeof t=="number")t=new na(t,16),a=t.byteLength();else if(typeof t=="object")a=t.length,t=new na(t,16);else{var i=t.toString();a=i.length+1>>>1,t=new na(i,16)}typeof n!="number"&&(n=a*8);var s=n-this.n.bitLength();return s>0&&(t=t.ushrn(s)),!r&&t.cmp(this.n)>=0?t.sub(this.n):t};Vn.prototype.sign=function(t,r,n,a){if(typeof n=="object"&&(a=n,n=null),a||(a={}),typeof t!="string"&&typeof t!="number"&&!na.isBN(t)){os(typeof t=="object"&&t&&typeof t.length=="number","Expected message to be an array-like, a hex string, or a BN instance"),os(t.length>>>0===t.length);for(var i=0;i=0)){var v=this.g.mul(g);if(!v.isInfinity()){var M=v.getX(),z=M.umod(this.n);if(z.cmpn(0)!==0){var K=g.invm(this.n).mul(z.mul(r.getPrivate()).iadd(t));if(K=K.umod(this.n),K.cmpn(0)!==0){var D=(v.getY().isOdd()?1:0)|(M.cmp(z)!==0?2:0);return a.canonical&&K.cmp(this.nh)>0&&(K=this.n.sub(K),D^=1),new Ad({r:z,s:K,recoveryParam:D})}}}}}};Vn.prototype.verify=function(t,r,n,a,i){i||(i={}),t=this._truncateToN(t,!1,i.msgBitLength),n=this.keyFromPublic(n,a),r=new Ad(r,"hex");var s=r.r,o=r.s;if(s.cmpn(1)<0||s.cmp(this.n)>=0||o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;var c=o.invm(this.n),d=c.mul(t).umod(this.n),p=c.mul(s).umod(this.n),y;return this.curve._maxwellTrick?(y=this.g.jmulAdd(d,n.getPublic(),p),y.isInfinity()?!1:y.eqXToP(s)):(y=this.g.mulAdd(d,n.getPublic(),p),y.isInfinity()?!1:y.getX().umod(this.n).cmp(s)===0)};Vn.prototype.recoverPubKey=function(e,t,r,n){os((3&r)===r,"The recovery param is more than two bits"),t=new Ad(t,n);var a=this.n,i=new na(e),s=t.r,o=t.s,c=r&1,d=r>>1;if(s.cmp(this.curve.p.umod(this.curve.n))>=0&&d)throw new Error("Unable to find sencond key candinate");d?s=this.curve.pointFromX(s.add(this.curve.n),c):s=this.curve.pointFromX(s,c);var p=t.r.invm(a),y=a.sub(i).mul(p).umod(a),g=o.mul(p).umod(a);return this.g.mulAdd(y,s,g)};Vn.prototype.getKeyRecoveryParam=function(e,t,r,n){if(t=new Ad(t,n),t.recoveryParam!==null)return t.recoveryParam;for(var a=0;a<4;a++){var i;try{i=this.recoverPubKey(e,t,a)}catch{continue}if(i.eq(r))return a}throw new Error("Unable to find valid recovery factor")};var $c=Bn,j6=$c.assert,Tx=$c.parseBytes,sl=$c.cachedProperty;function Mr(e,t){this.eddsa=e,this._secret=Tx(t.secret),e.isPoint(t.pub)?this._pub=t.pub:this._pubBytes=Tx(t.pub)}Mr.fromPublic=function(t,r){return r instanceof Mr?r:new Mr(t,{pub:r})};Mr.fromSecret=function(t,r){return r instanceof Mr?r:new Mr(t,{secret:r})};Mr.prototype.secret=function(){return this._secret};sl(Mr,"pubBytes",function(){return this.eddsa.encodePoint(this.pub())});sl(Mr,"pub",function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())});sl(Mr,"privBytes",function(){var t=this.eddsa,r=this.hash(),n=t.encodingLength-1,a=r.slice(0,t.encodingLength);return a[0]&=248,a[n]&=127,a[n]|=64,a});sl(Mr,"priv",function(){return this.eddsa.decodeInt(this.privBytes())});sl(Mr,"hash",function(){return this.eddsa.hash().update(this.secret()).digest()});sl(Mr,"messagePrefix",function(){return this.hash().slice(this.eddsa.encodingLength)});Mr.prototype.sign=function(t){return j6(this._secret,"KeyPair can only verify"),this.eddsa.sign(t,this)};Mr.prototype.verify=function(t,r){return this.eddsa.verify(t,r,this)};Mr.prototype.getSecret=function(t){return j6(this._secret,"KeyPair is public only"),$c.encode(this.secret(),t)};Mr.prototype.getPublic=function(t){return $c.encode(this.pubBytes(),t)};var rT=Mr,nT=ri,Nd=Bn,Mx=Nd.assert,jd=Nd.cachedProperty,aT=Nd.parseBytes;function $s(e,t){this.eddsa=e,typeof t!="object"&&(t=aT(t)),Array.isArray(t)&&(Mx(t.length===e.encodingLength*2,"Signature has invalid size"),t={R:t.slice(0,e.encodingLength),S:t.slice(e.encodingLength)}),Mx(t.R&&t.S,"Signature without R or S"),e.isPoint(t.R)&&(this._R=t.R),t.S instanceof nT&&(this._S=t.S),this._Rencoded=Array.isArray(t.R)?t.R:t.Rencoded,this._Sencoded=Array.isArray(t.S)?t.S:t.Sencoded}jd($s,"S",function(){return this.eddsa.decodeInt(this.Sencoded())});jd($s,"R",function(){return this.eddsa.decodePoint(this.Rencoded())});jd($s,"Rencoded",function(){return this.eddsa.encodePoint(this.R())});jd($s,"Sencoded",function(){return this.eddsa.encodeInt(this.S())});$s.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())};$s.prototype.toHex=function(){return Nd.encode(this.toBytes(),"hex").toUpperCase()};var iT=$s,sT=_d,oT=wd,Lo=Bn,lT=Lo.assert,T6=Lo.parseBytes,M6=rT,Cx=iT;function pn(e){if(lT(e==="ed25519","only tested with ed25519 so far"),!(this instanceof pn))return new pn(e);e=oT[e].curve,this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=sT.sha512}var cT=pn;pn.prototype.sign=function(t,r){t=T6(t);var n=this.keyFromSecret(r),a=this.hashInt(n.messagePrefix(),t),i=this.g.mul(a),s=this.encodePoint(i),o=this.hashInt(s,n.pubBytes(),t).mul(n.priv()),c=a.add(o).umod(this.curve.n);return this.makeSignature({R:i,S:c,Rencoded:s})};pn.prototype.verify=function(t,r,n){if(t=T6(t),r=this.makeSignature(r),r.S().gte(r.eddsa.curve.n)||r.S().isNeg())return!1;var a=this.keyFromPublic(n),i=this.hashInt(r.Rencoded(),a.pubBytes(),t),s=this.g.mul(r.S()),o=r.R().add(a.pub().mul(i));return o.eq(s)};pn.prototype.hashInt=function(){for(var t=this.hash(),r=0;r=0)return null;r=r.toRed(bt.red);let n=r.redSqr().redIMul(r).redIAdd(bt.b).redSqrt();e===3!==n.isOdd()&&(n=n.redNeg());const a=r.redSqr().redIMul(r);return n.redSqr().redISub(a.redIAdd(bt.b)).isZero()?oa.keyPair({pub:{x:r,y:n}}):null}function dT(e,t,r){let n=new Ht(t),a=new Ht(r);if(n.cmp(bt.p)>=0||a.cmp(bt.p)>=0||(n=n.toRed(bt.red),a=a.toRed(bt.red),(e===6||e===7)&&a.isOdd()!==(e===7)))return null;const i=n.redSqr().redIMul(n);return a.redSqr().redISub(i.redIAdd(bt.b)).isZero()?oa.keyPair({pub:{x:n,y:a}}):null}function oi(e){const t=e[0];switch(t){case 2:case 3:return e.length!==33?null:fT(t,e.subarray(1,33));case 4:case 6:case 7:return e.length!==65?null:dT(t,e.subarray(1,33),e.subarray(33,65));default:return null}}function rs(e,t){const r=t.encode(null,e.length===33);for(let n=0;n=0||(r.iadd(new Ht(e)),r.cmp(bt.n)>=0&&r.isub(bt.n),r.isZero()))return 1;const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},privateKeyTweakMul(e,t){let r=new Ht(t);if(r.cmp(bt.n)>=0||r.isZero())return 1;r.imul(new Ht(e)),r.cmp(bt.n)>=0&&(r=r.umod(bt.n));const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},publicKeyVerify(e){return oi(e)===null?1:0},publicKeyCreate(e,t){const r=new Ht(t);if(r.cmp(bt.n)>=0||r.isZero())return 1;const n=oa.keyFromPrivate(t).getPublic();return rs(e,n),0},publicKeyConvert(e,t){const r=oi(t);if(r===null)return 1;const n=r.getPublic();return rs(e,n),0},publicKeyNegate(e,t){const r=oi(t);if(r===null)return 1;const n=r.getPublic();return n.y=n.y.redNeg(),rs(e,n),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let a=0;a=0)return 2;const a=n.getPublic().add(bt.g.mul(r));return a.isInfinity()?2:(rs(e,a),0)},publicKeyTweakMul(e,t,r){const n=oi(t);if(n===null)return 1;if(r=new Ht(r),r.cmp(bt.n)>=0||r.isZero())return 2;const a=n.getPublic().mul(r);return rs(e,a),0},signatureNormalize(e){const t=new Ht(e.subarray(0,32)),r=new Ht(e.subarray(32,64));return t.cmp(bt.n)>=0||r.cmp(bt.n)>=0?1:(r.cmp(oa.nh)===1&&e.set(bt.n.sub(r).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,t){const r=t.subarray(0,32),n=t.subarray(32,64);if(new Ht(r).cmp(bt.n)>=0||new Ht(n).cmp(bt.n)>=0)return 1;const{output:a}=e;let i=a.subarray(4,37);i[0]=0,i.set(r,1);let s=33,o=0;for(;s>1&&i[o]===0&&!(i[o+1]&128);--s,++o);if(i=i.subarray(o),i[0]&128||s>1&&i[0]===0&&!(i[1]&128))return 1;let c=a.subarray(39,72);c[0]=0,c.set(n,1);let d=33,p=0;for(;d>1&&c[p]===0&&!(c[p+1]&128);--d,++p);return c=c.subarray(p),c[0]&128||d>1&&c[0]===0&&!(c[1]&128)?1:(e.outputlen=6+s+d,a[0]=48,a[1]=e.outputlen-2,a[2]=2,a[3]=i.length,a.set(i,4),a[4+s]=2,a[5+s]=c.length,a.set(c,6+s),0)},signatureImport(e,t){if(t.length<8||t.length>72||t[0]!==48||t[1]!==t.length-2||t[2]!==2)return 1;const r=t[3];if(r===0||5+r>=t.length||t[4+r]!==2)return 1;const n=t[5+r];if(n===0||6+r+n!==t.length||t[4]&128||r>1&&t[4]===0&&!(t[5]&128)||t[r+6]&128||n>1&&t[r+6]===0&&!(t[r+7]&128))return 1;let a=t.subarray(4,4+r);if(a.length===33&&a[0]===0&&(a=a.subarray(1)),a.length>32)return 1;let i=t.subarray(6+r);if(i.length===33&&i[0]===0&&(i=i.slice(1)),i.length>32)throw new Error("S length is too long");let s=new Ht(a);s.cmp(bt.n)>=0&&(s=new Ht(0));let o=new Ht(t.subarray(6+r));return o.cmp(bt.n)>=0&&(o=new Ht(0)),e.set(s.toArrayLike(Uint8Array,"be",32),0),e.set(o.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(e,t,r,n,a){if(a){const o=a;a=c=>{const d=o(t,r,null,n,c);if(!(d instanceof Uint8Array&&d.length===32))throw new Error("This is the way");return new Ht(d)}}const i=new Ht(r);if(i.cmp(bt.n)>=0||i.isZero())return 1;let s;try{s=oa.sign(t,r,{canonical:!0,k:a,pers:n})}catch{return 1}return e.signature.set(s.r.toArrayLike(Uint8Array,"be",32),0),e.signature.set(s.s.toArrayLike(Uint8Array,"be",32),32),e.recid=s.recoveryParam,0},ecdsaVerify(e,t,r){const n={r:e.subarray(0,32),s:e.subarray(32,64)},a=new Ht(n.r),i=new Ht(n.s);if(a.cmp(bt.n)>=0||i.cmp(bt.n)>=0)return 1;if(i.cmp(oa.nh)===1||a.isZero()||i.isZero())return 3;const s=oi(r);if(s===null)return 2;const o=s.getPublic();return oa.verify(t,n,o)?0:3},ecdsaRecover(e,t,r,n){const a={r:t.slice(0,32),s:t.slice(32,64)},i=new Ht(a.r),s=new Ht(a.s);if(i.cmp(bt.n)>=0||s.cmp(bt.n)>=0)return 1;if(i.isZero()||s.isZero())return 2;let o;try{o=oa.recoverPubKey(n,a,r)}catch{return 2}return rs(e,o),0},ecdh(e,t,r,n,a,i,s){const o=oi(t);if(o===null)return 1;const c=new Ht(r);if(c.cmp(bt.n)>=0||c.isZero())return 2;const d=o.getPublic().mul(c);if(a===void 0){const p=d.encode(null,!0),y=oa.hash().update(p).digest();for(let g=0;g<32;++g)e[g]=y[g]}else{i||(i=new Uint8Array(32));const p=d.getX().toArray("be",32);for(let M=0;M<32;++M)i[M]=p[M];s||(s=new Uint8Array(32));const y=d.getY().toArray("be",32);for(let M=0;M<32;++M)s[M]=y[M];const g=a(i,s,n);if(!(g instanceof Uint8Array&&g.length===e.length))return 2;e.set(g)}return 0}},C6=sN(hT),pT=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(el,"__esModule",{value:!0});el.PublicKey=void 0;const Bx=Wo,bT=$1,mT=pT(C6),ln=Ja;function xT(e){switch(e){case ln.KeyType.ED25519:return"ed25519";case ln.KeyType.SECP256K1:return"secp256k1";default:throw new Error(`Unknown key type ${e}`)}}function yT(e){switch(e.toLowerCase()){case"ed25519":return ln.KeyType.ED25519;case"secp256k1":return ln.KeyType.SECP256K1;default:throw new Error(`Unknown key type ${e}`)}}function gT(e){switch(e){case ln.KeyType.ED25519:return"ed25519Key";case ln.KeyType.SECP256K1:return"secp256k1Key";default:throw Error(`unknown type ${e}`)}}class vT{constructor(t){if(Object.keys(t).length!==1)throw new Error("Enum can only take single value");Object.keys(t).map(r=>{this[r]=t[r]})}}class Tf extends vT{constructor(r){const n=gT(r.keyType);super({[n]:r});Bt(this,"enum");Bt(this,"ed25519Key");Bt(this,"secp256k1Key");this[n]=r,this.enum=n}static from(r){return typeof r=="string"?Tf.fromString(r):r}static fromString(r){const n=r.split(":");let a,i;if(n.length===1)a=n[0];else if(n.length===2)a=n[1],i=yT(n[0]);else throw new Error("Invalid encoded key format, must be :");const s=(0,Bx.baseDecode)(a);i||(i=s.length===ln.KeySize.SECP256k1_PUBLIC_KEY?ln.KeyType.SECP256K1:ln.KeyType.ED25519);const o=i===ln.KeyType.ED25519?ln.KeySize.ED25519_PUBLIC_KEY:ln.KeySize.SECP256k1_PUBLIC_KEY;if(s.length!==o)throw new Error(`Invalid public key size (${s.length}), must be ${o}`);return new Tf({keyType:i,data:s})}toString(){const r=(0,Bx.baseEncode)(this.data);return`${xT(this.keyType)}:${r}`}verify(r,n){const a=this.keyType,i=this.data;switch(a){case ln.KeyType.ED25519:return bT.ed25519.verify(n,r,i);case ln.KeyType.SECP256K1:return mT.default.ecdsaVerify(n.subarray(0,64),r,new Uint8Array([4,...i]));default:throw new Error(`Unknown key type: ${a}`)}}get keyPair(){return this.ed25519Key||this.secp256k1Key}get keyType(){return this.keyPair.keyType}get data(){return this.keyPair.data}}el.PublicKey=Tf;var wT=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(zc,"__esModule",{value:!0});zc.KeyPairEd25519=void 0;const mu=Wo,P0=$1,_T=wT(r6),G0=Ja,ST=Jo,ET=el;class ab extends ST.KeyPairBase{constructor(r){super();Bt(this,"publicKey");Bt(this,"secretKey");Bt(this,"extendedSecretKey");const n=(0,mu.baseDecode)(r),a=new Uint8Array(n.slice(0,G0.KeySize.SECRET_KEY)),i=P0.ed25519.getPublicKey(new Uint8Array(a));this.publicKey=new ET.PublicKey({keyType:G0.KeyType.ED25519,data:i}),this.secretKey=(0,mu.baseEncode)(a),this.extendedSecretKey=r}static fromRandom(){const r=(0,_T.default)(G0.KeySize.SECRET_KEY),n=P0.ed25519.getPublicKey(new Uint8Array(r)),a=new Uint8Array([...r,...n]);return new ab((0,mu.baseEncode)(a))}sign(r){return{signature:P0.ed25519.sign(r,(0,mu.baseDecode)(this.secretKey)),publicKey:this.publicKey}}verify(r,n){return this.publicKey.verify(r,n)}toString(){return`ed25519:${this.extendedSecretKey}`}getPublicKey(){return this.publicKey}}zc.KeyPairEd25519=ab;var Fc={},B6=Ie&&Ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Fc,"__esModule",{value:!0});Fc.KeyPairSecp256k1=void 0;const xu=Wo,AT=B6(r6),Y0=B6(C6),V0=Ja,NT=Jo,jT=el;class ib extends NT.KeyPairBase{constructor(r){super();Bt(this,"publicKey");Bt(this,"secretKey");Bt(this,"extendedSecretKey");const n=(0,xu.baseDecode)(r),a=new Uint8Array(n.slice(0,V0.KeySize.SECRET_KEY)),i=Y0.default.publicKeyCreate(new Uint8Array(a),!1),s=i.subarray(1,i.length);this.publicKey=new jT.PublicKey({keyType:V0.KeyType.SECP256K1,data:s}),this.secretKey=(0,xu.baseEncode)(a),this.extendedSecretKey=r}static fromRandom(){const r=(0,AT.default)(V0.KeySize.SECRET_KEY),n=Y0.default.publicKeyCreate(new Uint8Array(r),!1),a=n.subarray(1,n.length),i=new Uint8Array([...r,...a]);return new ib((0,xu.baseEncode)(i))}sign(r){const{signature:n,recid:a}=Y0.default.ecdsaSign(r,(0,xu.baseDecode)(this.secretKey));return{signature:new Uint8Array([...n,a]),publicKey:this.publicKey}}verify(r,n){return this.publicKey.verify(r,n)}toString(){return`secp256k1:${this.extendedSecretKey}`}getPublicKey(){return this.publicKey}}Fc.KeyPairSecp256k1=ib;Object.defineProperty(rd,"__esModule",{value:!0});rd.KeyPair=void 0;const TT=Jo,Ox=zc,Rx=Fc;class MT extends TT.KeyPairBase{static fromRandom(t){switch(t.toUpperCase()){case"ED25519":return Ox.KeyPairEd25519.fromRandom();case"SECP256K1":return Rx.KeyPairSecp256k1.fromRandom();default:throw new Error(`Unknown curve ${t}`)}}static fromString(t){const r=t.split(":");if(r.length===2)switch(r[0].toUpperCase()){case"ED25519":return new Ox.KeyPairEd25519(r[1]);case"SECP256K1":return new Rx.KeyPairSecp256k1(r[1]);default:throw new Error(`Unknown curve: ${r[0]}`)}else throw new Error("Invalid encoded key format, must be :")}}rd.KeyPair=MT;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.PublicKey=e.KeyPairSecp256k1=e.KeyPairEd25519=e.KeyPair=e.KeyType=void 0;var t=Ja;Object.defineProperty(e,"KeyType",{enumerable:!0,get:function(){return t.KeyType}});var r=rd;Object.defineProperty(e,"KeyPair",{enumerable:!0,get:function(){return r.KeyPair}});var n=zc;Object.defineProperty(e,"KeyPairEd25519",{enumerable:!0,get:function(){return n.KeyPairEd25519}});var a=Fc;Object.defineProperty(e,"KeyPairSecp256k1",{enumerable:!0,get:function(){return a.KeyPairSecp256k1}});var i=el;Object.defineProperty(e,"PublicKey",{enumerable:!0,get:function(){return i.PublicKey}})})(r3);(function(e){var t=Ie&&Ie.__createBinding||(Object.create?function(p,y,g,v){v===void 0&&(v=g);var M=Object.getOwnPropertyDescriptor(y,g);(!M||("get"in M?!y.__esModule:M.writable||M.configurable))&&(M={enumerable:!0,get:function(){return y[g]}}),Object.defineProperty(p,v,M)}:function(p,y,g,v){v===void 0&&(v=g),p[v]=y[g]}),r=Ie&&Ie.__setModuleDefault||(Object.create?function(p,y){Object.defineProperty(p,"default",{enumerable:!0,value:y})}:function(p,y){p.default=y}),n=Ie&&Ie.__importStar||function(p){if(p&&p.__esModule)return p;var y={};if(p!=null)for(var g in p)g!=="default"&&Object.prototype.hasOwnProperty.call(p,g)&&t(y,p,g);return r(y,p),y},a=Ie&&Ie.__importDefault||function(p){return p&&p.__esModule?p:{default:p}};Object.defineProperty(e,"__esModule",{value:!0}),e.authPayloadSchema=e.AuthPayload=void 0,e.verifySignature=d;const i=n(Oo),s=a(Q7),o=r3;class c{constructor({message:y,nonce:g,recipient:v}){Bt(this,"message");Bt(this,"recipient");Bt(this,"nonce");Bt(this,"callbackUrl");Bt(this,"tag");this.tag=2147484061,this.message=y,this.nonce=g,this.recipient=v}}e.AuthPayload=c,e.authPayloadSchema={struct:{tag:"u32",message:"string",nonce:{array:{type:"u8",len:32}},recipient:"string",callbackUrl:{option:"string"}}};function d(p,y){const g=new c(p),v=i.serialize(e.authPayloadSchema,g),M=Uint8Array.from(s.default.sha256.array(v));let z=new Uint8Array(Buffer.from(y.signature,"base64"));return o.PublicKey.from(y.publicKey).verify(M,z)}})(Wv);var O6={};const CT=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function R6(e){return CT.test(e)}function xp(){var e=URL.createObjectURL(new Blob),t=e.toString();return URL.revokeObjectURL(e),t.split(/[:\/]/g).pop().toLowerCase()}xp.valid=R6;const BT=Object.freeze(Object.defineProperty({__proto__:null,default:xp,uuid4:xp,valid:R6},Symbol.toStringTag,{value:"Module"})),U6=Yx(BT);var k6={},z6={exports:{}},D6={exports:{}};(function(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t={rotl:function(r,n){return r<>>32-n},rotr:function(r,n){return r<<32-n|r>>>n},endian:function(r){if(r.constructor==Number)return t.rotl(r,8)&16711935|t.rotl(r,24)&4278255360;for(var n=0;n0;r--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(r){for(var n=[],a=0,i=0;a>>5]|=r[a]<<24-i%32;return n},wordsToBytes:function(r){for(var n=[],a=0;a>>5]>>>24-a%32&255);return n},bytesToHex:function(r){for(var n=[],a=0;a>>4).toString(16)),n.push((r[a]&15).toString(16));return n.join("")},hexToBytes:function(r){for(var n=[],a=0;a>>6*(3-s)&63)):n.push("=");return n.join("")},base64ToBytes:function(r){r=r.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],a=0,i=0;a>>6-i*2);return n}};D6.exports=t})();var OT=D6.exports,yp={utf8:{stringToBytes:function(e){return yp.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(yp.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],r=0;r>5]|=128<<24-o%32,s[(o+64>>>9<<4)+15]=o;for(var M=0;M>>31}var F=(d<<5|d>>>27)+v+(c[L]>>>0)+(L<20?(p&y|~p&g)+1518500249:L<40?(p^y^g)+1859775393:L<60?(p&y|p&g|y&g)-1894007588:(p^y^g)-899497514);v=g,g=y,y=p<<30|p>>>2,p=d,d=F}d+=z,p+=K,y+=D,g+=T,v+=k}return[d,p,y,g,v]},a=function(i,s){var o=e.wordsToBytes(n(i));return s&&s.asBytes?o:s&&s.asString?r.bytesToString(o):e.bytesToHex(o)};a._blocksize=16,a._digestsize=20,z6.exports=a})();var RT=z6.exports;(function(e){var t=Ie&&Ie.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(e,"__esModule",{value:!0}),e.createRequest=e.computeRequestId=e.deleteRequest=e.getResponse=e.proxyApi=void 0;const r=t(RT),n=t(U6),a=Wo;e.proxyApi="https://h4n.app";const i=async d=>{const p=await fetch(`${e.proxyApi}/${d}/response`,{headers:{"content-type":"application/json"},method:"GET"});if(p.ok===!1)throw Error(await p.text());const{data:y}=await p.json();return JSON.parse(y)};e.getResponse=i;const s=async d=>{const p=await fetch(`${e.proxyApi}/${d}`,{headers:{"content-type":"application/json"},method:"DELETE"});if(p.ok===!1)throw Error(await p.text())};e.deleteRequest=s;const o=async d=>{const p=(0,a.baseEncode)(JSON.stringify({...d,_id:(0,n.default)()})),y=(0,r.default)(p);return{requestId:Buffer.from(y,"hex").toString("base64").replaceAll("/","_").replaceAll("-","+").slice(0,13),query:p}};e.computeRequestId=o;const c=async(d,p)=>{const{query:y,requestId:g}=await(0,e.computeRequestId)(d),v=await fetch(`${e.proxyApi}/${g}/request`,{body:JSON.stringify({data:y}),headers:{"content-type":"application/json"},method:"POST",signal:p});if(v.ok===!1)throw Error(await v.text());return g};e.createRequest=c})(k6);(function(e){var t=Ie&&Ie.__importDefault||function(y){return y&&y.__esModule?y:{default:y}};Object.defineProperty(e,"__esModule",{value:!0}),e.getExtension=e.RequestFailed=e.wait=void 0;const r=t(U6),n=Wo,a=k6,i=y=>new Promise(g=>setTimeout(g,y));e.wait=i;class s extends Error{constructor(v){super();Bt(this,"payload");Bt(this,"name","RequestFailed");this.payload=v}}e.RequestFailed=s;const o=()=>typeof window>"u"?null:window.hotExtension;e.getExtension=o;let c;typeof window<"u"&&window.addEventListener("message",y=>{y.data==="hot-close"&&(c==null||c.remove(),c=void 0)});const d=y=>{c==null||c.remove(),c=document.createElement("div");const g=document.createElement("iframe");return c==null||c.appendChild(g),g.src=y,g.allow="usb",g.style.border="none",g.style.borderRadius="16px",g.style.background="#fff",g.style.overflow="hidden",g.style.background="#1D1F20",g.style.border="1px solid #2C3034",g.style.width="375px",g.style.height="560px",g.onclick=v=>v.stopPropagation(),c.style.padding="16px",c.style.zIndex="100000000000000",c.style.position="fixed",c.style.display="flex",c.style.justifyContent="center",c.style.alignItems="center",c.style.top="0",c.style.left="0",c.style.width="100%",c.style.height="100%",c.style.background="rgba(0, 0, 0, 0.1)",c.style.backdropFilter="blur(24px)",c.onclick=()=>{c==null||c.remove(),c=void 0},document.body.appendChild(c),c};class p{constructor(){Bt(this,"walletId","https://t.me/herewalletbot/app");Bt(this,"ancestorOrigins",["http://localhost:1234","https://my.herewallet.app","https://tgapp-dev.herewallet.app","https://tgapp.herewallet.app","https://beta.herewallet.app"]);Bt(this,"connection",new Promise(g=>{if(typeof window>"u"||(window==null?void 0:window.self)===(window==null?void 0:window.top))return g(null);this.injectedRequest("initialized",{}).then(g).catch(()=>g(null))}));Bt(this,"openInHotBrowserUrl",null);Bt(this,"customProvider")}get isInjected(){var g;return typeof window>"u"?!1:window.hotExtension!=null?window.hotExtension.autoRun:this.ancestorOrigins.includes((g=window.location.ancestorOrigins)==null?void 0:g[0])}toggleOpenInHotBrowser(g){this.openInHotBrowserUrl=g}setupEthProvider(g){this.customProvider=g}async injectedRequest(g,v){const M=(0,r.default)();return new Promise((z,K)=>{const D=T=>{if(T.data.id===M)return window==null||window.removeEventListener("message",D),T.data.success?z(T.data.payload):K(T.data.payload)};window==null||window.parent.postMessage({$hot:!0,method:g,request:v,id:M},"*"),window==null||window.addEventListener("message",D)})}subscribe(g,v){return window.hotExtension?window.hotExtension.subscribe(g,v):()=>{}}async request(g,v){var L;if(window.hotExtension!=null)return window.hotExtension.request(g,v);if(this.isInjected)return this.injectedRequest(g,v);const M=(0,r.default)(),z=(L=window==null?void 0:window.Telegram)==null?void 0:L.WebApp,K=await(0,a.createRequest)({inside:!!this.openInHotBrowserUrl||g==="ethereum"&&this.customProvider==null,origin:typeof this.openInHotBrowserUrl=="string"?this.openInHotBrowserUrl:location.href,$hot:!0,method:g,request:v,id:M}),D=`${this.walletId}?startapp=hotconnect-${(0,n.baseEncode)(K)}`;z?z==null||z.openTelegramLink(D):d(`https://hot-labs.org/hot-widget/index.html?hotconnect-${(0,n.baseEncode)(K)}`);const T=async()=>{await(0,e.wait)(3e3);const $=await(0,a.getResponse)(K).catch(()=>null);if($==null)return await T();if($.success)return $.payload;throw new s($.payload)},k=await T();return c==null||c.remove(),k}}e.default=new p})(O6);(function(e){var t=Ie&&Ie.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(e,"__esModule",{value:!0}),e.RequestFailed=e.HOT=e.authPayloadSchema=e.AuthPayload=e.verifySignature=void 0;var r=Wv;Object.defineProperty(e,"verifySignature",{enumerable:!0,get:function(){return r.verifySignature}}),Object.defineProperty(e,"AuthPayload",{enumerable:!0,get:function(){return r.AuthPayload}}),Object.defineProperty(e,"authPayloadSchema",{enumerable:!0,get:function(){return r.authPayloadSchema}});var n=O6;Object.defineProperty(e,"HOT",{enumerable:!0,get:function(){return t(n).default}}),Object.defineProperty(e,"RequestFailed",{enumerable:!0,get:function(){return n.RequestFailed}})})(w7);function un(e){var t,r,n;return{code:((t=e==null?void 0:e.error)==null?void 0:t.code)||(e==null?void 0:e.code)||-1,message:((r=e==null?void 0:e.error)==null?void 0:r.message)||(e==null?void 0:e.message)||typeof e=="string"&&e||"Unhandled error from the wallet",ext:((n=e==null?void 0:e.error)==null?void 0:n.ext)||(e==null?void 0:e.ext)}}const I6=re.createContext(null),X0="clevercon_pubkey",Z0="clevercon_wallet_id",UT=bs.TESTNET;function Q0(e){return new b9({network:UT,selectedWalletId:e,modules:[new f7,new v7,new t7,new h7,new b7]})}function kT({children:e}){const[t,r]=re.useState(null),[n,a]=re.useState(null),[i,s]=re.useState(!0),o=re.useRef(Q0());re.useEffect(()=>{const g=localStorage.getItem(X0),v=localStorage.getItem(Z0);g&&v&&(o.current=Q0(v),r(g),a(v)),s(!1)},[]);const c=async g=>{s(!0);try{o.current=Q0(g),o.current.setWallet(g);const{address:v}=await o.current.getAddress();if(!v)throw new Error("Could not retrieve public key from wallet.");r(v),a(g),localStorage.setItem(X0,v),localStorage.setItem(Z0,g)}finally{s(!1)}},d=()=>{var g,v;(v=(g=o.current).disconnect)==null||v.call(g).catch(()=>{}),r(null),a(null),localStorage.removeItem(X0),localStorage.removeItem(Z0)},p=async(g,v)=>{const{signedTxXdr:M}=await o.current.signTransaction(g,{networkPassphrase:v});if(!M)throw new Error("Wallet returned no signed XDR.");return M},y=()=>o.current.getSupportedWallets();return l.jsx(I6.Provider,{value:{publicKey:t,isConnected:!!t,isLoading:i,walletId:n,connect:c,disconnect:d,signTransaction:p,getSupportedWallets:y},children:e})}function On(){const e=re.useContext(I6);if(!e)throw new Error("useWallet must be used within WalletProvider");return e}const Td="";async function sb(e){const t=await fetch(`${Td}/api/vault/account/${e}`);if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error??`HTTP ${t.status}`)}return t.json()}async function zT(e,t){const r=await fetch(`${Td}/api/vault/deposit-xdr`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,amount:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Failed to build deposit XDR");return n.xdr}async function DT(e,t){const r=await fetch(`${Td}/api/vault/withdraw-xdr`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,amount:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Failed to build withdraw XDR");return n.xdr}async function kx(e,t){const r=await fetch(`${Td}/api/vault/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({signed_xdr:e,...t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Transaction failed");return n.tx_hash}const IT=["What's the current XLM price and any recent Stellar news?","Analyze Stellar DEX activity and write a market briefing","Get blockchain news, live prices and compile a full report"];function LT({available:e,required:t,orchestratorName:r,onFund:n,onClose:a}){const i=Math.max(0,t-e);return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-sm bg-gray-900 border border-amber-800/50 rounded-2xl shadow-2xl",children:[l.jsx("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-950 border border-amber-800 flex items-center justify-center shrink-0",children:l.jsx(Ka,{size:16,className:"text-amber-400"})}),l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-semibold text-white mb-0.5",children:"Insufficient vault balance"}),l.jsxs("p",{className:"text-xs text-gray-400 leading-relaxed",children:[r," needs ",l.jsxs("span",{className:"text-white font-semibold",children:["$",t.toFixed(2)," USDC"]})," to run this task."]})]}),l.jsx("button",{onClick:a,className:"text-gray-600 hover:text-gray-400 ml-auto shrink-0",children:l.jsx(ya,{size:14})})]})}),l.jsxs("div",{className:"px-5 py-4 space-y-3",children:[l.jsxs("div",{className:"flex justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Your vault balance"}),l.jsxs("span",{className:"text-white font-mono font-semibold",children:["$",e.toFixed(4)," USDC"]})]}),l.jsxs("div",{className:"flex justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Task budget"}),l.jsxs("span",{className:"text-white font-mono font-semibold",children:["$",t.toFixed(4)," USDC"]})]}),l.jsxs("div",{className:"flex justify-between text-xs border-t border-gray-800 pt-3",children:[l.jsx("span",{className:"text-amber-400",children:"Deposit needed"}),l.jsxs("span",{className:"text-amber-400 font-mono font-semibold",children:["$",i.toFixed(4)," USDC"]})]})]}),l.jsxs("div",{className:"px-5 pb-5 flex gap-2",children:[l.jsx("button",{onClick:a,className:"flex-1 px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-700 text-gray-300 text-sm font-medium transition-colors",children:"Cancel"}),l.jsxs("button",{onClick:n,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white text-sm font-semibold transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(Cc,{size:14}),"Fund Vault"]})]})]})})}function HT({onSubmit:e,isRunning:t,orchestratorName:r,onFundVault:n,onBotClick:a}){const{publicKey:i}=On(),[s,o]=re.useState(""),[c,d]=re.useState(""),[p,y]=re.useState(null),[g,v]=re.useState(!1),M=re.useRef(null);re.useEffect(()=>{if(!i)return;const $=()=>sb(i).then(V=>y((V==null?void 0:V.available)??0)).catch(()=>{});$();const F=setInterval($,1e4);return()=>clearInterval(F)},[i]),re.useEffect(()=>{const $=M.current;$&&($.style.height="auto",$.style.height=`${Math.min($.scrollHeight,180)}px`)},[s]);const z=parseFloat(c)||0,K=z>0,D=!K||p===null||p>=z,T=re.useCallback(()=>{if(!(!s.trim()||t||!K)){if(p!==null&&p{$.key==="Enter"&&($.metaKey||$.ctrlKey)&&($.preventDefault(),T())},L=()=>{v(!1),n==null||n()};return l.jsxs(l.Fragment,{children:[g&&l.jsx(LT,{available:p??0,required:z,orchestratorName:r,onFund:L,onClose:()=>v(!1)}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-gray-800/80",children:[l.jsxs("button",{onClick:a,className:"relative shrink-0 group",title:"View agent details",children:[l.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-purple-600 to-purple-800 rounded-xl flex items-center justify-center shadow-lg shadow-purple-900/40 group-hover:from-purple-500 group-hover:to-purple-700 transition-all",children:l.jsx(jc,{size:14,className:"text-white"})}),l.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full border-2 border-gray-900 ${t?"bg-amber-400 animate-pulse":"bg-emerald-400"}`})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs font-semibold text-white leading-none",children:r}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-0.5",children:t?"Working on it…":"Ready for a task"})]}),p!==null&&l.jsxs("div",{className:`text-right shrink-0 ${D?"":"text-amber-400"}`,children:[l.jsxs("p",{className:"text-xs font-mono font-semibold text-gray-300",children:["$",p.toFixed(2)]}),l.jsx("p",{className:"text-xs text-gray-600",children:"vault"})]})]}),l.jsxs("div",{className:"p-4",children:[l.jsxs("p",{className:"text-xs text-gray-500 mb-2.5",children:["What do you want ",l.jsx("span",{className:"text-purple-400 font-medium",children:r})," to do?"]}),l.jsxs("div",{className:"relative",children:[l.jsx("textarea",{ref:M,value:s,onChange:$=>o($.target.value),onKeyDown:k,disabled:t,placeholder:`Ask ${r} anything…`,rows:2,className:"w-full bg-gray-800/80 border border-gray-700/80 rounded-xl px-3.5 py-3 pr-11 text-sm text-gray-200 placeholder-gray-600 resize-none focus:outline-none focus:border-purple-500/70 focus:bg-gray-800 transition-all disabled:opacity-50"}),l.jsx("button",{onClick:T,disabled:!s.trim()||t||!K,title:K?t?`${r} is working on another task`:"Send (⌘+Enter)":"Enter a budget first",className:"absolute bottom-2.5 right-2.5 w-7 h-7 flex items-center justify-center bg-purple-600 hover:bg-purple-500 disabled:bg-gray-700 disabled:text-gray-600 text-white rounded-lg transition-all shadow-sm",children:l.jsx(sw,{size:12})})]}),!s&&!t&&l.jsx("div",{className:"mt-2.5 space-y-1.5",children:IT.map(($,F)=>l.jsxs("button",{onClick:()=>o($),className:"w-full text-left text-xs text-gray-500 hover:text-gray-300 bg-gray-800/50 hover:bg-gray-800 border border-gray-800 hover:border-gray-700 rounded-lg px-3 py-2 transition-all leading-snug",children:[l.jsx(tv,{size:9,className:"inline mr-1.5 text-purple-500"}),$]},F))}),t&&l.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[l.jsx("div",{className:"flex gap-1",children:[0,150,300].map($=>l.jsx("span",{className:"w-1.5 h-1.5 bg-purple-400 rounded-full animate-bounce",style:{animationDelay:`${$}ms`}},$))}),l.jsxs("span",{className:"text-xs text-gray-500",children:[r," is working…"]})]})]}),l.jsxs("div",{className:"px-4 py-3 border-t border-gray-800/80 space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("label",{className:"text-xs text-gray-500",children:"Budget (USDC)"}),p!==null&&l.jsxs("span",{className:`text-xs font-mono ${D?"text-gray-600":"text-amber-400"}`,children:["vault: $",p.toFixed(2)]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:[.25,.5,1,2].map($=>l.jsxs("button",{onClick:()=>d($.toFixed(2)),disabled:t,className:`text-xs rounded-lg py-1.5 transition-all border font-mono disabled:opacity-40 ${c===$.toFixed(2)?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-400 hover:border-gray-600 hover:text-gray-300"}`,children:["$",$.toFixed(2)]},$))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:c,onChange:$=>d($.target.value),placeholder:"0.00",disabled:t,className:`w-full bg-gray-800/80 border rounded-xl pl-6 pr-14 py-2 text-sm font-mono font-semibold focus:outline-none transition-all disabled:opacity-50 ${!D&&K?"border-amber-700/60 text-amber-400 focus:border-amber-600":!K&&c!==""?"border-red-800/60 text-red-400 focus:border-red-600":"border-gray-700/80 text-purple-300 focus:border-purple-500/70"}`}),l.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-600",children:"USDC"})]}),!D&&K&&p!==null&&l.jsxs("p",{className:"text-xs text-amber-500/80",children:["Exceeds vault balance — deposit $",(z-p).toFixed(4)," more."]})]})]})]})}const L6=[{label:"30s",ms:3e4},{label:"5 min",ms:3e5},{label:"15 min",ms:9e5},{label:"30 min",ms:18e5}],H6=[.25,.5,1,2];function qT(e){const t=Math.max(0,e),r=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3);return r>0?`${r}m ${n}s`:`${n}s`}function $T(e){return e<6e4?`${Math.round(e/1e3)}s`:`${Math.round(e/6e4)} min`}function FT({initial:e,isFirst:t,onSave:r,onCancel:n}){const[a,i]=re.useState(e.task),[s,o]=re.useState(e.budget.toFixed(2)),[c,d]=re.useState(e.delay_ms),[p,y]=re.useState(""),[g,v]=re.useState(""),M=parseFloat(s)||0;return l.jsxs("div",{className:"px-3 py-2.5 space-y-2.5 bg-gray-800/60 border border-purple-800/40 rounded-xl",children:[l.jsx("textarea",{rows:2,value:a,onChange:z=>i(z.target.value),autoFocus:!0,className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-lg px-2.5 py-1.5 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors"}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Budget"}),l.jsx("div",{className:"grid grid-cols-4 gap-1 mb-1",children:H6.map(z=>l.jsxs("button",{onClick:()=>o(z.toFixed(2)),className:`text-xs py-1 rounded-lg border transition-all font-mono ${s===z.toFixed(2)?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:["$",z.toFixed(2)]},z))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:s,onChange:z=>o(z.target.value),placeholder:"0.00",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg pl-5 pr-3 py-1 text-xs font-mono font-semibold text-purple-300 outline-none transition-all"})]})]}),!t&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Wait after previous task"}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:L6.map(z=>l.jsx("button",{onClick:()=>{d(z.ms),y(""),v("")},className:`text-xs py-1 rounded-lg border transition-all font-mono ${c===z.ms&&!p&&!g?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:z.label},z.ms))}),l.jsxs("div",{className:"grid grid-cols-2 gap-1.5 mt-1",children:[l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Seconds",value:p,onChange:z=>{y(z.target.value),v("");const K=parseFloat(z.target.value);!isNaN(K)&&K>0&&d(Math.round(K*1e3))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"s"})]}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Minutes",value:g,onChange:z=>{v(z.target.value),y("");const K=parseFloat(z.target.value);!isNaN(K)&&K>0&&d(Math.round(K*6e4))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"m"})]})]})]}),l.jsxs("div",{className:"flex gap-1.5",children:[l.jsxs("button",{onClick:n,className:"flex items-center gap-1 text-xs px-2.5 py-1.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:[l.jsx(Jh,{size:9})," Cancel"]}),l.jsxs("button",{onClick:()=>{a.trim()&&M>0&&r(a.trim(),M,c)},disabled:!a.trim()||M<=0,className:"flex-1 flex items-center justify-center gap-1 text-xs py-1.5 rounded-lg bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(mr,{size:9})," Save"]})]})]})}function KT({items:e,vaultAvailable:t,onAdd:r,onUpdate:n,onRemove:a,onClearDone:i,onRunQueue:s}){const[o,c]=re.useState(!1),[d,p]=re.useState(!1),[y,g]=re.useState(null),[v,M]=re.useState(""),[z,K]=re.useState(""),[D,T]=re.useState(3e5),[k,L]=re.useState(""),[$,F]=re.useState(""),[,V]=re.useState(0);re.useEffect(()=>{const h=setInterval(()=>V(C=>C+1),1e3);return()=>clearInterval(h)},[]);const J=()=>{const h=parseFloat(z)||0;!v.trim()||h<=0||(r(v.trim(),h,D),M(""),K(""),T(3e5),L(""),F(""),c(!1))},Y=e.some(h=>h.status==="done"||h.status==="failed"),ee=e.filter(h=>h.status!=="done"&&h.status!=="failed"),x=e.filter(h=>h.status==="queued"),u=ee.reduce((h,C)=>h+C.budget,0),f=t!==null&&u>t,_=[];let E=0;for(const h of e)(h.status==="queued"||h.status==="countdown"||h.status==="running")&&(E+=h.budget),_.push(E);const S=parseFloat(z)||0,j=t!==null?Math.max(0,t-u):null,R=j===null||S<=0||S<=j,N=x.length>0&&!e.some(h=>h.status==="running"||h.status==="countdown");return e.length===0&&!o?l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl px-4 py-3 flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[l.jsx(pa,{size:12}),l.jsx("span",{children:"No tasks queued"})]}),l.jsxs("button",{onClick:()=>c(!0),className:"flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 bg-purple-950/40 hover:bg-purple-950/60 border border-purple-900/60 rounded-lg px-2.5 py-1 transition-all",children:[l.jsx(Fl,{size:11})," Schedule"]})]}):l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(pa,{size:13,className:"text-purple-400"}),l.jsx("span",{className:"text-sm font-semibold text-gray-200 flex-1",children:"Queue"}),ee.length>0&&l.jsxs("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded ${f?"text-amber-400 bg-amber-950/40":"text-gray-500 bg-gray-800"}`,children:["$",u.toFixed(2)]}),ee.length>0&&l.jsx("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded",children:ee.length}),Y&&l.jsx("button",{onClick:i,className:"text-xs text-gray-600 hover:text-gray-400 transition-colors",children:"Clear done"}),l.jsx("button",{onClick:()=>c(h=>!h),className:"text-xs text-purple-400 hover:text-purple-300 transition-colors",children:l.jsx(Fl,{size:11})}),l.jsx("button",{onClick:()=>p(h=>!h),className:"text-gray-600 hover:text-gray-400 transition-colors",children:d?l.jsx(Ds,{size:13}):l.jsx(Mc,{size:13})})]}),f&&!d&&l.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-amber-950/30 border-b border-amber-900/30",children:[l.jsx(Ka,{size:10,className:"text-amber-400 shrink-0"}),l.jsxs("p",{className:"text-xs text-amber-400",children:["Pipeline needs ",l.jsxs("span",{className:"font-mono font-semibold",children:["$",u.toFixed(2)]})," but vault has"," ",l.jsxs("span",{className:"font-mono font-semibold",children:["$",t.toFixed(2)]}),"."]})]}),!d&&l.jsxs(l.Fragment,{children:[e.length>0&&l.jsx("div",{className:"px-3 py-3 space-y-0",children:e.map((h,C)=>{const ae=C===0||e.slice(0,C).every(Q=>Q.status==="done"||Q.status==="failed"),he=h.status==="countdown"&&h.scheduled_run_at,q=he?h.scheduled_run_at-Date.now():0,G=he?Math.max(0,Math.min(100,(1-q/h.delay_ms)*100)):0,W=_[C],be=t!==null&&(h.status==="queued"||h.status==="countdown")&&W>t,ue=y===h.id;return l.jsxs("div",{children:[C>0&&!ae&&l.jsxs("div",{className:"flex items-center gap-2 py-1 pl-3",children:[l.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[l.jsx("div",{className:"w-px h-3 bg-gray-700"}),l.jsx("div",{className:"w-px h-3 bg-gray-700"})]}),l.jsxs("span",{className:"text-xs text-gray-700 font-mono",children:["+",$T(h.delay_ms)]})]}),ue?l.jsx(FT,{initial:h,isFirst:ae,onSave:(Q,le,Se)=>{n(h.id,Q,le,Se),g(null)},onCancel:()=>g(null)}):l.jsxs("div",{className:`flex items-start gap-2 rounded-xl p-2.5 transition-colors ${h.status==="running"?"bg-amber-950/30 border border-amber-900/40":h.status==="countdown"?"bg-purple-950/30 border border-purple-900/40":h.status==="done"?"bg-gray-800/30 border border-gray-800/60":h.status==="failed"?"bg-red-950/20 border border-red-900/30":be?"bg-amber-950/15 border border-amber-900/30":"bg-gray-800/40 border border-gray-800/60"}`,children:[l.jsxs("div",{className:"mt-0.5 shrink-0",children:[h.status==="running"&&l.jsx(ga,{size:12,className:"text-amber-400 animate-pulse"}),h.status==="countdown"&&l.jsx(pa,{size:12,className:"text-purple-400"}),h.status==="queued"&&(be?l.jsx(Ka,{size:12,className:"text-amber-500"}):l.jsx("div",{className:"w-3 h-3 rounded-full border-2 border-gray-600"})),h.status==="done"&&l.jsx(mr,{size:12,className:"text-emerald-500"}),h.status==="failed"&&l.jsx(En,{size:12,className:"text-red-500"})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:`text-xs truncate leading-relaxed ${h.status==="done"||h.status==="failed"?"text-gray-600":"text-gray-300"}`,children:h.task}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsxs("span",{className:`text-xs font-mono ${be?"text-amber-600":"text-gray-600"}`,children:["$",h.budget.toFixed(2)]}),ae&&h.status==="queued"&&l.jsx("span",{className:"text-xs text-purple-500 italic",children:"starts first"}),be&&l.jsx("span",{className:"text-xs text-amber-600 italic",children:"may be short"}),he&&q>0&&l.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[l.jsx("div",{className:"flex-1 h-0.5 bg-gray-700 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-purple-500 rounded-full transition-all duration-1000",style:{width:`${G}%`}})}),l.jsx("span",{className:"text-xs font-mono text-purple-400 tabular-nums shrink-0",children:qT(q)})]}),he&&q<=0&&l.jsx("span",{className:"text-xs text-purple-400 italic",children:"starting…"}),h.status==="running"&&l.jsx("span",{className:"text-xs text-amber-400",children:"running now"})]}),h.status==="failed"&&h.failReason&&l.jsx("p",{className:"text-xs text-red-500 mt-1 leading-snug",children:h.failReason})]}),h.status==="queued"&&l.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[l.jsx("button",{onClick:()=>g(h.id),className:"p-1 text-gray-700 hover:text-gray-300 transition-colors",title:"Edit",children:l.jsx(Vf,{size:10})}),l.jsx("button",{onClick:()=>a(h.id),className:"p-1 text-gray-700 hover:text-red-400 transition-colors",children:l.jsx(ya,{size:11})})]})]})]},h.id)})}),N&&l.jsx("div",{className:"px-3 pb-3",children:l.jsxs("button",{onClick:s,className:"w-full flex items-center justify-center gap-2 text-xs font-semibold py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(aw,{size:11}),"Review & Run Queue (",x.length," task",x.length!==1?"s":"",")"]})}),o&&l.jsxs("div",{className:"px-4 pb-4 pt-1 border-t border-gray-800 space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between pt-2",children:[l.jsx("p",{className:"text-xs text-gray-500",children:"Add to queue"}),t!==null&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-mono",children:[l.jsxs("span",{className:"text-gray-600",children:["vault $",t.toFixed(2)]}),u>0&&l.jsxs("span",{className:j!==null&&S>0&&S>j?"text-amber-400":"text-gray-500",children:["· rem $",(j??0).toFixed(2)]})]})]}),l.jsx("textarea",{rows:2,value:v,onChange:h=>M(h.target.value),placeholder:"What should the agent do next?",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-xl px-3 py-2 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors"}),ee.length>0&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5",children:"Wait after previous task"}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:L6.map(h=>l.jsx("button",{onClick:()=>{T(h.ms),L(""),F("")},className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${D===h.ms&&!k&&!$?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:h.label},h.ms))}),l.jsxs("div",{className:"grid grid-cols-2 gap-1.5 mt-1.5",children:[l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Seconds",value:k,onChange:h=>{L(h.target.value),F("");const C=parseFloat(h.target.value);!isNaN(C)&&C>0&&T(Math.round(C*1e3))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1.5 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"s"})]}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{type:"number",min:"1",placeholder:"Minutes",value:$,onChange:h=>{F(h.target.value),L("");const C=parseFloat(h.target.value);!isNaN(C)&&C>0&&T(Math.round(C*6e4))},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg px-2.5 pr-6 py-1.5 text-xs text-gray-300 placeholder-gray-600 outline-none"}),l.jsx("span",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-xs text-gray-600 pointer-events-none",children:"m"})]})]})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Budget"}),!R&&t!==null&&l.jsxs("span",{className:"text-xs text-amber-500 flex items-center gap-1",children:[l.jsx(Ka,{size:9}),"exceeds remaining $",(j??0).toFixed(2)]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-1",children:H6.map(h=>{const C=j===null||h<=j;return l.jsxs("button",{onClick:()=>K(h.toFixed(2)),className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${z===h.toFixed(2)?C?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-amber-900/30 border-amber-700/60 text-amber-300":C?"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300":"bg-gray-800 border-amber-900/40 text-amber-700 hover:text-amber-500"}`,children:["$",h.toFixed(2)]},h)})}),l.jsxs("div",{className:"relative mt-1.5",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:z,onChange:h=>K(h.target.value),placeholder:"0.00",className:`w-full bg-gray-800 border rounded-lg pl-5 pr-3 py-1.5 text-xs font-mono font-semibold focus:outline-none transition-all ${!R&&S>0?"border-amber-700/60 text-amber-400 focus:border-amber-600":"border-gray-700 text-purple-300 focus:border-purple-500/50"}`})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:()=>c(!1),className:"flex-1 text-xs py-2 rounded-xl bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:"Cancel"}),l.jsxs("button",{onClick:J,disabled:!v.trim()||S<=0,className:"flex-1 flex items-center justify-center gap-1.5 text-xs py-2 rounded-xl bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(Fl,{size:11}),!R&&S>0?"Add Anyway":"Add to Queue"]})]})]})]})]})}const PT={task_accepted:{icon:l.jsx(ga,{size:11}),color:"text-purple-400",bg:"bg-purple-950/60 border-purple-900/60"},agents_loaded:{icon:l.jsx(Uu,{size:11}),color:"text-blue-400",bg:"bg-blue-950/60 border-blue-900/60"},agents_scored:{icon:l.jsx(rv,{size:11}),color:"text-violet-400",bg:"bg-violet-950/60 border-violet-900/60"},feasibility_checked:{icon:l.jsx(Xh,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},plan_created:{icon:l.jsx(Xh,{size:11}),color:"text-blue-400",bg:"bg-blue-950/60 border-blue-900/60"},plan_validated:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},plan_approval_required:{icon:l.jsx(pa,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},plan_approved:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},plan_rejected:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},plan_auto_approved:{icon:l.jsx(mr,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},vault_skipped:{icon:l.jsx(cn,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},budget_locked:{icon:l.jsx(cn,{size:11}),color:"text-purple-400",bg:"bg-purple-950/60 border-purple-900/60"},budget_released:{icon:l.jsx(cn,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},budget_approved:{icon:l.jsx(cn,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},budget_denied:{icon:l.jsx(cn,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},budget_finalized:{icon:l.jsx(cn,{size:11}),color:"text-gray-400",bg:"bg-gray-800/60 border-gray-700/60"},task_started:{icon:l.jsx(ga,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},step_started:{icon:l.jsx(pa,{size:11}),color:"text-amber-400",bg:"bg-amber-950/60 border-amber-900/60"},step_complete:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},step_failed:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},task_complete:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},task_result:{icon:l.jsx(mr,{size:11}),color:"text-emerald-400",bg:"bg-emerald-950/60 border-emerald-900/60"},task_error:{icon:l.jsx(En,{size:11}),color:"text-red-400",bg:"bg-red-950/60 border-red-900/60"},task_infeasible:{icon:l.jsx(En,{size:11}),color:"text-orange-400",bg:"bg-orange-950/60 border-orange-900/60"}};function GT(e,t){return{task_accepted:"Task Accepted",agents_loaded:"Agents Loaded",agents_scored:"Agents Scored",feasibility_checked:"Feasibility Checked",plan_created:`${t} Created Plan`,plan_validated:"Plan Validated",plan_approval_required:"Plan Approval Required",plan_approved:"Plan Approved",plan_rejected:"Plan Rejected",plan_auto_approved:"Auto-Approved",vault_skipped:"Vault Bypassed",budget_locked:"Budget Locked",budget_released:"Budget Released",budget_approved:"Budget Approved",budget_denied:"Budget Denied",budget_finalized:"Budget Finalized",task_started:`${t} Started`,step_started:"Step Started",step_complete:"Step Complete",step_failed:"Step Failed",task_complete:"Task Complete",task_result:"Task Result",task_error:"Task Error",task_infeasible:"Task Infeasible"}[e]??e.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function YT(e,t,r){var n,a,i,s,o,c,d,p,y,g,v,M,z,K,D,T,k;if(!t)return{text:""};switch(e){case"agents_loaded":return{text:`${t.count??0} agents available`};case"agents_scored":return{text:`${((n=t.agents)==null?void 0:n.length)??0} scored · top: ${((i=(a=t.agents)==null?void 0:a[0])==null?void 0:i.name)??"?"} (${((o=(s=t.agents)==null?void 0:s[0])==null?void 0:o.score)??0})`};case"feasibility_checked":return{text:`${t.feasible?"Feasible":"Infeasible"} · [${(c=t.needed)==null?void 0:c.slice(0,3).join(", ")}${(((d=t.needed)==null?void 0:d.length)??0)>3?"…":""}]`};case"plan_created":{const L=(t.step_selections??[]).filter($=>{var F;return((F=$.alternatives)==null?void 0:F.length)>0}).slice(0,1).map($=>`${$.agent_name} (${Math.round($.selected_score*100)}) over ${$.alternatives[0].name} (${Math.round($.alternatives[0].score*100)})`);return{text:`${t.steps} steps · $${(p=t.total_estimated_cost)==null?void 0:p.toFixed(3)}${L.length?" · "+L[0]:""}`}}case"plan_approval_required":return{text:`${((y=t.steps)==null?void 0:y.length)??0} steps · $${(g=t.total_estimated_cost)==null?void 0:g.toFixed(3)} — awaiting approval`};case"plan_approved":return{text:`${r} is executing`};case"plan_auto_approved":return{text:"Approved automatically — within budget"};case"plan_rejected":return{text:"Plan was rejected"};case"vault_skipped":return{text:t.reason??"Vault bypassed — complete on-chain orchestrator registration to enable"};case"budget_locked":return{text:`task #${t.contract_task_id} · $${(v=t.budget_usdc)==null?void 0:v.toFixed(2)} locked on-chain`};case"budget_released":return{text:`${t.agent_name} · $${(M=t.amount)==null?void 0:M.toFixed(4)} released`,txHash:t.tx_hash};case"budget_approved":return{text:`${t.agent_name} · $${(z=t.amount)==null?void 0:z.toFixed(3)} approved`};case"budget_denied":return{text:`${t.agent_name} · $${(K=t.amount)==null?void 0:K.toFixed(3)} denied — over budget`};case"budget_finalized":return{text:`task #${t.contract_task_id} · $${(D=t.total_spent)==null?void 0:D.toFixed(4)} spent`};case"task_started":return{text:`${t.step_count??0} steps planned`};case"step_started":return{text:`${t.agent_name}: ${(t.action??"").slice(0,80)}`};case"step_complete":{const L=t.latency_ms?` · ${t.latency_ms}ms`:"";return{text:`${t.agent_name}${L}`,txHash:t.tx_hash}}case"step_failed":return{text:`${t.agent_name}: ${(t.error??"").slice(0,80)}`};case"task_complete":return{text:`${t.status} · $${(T=t.total_cost)==null?void 0:T.toFixed(4)} · ${(t.total_time_ms/1e3).toFixed(1)}s`};case"task_result":return{text:`${t.status} · $${(k=t.total_cost)==null?void 0:k.toFixed(4)} · ${(t.total_time_ms/1e3).toFixed(1)}s`};case"task_error":return{text:(t.error??"").slice(0,100)};default:return{text:JSON.stringify(t).slice(0,80)}}}function VT({events:e,connected:t,onClear:r,orchestratorName:n="Agent"}){const a=re.useRef(null);return re.useEffect(()=>{var i;(i=a.current)==null||i.scrollIntoView({behavior:"smooth"})},[e.length]),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl flex flex-col h-full overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800 shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(Uu,{size:14,className:"text-gray-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Activity Feed"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${t?"bg-emerald-400":"bg-red-500 animate-pulse"}`}),l.jsx("span",{className:"text-xs text-gray-600",children:t?"live":"reconnecting…"})]})]}),e.length>0&&l.jsx("button",{onClick:r,className:"text-xs text-gray-600 hover:text-gray-400 transition-colors px-2 py-1 rounded-lg hover:bg-gray-800",children:"Clear"})]}),l.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0 px-3 py-3 space-y-1",children:[e.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3 py-12",children:[l.jsx("div",{className:"w-10 h-10 rounded-full bg-gray-800 flex items-center justify-center",children:l.jsx(Uu,{size:18,className:"text-gray-600"})}),l.jsxs("p",{className:"text-xs text-gray-600 text-center",children:["Submit a task to see ",n," in action"]})]}):[...e].reverse().map((i,s)=>{const o=PT[i.event]??{icon:l.jsx(Uu,{size:11}),color:"text-gray-500",bg:"bg-gray-800/60 border-gray-700/60"},c=GT(i.event,n),{text:d,txHash:p}=YT(i.event,i.data,n),y=new Date(i.timestamp).toLocaleTimeString("en",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"});return l.jsxs("div",{className:`flex items-start gap-2.5 px-2.5 py-2 rounded-xl border ${o.bg} transition-all`,children:[l.jsx("span",{className:`mt-0.5 shrink-0 ${o.color}`,children:o.icon}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("span",{className:`text-xs font-semibold ${o.color}`,children:c}),l.jsx("span",{className:"text-xs text-gray-700 font-mono shrink-0 tabular-nums",children:y})]}),(d||p)&&l.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[d&&l.jsx("p",{className:"text-xs text-gray-500 truncate leading-relaxed",children:d}),p&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${p}`,target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-gray-600 hover:text-blue-400 transition-colors",title:"View transaction",children:l.jsx(Xr,{size:9})})]})]})]},s)}),l.jsx("div",{ref:a})]})]})}function XT(e){return e.replace(/^### (.+)$/gm,'

    $1

    ').replace(/^## (.+)$/gm,'

    $1

    ').replace(/^# (.+)$/gm,'

    $1

    ').replace(/\*\*(.+?)\*\*/g,'$1').replace(/\*(.+?)\*/g,'$1').replace(/`([^`]+)`/g,'$1').replace(/^---$/gm,'
    ').replace(/^\| (.+)$/gm,t=>t.includes("|---")?"":`${t.split("|").filter(Boolean).map(n=>n.trim()).map(n=>`${n}`).join("")}`).replace(/^- (.+)$/gm,'
  • $1
  • ').replace(/^\d+\. (.+)$/gm,'
  • $1
  • ').replace(/\n\n/g,` `).split(` `).map(t=>t.trim()?t.startsWith("<")?t:`

    ${t}

    `:"").join(` -`)}function ZT({events:e}){var s,o,c,h;const t=(s=e.find(p=>p.event==="task_result"))==null?void 0:s.data,r=(o=e.find(p=>p.event==="task_error"))==null?void 0:o.data,n=(c=e.find(p=>p.event==="task_complete"))==null?void 0:c.data;if(!t&&!r&&!n)return null;const a=(t==null?void 0:t.status)??(r?"failed":"running"),i={complete:{icon:l.jsx(mr,{size:13,className:"text-emerald-400"}),label:"Complete",color:"text-emerald-400",border:"border-emerald-900/40",bg:"bg-emerald-950/20"},partial:{icon:l.jsx(Ka,{size:13,className:"text-amber-400"}),label:"Partial",color:"text-amber-400",border:"border-amber-900/40",bg:"bg-amber-950/20"},failed:{icon:l.jsx(En,{size:13,className:"text-red-400"}),label:"Failed",color:"text-red-400",border:"border-red-900/40",bg:"bg-red-950/20"}}[a]??{icon:l.jsx(Zh,{size:13,className:"text-gray-400"}),label:a,color:"text-gray-400",border:"border-gray-700",bg:""};return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Zh,{size:14,className:"text-gray-500"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Result"}),l.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full border ${i.border} ${i.bg}`,children:[i.icon,l.jsx("span",{className:`text-xs font-medium capitalize ${i.color}`,children:i.label})]})]}),t&&l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(Q8,{size:10}),l.jsx("span",{className:"font-mono tabular-nums",children:(h=t.total_cost)==null?void 0:h.toFixed(4)})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(ha,{size:10}),l.jsxs("span",{className:"tabular-nums",children:[(t.total_time_ms/1e3).toFixed(1),"s"]})]})]})]}),r&&l.jsxs("div",{className:"mx-4 mt-4 bg-red-950/40 border border-red-900/50 rounded-xl p-3",children:[l.jsx("p",{className:"text-xs font-semibold text-red-400 mb-1",children:"Error"}),l.jsx("p",{className:"text-xs text-red-300/80",children:r.error})]}),(t==null?void 0:t.final_output)&&l.jsx("div",{className:"px-4 py-4 max-h-72 overflow-y-auto text-xs text-gray-400 leading-relaxed",dangerouslySetInnerHTML:{__html:XT(t.final_output)}}),(t==null?void 0:t.steps)&&t.steps.length>0&&l.jsxs("div",{className:"px-4 pb-4 border-t border-gray-800 mt-0 pt-3",children:[l.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2",children:"Execution Steps"}),l.jsx("div",{className:"space-y-1.5",children:t.steps.map(p=>{var y;return l.jsxs("div",{className:`flex items-center gap-2.5 text-xs px-3 py-2 rounded-xl ${p.success?"bg-gray-800/50":"bg-red-950/30"}`,children:[p.success?l.jsx(mr,{size:11,className:"text-emerald-400 shrink-0"}):l.jsx(En,{size:11,className:"text-red-400 shrink-0"}),l.jsx("span",{className:`font-medium ${p.success?"text-gray-300":"text-red-400"}`,children:p.agent_name}),l.jsx("span",{className:"text-gray-700",children:"·"}),l.jsxs("span",{className:"text-gray-500 tabular-nums",children:[(p.latency_ms/1e3).toFixed(1),"s"]}),((y=p.payment)==null?void 0:y.tx_hash)&&l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/tx/${p.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"ml-auto flex items-center gap-1 text-gray-600 hover:text-blue-400 transition-colors font-mono",children:[l.jsxs("span",{children:[p.payment.tx_hash.slice(0,8),"…"]}),l.jsx(Xr,{size:9})]}),!p.success&&p.error&&l.jsx("span",{className:"text-red-500 truncate ml-auto max-w-48 text-right",children:p.error.slice(0,60)})]},p.step_id)})})]})]})}function QT({events:e}){var i,s,o,c,h,p;const t=(i=e.find(y=>y.event==="task_result"))==null?void 0:i.data;if(!t)return null;const r=((s=t.steps)==null?void 0:s.filter(y=>y.success))??[],n=((o=t.steps)==null?void 0:o.filter(y=>!y.success))??[],a=t.status==="complete"?"text-emerald-400":t.status==="partial"?"text-amber-400":"text-red-400";return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(ev,{size:14,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Receipt"}),l.jsx("span",{className:`text-xs font-medium ml-auto capitalize ${a}`,children:t.status})]}),l.jsx("div",{className:"px-4 py-3 border-b border-gray-800",children:l.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Task ID"}),l.jsxs("p",{className:"text-xs text-gray-400 font-mono",children:[(c=t.task_id)==null?void 0:c.slice(0,12),"…"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Duration"}),l.jsxs("p",{className:"text-xs text-gray-300 tabular-nums",children:[(t.total_time_ms/1e3).toFixed(1),"s"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Total Cost"}),l.jsxs("p",{className:"text-xs text-emerald-400 font-mono font-semibold",children:["$",(h=t.total_cost)==null?void 0:h.toFixed(4)]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Steps"}),l.jsxs("p",{className:"text-xs",children:[l.jsxs("span",{className:"text-emerald-400",children:[r.length," ok"]}),n.length>0&&l.jsxs("span",{className:"text-red-400 ml-1",children:[n.length," failed"]})]})]})]})}),l.jsx("div",{className:"divide-y divide-gray-800",children:(t.steps??[]).map(y=>{var g,v,M;return l.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[y.success?l.jsx(mr,{size:10,className:"text-emerald-500 shrink-0"}):l.jsx(En,{size:10,className:"text-red-500 shrink-0"}),l.jsx("span",{className:"text-xs text-gray-400 flex-1 truncate",children:y.agent_name}),((g=y.payment)==null?void 0:g.method)&&l.jsx("span",{className:"text-xs text-gray-700 uppercase",children:y.payment.method}),((v=y.payment)==null?void 0:v.amount)>0&&l.jsxs("span",{className:"text-xs font-mono text-gray-300 tabular-nums",children:["$",y.payment.amount.toFixed(4)]}),((M=y.payment)==null?void 0:M.tx_hash)&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${y.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",children:l.jsx(Xr,{size:10})})]},y.step_id)})}),l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-gray-800 bg-gray-950/30",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-400",children:"Total"}),l.jsxs("span",{className:"text-sm font-mono font-bold text-emerald-400",children:["$",(p=t.total_cost)==null?void 0:p.toFixed(4)," USDC"]})]})]})}const JT="http://localhost:4000",zx={agent_id:"",name:"",description:"",capabilities:"",payment_model:"x402",price_per_call:"0.02",endpoint:"",stellar_address:"",health_check:"",provision_wallet:!1};function WT(e){if(!e.agent_id.match(/^[a-z0-9-]+$/))return"Agent ID must be lowercase letters, numbers, and hyphens only";if(!e.name.trim())return"Display name is required";if(!e.endpoint.startsWith("http"))return"Endpoint must be a valid URL starting with http(s)://";if(!e.provision_wallet&&!e.stellar_address.match(/^G[A-Z0-9]{55}$/))return"Stellar address must start with G and be 56 characters";if(!e.capabilities.trim())return"At least one capability is required";const t=parseFloat(e.price_per_call);return isNaN(t)||t<=0?"Price must be a positive number":null}function eM(){const{publicKey:e}=On(),[t,r]=re.useState(zx),[n,a]=re.useState("idle"),[i,s]=re.useState(""),[o,c]=re.useState(null),[h,p]=re.useState(!1),y=(K,D)=>{r(T=>({...T,[K]:D})),n==="error"&&a("idle")},g=()=>{r(zx),a("idle"),s(""),c(null),p(!1)},v=async()=>{o&&(await navigator.clipboard.writeText(o.secretKey),p(!0),setTimeout(()=>p(!1),2e3))},M=async()=>{const K=WT(t);if(K){a("error"),s(K);return}let D=t.stellar_address;if(t.provision_wallet){a("provisioning");try{const T=await fetch("/api/provision-wallet",{method:"POST"});if(!T.ok){const L=await T.json().catch(()=>({error:`HTTP ${T.status}`}));throw new Error(L.error??"Wallet provisioning failed")}const z=await T.json();c(z),D=z.publicKey}catch(T){a("error"),s(`Wallet provisioning failed: ${T.message}`);return}}a("loading");try{const T={agent_id:t.agent_id,name:t.name,description:t.description,capabilities:t.capabilities.split(",").map(L=>L.trim()).filter(Boolean),pricing:{model:t.payment_model,price_per_call:parseFloat(t.price_per_call),currency:"USDC"},endpoint:t.endpoint,stellar_address:D,health_check:t.health_check||`${t.endpoint.replace(/\/[^/]*$/,"")}/health`,registered_by:e??void 0},z=await fetch(`${JT}/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)});if(z.ok)a("success"),s(`${t.name} registered successfully! It will appear in the agent list and be available for tasks immediately.`);else{const L=await z.json().catch(()=>({error:`HTTP ${z.status}`}));a("error"),s(L.error??"Registration failed")}}catch(T){a("error"),s(`Could not reach registry: ${T.message}`)}},k=n!=="loading"&&n!=="provisioning"&&t.agent_id.trim()!==""&&t.endpoint.trim()!==""&&(t.provision_wallet||t.stellar_address.trim()!=="");return l.jsx("div",{className:"max-w-xl mx-auto",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-6",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[l.jsx(bf,{size:18,className:"text-purple-400"}),l.jsx("h2",{className:"text-base font-semibold text-gray-200",children:"Register Agent"})]}),n==="success"?l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-start gap-3 bg-green-950 border border-green-800 rounded-lg p-4",children:[l.jsx(Tc,{size:16,className:"text-green-400 mt-0.5 shrink-0"}),l.jsx("p",{className:"text-sm text-green-300",children:i})]}),o&&l.jsxs("div",{className:"bg-yellow-950 border border-yellow-700 rounded-lg p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Cc,{size:14,className:"text-yellow-400"}),l.jsx("span",{className:"text-sm font-medium text-yellow-300",children:"Wallet provisioned — save your secret key now"})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-gray-400 mb-1",children:"Public Key"}),l.jsx("div",{className:"font-mono text-xs text-gray-300 bg-gray-800 rounded px-2 py-1.5 break-all",children:o.publicKey})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-gray-400 mb-1",children:"Secret Key (save this — shown once)"}),l.jsx("div",{className:"font-mono text-xs text-red-300 bg-gray-800 rounded px-2 py-1.5 break-all border border-red-900",children:o.secretKey}),l.jsxs("button",{onClick:v,className:"mt-1.5 flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[l.jsx(v1,{size:11}),h?"Copied!":"Copy secret key"]})]}),o.explorerUrl&&l.jsxs("a",{href:o.explorerUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs text-blue-400 hover:text-blue-300 transition-colors",children:[l.jsx(Xr,{size:11}),"View sponsorship on stellar.expert"]})]}),l.jsxs("button",{onClick:g,className:"w-full flex items-center justify-center gap-2 bg-gray-800 hover:bg-gray-700 text-gray-200 text-sm font-medium rounded-lg px-4 py-2.5 transition-colors",children:[l.jsx(Qa,{size:14}),"Register Another Agent"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-3",children:[[{key:"agent_id",label:"Agent ID",placeholder:"my-agent (lowercase, hyphens ok)"},{key:"name",label:"Display Name",placeholder:"MyBot"},{key:"endpoint",label:"Endpoint URL",placeholder:"https://my-server.com/query"},{key:"health_check",label:"Health Check URL (optional)",placeholder:"auto-derived from endpoint if blank"}].map(({key:K,label:D,placeholder:T})=>l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:D}),l.jsx("input",{type:"text",value:t[K],onChange:z=>y(K,z.target.value),placeholder:T,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]},K)),l.jsxs("div",{className:"bg-gray-800 border border-gray-700 rounded-lg p-3 space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("input",{type:"checkbox",id:"provision_wallet",checked:t.provision_wallet,onChange:K=>y("provision_wallet",K.target.checked),className:"accent-purple-500"}),l.jsx("label",{htmlFor:"provision_wallet",className:"text-xs text-gray-300 cursor-pointer",children:"Provision a Stellar wallet for me (sponsored — free, USDC-ready)"})]}),!t.provision_wallet&&l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Stellar Address (G...)"}),l.jsx("input",{type:"text",value:t.stellar_address,onChange:K=>y("stellar_address",K.target.value),placeholder:"G... (56 characters)",className:"w-full bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]}),t.provision_wallet&&l.jsx("p",{className:"text-xs text-gray-500",children:"A new Stellar account will be created and sponsored. The secret key will be shown after registration — save it immediately."})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Description"}),l.jsx("textarea",{value:t.description,onChange:K=>y("description",K.target.value),placeholder:"What does your agent do?",rows:2,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 resize-none focus:outline-none focus:border-purple-500"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Capabilities (comma-separated)"}),l.jsx("input",{type:"text",value:t.capabilities,onChange:K=>y("capabilities",K.target.value),placeholder:"news, translation, data-analysis",className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Payment Model"}),l.jsxs("select",{value:t.payment_model,onChange:K=>y("payment_model",K.target.value),className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 focus:outline-none focus:border-purple-500",children:[l.jsx("option",{value:"x402",children:"x402"}),l.jsx("option",{value:"mpp",children:"MPP"})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Price per call (USDC)"}),l.jsx("input",{type:"number",value:t.price_per_call,onChange:K=>y("price_per_call",K.target.value),step:.001,min:0,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 focus:outline-none focus:border-purple-500"})]})]})]}),n==="error"&&l.jsxs("div",{className:"mt-4 flex items-start gap-2 bg-red-950 border border-red-800 rounded-lg p-3",children:[l.jsx(Jg,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),l.jsx("span",{className:"text-sm text-red-300",children:i})]}),l.jsxs("div",{className:"mt-4 flex gap-2",children:[(n==="error"||t.agent_id)&&l.jsx("button",{onClick:g,className:"px-4 py-2.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 text-sm transition-colors",children:"Clear"}),l.jsx("button",{onClick:M,disabled:!k,className:"flex-1 bg-purple-600 hover:bg-purple-500 disabled:bg-gray-700 disabled:text-gray-500 disabled:cursor-not-allowed text-white text-sm font-medium rounded-lg px-4 py-2.5 transition-colors",children:n==="provisioning"?"Provisioning wallet...":n==="loading"?"Registering...":t.provision_wallet?"Provision Wallet & Register":"Register Agent"})]})]}),l.jsx("div",{className:"mt-4 pt-4 border-t border-gray-800",children:l.jsxs("p",{className:"text-xs text-gray-600",children:["Your agent must implement ",l.jsx("code",{className:"text-gray-500",children:"GET /health"})," and at least one x402 or MPP protected endpoint. It will be available for task assignment immediately after registration."]})})]})})}const Ta="";async function tM(e,t,r){return(await fetch(`${Ta}/api/tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({task:e,budget:t,user_address:r})})).json()}async function q6(){return(await(await fetch(`${Ta}/api/agents`)).json()).agents??[]}async function rM(e){return(await fetch(`${Ta}/api/tasks/${e}/approve`,{method:"POST"})).json()}async function nM(e){return(await fetch(`${Ta}/api/tasks/${e}/reject`,{method:"POST"})).json()}async function aM(e){const t=await fetch(`${Ta}/api/orchestrators/usdc-trustline`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e})}),r=await t.json();if(!t.ok)throw new Error(r.error??"Failed to build XDR");return r.xdr}async function iM(e){const t=await fetch(`${Ta}/api/orchestrators/usdc-trustline/confirm`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({signed_xdr:e})}),r=await t.json();if(!t.ok)throw new Error(r.error??"Failed to submit");return r.tx_hash}async function sM(e,t,r){const n=await fetch(`http://localhost:4000/agents/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,requester_address:r})}),a=await n.json();if(!n.ok)throw new Error(a.error??"Rename failed");return a}async function oM(e,t){const r=await fetch("/api/orchestrators/rename",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,name:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Rename failed");return n}async function lM(e,t){const r=await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({requester_address:t})}),n=await r.json().catch(()=>({}));if(!r.ok)throw new Error(n.error??"Delete failed");return!0}async function cM(e){return(await(await fetch(`${Ta}/api/vault/ledger/${encodeURIComponent(e)}`)).json()).entries??[]}async function uM(e){return(await(await fetch(`${Ta}/api/tasks/history/${encodeURIComponent(e)}`)).json()).results??[]}async function fM(e,t){return(await fetch(`${Ta}/api/tasks/history/${encodeURIComponent(e)}?user_address=${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function dM(e,t){const r=await fetch(`${Ta}/api/vault/force-complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,vault_task_id:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Force complete failed");return n}function wl({value:e,label:t}){const r=Math.round(e*100),n=r>=70?"bg-emerald-500":r>=40?"bg-amber-500":"bg-red-500";return l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx("span",{className:"text-xs text-gray-500 w-32 shrink-0",children:t}),l.jsx("div",{className:"flex-1 h-1 bg-gray-700 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${n} rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),l.jsxs("span",{className:"text-xs text-gray-400 w-8 text-right tabular-nums",children:[r,"%"]})]})}function hM(e){return e>=.7?"text-emerald-400":e>=.4?"text-amber-400":"text-red-400"}function pM(e){return e>=.7?"bg-emerald-950 border-emerald-800 text-emerald-400":e>=.4?"bg-amber-950 border-amber-800 text-amber-400":"bg-red-950 border-red-800 text-red-400"}function bM({plan:e,onDismiss:t,orchestratorName:r="Your Agent"}){const n=Math.ceil(e.auto_approve_in_ms/1e3),[a,i]=re.useState(n),[s,o]=re.useState(null),[c,h]=re.useState(null),p=re.useRef(!1),y=async()=>{if(s===null){o("approve");try{await rM(e.task_id)}catch{}t()}},g=async()=>{if(s===null){o("reject");try{await nM(e.task_id)}catch{}t()}};re.useEffect(()=>{if(s!==null)return;const k=setInterval(()=>{i(K=>Math.max(0,K-1))},1e3);return()=>clearInterval(k)},[s]),re.useEffect(()=>{a===0&&!p.current&&s===null&&(p.current=!0,y())},[a]);const v=a/n*100,M=v>50?"bg-purple-500":v>20?"bg-amber-500":"bg-red-500";return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-xl bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl flex flex-col max-h-[88vh] overflow-hidden",children:[l.jsxs("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx(ya,{size:16,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsxs("span",{className:"text-xs font-semibold text-purple-400 uppercase tracking-widest",children:[r,"'s Plan"]}),l.jsx("span",{className:"text-xs text-gray-600",children:"·"}),l.jsxs("span",{className:"text-xs text-gray-500",children:[e.steps.length," steps"]})]}),l.jsx("h2",{className:"text-sm font-semibold text-white leading-snug line-clamp-2",children:e.task})]}),l.jsxs("div",{className:"text-right shrink-0",children:[l.jsxs("div",{className:"text-xl font-bold text-white tabular-nums",children:["$",e.total_estimated_cost.toFixed(3)]}),l.jsx("div",{className:"text-xs text-gray-500",children:"USDC budget"})]})]}),e.reasoning&&l.jsx("p",{className:"text-xs text-gray-500 mt-3 leading-relaxed",children:e.reasoning})]}),l.jsxs("div",{className:"px-5 py-3 bg-gray-950/50 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[l.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1.5",children:[l.jsx(ha,{size:10}),s===null?a>0?`Auto-approving in ${a}s — plan is within your budget`:"Auto-approving…":s==="approve"?"Approving plan…":"Rejecting plan…"]}),l.jsxs("span",{className:"text-xs font-mono text-gray-500 tabular-nums",children:[a,"s"]})]}),l.jsx("div",{className:"h-1 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${M} rounded-full transition-all duration-1000 ease-linear`,style:{width:`${v}%`}})})]}),l.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-5 py-3 space-y-2",children:e.steps.map((k,K)=>l.jsxs("div",{className:"border border-gray-800 rounded-xl overflow-hidden",children:[l.jsxs("button",{className:"w-full text-left px-4 py-3 flex items-start gap-3 hover:bg-gray-800/50 transition-colors",onClick:()=>h(c===k.step_id?null:k.step_id),children:[l.jsx("div",{className:"w-5 h-5 rounded-full bg-gray-800 border border-gray-700 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx("span",{className:"text-xs font-mono text-gray-400",children:K+1})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-200",children:k.agent_name}),l.jsx("span",{className:`text-xs font-mono px-1.5 py-px rounded border text-xs leading-none ${pM(k.selected_score)}`,children:Math.round(k.selected_score*100)}),k.alternatives.length>0&&l.jsxs("span",{className:"text-xs text-gray-600 hidden sm:block",children:["beat ",k.alternatives[0].name," (",Math.round(k.alternatives[0].score*100),")"]})]}),l.jsx("p",{className:"text-xs text-gray-500 line-clamp-1 leading-relaxed",children:k.action})]}),l.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[l.jsxs("div",{className:"text-right",children:[l.jsxs("div",{className:"text-xs font-mono font-semibold text-gray-300",children:["$",k.estimated_cost.toFixed(3)]}),l.jsx("div",{className:"text-xs text-gray-600 uppercase",children:k.payment_method})]}),l.jsx(Ds,{size:13,className:`text-gray-600 transition-transform duration-200 ${c===k.step_id?"rotate-180":""}`})]})]}),c===k.step_id&&l.jsxs("div",{className:"px-4 pb-4 pt-1 bg-gray-950/50 border-t border-gray-800 space-y-4",children:[k.score_breakdown&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Score Breakdown"}),l.jsx(wl,{value:k.score_breakdown.capability_match,label:"Capability match"}),l.jsx(wl,{value:k.score_breakdown.reputation,label:"Reputation"}),l.jsx(wl,{value:k.score_breakdown.price_efficiency,label:"Price efficiency"}),l.jsx(wl,{value:k.score_breakdown.latency_score,label:"Latency"}),l.jsx(wl,{value:k.score_breakdown.discovery_bonus,label:"Discovery bonus"})]}),k.alternatives.length>0&&l.jsxs("div",{children:[l.jsxs("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wider mb-2 flex items-center gap-1",children:[l.jsx(ow,{size:10})," Alternatives"]}),l.jsx("div",{className:"space-y-1",children:k.alternatives.map(D=>l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-xs text-gray-400",children:D.name}),l.jsx("span",{className:`text-xs font-mono font-semibold ${hM(D.score)}`,children:Math.round(D.score*100)})]},D.agent_id))})]})]})]},k.step_id))}),l.jsxs("div",{className:"px-5 py-4 border-t border-gray-800 flex gap-3",children:[l.jsxs("button",{onClick:g,disabled:s!==null,className:"flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-750 border border-gray-700 text-gray-300 hover:text-white text-sm font-medium transition-all disabled:opacity-40",children:[l.jsx(En,{size:14,className:"text-red-400"}),"Reject"]}),l.jsxs("button",{onClick:y,disabled:s!==null,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white text-sm font-semibold transition-all disabled:opacity-40 shadow-lg shadow-purple-900/30",children:[l.jsx(mr,{size:14}),s==="approve"?"Approving…":"Approve & Run"]})]})]})})}const mM="CDFLEJ2HFPK3WKFTWB4CKP2JHEYNAUWKXGEJRYW4YMMGDSQSQ7D4LRTE",Dx=`https://stellar.expert/explorer/testnet/contract/${mM}`;function xM(e){var i,s,o,c;const t=e.find(h=>h.event==="budget_locked");if(!t)return null;const r=e.filter(h=>h.event==="budget_released").map(h=>{var p,y,g;return{agent_name:((p=h.data)==null?void 0:p.agent_name)??"",amount:((y=h.data)==null?void 0:y.amount)??0,tx_hash:((g=h.data)==null?void 0:g.tx_hash)??""}}),n=e.find(h=>h.event==="budget_finalized"),a=((i=n==null?void 0:n.data)==null?void 0:i.total_spent)??r.reduce((h,p)=>h+p.amount,0);return{vault_task_id:((s=t.data)==null?void 0:s.contract_task_id)??null,plan_cost_usdc:((o=t.data)==null?void 0:o.budget_usdc)??0,spent_usdc:a,releases:r,completed:!!n,refund_usdc:((c=n==null?void 0:n.data)==null?void 0:c.refund_usdc)??0}}function yM({events:e}){const t=xM(e);if(!t)return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(wn,{size:14,className:"text-gray-600"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-500",children:"Vault Activity"}),l.jsx("a",{href:Dx,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-700 hover:text-gray-500 transition-colors",children:l.jsx(Xr,{size:10})})]}),l.jsx("p",{className:"text-xs text-gray-700 text-center py-3",children:"No active task"})]});const r=t.plan_cost_usdc>0?Math.min(100,t.spent_usdc/t.plan_cost_usdc*100):0,n=r>=90?"bg-red-500":r>=70?"bg-amber-500":"bg-purple-500";return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[l.jsx(wn,{size:14,className:t.completed?"text-gray-500":"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Vault Activity"}),t.vault_task_id!==null&&l.jsxs("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded-md",children:["#",t.vault_task_id]}),l.jsx("a",{href:Dx,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(Xr,{size:10})})]}),l.jsx("div",{className:"flex items-center gap-1.5 text-xs mb-3",children:t.completed?l.jsx("span",{className:"text-gray-600",children:"finalized"}):l.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-lg bg-amber-950/40 border border-amber-900/40",children:[l.jsx(Wg,{size:9,className:"text-amber-400"}),l.jsxs("span",{className:"text-amber-400 font-mono",children:["$",t.plan_cost_usdc.toFixed(4)," locked"]})]})}),l.jsxs("div",{className:"mb-3",children:[l.jsxs("div",{className:"flex justify-between text-xs mb-1.5",children:[l.jsxs("span",{className:"text-gray-400 font-mono",children:["$",t.spent_usdc.toFixed(4)," released"]}),l.jsxs("span",{className:"text-gray-600 font-mono",children:["of $",t.plan_cost_usdc.toFixed(4)]})]}),l.jsx("div",{className:"h-1.5 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${n} rounded-full transition-all duration-700`,style:{width:`${r}%`}})})]}),t.releases.length>0&&l.jsx("div",{className:"space-y-1.5 mb-3",children:t.releases.map((a,i)=>l.jsxs("div",{className:"flex items-center gap-2 text-xs bg-gray-800/50 rounded-lg px-2.5 py-1.5",children:[l.jsx(Qg,{size:10,className:"text-purple-400 shrink-0"}),l.jsx("span",{className:"text-gray-400 truncate",children:a.agent_name}),l.jsxs("span",{className:"text-purple-300 font-mono ml-auto shrink-0",children:["$",a.amount.toFixed(4)]}),a.tx_hash&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${a.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",children:l.jsx(Xr,{size:9})})]},i))}),t.completed&&l.jsxs("div",{className:"pt-2.5 border-t border-gray-800 space-y-1.5",children:[l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-emerald-400",children:[l.jsx(mr,{size:11}),l.jsx("span",{children:"Finalized on-chain"})]}),t.refund_usdc>1e-6&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 pl-4",children:[l.jsx(X8,{size:9}),l.jsxs("span",{children:["$",t.refund_usdc.toFixed(4)," refunded to vault"]})]})]})]})}const gM="CDFLEJ2HFPK3WKFTWB4CKP2JHEYNAUWKXGEJRYW4YMMGDSQSQ7D4LRTE",Ix="Test SDF Network ; September 2015",vM=[1,5,10,20],yu={amount:"",status:"idle",error:null,txHash:null};function Lx(e){const t=(e==null?void 0:e.message)??String(e);return/user declined|rejected|denied|cancel/i.test(t)?"Transaction rejected. Try again when ready.":/simulation failed/i.test(t)?"Simulation failed — check your vault balance and try again.":t.slice(0,120)}function wM({forceOpenFund:e,onFundOpened:t,onDepositSuccess:r,onWithdrawSuccess:n,onError:a}={}){const{publicKey:i,signTransaction:s}=On(),[o,c]=re.useState(null),[h,p]=re.useState(!0),[y,g]=re.useState("none"),[v,M]=re.useState(yu),k=re.useCallback(async()=>{if(i)try{const F=await sb(i);c(F)}catch{}finally{p(!1)}},[i]);re.useEffect(()=>{if(!i)return;k();const F=setInterval(k,8e3);return()=>clearInterval(F)},[k]),re.useEffect(()=>{e&&y==="none"&&(g("fund"),M(yu),t==null||t())},[e]);const K=F=>{g(F),M(yu)},D=()=>{v.status==="signing"||v.status==="submitting"||(g("none"),M(yu),v.status==="success"&&k())},T=async()=>{if(!i)return;const F=parseFloat(v.amount);if(!(!F||F<=0))try{M(te=>({...te,status:"building",error:null}));const V=await zT(i,F);M(te=>({...te,status:"signing"}));const J=await s(V,Ix);M(te=>({...te,status:"submitting"}));const Y=await kx(J,{user_address:i,tx_type:"deposit",amount:F});M(te=>({...te,status:"success",txHash:Y})),k(),r==null||r()}catch(V){const J=Lx(V);M(Y=>({...Y,status:"error",error:J})),a==null||a(J)}},z=async()=>{if(!i)return;const F=parseFloat(v.amount);if(!F||F<=0)return;const V=(o==null?void 0:o.available)??0;if(!(F>V))try{M(x=>({...x,status:"building",error:null}));const J=await DT(i,F);M(x=>({...x,status:"signing"}));const Y=await s(J,Ix);M(x=>({...x,status:"submitting"}));const te=await kx(Y,{user_address:i,tx_type:"withdrawal",amount:F});M(x=>({...x,status:"success",txHash:te})),k(),n==null||n()}catch(J){const Y=Lx(J);M(te=>({...te,status:"error",error:Y})),a==null||a(Y)}},L=v.status==="building"||v.status==="signing"||v.status==="submitting",$=!o||o.available<=0||o.active_tasks_count>0;return i?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[l.jsx(cw,{size:16,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"CleverVault"}),l.jsx("a",{href:`https://stellar.expert/explorer/testnet/contract/${gM}`,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-600 hover:text-gray-400 transition-colors",title:"View contract on Stellar Expert",children:l.jsx(Xr,{size:12})})]}),h?l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 py-3 justify-center",children:[l.jsx(Qa,{size:11,className:"animate-spin"}),l.jsx("span",{children:"Loading vault…"})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-gray-800 rounded-xl p-4 mb-3",children:[l.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Total Balance"}),l.jsxs("div",{className:"flex items-baseline gap-1.5",children:[l.jsx("span",{className:"text-2xl font-mono font-bold text-white",children:o?o.balance.toFixed(2):"0.00"}),l.jsx("span",{className:"text-sm text-gray-400",children:"USDC"})]}),o&&o.locked>0&&l.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-amber-400",children:[l.jsx(Wg,{size:10}),l.jsxs("span",{children:[o.locked.toFixed(4)," USDC locked in active task"]})]}),l.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-gray-700",children:[l.jsxs("div",{className:"text-xs",children:[l.jsx("p",{className:"text-gray-500",children:"Available"}),l.jsxs("p",{className:"text-green-400 font-mono font-semibold",children:["$",o?o.available.toFixed(2):"0.00"]})]}),o&&(o.total_deposited>0||o.total_spent>0)&&l.jsxs("div",{className:"text-right text-xs",children:[l.jsx("p",{className:"text-gray-500",children:"Lifetime spent"}),l.jsxs("p",{className:"text-gray-400 font-mono",children:["$",o.total_spent.toFixed(4)]})]})]})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[l.jsxs("button",{onClick:()=>K("fund"),className:"flex items-center justify-center gap-1.5 bg-purple-600 hover:bg-purple-500 text-white text-xs font-medium rounded-lg px-3 py-2 transition-colors",children:[l.jsx(Fl,{size:12}),"Fund"]}),l.jsxs("button",{onClick:()=>K("withdraw"),disabled:$,title:o!=null&&o.active_tasks_count?"Cannot withdraw while a task is running":(o==null?void 0:o.available)===0?"No available balance":void 0,className:"flex items-center justify-center gap-1.5 bg-gray-700 hover:bg-gray-600 disabled:opacity-40 disabled:cursor-not-allowed text-gray-200 text-xs font-medium rounded-lg px-3 py-2 transition-colors",children:[l.jsx(nw,{size:12}),"Withdraw"]})]}),o!=null&&o.active_tasks_count?l.jsx("p",{className:"text-xs text-amber-400 text-center mt-2",children:"Withdrawal locked — task in progress"}):null]})]}),y==="fund"&&l.jsx(qx,{title:"Fund CleverVault",subtitle:"Deposit USDC from your Freighter wallet into the smart contract",amountLabel:"Deposit amount (USDC)",confirmLabel:L?Hx(v.status):"Deposit",amount:v.amount,maxAmount:void 0,status:v.status,error:v.error,txHash:v.txHash,onAmountChange:F=>M(V=>({...V,amount:F,error:null})),onConfirm:T,onClose:D}),y==="withdraw"&&l.jsx(qx,{title:"Withdraw from CleverVault",subtitle:`Available: $${(o==null?void 0:o.available.toFixed(2))??"0.00"} USDC`,amountLabel:"Withdraw amount (USDC)",confirmLabel:L?Hx(v.status):"Withdraw",amount:v.amount,maxAmount:o==null?void 0:o.available,status:v.status,error:v.error,txHash:v.txHash,onAmountChange:F=>M(V=>({...V,amount:F,error:null})),onConfirm:z,onClose:D})]}):null}function Hx(e){return e==="building"?"Building transaction…":e==="signing"?"Sign in Freighter…":e==="submitting"?"Submitting…":""}function qx({title:e,subtitle:t,amountLabel:r,confirmLabel:n,amount:a,maxAmount:i,status:s,error:o,txHash:c,onAmountChange:h,onConfirm:p,onClose:y}){const g=s==="building"||s==="signing"||s==="submitting",v=s==="success",M=parseFloat(a),k=!isNaN(M)&&M>0&&(i===void 0||M<=i);return l.jsx("div",{className:"fixed inset-0 bg-black/70 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-2xl w-full max-w-sm shadow-2xl",children:[l.jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-3",children:[l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-semibold text-white",children:e}),l.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:t})]}),!g&&l.jsx("button",{onClick:y,className:"text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(xa,{size:16})})]}),l.jsx("div",{className:"px-5 pb-5 space-y-4",children:v?l.jsxs("div",{className:"text-center py-4 space-y-3",children:[l.jsx("div",{className:"w-12 h-12 bg-green-900/40 rounded-full flex items-center justify-center mx-auto",children:l.jsx(mr,{size:24,className:"text-green-400"})}),l.jsxs("div",{children:[l.jsx("p",{className:"text-sm font-semibold text-white",children:"Transaction complete"}),c&&l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/tx/${c}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-purple-400 hover:text-purple-300 flex items-center gap-1 justify-center mt-1",children:["View on Stellar Expert ",l.jsx(Xr,{size:10})]})]}),l.jsx("button",{onClick:y,className:"w-full bg-gray-700 hover:bg-gray-600 text-white text-sm font-medium rounded-xl px-4 py-2.5 transition-colors",children:"Close"})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-500 mb-2",children:r}),l.jsx("div",{className:"grid grid-cols-4 gap-1.5 mb-2",children:vM.map(K=>l.jsxs("button",{onClick:()=>h(String(K)),disabled:i!==void 0&&K>i,className:"text-xs bg-gray-800 hover:bg-gray-700 disabled:opacity-30 text-gray-300 rounded-lg py-1.5 transition-colors border border-gray-700 hover:border-gray-600",children:["$",K]},K))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 text-sm",children:"$"}),l.jsx("input",{type:"number",min:"0.01",step:"0.01",max:i,value:a,onChange:K=>h(K.target.value),placeholder:"0.00",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500 rounded-xl pl-7 pr-14 py-2.5 text-sm text-white placeholder-gray-600 outline-none transition-colors"}),l.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:"USDC"})]}),i!==void 0&&M>i&&l.jsxs("p",{className:"text-xs text-red-400 mt-1",children:["Exceeds available balance ($",i.toFixed(2),")"]})]}),o&&l.jsx("div",{className:"bg-red-900/30 border border-red-800/50 rounded-lg px-3 py-2",children:l.jsx("p",{className:"text-xs text-red-400",children:o})}),g&&l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:[l.jsx(Qa,{size:11,className:"animate-spin"}),l.jsx("span",{children:n})]}),l.jsx("button",{onClick:p,disabled:g||!k,className:"w-full bg-purple-600 hover:bg-purple-500 disabled:opacity-40 disabled:cursor-not-allowed text-white text-sm font-semibold rounded-xl px-4 py-2.5 transition-colors",children:g?"…":n})]})})]})})}const _M="https://horizon-testnet.stellar.org",SM="GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";async function EM(e,t){try{const r=await fetch(`${_M}/accounts/${e}`);if(r.status===404)return{address:e,label:t,xlm:"0.00",usdc:null,loading:!1,error:!1};if(!r.ok)throw new Error(`HTTP ${r.status}`);const a=(await r.json()).balances??[],i=a.find(h=>h.asset_type==="native"),s=a.find(h=>h.asset_code==="USDC"&&h.asset_issuer===SM),o=i?parseFloat(i.balance).toFixed(2):"0.00",c=s?parseFloat(s.balance).toFixed(4):null;return{address:e,label:t,xlm:o,usdc:c,loading:!1,error:!1}}catch{return{address:e,label:t,xlm:"—",usdc:null,loading:!1,error:!0}}}function $6(e){const[t,r]=re.useState(()=>e.map(a=>({...a,xlm:"…",usdc:null,loading:!0,error:!1}))),n=e.map(a=>a.address).join(",");return re.useEffect(()=>{if(e.length===0){r([]);return}r(e.map(o=>({...o,xlm:"…",usdc:null,loading:!0,error:!1})));let a=!1;const i=async()=>{const o=await Promise.all(e.map(c=>EM(c.address,c.label)));a||r(o)};i();const s=setInterval(i,1e4);return()=>{a=!0,clearInterval(s)}},[n]),t}const AM="https://stellar.expert/explorer/testnet/account";function NM({text:e}){const[t,r]=re.useState(!1);return l.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},className:"text-gray-700 hover:text-gray-400 transition-colors",title:"Copy address",children:t?l.jsx(Tc,{size:10,className:"text-emerald-400"}):l.jsx(v1,{size:10})})}function jM(){const{publicKey:e,signTransaction:t}=On(),[r,n]=re.useState(!1),[a,i]=re.useState(null),s=e?[{address:e,label:"Your Wallet"}]:[],[o]=$6(s),c=o&&!o.loading&&!o.error&&o.usdc===null,h=async()=>{if(e){n(!0),i(null);try{const p=await aM(e),y=await t(p,"Test SDF Network ; September 2015");await iM(y)}catch(p){const y=(p==null?void 0:p.message)??String(p);i(/declined|rejected|denied|cancel/i.test(y)?"Transaction rejected. Try again when ready.":y.slice(0,100))}finally{n(!1)}}};return e?l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(Cc,{size:14,className:"text-emerald-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Your Wallet"}),l.jsx("span",{className:"text-xs text-gray-600 ml-auto",children:"Testnet"})]}),l.jsxs("div",{className:"px-4 py-3",children:[l.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[l.jsxs("span",{className:"text-xs font-mono text-gray-600 flex-1 truncate",children:[e.slice(0,6),"…",e.slice(-4)]}),l.jsx(NM,{text:e}),l.jsx("a",{href:`${AM}/${e}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(Xr,{size:10})})]}),o!=null&&o.loading?l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-700",children:[l.jsx(Qa,{size:9,className:"animate-spin"}),l.jsx("span",{children:"Loading…"})]}):o!=null&&o.error?l.jsx("p",{className:"text-xs text-red-500",children:"Failed to load balances"}):l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"XLM"}),l.jsx("p",{className:"text-sm font-mono font-bold text-emerald-400",children:(o==null?void 0:o.xlm)??"—"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"USDC"}),(o==null?void 0:o.usdc)!==null?l.jsx("p",{className:"text-sm font-mono font-bold text-blue-400",children:o==null?void 0:o.usdc}):l.jsx("p",{className:"text-xs text-gray-600 italic",children:"No trustline"})]})]}),c&&l.jsxs("div",{className:"mt-3",children:[a&&l.jsx("p",{className:"text-xs text-red-400 mb-1.5",children:a}),l.jsxs("button",{onClick:h,disabled:r,className:"w-full flex items-center justify-center gap-1.5 text-xs text-blue-400 hover:text-blue-300 bg-blue-950/30 hover:bg-blue-950/50 border border-blue-900/50 rounded-xl px-3 py-2 transition-all disabled:opacity-50",children:[r?l.jsx(Qa,{size:10,className:"animate-spin"}):l.jsx(Fl,{size:10}),r?"Adding…":"Add USDC Trustline"]})]})]})]}):null}const F6=re.createContext(null);function TM({children:e}){const{publicKey:t}=On(),[r,n]=re.useState(null),[a,i]=re.useState(!0),s=re.useCallback(async()=>{if(!t){i(!1);return}i(!0);try{const o=await fetch(`/api/orchestrators/${encodeURIComponent(t)}`);if(!o.ok)throw new Error("Failed to fetch");const c=await o.json();n(c.exists?{name:c.name,pubkey:c.pubkey,registered_on_chain:c.registered_on_chain,system_prompt:c.system_prompt}:null)}catch{n(null)}finally{i(!1)}},[t]);return re.useEffect(()=>{s()},[s]),l.jsx(F6.Provider,{value:{orchestrator:r,isLoading:a,refresh:s},children:e})}function Kc(){const e=re.useContext(F6);if(!e)throw new Error("useOrchestrator must be used within OrchestratorProvider");return e}const MM=new Set(["stellar-oracle","web-intel-v1","web-intel-v2","analysis-agent","reporter-agent"]),CM=["x402","mpp"],BM=[{label:"Any",min:0},{label:"50+",min:50},{label:"70+",min:70},{label:"90+",min:90}];function OM(e){return e>=80?"text-emerald-400 bg-emerald-950/60 border-emerald-900":e>=50?"text-amber-400 bg-amber-950/60 border-amber-900":"text-red-400 bg-red-950/60 border-red-900"}function RM(e){return e==="x402"?"bg-blue-950/60 border-blue-900/60 text-blue-400":"bg-violet-950/60 border-violet-900/60 text-violet-400"}function $x(e){const t=Date.now()-new Date(e).getTime(),r=Math.floor(t/6e4);if(r<2)return"just now";if(r<60)return`${r}m ago`;const n=Math.floor(r/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function UM({agent:e,requesterAddress:t,onDone:r}){const[n,a]=re.useState(e.name),[i,s]=re.useState(!1),[o,c]=re.useState(""),h=async()=>{const p=n.trim();if(!p||p===e.name){r();return}s(!0);try{await sM(e.agent_id,p,t),r(p)}catch(y){c(y.message??"Failed"),s(!1)}};return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{autoFocus:!0,value:n,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key==="Enter"&&h(),p.key==="Escape"&&r()},className:"flex-1 bg-gray-800 border border-purple-600/50 rounded-lg px-2 py-1 text-xs text-white outline-none"}),l.jsx("button",{onClick:h,disabled:i||!n.trim(),className:"p-1 text-emerald-400 hover:text-emerald-300 disabled:opacity-40 transition-colors",children:l.jsx(Tc,{size:12})}),l.jsx("button",{onClick:()=>r(),className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(xa,{size:12})})]}),o&&l.jsx("p",{className:"text-xs text-red-400",children:o})]})}function Fx({agent:e,isMine:t,requesterAddress:r,onRename:n,onDelete:a}){var k,K,D,T;const[i,s]=re.useState(!1),[o,c]=re.useState(!1),[h,p]=re.useState(!1),[y,g]=re.useState(!1),v=MM.has(e.agent_id),M=async()=>{g(!0);try{await lM(e.agent_id,r),a(e.agent_id)}catch{}g(!1),p(!1)};return l.jsxs("div",{className:`bg-gray-900 border rounded-xl overflow-hidden transition-colors ${t?"border-purple-800/50":"border-gray-800"}`,children:[l.jsx("div",{className:"px-4 py-3",children:l.jsxs("div",{className:"flex items-start gap-2.5",children:[l.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${t?"bg-purple-600/20 border border-purple-600/30":"bg-gray-800 border border-gray-700"}`,children:l.jsx(jc,{size:14,className:t?"text-purple-400":"text-gray-500"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[o?l.jsx(UM,{agent:e,requesterAddress:r,onDone:z=>{z&&n(e.agent_id,z),c(!1)}}):l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[l.jsx("span",{className:"text-sm font-semibold text-gray-100",children:e.name}),t&&l.jsx("span",{className:"text-xs px-1.5 py-px rounded bg-purple-950/60 border border-purple-800/60 text-purple-400 leading-none",children:"mine"}),l.jsx("span",{className:`text-xs font-mono px-1.5 py-px rounded border leading-none ${OM(((k=e.reputation)==null?void 0:k.score)??50)}`,children:(((K=e.reputation)==null?void 0:K.score)??50).toFixed(0)}),l.jsx("span",{className:`text-xs px-1.5 py-px rounded border leading-none uppercase font-medium ${RM(e.pricing.model)}`,children:e.pricing.model})]}),!o&&l.jsxs("div",{className:"flex items-center gap-3 mt-1 flex-wrap",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(ya,{size:9,className:"text-purple-500"}),l.jsxs("span",{className:"font-mono",children:["$",e.pricing.price_per_call.toFixed(3),"/call"]})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(rv,{size:9,className:"text-yellow-600"}),l.jsx("span",{children:(((D=e.reputation)==null?void 0:D.avg_quality)??0).toFixed(1)}),l.jsx("span",{className:"text-gray-700",children:"·"}),l.jsxs("span",{children:[((T=e.reputation)==null?void 0:T.total_jobs)??0," jobs"]})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-700",children:[l.jsx(ha,{size:8}),l.jsx("span",{children:$x(e.last_seen)})]})]})]}),l.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[t&&!o&&l.jsx("button",{onClick:()=>c(!0),className:"p-1.5 text-gray-700 hover:text-gray-300 rounded-lg hover:bg-gray-800 transition-all",title:"Rename",children:l.jsx(Vf,{size:11})}),l.jsx("button",{onClick:()=>s(z=>!z),className:"p-1.5 text-gray-700 hover:text-gray-400 rounded-lg hover:bg-gray-800 transition-all",children:i?l.jsx(Mc,{size:11}):l.jsx(Ds,{size:11})}),t&&!v&&!o&&(h?l.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[l.jsx("button",{onClick:M,disabled:y,className:"text-xs px-2 py-1 rounded-lg bg-red-950 text-red-400 border border-red-900 hover:bg-red-900 transition-colors",children:y?"…":"Remove"}),l.jsx("button",{onClick:()=>p(!1),className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(xa,{size:11})})]}):l.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-gray-700 hover:text-red-400 rounded-lg hover:bg-gray-800 transition-all",title:"Remove",children:l.jsx(nv,{size:11})}))]})]})}),i&&l.jsxs("div",{className:"px-4 pb-4 border-t border-gray-800 space-y-3 pt-3",children:[e.description&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1",children:"About"}),l.jsx("p",{className:"text-xs text-gray-400 leading-relaxed",children:e.description})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Stats"}),l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Success rate"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.total_jobs>0?`${(e.reputation.successful_jobs/e.reputation.total_jobs*100).toFixed(0)}%`:"—"})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Avg latency"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.avg_latency_ms>0?`${(e.reputation.avg_latency_ms/1e3).toFixed(1)}s`:"—"})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Failed jobs"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.failed_jobs})]})]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Details"}),l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Status"}),l.jsx("span",{className:`font-mono ${e.status==="active"?"text-emerald-400":"text-gray-500"}`,children:e.status})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Registered"}),l.jsx("span",{className:"text-gray-400",children:$x(e.registered_at)})]})]})]})]}),e.capabilities.length>0&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1.5",children:"Capabilities"}),l.jsx("div",{className:"flex flex-wrap gap-1",children:e.capabilities.map(z=>l.jsx("span",{className:"text-xs bg-gray-800 text-gray-400 border border-gray-700/60 rounded-md px-1.5 py-0.5 leading-none",children:z},z))})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1.5",children:"Source"}),l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsxs("span",{className:"text-gray-600 font-mono truncate",children:[e.stellar_address.slice(0,8),"…",e.stellar_address.slice(-4)]}),l.jsx("a",{href:`https://stellar.expert/explorer/testnet/account/${e.stellar_address}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-600 hover:text-blue-400 transition-colors shrink-0",title:"View on Stellar Expert",children:l.jsx(Xr,{size:10})})]})]})]})]})}const kM=[{title:"1. Create an agent server",body:"Build an HTTP service that accepts POST /execute with a { task } body and returns { output, cost } JSON. Any language or framework works."},{title:"2. Set up a Stellar wallet",body:"Create a Stellar keypair on testnet for your agent. Fund it with XLM (friendbot) and add a USDC trustline so it can receive payments."},{title:"3. Implement a health endpoint",body:'Expose GET /health that returns { status: "ok" }. CleverCon pings this to verify the agent is reachable before dispatching tasks.'},{title:"4. Choose a payment model",body:"x402: per-request micropayment via HTTP 402. The orchestrator pays per call. mpp: multi-party payment, locked upfront in the vault smart contract."},{title:"5. Register your agent",body:"Use the Register tab to submit your agent manifest: name, description, capabilities, pricing, endpoint, stellar_address, and health_check URL."}];function zM(){const[e,t]=re.useState(null);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(V8,{size:13,className:"text-blue-400"}),l.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"How to set up an agent"})]}),l.jsx("div",{className:"divide-y divide-gray-800",children:kM.map((r,n)=>l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>t(e===n?null:n),className:"w-full flex items-center justify-between px-4 py-3 text-left hover:bg-gray-800/30 transition-colors",children:[l.jsx("span",{className:"text-xs font-medium text-gray-300",children:r.title}),e===n?l.jsx(Mc,{size:11,className:"text-gray-600 shrink-0"}):l.jsx(Ds,{size:11,className:"text-gray-600 shrink-0"})]}),e===n&&l.jsx("div",{className:"px-4 pb-3",children:l.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:r.body})})]},n))}),l.jsx("div",{className:"px-4 py-3 border-t border-gray-800",children:l.jsx("p",{className:"text-xs text-gray-600",children:"Once registered, your agent becomes discoverable in the marketplace and the orchestrator will automatically hire it when its capabilities match a task."})})]})}function DM({onRegisterClick:e}){const{publicKey:t}=On(),{orchestrator:r}=Kc(),[n,a]=re.useState([]),[i,s]=re.useState(!0),[o,c]=re.useState(""),[h,p]=re.useState(null),[y,g]=re.useState(0),v=async()=>{s(!0);try{a(await q6())}catch{}s(!1)};re.useEffect(()=>{v()},[]);const M=re.useMemo(()=>{const $=new Set;return t&&$.add(t),r!=null&&r.pubkey&&$.add(r.pubkey),$},[t,r]),k=$=>M.has($.stellar_address)||!!$.registered_by&&M.has($.registered_by),K=re.useMemo(()=>n.filter(k),[n,M]),D=re.useMemo(()=>{const $=o.toLowerCase();return n.filter(F=>{var V;return!($&&!F.name.toLowerCase().includes($)&&!F.description.toLowerCase().includes($)&&!F.capabilities.some(J=>J.toLowerCase().includes($))||h&&F.pricing.model!==h||(((V=F.reputation)==null?void 0:V.score)??0)D.filter($=>!k($)),[D,M]),z=($,F)=>{a(V=>V.map(J=>J.agent_id===$?{...J,name:F}:J))},L=$=>{a(F=>F.filter(V=>V.agent_id!==$))};return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center",children:[l.jsxs("div",{className:"relative flex-1 max-w-sm",children:[l.jsx(iw,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-600"}),l.jsx("input",{value:o,onChange:$=>c($.target.value),placeholder:"Search agents, capabilities…",className:"w-full bg-gray-900 border border-gray-800 rounded-xl pl-8 pr-3 py-2 text-xs text-gray-200 placeholder-gray-600 outline-none focus:border-purple-600/50 transition-colors"})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[CM.map($=>l.jsx("button",{onClick:()=>p(h===$?null:$),className:`text-xs px-2.5 py-1 rounded-lg border font-medium uppercase transition-all ${h===$?$==="x402"?"bg-blue-950/60 border-blue-700 text-blue-300":"bg-violet-950/60 border-violet-700 text-violet-300":"bg-gray-900 border-gray-800 text-gray-600 hover:text-gray-300 hover:border-gray-700"}`,children:$},$)),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:["Rep:",BM.map($=>l.jsx("button",{onClick:()=>g($.min),className:`px-2 py-1 rounded-lg border transition-all ${y===$.min?"bg-purple-950/60 border-purple-700 text-purple-300":"bg-gray-900 border-gray-800 text-gray-600 hover:text-gray-300"}`,children:$.label},$.min))]}),l.jsx("button",{onClick:v,className:"p-1.5 rounded-lg text-gray-600 hover:text-gray-400 hover:bg-gray-800 transition-all",children:l.jsx(Qa,{size:12,className:i?"animate-spin":""})})]})]}),l.jsxs("div",{className:"grid grid-cols-12 gap-6 items-start",children:[l.jsxs("div",{className:"col-span-12 lg:col-span-8 space-y-5",children:[K.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs text-purple-400 uppercase tracking-widest font-semibold mb-3",children:"My Agents"}),l.jsx("div",{className:"space-y-2",children:K.map($=>{const F=$.registered_by&&M.has($.registered_by)?$.registered_by:$.stellar_address;return l.jsx(Fx,{agent:$,isMine:!0,requesterAddress:F,onRename:z,onDelete:L},$.agent_id)})})]}),l.jsxs("div",{children:[l.jsx("div",{className:"flex items-center justify-between mb-3",children:l.jsxs("h3",{className:"text-xs text-gray-500 uppercase tracking-widest font-semibold",children:["All Agents ",!i&&l.jsxs("span",{className:"text-gray-700",children:["(",T.length,")"]})]})}),i?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx("div",{className:"w-6 h-6 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-600 mt-3",children:"Loading agents…"})]}):T.length===0?l.jsxs("div",{className:"py-12 text-center bg-gray-900 border border-gray-800 rounded-2xl",children:[l.jsx(jc,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsxs("p",{className:"text-xs text-gray-600",children:["No agents found",o?" matching your search":""]})]}):l.jsx("div",{className:"space-y-2",children:T.map($=>l.jsx(Fx,{agent:$,isMine:!1,requesterAddress:"",onRename:z,onDelete:L},$.agent_id))})]})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-4 space-y-4",children:[l.jsxs("div",{className:"bg-gray-900 border border-purple-800/40 rounded-2xl p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(bf,{size:14,className:"text-purple-400"}),l.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"Register an Agent"})]}),l.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:"Have a specialized AI service? Register it to get hired by orchestrators and earn USDC per task."}),l.jsxs("button",{onClick:e,className:"w-full flex items-center justify-center gap-2 text-xs font-semibold py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(bf,{size:12}),"Register Agent"]})]}),l.jsx(zM,{})]})]})]})}const IM="https://stellar.expert/explorer/testnet/tx";function LM(e){return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function HM(e){return e==="deposit"?"Deposit":e==="withdrawal"?"Withdrawal":e==="payment"?"Agent payment":e==="budget_lock"?"Budget locked":e}function qM(e){return e==="deposit"?l.jsx(Qg,{size:12,className:"text-emerald-400"}):e==="withdrawal"?l.jsx(Vh,{size:12,className:"text-red-400"}):e==="payment"?l.jsx(Vh,{size:12,className:"text-purple-400"}):l.jsx(wn,{size:12,className:"text-amber-400"})}function _l(e){return e==="deposit"}function $M({entries:e,loading:t,onRefresh:r}){const n=e.filter(i=>_l(i.type)).reduce((i,s)=>i+s.amount_usdc,0),a=e.filter(i=>!_l(i.type)&&i.type!=="budget_lock").reduce((i,s)=>i+s.amount_usdc,0);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(wn,{size:13,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Vault Transactions"})]}),l.jsxs("div",{className:"flex items-center gap-3",children:[e.length>0&&l.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[l.jsxs("span",{className:"text-emerald-400",children:["+$",n.toFixed(4)]}),l.jsxs("span",{className:"text-red-400",children:["-$",a.toFixed(4)]})]}),l.jsx("button",{onClick:r,className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Qa,{size:12,className:t?"animate-spin":""})})]})]}),e.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx(Y8,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-gray-600",children:"No transactions yet"}),l.jsx("p",{className:"text-xs text-gray-700 mt-1",children:"Deposits, withdrawals and agent payments will appear here"})]}):l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{children:l.jsxs("tr",{className:"border-b border-gray-800 text-gray-600 uppercase tracking-wider text-left",children:[l.jsx("th",{className:"px-4 py-2 font-medium",children:"Type"}),l.jsx("th",{className:"px-4 py-2 font-medium",children:"Amount"}),l.jsx("th",{className:"px-4 py-2 font-medium hidden sm:table-cell",children:"Task / Agent"}),l.jsx("th",{className:"px-4 py-2 font-medium hidden md:table-cell",children:"Date"}),l.jsx("th",{className:"px-4 py-2 font-medium text-center",children:"Tx"})]})}),l.jsx("tbody",{className:"divide-y divide-gray-800/60",children:e.map(i=>l.jsxs("tr",{className:"hover:bg-gray-800/30 transition-colors",children:[l.jsx("td",{className:"px-4 py-2.5",children:l.jsxs("div",{className:"flex items-center gap-2",children:[qM(i.type),l.jsx("span",{className:`font-medium ${_l(i.type)?"text-emerald-300":i.type==="payment"?"text-purple-300":i.type==="withdrawal"?"text-red-300":"text-amber-300"}`,children:HM(i.type)})]})}),l.jsx("td",{className:"px-4 py-2.5 font-mono font-semibold",children:l.jsxs("span",{className:_l(i.type)?"text-emerald-400":"text-red-400",children:[_l(i.type)?"+":"-","$",i.amount_usdc.toFixed(4)]})}),l.jsxs("td",{className:"px-4 py-2.5 hidden sm:table-cell text-gray-500 max-w-[200px]",children:[i.agent_name&&l.jsx("span",{className:"truncate block",children:i.agent_name}),i.task_id&&!i.agent_name&&l.jsxs("span",{className:"font-mono text-gray-700 truncate block",title:i.task_id,children:[i.task_id.slice(0,12),"…"]}),!i.agent_name&&!i.task_id&&l.jsx("span",{className:"text-gray-700",children:"—"})]}),l.jsx("td",{className:"px-4 py-2.5 hidden md:table-cell text-gray-600 whitespace-nowrap",children:LM(i.timestamp)}),l.jsx("td",{className:"px-4 py-2.5 text-center",children:i.tx_hash?l.jsx("a",{href:`${IM}/${i.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex text-gray-600 hover:text-blue-400 transition-colors",title:"View on Stellar Expert",children:l.jsx(Xr,{size:11})}):l.jsx("span",{className:"text-gray-800",children:"—"})})]},i.id))})]})})]})}function FM(){const[e,t]=re.useState([]);re.useEffect(()=>{const a=async()=>{try{t(await q6())}catch{}};a();const i=setInterval(a,15e3);return()=>clearInterval(i)},[]);const r=[...e].sort((a,i)=>{const s=a.reputation.successful_jobs*a.pricing.price_per_call;return i.reputation.successful_jobs*i.pricing.price_per_call-s}),n=r.reduce((a,i)=>a+i.reputation.successful_jobs*i.pricing.price_per_call,0);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(lw,{size:13,className:"text-emerald-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Agent Earnings"})]}),l.jsxs("span",{className:"text-sm font-mono font-bold text-emerald-400",children:["$",n.toFixed(4)]})]}),l.jsxs("div",{className:"p-4 space-y-2.5",children:[r.map(a=>{const i=a.reputation.successful_jobs*a.pricing.price_per_call,s=r[0]?r[0].reputation.successful_jobs*r[0].pricing.price_per_call:1,o=s>0?i/s*100:0;return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-xs font-medium text-gray-200",children:a.name}),l.jsxs("span",{className:"text-xs text-gray-600 ml-2",children:[a.reputation.successful_jobs,"/",a.reputation.total_jobs," jobs"]})]}),l.jsxs("span",{className:"text-xs font-mono text-emerald-400",children:["$",i.toFixed(4)]})]}),l.jsx("div",{className:"h-1 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-emerald-500/70 rounded-full transition-all",style:{width:`${o}%`}})})]},a.agent_id)}),e.length===0&&l.jsx("p",{className:"text-xs text-gray-600 py-4 text-center",children:"Loading agent data…"})]})]})}function KM(){const{publicKey:e}=On(),[t,r]=re.useState([]),[n,a]=re.useState(!0),i=async()=>{if(e){a(!0);try{r(await cM(e))}catch{}a(!1)}};return re.useEffect(()=>{i();const s=setInterval(i,15e3);return()=>clearInterval(s)},[e]),l.jsxs("div",{className:"grid grid-cols-12 gap-6 items-start",children:[l.jsx("div",{className:"col-span-12 lg:col-span-8",children:l.jsx($M,{entries:t,loading:n,onRefresh:i})}),l.jsx("div",{className:"col-span-12 lg:col-span-4",children:l.jsx(FM,{})})]})}const PM="https://stellar.expert/explorer/testnet/tx",Kx=80;function GM(e){return e.replace(/^### (.+)$/gm,'

    $1

    ').replace(/^## (.+)$/gm,'

    $1

    ').replace(/^# (.+)$/gm,'

    $1

    ').replace(/\*\*(.+?)\*\*/g,'$1').replace(/\*(.+?)\*/g,'$1').replace(/`([^`]+)`/g,'$1').replace(/^- (.+)$/gm,'
  • $1
  • ').replace(/^\d+\. (.+)$/gm,'
  • $1
  • ').split(` +`)}function ZT({events:e}){var s,o,c,d;const t=(s=e.find(p=>p.event==="task_result"))==null?void 0:s.data,r=(o=e.find(p=>p.event==="task_error"))==null?void 0:o.data,n=(c=e.find(p=>p.event==="task_complete"))==null?void 0:c.data;if(!t&&!r&&!n)return null;const a=(t==null?void 0:t.status)??(r?"failed":"running"),i={complete:{icon:l.jsx(mr,{size:13,className:"text-emerald-400"}),label:"Complete",color:"text-emerald-400",border:"border-emerald-900/40",bg:"bg-emerald-950/20"},partial:{icon:l.jsx(Ka,{size:13,className:"text-amber-400"}),label:"Partial",color:"text-amber-400",border:"border-amber-900/40",bg:"bg-amber-950/20"},failed:{icon:l.jsx(En,{size:13,className:"text-red-400"}),label:"Failed",color:"text-red-400",border:"border-red-900/40",bg:"bg-red-950/20"}}[a]??{icon:l.jsx(Zh,{size:13,className:"text-gray-400"}),label:a,color:"text-gray-400",border:"border-gray-700",bg:""};return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Zh,{size:14,className:"text-gray-500"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Result"}),l.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full border ${i.border} ${i.bg}`,children:[i.icon,l.jsx("span",{className:`text-xs font-medium capitalize ${i.color}`,children:i.label})]})]}),t&&l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(Q8,{size:10}),l.jsx("span",{className:"font-mono tabular-nums",children:(d=t.total_cost)==null?void 0:d.toFixed(4)})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(pa,{size:10}),l.jsxs("span",{className:"tabular-nums",children:[(t.total_time_ms/1e3).toFixed(1),"s"]})]})]})]}),r&&l.jsxs("div",{className:"mx-4 mt-4 bg-red-950/40 border border-red-900/50 rounded-xl p-3",children:[l.jsx("p",{className:"text-xs font-semibold text-red-400 mb-1",children:"Error"}),l.jsx("p",{className:"text-xs text-red-300/80",children:r.error})]}),(t==null?void 0:t.final_output)&&l.jsx("div",{className:"px-4 py-4 max-h-72 overflow-y-auto text-xs text-gray-400 leading-relaxed",dangerouslySetInnerHTML:{__html:XT(t.final_output)}}),(t==null?void 0:t.steps)&&t.steps.length>0&&l.jsxs("div",{className:"px-4 pb-4 border-t border-gray-800 mt-0 pt-3",children:[l.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2",children:"Execution Steps"}),l.jsx("div",{className:"space-y-1.5",children:t.steps.map(p=>{var y;return l.jsxs("div",{className:`flex items-center gap-2.5 text-xs px-3 py-2 rounded-xl ${p.success?"bg-gray-800/50":"bg-red-950/30"}`,children:[p.success?l.jsx(mr,{size:11,className:"text-emerald-400 shrink-0"}):l.jsx(En,{size:11,className:"text-red-400 shrink-0"}),l.jsx("span",{className:`font-medium ${p.success?"text-gray-300":"text-red-400"}`,children:p.agent_name}),l.jsx("span",{className:"text-gray-700",children:"·"}),l.jsxs("span",{className:"text-gray-500 tabular-nums",children:[(p.latency_ms/1e3).toFixed(1),"s"]}),((y=p.payment)==null?void 0:y.tx_hash)&&l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/tx/${p.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"ml-auto flex items-center gap-1 text-gray-600 hover:text-blue-400 transition-colors font-mono",children:[l.jsxs("span",{children:[p.payment.tx_hash.slice(0,8),"…"]}),l.jsx(Xr,{size:9})]}),!p.success&&p.error&&l.jsx("span",{className:"text-red-500 truncate ml-auto max-w-48 text-right",children:p.error.slice(0,60)})]},p.step_id)})})]})]})}function QT({events:e}){var i,s,o,c,d,p;const t=(i=e.find(y=>y.event==="task_result"))==null?void 0:i.data;if(!t)return null;const r=((s=t.steps)==null?void 0:s.filter(y=>y.success))??[],n=((o=t.steps)==null?void 0:o.filter(y=>!y.success))??[],a=t.status==="complete"?"text-emerald-400":t.status==="partial"?"text-amber-400":"text-red-400";return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(ev,{size:14,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Receipt"}),l.jsx("span",{className:`text-xs font-medium ml-auto capitalize ${a}`,children:t.status})]}),l.jsx("div",{className:"px-4 py-3 border-b border-gray-800",children:l.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Task ID"}),l.jsxs("p",{className:"text-xs text-gray-400 font-mono",children:[(c=t.task_id)==null?void 0:c.slice(0,12),"…"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Duration"}),l.jsxs("p",{className:"text-xs text-gray-300 tabular-nums",children:[(t.total_time_ms/1e3).toFixed(1),"s"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Total Cost"}),l.jsxs("p",{className:"text-xs text-emerald-400 font-mono font-semibold",children:["$",(d=t.total_cost)==null?void 0:d.toFixed(4)]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600",children:"Steps"}),l.jsxs("p",{className:"text-xs",children:[l.jsxs("span",{className:"text-emerald-400",children:[r.length," ok"]}),n.length>0&&l.jsxs("span",{className:"text-red-400 ml-1",children:[n.length," failed"]})]})]})]})}),l.jsx("div",{className:"divide-y divide-gray-800",children:(t.steps??[]).map(y=>{var g,v,M;return l.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[y.success?l.jsx(mr,{size:10,className:"text-emerald-500 shrink-0"}):l.jsx(En,{size:10,className:"text-red-500 shrink-0"}),l.jsx("span",{className:"text-xs text-gray-400 flex-1 truncate",children:y.agent_name}),((g=y.payment)==null?void 0:g.method)&&l.jsx("span",{className:"text-xs text-gray-700 uppercase",children:y.payment.method}),((v=y.payment)==null?void 0:v.amount)>0&&l.jsxs("span",{className:"text-xs font-mono text-gray-300 tabular-nums",children:["$",y.payment.amount.toFixed(4)]}),((M=y.payment)==null?void 0:M.tx_hash)&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${y.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",children:l.jsx(Xr,{size:10})})]},y.step_id)})}),l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-gray-800 bg-gray-950/30",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-400",children:"Total"}),l.jsxs("span",{className:"text-sm font-mono font-bold text-emerald-400",children:["$",(p=t.total_cost)==null?void 0:p.toFixed(4)," USDC"]})]})]})}const JT="/api",zx={agent_id:"",name:"",description:"",capabilities:"",payment_model:"x402",price_per_call:"0.02",endpoint:"",stellar_address:"",health_check:"",provision_wallet:!1};function WT(e){if(!e.agent_id.match(/^[a-z0-9-]+$/))return"Agent ID must be lowercase letters, numbers, and hyphens only";if(!e.name.trim())return"Display name is required";if(!e.endpoint.startsWith("http"))return"Endpoint must be a valid URL starting with http(s)://";if(!e.provision_wallet&&!e.stellar_address.match(/^G[A-Z0-9]{55}$/))return"Stellar address must start with G and be 56 characters";if(!e.capabilities.trim())return"At least one capability is required";const t=parseFloat(e.price_per_call);return isNaN(t)||t<=0?"Price must be a positive number":null}function eM(){const{publicKey:e}=On(),[t,r]=re.useState(zx),[n,a]=re.useState("idle"),[i,s]=re.useState(""),[o,c]=re.useState(null),[d,p]=re.useState(!1),y=(K,D)=>{r(T=>({...T,[K]:D})),n==="error"&&a("idle")},g=()=>{r(zx),a("idle"),s(""),c(null),p(!1)},v=async()=>{o&&(await navigator.clipboard.writeText(o.secretKey),p(!0),setTimeout(()=>p(!1),2e3))},M=async()=>{const K=WT(t);if(K){a("error"),s(K);return}let D=t.stellar_address;if(t.provision_wallet){a("provisioning");try{const T=await fetch("/api/provision-wallet",{method:"POST"});if(!T.ok){const L=await T.json().catch(()=>({error:`HTTP ${T.status}`}));throw new Error(L.error??"Wallet provisioning failed")}const k=await T.json();c(k),D=k.publicKey}catch(T){a("error"),s(`Wallet provisioning failed: ${T.message}`);return}}a("loading");try{const T={agent_id:t.agent_id,name:t.name,description:t.description,capabilities:t.capabilities.split(",").map(L=>L.trim()).filter(Boolean),pricing:{model:t.payment_model,price_per_call:parseFloat(t.price_per_call),currency:"USDC"},endpoint:t.endpoint,stellar_address:D,health_check:t.health_check||`${t.endpoint.replace(/\/[^/]*$/,"")}/health`,registered_by:e??void 0},k=await fetch(`${JT}/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)});if(k.ok)a("success"),s(`${t.name} registered successfully! It will appear in the agent list and be available for tasks immediately.`);else{const L=await k.json().catch(()=>({error:`HTTP ${k.status}`}));a("error"),s(L.error??"Registration failed")}}catch(T){a("error"),s(`Could not reach registry: ${T.message}`)}},z=n!=="loading"&&n!=="provisioning"&&t.agent_id.trim()!==""&&t.endpoint.trim()!==""&&(t.provision_wallet||t.stellar_address.trim()!=="");return l.jsx("div",{className:"max-w-xl mx-auto",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-6",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[l.jsx(bf,{size:18,className:"text-purple-400"}),l.jsx("h2",{className:"text-base font-semibold text-gray-200",children:"Register Agent"})]}),n==="success"?l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-start gap-3 bg-green-950 border border-green-800 rounded-lg p-4",children:[l.jsx(Tc,{size:16,className:"text-green-400 mt-0.5 shrink-0"}),l.jsx("p",{className:"text-sm text-green-300",children:i})]}),o&&l.jsxs("div",{className:"bg-yellow-950 border border-yellow-700 rounded-lg p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Cc,{size:14,className:"text-yellow-400"}),l.jsx("span",{className:"text-sm font-medium text-yellow-300",children:"Wallet provisioned — save your secret key now"})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-gray-400 mb-1",children:"Public Key"}),l.jsx("div",{className:"font-mono text-xs text-gray-300 bg-gray-800 rounded px-2 py-1.5 break-all",children:o.publicKey})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-gray-400 mb-1",children:"Secret Key (save this — shown once)"}),l.jsx("div",{className:"font-mono text-xs text-red-300 bg-gray-800 rounded px-2 py-1.5 break-all border border-red-900",children:o.secretKey}),l.jsxs("button",{onClick:v,className:"mt-1.5 flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[l.jsx(v1,{size:11}),d?"Copied!":"Copy secret key"]})]}),o.explorerUrl&&l.jsxs("a",{href:o.explorerUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs text-blue-400 hover:text-blue-300 transition-colors",children:[l.jsx(Xr,{size:11}),"View sponsorship on stellar.expert"]})]}),l.jsxs("button",{onClick:g,className:"w-full flex items-center justify-center gap-2 bg-gray-800 hover:bg-gray-700 text-gray-200 text-sm font-medium rounded-lg px-4 py-2.5 transition-colors",children:[l.jsx(Qa,{size:14}),"Register Another Agent"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-3",children:[[{key:"agent_id",label:"Agent ID",placeholder:"my-agent (lowercase, hyphens ok)"},{key:"name",label:"Display Name",placeholder:"MyBot"},{key:"endpoint",label:"Endpoint URL",placeholder:"https://my-server.com/query"},{key:"health_check",label:"Health Check URL (optional)",placeholder:"auto-derived from endpoint if blank"}].map(({key:K,label:D,placeholder:T})=>l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:D}),l.jsx("input",{type:"text",value:t[K],onChange:k=>y(K,k.target.value),placeholder:T,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]},K)),l.jsxs("div",{className:"bg-gray-800 border border-gray-700 rounded-lg p-3 space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("input",{type:"checkbox",id:"provision_wallet",checked:t.provision_wallet,onChange:K=>y("provision_wallet",K.target.checked),className:"accent-purple-500"}),l.jsx("label",{htmlFor:"provision_wallet",className:"text-xs text-gray-300 cursor-pointer",children:"Provision a Stellar wallet for me (sponsored — free, USDC-ready)"})]}),!t.provision_wallet&&l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Stellar Address (G...)"}),l.jsx("input",{type:"text",value:t.stellar_address,onChange:K=>y("stellar_address",K.target.value),placeholder:"G... (56 characters)",className:"w-full bg-gray-700 border border-gray-600 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]}),t.provision_wallet&&l.jsx("p",{className:"text-xs text-gray-500",children:"A new Stellar account will be created and sponsored. The secret key will be shown after registration — save it immediately."})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Description"}),l.jsx("textarea",{value:t.description,onChange:K=>y("description",K.target.value),placeholder:"What does your agent do?",rows:2,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 resize-none focus:outline-none focus:border-purple-500"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Capabilities (comma-separated)"}),l.jsx("input",{type:"text",value:t.capabilities,onChange:K=>y("capabilities",K.target.value),placeholder:"news, translation, data-analysis",className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-500"})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Payment Model"}),l.jsxs("select",{value:t.payment_model,onChange:K=>y("payment_model",K.target.value),className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 focus:outline-none focus:border-purple-500",children:[l.jsx("option",{value:"x402",children:"x402"}),l.jsx("option",{value:"mpp",children:"MPP"})]})]}),l.jsxs("div",{children:[l.jsx("label",{className:"block text-xs text-gray-400 mb-1",children:"Price per call (USDC)"}),l.jsx("input",{type:"number",value:t.price_per_call,onChange:K=>y("price_per_call",K.target.value),step:.001,min:0,className:"w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-gray-200 focus:outline-none focus:border-purple-500"})]})]})]}),n==="error"&&l.jsxs("div",{className:"mt-4 flex items-start gap-2 bg-red-950 border border-red-800 rounded-lg p-3",children:[l.jsx(Jg,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),l.jsx("span",{className:"text-sm text-red-300",children:i})]}),l.jsxs("div",{className:"mt-4 flex gap-2",children:[(n==="error"||t.agent_id)&&l.jsx("button",{onClick:g,className:"px-4 py-2.5 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 text-sm transition-colors",children:"Clear"}),l.jsx("button",{onClick:M,disabled:!z,className:"flex-1 bg-purple-600 hover:bg-purple-500 disabled:bg-gray-700 disabled:text-gray-500 disabled:cursor-not-allowed text-white text-sm font-medium rounded-lg px-4 py-2.5 transition-colors",children:n==="provisioning"?"Provisioning wallet...":n==="loading"?"Registering...":t.provision_wallet?"Provision Wallet & Register":"Register Agent"})]})]}),l.jsx("div",{className:"mt-4 pt-4 border-t border-gray-800",children:l.jsxs("p",{className:"text-xs text-gray-600",children:["Your agent must implement ",l.jsx("code",{className:"text-gray-500",children:"GET /health"})," and at least one x402 or MPP protected endpoint. It will be available for task assignment immediately after registration."]})})]})})}const sa="";async function tM(e,t,r){return(await fetch(`${sa}/api/tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({task:e,budget:t,user_address:r})})).json()}async function q6(){return(await(await fetch(`${sa}/api/agents`)).json()).agents??[]}async function rM(e){return(await fetch(`${sa}/api/tasks/${e}/approve`,{method:"POST"})).json()}async function nM(e){return(await fetch(`${sa}/api/tasks/${e}/reject`,{method:"POST"})).json()}async function aM(e){const t=await fetch(`${sa}/api/orchestrators/usdc-trustline`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e})}),r=await t.json();if(!t.ok)throw new Error(r.error??"Failed to build XDR");return r.xdr}async function iM(e){const t=await fetch(`${sa}/api/orchestrators/usdc-trustline/confirm`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({signed_xdr:e})}),r=await t.json();if(!t.ok)throw new Error(r.error??"Failed to submit");return r.tx_hash}async function sM(e,t,r){const n=await fetch(`${sa}/api/agents/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,requester_address:r})}),a=await n.json();if(!n.ok)throw new Error(a.error??"Rename failed");return a}async function oM(e,t){const r=await fetch("/api/orchestrators/rename",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,name:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Rename failed");return n}async function lM(e,t){const r=await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({requester_address:t})}),n=await r.json().catch(()=>({}));if(!r.ok)throw new Error(n.error??"Delete failed");return!0}async function cM(e){return(await(await fetch(`${sa}/api/vault/ledger/${encodeURIComponent(e)}`)).json()).entries??[]}async function uM(e){return(await(await fetch(`${sa}/api/tasks/history/${encodeURIComponent(e)}`)).json()).results??[]}async function fM(e,t){return(await fetch(`${sa}/api/tasks/history/${encodeURIComponent(e)}?user_address=${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function dM(e,t){const r=await fetch(`${sa}/api/vault/force-complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,vault_task_id:t})}),n=await r.json();if(!r.ok)throw new Error(n.error??"Force complete failed");return n}function wl({value:e,label:t}){const r=Math.round(e*100),n=r>=70?"bg-emerald-500":r>=40?"bg-amber-500":"bg-red-500";return l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx("span",{className:"text-xs text-gray-500 w-32 shrink-0",children:t}),l.jsx("div",{className:"flex-1 h-1 bg-gray-700 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${n} rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),l.jsxs("span",{className:"text-xs text-gray-400 w-8 text-right tabular-nums",children:[r,"%"]})]})}function hM(e){return e>=.7?"text-emerald-400":e>=.4?"text-amber-400":"text-red-400"}function pM(e){return e>=.7?"bg-emerald-950 border-emerald-800 text-emerald-400":e>=.4?"bg-amber-950 border-amber-800 text-amber-400":"bg-red-950 border-red-800 text-red-400"}function bM({plan:e,onDismiss:t,orchestratorName:r="Your Agent"}){const n=Math.ceil(e.auto_approve_in_ms/1e3),[a,i]=re.useState(n),[s,o]=re.useState(null),[c,d]=re.useState(null),p=re.useRef(!1),y=async()=>{if(s===null){o("approve");try{await rM(e.task_id)}catch{}t()}},g=async()=>{if(s===null){o("reject");try{await nM(e.task_id)}catch{}t()}};re.useEffect(()=>{if(s!==null)return;const z=setInterval(()=>{i(K=>Math.max(0,K-1))},1e3);return()=>clearInterval(z)},[s]),re.useEffect(()=>{a===0&&!p.current&&s===null&&(p.current=!0,y())},[a]);const v=a/n*100,M=v>50?"bg-purple-500":v>20?"bg-amber-500":"bg-red-500";return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-xl bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl flex flex-col max-h-[88vh] overflow-hidden",children:[l.jsxs("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx(ga,{size:16,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsxs("span",{className:"text-xs font-semibold text-purple-400 uppercase tracking-widest",children:[r,"'s Plan"]}),l.jsx("span",{className:"text-xs text-gray-600",children:"·"}),l.jsxs("span",{className:"text-xs text-gray-500",children:[e.steps.length," steps"]})]}),l.jsx("h2",{className:"text-sm font-semibold text-white leading-snug line-clamp-2",children:e.task})]}),l.jsxs("div",{className:"text-right shrink-0",children:[l.jsxs("div",{className:"text-xl font-bold text-white tabular-nums",children:["$",e.total_estimated_cost.toFixed(3)]}),l.jsx("div",{className:"text-xs text-gray-500",children:"USDC budget"})]})]}),e.reasoning&&l.jsx("p",{className:"text-xs text-gray-500 mt-3 leading-relaxed",children:e.reasoning})]}),l.jsxs("div",{className:"px-5 py-3 bg-gray-950/50 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[l.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1.5",children:[l.jsx(pa,{size:10}),s===null?a>0?`Auto-approving in ${a}s — plan is within your budget`:"Auto-approving…":s==="approve"?"Approving plan…":"Rejecting plan…"]}),l.jsxs("span",{className:"text-xs font-mono text-gray-500 tabular-nums",children:[a,"s"]})]}),l.jsx("div",{className:"h-1 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${M} rounded-full transition-all duration-1000 ease-linear`,style:{width:`${v}%`}})})]}),l.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-5 py-3 space-y-2",children:e.steps.map((z,K)=>l.jsxs("div",{className:"border border-gray-800 rounded-xl overflow-hidden",children:[l.jsxs("button",{className:"w-full text-left px-4 py-3 flex items-start gap-3 hover:bg-gray-800/50 transition-colors",onClick:()=>d(c===z.step_id?null:z.step_id),children:[l.jsx("div",{className:"w-5 h-5 rounded-full bg-gray-800 border border-gray-700 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx("span",{className:"text-xs font-mono text-gray-400",children:K+1})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-200",children:z.agent_name}),l.jsx("span",{className:`text-xs font-mono px-1.5 py-px rounded border text-xs leading-none ${pM(z.selected_score)}`,children:Math.round(z.selected_score*100)}),z.alternatives.length>0&&l.jsxs("span",{className:"text-xs text-gray-600 hidden sm:block",children:["beat ",z.alternatives[0].name," (",Math.round(z.alternatives[0].score*100),")"]})]}),l.jsx("p",{className:"text-xs text-gray-500 line-clamp-1 leading-relaxed",children:z.action})]}),l.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[l.jsxs("div",{className:"text-right",children:[l.jsxs("div",{className:"text-xs font-mono font-semibold text-gray-300",children:["$",z.estimated_cost.toFixed(3)]}),l.jsx("div",{className:"text-xs text-gray-600 uppercase",children:z.payment_method})]}),l.jsx(Ds,{size:13,className:`text-gray-600 transition-transform duration-200 ${c===z.step_id?"rotate-180":""}`})]})]}),c===z.step_id&&l.jsxs("div",{className:"px-4 pb-4 pt-1 bg-gray-950/50 border-t border-gray-800 space-y-4",children:[z.score_breakdown&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Score Breakdown"}),l.jsx(wl,{value:z.score_breakdown.capability_match,label:"Capability match"}),l.jsx(wl,{value:z.score_breakdown.reputation,label:"Reputation"}),l.jsx(wl,{value:z.score_breakdown.price_efficiency,label:"Price efficiency"}),l.jsx(wl,{value:z.score_breakdown.latency_score,label:"Latency"}),l.jsx(wl,{value:z.score_breakdown.discovery_bonus,label:"Discovery bonus"})]}),z.alternatives.length>0&&l.jsxs("div",{children:[l.jsxs("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wider mb-2 flex items-center gap-1",children:[l.jsx(ow,{size:10})," Alternatives"]}),l.jsx("div",{className:"space-y-1",children:z.alternatives.map(D=>l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-xs text-gray-400",children:D.name}),l.jsx("span",{className:`text-xs font-mono font-semibold ${hM(D.score)}`,children:Math.round(D.score*100)})]},D.agent_id))})]})]})]},z.step_id))}),l.jsxs("div",{className:"px-5 py-4 border-t border-gray-800 flex gap-3",children:[l.jsxs("button",{onClick:g,disabled:s!==null,className:"flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-750 border border-gray-700 text-gray-300 hover:text-white text-sm font-medium transition-all disabled:opacity-40",children:[l.jsx(En,{size:14,className:"text-red-400"}),"Reject"]}),l.jsxs("button",{onClick:y,disabled:s!==null,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white text-sm font-semibold transition-all disabled:opacity-40 shadow-lg shadow-purple-900/30",children:[l.jsx(mr,{size:14}),s==="approve"?"Approving…":"Approve & Run"]})]})]})})}const mM="CDFLEJ2HFPK3WKFTWB4CKP2JHEYNAUWKXGEJRYW4YMMGDSQSQ7D4LRTE",Dx=`https://stellar.expert/explorer/testnet/contract/${mM}`;function xM(e){var i,s,o,c;const t=e.find(d=>d.event==="budget_locked");if(!t)return null;const r=e.filter(d=>d.event==="budget_released").map(d=>{var p,y,g;return{agent_name:((p=d.data)==null?void 0:p.agent_name)??"",amount:((y=d.data)==null?void 0:y.amount)??0,tx_hash:((g=d.data)==null?void 0:g.tx_hash)??""}}),n=e.find(d=>d.event==="budget_finalized"),a=((i=n==null?void 0:n.data)==null?void 0:i.total_spent)??r.reduce((d,p)=>d+p.amount,0);return{vault_task_id:((s=t.data)==null?void 0:s.contract_task_id)??null,plan_cost_usdc:((o=t.data)==null?void 0:o.budget_usdc)??0,spent_usdc:a,releases:r,completed:!!n,refund_usdc:((c=n==null?void 0:n.data)==null?void 0:c.refund_usdc)??0}}function yM({events:e}){const t=xM(e);if(!t)return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l.jsx(cn,{size:14,className:"text-gray-600"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-500",children:"Vault Activity"}),l.jsx("a",{href:Dx,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-700 hover:text-gray-500 transition-colors",children:l.jsx(Xr,{size:10})})]}),l.jsx("p",{className:"text-xs text-gray-700 text-center py-3",children:"No active task"})]});const r=t.plan_cost_usdc>0?Math.min(100,t.spent_usdc/t.plan_cost_usdc*100):0,n=r>=90?"bg-red-500":r>=70?"bg-amber-500":"bg-purple-500";return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[l.jsx(cn,{size:14,className:t.completed?"text-gray-500":"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Vault Activity"}),t.vault_task_id!==null&&l.jsxs("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded-md",children:["#",t.vault_task_id]}),l.jsx("a",{href:Dx,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(Xr,{size:10})})]}),l.jsx("div",{className:"flex items-center gap-1.5 text-xs mb-3",children:t.completed?l.jsx("span",{className:"text-gray-600",children:"finalized"}):l.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-lg bg-amber-950/40 border border-amber-900/40",children:[l.jsx(Wg,{size:9,className:"text-amber-400"}),l.jsxs("span",{className:"text-amber-400 font-mono",children:["$",t.plan_cost_usdc.toFixed(4)," locked"]})]})}),l.jsxs("div",{className:"mb-3",children:[l.jsxs("div",{className:"flex justify-between text-xs mb-1.5",children:[l.jsxs("span",{className:"text-gray-400 font-mono",children:["$",t.spent_usdc.toFixed(4)," released"]}),l.jsxs("span",{className:"text-gray-600 font-mono",children:["of $",t.plan_cost_usdc.toFixed(4)]})]}),l.jsx("div",{className:"h-1.5 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full ${n} rounded-full transition-all duration-700`,style:{width:`${r}%`}})})]}),t.releases.length>0&&l.jsx("div",{className:"space-y-1.5 mb-3",children:t.releases.map((a,i)=>l.jsxs("div",{className:"flex items-center gap-2 text-xs bg-gray-800/50 rounded-lg px-2.5 py-1.5",children:[l.jsx(Qg,{size:10,className:"text-purple-400 shrink-0"}),l.jsx("span",{className:"text-gray-400 truncate",children:a.agent_name}),l.jsxs("span",{className:"text-purple-300 font-mono ml-auto shrink-0",children:["$",a.amount.toFixed(4)]}),a.tx_hash&&l.jsx("a",{href:`https://stellar.expert/explorer/testnet/tx/${a.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",children:l.jsx(Xr,{size:9})})]},i))}),t.completed&&l.jsxs("div",{className:"pt-2.5 border-t border-gray-800 space-y-1.5",children:[l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-emerald-400",children:[l.jsx(mr,{size:11}),l.jsx("span",{children:"Finalized on-chain"})]}),t.refund_usdc>1e-6&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 pl-4",children:[l.jsx(X8,{size:9}),l.jsxs("span",{children:["$",t.refund_usdc.toFixed(4)," refunded to vault"]})]})]})]})}const gM="CDFLEJ2HFPK3WKFTWB4CKP2JHEYNAUWKXGEJRYW4YMMGDSQSQ7D4LRTE",Ix="Test SDF Network ; September 2015",vM=[1,5,10,20],yu={amount:"",status:"idle",error:null,txHash:null};function Lx(e){const t=(e==null?void 0:e.message)??String(e);return/user declined|rejected|denied|cancel/i.test(t)?"Transaction rejected. Try again when ready.":/simulation failed/i.test(t)?"Simulation failed — check your vault balance and try again.":t.slice(0,120)}function wM({forceOpenFund:e,onFundOpened:t,onDepositSuccess:r,onWithdrawSuccess:n,onError:a}={}){const{publicKey:i,signTransaction:s}=On(),[o,c]=re.useState(null),[d,p]=re.useState(!0),[y,g]=re.useState("none"),[v,M]=re.useState(yu),z=re.useCallback(async()=>{if(i)try{const F=await sb(i);c(F)}catch{}finally{p(!1)}},[i]);re.useEffect(()=>{if(!i)return;z();const F=setInterval(z,8e3);return()=>clearInterval(F)},[z]),re.useEffect(()=>{e&&y==="none"&&(g("fund"),M(yu),t==null||t())},[e]);const K=F=>{g(F),M(yu)},D=()=>{v.status==="signing"||v.status==="submitting"||(g("none"),M(yu),v.status==="success"&&z())},T=async()=>{if(!i)return;const F=parseFloat(v.amount);if(!(!F||F<=0))try{M(ee=>({...ee,status:"building",error:null}));const V=await zT(i,F);M(ee=>({...ee,status:"signing"}));const J=await s(V,Ix);M(ee=>({...ee,status:"submitting"}));const Y=await kx(J,{user_address:i,tx_type:"deposit",amount:F});M(ee=>({...ee,status:"success",txHash:Y})),z(),r==null||r()}catch(V){const J=Lx(V);M(Y=>({...Y,status:"error",error:J})),a==null||a(J)}},k=async()=>{if(!i)return;const F=parseFloat(v.amount);if(!F||F<=0)return;const V=(o==null?void 0:o.available)??0;if(!(F>V))try{M(x=>({...x,status:"building",error:null}));const J=await DT(i,F);M(x=>({...x,status:"signing"}));const Y=await s(J,Ix);M(x=>({...x,status:"submitting"}));const ee=await kx(Y,{user_address:i,tx_type:"withdrawal",amount:F});M(x=>({...x,status:"success",txHash:ee})),z(),n==null||n()}catch(J){const Y=Lx(J);M(ee=>({...ee,status:"error",error:Y})),a==null||a(Y)}},L=v.status==="building"||v.status==="signing"||v.status==="submitting",$=!o||o.available<=0||o.active_tasks_count>0;return i?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-xl p-4",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[l.jsx(cw,{size:16,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"CleverVault"}),l.jsx("a",{href:`https://stellar.expert/explorer/testnet/contract/${gM}`,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-gray-600 hover:text-gray-400 transition-colors",title:"View contract on Stellar Expert",children:l.jsx(Xr,{size:12})})]}),d?l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 py-3 justify-center",children:[l.jsx(Qa,{size:11,className:"animate-spin"}),l.jsx("span",{children:"Loading vault…"})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-gray-800 rounded-xl p-4 mb-3",children:[l.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Total Balance"}),l.jsxs("div",{className:"flex items-baseline gap-1.5",children:[l.jsx("span",{className:"text-2xl font-mono font-bold text-white",children:o?o.balance.toFixed(2):"0.00"}),l.jsx("span",{className:"text-sm text-gray-400",children:"USDC"})]}),o&&o.locked>0&&l.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-amber-400",children:[l.jsx(Wg,{size:10}),l.jsxs("span",{children:[o.locked.toFixed(4)," USDC locked in active task"]})]}),l.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-gray-700",children:[l.jsxs("div",{className:"text-xs",children:[l.jsx("p",{className:"text-gray-500",children:"Available"}),l.jsxs("p",{className:"text-green-400 font-mono font-semibold",children:["$",o?o.available.toFixed(2):"0.00"]})]}),o&&(o.total_deposited>0||o.total_spent>0)&&l.jsxs("div",{className:"text-right text-xs",children:[l.jsx("p",{className:"text-gray-500",children:"Lifetime spent"}),l.jsxs("p",{className:"text-gray-400 font-mono",children:["$",o.total_spent.toFixed(4)]})]})]})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[l.jsxs("button",{onClick:()=>K("fund"),className:"flex items-center justify-center gap-1.5 bg-purple-600 hover:bg-purple-500 text-white text-xs font-medium rounded-lg px-3 py-2 transition-colors",children:[l.jsx(Fl,{size:12}),"Fund"]}),l.jsxs("button",{onClick:()=>K("withdraw"),disabled:$,title:o!=null&&o.active_tasks_count?"Cannot withdraw while a task is running":(o==null?void 0:o.available)===0?"No available balance":void 0,className:"flex items-center justify-center gap-1.5 bg-gray-700 hover:bg-gray-600 disabled:opacity-40 disabled:cursor-not-allowed text-gray-200 text-xs font-medium rounded-lg px-3 py-2 transition-colors",children:[l.jsx(nw,{size:12}),"Withdraw"]})]}),o!=null&&o.active_tasks_count?l.jsx("p",{className:"text-xs text-amber-400 text-center mt-2",children:"Withdrawal locked — task in progress"}):null]})]}),y==="fund"&&l.jsx(qx,{title:"Fund CleverVault",subtitle:"Deposit USDC from your Freighter wallet into the smart contract",amountLabel:"Deposit amount (USDC)",confirmLabel:L?Hx(v.status):"Deposit",amount:v.amount,maxAmount:void 0,status:v.status,error:v.error,txHash:v.txHash,onAmountChange:F=>M(V=>({...V,amount:F,error:null})),onConfirm:T,onClose:D}),y==="withdraw"&&l.jsx(qx,{title:"Withdraw from CleverVault",subtitle:`Available: $${(o==null?void 0:o.available.toFixed(2))??"0.00"} USDC`,amountLabel:"Withdraw amount (USDC)",confirmLabel:L?Hx(v.status):"Withdraw",amount:v.amount,maxAmount:o==null?void 0:o.available,status:v.status,error:v.error,txHash:v.txHash,onAmountChange:F=>M(V=>({...V,amount:F,error:null})),onConfirm:k,onClose:D})]}):null}function Hx(e){return e==="building"?"Building transaction…":e==="signing"?"Sign in Freighter…":e==="submitting"?"Submitting…":""}function qx({title:e,subtitle:t,amountLabel:r,confirmLabel:n,amount:a,maxAmount:i,status:s,error:o,txHash:c,onAmountChange:d,onConfirm:p,onClose:y}){const g=s==="building"||s==="signing"||s==="submitting",v=s==="success",M=parseFloat(a),z=!isNaN(M)&&M>0&&(i===void 0||M<=i);return l.jsx("div",{className:"fixed inset-0 bg-black/70 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-700 rounded-2xl w-full max-w-sm shadow-2xl",children:[l.jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-3",children:[l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-semibold text-white",children:e}),l.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:t})]}),!g&&l.jsx("button",{onClick:y,className:"text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(ya,{size:16})})]}),l.jsx("div",{className:"px-5 pb-5 space-y-4",children:v?l.jsxs("div",{className:"text-center py-4 space-y-3",children:[l.jsx("div",{className:"w-12 h-12 bg-green-900/40 rounded-full flex items-center justify-center mx-auto",children:l.jsx(mr,{size:24,className:"text-green-400"})}),l.jsxs("div",{children:[l.jsx("p",{className:"text-sm font-semibold text-white",children:"Transaction complete"}),c&&l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/tx/${c}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-purple-400 hover:text-purple-300 flex items-center gap-1 justify-center mt-1",children:["View on Stellar Expert ",l.jsx(Xr,{size:10})]})]}),l.jsx("button",{onClick:y,className:"w-full bg-gray-700 hover:bg-gray-600 text-white text-sm font-medium rounded-xl px-4 py-2.5 transition-colors",children:"Close"})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-500 mb-2",children:r}),l.jsx("div",{className:"grid grid-cols-4 gap-1.5 mb-2",children:vM.map(K=>l.jsxs("button",{onClick:()=>d(String(K)),disabled:i!==void 0&&K>i,className:"text-xs bg-gray-800 hover:bg-gray-700 disabled:opacity-30 text-gray-300 rounded-lg py-1.5 transition-colors border border-gray-700 hover:border-gray-600",children:["$",K]},K))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 text-sm",children:"$"}),l.jsx("input",{type:"number",min:"0.01",step:"0.01",max:i,value:a,onChange:K=>d(K.target.value),placeholder:"0.00",className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500 rounded-xl pl-7 pr-14 py-2.5 text-sm text-white placeholder-gray-600 outline-none transition-colors"}),l.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:"USDC"})]}),i!==void 0&&M>i&&l.jsxs("p",{className:"text-xs text-red-400 mt-1",children:["Exceeds available balance ($",i.toFixed(2),")"]})]}),o&&l.jsx("div",{className:"bg-red-900/30 border border-red-800/50 rounded-lg px-3 py-2",children:l.jsx("p",{className:"text-xs text-red-400",children:o})}),g&&l.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:[l.jsx(Qa,{size:11,className:"animate-spin"}),l.jsx("span",{children:n})]}),l.jsx("button",{onClick:p,disabled:g||!z,className:"w-full bg-purple-600 hover:bg-purple-500 disabled:opacity-40 disabled:cursor-not-allowed text-white text-sm font-semibold rounded-xl px-4 py-2.5 transition-colors",children:g?"…":n})]})})]})})}const _M="https://horizon-testnet.stellar.org",SM="GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";async function EM(e,t){try{const r=await fetch(`${_M}/accounts/${e}`);if(r.status===404)return{address:e,label:t,xlm:"0.00",usdc:null,loading:!1,error:!1};if(!r.ok)throw new Error(`HTTP ${r.status}`);const a=(await r.json()).balances??[],i=a.find(d=>d.asset_type==="native"),s=a.find(d=>d.asset_code==="USDC"&&d.asset_issuer===SM),o=i?parseFloat(i.balance).toFixed(2):"0.00",c=s?parseFloat(s.balance).toFixed(4):null;return{address:e,label:t,xlm:o,usdc:c,loading:!1,error:!1}}catch{return{address:e,label:t,xlm:"—",usdc:null,loading:!1,error:!0}}}function $6(e){const[t,r]=re.useState(()=>e.map(a=>({...a,xlm:"…",usdc:null,loading:!0,error:!1}))),n=e.map(a=>a.address).join(",");return re.useEffect(()=>{if(e.length===0){r([]);return}r(e.map(o=>({...o,xlm:"…",usdc:null,loading:!0,error:!1})));let a=!1;const i=async()=>{const o=await Promise.all(e.map(c=>EM(c.address,c.label)));a||r(o)};i();const s=setInterval(i,1e4);return()=>{a=!0,clearInterval(s)}},[n]),t}const AM="https://stellar.expert/explorer/testnet/account";function NM({text:e}){const[t,r]=re.useState(!1);return l.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},className:"text-gray-700 hover:text-gray-400 transition-colors",title:"Copy address",children:t?l.jsx(Tc,{size:10,className:"text-emerald-400"}):l.jsx(v1,{size:10})})}function jM(){const{publicKey:e,signTransaction:t}=On(),[r,n]=re.useState(!1),[a,i]=re.useState(null),s=e?[{address:e,label:"Your Wallet"}]:[],[o]=$6(s),c=o&&!o.loading&&!o.error&&o.usdc===null,d=async()=>{if(e){n(!0),i(null);try{const p=await aM(e),y=await t(p,"Test SDF Network ; September 2015");await iM(y)}catch(p){const y=(p==null?void 0:p.message)??String(p);i(/declined|rejected|denied|cancel/i.test(y)?"Transaction rejected. Try again when ready.":y.slice(0,100))}finally{n(!1)}}};return e?l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(Cc,{size:14,className:"text-emerald-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Your Wallet"}),l.jsx("span",{className:"text-xs text-gray-600 ml-auto",children:"Testnet"})]}),l.jsxs("div",{className:"px-4 py-3",children:[l.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[l.jsxs("span",{className:"text-xs font-mono text-gray-600 flex-1 truncate",children:[e.slice(0,6),"…",e.slice(-4)]}),l.jsx(NM,{text:e}),l.jsx("a",{href:`${AM}/${e}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(Xr,{size:10})})]}),o!=null&&o.loading?l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-700",children:[l.jsx(Qa,{size:9,className:"animate-spin"}),l.jsx("span",{children:"Loading…"})]}):o!=null&&o.error?l.jsx("p",{className:"text-xs text-red-500",children:"Failed to load balances"}):l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"XLM"}),l.jsx("p",{className:"text-sm font-mono font-bold text-emerald-400",children:(o==null?void 0:o.xlm)??"—"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"USDC"}),(o==null?void 0:o.usdc)!==null?l.jsx("p",{className:"text-sm font-mono font-bold text-blue-400",children:o==null?void 0:o.usdc}):l.jsx("p",{className:"text-xs text-gray-600 italic",children:"No trustline"})]})]}),c&&l.jsxs("div",{className:"mt-3",children:[a&&l.jsx("p",{className:"text-xs text-red-400 mb-1.5",children:a}),l.jsxs("button",{onClick:d,disabled:r,className:"w-full flex items-center justify-center gap-1.5 text-xs text-blue-400 hover:text-blue-300 bg-blue-950/30 hover:bg-blue-950/50 border border-blue-900/50 rounded-xl px-3 py-2 transition-all disabled:opacity-50",children:[r?l.jsx(Qa,{size:10,className:"animate-spin"}):l.jsx(Fl,{size:10}),r?"Adding…":"Add USDC Trustline"]})]})]})]}):null}const F6=re.createContext(null);function TM({children:e}){const{publicKey:t}=On(),[r,n]=re.useState(null),[a,i]=re.useState(!0),s=re.useCallback(async()=>{if(!t){i(!1);return}i(!0);try{const o=await fetch(`/api/orchestrators/${encodeURIComponent(t)}`);if(!o.ok)throw new Error("Failed to fetch");const c=await o.json();if(!c.exists){const d=localStorage.getItem(`clevercon_orchestrator_${t}`);if(d)try{const p=JSON.parse(d);if((await fetch("/api/orchestrators/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)})).ok){const v=await(await fetch(`/api/orchestrators/${encodeURIComponent(t)}`)).json();if(v.exists){n({name:v.name,pubkey:v.pubkey,registered_on_chain:v.registered_on_chain,system_prompt:v.system_prompt});return}}}catch{}n(null);return}n({name:c.name,pubkey:c.pubkey,registered_on_chain:c.registered_on_chain,system_prompt:c.system_prompt})}catch{n(null)}finally{i(!1)}},[t]);return re.useEffect(()=>{s()},[s]),l.jsx(F6.Provider,{value:{orchestrator:r,isLoading:a,refresh:s},children:e})}function Kc(){const e=re.useContext(F6);if(!e)throw new Error("useOrchestrator must be used within OrchestratorProvider");return e}const MM=new Set(["stellar-oracle","web-intel-v1","web-intel-v2","analysis-agent","reporter-agent"]),CM=["x402","mpp"],BM=[{label:"Any",min:0},{label:"50+",min:50},{label:"70+",min:70},{label:"90+",min:90}];function OM(e){return e>=80?"text-emerald-400 bg-emerald-950/60 border-emerald-900":e>=50?"text-amber-400 bg-amber-950/60 border-amber-900":"text-red-400 bg-red-950/60 border-red-900"}function RM(e){return e==="x402"?"bg-blue-950/60 border-blue-900/60 text-blue-400":"bg-violet-950/60 border-violet-900/60 text-violet-400"}function $x(e){const t=Date.now()-new Date(e).getTime(),r=Math.floor(t/6e4);if(r<2)return"just now";if(r<60)return`${r}m ago`;const n=Math.floor(r/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function UM({agent:e,requesterAddress:t,onDone:r}){const[n,a]=re.useState(e.name),[i,s]=re.useState(!1),[o,c]=re.useState(""),d=async()=>{const p=n.trim();if(!p||p===e.name){r();return}s(!0);try{await sM(e.agent_id,p,t),r(p)}catch(y){c(y.message??"Failed"),s(!1)}};return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{autoFocus:!0,value:n,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key==="Enter"&&d(),p.key==="Escape"&&r()},className:"flex-1 bg-gray-800 border border-purple-600/50 rounded-lg px-2 py-1 text-xs text-white outline-none"}),l.jsx("button",{onClick:d,disabled:i||!n.trim(),className:"p-1 text-emerald-400 hover:text-emerald-300 disabled:opacity-40 transition-colors",children:l.jsx(Tc,{size:12})}),l.jsx("button",{onClick:()=>r(),className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(ya,{size:12})})]}),o&&l.jsx("p",{className:"text-xs text-red-400",children:o})]})}function Fx({agent:e,isMine:t,requesterAddress:r,onRename:n,onDelete:a}){var z,K,D,T;const[i,s]=re.useState(!1),[o,c]=re.useState(!1),[d,p]=re.useState(!1),[y,g]=re.useState(!1),v=MM.has(e.agent_id),M=async()=>{g(!0);try{await lM(e.agent_id,r),a(e.agent_id)}catch{}g(!1),p(!1)};return l.jsxs("div",{className:`bg-gray-900 border rounded-xl overflow-hidden transition-colors ${t?"border-purple-800/50":"border-gray-800"}`,children:[l.jsx("div",{className:"px-4 py-3",children:l.jsxs("div",{className:"flex items-start gap-2.5",children:[l.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${t?"bg-purple-600/20 border border-purple-600/30":"bg-gray-800 border border-gray-700"}`,children:l.jsx(jc,{size:14,className:t?"text-purple-400":"text-gray-500"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[o?l.jsx(UM,{agent:e,requesterAddress:r,onDone:k=>{k&&n(e.agent_id,k),c(!1)}}):l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[l.jsx("span",{className:"text-sm font-semibold text-gray-100",children:e.name}),t&&l.jsx("span",{className:"text-xs px-1.5 py-px rounded bg-purple-950/60 border border-purple-800/60 text-purple-400 leading-none",children:"mine"}),l.jsx("span",{className:`text-xs font-mono px-1.5 py-px rounded border leading-none ${OM(((z=e.reputation)==null?void 0:z.score)??50)}`,children:(((K=e.reputation)==null?void 0:K.score)??50).toFixed(0)}),l.jsx("span",{className:`text-xs px-1.5 py-px rounded border leading-none uppercase font-medium ${RM(e.pricing.model)}`,children:e.pricing.model})]}),!o&&l.jsxs("div",{className:"flex items-center gap-3 mt-1 flex-wrap",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[l.jsx(ga,{size:9,className:"text-purple-500"}),l.jsxs("span",{className:"font-mono",children:["$",e.pricing.price_per_call.toFixed(3),"/call"]})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(rv,{size:9,className:"text-yellow-600"}),l.jsx("span",{children:(((D=e.reputation)==null?void 0:D.avg_quality)??0).toFixed(1)}),l.jsx("span",{className:"text-gray-700",children:"·"}),l.jsxs("span",{children:[((T=e.reputation)==null?void 0:T.total_jobs)??0," jobs"]})]}),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-700",children:[l.jsx(pa,{size:8}),l.jsx("span",{children:$x(e.last_seen)})]})]})]}),l.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[t&&!o&&l.jsx("button",{onClick:()=>c(!0),className:"p-1.5 text-gray-700 hover:text-gray-300 rounded-lg hover:bg-gray-800 transition-all",title:"Rename",children:l.jsx(Vf,{size:11})}),l.jsx("button",{onClick:()=>s(k=>!k),className:"p-1.5 text-gray-700 hover:text-gray-400 rounded-lg hover:bg-gray-800 transition-all",children:i?l.jsx(Mc,{size:11}):l.jsx(Ds,{size:11})}),t&&!v&&!o&&(d?l.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[l.jsx("button",{onClick:M,disabled:y,className:"text-xs px-2 py-1 rounded-lg bg-red-950 text-red-400 border border-red-900 hover:bg-red-900 transition-colors",children:y?"…":"Remove"}),l.jsx("button",{onClick:()=>p(!1),className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(ya,{size:11})})]}):l.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-gray-700 hover:text-red-400 rounded-lg hover:bg-gray-800 transition-all",title:"Remove",children:l.jsx(nv,{size:11})}))]})]})}),i&&l.jsxs("div",{className:"px-4 pb-4 border-t border-gray-800 space-y-3 pt-3",children:[e.description&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1",children:"About"}),l.jsx("p",{className:"text-xs text-gray-400 leading-relaxed",children:e.description})]}),l.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Stats"}),l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Success rate"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.total_jobs>0?`${(e.reputation.successful_jobs/e.reputation.total_jobs*100).toFixed(0)}%`:"—"})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Avg latency"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.avg_latency_ms>0?`${(e.reputation.avg_latency_ms/1e3).toFixed(1)}s`:"—"})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Failed jobs"}),l.jsx("span",{className:"text-gray-300 font-mono",children:e.reputation.failed_jobs})]})]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Details"}),l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Status"}),l.jsx("span",{className:`font-mono ${e.status==="active"?"text-emerald-400":"text-gray-500"}`,children:e.status})]}),l.jsxs("div",{className:"flex justify-between",children:[l.jsx("span",{className:"text-gray-600",children:"Registered"}),l.jsx("span",{className:"text-gray-400",children:$x(e.registered_at)})]})]})]})]}),e.capabilities.length>0&&l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1.5",children:"Capabilities"}),l.jsx("div",{className:"flex flex-wrap gap-1",children:e.capabilities.map(k=>l.jsx("span",{className:"text-xs bg-gray-800 text-gray-400 border border-gray-700/60 rounded-md px-1.5 py-0.5 leading-none",children:k},k))})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 uppercase tracking-wider font-medium mb-1.5",children:"Source"}),l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsxs("span",{className:"text-gray-600 font-mono truncate",children:[e.stellar_address.slice(0,8),"…",e.stellar_address.slice(-4)]}),l.jsx("a",{href:`https://stellar.expert/explorer/testnet/account/${e.stellar_address}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-600 hover:text-blue-400 transition-colors shrink-0",title:"View on Stellar Expert",children:l.jsx(Xr,{size:10})})]})]})]})]})}const kM=[{title:"1. Create an agent server",body:"Build an HTTP service that accepts POST /execute with a { task } body and returns { output, cost } JSON. Any language or framework works."},{title:"2. Set up a Stellar wallet",body:"Create a Stellar keypair on testnet for your agent. Fund it with XLM (friendbot) and add a USDC trustline so it can receive payments."},{title:"3. Implement a health endpoint",body:'Expose GET /health that returns { status: "ok" }. CleverCon pings this to verify the agent is reachable before dispatching tasks.'},{title:"4. Choose a payment model",body:"x402: per-request micropayment via HTTP 402. The orchestrator pays per call. mpp: multi-party payment, locked upfront in the vault smart contract."},{title:"5. Register your agent",body:"Use the Register tab to submit your agent manifest: name, description, capabilities, pricing, endpoint, stellar_address, and health_check URL."}];function zM(){const[e,t]=re.useState(null);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-gray-800",children:[l.jsx(V8,{size:13,className:"text-blue-400"}),l.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"How to set up an agent"})]}),l.jsx("div",{className:"divide-y divide-gray-800",children:kM.map((r,n)=>l.jsxs("div",{children:[l.jsxs("button",{onClick:()=>t(e===n?null:n),className:"w-full flex items-center justify-between px-4 py-3 text-left hover:bg-gray-800/30 transition-colors",children:[l.jsx("span",{className:"text-xs font-medium text-gray-300",children:r.title}),e===n?l.jsx(Mc,{size:11,className:"text-gray-600 shrink-0"}):l.jsx(Ds,{size:11,className:"text-gray-600 shrink-0"})]}),e===n&&l.jsx("div",{className:"px-4 pb-3",children:l.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:r.body})})]},n))}),l.jsx("div",{className:"px-4 py-3 border-t border-gray-800",children:l.jsx("p",{className:"text-xs text-gray-600",children:"Once registered, your agent becomes discoverable in the marketplace and the orchestrator will automatically hire it when its capabilities match a task."})})]})}function DM({onRegisterClick:e}){const{publicKey:t}=On(),{orchestrator:r}=Kc(),[n,a]=re.useState([]),[i,s]=re.useState(!0),[o,c]=re.useState(""),[d,p]=re.useState(null),[y,g]=re.useState(0),v=async()=>{s(!0);try{a(await q6())}catch{}s(!1)};re.useEffect(()=>{v()},[]);const M=re.useMemo(()=>{const $=new Set;return t&&$.add(t),r!=null&&r.pubkey&&$.add(r.pubkey),$},[t,r]),z=$=>M.has($.stellar_address)||!!$.registered_by&&M.has($.registered_by),K=re.useMemo(()=>n.filter(z),[n,M]),D=re.useMemo(()=>{const $=o.toLowerCase();return n.filter(F=>{var V;return!($&&!F.name.toLowerCase().includes($)&&!F.description.toLowerCase().includes($)&&!F.capabilities.some(J=>J.toLowerCase().includes($))||d&&F.pricing.model!==d||(((V=F.reputation)==null?void 0:V.score)??0)D.filter($=>!z($)),[D,M]),k=($,F)=>{a(V=>V.map(J=>J.agent_id===$?{...J,name:F}:J))},L=$=>{a(F=>F.filter(V=>V.agent_id!==$))};return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center",children:[l.jsxs("div",{className:"relative flex-1 max-w-sm",children:[l.jsx(iw,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-600"}),l.jsx("input",{value:o,onChange:$=>c($.target.value),placeholder:"Search agents, capabilities…",className:"w-full bg-gray-900 border border-gray-800 rounded-xl pl-8 pr-3 py-2 text-xs text-gray-200 placeholder-gray-600 outline-none focus:border-purple-600/50 transition-colors"})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[CM.map($=>l.jsx("button",{onClick:()=>p(d===$?null:$),className:`text-xs px-2.5 py-1 rounded-lg border font-medium uppercase transition-all ${d===$?$==="x402"?"bg-blue-950/60 border-blue-700 text-blue-300":"bg-violet-950/60 border-violet-700 text-violet-300":"bg-gray-900 border-gray-800 text-gray-600 hover:text-gray-300 hover:border-gray-700"}`,children:$},$)),l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:["Rep:",BM.map($=>l.jsx("button",{onClick:()=>g($.min),className:`px-2 py-1 rounded-lg border transition-all ${y===$.min?"bg-purple-950/60 border-purple-700 text-purple-300":"bg-gray-900 border-gray-800 text-gray-600 hover:text-gray-300"}`,children:$.label},$.min))]}),l.jsx("button",{onClick:v,className:"p-1.5 rounded-lg text-gray-600 hover:text-gray-400 hover:bg-gray-800 transition-all",children:l.jsx(Qa,{size:12,className:i?"animate-spin":""})})]})]}),l.jsxs("div",{className:"grid grid-cols-12 gap-6 items-start",children:[l.jsxs("div",{className:"col-span-12 lg:col-span-8 space-y-5",children:[K.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs text-purple-400 uppercase tracking-widest font-semibold mb-3",children:"My Agents"}),l.jsx("div",{className:"space-y-2",children:K.map($=>{const F=$.registered_by&&M.has($.registered_by)?$.registered_by:$.stellar_address;return l.jsx(Fx,{agent:$,isMine:!0,requesterAddress:F,onRename:k,onDelete:L},$.agent_id)})})]}),l.jsxs("div",{children:[l.jsx("div",{className:"flex items-center justify-between mb-3",children:l.jsxs("h3",{className:"text-xs text-gray-500 uppercase tracking-widest font-semibold",children:["All Agents ",!i&&l.jsxs("span",{className:"text-gray-700",children:["(",T.length,")"]})]})}),i?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx("div",{className:"w-6 h-6 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-600 mt-3",children:"Loading agents…"})]}):T.length===0?l.jsxs("div",{className:"py-12 text-center bg-gray-900 border border-gray-800 rounded-2xl",children:[l.jsx(jc,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsxs("p",{className:"text-xs text-gray-600",children:["No agents found",o?" matching your search":""]})]}):l.jsx("div",{className:"space-y-2",children:T.map($=>l.jsx(Fx,{agent:$,isMine:!1,requesterAddress:"",onRename:k,onDelete:L},$.agent_id))})]})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-4 space-y-4",children:[l.jsxs("div",{className:"bg-gray-900 border border-purple-800/40 rounded-2xl p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(bf,{size:14,className:"text-purple-400"}),l.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"Register an Agent"})]}),l.jsx("p",{className:"text-xs text-gray-500 leading-relaxed",children:"Have a specialized AI service? Register it to get hired by orchestrators and earn USDC per task."}),l.jsxs("button",{onClick:e,className:"w-full flex items-center justify-center gap-2 text-xs font-semibold py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 text-white transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(bf,{size:12}),"Register Agent"]})]}),l.jsx(zM,{})]})]})]})}const IM="https://stellar.expert/explorer/testnet/tx";function LM(e){return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function HM(e){return e==="deposit"?"Deposit":e==="withdrawal"?"Withdrawal":e==="payment"?"Agent payment":e==="budget_lock"?"Budget locked":e}function qM(e){return e==="deposit"?l.jsx(Qg,{size:12,className:"text-emerald-400"}):e==="withdrawal"?l.jsx(Vh,{size:12,className:"text-red-400"}):e==="payment"?l.jsx(Vh,{size:12,className:"text-purple-400"}):l.jsx(cn,{size:12,className:"text-amber-400"})}function _l(e){return e==="deposit"}function $M({entries:e,loading:t,onRefresh:r}){const n=e.filter(i=>_l(i.type)).reduce((i,s)=>i+s.amount_usdc,0),a=e.filter(i=>!_l(i.type)&&i.type!=="budget_lock").reduce((i,s)=>i+s.amount_usdc,0);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(cn,{size:13,className:"text-purple-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Vault Transactions"})]}),l.jsxs("div",{className:"flex items-center gap-3",children:[e.length>0&&l.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[l.jsxs("span",{className:"text-emerald-400",children:["+$",n.toFixed(4)]}),l.jsxs("span",{className:"text-red-400",children:["-$",a.toFixed(4)]})]}),l.jsx("button",{onClick:r,className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Qa,{size:12,className:t?"animate-spin":""})})]})]}),e.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx(Y8,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-gray-600",children:"No transactions yet"}),l.jsx("p",{className:"text-xs text-gray-700 mt-1",children:"Deposits, withdrawals and agent payments will appear here"})]}):l.jsx("div",{className:"overflow-x-auto",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{children:l.jsxs("tr",{className:"border-b border-gray-800 text-gray-600 uppercase tracking-wider text-left",children:[l.jsx("th",{className:"px-4 py-2 font-medium",children:"Type"}),l.jsx("th",{className:"px-4 py-2 font-medium",children:"Amount"}),l.jsx("th",{className:"px-4 py-2 font-medium hidden sm:table-cell",children:"Task / Agent"}),l.jsx("th",{className:"px-4 py-2 font-medium hidden md:table-cell",children:"Date"}),l.jsx("th",{className:"px-4 py-2 font-medium text-center",children:"Tx"})]})}),l.jsx("tbody",{className:"divide-y divide-gray-800/60",children:e.map(i=>l.jsxs("tr",{className:"hover:bg-gray-800/30 transition-colors",children:[l.jsx("td",{className:"px-4 py-2.5",children:l.jsxs("div",{className:"flex items-center gap-2",children:[qM(i.type),l.jsx("span",{className:`font-medium ${_l(i.type)?"text-emerald-300":i.type==="payment"?"text-purple-300":i.type==="withdrawal"?"text-red-300":"text-amber-300"}`,children:HM(i.type)})]})}),l.jsx("td",{className:"px-4 py-2.5 font-mono font-semibold",children:l.jsxs("span",{className:_l(i.type)?"text-emerald-400":"text-red-400",children:[_l(i.type)?"+":"-","$",i.amount_usdc.toFixed(4)]})}),l.jsxs("td",{className:"px-4 py-2.5 hidden sm:table-cell text-gray-500 max-w-[200px]",children:[i.agent_name&&l.jsx("span",{className:"truncate block",children:i.agent_name}),i.task_id&&!i.agent_name&&l.jsxs("span",{className:"font-mono text-gray-700 truncate block",title:i.task_id,children:[i.task_id.slice(0,12),"…"]}),!i.agent_name&&!i.task_id&&l.jsx("span",{className:"text-gray-700",children:"—"})]}),l.jsx("td",{className:"px-4 py-2.5 hidden md:table-cell text-gray-600 whitespace-nowrap",children:LM(i.timestamp)}),l.jsx("td",{className:"px-4 py-2.5 text-center",children:i.tx_hash?l.jsx("a",{href:`${IM}/${i.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex text-gray-600 hover:text-blue-400 transition-colors",title:"View on Stellar Expert",children:l.jsx(Xr,{size:11})}):l.jsx("span",{className:"text-gray-800",children:"—"})})]},i.id))})]})})]})}function FM(){const[e,t]=re.useState([]);re.useEffect(()=>{const a=async()=>{try{t(await q6())}catch{}};a();const i=setInterval(a,15e3);return()=>clearInterval(i)},[]);const r=[...e].sort((a,i)=>{const s=a.reputation.successful_jobs*a.pricing.price_per_call;return i.reputation.successful_jobs*i.pricing.price_per_call-s}),n=r.reduce((a,i)=>a+i.reputation.successful_jobs*i.pricing.price_per_call,0);return l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(lw,{size:13,className:"text-emerald-400"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Agent Earnings"})]}),l.jsxs("span",{className:"text-sm font-mono font-bold text-emerald-400",children:["$",n.toFixed(4)]})]}),l.jsxs("div",{className:"p-4 space-y-2.5",children:[r.map(a=>{const i=a.reputation.successful_jobs*a.pricing.price_per_call,s=r[0]?r[0].reputation.successful_jobs*r[0].pricing.price_per_call:1,o=s>0?i/s*100:0;return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-xs font-medium text-gray-200",children:a.name}),l.jsxs("span",{className:"text-xs text-gray-600 ml-2",children:[a.reputation.successful_jobs,"/",a.reputation.total_jobs," jobs"]})]}),l.jsxs("span",{className:"text-xs font-mono text-emerald-400",children:["$",i.toFixed(4)]})]}),l.jsx("div",{className:"h-1 bg-gray-800 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-emerald-500/70 rounded-full transition-all",style:{width:`${o}%`}})})]},a.agent_id)}),e.length===0&&l.jsx("p",{className:"text-xs text-gray-600 py-4 text-center",children:"Loading agent data…"})]})]})}function KM(){const{publicKey:e}=On(),[t,r]=re.useState([]),[n,a]=re.useState(!0),i=async()=>{if(e){a(!0);try{r(await cM(e))}catch{}a(!1)}};return re.useEffect(()=>{i();const s=setInterval(i,15e3);return()=>clearInterval(s)},[e]),l.jsxs("div",{className:"grid grid-cols-12 gap-6 items-start",children:[l.jsx("div",{className:"col-span-12 lg:col-span-8",children:l.jsx($M,{entries:t,loading:n,onRefresh:i})}),l.jsx("div",{className:"col-span-12 lg:col-span-4",children:l.jsx(FM,{})})]})}const PM="https://stellar.expert/explorer/testnet/tx",Kx=80;function GM(e){return e.replace(/^### (.+)$/gm,'

    $1

    ').replace(/^## (.+)$/gm,'

    $1

    ').replace(/^# (.+)$/gm,'

    $1

    ').replace(/\*\*(.+?)\*\*/g,'$1').replace(/\*(.+?)\*/g,'$1').replace(/`([^`]+)`/g,'$1').replace(/^- (.+)$/gm,'
  • $1
  • ').replace(/^\d+\. (.+)$/gm,'
  • $1
  • ').split(` `).map(t=>t.trim()?t.startsWith("<")?t:`

    ${t}

    `:"").join(` -`)}function YM({entry:e}){const t=e.status==="complete"?"text-emerald-400":e.status==="partial"?"text-amber-400":"text-red-400";return l.jsxs("div",{className:"space-y-3",children:[e.final_output&&l.jsxs("div",{className:"bg-gray-800/50 border border-gray-700/60 rounded-xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-700/60",children:[l.jsx(Zh,{size:11,className:"text-purple-400"}),l.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Result"}),l.jsx("span",{className:`text-xs ml-auto capitalize font-medium ${t}`,children:e.status})]}),l.jsx("div",{className:"px-3 py-2.5 prose-sm max-h-64 overflow-y-auto",dangerouslySetInnerHTML:{__html:GM(e.final_output)}})]}),l.jsxs("div",{className:"bg-gray-800/50 border border-gray-700/60 rounded-xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-700/60",children:[l.jsx(ev,{size:11,className:"text-purple-400"}),l.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Receipt"}),l.jsxs("span",{className:"text-xs font-mono text-red-400 ml-auto",children:["-$",e.total_cost.toFixed(4)]})]}),l.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-xs mb-2",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600",children:"Task ID"}),l.jsxs("p",{className:"text-gray-500 font-mono",children:[e.task_id.slice(0,12),"…"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600",children:"Duration"}),l.jsxs("p",{className:"text-gray-400 font-mono",children:[(e.total_time_ms/1e3).toFixed(1),"s"]})]})]}),e.steps.length>0&&l.jsx("div",{className:"space-y-1",children:e.steps.map(r=>l.jsxs("div",{className:"flex items-center gap-2 text-xs bg-gray-800 rounded-lg px-2.5 py-1.5",children:[r.success?l.jsx(mr,{size:10,className:"text-emerald-400 shrink-0"}):l.jsx(En,{size:10,className:"text-red-400 shrink-0"}),l.jsx("span",{className:"text-gray-400 truncate flex-1",children:r.agent_name}),r.payment.amount>0&&l.jsxs("span",{className:"text-purple-400 font-mono shrink-0",children:[l.jsx(Vh,{size:9,className:"inline"}),"$",r.payment.amount.toFixed(4)]}),r.payment.tx_hash&&l.jsx("a",{href:`${PM}/${r.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",title:"View on Stellar Expert",children:l.jsx(Xr,{size:9})})]},r.step_id))})]})]})]})}function VM({entry:e,userAddress:t,onDelete:r}){const[n,a]=re.useState(!1),[i,s]=re.useState(!1),[o,c]=re.useState(!1),h=e.prompt.length>Kx?e.prompt.slice(0,Kx)+"…":e.prompt,p=e.status==="complete"?"text-emerald-400":e.status==="partial"?"text-amber-400":"text-red-400",y=async()=>{c(!0),await fM(e.task_id,t),r(e.task_id)};return l.jsxs("div",{className:"border-b border-gray-800/60 last:border-0",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",children:[l.jsxs("button",{onClick:()=>a(g=>!g),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left hover:opacity-80 transition-opacity",children:[l.jsxs("div",{className:"shrink-0",children:[e.status==="complete"&&l.jsx(mr,{size:13,className:"text-emerald-400"}),e.status==="partial"&&l.jsx(mr,{size:13,className:"text-amber-400"}),e.status==="failed"&&l.jsx(En,{size:13,className:"text-red-400"})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs text-gray-200 leading-relaxed",title:e.prompt,children:h}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(ha,{size:8}),l.jsx("span",{children:new Date(e.timestamp).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),e.steps.length>0&&l.jsxs("span",{className:"text-xs text-gray-700",children:[e.steps.length," step",e.steps.length!==1?"s":""]})]})]}),l.jsxs("div",{className:"shrink-0 text-right mr-1",children:[e.total_cost>0&&l.jsxs("p",{className:"text-xs font-mono font-semibold text-red-400",children:["-$",e.total_cost.toFixed(4)]}),l.jsx("p",{className:`text-xs capitalize ${p}`,children:e.status})]}),l.jsx("div",{className:"text-gray-700 shrink-0",children:n?l.jsx(Mc,{size:11}):l.jsx(Ds,{size:11})})]}),i?l.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[l.jsx("button",{onClick:y,disabled:o,className:"text-xs px-2 py-1 rounded-lg bg-red-950 text-red-400 border border-red-900 hover:bg-red-900 transition-colors",children:o?"…":"Delete"}),l.jsx("button",{onClick:()=>s(!1),className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(En,{size:11})})]}):l.jsx("button",{onClick:()=>s(!0),className:"p-1 shrink-0 text-gray-700 hover:text-red-400 transition-colors",title:"Delete",children:l.jsx(nv,{size:11})})]}),n&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx(YM,{entry:e})})]})}function XM(){const{publicKey:e}=On(),[t,r]=re.useState([]),[n,a]=re.useState(!0),i=async()=>{if(e){a(!0);try{r(await uM(e))}catch{}a(!1)}};re.useEffect(()=>{i();const h=setInterval(i,2e4);return()=>clearInterval(h)},[e]);const s=h=>{r(p=>p.filter(y=>y.task_id!==h))},o=t.filter(h=>h.status==="complete").length,c=t.reduce((h,p)=>h+p.total_cost,0);return l.jsxs("div",{className:"max-w-2xl mx-auto space-y-4",children:[t.length>0&&l.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"Tasks",value:t.length,color:"text-gray-200"},{label:"Completed",value:o,color:"text-emerald-400"},{label:"Total spent",value:`$${c.toFixed(4)}`,color:"text-red-400"}].map(h=>l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-xl px-4 py-3 text-center",children:[l.jsx("p",{className:`text-lg font-bold font-mono ${h.color}`,children:h.value}),l.jsx("p",{className:"text-xs text-gray-600 mt-0.5",children:h.label})]},h.label))}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Qh,{size:13,className:"text-gray-500"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Task History"}),t.length>0&&l.jsx("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded-md",children:t.length})]}),l.jsx("button",{onClick:i,className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Qa,{size:12,className:n?"animate-spin":""})})]}),n&&t.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx("div",{className:"w-5 h-5 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-600 mt-2",children:"Loading…"})]}):t.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx(Qh,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-gray-600",children:"No completed tasks yet"}),l.jsx("p",{className:"text-xs text-gray-700 mt-1",children:"Task results will appear here after completion"})]}):l.jsx("div",{children:t.map(h=>l.jsx(VM,{entry:h,userAddress:e,onDelete:s},h.task_id))})]})]})}const ZM="https://stellar.expert/explorer/testnet/account";function QM({text:e}){const[t,r]=re.useState(!1);return l.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},className:"text-gray-600 hover:text-gray-300 transition-colors",title:"Copy",children:t?l.jsx(Tc,{size:11,className:"text-emerald-400"}):l.jsx(v1,{size:11})})}function JM({name:e,pubkey:t,registered:r,onClose:n}){const i=$6([{address:t,label:e}])[0],{refresh:s}=Kc(),{publicKey:o}=On(),[c,h]=re.useState(!1),[p,y]=re.useState(e),[g,v]=re.useState(!1),[M,k]=re.useState(""),K=async()=>{const D=p.trim();if(!D||D===e){h(!1);return}if(o){v(!0),k("");try{await oM(o,D),await s(),h(!1)}catch(T){k(T.message??"Rename failed")}finally{v(!1)}}};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center p-4 bg-black/60 backdrop-blur-sm",children:l.jsxs("div",{className:"w-full max-w-sm bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl",children:[l.jsxs("div",{className:"flex items-center gap-3 px-5 pt-5 pb-4 border-b border-gray-800",children:[l.jsx("div",{className:"w-10 h-10 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0",children:l.jsx(jc,{size:18,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[c?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{autoFocus:!0,value:p,onChange:D=>y(D.target.value),onKeyDown:D=>{D.key==="Enter"&&K(),D.key==="Escape"&&h(!1)},className:"flex-1 bg-gray-800 border border-purple-600/50 rounded-lg px-2 py-1 text-sm text-white outline-none"}),l.jsx("button",{onClick:K,disabled:g,className:"p-1 text-emerald-400 hover:text-emerald-300 disabled:opacity-40",children:l.jsx(Tc,{size:13})}),l.jsx("button",{onClick:()=>{h(!1),y(e),k("")},className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(xa,{size:13})})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("p",{className:"text-sm font-semibold text-white truncate",children:e}),l.jsx("button",{onClick:()=>{y(e),h(!0)},className:"p-0.5 text-gray-700 hover:text-gray-400 transition-colors",title:"Rename",children:l.jsx(Vf,{size:11})})]}),M&&l.jsx("p",{className:"text-xs text-red-400 mt-0.5",children:M}),!c&&l.jsxs("p",{className:"text-xs text-gray-500 flex items-center gap-1 mt-0.5",children:[l.jsx(Z8,{size:9}),"AI Orchestrator · Stellar Testnet"]})]}),l.jsx("button",{onClick:n,className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(xa,{size:16})})]}),l.jsxs("div",{className:"px-5 py-4 space-y-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Stellar Address"}),l.jsxs("div",{className:"flex items-center gap-2 bg-gray-800 rounded-xl px-3 py-2.5",children:[l.jsx("span",{className:"text-xs font-mono text-gray-400 flex-1 truncate",children:t}),l.jsx(QM,{text:t}),l.jsx("a",{href:`${ZM}/${t}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-600 hover:text-blue-400 transition-colors",children:l.jsx(Xr,{size:11})})]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Balances"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[l.jsxs("div",{className:"bg-gray-800 rounded-xl px-3 py-2.5 text-center",children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"XLM"}),l.jsx("p",{className:"text-sm font-mono font-bold text-emerald-400",children:i!=null&&i.loading?"…":(i==null?void 0:i.xlm)??"—"})]}),l.jsxs("div",{className:"bg-gray-800 rounded-xl px-3 py-2.5 text-center",children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"USDC"}),l.jsx("p",{className:"text-sm font-mono font-bold text-blue-400",children:i!=null&&i.loading?"…":(i==null?void 0:i.usdc)??"no trustline"})]})]})]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-gray-800/60 border border-gray-800",children:[l.jsx(wn,{size:11,className:r?"text-emerald-400":"text-gray-600"}),l.jsx("span",{className:"text-xs text-gray-400",children:r?"Registered on-chain":"Not yet registered on-chain"})]})]})]})})}const WM=[.1,.25,.5,1];function eC(e){return e<6e4?`${Math.round(e/1e3)}s`:`${Math.round(e/6e4)} min`}async function tC(e,t){const r=await fetch("/api/tasks/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({task:e,budget:t})});if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}function rC({items:e,vaultAvailable:t,orchestratorName:r,onFundVault:n,onConfirm:a,onClose:i}){const[s,o]=re.useState(()=>e.map(f=>({id:f.id,task:f.task,budget:f.budget,delay_ms:f.delay_ms,status:"loading",selected:!0}))),[c,h]=re.useState(null),[p,y]=re.useState(null),[g,v]=re.useState(""),[M,k]=re.useState(.25),K=re.useCallback((f,_,E)=>{o(S=>S.map(j=>j.id===f?{...j,status:"loading",steps:void 0,estimated_cost:void 0}:j)),tC(_,E).then(S=>{o(j=>j.map(R=>R.id!==f?R:S.error?{...R,status:"error",errorMsg:S.message??S.error}:S.feasible?{...R,status:"ready",estimated_cost:S.total_estimated_cost,steps:S.steps,reasoning:S.reasoning}:{...R,status:"infeasible",missing:S.missing,errorMsg:S.message}))}).catch(S=>{o(j=>j.map(R=>R.id===f?{...R,status:"error",errorMsg:S.message??"Preview failed"}:R))})},[]);re.useEffect(()=>{e.forEach(f=>K(f.id,f.task,f.budget))},[]);const D=f=>{y(f.id),v(f.task),k(f.budget),h(null)},T=()=>y(null),z=f=>{const _=g.trim();_&&(o(E=>E.map(S=>S.id===f?{...S,task:_,budget:M}:S)),y(null),K(f,_,M))},L=f=>o(_=>_.map(E=>E.id===f?{...E,selected:!E.selected}:E)),$=s.filter(f=>f.selected),F=s.every(f=>f.status!=="loading"),V=$.reduce((f,_)=>f+(_.status==="ready"&&_.estimated_cost!==void 0?_.estimated_cost:_.budget),0),J=t!==null&&V>t,Y=t!==null?Math.max(0,V-t):0,te=$.some(f=>f.status==="infeasible"),x=F&&$.length>0&&!J&&!te&&p===null,u=()=>{a($.map(f=>({id:f.id,task:f.task,budget:f.budget})))};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-xl bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl flex flex-col max-h-[90vh] overflow-hidden",children:[l.jsx("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx(ya,{size:16,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("p",{className:"text-xs font-semibold text-purple-400 uppercase tracking-widest mb-1",children:[r," · Queue Review"]}),l.jsxs("p",{className:"text-sm text-gray-300",children:[s.length," task",s.length!==1?"s":""," to run in sequence"]})]}),l.jsx("button",{onClick:i,className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(xa,{size:16})})]})}),l.jsxs("div",{className:"px-5 py-3 bg-gray-950/50 border-b border-gray-800 space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Vault balance"}),l.jsx("span",{className:"font-mono font-semibold text-gray-300",children:t!==null?`$${t.toFixed(4)} USDC`:"—"})]}),l.jsxs("div",{className:"flex items-center justify-between text-xs",children:[l.jsxs("span",{className:"text-gray-500",children:["Selected total ",!F&&l.jsx("span",{className:"text-gray-700 ml-1",children:"(loading…)"})]}),l.jsxs("span",{className:`font-mono font-semibold ${J?"text-amber-400":"text-white"}`,children:["~$",V.toFixed(4)," USDC"]})]}),J&&l.jsxs("div",{className:"flex items-center justify-between text-xs border-t border-gray-800 pt-2",children:[l.jsx("span",{className:"text-amber-400",children:"Deposit needed"}),l.jsxs("span",{className:"text-amber-400 font-mono font-semibold",children:["$",Y.toFixed(4)," USDC"]})]})]}),l.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-5 py-3 space-y-2",children:s.map((f,_)=>{var S;const E=p===f.id;return l.jsxs("div",{children:[_>0&&l.jsxs("div",{className:"flex items-center gap-2 py-1 pl-3",children:[l.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[l.jsx("div",{className:"w-px h-3 bg-gray-700"}),l.jsx("div",{className:"w-px h-3 bg-gray-700"})]}),l.jsx(ha,{size:9,className:"text-gray-700"}),l.jsxs("span",{className:"text-xs text-gray-700 font-mono",children:["+",eC(f.delay_ms)," after previous"]})]}),l.jsx("div",{className:`border rounded-xl overflow-hidden transition-colors ${E?"border-purple-700/60":f.selected?f.status==="infeasible"?"border-red-900/60":f.status==="error"?"border-red-900/40":J?"border-amber-900/40":"border-gray-700":"border-gray-800 opacity-50"}`,children:E?l.jsxs("div",{className:"px-4 py-3 space-y-3",children:[l.jsx("p",{className:"text-xs text-purple-400 font-medium uppercase tracking-wider",children:"Edit task"}),l.jsx("textarea",{rows:3,value:g,onChange:j=>v(j.target.value),className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-xl px-3 py-2 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors",autoFocus:!0}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5",children:"Budget"}),l.jsx("div",{className:"grid grid-cols-4 gap-1 mb-1.5",children:WM.map(j=>l.jsxs("button",{onClick:()=>k(j),className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${M===j?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:["$",j.toFixed(2)]},j))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:M,onChange:j=>{const R=parseFloat(j.target.value);!isNaN(R)&&R>0&&k(R)},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg pl-5 pr-3 py-1.5 text-xs font-mono font-semibold text-purple-300 outline-none transition-all"})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsxs("button",{onClick:T,className:"flex items-center gap-1.5 text-xs px-3 py-2 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:[l.jsx(Jh,{size:10}),"Cancel"]}),l.jsxs("button",{onClick:()=>z(f.id),disabled:!g.trim(),className:"flex-1 flex items-center justify-center gap-1.5 text-xs py-2 rounded-lg bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(mr,{size:10}),"Save & Replan"]})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[l.jsx("button",{onClick:()=>L(f.id),className:`mt-0.5 w-4 h-4 rounded border-2 flex items-center justify-center shrink-0 transition-colors ${f.selected?"bg-purple-600 border-purple-600":"border-gray-600 hover:border-gray-400"}`,children:f.selected&&l.jsx(mr,{size:10,className:"text-white"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs text-gray-200 leading-relaxed",children:f.task}),l.jsxs("div",{className:"flex items-center gap-3 mt-1.5 flex-wrap",children:[l.jsxs("span",{className:"text-xs font-mono text-gray-600",children:["$",f.budget.toFixed(2)," budget"]}),f.status==="loading"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(Qa,{size:9,className:"animate-spin"}),"planning…"]}),f.status==="ready"&&f.estimated_cost!==void 0&&l.jsxs("span",{className:`flex items-center gap-1 text-xs font-mono font-semibold ${f.estimated_cost>f.budget?"text-amber-400":"text-emerald-400"}`,children:["~$",f.estimated_cost.toFixed(4)," est.",f.estimated_cost>f.budget&&l.jsx(Ka,{size:9})]}),f.status==="infeasible"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[l.jsx(En,{size:9}),"infeasible"]}),f.status==="error"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[l.jsx(Ka,{size:9}),"preview failed"]})]}),f.status==="infeasible"&&l.jsx("p",{className:"text-xs text-red-500 mt-1",children:f.errorMsg??`Missing: ${(S=f.missing)==null?void 0:S.join(", ")}`}),f.status==="error"&&l.jsx("p",{className:"text-xs text-red-500/70 mt-1",children:f.errorMsg}),f.status==="ready"&&f.reasoning&&l.jsx("p",{className:"text-xs text-gray-600 mt-1 italic",children:f.reasoning})]}),l.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[l.jsx("button",{onClick:()=>D(f),className:"p-1 text-gray-600 hover:text-gray-300 transition-colors",title:"Edit task",children:l.jsx(Vf,{size:11})}),(f.status==="error"||f.status==="infeasible")&&l.jsx("button",{onClick:()=>K(f.id,f.task,f.budget),className:"p-1 text-gray-600 hover:text-gray-300 transition-colors",title:"Retry preview",children:l.jsx(Jh,{size:11})}),f.status==="ready"&&f.steps&&f.steps.length>0&&l.jsx("button",{onClick:()=>h(c===f.id?null:f.id),className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Ds,{size:13,className:`transition-transform duration-200 ${c===f.id?"rotate-180":""}`})})]})]}),c===f.id&&f.steps&&l.jsx("div",{className:"px-4 pb-3 pt-1 border-t border-gray-800 bg-gray-950/40 space-y-1.5",children:f.steps.map((j,R)=>l.jsxs("div",{className:"flex items-start gap-2",children:[l.jsx("span",{className:"w-4 h-4 rounded-full bg-gray-800 border border-gray-700 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx("span",{className:"text-xs font-mono text-gray-500",children:R+1})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-300",children:j.agent_name}),l.jsxs("span",{className:"text-xs text-gray-600 ml-1",children:["· ",j.action]})]}),l.jsxs("span",{className:"text-xs font-mono text-gray-500 shrink-0",children:["$",j.estimated_cost.toFixed(4)]})]},R))})]})})]},f.id)})}),l.jsxs("div",{className:"px-5 py-4 border-t border-gray-800 space-y-3",children:[J&&l.jsxs("button",{onClick:n,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-amber-600/20 hover:bg-amber-600/30 border border-amber-700/50 text-amber-300 text-sm font-medium transition-all",children:[l.jsx(Cc,{size:14}),"Fund Vault (need $",Y.toFixed(4)," more)"]}),l.jsxs("div",{className:"flex gap-3",children:[l.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-700 border border-gray-700 text-gray-300 text-sm font-medium transition-all",children:"Cancel"}),l.jsxs("button",{onClick:u,disabled:!x,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 disabled:opacity-40 disabled:cursor-not-allowed text-white text-sm font-semibold transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(ya,{size:14}),p!==null?"Finish editing first":te?"Deselect infeasible tasks first":J?"Insufficient balance":`Run ${$.length} Task${$.length!==1?"s":""} in Sequence`]})]})]})]})})}const K6=re.createContext(null);let nC=0;function aC({children:e}){const[t,r]=re.useState([]),n=re.useCallback(i=>{r(s=>s.filter(o=>o.id!==i))},[]),a=re.useCallback((i,s="info")=>{const o=`toast_${Date.now()}_${++nC}`;r(c=>[...c.slice(-4),{id:o,message:i,variant:s}]),setTimeout(()=>n(o),s==="error"?6e3:4e3)},[n]);return l.jsx(K6.Provider,{value:{toasts:t,addToast:a,removeToast:n},children:e})}function ob(){const e=re.useContext(K6);if(!e)throw new Error("useToast must be used within ToastProvider");return e}const iC={success:{icon:mr,bg:"bg-emerald-950 border-emerald-800",icon_class:"text-emerald-400",text:"text-emerald-200"},error:{icon:Jg,bg:"bg-red-950 border-red-800",icon_class:"text-red-400",text:"text-red-200"},warning:{icon:Ka,bg:"bg-amber-950 border-amber-800",icon_class:"text-amber-400",text:"text-amber-200"},info:{icon:ew,bg:"bg-gray-900 border-gray-700",icon_class:"text-purple-400",text:"text-gray-200"}};function sC({toast:e}){const{removeToast:t}=ob(),r=iC[e.variant],n=r.icon;return l.jsxs("div",{className:`flex items-start gap-3 px-4 py-3 rounded-xl border shadow-2xl backdrop-blur-sm ${r.bg} animate-in slide-in-from-right-4 duration-200`,children:[l.jsx(n,{size:15,className:`shrink-0 mt-px ${r.icon_class}`}),l.jsx("p",{className:`text-xs flex-1 leading-relaxed ${r.text}`,children:e.message}),l.jsx("button",{onClick:()=>t(e.id),className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(xa,{size:12})})]})}function oC(){const{toasts:e}=ob();return e.length===0?null:l.jsx("div",{className:"fixed bottom-4 right-4 z-[100] flex flex-col gap-2 w-80 max-w-[calc(100vw-2rem)]",children:e.map(t=>l.jsx(sC,{toast:t},t.id))})}function Px({wallet:e,onSelect:t,loading:r}){return l.jsxs("button",{onClick:()=>e.isAvailable&&t(e.id),disabled:r||!e.isAvailable,className:["w-full flex items-center gap-3 px-4 py-3 rounded-xl border transition-all text-left",e.isAvailable?"border-gray-700 bg-gray-800/60 hover:border-purple-600/60 hover:bg-gray-800 active:scale-[0.99] cursor-pointer":"border-gray-800/50 bg-gray-800/20 opacity-50 cursor-not-allowed"].join(" "),children:[l.jsx("img",{src:e.icon,alt:e.name,className:"w-8 h-8 rounded-lg object-contain flex-shrink-0",onError:n=>{n.target.style.display="none"}}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-sm font-medium text-gray-200 leading-none",children:e.name}),l.jsx("p",{className:"text-xs text-gray-500 mt-0.5 leading-none",children:e.isAvailable?"Ready to connect":"Not installed"})]}),e.isAvailable?l.jsx(Xh,{size:14,className:"text-gray-500 flex-shrink-0"}):l.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:n=>n.stopPropagation(),className:"flex items-center gap-1 text-xs text-gray-600 hover:text-purple-400 transition-colors flex-shrink-0",children:l.jsx(J8,{size:12})})]})}function lC(){const{connect:e,isLoading:t,getSupportedWallets:r}=On(),[n,a]=re.useState([]),[i,s]=re.useState(!0),[o,c]=re.useState(null),[h,p]=re.useState(null);re.useEffect(()=>{let k=!1;const K=async()=>{try{const z=await r();k||a(z)}catch{k||a([])}};K().finally(()=>{k||s(!1)});const D=setTimeout(K,800),T=setTimeout(K,2e3);return()=>{k=!0,clearTimeout(D),clearTimeout(T)}},[]);const y=async k=>{p(null),c(k);try{await e(k)}catch(K){p(K instanceof Error?K.message:"Connection failed"),c(null)}},g=n.filter(k=>k.isAvailable),v=n.filter(k=>!k.isAvailable),M=t||!!o;return l.jsxs("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:[l.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-xl flex items-center justify-center",children:l.jsx(w1,{size:20,className:"text-white"})}),l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-bold text-white leading-none",children:"CleverCon"}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-1",children:"AI Agent Marketplace · Stellar Testnet"})]})]}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md",children:[l.jsxs("div",{className:"text-center mb-6",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-900/50 border border-purple-800/50 rounded-xl flex items-center justify-center mx-auto mb-3",children:l.jsx(Cc,{size:18,className:"text-purple-400"})}),l.jsx("h2",{className:"text-lg font-semibold text-white mb-1.5",children:"Connect your wallet"}),l.jsx("p",{className:"text-sm text-gray-400 leading-relaxed",children:"Choose a Stellar wallet to access CleverCon. Your funds stay in your control."})]}),l.jsx("div",{className:"space-y-2 mb-6",children:i?l.jsxs("div",{className:"py-8 text-center",children:[l.jsx("div",{className:"w-5 h-5 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"Detecting wallets…"})]}):n.length===0?l.jsx("div",{className:"py-6 text-center",children:l.jsx("p",{className:"text-xs text-gray-500",children:"No Stellar wallets found."})}):l.jsxs(l.Fragment,{children:[g.map(k=>l.jsx(Px,{wallet:k,onSelect:y,loading:M},k.id)),v.length>0&&l.jsxs(l.Fragment,{children:[g.length>0&&l.jsx("p",{className:"text-xs text-gray-700 pt-1 pb-0.5 px-1",children:"Not installed"}),v.map(k=>l.jsx(Px,{wallet:k,onSelect:y,loading:M},k.id))]})]})}),h&&l.jsx("div",{className:"bg-red-950/50 border border-red-800/50 rounded-xl px-3 py-2.5 mb-4",children:l.jsx("p",{className:"text-xs text-red-400",children:h})}),l.jsx("div",{className:"space-y-2.5 pt-4 border-t border-gray-800",children:[{icon:wn,title:"Trustless treasury",desc:"Your USDC held by CleverVault, not us."},{icon:ya,title:"Personal AI agent",desc:"Name your orchestrator and hire specialists."},{icon:W8,title:"On-chain transparency",desc:"Every payment verifiable on stellar.expert."}].map(({icon:k,title:K,desc:D})=>l.jsxs("div",{className:"flex items-start gap-2.5",children:[l.jsx("div",{className:"w-6 h-6 bg-purple-900/40 border border-purple-800/40 rounded-lg flex items-center justify-center flex-shrink-0 mt-0.5",children:l.jsx(k,{size:11,className:"text-purple-400"})}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs font-medium text-gray-300",children:K}),l.jsx("p",{className:"text-xs text-gray-500",children:D})]})]},K))}),l.jsx("p",{className:"mt-4 text-center text-xs text-amber-600/80 font-medium",children:"Make sure your wallet is set to Stellar Testnet"})]}),l.jsx("p",{className:"mt-6 text-xs text-gray-700",children:"Powered by Stellar · Testnet"})]})}const cC=["Phoenix","Atlas","Sage","Nova","Orion","Ember"];function uC(){const{publicKey:e,signTransaction:t}=On(),{refresh:r}=Kc(),[n,a]=re.useState(""),[i,s]=re.useState(""),[o,c]=re.useState(!1),[h,p]=re.useState("form"),[y,g]=re.useState(null),[v,M]=re.useState(null),k=async()=>{if(!(!e||!n.trim())){g(null),p("creating");try{const T=await fetch("/api/orchestrators",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,name:n.trim(),system_prompt:i.trim()||void 0})});if(T.status===409){await r();return}if(!T.ok){const F=await T.json();throw new Error(F.error||`Server error ${T.status}`)}const{orchestrator_pubkey:z,name:L,registration_xdr:$}=await T.json();if($){p("signing");const F=await t($,"Test SDF Network ; September 2015"),V=await fetch("/api/orchestrators/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,signed_xdr:F})});if(!V.ok){const J=await V.json();throw new Error(J.error||"On-chain registration failed")}}M({pubkey:z,name:L}),p("success"),await r()}catch(T){g(T.message??"Something went wrong"),p("form")}}};if(h==="success"&&v)return l.jsx("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md text-center",children:[l.jsx("div",{className:"w-14 h-14 bg-purple-600 rounded-2xl flex items-center justify-center mx-auto mb-4",children:l.jsx(tv,{size:24,className:"text-white"})}),l.jsxs("h2",{className:"text-xl font-bold text-white mb-1",children:[v.name," is ready"]}),l.jsx("p",{className:"text-sm text-gray-400 mb-6",children:"Your personal AI agent has been created on Stellar Testnet."}),l.jsxs("div",{className:"bg-gray-800 rounded-xl p-3 mb-4",children:[l.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Orchestrator wallet"}),l.jsx("p",{className:"text-xs font-mono text-gray-300 break-all",children:v.pubkey})]}),l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/account/${v.pubkey}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 transition-colors",children:["View on stellar.expert ",l.jsx(Xr,{size:11})]}),l.jsx("p",{className:"mt-6 text-xs text-gray-600",children:"Redirecting to dashboard…"})]})});const K=h==="creating"||h==="signing",D=h==="creating"?`Creating ${n||"your agent"}…`:h==="signing"?"Check Freighter to sign…":"";return l.jsxs("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:[l.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-xl flex items-center justify-center",children:l.jsx(w1,{size:20,className:"text-white"})}),l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-bold text-white leading-none",children:"CleverCon"}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-1",children:"AI Agent Marketplace · Stellar Testnet"})]})]}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md",children:[l.jsxs("div",{className:"mb-6",children:[l.jsx("h2",{className:"text-lg font-semibold text-white mb-1",children:"Create your AI agent"}),l.jsx("p",{className:"text-sm text-gray-400 leading-relaxed",children:"Your agent will plan tasks, hire specialized agents, and pay them on Stellar. Give it a name."})]}),l.jsxs("div",{className:"mb-4",children:[l.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1.5",children:"Agent name"}),l.jsx("input",{type:"text",value:n,onChange:T=>a(T.target.value),maxLength:30,disabled:K,placeholder:"e.g., Phoenix, Atlas, Sage, Nova…",className:"w-full bg-gray-800 border border-gray-700 rounded-xl px-3 py-2.5 text-sm text-white placeholder-gray-600 focus:outline-none focus:border-purple-500 disabled:opacity-50"}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:cC.map(T=>l.jsx("button",{onClick:()=>a(T),disabled:K,className:"text-xs px-2 py-0.5 rounded-full bg-gray-800 border border-gray-700 text-gray-400 hover:border-purple-600 hover:text-purple-400 transition-colors disabled:opacity-40",children:T},T))})]}),l.jsxs("div",{className:"mb-6",children:[l.jsxs("button",{onClick:()=>c(!o),className:"flex items-center gap-1 text-xs text-gray-500 hover:text-gray-300 transition-colors mb-2",children:[o?l.jsx(Mc,{size:12}):l.jsx(Ds,{size:12}),"Add personality (optional)"]}),o&&l.jsx("textarea",{value:i,onChange:T=>s(T.target.value),disabled:K,rows:3,placeholder:"e.g., Focus on research tasks. Always cite sources. Prefer cheaper agents.",className:"w-full bg-gray-800 border border-gray-700 rounded-xl px-3 py-2.5 text-xs text-white placeholder-gray-600 focus:outline-none focus:border-purple-500 resize-none disabled:opacity-50"})]}),y&&l.jsx("div",{className:"bg-red-900/30 border border-red-800/50 rounded-xl px-3 py-2 mb-4",children:l.jsx("p",{className:"text-xs text-red-400",children:y})}),l.jsx("button",{onClick:k,disabled:!n.trim()||K,className:"w-full flex items-center justify-center gap-2 bg-purple-600 hover:bg-purple-500 disabled:bg-purple-900 disabled:cursor-not-allowed text-white font-medium py-3 px-4 rounded-xl transition-colors text-sm",children:K?l.jsxs(l.Fragment,{children:[l.jsx(tw,{size:15,className:"animate-spin"}),D]}):`Create ${n.trim()||"Agent"}`}),l.jsx("p",{className:"mt-4 text-center text-xs text-gray-600",children:"A Stellar wallet will be created for your agent on testnet"})]})]})}function fC(e){const[t,r]=re.useState([]),[n,a]=re.useState(!1),i=re.useRef(null),s=re.useRef(null),o=re.useCallback(()=>{try{const h=new WebSocket(e);i.current=h,h.onopen=()=>{a(!0),s.current&&clearTimeout(s.current)},h.onmessage=p=>{try{const y=JSON.parse(p.data);r(g=>[y,...g].slice(0,200))}catch{}},h.onclose=()=>{a(!1),s.current=setTimeout(o,3e3)},h.onerror=()=>{h.close()}}catch{}},[e]);re.useEffect(()=>(o(),()=>{var h;s.current&&clearTimeout(s.current),(h=i.current)==null||h.close()}),[o]);const c=re.useCallback(()=>r([]),[]);return{events:t,connected:n,clearEvents:c}}const dC=()=>`q_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,hC=5*60*1e3,pC=30*60*1e3,bC=[{id:"run",label:"Run",icon:l.jsx(ya,{size:12})},{id:"financial",label:"Financial",icon:l.jsx(wn,{size:12})},{id:"agents",label:"Agents",icon:l.jsx(jc,{size:12})},{id:"history",label:"History",icon:l.jsx(Qh,{size:12})},{id:"register",label:"Register",icon:l.jsx(bf,{size:12})}];function mC({stuckMs:e,vaultTaskId:t,onForceComplete:r,onDismiss:n}){const a=e>=pC&&t!=null;return l.jsxs("div",{className:"border-t border-amber-900/40 bg-amber-950/40 px-4 py-2 flex items-center gap-3",children:[l.jsx(Ka,{size:11,className:"text-amber-400 shrink-0"}),l.jsxs("p",{className:"text-xs text-amber-300 flex-1",children:["No progress for ",Math.floor(e/6e4)," min.",a&&" Unlock vault balance?"]}),a&&l.jsx("button",{onClick:r,className:"text-xs px-2.5 py-1 rounded-lg bg-amber-700 hover:bg-amber-600 text-white transition-colors shrink-0",children:"Force Complete"}),l.jsx("button",{onClick:n,className:"text-amber-700 hover:text-amber-500 shrink-0",children:l.jsx(xa,{size:11})})]})}function xC(){const{publicKey:e,disconnect:t}=On(),{orchestrator:r}=Kc(),{addToast:n}=ob(),[a,i]=re.useState("run"),[s,o]=re.useState(!1),[c,h]=re.useState(null),[p,y]=re.useState(null),[g,v]=re.useState(!1),[M,k]=re.useState(!1),[K,D]=re.useState(!1),[T,z]=re.useState(!1),[L,$]=re.useState([]),F=re.useRef([]);F.current=L;const V=re.useRef(null);V.current=p;const[J,Y]=re.useState(null),[te,x]=re.useState(null),[u,f]=re.useState(0),[_,E]=re.useState(!1),S=re.useRef(null),j=`ws://${window.location.host}/ws`,{events:R,connected:N,clearEvents:d}=fC(j);re.useEffect(()=>{if(!e)return;const fe=()=>sb(e).then(pe=>y((pe==null?void 0:pe.available)??0)).catch(()=>{});fe();const ie=setInterval(fe,1e4);return()=>clearInterval(ie)},[e]),re.useEffect(()=>{if(!s||!te){S.current&&clearInterval(S.current),f(0);return}return S.current=setInterval(()=>f(Date.now()-te),1e4),()=>{S.current&&clearInterval(S.current)}},[s,te]);const C=re.useCallback((fe,ie)=>{$(pe=>{const me=fe?pe.map(Ce=>Ce.id===fe?{...Ce,status:"failed",failReason:ie}:Ce):pe.map(Ce=>Ce.status==="running"?{...Ce,status:"done"}:Ce),ye=me.find(Ce=>Ce.status==="queued");return ye?me.map(Ce=>Ce.id===ye.id?{...Ce,status:"countdown",scheduled_run_at:Date.now()+Ce.delay_ms}:Ce):me})},[]),ae=re.useCallback(async(fe,ie,pe)=>{o(!0),k(!1),E(!1),x(Date.now()),d();try{const me=await tM(fe,ie,e??void 0);(me==null?void 0:me.error)==="insufficient_vault_balance"&&(o(!1),x(null),n("Insufficient vault balance.","error"),pe&&C(pe,"Insufficient vault balance"))}catch{o(!1),x(null),pe&&C(pe,"Task submission failed")}},[e,d,n,C]),he=re.useRef(()=>{});he.current=()=>{const fe=F.current,ie=V.current,pe=fe.find(me=>me.status==="countdown"&&me.scheduled_run_at&&me.scheduled_run_at<=Date.now());if(pe){if(ie!==null&&ieme.map(ye=>ye.id===pe.id?{...ye,status:"running"}:ye)),ae(pe.task,pe.budget,pe.id)}},re.useEffect(()=>{const fe=setInterval(()=>he.current(),500);return()=>clearInterval(fe)},[]),re.useEffect(()=>{var ie,pe,me;const fe=R[0];if(fe){if(["task_complete","task_error","task_result","task_infeasible"].includes(fe.event)&&(o(!1),Y(null),x(null),E(!1),C()),["task_started","step_started","step_complete","plan_approved","plan_auto_approved"].includes(fe.event)&&(x(Date.now()),f(0),E(!1)),fe.event==="plan_approval_required"&&h(fe.data),["plan_approved","plan_rejected","plan_auto_approved"].includes(fe.event)&&h(null),fe.event==="budget_locked"&&Y(((ie=fe.data)==null?void 0:ie.contract_task_id)??null),fe.event==="task_result"){k(!0);const ye=fe.data;(ye==null?void 0:ye.status)==="complete"?n(`Done — $${(pe=ye.total_cost)==null?void 0:pe.toFixed(4)} USDC spent`,"success"):(ye==null?void 0:ye.status)==="partial"&&n("Partially completed — some steps failed","warning")}fe.event==="task_error"&&n(`Task failed: ${((me=fe.data)==null?void 0:me.error)??"unknown"}`,"error")}},[R]);const q=(fe,ie)=>ae(fe,ie),G=async()=>{if(!(!e||J==null))try{await dM(e,J),n("Force-complete submitted — vault balance will unlock shortly.","success"),o(!1),Y(null),x(null)}catch(fe){n(`Force-complete failed: ${fe.message}`,"error")}},W=(fe,ie,pe)=>{$(me=>[...me,{id:dC(),task:fe,budget:ie,delay_ms:pe,status:"queued"}])},be=(fe,ie,pe,me)=>{$(ye=>ye.map(Ce=>Ce.id===fe?{...Ce,task:ie,budget:pe,delay_ms:me}:Ce))},ue=fe=>{$(ie=>ie.filter(pe=>pe.id!==fe))},Q=()=>{$(fe=>fe.filter(ie=>ie.status!=="done"&&ie.status!=="failed"))},le=fe=>{z(!1);const ie=new Set(fe.map(me=>me.id)),pe=new Map(fe.map(me=>[me.id,me]));$(me=>{const ye=me.filter(Te=>Te.status!=="queued"||ie.has(Te.id)).map(Te=>{const ct=pe.get(Te.id);return ct?{...Te,task:ct.task,budget:ct.budget}:Te});if(ye.some(Te=>Te.status==="running"||Te.status==="countdown"))return ye;const je=ye.find(Te=>Te.status==="queued");return je?ye.map(Te=>Te.id===je.id?{...Te,status:"countdown",scheduled_run_at:Date.now()}:Te):ye})},Se=s&&!_&&u>=hC;return l.jsxs("div",{className:"min-h-screen bg-gray-950 text-gray-200 flex flex-col",children:[l.jsxs("header",{className:"sticky top-0 z-20 bg-gray-950/95 backdrop-blur-xl border-b border-gray-800/80 shrink-0",children:[l.jsxs("div",{className:"max-w-screen-xl mx-auto px-4 flex items-center gap-3 h-12",children:[l.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[l.jsx("div",{className:"w-6 h-6 bg-gradient-to-br from-purple-600 to-purple-800 rounded-md flex items-center justify-center",children:l.jsx(w1,{size:11,className:"text-white"})}),l.jsx("span",{className:"text-sm font-bold text-white",children:"CleverCon"})]}),s&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-amber-950/60 border border-amber-900/60 text-xs text-amber-400",children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"}),(r==null?void 0:r.name)??"Agent"," working"]}),c&&!s&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-purple-950/60 border border-purple-900/60 text-xs text-purple-400",children:[l.jsx(ya,{size:9,className:"animate-pulse"}),"Plan ready"]}),L.some(fe=>fe.status==="countdown")&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-blue-950/60 border border-blue-900/60 text-xs text-blue-400",children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),"Next task queued"]}),p!==null&&l.jsxs("button",{onClick:()=>i("financial"),className:"hidden md:flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-purple-950/60 border border-purple-800/60 text-xs text-purple-300 hover:bg-purple-950/80 transition-colors",children:[l.jsx(wn,{size:9,className:"text-purple-500"}),l.jsxs("span",{className:"font-mono font-semibold",children:["$",p.toFixed(2)]}),l.jsx("span",{className:"text-purple-600 text-xs",children:"USDC"})]}),l.jsx("div",{className:"flex-1"}),l.jsx("nav",{className:"hidden sm:flex items-center gap-0.5",children:bC.map(fe=>l.jsxs("button",{onClick:()=>i(fe.id),className:`relative flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-all ${a===fe.id?"bg-gray-800 text-white":"text-gray-500 hover:text-gray-300 hover:bg-gray-800/50"}`,children:[fe.icon,fe.label,fe.id==="run"&&M&&!s&&l.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full bg-emerald-400"})]},fe.id))}),l.jsxs("div",{className:"flex items-center gap-2 pl-3 border-l border-gray-800 shrink-0",children:[l.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${N?"bg-emerald-400":"bg-red-500 animate-pulse"}`}),e&&l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"text-xs text-gray-600 font-mono hidden md:block",children:[e.slice(0,4),"…",e.slice(-4)]}),l.jsx("button",{onClick:t,title:"Disconnect",className:"text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(rw,{size:12})})]})]})]}),Se&&l.jsx(mC,{stuckMs:u,vaultTaskId:J,onForceComplete:G,onDismiss:()=>E(!0)})]}),l.jsxs("main",{className:"flex-1 max-w-screen-xl w-full mx-auto px-4 py-6",children:[a==="run"&&l.jsx("div",{className:"flex flex-col gap-5",children:l.jsxs("div",{className:"grid grid-cols-12 gap-4 items-start",children:[l.jsxs("div",{className:"col-span-12 lg:col-span-4 space-y-3",children:[l.jsx(HT,{onSubmit:q,isRunning:s,orchestratorName:(r==null?void 0:r.name)??"CleverCon",onFundVault:()=>v(!0),onBotClick:()=>D(!0)}),l.jsx(KT,{items:L,vaultAvailable:p,onAdd:W,onUpdate:be,onRemove:ue,onClearDone:Q,onRunQueue:()=>z(!0)})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-5 space-y-4",children:[l.jsx(VT,{events:R,connected:N,onClear:d,orchestratorName:(r==null?void 0:r.name)??"Agent"}),M&&l.jsxs(l.Fragment,{children:[l.jsx(ZT,{events:R}),l.jsx(QT,{events:R})]})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-3 space-y-4",children:[l.jsx(wM,{forceOpenFund:g,onFundOpened:()=>v(!1),onDepositSuccess:()=>n("Deposit confirmed.","success"),onWithdrawSuccess:()=>n("Withdrawal confirmed.","success"),onError:fe=>n(fe,"error")}),l.jsx(jM,{}),l.jsx(yM,{events:R})]})]})}),a==="financial"&&l.jsx(KM,{}),a==="agents"&&l.jsx(DM,{onRegisterClick:()=>i("register")}),a==="history"&&l.jsx(XM,{}),a==="register"&&l.jsx("div",{className:"max-w-2xl mx-auto",children:l.jsx(eM,{})})]}),c&&l.jsx(bM,{plan:c,onDismiss:()=>h(null),orchestratorName:(r==null?void 0:r.name)??"Your Agent"}),K&&r&&l.jsx(JM,{name:r.name,pubkey:r.pubkey,registered:r.registered_on_chain??!1,onClose:()=>D(!1)}),T&&l.jsx(rC,{items:L.filter(fe=>fe.status==="queued"),vaultAvailable:p,orchestratorName:(r==null?void 0:r.name)??"CleverCon",onFundVault:()=>{z(!1),v(!0)},onConfirm:le,onClose:()=>z(!1)}),l.jsx(oC,{})]})}function yC(){const{isConnected:e,isLoading:t}=On(),{orchestrator:r,isLoading:n}=Kc();return t||e&&n?l.jsx("div",{className:"min-h-screen bg-gray-950 flex items-center justify-center",children:l.jsx("div",{className:"w-8 h-8 border-2 border-purple-500 border-t-transparent rounded-full animate-spin"})}):e?r?l.jsx(xC,{}):l.jsx(uC,{}):l.jsx(lC,{})}function gC(){return l.jsx(kT,{children:l.jsx(TM,{children:l.jsx(aC,{children:l.jsx(yC,{})})})})}window.addEventListener("unhandledrejection",e=>{var r;const t=((r=e.reason)==null?void 0:r.message)??String(e.reason??"");(t.includes("MetaMask")||t.includes("Failed to connect")||t.includes("no elements in sequence")||t.includes("ethereum")||t.includes("Web3"))&&e.preventDefault()});class vC extends re.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){console.error("[ErrorBoundary]",t,r)}render(){const{error:t}=this.state;return t?l.jsxs("div",{style:{minHeight:"100vh",background:"#0f1117",color:"#f87171",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2rem",fontFamily:"monospace"},children:[l.jsx("h2",{style:{color:"#fca5a5",marginBottom:"1rem"},children:"React render error"}),l.jsxs("pre",{style:{background:"#1e1e2e",padding:"1rem",borderRadius:"8px",maxWidth:"90vw",overflow:"auto",fontSize:"0.8rem",color:"#f87171"},children:[t.message,` +`)}function YM({entry:e}){const t=e.status==="complete"?"text-emerald-400":e.status==="partial"?"text-amber-400":"text-red-400";return l.jsxs("div",{className:"space-y-3",children:[e.final_output&&l.jsxs("div",{className:"bg-gray-800/50 border border-gray-700/60 rounded-xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-700/60",children:[l.jsx(Zh,{size:11,className:"text-purple-400"}),l.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Result"}),l.jsx("span",{className:`text-xs ml-auto capitalize font-medium ${t}`,children:e.status})]}),l.jsx("div",{className:"px-3 py-2.5 prose-sm max-h-64 overflow-y-auto",dangerouslySetInnerHTML:{__html:GM(e.final_output)}})]}),l.jsxs("div",{className:"bg-gray-800/50 border border-gray-700/60 rounded-xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-700/60",children:[l.jsx(ev,{size:11,className:"text-purple-400"}),l.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Receipt"}),l.jsxs("span",{className:"text-xs font-mono text-red-400 ml-auto",children:["-$",e.total_cost.toFixed(4)]})]}),l.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-xs mb-2",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600",children:"Task ID"}),l.jsxs("p",{className:"text-gray-500 font-mono",children:[e.task_id.slice(0,12),"…"]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-gray-600",children:"Duration"}),l.jsxs("p",{className:"text-gray-400 font-mono",children:[(e.total_time_ms/1e3).toFixed(1),"s"]})]})]}),e.steps.length>0&&l.jsx("div",{className:"space-y-1",children:e.steps.map(r=>l.jsxs("div",{className:"flex items-center gap-2 text-xs bg-gray-800 rounded-lg px-2.5 py-1.5",children:[r.success?l.jsx(mr,{size:10,className:"text-emerald-400 shrink-0"}):l.jsx(En,{size:10,className:"text-red-400 shrink-0"}),l.jsx("span",{className:"text-gray-400 truncate flex-1",children:r.agent_name}),r.payment.amount>0&&l.jsxs("span",{className:"text-purple-400 font-mono shrink-0",children:[l.jsx(Vh,{size:9,className:"inline"}),"$",r.payment.amount.toFixed(4)]}),r.payment.tx_hash&&l.jsx("a",{href:`${PM}/${r.payment.tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-blue-400 transition-colors shrink-0",title:"View on Stellar Expert",children:l.jsx(Xr,{size:9})})]},r.step_id))})]})]})]})}function VM({entry:e,userAddress:t,onDelete:r}){const[n,a]=re.useState(!1),[i,s]=re.useState(!1),[o,c]=re.useState(!1),d=e.prompt.length>Kx?e.prompt.slice(0,Kx)+"…":e.prompt,p=e.status==="complete"?"text-emerald-400":e.status==="partial"?"text-amber-400":"text-red-400",y=async()=>{c(!0),await fM(e.task_id,t),r(e.task_id)};return l.jsxs("div",{className:"border-b border-gray-800/60 last:border-0",children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",children:[l.jsxs("button",{onClick:()=>a(g=>!g),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left hover:opacity-80 transition-opacity",children:[l.jsxs("div",{className:"shrink-0",children:[e.status==="complete"&&l.jsx(mr,{size:13,className:"text-emerald-400"}),e.status==="partial"&&l.jsx(mr,{size:13,className:"text-amber-400"}),e.status==="failed"&&l.jsx(En,{size:13,className:"text-red-400"})]}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs text-gray-200 leading-relaxed",title:e.prompt,children:d}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[l.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(pa,{size:8}),l.jsx("span",{children:new Date(e.timestamp).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),e.steps.length>0&&l.jsxs("span",{className:"text-xs text-gray-700",children:[e.steps.length," step",e.steps.length!==1?"s":""]})]})]}),l.jsxs("div",{className:"shrink-0 text-right mr-1",children:[e.total_cost>0&&l.jsxs("p",{className:"text-xs font-mono font-semibold text-red-400",children:["-$",e.total_cost.toFixed(4)]}),l.jsx("p",{className:`text-xs capitalize ${p}`,children:e.status})]}),l.jsx("div",{className:"text-gray-700 shrink-0",children:n?l.jsx(Mc,{size:11}):l.jsx(Ds,{size:11})})]}),i?l.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[l.jsx("button",{onClick:y,disabled:o,className:"text-xs px-2 py-1 rounded-lg bg-red-950 text-red-400 border border-red-900 hover:bg-red-900 transition-colors",children:o?"…":"Delete"}),l.jsx("button",{onClick:()=>s(!1),className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(En,{size:11})})]}):l.jsx("button",{onClick:()=>s(!0),className:"p-1 shrink-0 text-gray-700 hover:text-red-400 transition-colors",title:"Delete",children:l.jsx(nv,{size:11})})]}),n&&l.jsx("div",{className:"px-4 pb-4",children:l.jsx(YM,{entry:e})})]})}function XM(){const{publicKey:e}=On(),[t,r]=re.useState([]),[n,a]=re.useState(!0),i=async()=>{if(e){a(!0);try{r(await uM(e))}catch{}a(!1)}};re.useEffect(()=>{i();const d=setInterval(i,2e4);return()=>clearInterval(d)},[e]);const s=d=>{r(p=>p.filter(y=>y.task_id!==d))},o=t.filter(d=>d.status==="complete").length,c=t.reduce((d,p)=>d+p.total_cost,0);return l.jsxs("div",{className:"max-w-2xl mx-auto space-y-4",children:[t.length>0&&l.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"Tasks",value:t.length,color:"text-gray-200"},{label:"Completed",value:o,color:"text-emerald-400"},{label:"Total spent",value:`$${c.toFixed(4)}`,color:"text-red-400"}].map(d=>l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-xl px-4 py-3 text-center",children:[l.jsx("p",{className:`text-lg font-bold font-mono ${d.color}`,children:d.value}),l.jsx("p",{className:"text-xs text-gray-600 mt-0.5",children:d.label})]},d.label))}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl overflow-hidden",children:[l.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-800",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Qh,{size:13,className:"text-gray-500"}),l.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Task History"}),t.length>0&&l.jsx("span",{className:"text-xs text-gray-600 bg-gray-800 px-1.5 py-0.5 rounded-md",children:t.length})]}),l.jsx("button",{onClick:i,className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Qa,{size:12,className:n?"animate-spin":""})})]}),n&&t.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx("div",{className:"w-5 h-5 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-600 mt-2",children:"Loading…"})]}):t.length===0?l.jsxs("div",{className:"py-12 text-center",children:[l.jsx(Qh,{size:20,className:"text-gray-700 mx-auto mb-2"}),l.jsx("p",{className:"text-xs text-gray-600",children:"No completed tasks yet"}),l.jsx("p",{className:"text-xs text-gray-700 mt-1",children:"Task results will appear here after completion"})]}):l.jsx("div",{children:t.map(d=>l.jsx(VM,{entry:d,userAddress:e,onDelete:s},d.task_id))})]})]})}const ZM="https://stellar.expert/explorer/testnet/account";function QM({text:e}){const[t,r]=re.useState(!1);return l.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},className:"text-gray-600 hover:text-gray-300 transition-colors",title:"Copy",children:t?l.jsx(Tc,{size:11,className:"text-emerald-400"}):l.jsx(v1,{size:11})})}function JM({name:e,pubkey:t,registered:r,onClose:n}){const i=$6([{address:t,label:e}])[0],{refresh:s}=Kc(),{publicKey:o}=On(),[c,d]=re.useState(!1),[p,y]=re.useState(e),[g,v]=re.useState(!1),[M,z]=re.useState(""),K=async()=>{const D=p.trim();if(!D||D===e){d(!1);return}if(o){v(!0),z("");try{await oM(o,D),await s(),d(!1)}catch(T){z(T.message??"Rename failed")}finally{v(!1)}}};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center p-4 bg-black/60 backdrop-blur-sm",children:l.jsxs("div",{className:"w-full max-w-sm bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl",children:[l.jsxs("div",{className:"flex items-center gap-3 px-5 pt-5 pb-4 border-b border-gray-800",children:[l.jsx("div",{className:"w-10 h-10 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0",children:l.jsx(jc,{size:18,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[c?l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{autoFocus:!0,value:p,onChange:D=>y(D.target.value),onKeyDown:D=>{D.key==="Enter"&&K(),D.key==="Escape"&&d(!1)},className:"flex-1 bg-gray-800 border border-purple-600/50 rounded-lg px-2 py-1 text-sm text-white outline-none"}),l.jsx("button",{onClick:K,disabled:g,className:"p-1 text-emerald-400 hover:text-emerald-300 disabled:opacity-40",children:l.jsx(Tc,{size:13})}),l.jsx("button",{onClick:()=>{d(!1),y(e),z("")},className:"p-1 text-gray-600 hover:text-gray-400",children:l.jsx(ya,{size:13})})]}):l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("p",{className:"text-sm font-semibold text-white truncate",children:e}),l.jsx("button",{onClick:()=>{y(e),d(!0)},className:"p-0.5 text-gray-700 hover:text-gray-400 transition-colors",title:"Rename",children:l.jsx(Vf,{size:11})})]}),M&&l.jsx("p",{className:"text-xs text-red-400 mt-0.5",children:M}),!c&&l.jsxs("p",{className:"text-xs text-gray-500 flex items-center gap-1 mt-0.5",children:[l.jsx(Z8,{size:9}),"AI Orchestrator · Stellar Testnet"]})]}),l.jsx("button",{onClick:n,className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(ya,{size:16})})]}),l.jsxs("div",{className:"px-5 py-4 space-y-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Stellar Address"}),l.jsxs("div",{className:"flex items-center gap-2 bg-gray-800 rounded-xl px-3 py-2.5",children:[l.jsx("span",{className:"text-xs font-mono text-gray-400 flex-1 truncate",children:t}),l.jsx(QM,{text:t}),l.jsx("a",{href:`${ZM}/${t}`,target:"_blank",rel:"noopener noreferrer",className:"text-gray-600 hover:text-blue-400 transition-colors",children:l.jsx(Xr,{size:11})})]})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5 uppercase tracking-wider font-medium",children:"Balances"}),l.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[l.jsxs("div",{className:"bg-gray-800 rounded-xl px-3 py-2.5 text-center",children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"XLM"}),l.jsx("p",{className:"text-sm font-mono font-bold text-emerald-400",children:i!=null&&i.loading?"…":(i==null?void 0:i.xlm)??"—"})]}),l.jsxs("div",{className:"bg-gray-800 rounded-xl px-3 py-2.5 text-center",children:[l.jsx("p",{className:"text-xs text-gray-600 mb-0.5",children:"USDC"}),l.jsx("p",{className:"text-sm font-mono font-bold text-blue-400",children:i!=null&&i.loading?"…":(i==null?void 0:i.usdc)??"no trustline"})]})]})]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-gray-800/60 border border-gray-800",children:[l.jsx(cn,{size:11,className:r?"text-emerald-400":"text-gray-600"}),l.jsx("span",{className:"text-xs text-gray-400",children:r?"Registered on-chain":"Not yet registered on-chain"})]})]})]})})}const WM=[.1,.25,.5,1];function eC(e){return e<6e4?`${Math.round(e/1e3)}s`:`${Math.round(e/6e4)} min`}async function tC(e,t){const r=await fetch("/api/tasks/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({task:e,budget:t})});if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}function rC({items:e,vaultAvailable:t,orchestratorName:r,onFundVault:n,onConfirm:a,onClose:i}){const[s,o]=re.useState(()=>e.map(f=>({id:f.id,task:f.task,budget:f.budget,delay_ms:f.delay_ms,status:"loading",selected:!0}))),[c,d]=re.useState(null),[p,y]=re.useState(null),[g,v]=re.useState(""),[M,z]=re.useState(.25),K=re.useCallback((f,_,E)=>{o(S=>S.map(j=>j.id===f?{...j,status:"loading",steps:void 0,estimated_cost:void 0}:j)),tC(_,E).then(S=>{o(j=>j.map(R=>R.id!==f?R:S.error?{...R,status:"error",errorMsg:S.message??S.error}:S.feasible?{...R,status:"ready",estimated_cost:S.total_estimated_cost,steps:S.steps,reasoning:S.reasoning}:{...R,status:"infeasible",missing:S.missing,errorMsg:S.message}))}).catch(S=>{o(j=>j.map(R=>R.id===f?{...R,status:"error",errorMsg:S.message??"Preview failed"}:R))})},[]);re.useEffect(()=>{e.forEach(f=>K(f.id,f.task,f.budget))},[]);const D=f=>{y(f.id),v(f.task),z(f.budget),d(null)},T=()=>y(null),k=f=>{const _=g.trim();_&&(o(E=>E.map(S=>S.id===f?{...S,task:_,budget:M}:S)),y(null),K(f,_,M))},L=f=>o(_=>_.map(E=>E.id===f?{...E,selected:!E.selected}:E)),$=s.filter(f=>f.selected),F=s.every(f=>f.status!=="loading"),V=$.reduce((f,_)=>f+(_.status==="ready"&&_.estimated_cost!==void 0?_.estimated_cost:_.budget),0),J=t!==null&&V>t,Y=t!==null?Math.max(0,V-t):0,ee=$.some(f=>f.status==="infeasible"),x=F&&$.length>0&&!J&&!ee&&p===null,u=()=>{a($.map(f=>({id:f.id,task:f.task,budget:f.budget})))};return l.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-md",children:l.jsxs("div",{className:"w-full max-w-xl bg-gray-900 border border-gray-700 rounded-2xl shadow-2xl flex flex-col max-h-[90vh] overflow-hidden",children:[l.jsx("div",{className:"px-5 pt-5 pb-4 border-b border-gray-800",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-9 h-9 rounded-xl bg-purple-600/20 border border-purple-600/30 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx(ga,{size:16,className:"text-purple-400"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("p",{className:"text-xs font-semibold text-purple-400 uppercase tracking-widest mb-1",children:[r," · Queue Review"]}),l.jsxs("p",{className:"text-sm text-gray-300",children:[s.length," task",s.length!==1?"s":""," to run in sequence"]})]}),l.jsx("button",{onClick:i,className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(ya,{size:16})})]})}),l.jsxs("div",{className:"px-5 py-3 bg-gray-950/50 border-b border-gray-800 space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between text-xs",children:[l.jsx("span",{className:"text-gray-500",children:"Vault balance"}),l.jsx("span",{className:"font-mono font-semibold text-gray-300",children:t!==null?`$${t.toFixed(4)} USDC`:"—"})]}),l.jsxs("div",{className:"flex items-center justify-between text-xs",children:[l.jsxs("span",{className:"text-gray-500",children:["Selected total ",!F&&l.jsx("span",{className:"text-gray-700 ml-1",children:"(loading…)"})]}),l.jsxs("span",{className:`font-mono font-semibold ${J?"text-amber-400":"text-white"}`,children:["~$",V.toFixed(4)," USDC"]})]}),J&&l.jsxs("div",{className:"flex items-center justify-between text-xs border-t border-gray-800 pt-2",children:[l.jsx("span",{className:"text-amber-400",children:"Deposit needed"}),l.jsxs("span",{className:"text-amber-400 font-mono font-semibold",children:["$",Y.toFixed(4)," USDC"]})]})]}),l.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-5 py-3 space-y-2",children:s.map((f,_)=>{var S;const E=p===f.id;return l.jsxs("div",{children:[_>0&&l.jsxs("div",{className:"flex items-center gap-2 py-1 pl-3",children:[l.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[l.jsx("div",{className:"w-px h-3 bg-gray-700"}),l.jsx("div",{className:"w-px h-3 bg-gray-700"})]}),l.jsx(pa,{size:9,className:"text-gray-700"}),l.jsxs("span",{className:"text-xs text-gray-700 font-mono",children:["+",eC(f.delay_ms)," after previous"]})]}),l.jsx("div",{className:`border rounded-xl overflow-hidden transition-colors ${E?"border-purple-700/60":f.selected?f.status==="infeasible"?"border-red-900/60":f.status==="error"?"border-red-900/40":J?"border-amber-900/40":"border-gray-700":"border-gray-800 opacity-50"}`,children:E?l.jsxs("div",{className:"px-4 py-3 space-y-3",children:[l.jsx("p",{className:"text-xs text-purple-400 font-medium uppercase tracking-wider",children:"Edit task"}),l.jsx("textarea",{rows:3,value:g,onChange:j=>v(j.target.value),className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/70 rounded-xl px-3 py-2 text-xs text-gray-200 placeholder-gray-600 resize-none outline-none transition-colors",autoFocus:!0}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-gray-600 mb-1.5",children:"Budget"}),l.jsx("div",{className:"grid grid-cols-4 gap-1 mb-1.5",children:WM.map(j=>l.jsxs("button",{onClick:()=>z(j),className:`text-xs py-1.5 rounded-lg border transition-all font-mono ${M===j?"bg-purple-600/30 border-purple-600/60 text-purple-300":"bg-gray-800 border-gray-700 text-gray-500 hover:text-gray-300"}`,children:["$",j.toFixed(2)]},j))}),l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500 text-xs",children:"$"}),l.jsx("input",{type:"number",min:.01,step:.01,value:M,onChange:j=>{const R=parseFloat(j.target.value);!isNaN(R)&&R>0&&z(R)},className:"w-full bg-gray-800 border border-gray-700 focus:border-purple-500/50 rounded-lg pl-5 pr-3 py-1.5 text-xs font-mono font-semibold text-purple-300 outline-none transition-all"})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsxs("button",{onClick:T,className:"flex items-center gap-1.5 text-xs px-3 py-2 rounded-lg bg-gray-800 hover:bg-gray-700 text-gray-400 transition-colors",children:[l.jsx(Jh,{size:10}),"Cancel"]}),l.jsxs("button",{onClick:()=>k(f.id),disabled:!g.trim(),className:"flex-1 flex items-center justify-center gap-1.5 text-xs py-2 rounded-lg bg-purple-600 hover:bg-purple-500 disabled:opacity-40 text-white font-medium transition-colors",children:[l.jsx(mr,{size:10}),"Save & Replan"]})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[l.jsx("button",{onClick:()=>L(f.id),className:`mt-0.5 w-4 h-4 rounded border-2 flex items-center justify-center shrink-0 transition-colors ${f.selected?"bg-purple-600 border-purple-600":"border-gray-600 hover:border-gray-400"}`,children:f.selected&&l.jsx(mr,{size:10,className:"text-white"})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-xs text-gray-200 leading-relaxed",children:f.task}),l.jsxs("div",{className:"flex items-center gap-3 mt-1.5 flex-wrap",children:[l.jsxs("span",{className:"text-xs font-mono text-gray-600",children:["$",f.budget.toFixed(2)," budget"]}),f.status==="loading"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-gray-600",children:[l.jsx(Qa,{size:9,className:"animate-spin"}),"planning…"]}),f.status==="ready"&&f.estimated_cost!==void 0&&l.jsxs("span",{className:`flex items-center gap-1 text-xs font-mono font-semibold ${f.estimated_cost>f.budget?"text-amber-400":"text-emerald-400"}`,children:["~$",f.estimated_cost.toFixed(4)," est.",f.estimated_cost>f.budget&&l.jsx(Ka,{size:9})]}),f.status==="infeasible"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[l.jsx(En,{size:9}),"infeasible"]}),f.status==="error"&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[l.jsx(Ka,{size:9}),"preview failed"]})]}),f.status==="infeasible"&&l.jsx("p",{className:"text-xs text-red-500 mt-1",children:f.errorMsg??`Missing: ${(S=f.missing)==null?void 0:S.join(", ")}`}),f.status==="error"&&l.jsx("p",{className:"text-xs text-red-500/70 mt-1",children:f.errorMsg}),f.status==="ready"&&f.reasoning&&l.jsx("p",{className:"text-xs text-gray-600 mt-1 italic",children:f.reasoning})]}),l.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[l.jsx("button",{onClick:()=>D(f),className:"p-1 text-gray-600 hover:text-gray-300 transition-colors",title:"Edit task",children:l.jsx(Vf,{size:11})}),(f.status==="error"||f.status==="infeasible")&&l.jsx("button",{onClick:()=>K(f.id,f.task,f.budget),className:"p-1 text-gray-600 hover:text-gray-300 transition-colors",title:"Retry preview",children:l.jsx(Jh,{size:11})}),f.status==="ready"&&f.steps&&f.steps.length>0&&l.jsx("button",{onClick:()=>d(c===f.id?null:f.id),className:"p-1 text-gray-600 hover:text-gray-400 transition-colors",children:l.jsx(Ds,{size:13,className:`transition-transform duration-200 ${c===f.id?"rotate-180":""}`})})]})]}),c===f.id&&f.steps&&l.jsx("div",{className:"px-4 pb-3 pt-1 border-t border-gray-800 bg-gray-950/40 space-y-1.5",children:f.steps.map((j,R)=>l.jsxs("div",{className:"flex items-start gap-2",children:[l.jsx("span",{className:"w-4 h-4 rounded-full bg-gray-800 border border-gray-700 flex items-center justify-center shrink-0 mt-0.5",children:l.jsx("span",{className:"text-xs font-mono text-gray-500",children:R+1})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-xs font-semibold text-gray-300",children:j.agent_name}),l.jsxs("span",{className:"text-xs text-gray-600 ml-1",children:["· ",j.action]})]}),l.jsxs("span",{className:"text-xs font-mono text-gray-500 shrink-0",children:["$",j.estimated_cost.toFixed(4)]})]},R))})]})})]},f.id)})}),l.jsxs("div",{className:"px-5 py-4 border-t border-gray-800 space-y-3",children:[J&&l.jsxs("button",{onClick:n,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-amber-600/20 hover:bg-amber-600/30 border border-amber-700/50 text-amber-300 text-sm font-medium transition-all",children:[l.jsx(Cc,{size:14}),"Fund Vault (need $",Y.toFixed(4)," more)"]}),l.jsxs("div",{className:"flex gap-3",children:[l.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-xl bg-gray-800 hover:bg-gray-700 border border-gray-700 text-gray-300 text-sm font-medium transition-all",children:"Cancel"}),l.jsxs("button",{onClick:u,disabled:!x,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-purple-600 hover:bg-purple-500 disabled:opacity-40 disabled:cursor-not-allowed text-white text-sm font-semibold transition-all shadow-lg shadow-purple-900/30",children:[l.jsx(ga,{size:14}),p!==null?"Finish editing first":ee?"Deselect infeasible tasks first":J?"Insufficient balance":`Run ${$.length} Task${$.length!==1?"s":""} in Sequence`]})]})]})]})})}const K6=re.createContext(null);let nC=0;function aC({children:e}){const[t,r]=re.useState([]),n=re.useCallback(i=>{r(s=>s.filter(o=>o.id!==i))},[]),a=re.useCallback((i,s="info")=>{const o=`toast_${Date.now()}_${++nC}`;r(c=>[...c.slice(-4),{id:o,message:i,variant:s}]),setTimeout(()=>n(o),s==="error"?6e3:4e3)},[n]);return l.jsx(K6.Provider,{value:{toasts:t,addToast:a,removeToast:n},children:e})}function ob(){const e=re.useContext(K6);if(!e)throw new Error("useToast must be used within ToastProvider");return e}const iC={success:{icon:mr,bg:"bg-emerald-950 border-emerald-800",icon_class:"text-emerald-400",text:"text-emerald-200"},error:{icon:Jg,bg:"bg-red-950 border-red-800",icon_class:"text-red-400",text:"text-red-200"},warning:{icon:Ka,bg:"bg-amber-950 border-amber-800",icon_class:"text-amber-400",text:"text-amber-200"},info:{icon:ew,bg:"bg-gray-900 border-gray-700",icon_class:"text-purple-400",text:"text-gray-200"}};function sC({toast:e}){const{removeToast:t}=ob(),r=iC[e.variant],n=r.icon;return l.jsxs("div",{className:`flex items-start gap-3 px-4 py-3 rounded-xl border shadow-2xl backdrop-blur-sm ${r.bg} animate-in slide-in-from-right-4 duration-200`,children:[l.jsx(n,{size:15,className:`shrink-0 mt-px ${r.icon_class}`}),l.jsx("p",{className:`text-xs flex-1 leading-relaxed ${r.text}`,children:e.message}),l.jsx("button",{onClick:()=>t(e.id),className:"text-gray-600 hover:text-gray-400 transition-colors shrink-0",children:l.jsx(ya,{size:12})})]})}function oC(){const{toasts:e}=ob();return e.length===0?null:l.jsx("div",{className:"fixed bottom-4 right-4 z-[100] flex flex-col gap-2 w-80 max-w-[calc(100vw-2rem)]",children:e.map(t=>l.jsx(sC,{toast:t},t.id))})}function Px({wallet:e,onSelect:t,loading:r}){return l.jsxs("button",{onClick:()=>e.isAvailable&&t(e.id),disabled:r||!e.isAvailable,className:["w-full flex items-center gap-3 px-4 py-3 rounded-xl border transition-all text-left",e.isAvailable?"border-gray-700 bg-gray-800/60 hover:border-purple-600/60 hover:bg-gray-800 active:scale-[0.99] cursor-pointer":"border-gray-800/50 bg-gray-800/20 opacity-50 cursor-not-allowed"].join(" "),children:[l.jsx("img",{src:e.icon,alt:e.name,className:"w-8 h-8 rounded-lg object-contain flex-shrink-0",onError:n=>{n.target.style.display="none"}}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("p",{className:"text-sm font-medium text-gray-200 leading-none",children:e.name}),l.jsx("p",{className:"text-xs text-gray-500 mt-0.5 leading-none",children:e.isAvailable?"Ready to connect":"Not installed"})]}),e.isAvailable?l.jsx(Xh,{size:14,className:"text-gray-500 flex-shrink-0"}):l.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:n=>n.stopPropagation(),className:"flex items-center gap-1 text-xs text-gray-600 hover:text-purple-400 transition-colors flex-shrink-0",children:l.jsx(J8,{size:12})})]})}function lC(){const{connect:e,isLoading:t,getSupportedWallets:r}=On(),[n,a]=re.useState([]),[i,s]=re.useState(!0),[o,c]=re.useState(null),[d,p]=re.useState(null);re.useEffect(()=>{let z=!1;const K=async()=>{try{const k=await r();z||a(k)}catch{z||a([])}};K().finally(()=>{z||s(!1)});const D=setTimeout(K,800),T=setTimeout(K,2e3);return()=>{z=!0,clearTimeout(D),clearTimeout(T)}},[]);const y=async z=>{p(null),c(z);try{await e(z)}catch(K){p(K instanceof Error?K.message:"Connection failed"),c(null)}},g=n.filter(z=>z.isAvailable),v=n.filter(z=>!z.isAvailable),M=t||!!o;return l.jsxs("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:[l.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-xl flex items-center justify-center",children:l.jsx(w1,{size:20,className:"text-white"})}),l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-bold text-white leading-none",children:"CleverCon"}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-1",children:"AI Agent Marketplace · Stellar Testnet"})]})]}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md",children:[l.jsxs("div",{className:"text-center mb-6",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-900/50 border border-purple-800/50 rounded-xl flex items-center justify-center mx-auto mb-3",children:l.jsx(Cc,{size:18,className:"text-purple-400"})}),l.jsx("h2",{className:"text-lg font-semibold text-white mb-1.5",children:"Connect your wallet"}),l.jsx("p",{className:"text-sm text-gray-400 leading-relaxed",children:"Choose a Stellar wallet to access CleverCon. Your funds stay in your control."})]}),l.jsx("div",{className:"space-y-2 mb-6",children:i?l.jsxs("div",{className:"py-8 text-center",children:[l.jsx("div",{className:"w-5 h-5 border-2 border-purple-500 border-t-transparent rounded-full animate-spin mx-auto"}),l.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"Detecting wallets…"})]}):n.length===0?l.jsx("div",{className:"py-6 text-center",children:l.jsx("p",{className:"text-xs text-gray-500",children:"No Stellar wallets found."})}):l.jsxs(l.Fragment,{children:[g.map(z=>l.jsx(Px,{wallet:z,onSelect:y,loading:M},z.id)),v.length>0&&l.jsxs(l.Fragment,{children:[g.length>0&&l.jsx("p",{className:"text-xs text-gray-700 pt-1 pb-0.5 px-1",children:"Not installed"}),v.map(z=>l.jsx(Px,{wallet:z,onSelect:y,loading:M},z.id))]})]})}),d&&l.jsx("div",{className:"bg-red-950/50 border border-red-800/50 rounded-xl px-3 py-2.5 mb-4",children:l.jsx("p",{className:"text-xs text-red-400",children:d})}),l.jsx("div",{className:"space-y-2.5 pt-4 border-t border-gray-800",children:[{icon:cn,title:"Trustless treasury",desc:"Your USDC held by CleverVault, not us."},{icon:ga,title:"Personal AI agent",desc:"Name your orchestrator and hire specialists."},{icon:W8,title:"On-chain transparency",desc:"Every payment verifiable on stellar.expert."}].map(({icon:z,title:K,desc:D})=>l.jsxs("div",{className:"flex items-start gap-2.5",children:[l.jsx("div",{className:"w-6 h-6 bg-purple-900/40 border border-purple-800/40 rounded-lg flex items-center justify-center flex-shrink-0 mt-0.5",children:l.jsx(z,{size:11,className:"text-purple-400"})}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs font-medium text-gray-300",children:K}),l.jsx("p",{className:"text-xs text-gray-500",children:D})]})]},K))}),l.jsx("p",{className:"mt-4 text-center text-xs text-amber-600/80 font-medium",children:"Make sure your wallet is set to Stellar Testnet"})]}),l.jsx("p",{className:"mt-6 text-xs text-gray-700",children:"Powered by Stellar · Testnet"})]})}const cC=["Phoenix","Atlas","Sage","Nova","Orion","Ember"];function uC(){const{publicKey:e,signTransaction:t}=On(),{refresh:r}=Kc(),[n,a]=re.useState(""),[i,s]=re.useState(""),[o,c]=re.useState(!1),[d,p]=re.useState("form"),[y,g]=re.useState(null),[v,M]=re.useState(null),z=async()=>{if(!(!e||!n.trim())){g(null),p("creating");try{const T=await fetch("/api/orchestrators",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,name:n.trim(),system_prompt:i.trim()||void 0})});if(T.status===409){await r();return}if(!T.ok){const J=await T.json();throw new Error(J.error||`Server error ${T.status}`)}const{orchestrator_pubkey:k,orchestrator_secret:L,name:$,registration_xdr:F}=await T.json();let V=!1;if(F){p("signing");const J=await t(F,"Test SDF Network ; September 2015"),Y=await fetch("/api/orchestrators/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_address:e,signed_xdr:J})});if(!Y.ok){const ee=await Y.json();throw new Error(ee.error||"On-chain registration failed")}V=!0}localStorage.setItem(`clevercon_orchestrator_${e}`,JSON.stringify({user_address:e,orchestrator_pubkey:k,orchestrator_secret:L,orchestrator_name:$,system_prompt:i.trim()||null,registered_on_chain:V,created_at:new Date().toISOString()})),M({pubkey:k,name:$}),p("success"),await r()}catch(T){g(T.message??"Something went wrong"),p("form")}}};if(d==="success"&&v)return l.jsx("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md text-center",children:[l.jsx("div",{className:"w-14 h-14 bg-purple-600 rounded-2xl flex items-center justify-center mx-auto mb-4",children:l.jsx(tv,{size:24,className:"text-white"})}),l.jsxs("h2",{className:"text-xl font-bold text-white mb-1",children:[v.name," is ready"]}),l.jsx("p",{className:"text-sm text-gray-400 mb-6",children:"Your personal AI agent has been created on Stellar Testnet with XLM and testnet USDC — ready to pay agents immediately."}),l.jsxs("div",{className:"bg-gray-800 rounded-xl p-3 mb-4",children:[l.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Orchestrator wallet"}),l.jsx("p",{className:"text-xs font-mono text-gray-300 break-all",children:v.pubkey})]}),l.jsxs("a",{href:`https://stellar.expert/explorer/testnet/account/${v.pubkey}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 transition-colors",children:["View on stellar.expert ",l.jsx(Xr,{size:11})]}),l.jsx("p",{className:"mt-6 text-xs text-gray-600",children:"Redirecting to dashboard…"})]})});const K=d==="creating"||d==="signing",D=d==="creating"?`Creating ${n||"your agent"} — funding wallet & adding USDC…`:d==="signing"?"Check Freighter to sign…":"";return l.jsxs("div",{className:"min-h-screen bg-gray-950 flex flex-col items-center justify-center px-4",children:[l.jsxs("div",{className:"flex items-center gap-3 mb-8",children:[l.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-xl flex items-center justify-center",children:l.jsx(w1,{size:20,className:"text-white"})}),l.jsxs("div",{children:[l.jsx("h1",{className:"text-xl font-bold text-white leading-none",children:"CleverCon"}),l.jsx("p",{className:"text-xs text-gray-500 leading-none mt-1",children:"AI Agent Marketplace · Stellar Testnet"})]})]}),l.jsxs("div",{className:"bg-gray-900 border border-gray-800 rounded-2xl p-8 w-full max-w-md",children:[l.jsxs("div",{className:"mb-6",children:[l.jsx("h2",{className:"text-lg font-semibold text-white mb-1",children:"Create your AI agent"}),l.jsx("p",{className:"text-sm text-gray-400 leading-relaxed",children:"Your agent will plan tasks, hire specialized agents, and pay them on Stellar. Give it a name."})]}),l.jsxs("div",{className:"mb-4",children:[l.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1.5",children:"Agent name"}),l.jsx("input",{type:"text",value:n,onChange:T=>a(T.target.value),maxLength:30,disabled:K,placeholder:"e.g., Phoenix, Atlas, Sage, Nova…",className:"w-full bg-gray-800 border border-gray-700 rounded-xl px-3 py-2.5 text-sm text-white placeholder-gray-600 focus:outline-none focus:border-purple-500 disabled:opacity-50"}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:cC.map(T=>l.jsx("button",{onClick:()=>a(T),disabled:K,className:"text-xs px-2 py-0.5 rounded-full bg-gray-800 border border-gray-700 text-gray-400 hover:border-purple-600 hover:text-purple-400 transition-colors disabled:opacity-40",children:T},T))})]}),l.jsxs("div",{className:"mb-6",children:[l.jsxs("button",{onClick:()=>c(!o),className:"flex items-center gap-1 text-xs text-gray-500 hover:text-gray-300 transition-colors mb-2",children:[o?l.jsx(Mc,{size:12}):l.jsx(Ds,{size:12}),"Add personality (optional)"]}),o&&l.jsx("textarea",{value:i,onChange:T=>s(T.target.value),disabled:K,rows:3,placeholder:"e.g., Focus on research tasks. Always cite sources. Prefer cheaper agents.",className:"w-full bg-gray-800 border border-gray-700 rounded-xl px-3 py-2.5 text-xs text-white placeholder-gray-600 focus:outline-none focus:border-purple-500 resize-none disabled:opacity-50"})]}),y&&l.jsx("div",{className:"bg-red-900/30 border border-red-800/50 rounded-xl px-3 py-2 mb-4",children:l.jsx("p",{className:"text-xs text-red-400",children:y})}),l.jsx("button",{onClick:z,disabled:!n.trim()||K,className:"w-full flex items-center justify-center gap-2 bg-purple-600 hover:bg-purple-500 disabled:bg-purple-900 disabled:cursor-not-allowed text-white font-medium py-3 px-4 rounded-xl transition-colors text-sm",children:K?l.jsxs(l.Fragment,{children:[l.jsx(tw,{size:15,className:"animate-spin"}),D]}):`Create ${n.trim()||"Agent"}`}),l.jsx("p",{className:"mt-4 text-center text-xs text-gray-600",children:"A Stellar wallet is created, funded with XLM, and given a USDC balance automatically"})]})]})}function fC(e){const[t,r]=re.useState([]),[n,a]=re.useState(!1),i=re.useRef(null),s=re.useRef(null),o=re.useCallback(()=>{try{const d=new WebSocket(e);i.current=d,d.onopen=()=>{a(!0),s.current&&clearTimeout(s.current)},d.onmessage=p=>{try{const y=JSON.parse(p.data);r(g=>[y,...g].slice(0,200))}catch{}},d.onclose=()=>{a(!1),s.current=setTimeout(o,3e3)},d.onerror=()=>{d.close()}}catch{}},[e]);re.useEffect(()=>(o(),()=>{var d;s.current&&clearTimeout(s.current),(d=i.current)==null||d.close()}),[o]);const c=re.useCallback(()=>r([]),[]);return{events:t,connected:n,clearEvents:c}}const dC=()=>`q_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,hC=5*60*1e3,pC=30*60*1e3,bC=[{id:"run",label:"Run",icon:l.jsx(ga,{size:12})},{id:"financial",label:"Financial",icon:l.jsx(cn,{size:12})},{id:"agents",label:"Agents",icon:l.jsx(jc,{size:12})},{id:"history",label:"History",icon:l.jsx(Qh,{size:12})},{id:"register",label:"Register",icon:l.jsx(bf,{size:12})}];function mC({stuckMs:e,vaultTaskId:t,onForceComplete:r,onDismiss:n}){const a=e>=pC&&t!=null;return l.jsxs("div",{className:"border-t border-amber-900/40 bg-amber-950/40 px-4 py-2 flex items-center gap-3",children:[l.jsx(Ka,{size:11,className:"text-amber-400 shrink-0"}),l.jsxs("p",{className:"text-xs text-amber-300 flex-1",children:["No progress for ",Math.floor(e/6e4)," min.",a&&" Unlock vault balance?"]}),a&&l.jsx("button",{onClick:r,className:"text-xs px-2.5 py-1 rounded-lg bg-amber-700 hover:bg-amber-600 text-white transition-colors shrink-0",children:"Force Complete"}),l.jsx("button",{onClick:n,className:"text-amber-700 hover:text-amber-500 shrink-0",children:l.jsx(ya,{size:11})})]})}function xC(){const{publicKey:e,disconnect:t}=On(),{orchestrator:r}=Kc(),{addToast:n}=ob(),[a,i]=re.useState("run"),[s,o]=re.useState(!1),[c,d]=re.useState(null),[p,y]=re.useState(null),[g,v]=re.useState(!1),[M,z]=re.useState(!1),[K,D]=re.useState(!1),[T,k]=re.useState(!1),[L,$]=re.useState([]),F=re.useRef([]);F.current=L;const V=re.useRef(null);V.current=p;const[J,Y]=re.useState(null),[ee,x]=re.useState(null),[u,f]=re.useState(0),[_,E]=re.useState(!1),S=re.useRef(null),j=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,{events:R,connected:N,clearEvents:h}=fC(j);re.useEffect(()=>{if(!e)return;const fe=()=>sb(e).then(pe=>y((pe==null?void 0:pe.available)??0)).catch(()=>{});fe();const ie=setInterval(fe,1e4);return()=>clearInterval(ie)},[e]),re.useEffect(()=>{if(!s||!ee){S.current&&clearInterval(S.current),f(0);return}return S.current=setInterval(()=>f(Date.now()-ee),1e4),()=>{S.current&&clearInterval(S.current)}},[s,ee]);const C=re.useCallback((fe,ie)=>{$(pe=>{const me=fe?pe.map(Ce=>Ce.id===fe?{...Ce,status:"failed",failReason:ie}:Ce):pe.map(Ce=>Ce.status==="running"?{...Ce,status:"done"}:Ce),ye=me.find(Ce=>Ce.status==="queued");return ye?me.map(Ce=>Ce.id===ye.id?{...Ce,status:"countdown",scheduled_run_at:Date.now()+Ce.delay_ms}:Ce):me})},[]),ae=re.useCallback(async(fe,ie,pe)=>{o(!0),z(!1),E(!1),x(Date.now()),h();try{const me=await tM(fe,ie,e??void 0);(me==null?void 0:me.error)==="insufficient_vault_balance"&&(o(!1),x(null),n("Insufficient vault balance.","error"),pe&&C(pe,"Insufficient vault balance"))}catch{o(!1),x(null),pe&&C(pe,"Task submission failed")}},[e,h,n,C]),he=re.useRef(()=>{});he.current=()=>{const fe=F.current,ie=V.current,pe=fe.find(me=>me.status==="countdown"&&me.scheduled_run_at&&me.scheduled_run_at<=Date.now());if(pe){if(ie!==null&&ieme.map(ye=>ye.id===pe.id?{...ye,status:"running"}:ye)),ae(pe.task,pe.budget,pe.id)}},re.useEffect(()=>{const fe=setInterval(()=>he.current(),500);return()=>clearInterval(fe)},[]),re.useEffect(()=>{var ie,pe,me;const fe=R[0];if(fe){if(["task_complete","task_error","task_result","task_infeasible"].includes(fe.event)&&(o(!1),Y(null),x(null),E(!1),C()),["task_started","step_started","step_complete","plan_approved","plan_auto_approved"].includes(fe.event)&&(x(Date.now()),f(0),E(!1)),fe.event==="plan_approval_required"&&d(fe.data),["plan_approved","plan_rejected","plan_auto_approved"].includes(fe.event)&&d(null),fe.event==="budget_locked"&&Y(((ie=fe.data)==null?void 0:ie.contract_task_id)??null),fe.event==="task_result"){z(!0);const ye=fe.data;(ye==null?void 0:ye.status)==="complete"?n(`Done — $${(pe=ye.total_cost)==null?void 0:pe.toFixed(4)} USDC spent`,"success"):(ye==null?void 0:ye.status)==="partial"&&n("Partially completed — some steps failed","warning")}fe.event==="task_error"&&n(`Task failed: ${((me=fe.data)==null?void 0:me.error)??"unknown"}`,"error")}},[R]);const q=(fe,ie)=>ae(fe,ie),G=async()=>{if(!(!e||J==null))try{await dM(e,J),n("Force-complete submitted — vault balance will unlock shortly.","success"),o(!1),Y(null),x(null)}catch(fe){n(`Force-complete failed: ${fe.message}`,"error")}},W=(fe,ie,pe)=>{$(me=>[...me,{id:dC(),task:fe,budget:ie,delay_ms:pe,status:"queued"}])},be=(fe,ie,pe,me)=>{$(ye=>ye.map(Ce=>Ce.id===fe?{...Ce,task:ie,budget:pe,delay_ms:me}:Ce))},ue=fe=>{$(ie=>ie.filter(pe=>pe.id!==fe))},Q=()=>{$(fe=>fe.filter(ie=>ie.status!=="done"&&ie.status!=="failed"))},le=fe=>{k(!1);const ie=new Set(fe.map(me=>me.id)),pe=new Map(fe.map(me=>[me.id,me]));$(me=>{const ye=me.filter(Te=>Te.status!=="queued"||ie.has(Te.id)).map(Te=>{const ct=pe.get(Te.id);return ct?{...Te,task:ct.task,budget:ct.budget}:Te});if(ye.some(Te=>Te.status==="running"||Te.status==="countdown"))return ye;const je=ye.find(Te=>Te.status==="queued");return je?ye.map(Te=>Te.id===je.id?{...Te,status:"countdown",scheduled_run_at:Date.now()}:Te):ye})},Se=s&&!_&&u>=hC;return l.jsxs("div",{className:"min-h-screen bg-gray-950 text-gray-200 flex flex-col",children:[l.jsxs("header",{className:"sticky top-0 z-20 bg-gray-950/95 backdrop-blur-xl border-b border-gray-800/80 shrink-0",children:[l.jsxs("div",{className:"max-w-screen-xl mx-auto px-4 flex items-center gap-3 h-12",children:[l.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[l.jsx("div",{className:"w-6 h-6 bg-gradient-to-br from-purple-600 to-purple-800 rounded-md flex items-center justify-center",children:l.jsx(w1,{size:11,className:"text-white"})}),l.jsx("span",{className:"text-sm font-bold text-white",children:"CleverCon"})]}),s&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-amber-950/60 border border-amber-900/60 text-xs text-amber-400",children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"}),(r==null?void 0:r.name)??"Agent"," working"]}),c&&!s&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-purple-950/60 border border-purple-900/60 text-xs text-purple-400",children:[l.jsx(ga,{size:9,className:"animate-pulse"}),"Plan ready"]}),L.some(fe=>fe.status==="countdown")&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2 py-1 rounded-md bg-blue-950/60 border border-blue-900/60 text-xs text-blue-400",children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),"Next task queued"]}),p!==null&&l.jsxs("button",{onClick:()=>i("financial"),className:"hidden md:flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-purple-950/60 border border-purple-800/60 text-xs text-purple-300 hover:bg-purple-950/80 transition-colors",children:[l.jsx(cn,{size:9,className:"text-purple-500"}),l.jsxs("span",{className:"font-mono font-semibold",children:["$",p.toFixed(2)]}),l.jsx("span",{className:"text-purple-600 text-xs",children:"USDC"})]}),l.jsx("div",{className:"flex-1"}),l.jsx("nav",{className:"hidden sm:flex items-center gap-0.5",children:bC.map(fe=>l.jsxs("button",{onClick:()=>i(fe.id),className:`relative flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-all ${a===fe.id?"bg-gray-800 text-white":"text-gray-500 hover:text-gray-300 hover:bg-gray-800/50"}`,children:[fe.icon,fe.label,fe.id==="run"&&M&&!s&&l.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full bg-emerald-400"})]},fe.id))}),l.jsxs("div",{className:"flex items-center gap-2 pl-3 border-l border-gray-800 shrink-0",children:[l.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${N?"bg-emerald-400":"bg-red-500 animate-pulse"}`}),e&&l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"text-xs text-gray-600 font-mono hidden md:block",children:[e.slice(0,4),"…",e.slice(-4)]}),l.jsx("button",{onClick:t,title:"Disconnect",className:"text-gray-700 hover:text-gray-400 transition-colors",children:l.jsx(rw,{size:12})})]})]})]}),Se&&l.jsx(mC,{stuckMs:u,vaultTaskId:J,onForceComplete:G,onDismiss:()=>E(!0)})]}),l.jsxs("main",{className:"flex-1 max-w-screen-xl w-full mx-auto px-4 py-6",children:[a==="run"&&l.jsx("div",{className:"flex flex-col gap-5",children:l.jsxs("div",{className:"grid grid-cols-12 gap-4 items-start",children:[l.jsxs("div",{className:"col-span-12 lg:col-span-4 space-y-3",children:[l.jsx(HT,{onSubmit:q,isRunning:s,orchestratorName:(r==null?void 0:r.name)??"CleverCon",onFundVault:()=>v(!0),onBotClick:()=>D(!0)}),l.jsx(KT,{items:L,vaultAvailable:p,onAdd:W,onUpdate:be,onRemove:ue,onClearDone:Q,onRunQueue:()=>k(!0)})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-5 space-y-4",children:[l.jsx(VT,{events:R,connected:N,onClear:h,orchestratorName:(r==null?void 0:r.name)??"Agent"}),M&&l.jsxs(l.Fragment,{children:[l.jsx(ZT,{events:R}),l.jsx(QT,{events:R})]})]}),l.jsxs("div",{className:"col-span-12 lg:col-span-3 space-y-4",children:[l.jsx(wM,{forceOpenFund:g,onFundOpened:()=>v(!1),onDepositSuccess:()=>n("Deposit confirmed.","success"),onWithdrawSuccess:()=>n("Withdrawal confirmed.","success"),onError:fe=>n(fe,"error")}),l.jsx(jM,{}),l.jsx(yM,{events:R})]})]})}),a==="financial"&&l.jsx(KM,{}),a==="agents"&&l.jsx(DM,{onRegisterClick:()=>i("register")}),a==="history"&&l.jsx(XM,{}),a==="register"&&l.jsx("div",{className:"max-w-2xl mx-auto",children:l.jsx(eM,{})})]}),c&&l.jsx(bM,{plan:c,onDismiss:()=>d(null),orchestratorName:(r==null?void 0:r.name)??"Your Agent"}),K&&r&&l.jsx(JM,{name:r.name,pubkey:r.pubkey,registered:r.registered_on_chain??!1,onClose:()=>D(!1)}),T&&l.jsx(rC,{items:L.filter(fe=>fe.status==="queued"),vaultAvailable:p,orchestratorName:(r==null?void 0:r.name)??"CleverCon",onFundVault:()=>{k(!1),v(!0)},onConfirm:le,onClose:()=>k(!1)}),l.jsx(oC,{})]})}function yC(){const{isConnected:e,isLoading:t}=On(),{orchestrator:r,isLoading:n}=Kc();return t||e&&n?l.jsx("div",{className:"min-h-screen bg-gray-950 flex items-center justify-center",children:l.jsx("div",{className:"w-8 h-8 border-2 border-purple-500 border-t-transparent rounded-full animate-spin"})}):e?r?l.jsx(xC,{}):l.jsx(uC,{}):l.jsx(lC,{})}function gC(){return l.jsx(kT,{children:l.jsx(TM,{children:l.jsx(aC,{children:l.jsx(yC,{})})})})}window.addEventListener("unhandledrejection",e=>{var r;const t=((r=e.reason)==null?void 0:r.message)??String(e.reason??"");(t.includes("MetaMask")||t.includes("Failed to connect")||t.includes("no elements in sequence")||t.includes("ethereum")||t.includes("Web3"))&&e.preventDefault()});class vC extends re.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,r){console.error("[ErrorBoundary]",t,r)}render(){const{error:t}=this.state;return t?l.jsxs("div",{style:{minHeight:"100vh",background:"#0f1117",color:"#f87171",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2rem",fontFamily:"monospace"},children:[l.jsx("h2",{style:{color:"#fca5a5",marginBottom:"1rem"},children:"React render error"}),l.jsxs("pre",{style:{background:"#1e1e2e",padding:"1rem",borderRadius:"8px",maxWidth:"90vw",overflow:"auto",fontSize:"0.8rem",color:"#f87171"},children:[t.message,` `,t.stack]})]}):this.props.children}}F8.createRoot(document.getElementById("root")).render(l.jsx(re.StrictMode,{children:l.jsx(vC,{children:l.jsx(gC,{})})})); diff --git a/packages/orchestrator/public/index.html b/packages/orchestrator/public/index.html index 9ca4ed9..d038d4c 100644 --- a/packages/orchestrator/public/index.html +++ b/packages/orchestrator/public/index.html @@ -4,8 +4,8 @@ - AgentForge - + CleverCon + diff --git a/packages/orchestrator/src/__tests__/vault-client.integration.test.ts b/packages/orchestrator/src/__tests__/vault-client.integration.test.ts new file mode 100644 index 0000000..179066e --- /dev/null +++ b/packages/orchestrator/src/__tests__/vault-client.integration.test.ts @@ -0,0 +1,351 @@ +import 'dotenv/config'; + +import { beforeAll, describe, expect, it, vi } from 'vitest'; +import { + Keypair, + Asset, + TransactionBuilder, + Operation, + Networks, + BASE_FEE, + Horizon, + rpc as SorobanRpc, + Contract, + Address, + nativeToScVal, + scValToNative, + xdr, +} from '@stellar/stellar-sdk'; + +import { + buildDepositXdr, + buildRegisterOrchestratorXdr, + buildWithdrawXdr, + completeTask, + createTask, + getAccount, + getAvailable, + releasePayment, + submitSignedXdr, +} from '../agent-vault-client.js'; + +const NETWORK_PASSPHRASE = Networks.TESTNET; +const STROOPS_PER_USDC = 10_000_000n; +const HORIZON_URL = process.env.HORIZON_URL || 'https://horizon-testnet.stellar.org'; +const RPC_URL = process.env.STELLAR_RPC_URL || 'https://soroban-testnet.stellar.org'; +const USDC_ISSUER = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'; +const USDC = new Asset('USDC', USDC_ISSUER); +const AGENT_VAULT_CONTRACT_ID = process.env.AGENT_VAULT_CONTRACT_ID ?? ''; +const ORCHESTRATOR_SECRET_KEY = process.env.ORCHESTRATOR_SECRET_KEY; +const VAULT_ACTIVE = AGENT_VAULT_CONTRACT_ID.length > 10 && !AGENT_VAULT_CONTRACT_ID.startsWith('C...'); + +const describeIf = VAULT_ACTIVE && ORCHESTRATOR_SECRET_KEY ? describe : describe.skip; + +function horizonServer() { + return new Horizon.Server(HORIZON_URL); +} + +function sorobanServer() { + return new SorobanRpc.Server(RPC_URL, { allowHttp: false }); +} + +function usdcToStroops(usdc: number): bigint { + return BigInt(Math.round(usdc * Number(STROOPS_PER_USDC))); +} + +function stroopsToUsdc(stroops: bigint): number { + return Number(stroops) / Number(STROOPS_PER_USDC); +} + +async function pollForConfirmation(server: SorobanRpc.Server, hash: string): Promise { + for (let i = 0; i < 30; i += 1) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + const result = await server.getTransaction(hash); + if (result.status === SorobanRpc.Api.GetTransactionStatus.SUCCESS) { + return hash; + } + if (result.status === SorobanRpc.Api.GetTransactionStatus.FAILED) { + throw new Error(`Transaction failed: ${hash}`); + } + } + throw new Error(`Transaction timed out: ${hash}`); +} + +async function signAndSubmitUserXdr(keypair: Keypair, unsignedXdr: string): Promise { + const tx = TransactionBuilder.fromXDR(unsignedXdr, NETWORK_PASSPHRASE); + tx.sign(keypair); + return submitSignedXdr(tx.toXDR()); +} + +async function fundFriendbot(publicKey: string): Promise { + const response = await fetch(`https://friendbot.stellar.org?addr=${encodeURIComponent(publicKey)}`); + if (!response.ok) { + throw new Error(`Friendbot failed: ${await response.text()}`); + } +} + +async function addUsdcTrustline(keypair: Keypair): Promise { + const server = horizonServer(); + const account = await server.loadAccount(keypair.publicKey()); + const existing = account.balances.find( + (balance: any) => balance.asset_code === 'USDC' && balance.asset_issuer === USDC_ISSUER, + ); + if (existing) { + return; + } + + const tx = new TransactionBuilder(account, { + fee: '100', + networkPassphrase: NETWORK_PASSPHRASE, + }) + .addOperation(Operation.changeTrust({ asset: USDC })) + .setTimeout(30) + .build(); + + tx.sign(keypair); + await server.submitTransaction(tx); +} + +async function sendUsdcFromFundedOrchestrator(destination: string, amount: string): Promise { + if (!ORCHESTRATOR_SECRET_KEY) { + throw new Error('Missing ORCHESTRATOR_SECRET_KEY for USDC funding'); + } + + const source = Keypair.fromSecret(ORCHESTRATOR_SECRET_KEY); + const server = horizonServer(); + const account = await server.loadAccount(source.publicKey()); + const tx = new TransactionBuilder(account, { + fee: '100', + networkPassphrase: NETWORK_PASSPHRASE, + }) + .addOperation( + Operation.payment({ + destination, + asset: USDC, + amount, + }), + ) + .setTimeout(30) + .build(); + + tx.sign(source); + await server.submitTransaction(tx); +} + +async function getUsdcBalance(publicKey: string): Promise { + const server = horizonServer(); + const account = await server.loadAccount(publicKey); + const balance = account.balances.find( + (b: any) => b.asset_code === 'USDC' && b.asset_issuer === USDC_ISSUER, + ); + return parseFloat(balance?.balance ?? '0'); +} + +async function getTaskInfo(taskId: bigint) { + const server = sorobanServer(); + const contract = new Contract(AGENT_VAULT_CONTRACT_ID); + const dummy = Keypair.random(); + const tx = new TransactionBuilder( + { + accountId: () => dummy.publicKey(), + sequenceNumber: () => '0', + incrementSequenceNumber: () => {}, + } as any, + { + fee: BASE_FEE, + networkPassphrase: NETWORK_PASSPHRASE, + }, + ) + .addOperation(contract.call('get_task', nativeToScVal(taskId, { type: 'u64' }))) + .setTimeout(30) + .build(); + + const simulated = await server.simulateTransaction(tx); + if (SorobanRpc.Api.isSimulationError(simulated)) return null; + if (!('result' in simulated) || !simulated.result) return null; + return scValToNative(simulated.result.retval); +} + +async function createFreshVaultParticipants() { + const user = Keypair.random(); + const orchestrator = Keypair.random(); + + await fundFriendbot(user.publicKey()); + await fundFriendbot(orchestrator.publicKey()); + await addUsdcTrustline(user); + await addUsdcTrustline(orchestrator); + await sendUsdcFromFundedOrchestrator(user.publicKey(), '2'); + + return { user, orchestrator }; +} + +async function registerOrchestrator(user: Keypair, orchestrator: Keypair): Promise { + const unsignedXdr = await buildRegisterOrchestratorXdr( + user.publicKey(), + orchestrator.publicKey(), + 'vitest-orchestrator', + ); + if (!unsignedXdr) { + throw new Error('AGENT_VAULT_CONTRACT_ID is not configured for register_orchestrator'); + } + await signAndSubmitUserXdr(user, unsignedXdr); +} + +async function depositToVault(user: Keypair, amountUsdc: number): Promise { + const unsignedXdr = await buildDepositXdr(user.publicKey(), amountUsdc); + if (!unsignedXdr) { + throw new Error('AGENT_VAULT_CONTRACT_ID is not configured for deposit'); + } + await signAndSubmitUserXdr(user, unsignedXdr); +} + +async function withdrawFromVault(user: Keypair, amountUsdc: number): Promise { + const unsignedXdr = await buildWithdrawXdr(user.publicKey(), amountUsdc); + if (!unsignedXdr) { + throw new Error('AGENT_VAULT_CONTRACT_ID is not configured for withdraw'); + } + await signAndSubmitUserXdr(user, unsignedXdr); +} + +async function releasePaymentDirect(orchestrator: Keypair, taskId: bigint, amountUsdc: number): Promise { + const server = sorobanServer(); + const account = await server.getAccount(orchestrator.publicKey()); + const contract = new Contract(AGENT_VAULT_CONTRACT_ID); + + let tx = new TransactionBuilder(account, { + fee: BASE_FEE, + networkPassphrase: NETWORK_PASSPHRASE, + }) + .addOperation( + contract.call( + 'release_payment', + new Address(orchestrator.publicKey()).toScVal(), + nativeToScVal(taskId, { type: 'u64' }), + nativeToScVal(usdcToStroops(amountUsdc), { type: 'i128' }), + ), + ) + .setTimeout(60) + .build(); + + const simulated = await server.simulateTransaction(tx); + if (SorobanRpc.Api.isSimulationError(simulated)) { + throw new Error(`Simulation failed: ${simulated.error}`); + } + + tx = SorobanRpc.assembleTransaction(tx, simulated).build(); + tx.sign(orchestrator); + + const response = await server.sendTransaction(tx); + if (response.status === 'ERROR') { + throw new Error(`Send failed: ${JSON.stringify(response.errorResult)}`); + } + + return pollForConfirmation(server, response.hash); +} + +const AVAILABLE_ONE_USDC = usdcToStroops(1); +const AVAILABLE_TENTH_USDC = usdcToStroops(0.1); +const AVAILABLE_FIFTY_MILLIS_USDC = usdcToStroops(0.05); + +describeIf('Vault client integration', () => { + beforeAll(() => { + vi.setTimeout(30000); + }); + + it.concurrent('@integration Deposit increases available by 1 USDC', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + + const before = await getAvailable(user.publicKey()); + expect(before).toBe(0n); + + await depositToVault(user, 1); + + const after = await getAvailable(user.publicKey()); + expect(after).toBe(AVAILABLE_ONE_USDC); + }); + + it.concurrent('@integration Create task decreases available and get_task returns the task', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + await depositToVault(user, 1); + + const before = await getAvailable(user.publicKey()); + expect(before).toBe(AVAILABLE_ONE_USDC); + + const taskId = await createTask(orchestrator, 0.1); + expect(taskId).not.toBeNull(); + + const after = await getAvailable(user.publicKey()); + expect(after).toBe(AVAILABLE_ONE_USDC - AVAILABLE_TENTH_USDC); + + const task = await getTaskInfo(taskId!); + expect(task).not.toBeNull(); + expect(task.task_id ?? task.taskId ?? task.id ?? null).not.toBeNull(); + expect(task.plan_cost).toBe(AVAILABLE_TENTH_USDC); + expect(task.spent).toBe(0n); + expect(task.completed).toBe(false); + }); + + it.concurrent('@integration Release payment increases orchestrator USDC balance', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + await depositToVault(user, 1); + + const taskId = await createTask(orchestrator, 0.1); + expect(taskId).not.toBeNull(); + + const beforeBalance = await getUsdcBalance(orchestrator.publicKey()); + const hash = await releasePayment(orchestrator, taskId!, 0.05); + expect(hash).not.toBeNull(); + + const afterBalance = await getUsdcBalance(orchestrator.publicKey()); + expect(afterBalance).toBeGreaterThan(beforeBalance); + expect(afterBalance - beforeBalance).toBeCloseTo(0.05, 4); + }); + + it.concurrent('@integration Withdraw remaining balance leaves available at 0', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + await depositToVault(user, 1); + + const taskId = await createTask(orchestrator, 0.1); + expect(taskId).not.toBeNull(); + + await releasePayment(orchestrator, taskId!, 0.05); + await completeTask(orchestrator, taskId!); + + const account = await getAccount(user.publicKey()); + expect(account).not.toBeNull(); + expect(account?.available).toBeCloseTo(0.95, 4); + + await withdrawFromVault(user, 0.95); + const afterAvailable = await getAvailable(user.publicKey()); + expect(afterAvailable).toBe(0n); + }); + + it.concurrent('@integration Double release on completed task fails', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + await depositToVault(user, 1); + + const taskId = await createTask(orchestrator, 0.1); + expect(taskId).not.toBeNull(); + + await releasePayment(orchestrator, taskId!, 0.05); + await completeTask(orchestrator, taskId!); + + await expect(async () => { + await releasePaymentDirect(orchestrator, taskId!, 0.01); + }).rejects.toThrow(/Task already completed/); + }); + + it.concurrent('@integration Creating a task with insufficient available balance fails', { tags: ['integration'] }, async () => { + const { user, orchestrator } = await createFreshVaultParticipants(); + await registerOrchestrator(user, orchestrator); + await depositToVault(user, 1); + + const taskId = await createTask(orchestrator, 2); + expect(taskId).toBeNull(); + }); +});