UNPKG

@fort-major/masquerade

Version:

Privacy-focused MetaMask snap for the Internet Computer (ICP)

1 lines 1.16 MB
(()=>{var e={3206:(e,t,r)=>{"use strict";r.r(t),r.d(t,{encodePath:()=>f,fetchNodeKeys:()=>l,request:()=>u});var n=r(8412),i=r(9019),a=r(9504),o=r(2614),s=r(4620),c=r(8873);const u=async e=>{const{agent:t,paths:r}=e,o=n.Principal.from(e.canisterId),s=[...new Set(r)],u=s.map((e=>f(e,o))),g=new Map,m=s.map(((e,r)=>(async()=>{var n;try{const e=await t.readState(o,{paths:[u[r]]}),n=await a.KB.create({certificate:e.certificate,rootKey:t.rootKey,canisterId:o}),i=(r,n)=>{if("subnet"===n){return{path:n,data:l(e.certificate,o,t.rootKey)}}return{path:n,data:(0,a.ti)(r.lookup(f(n,o)))}},{path:m,data:b}=i(n,s[r]);if(b)switch(m){case"time":g.set(m,(0,c.b)(b));break;case"controllers":g.set(m,p(b));break;case"module_hash":g.set(m,A(b));break;case"subnet":g.set(m,b);break;case"candid":g.set(m,(new TextDecoder).decode(b));break;default:if("string"!=typeof m&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":g.set(m.key,b);break;case"leb128":g.set(m.key,(0,c.o)(b));break;case"cbor":g.set(m.key,d(b));break;case"hex":g.set(m.key,A(b));break;case"utf-8":g.set(m.key,h(b))}}else console.warn(`Expected to find result for path ${m}, but instead found nothing.`),"string"==typeof m?g.set(m,null):g.set(m.key,null)}catch(t){if(null===(n=null==t?void 0:t.message)||void 0===n?void 0:n.includes("Invalid certificate"))throw new i.e(t.message);"string"!=typeof e&&"key"in e&&"path"in e?g.set(e.key,null):g.set(e,null),console.group(),console.warn(`Expected to find result for path ${e}, but instead found nothing.`),console.warn(t),console.groupEnd()}})()));return await Promise.all(m),g},l=(e,t,r)=>{if(!t._isPrincipal)throw new Error("Invalid canisterId");const i=s.decode(new Uint8Array(e)),o=i.tree;let c,u=i.delegation;u&&u.subnet_id?c=n.Principal.fromUint8Array(new Uint8Array(u.subnet_id)):u||void 0===r?(c=n.Principal.selfAuthenticating(n.Principal.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),u={subnet_id:c.toUint8Array(),certificate:new ArrayBuffer(0)}):(c=n.Principal.selfAuthenticating(new Uint8Array(r)),u={subnet_id:c.toUint8Array(),certificate:new ArrayBuffer(0)});if(!(0,a.Gt)({canisterId:t,subnetId:c,tree:o}))throw new Error("Canister not in range");const l=(0,a.OZ)(["subnet",null==u?void 0:u.subnet_id,"node"],o),f=(0,a.UV)(l);f.length;const A=new Map;return f.forEach((e=>{Object.getPrototypeOf(new Uint8Array(e[1]));const t=n.Principal.from(new Uint8Array(e[1])).toText(),r=(0,a.OZ)(["public_key"],e[2]);if(44!==r.byteLength)throw new Error("Invalid public key length");A.set(t,r)})),{subnetId:n.Principal.fromUint8Array(new Uint8Array(u.subnet_id)).toText(),nodeKeys:A}},f=(e,t)=>{const r=new TextEncoder,n=e=>new DataView(r.encode(e).buffer).buffer,i=new DataView(t.toUint8Array().buffer).buffer;switch(e){case"time":return[n("time")];case"controllers":return[n("canister"),i,n("controllers")];case"module_hash":return[n("canister"),i,n("module_hash")];case"subnet":return[n("subnet")];case"candid":return[n("canister"),i,n("metadata"),n("candid:service")];default:if("key"in e&&"path"in e){if("string"==typeof e.path||e.path instanceof ArrayBuffer){const t=e.path,r="string"==typeof t?n(t):t;return[n("canister"),i,n("metadata"),r]}return e.path}}throw new Error(`An unexpeected error was encountered while encoding your path for canister status. Please ensure that your path, ${e} was formatted correctly.`)},A=e=>(0,o.NC)(e),d=e=>s.decode(e),h=e=>(new TextDecoder).decode(e),p=e=>d(e).map((e=>n.Principal.fromUint8Array(new Uint8Array(e))))},4620:(e,t,r)=>{"use strict";r.r(t),r.d(t,{CborTag:()=>s,decode:()=>f,encode:()=>c});var n=r(3492),i=r(7270),a=(r.n(i),r(2614));const o=i.SelfDescribeCborSerializer.withDefaultEncoders(!0);var s;function c(e){return o.serialize(e)}function u(e){const t=e.byteLength;let r=BigInt(0);for(let n=0;n<t;n++)r=r*BigInt(256)+BigInt(e[n]);return r}o.addEncoder(new class{get name(){return"Principal"}get priority(){return 0}match(e){return e&&!0===e._isPrincipal}encode(e){return i.value.bytes(e.toUint8Array())}}),o.addEncoder(new class{get name(){return"Buffer"}get priority(){return 1}match(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)}encode(e){return i.value.bytes(new Uint8Array(e))}}),o.addEncoder(new class{get name(){return"BigInt"}get priority(){return 1}match(e){return"bigint"==typeof e}encode(e){return e>BigInt(0)?i.value.tagged(2,i.value.bytes((0,a.H_)(e.toString(16)))):i.value.tagged(3,i.value.bytes((0,a.H_)((BigInt("-1")*e).toString(16))))}}),function(e){e[e.Uint64LittleEndian=71]="Uint64LittleEndian",e[e.Semantic=55799]="Semantic"}(s||(s={}));class l extends n.Decoder{createByteString(e){return(0,a.zo)(...e)}createByteStringFromHeap(e,t){return e===t?new ArrayBuffer(0):new Uint8Array(this._heap.slice(e,t))}}function f(e){const t=new Uint8Array(e);return new l({size:t.byteLength,tags:{2:e=>u(e),3:e=>-u(e),[s.Semantic]:e=>e}}).decodeFirst(t)}},9504:(e,t,r)=>{"use strict";r.d(t,{Gt:()=>I,I6:()=>A,KB:()=>h,OZ:()=>v,UV:()=>E,XO:()=>b,_X:()=>f,kt:()=>l,ti:()=>m});var n=r(4620),i=r(9019),a=r(8932),o=r(2614),s=r(8412),c=r(8529),u=r(8873);class l extends i.e{constructor(e){super(`Invalid certificate: ${e}`)}}const f={Empty:0,Fork:1,Labeled:2,Leaf:3,Pruned:4};function A(e){const t=e=>e.split("\n").map((e=>" "+e)).join("\n");switch(e[0]){case f.Empty:return"()";case f.Fork:if(e[1]instanceof Array&&e[2]instanceof ArrayBuffer){const r=A(e[1]),n=A(e[2]);return`sub(\n left:\n${t(r)}\n---\n right:\n${t(n)}\n)`}throw new Error("Invalid tree structure for fork");case f.Labeled:if(e[1]instanceof ArrayBuffer&&e[2]instanceof ArrayBuffer){const r=function(e){const t=new TextDecoder(void 0,{fatal:!0});try{return JSON.stringify(t.decode(e))}catch(t){return`data(...${e.byteLength} bytes)`}}(e[1]),n=A(e[2]);return`label(\n label:\n${t(r)}\n sub:\n${t(n)}\n)`}throw new Error("Invalid tree structure for labeled");case f.Leaf:if(!e[1])throw new Error("Invalid tree structure for leaf");return Array.isArray(e[1])?JSON.stringify(e[1]):`leaf(...${e[1].byteLength} bytes)`;case f.Pruned:if(!e[1])throw new Error("Invalid tree structure for pruned");return Array.isArray(e[1])?JSON.stringify(e[1]):`pruned(${(0,o.NC)(new Uint8Array(e[1]))}`;default:return`unknown(${JSON.stringify(e[0])})`}}function d(e,t){if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),n=new Uint8Array(t);for(let e=0;e<r.length;e++)if(r[e]!==n[e])return!1;return!0}class h{constructor(e,t,r,i,a=5){this._rootKey=t,this._canisterId=r,this._blsVerify=i,this._maxAgeInMinutes=a,this.cert=n.decode(new Uint8Array(e))}static async create(e){let t=e.blsVerify;t||(t=c.O);const r=new h(e.certificate,e.rootKey,e.canisterId,t,e.maxAgeInMinutes);return await r.verify(),r}lookup(e){return m(v(e,this.cert.tree))}lookup_label(e){return this.lookup([e])}async verify(){const e=await b(this.cert.tree),t=await this._checkDelegationAndGetKey(this.cert.delegation),r=this.cert.signature,n=function(e){const t=p.byteLength+g;if(e.byteLength!==t)throw new TypeError(`BLS DER-encoded public key must be ${t} bytes long`);const r=e.slice(0,p.byteLength);if(!d(r,p))throw new TypeError(`BLS DER-encoded public key is invalid. Expect the following prefix: ${p}, but get ${r}`);return e.slice(p.byteLength)}(t),i=(0,o.zo)(y("ic-state-root"),e);let a=!1;const s=this.lookup(["time"]);if(!s)throw new l("Certificate does not contain a time");const c=60*this._maxAgeInMinutes*1e3,f=Date.now(),A=f-c,h=f+3e5,m=(0,u.b)(s);if(m.getTime()<A)throw new l(`Certificate is signed more than ${this._maxAgeInMinutes} minutes in the past. Certificate time: `+m.toISOString()+" Current time: "+new Date(f).toISOString());if(m.getTime()>h)throw new l("Certificate is signed more than 5 minutes in the future. Certificate time: "+m.toISOString()+" Current time: "+new Date(f).toISOString());try{a=await this._blsVerify(new Uint8Array(n),new Uint8Array(r),new Uint8Array(i))}catch(e){a=!1}if(!a)throw new l("Signature verification failed")}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;const t=await h.create({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,maxAgeInMinutes:1/0});if(!I({canisterId:this._canisterId,subnetId:s.Principal.fromUint8Array(new Uint8Array(e.subnet_id)),tree:t.cert.tree}))throw new l(`Canister ${this._canisterId} not in range of delegations for subnet 0x${(0,o.NC)(e.subnet_id)}`);const r=t.lookup(["subnet",e.subnet_id,"public_key"]);if(!r)throw new Error(`Could not find subnet key for subnet 0x${(0,o.NC)(e.subnet_id)}`);return r}}const p=(0,o.H_)("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),g=96;function m(e){return e instanceof ArrayBuffer?e:e instanceof Uint8Array?e.buffer:void 0}async function b(e){switch(e[0]){case f.Empty:return(0,a.vp)(y("ic-hashtree-empty"));case f.Pruned:return e[1];case f.Leaf:return(0,a.vp)((0,o.zo)(y("ic-hashtree-leaf"),e[1]));case f.Labeled:return(0,a.vp)((0,o.zo)(y("ic-hashtree-labeled"),e[1],await b(e[2])));case f.Fork:return(0,a.vp)((0,o.zo)(y("ic-hashtree-fork"),await b(e[1]),await b(e[2])));default:throw new Error("unreachable")}}function y(e){const t=new Uint8Array([e.length]),r=(new TextEncoder).encode(e);return(0,o.zo)(t,r)}function v(e,t){if(0===e.length)switch(t[0]){case f.Leaf:if(!t[1])throw new Error("Invalid tree structure for leaf");return t[1]instanceof ArrayBuffer?t[1]:t[1]instanceof Uint8Array?t[1].buffer:t[1];case f.Fork:default:return t}const r=function(e,t){if(0===t.length)return;for(const r of t)if(r[0]===f.Labeled){if(d(e,r[1]))return r[2]}}("string"==typeof e[0]?(new TextEncoder).encode(e[0]):e[0],E(t));if(r)return v(e.slice(1),r)}function E(e){switch(e[0]){case f.Empty:return[];case f.Fork:return E(e[1]).concat(E(e[2]));default:return[e]}}function I(e){const{canisterId:t,subnetId:r,tree:i}=e,a=v(["subnet",r.toUint8Array(),"canister_ranges"],i);if(!(a&&a instanceof ArrayBuffer))throw new Error(`Could not find canister ranges for subnet ${r}`);return n.decode(a).map((e=>[s.Principal.fromUint8Array(e[0]),s.Principal.fromUint8Array(e[1])])).some((e=>e[0].ltEq(t)&&e[1].gtEq(t)))}},9019:(e,t,r)=>{"use strict";r.d(t,{e:()=>n});class n extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,n.prototype)}}},299:(e,t,r)=>{"use strict";r.r(t),r.d(t,{ACTOR_METHOD_WITH_HTTP_DETAILS:()=>Kt,Actor:()=>zt,ActorCallError:()=>Ut,AnonymousIdentity:()=>h,CanisterInstallMode:()=>qt,CanisterStatus:()=>k,Cbor:()=>g,Certificate:()=>S.KB,CertificateVerificationError:()=>S.kt,DER_COSE_OID:()=>tt,ED25519_OID:()=>rt,Ed25519PublicKey:()=>lt,Expiry:()=>w,HttpAgent:()=>It,IdentityInvalidError:()=>Et,NodeId:()=>S._X,ProxyAgent:()=>Ct,ProxyMessageKind:()=>wt,ProxyStubAgent:()=>Bt,QueryCallRejectedError:()=>Lt,ReplicaRejectCode:()=>a,RequestStatusResponseStatus:()=>gt,SECP256K1_OID:()=>nt,SignIdentity:()=>d,SubmitRequestType:()=>v,UpdateCallRejectedError:()=>Ft,blsVerify:()=>Wt.O,bufEquals:()=>l.IA,check_canister_ranges:()=>S.Gt,compare:()=>l.qu,concat:()=>l.zo,createAssetCanisterActor:()=>$t,createIdentityDescriptor:()=>p,decodeLen:()=>et,decodeLenBytes:()=>Xe,encodeLen:()=>We,encodeLenBytes:()=>Ve,fetchCandid:()=>Vt,flatten_forks:()=>S.UV,fromHex:()=>l.H_,getDefaultAgent:()=>Qt,getManagementCanister:()=>Jt,hash:()=>u.vp,hashOfMap:()=>u.E$,hashTreeToString:()=>S.I6,hashValue:()=>u.fm,httpHeadersTransform:()=>Q,lookupResultToBuffer:()=>S.ti,lookup_path:()=>S.OZ,makeExpiryTransform:()=>C,makeNonce:()=>E,makeNonceTransform:()=>B,polling:()=>i,randomNumber:()=>y,reconstruct:()=>S.XO,requestIdOf:()=>u.vH,toHex:()=>l.NC,uint8ToBuf:()=>l.wy,unwrapDER:()=>at,verify:()=>Wt.T,wrapDER:()=>it});var n={};r.r(n),r.d(n,{backoff:()=>Rt,chain:()=>Tt,conditionalDelay:()=>xt,defaultStrategy:()=>kt,maxAttempts:()=>Mt,once:()=>St,throttle:()=>Nt,timeout:()=>Dt});var i={};r.r(i),r.d(i,{defaultStrategy:()=>kt,pollForResponse:()=>Ot,strategy:()=>n});var a,o=r(5313);!function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"}(a||(a={}));var s=r(8412),c=r(9019),u=r(8932),l=r(2614),f=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};const A=(new TextEncoder).encode("\nic-request");class d{getPrincipal(){return this._principal||(this._principal=s.Principal.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){const{body:t}=e,r=f(e,["body"]),n=await(0,u.vH)(t);return Object.assign(Object.assign({},r),{body:{content:t,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign((0,l.zo)(A,n))}})}}class h{getPrincipal(){return s.Principal.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}}function p(e){return"getPublicKey"in e?{type:"PublicKeyIdentity",publicKey:(0,l.NC)(e.getPublicKey().toDer())}:{type:"AnonymousIdentity"}}var g=r(4620),m=r(4018),b=r(7270);const y=()=>{if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues){const e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if("undefined"!=typeof crypto&&crypto.getRandomValues){const e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return"undefined"!=typeof crypto&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(4294967295*Math.random())};var v;function E(){const e=new ArrayBuffer(16),t=new DataView(e),r=y(),n=y(),i=y(),a=y();return t.setUint32(0,r),t.setUint32(4,n),t.setUint32(8,i),t.setUint32(12,a),e}!function(e){e.Call="call"}(v||(v={}));const I=BigInt(1e6);class w{constructor(e){const t=BigInt(Math.floor(Date.now()+e-6e4))*I/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=t}toCBOR(){return b.value.u64(this._value.toString(16),16)}toHash(){return(0,m.dZ)(this._value)}}function B(e=E){return async t=>{const r=t.request.headers;t.request.headers=r,"call"===t.endpoint&&(t.body.nonce=e())}}function C(e){return async t=>{t.body.ingress_expiry=new w(e)}}function Q(e){const t=[];return e.forEach(((e,r)=>{t.push([r,e])})),t}class _ extends Error{constructor(e,t){super(e),this.response=t,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}}var k=r(3206),S=r(9504),x=r(2502);const M=BigInt(2**32-1),N=BigInt(32);function D(e,t=!1){return t?{h:Number(e&M),l:Number(e>>N&M)}:{h:0|Number(e>>N&M),l:0|Number(e&M)}}const R={fromBig:D,split:function(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:a,l:o}=D(e[i],t);[r[i],n[i]]=[a,o]}return[r,n]},toBig:(e,t)=>BigInt(e>>>0)<<N|BigInt(t>>>0),shrSH:(e,t,r)=>e>>>r,shrSL:(e,t,r)=>e<<32-r|t>>>r,rotrSH:(e,t,r)=>e>>>r|t<<32-r,rotrSL:(e,t,r)=>e<<32-r|t>>>r,rotrBH:(e,t,r)=>e<<64-r|t>>>r-32,rotrBL:(e,t,r)=>e>>>r-32|t<<64-r,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:(e,t,r)=>e<<r|t>>>32-r,rotlSL:(e,t,r)=>t<<r|e>>>32-r,rotlBH:(e,t,r)=>t<<r-32|e>>>64-r,rotlBL:(e,t,r)=>e<<r-32|t>>>64-r,add:function(e,t,r,n){const i=(t>>>0)+(n>>>0);return{h:e+r+(i/2**32|0)|0,l:0|i}},add3L:(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),add3H:(e,t,r,n)=>t+r+n+(e/2**32|0)|0,add4L:(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),add4H:(e,t,r,n,i)=>t+r+n+i+(e/2**32|0)|0,add5H:(e,t,r,n,i,a)=>t+r+n+i+a+(e/2**32|0)|0,add5L:(e,t,r,n,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(i>>>0)},T=R;var O=r(5216);const[j,U]=T.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)))),L=new Uint32Array(80),F=new Uint32Array(80);class q extends x.N{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:e,Al:t,Bh:r,Bl:n,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:u,Fh:l,Fl:f,Gh:A,Gl:d,Hh:h,Hl:p}=this;return[e,t,r,n,i,a,o,s,c,u,l,f,A,d,h,p]}set(e,t,r,n,i,a,o,s,c,u,l,f,A,d,h,p){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|i,this.Cl=0|a,this.Dh=0|o,this.Dl=0|s,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|A,this.Gl=0|d,this.Hh=0|h,this.Hl=0|p}process(e,t){for(let r=0;r<16;r++,t+=4)L[r]=e.getUint32(t),F[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|L[e-15],r=0|F[e-15],n=T.rotrSH(t,r,1)^T.rotrSH(t,r,8)^T.shrSH(t,r,7),i=T.rotrSL(t,r,1)^T.rotrSL(t,r,8)^T.shrSL(t,r,7),a=0|L[e-2],o=0|F[e-2],s=T.rotrSH(a,o,19)^T.rotrBH(a,o,61)^T.shrSH(a,o,6),c=T.rotrSL(a,o,19)^T.rotrBL(a,o,61)^T.shrSL(a,o,6),u=T.add4L(i,c,F[e-7],F[e-16]),l=T.add4H(u,n,s,L[e-7],L[e-16]);L[e]=0|l,F[e]=0|u}let{Ah:r,Al:n,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:u,Eh:l,El:f,Fh:A,Fl:d,Gh:h,Gl:p,Hh:g,Hl:m}=this;for(let e=0;e<80;e++){const t=T.rotrSH(l,f,14)^T.rotrSH(l,f,18)^T.rotrBH(l,f,41),b=T.rotrSL(l,f,14)^T.rotrSL(l,f,18)^T.rotrBL(l,f,41),y=l&A^~l&h,v=f&d^~f&p,E=T.add5L(m,b,v,U[e],F[e]),I=T.add5H(E,g,t,y,j[e],L[e]),w=0|E,B=T.rotrSH(r,n,28)^T.rotrBH(r,n,34)^T.rotrBH(r,n,39),C=T.rotrSL(r,n,28)^T.rotrBL(r,n,34)^T.rotrBL(r,n,39),Q=r&i^r&o^i&o,_=n&a^n&s^a&s;g=0|h,m=0|p,h=0|A,p=0|d,A=0|l,d=0|f,({h:l,l:f}=T.add(0|c,0|u,0|I,0|w)),c=0|o,u=0|s,o=0|i,s=0|a,i=0|r,a=0|n;const k=T.add3L(w,C,_);r=T.add3H(k,I,B,Q),n=0|k}({h:r,l:n}=T.add(0|this.Ah,0|this.Al,0|r,0|n)),({h:i,l:a}=T.add(0|this.Bh,0|this.Bl,0|i,0|a)),({h:o,l:s}=T.add(0|this.Ch,0|this.Cl,0|o,0|s)),({h:c,l:u}=T.add(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=T.add(0|this.Eh,0|this.El,0|l,0|f)),({h:A,l:d}=T.add(0|this.Fh,0|this.Fl,0|A,0|d)),({h,l:p}=T.add(0|this.Gh,0|this.Gl,0|h,0|p)),({h:g,l:m}=T.add(0|this.Hh,0|this.Hl,0|g,0|m)),this.set(r,n,i,a,o,s,c,u,l,f,A,d,h,p,g,m)}roundClean(){L.fill(0),F.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)}}const P=(0,O.hE)((()=>new q)),z=(BigInt(0),BigInt(1)),G=BigInt(2),H=e=>e instanceof Uint8Array,K=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function Y(e){if(!H(e))throw new Error("Uint8Array expected");let t="";for(let r=0;r<e.length;r++)t+=K[e[r]];return t}function J(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function Z(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(t/2);for(let t=0;t<r.length;t++){const n=2*t,i=e.slice(n,n+2),a=Number.parseInt(i,16);if(Number.isNaN(a)||a<0)throw new Error("Invalid byte sequence");r[t]=a}return r}function $(e){if(!H(e))throw new Error("Uint8Array expected");return J(Y(Uint8Array.from(e).reverse()))}function V(e,t){return Z(e.toString(16).padStart(2*t,"0"))}function W(e,t){return V(e,t).reverse()}function X(e,t,r){let n;if("string"==typeof t)try{n=Z(t)}catch(r){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${r}`)}else{if(!H(t))throw new Error(`${e} must be hex string or Uint8Array`);n=Uint8Array.from(t)}const i=n.length;if("number"==typeof r&&i!==r)throw new Error(`${e} expected ${r} bytes, got ${i}`);return n}function ee(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.length),0));let r=0;return e.forEach((e=>{if(!H(e))throw new Error("Uint8Array expected");t.set(e,r),r+=e.length})),t}const te={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function re(e,t,r={}){const n=(t,r,n)=>{const i=te[r];if("function"!=typeof i)throw new Error(`Invalid validator "${r}", expected function`);const a=e[t];if(!(n&&void 0===a||i(a,e)))throw new Error(`Invalid param ${String(t)}=${a} (${typeof a}), expected ${r}`)};for(const[e,r]of Object.entries(t))n(e,r,!1);for(const[e,t]of Object.entries(r))n(e,t,!0);return e}const ne=BigInt(0),ie=BigInt(1),ae=BigInt(2),oe=BigInt(3),se=BigInt(4),ce=BigInt(5),ue=BigInt(8);BigInt(9),BigInt(16);function le(e,t){const r=e%t;return r>=ne?r:t+r}function fe(e,t,r){if(r<=ne||t<ne)throw new Error("Expected power/modulo > 0");if(r===ie)return ne;let n=ie;for(;t>ne;)t&ie&&(n=n*e%r),e=e*e%r,t>>=ie;return n}function Ae(e,t,r){let n=e;for(;t-- >ne;)n*=n,n%=r;return n}function de(e,t){if(e===ne||t<=ne)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let r=le(e,t),n=t,i=ne,a=ie,o=ie,s=ne;for(;r!==ne;){const e=n/r,t=n%r,c=i-o*e,u=a-s*e;n=r,r=t,i=o,a=s,o=c,s=u}if(n!==ie)throw new Error("invert: does not exist");return le(i,t)}function he(e){if(e%se===oe){const t=(e+ie)/se;return function(e,r){const n=e.pow(r,t);if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root");return n}}if(e%ue===ce){const t=(e-ce)/ue;return function(e,r){const n=e.mul(r,ae),i=e.pow(n,t),a=e.mul(r,i),o=e.mul(e.mul(a,ae),i),s=e.mul(a,e.sub(o,e.ONE));if(!e.eql(e.sqr(s),r))throw new Error("Cannot find square root");return s}}return function(e){const t=(e-ie)/ae;let r,n,i;for(r=e-ie,n=0;r%ae===ne;r/=ae,n++);for(i=ae;i<e&&fe(i,t,e)!==e-ie;i++);if(1===n){const t=(e+ie)/se;return function(e,r){const n=e.pow(r,t);if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root");return n}}const a=(r+ie)/ae;return function(e,o){if(e.pow(o,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let s=n,c=e.pow(e.mul(e.ONE,i),r),u=e.pow(o,a),l=e.pow(o,r);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let r=e.sqr(l);t<s&&!e.eql(r,e.ONE);t++)r=e.sqr(r);const r=e.pow(c,ie<<BigInt(s-t-1));c=e.sqr(r),u=e.mul(u,r),l=e.mul(l,c),s=t}return u}}(e)}const pe=(e,t)=>(le(e,t)&ie)===ie,ge=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function me(e,t){const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}const be=BigInt(0),ye=BigInt(1);function ve(e){return re(e.Fp,ge.reduce(((e,t)=>(e[t]="function",e)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),re(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...me(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const Ee=BigInt(0),Ie=BigInt(1),we=BigInt(2),Be=BigInt(8),Ce={zip215:!0};function Qe(e){const t=function(e){const t=ve(e);return re(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}(e),{Fp:r,n,prehash:i,hash:a,randomBytes:o,nByteLength:s,h:c}=t,u=we<<BigInt(8*s)-Ie,l=r.create,f=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:r.sqrt(e*r.inv(t))}}catch(e){return{isValid:!1,value:Ee}}}),A=t.adjustScalarBytes||(e=>e),d=t.domain||((e,t,r)=>{if(t.length||r)throw new Error("Contexts/pre-hash are not supported");return e}),h=e=>"bigint"==typeof e&&Ee<e,p=(e,t)=>h(e)&&h(t)&&e<t,g=e=>e===Ee||p(e,u);function m(e,t){if(p(e,t))return e;throw new Error(`Expected valid scalar < ${t}, got ${typeof e} ${e}`)}function b(e){return e===Ee?e:m(e,n)}const y=new Map;function v(e){if(!(e instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(e,t,r,n){if(this.ex=e,this.ey=t,this.ez=r,this.et=n,!g(e))throw new Error("x required");if(!g(t))throw new Error("y required");if(!g(r))throw new Error("z required");if(!g(n))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(e){if(e instanceof E)throw new Error("extended point not allowed");const{x:t,y:r}=e||{};if(!g(t)||!g(r))throw new Error("invalid affine point");return new E(t,r,Ie,l(t*r))}static normalizeZ(e){const t=r.invertBatch(e.map((e=>e.ez)));return e.map(((e,r)=>e.toAffine(t[r]))).map(E.fromAffine)}_setWindowSize(e){this._WINDOW_SIZE=e,y.delete(this)}assertValidity(){const{a:e,d:r}=t;if(this.is0())throw new Error("bad point: ZERO");const{ex:n,ey:i,ez:a,et:o}=this,s=l(n*n),c=l(i*i),u=l(a*a),f=l(u*u),A=l(s*e);if(l(u*l(A+c))!==l(f+l(r*l(s*c))))throw new Error("bad point: equation left != right (1)");if(l(n*i)!==l(a*o))throw new Error("bad point: equation left != right (2)")}equals(e){v(e);const{ex:t,ey:r,ez:n}=this,{ex:i,ey:a,ez:o}=e,s=l(t*o),c=l(i*n),u=l(r*o),f=l(a*n);return s===c&&u===f}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){const{a:e}=t,{ex:r,ey:n,ez:i}=this,a=l(r*r),o=l(n*n),s=l(we*l(i*i)),c=l(e*a),u=r+n,f=l(l(u*u)-a-o),A=c+o,d=A-s,h=c-o,p=l(f*d),g=l(A*h),m=l(f*h),b=l(d*A);return new E(p,g,b,m)}add(e){v(e);const{a:r,d:n}=t,{ex:i,ey:a,ez:o,et:s}=this,{ex:c,ey:u,ez:f,et:A}=e;if(r===BigInt(-1)){const e=l((a-i)*(u+c)),t=l((a+i)*(u-c)),r=l(t-e);if(r===Ee)return this.double();const n=l(o*we*A),d=l(s*we*f),h=d+n,p=t+e,g=d-n,m=l(h*r),b=l(p*g),y=l(h*g),v=l(r*p);return new E(m,b,v,y)}const d=l(i*c),h=l(a*u),p=l(s*n*A),g=l(o*f),m=l((i+a)*(c+u)-d-h),b=g-p,y=g+p,I=l(h-r*d),w=l(m*b),B=l(y*I),C=l(m*I),Q=l(b*y);return new E(w,B,Q,C)}subtract(e){return this.add(e.negate())}wNAF(e){return B.wNAFCached(this,y,e,E.normalizeZ)}multiply(e){const{p:t,f:r}=this.wNAF(m(e,n));return E.normalizeZ([t,r])[0]}multiplyUnsafe(e){let t=b(e);return t===Ee?w:this.equals(w)||t===Ie?this:this.equals(I)?this.wNAF(t).p:B.unsafeLadder(this,t)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(e){const{ex:t,ey:n,ez:i}=this,a=this.is0();null==e&&(e=a?Be:r.inv(i));const o=l(t*e),s=l(n*e),c=l(i*e);if(a)return{x:Ee,y:Ie};if(c!==Ie)throw new Error("invZ was invalid");return{x:o,y:s}}clearCofactor(){const{h:e}=t;return e===Ie?this:this.multiplyUnsafe(e)}static fromHex(e,n=!1){const{d:i,a}=t,o=r.BYTES,s=(e=X("pointHex",e,o)).slice(),c=e[o-1];s[o-1]=-129&c;const A=$(s);A===Ee||m(A,n?u:r.ORDER);const d=l(A*A),h=l(d-Ie),p=l(i*d-a);let{isValid:g,value:b}=f(h,p);if(!g)throw new Error("Point.fromHex: invalid y coordinate");const y=(b&Ie)===Ie,v=0!=(128&c);if(!n&&b===Ee&&v)throw new Error("Point.fromHex: x=0 and x_0=1");return v!==y&&(b=l(-b)),E.fromAffine({x:b,y:A})}static fromPrivateKey(e){return _(e).point}toRawBytes(){const{x:e,y:t}=this.toAffine(),n=W(t,r.BYTES);return n[n.length-1]|=e&Ie?128:0,n}toHex(){return Y(this.toRawBytes())}}E.BASE=new E(t.Gx,t.Gy,Ie,l(t.Gx*t.Gy)),E.ZERO=new E(Ee,Ie,Ie,Ee);const{BASE:I,ZERO:w}=E,B=function(e,t){const r=(e,t)=>{const r=t.negate();return e?r:t},n=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:r,unsafeLadder(t,r){let n=e.ZERO,i=t;for(;r>be;)r&ye&&(n=n.add(i)),i=i.double(),r>>=ye;return n},precomputeWindow(e,t){const{windows:r,windowSize:i}=n(t),a=[];let o=e,s=o;for(let e=0;e<r;e++){s=o,a.push(s);for(let e=1;e<i;e++)s=s.add(o),a.push(s);o=s.double()}return a},wNAF(t,i,a){const{windows:o,windowSize:s}=n(t);let c=e.ZERO,u=e.BASE;const l=BigInt(2**t-1),f=2**t,A=BigInt(t);for(let e=0;e<o;e++){const t=e*s;let n=Number(a&l);a>>=A,n>s&&(n-=f,a+=ye);const o=t,d=t+Math.abs(n)-1,h=e%2!=0,p=n<0;0===n?u=u.add(r(h,i[o])):c=c.add(r(p,i[d]))}return{p:c,f:u}},wNAFCached(e,t,r,n){const i=e._WINDOW_SIZE||1;let a=t.get(e);return a||(a=this.precomputeWindow(e,i),1!==i&&t.set(e,n(a))),this.wNAF(i,a,r)}}}(E,8*s);function C(e){return le(e,n)}function Q(e){return C($(e))}function _(e){const t=s;e=X("private key",e,t);const r=X("hashed private key",a(e),2*t),n=A(r.slice(0,t)),i=r.slice(t,2*t),o=Q(n),c=I.multiply(o),u=c.toRawBytes();return{head:n,prefix:i,scalar:o,point:c,pointBytes:u}}function k(e=new Uint8Array,...t){const r=ee(...t);return Q(a(d(r,X("context",e),!!i)))}const S=Ce;I._setWindowSize(8);return{CURVE:t,getPublicKey:function(e){return _(e).pointBytes},sign:function(e,t,n={}){e=X("message",e),i&&(e=i(e));const{prefix:a,scalar:o,pointBytes:c}=_(t),u=k(n.context,a,e),l=I.multiply(u).toRawBytes(),f=C(u+k(n.context,l,c,e)*o);return b(f),X("result",ee(l,W(f,r.BYTES)),2*s)},verify:function(e,t,n,a=S){const{context:o,zip215:s}=a,c=r.BYTES;e=X("signature",e,2*c),t=X("message",t),i&&(t=i(t));const u=$(e.slice(c,2*c));let l,f,A;try{l=E.fromHex(n,s),f=E.fromHex(e.slice(0,c),s),A=I.multiplyUnsafe(u)}catch(e){return!1}if(!s&&l.isSmallOrder())return!1;const d=k(o,f.toRawBytes(),l.toRawBytes(),t);return f.add(l.multiplyUnsafe(d)).subtract(A).clearCofactor().equals(E.ZERO)},ExtendedPoint:E,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>o(r.BYTES),precompute:(e=8,t=E.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)}}}const _e=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ke=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Se=(BigInt(0),BigInt(1)),xe=BigInt(2),Me=BigInt(5),Ne=BigInt(10),De=BigInt(20),Re=BigInt(40),Te=BigInt(80);function Oe(e){const t=_e,r=e*e%t*e%t,n=Ae(r,xe,t)*r%t,i=Ae(n,Se,t)*e%t,a=Ae(i,Me,t)*i%t,o=Ae(a,Ne,t)*a%t,s=Ae(o,De,t)*o%t,c=Ae(s,Re,t)*s%t,u=Ae(c,Te,t)*c%t,l=Ae(u,Te,t)*c%t,f=Ae(l,Ne,t)*a%t;return{pow_p_5_8:Ae(f,xe,t)*e%t,b2:r}}function je(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Ue(e,t){const r=_e,n=le(t*t*t,r),i=le(n*n*t,r);let a=le(e*n*Oe(e*i).pow_p_5_8,r);const o=le(t*a*a,r),s=a,c=le(a*ke,r),u=o===e,l=o===le(-e,r),f=o===le(-e*ke,r);return u&&(a=s),(l||f)&&(a=c),pe(a,r)&&(a=le(-a,r)),{isValid:u||l,value:a}}const Le=function(e,t,r=!1,n={}){if(e<=ne)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:a}=me(e,t);if(a>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=he(e),s=Object.freeze({ORDER:e,BITS:i,BYTES:a,MASK:(c=i,(G<<BigInt(c-1))-z),ZERO:ne,ONE:ie,create:t=>le(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return ne<=t&&t<e},is0:e=>e===ne,isOdd:e=>(e&ie)===ie,neg:t=>le(-t,e),eql:(e,t)=>e===t,sqr:t=>le(t*t,e),add:(t,r)=>le(t+r,e),sub:(t,r)=>le(t-r,e),mul:(t,r)=>le(t*r,e),pow:(e,t)=>function(e,t,r){if(r<ne)throw new Error("Expected power > 0");if(r===ne)return e.ONE;if(r===ie)return t;let n=e.ONE,i=t;for(;r>ne;)r&ie&&(n=e.mul(n,i)),i=e.sqr(i),r>>=ie;return n}(s,e,t),div:(t,r)=>le(t*de(r,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>de(t,e),sqrt:n.sqrt||(e=>o(s,e)),invertBatch:e=>function(e,t){const r=new Array(t.length),n=t.reduce(((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n))),e.ONE),i=e.inv(n);return t.reduceRight(((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n))),i),r}(s,e),cmov:(e,t,r)=>r?t:e,toBytes:e=>r?W(e,a):V(e,a),fromBytes:e=>{if(e.length!==a)throw new Error(`Fp.fromBytes: expected ${a}, got ${e.length}`);return r?$(e):function(e){return J(Y(e))}(e)}});var c;return Object.freeze(s)}(_e,void 0,!0),Fe={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Le,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:P,randomBytes:O.O6,adjustScalarBytes:je,uvRatio:Ue},qe=Qe(Fe);function Pe(e,t,r){if(t.length>255)throw new Error("Context is too big");return(0,O.eV)((0,O.iY)("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,t.length]),t,e)}Qe({...Fe,domain:Pe}),Qe({...Fe,domain:Pe,prehash:P});const ze=(Le.ORDER+BigInt(3))/BigInt(8);Le.pow(xe,ze),Le.sqrt(Le.neg(Le.ONE)),Le.ORDER,BigInt(5),BigInt(8),BigInt(486662);!function(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");const r=e.sqrt(t);e.isOdd(r)&&e.neg(r)}(Le,Le.neg(BigInt(486664)));BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ge,He,Ke,Ye,Je=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},Ze=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class $e{constructor(e={}){Ge.set(this,void 0),He.set(this,void 0),this[Ke]=this.entries.bind(this),this[Ye]="ExpirableMap";const{source:t=[],expirationTime:r=6e5}=e,n=Date.now();Je(this,Ge,new Map([...t].map((([e,t])=>[e,{value:t,timestamp:n}]))),"f"),Je(this,He,r,"f")}prune(){const e=Date.now();for(const[t,r]of Ze(this,Ge,"f").entries())e-r.timestamp>Ze(this,He,"f")&&Ze(this,Ge,"f").delete(t);return this}set(e,t){this.prune();const r={value:t,timestamp:Date.now()};return Ze(this,Ge,"f").set(e,r),this}get(e){const t=Ze(this,Ge,"f").get(e);if(void 0!==t){if(!(Date.now()-t.timestamp>Ze(this,He,"f")))return t.value;Ze(this,Ge,"f").delete(e)}}clear(){Ze(this,Ge,"f").clear()}entries(){const e=Ze(this,Ge,"f").entries();return function*(){for(const[t,r]of e)yield[t,r.value]}()}values(){const e=Ze(this,Ge,"f").values();return function*(){for(const t of e)yield t.value}()}keys(){return Ze(this,Ge,"f").keys()}forEach(e,t){for(const[r,n]of Ze(this,Ge,"f").entries())e.call(t,n.value,r,this)}has(e){return Ze(this,Ge,"f").has(e)}delete(e){return Ze(this,Ge,"f").delete(e)}get size(){return Ze(this,Ge,"f").size}}Ge=new WeakMap,He=new WeakMap,Ke=Symbol.iterator,Ye=Symbol.toStringTag;const Ve=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},We=(e,t,r)=>{if(r<=127)return e[t]=r,1;if(r<=255)return e[t]=129,e[t+1]=r,2;if(r<=65535)return e[t]=130,e[t+1]=r>>8,e[t+2]=r,3;if(r<=16777215)return e[t]=131,e[t+1]=r>>16,e[t+2]=r>>8,e[t+3]=r,4;throw new Error("Length too long (> 4 bytes)")},Xe=(e,t)=>{if(e[t]<128)return 1;if(128===e[t])throw new Error("Invalid length 0");if(129===e[t])return 2;if(130===e[t])return 3;if(131===e[t])return 4;throw new Error("Length too long (> 4 bytes)")},et=(e,t)=>{const r=Xe(e,t);if(1===r)return e[t];if(2===r)return e[t+1];if(3===r)return(e[t+1]<<8)+e[t+2];if(4===r)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw new Error("Length too long (> 4 bytes)")},tt=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),rt=Uint8Array.from([48,5,6,3,43,101,112]),nt=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function it(e,t){const r=2+Ve(e.byteLength+1),n=t.byteLength+r+e.byteLength;let i=0;const a=new Uint8Array(1+Ve(n)+n);return a[i++]=48,i+=We(a,i,n),a.set(t,i),i+=t.byteLength,a[i++]=3,i+=We(a,i,e.byteLength+1),a[i++]=0,a.set(new Uint8Array(e),i),a}const at=(e,t)=>{let r=0;const n=(e,t)=>{if(i[r++]!==e)throw new Error("Expected: "+t)},i=new Uint8Array(e);if(n(48,"sequence"),r+=Xe(i,r),!(0,l.IA)(i.slice(r,r+t.byteLength),t))throw new Error("Not the expected OID.");r+=t.byteLength,n(3,"bit string");const a=et(i,r)-1;r+=Xe(i,r),n(0,"0 padding");const o=i.slice(r);if(a!==o.length)throw new Error(`DER payload mismatch: Expected length ${a} actual length ${o.length}`);return o};var ot,st,ct=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},ut=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class lt{constructor(e){if(ot.set(this,void 0),st.set(this,void 0),e.byteLength!==lt.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");ct(this,ot,e,"f"),ct(this,st,lt.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new lt(e)}static fromDer(e){return new lt(this.derDecode(e))}static derEncode(e){return it(e,rt).buffer}static derDecode(e){const t=at(e,rt);if(t.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return t}get rawKey(){return ut(this,ot,"f")}get derKey(){return ut(this,st,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}}ot=new WeakMap,st=new WeakMap,lt.RAW_KEY_LENGTH=32;var ft,At,dt,ht,pt,gt,mt=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r},bt=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};!function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"}(gt||(gt={}));const yt=3e5;class vt extends c.e{constructor(e){super(e),this.message=e}}class Et extends c.e{constructor(e){super(e),this.message=e}}class It{constructor(e={}){if(this.rootKey=(0,l.H_)("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae"),this._timeDiffMsecs=0,this._rootKeyFetched=!1,this._isAgent=!0,ft.set(this,[]),At.set(this,[]),dt.set(this,new $e({expirationTime:3e5})),ht.set(this,!0),pt.set(this,((e,t)=>{if(!1===bt(this,ht,"f"))return e;if(!t)throw new S.kt("Invalid signature from replica signed query: no matching node key found.");const{status:r,signatures:n=[],requestId:i}=e,a=(new TextEncoder).encode("\vic-response");for(const o of n){const{timestamp:n,identity:c}=o,f=s.Principal.fromUint8Array(c).toText();let A;if("replied"===r){const{reply:t}=e;A=(0,u.E$)({status:r,reply:t,timestamp:BigInt(n),request_id:i})}else{if("rejected"!==r)throw new Error(`Unknown status: ${r}`);{const{reject_code:t,reject_message:a,error_code:o}=e;A=(0,u.E$)({status:r,reject_code:t,reject_message:a,error_code:o,timestamp:BigInt(n),request_id:i})}}const d=(0,l.zo)(a,new Uint8Array(A)),h=null==t?void 0:t.nodeKeys.get(f);if(!h)throw new S.kt("Invalid signature from replica signed query: no matching node key found.");const p=lt.fromDer(h).rawKey;if(qe.verify(o.signature,new Uint8Array(d),new Uint8Array(p)))return e;throw new S.kt(`Invalid signature from replica ${f} signed query.`)}return e})),e.source){if(!(e.source instanceof It))throw new Error("An Agent's source can only be another HttpAgent");this._identity=e.source._identity,this._fetch=e.source._fetch,this._host=e.source._host,this._credentials=e.source._credentials}else this._fetch=e.fetch||function(){let e;if("undefined"!=typeof window){if(!window.fetch)throw new vt("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.");e=window.fetch.bind(window)}else if(void 0!==r.g){if(!r.g.fetch)throw new vt("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.");e=r.g.fetch.bind(r.g)}else"undefined"!=typeof self&&self.fetch&&(e=self.fetch.bind(self));if(e)return e;throw new vt("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}()||fetch.bind(r.g),this._fetchOptions=e.fetchOptions,this._callOptions=e.callOptions;if(void 0!==e.host)e.host.match(/^[a-z]+:/)||"undefined"==typeof window?this._host=new URL(e.host):this._host=new URL(window.location.protocol+"//"+e.host);else if(void 0!==e.source)this._host=e.source._host;else{const e="undefined"!=typeof window?window.location:void 0;e||(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."));const t=["ic0.app","icp0.io","127.0.0.1","localhost"],r=null==e?void 0:e.hostname;let n;r&&"string"==typeof r&&(n=t.find((e=>r.endsWith(e)))),e&&n?this._host=new URL(`${e.protocol}//${n}${e.port?":"+e.port:""}`):(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."))}if(void 0!==e.verifyQuerySignatures&&mt(this,ht,e.verifyQuerySignatures,"f"),this._retryTimes=void 0!==e.retryTimes&&e.retryTimes>=0?e.retryTimes:3,this._host.hostname.endsWith(".ic0.app")?this._host.hostname="ic0.app":this._host.hostname.endsWith(".icp0.io")?this._host.hostname="icp0.io":this._host.hostname.endsWith(".icp-api.io")&&(this._host.hostname="icp-api.io"),e.credentials){const{name:t,password:r}=e.credentials;this._credentials=`${t}${r?":"+r:""}`}this._identity=Promise.resolve(e.identity||new h),this.addTransform("update",B(E)),e.useQueryNonces&&this.addTransform("query",B(E))}isLocal(){const e=this._host.hostname;return"127.0.0.1"===e||e.endsWith("127.0.0.1")}addTransform(e,t,r=t.priority||0){if("update"===e){const e=bt(this,At,"f").findIndex((e=>(e.priority||0)<r));bt(this,At,"f").splice(e>=0?e:bt(this,At,"f").length,0,Object.assign(t,{priority:r}))}else if("query"===e){const e=bt(this,ft,"f").findIndex((e=>(e.priority||0)<r));bt(this,ft,"f").splice(e>=0?e:bt(this,ft,"f").length,0,Object.assign(t,{priority:r}))}}async getPrincipal(){if(!this._identity)throw new Et("This identity has expired due this application's security policy. Please refresh your authentication.");return(await this._identity).getPrincipal()}async call(e,t,r){const n=await(void 0!==r?await r:await this._identity);if(!n)throw new Et("This identity has expired due this application's security policy. Please refresh your authentication.");const i=s.Principal.from(e),a=t.effectiveCanisterId?s.Principal.from(t.effectiveCanisterId):i,o=n.getPrincipal()||s.Principal.anonymous();let c=new w(yt);Math.abs(this._timeDiffMsecs)>3e4&&(c=new w(yt+this._timeDiffMsecs));const l={request_type:v.Call,canister_id:i,method_name:t.methodName,arg:t.arg,sender:o,ingress_expiry:c};let f=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"call",body:l});f=await n.transformRequest(f);const A=g.encode(f.body),d=this._requestAndRetry((()=>this._fetch(""+new URL(`/api/v2/canister/${a.toText()}/call`,this._host),Object.assign(Object.assign(Object.assign({},this._callOptions),f.request),{body:A})))),[h,p]=await Promise.all([d,(0,u.vH)(l)]),m=await h.arrayBuffer(),b=200===h.status&&m.byteLength>0?g.decode(m):null;return{requestId:p,response:{ok:h.ok,status:h.status,statusText:h.statusText,body:b,headers:Q(h.headers)}}}async _requestAndRetry(e,t=0){let r;try{r=await e()}catch(r){if(this._retryTimes>t)return console.warn(`Caught exception while attempting to make request:\n ${r}\n Retrying request.`),await this._requestAndRetry(e,t+1);throw r}if(r.ok)return r;const n=await r.clone().text(),i=`Server returned an error:\n Code: ${r.status} (${r.statusText})\n Body: ${n}\n`;if(this._retryTimes>t)return console.warn(i+" Retrying request."),await this._requestAndRetry(e,t+1);throw new _(i,{ok:r.ok,status:r.status,statusText:r.statusText,headers:Q(r.headers)})}async query(e,t,r){const[n,i]=await Promise.all([(async()=>{const n=await(void 0!==r?await r:await this._identity);if(!n)throw new Et("This identity has expired due this application's security policy. Please refresh your authentication.");const i=s.Principal.from(e),a=(null==n?void 0:n.getPrincipal())||s.Principal.anonymous(),o={request_type:"query",canister_id:i,method_name:t.methodName,arg:t.arg,sender:a,ingress_expiry:new w(yt)},c=await(0,u.vH)(o);let l=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read",body:o});l=await(null==n?void 0:n.transformRequest(l));const f=g.encode(l.body),A=await this._requestAndRetry((()=>this._fetch(""+new URL(`/api/v2/canister/${i.toText()}/query`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),l.request),{body:f})))),d=g.decode(await A.arrayBuffer());return Object.assign(Object.assign({},d),{httpDetails:{ok:A.ok,status:A.status,statusText:A.statusText,headers:Q(A.headers)},requestId:c})})(),(async()=>{if(!bt(this,ht,"f"))return;const t=bt(this,dt,"f").get(e.toString());return t||(await this.fetchSubnetKeys(e.toString()),bt(this,dt,"f").get(e.toString()))})()]);if(!bt(this,ht,"f"))return n;try{return bt(this,pt,"f").call(this,n,i)}catch(t){console.warn("Query response verification failed. Retrying with fresh subnet keys."),bt(this,dt,"f").delete(e.toString()),await this.fetchSubnetKeys(e.toString());const r=bt(this,dt,"f").get(e.toString());if(!r)throw new S.kt("Invalid signature from replica signed query: no matching node key found.");return bt(this,pt,"f").call(this,n,r)}}async createReadStateRequest(e,t){const r=await(void 0!==t?await t:await this._identity);if(!r)throw new Et("This identity has expired due this application's security policy. Please refresh your authentication.");const n=(null==r?void 0:r.getPrincipal())||s.Principal.anonymous(),i=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:n,ingress_expiry:new w(yt)}});return null==r?void 0:r.transformRequest(i)}async readState(e,t,r,n){const i="string"==typeof e?s.Principal.fromText(e):e,a=null!=n?n:await this.createReadStateRequest(t,r),o=g.encode(a.body),c=await this._requestAndRetry((()=>this._fetch(""+new URL(`/api/v2/canister/${i}/read_state`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),a.request),{body:o}))));if(!c.ok)throw new Error(`Server returned an error:\n Code: ${c.status} (${c.statusText})\n Body: ${await c.text()}\n`);return g.decode(await c.arrayBuffer())}async syncTime(e){const t=await Promise.resolve().then(r.bind(r,3206)),n=Date.now();try{e||console.log("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");const r=(await t.request({canisterId:null!=e?e:s.Principal.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");r&&(this._timeDiffMsecs=Number(r)-Number(n))}catch(e){console.error("Caught exception while attempting to sync time:",e)}}async status(){const e=this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{},t=await this._requestAndRetry((()=>this._fetch(""+new URL("/api/v2/status",this._host),Object.assign({headers:e},this._fetchOptions))));return g.decode(await t.arrayBuffer())}async fetchRootKey(){return this._rootKeyFetched||(this.rootKey=(await this.status()).root_key,this._rootKeyFetched=!0),this.rootKey}invalidateIdentity(){this._identity=null}replaceIdentity(e){this._identity=Promise.resolve(e)}async fetchSubnetKeys(e){const t=