@latticexyz/entrykit 2.2.15-entrykit-9e962cbe09a2652e004a4090af986a0f3f2e523e → 2.2.15-entrykit-1694d69f0a35d77c65b0388284ad9c38c32168bd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- function rr(e){return{...e,appName:e.appName??document.title,appIcon:e.appIcon??document.querySelector("link[rel~='icon']")?.getAttribute("href")??"/favico.ico"}}import{Root as wr,DialogPortal as br,DialogContent as xr}from"@radix-ui/react-dialog";import{forwardRef as lr,useEffect as ur,useRef as Be,useState as Ke}from"react";import mr from"react-dom";var Te=`*, ::before, ::after {
1
+ function Ft(e){return{...e,appName:e.appName??document.title,appIcon:e.appIcon??document.querySelector("link[rel~='icon']")?.getAttribute("href")??"/favico.ico"}}import{Root as tr,DialogPortal as rr,DialogContent as or}from"@radix-ui/react-dialog";import{forwardRef as Yt,useEffect as jt,useRef as Te,useState as Me}from"react";import Xt from"react-dom";var ve=`*, ::before, ::after {
2
2
  --tw-border-spacing-x: 0;
3
3
  --tw-border-spacing-y: 0;
4
4
  --tw-translate-x: 0;
@@ -1436,7 +1436,7 @@ video {
1436
1436
  --tw-text-opacity: 1;
1437
1437
  color: rgb(255 255 255 / var(--tw-text-opacity));
1438
1438
  }
1439
- `;import{useResizeObserver as fr}from"usehooks-ts";import{mergeRefs as yr}from"react-merge-refs";import{createContext as or,useContext as ar}from"react";import{jsx as ir}from"react/jsx-runtime";var Ne=or(null);function Ee({frame:e,children:t}){if(ar(Ne))throw new Error("`FrameProvider` can only be used once.");return ir(Ne.Provider,{value:{frame:e},children:t})}import{useMediaQuery as pr}from"usehooks-ts";import"@rainbow-me/rainbowkit/styles.css";import{createContext as sr,useContext as qe}from"react";import{RainbowKitProvider as cr,lightTheme as He,midnightTheme as De}from"@rainbow-me/rainbowkit";import{useChains as dr}from"wagmi";function W(e){let t=e.contracts?.quarryPaymaster&&"address"in e.contracts.quarryPaymaster?e.contracts?.quarryPaymaster.address:void 0;if(!t)throw new Error(`Chain ${e.id} config did not include a \`quarryPaymaster\` contract address.`);return t}import{jsx as ze}from"react/jsx-runtime";var me=sr(null);function Le({config:e,children:t}){if(qe(me))throw new Error("`EntryKitProvider` can only be used once.");let o=dr().find(({id:s})=>s===e.chainId);if(!o)throw new Error(`Could not find configured chain for chain ID ${e.chainId}.`);let a=W(o);return ze(cr,{initialChain:0,appInfo:{appName:e.appName},theme:e.theme==="light"?He({borderRadius:"none"}):e.theme==="dark"?De({borderRadius:"none"}):{lightMode:He({borderRadius:"none"}),darkMode:De({borderRadius:"none"})},children:ze(me.Provider,{value:{...e,chain:o,paymasterAddress:a},children:t})})}function f(){let e=qe(me);if(!e)throw new Error("`useEntryKitConfig` can only be used within a `EntryKitProvider`.");return e}function Ue(){let{theme:e}=f(),t=pr("(prefers-color-scheme: dark)");return e??(t?"dark":"light")}import{jsx as H,jsxs as hr}from"react/jsx-runtime";function gr({onSize:e,...t}){let r=Be(null);return fr({ref:r,onResize:e}),H("div",{ref:r,...t,style:{...t.style,display:"inline-grid"}})}var _=lr(function({mode:t,children:r},n){let o=Be(null),[a,s]=Ke(!1),c=a?o.current:null,[l,i]=Ke({width:void 0,height:void 0}),d=c?.contentDocument,p=Ue();ur(()=>{d&&d.body.setAttribute("data-theme",p)},[d,p]);let u=t==="modal"?{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"2147483646"}:l.width&&l.height?{all:"unset",display:"inline-grid",width:`${l.width}px`,height:`${l.height}px`}:{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",opacity:0,pointerEvents:"none"};return H("iframe",{ref:yr([n,o]),style:u,onLoad:()=>s(!0),srcDoc:"<!doctype html><title>\u2026</title>",children:d?mr.createPortal(hr(Ee,{frame:c,children:[H("div",{children:t==="modal"?r:H(gr,{onSize:i,children:r})}),H("style",{dangerouslySetInnerHTML:{__html:Te}})]}),d.body):null})});import{twMerge as Fe}from"tailwind-merge";import{jsx as R,jsxs as vr}from"react/jsx-runtime";function Ge({open:e,onOpenChange:t,children:r}){return R(wr,{open:e,onOpenChange:t,children:R(br,{children:vr(_,{mode:"modal",children:[R("div",{className:Fe("fixed inset-0","bg-neutral-800/85","animate-in animate-duration-300 fade-in")}),R("div",{className:Fe("fixed inset-0","grid items-end sm:items-center","animate-in animate-duration-300 fade-in slide-in-from-bottom-16"),children:R("div",{children:R(xr,{className:"outline-none w-full max-w-[26rem] mx-auto","aria-describedby":void 0,onOpenAutoFocus:n=>{n.preventDefault()},children:r})})})]})})})}import{useCallback as fe,useMemo as Cr}from"react";import{useStore as Ar}from"zustand";import{createStore as kr}from"zustand/vanilla";var V=kr(()=>({open:!1}));function w(){let e=Ar(V,o=>o.open),t=fe(()=>{V.setState({open:!0})},[]),r=fe(()=>{V.setState({open:!1})},[]),n=fe(o=>{V.setState({open:o})},[]);return Cr(()=>({accountModalOpen:e,openAccountModal:t,closeAccountModal:r,toggleAccountModal:n}),[e,t,r,n])}import{twMerge as Vt}from"tailwind-merge";import{useAccount as sa,useConnectorClient as ca}from"wagmi";import{useAccount as Fn}from"wagmi";import{twMerge as z}from"tailwind-merge";import{twMerge as Sr}from"tailwind-merge";import{jsx as We,jsxs as Pr}from"react/jsx-runtime";function A({className:e,...t}){return Pr("svg",{className:Sr("-my-[0.125em] h-[1.25em] w-[1.25em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",...t,children:[We("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),We("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}import{jsx as D,jsxs as Or}from"react/jsx-runtime";var Rr=({variant:e="secondary"}={})=>z("group/button self-center leading-none outline-none border-4 border-transparent","transition hover:brightness-125 active:brightness-150","focus:border-orange-500","aria-disabled:pointer-events-none aria-busy:pointer-events-none","aria-disabled:opacity-50","p-[.75em] font-medium",{primary:z("bg-orange-600 text-white focus:border-yellow-400"),secondary:z("bg-neutral-700 text-white focus:border-orange-500"),tertiary:z("bg-neutral-800 text-white focus:border-orange-500")}[e]),b=({pending:e,variant:t,type:r,className:n,children:o,disabled:a,...s})=>D("button",{type:r||"button",className:z(Rr({variant:t,pending:e}),n),"aria-busy":e,"aria-disabled":a,disabled:a||e,...s,children:Or("span",{className:"grid grid-cols-[1fr_auto_1fr] gap-2",children:[D("span",{className:"flex items-center justify-end text-[.75em]",children:D("span",{className:"transition opacity-0 translate-x-2 group-aria-busy/button:opacity-100 group-aria-busy/button:translate-x-0 duration-100 group-aria-busy/button:duration-300",children:D(A,{})})}),D("span",{children:o})]})});import{useConnectModal as Gn}from"@rainbow-me/rainbowkit";import{useMutation as lt}from"@tanstack/react-query";import{useConnectors as qn}from"wagmi";import{createClient as In,custom as Mn,getAddress as Tn,numberToHex as st,SwitchChainError as Nn}from"viem";import{ChainNotConfiguredError as En,createConnector as Hn}from"wagmi";import{createStore as Ir}from"zustand/vanilla";import{persist as Mr}from"zustand/middleware";var g=Ir(Mr(()=>({publicKeys:{},activeCredential:null}),{name:"mud:passkey:cache"}));function Tr(e){e.key===g.persist.getOptions().name&&g.persist.rehydrate()}window.addEventListener("storage",Tr);import{smartAccountActions as Dn}from"permissionless/clients";import{toWebAuthnAccount as Vr}from"viem/account-abstraction";import{pad as Nr,encodeFunctionData as ye,hashMessage as Er,hashTypedData as Ve,encodeAbiParameters as Qe,stringToHex as Hr,size as Dr,encodePacked as zr,parseSignature as qr,BaseError as Lr}from"viem";import{entryPoint07Abi as Ur,entryPoint07Address as Kr,getUserOperationHash as Br,toSmartAccount as Fr}from"viem/account-abstraction";import{readContract as _e}from"viem/actions";import{parseSignature as Gr}from"webauthn-p256";async function $(e){let{client:t,owners:r,nonce:n=0n}=e,o=e.address,a={abi:Ur,address:Kr,version:"0.7"},s={abi:_r,address:"0x356336adA1619BeC1Ae4E6D94Dd9c0490DA414a8"};if(!r.length)throw new Error("`owners` must have at least one account.");function c(p){return p.type==="webAuthn"?p.publicKey:Nr(p.address)}let l=e.signer??r[0],i=r.indexOf(l);if(i===-1)throw new Error("`signer` must be one of `owners`.");let d=0n;return Fr({client:t,entryPoint:a,extend:{__isCoinbaseSmartAccount:!0,abi:Y,factory:s,signer:l},async encodeCalls(p){return p.length===1?ye({abi:Y,functionName:"execute",args:[p[0].to,p[0].value??0n,p[0].data??"0x"]}):ye({abi:Y,functionName:"executeBatch",args:[p.map(u=>({data:u.data??"0x",target:u.to,value:u.value??0n}))]})},async getAddress(){return o??=await _e(t,{...s,functionName:"getAddress",args:[r.map(c),n]}),o},async getNonce(){let p=8n;return d=(d+1n)%(1n<<p),(BigInt(Date.now())<<p)+d<<64n},async getFactoryArgs(){let p=ye({abi:s.abi,functionName:"createAccount",args:[r.map(c),n]});return{factory:s.address,factoryData:p}},async getStubSignature(){return l.type==="webAuthn"?"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001949fc7c88032b9fcb5f6efc7a7b8c63668eae9871b765e23123bb473ff57aa831a7c0d9276168ebcc29f2875a0239cffdf2a9cd1c2007c5c77c071db9264df1d000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2273496a396e6164474850596759334b7156384f7a4a666c726275504b474f716d59576f4d57516869467773222c226f726967696e223a2268747470733a2f2f7369676e2e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73657d00000000000000000000000000000000000000000000":q({signature:"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",ownerIndex:i})},async sign(p){let u=await this.getAddress(),m=ge({address:u,chainId:t.chain.id,hash:p.hash}),h=await Q({hash:m,owner:l});return q({signature:h,ownerIndex:i})},async signMessage(p){let{message:u}=p,m=await this.getAddress(),h=ge({address:m,chainId:t.chain.id,hash:Er(u)}),C=await Q({hash:h,owner:l});return q({signature:C,ownerIndex:i})},async signTypedData(p){let{domain:u,types:m,primaryType:h,message:C}=p,y=await this.getAddress(),ue=ge({address:y,chainId:t.chain.id,hash:Ve({domain:u,message:C,primaryType:h,types:m})}),E=await Q({hash:ue,owner:l});return q({signature:E,ownerIndex:i})},async signUserOperation(p){let{chainId:u=t.chain.id,...m}=p,h=await this.getAddress(),C=Br({chainId:u,entryPointAddress:a.address,entryPointVersion:a.version,userOperation:{...m,sender:h}}),y=await Q({hash:C,owner:l});return q({signature:y,ownerIndex:i})},userOperation:{async estimateGas(p){if(l.type==="webAuthn")return{verificationGasLimit:BigInt(Math.max(Number(p.verificationGasLimit??0n),8e5))}}},async isOwner(p){return await _e(t,{abi:Y,address:await this.getAddress(),functionName:"isOwnerBytes",args:[c(p)]})}})}async function Q({hash:e,owner:t}){if(t.type==="webAuthn"){let{signature:r,webauthn:n}=await t.sign({hash:e});return Wr({signature:r,webauthn:n})}if(t.sign)return t.sign({hash:e});throw new Lr("`owner` does not support raw sign.")}function ge({address:e,chainId:t,hash:r}){return Ve({domain:{chainId:t,name:"Coinbase Smart Wallet",verifyingContract:e,version:"1"},types:{CoinbaseSmartWalletMessage:[{name:"hash",type:"bytes32"}]},primaryType:"CoinbaseSmartWalletMessage",message:{hash:r}})}function Wr({webauthn:e,signature:t}){let{r,s:n}=Gr(t);return Qe([{components:[{name:"authenticatorData",type:"bytes"},{name:"clientDataJSON",type:"bytes"},{name:"challengeIndex",type:"uint256"},{name:"typeIndex",type:"uint256"},{name:"r",type:"uint256"},{name:"s",type:"uint256"}],type:"tuple"}],[{authenticatorData:e.authenticatorData,clientDataJSON:Hr(e.clientDataJSON),challengeIndex:BigInt(e.challengeIndex),typeIndex:BigInt(e.typeIndex),r,s:n}])}function q(e){let{ownerIndex:t}=e,r=(()=>{if(Dr(e.signature)!==65)return e.signature;let n=qr(e.signature);return zr(["bytes32","bytes32","uint8"],[n.r,n.s,n.yParity===0?27:28])})();return Qe([{components:[{name:"ownerIndex",type:"uint8"},{name:"signatureData",type:"bytes"}],type:"tuple"}],[{ownerIndex:t,signatureData:r}])}var Y=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[{name:"owner",type:"bytes"}],name:"AlreadyOwner",type:"error"},{inputs:[],name:"Initialized",type:"error"},{inputs:[{name:"owner",type:"bytes"}],name:"InvalidEthereumAddressOwner",type:"error"},{inputs:[{name:"key",type:"uint256"}],name:"InvalidNonceKey",type:"error"},{inputs:[{name:"owner",type:"bytes"}],name:"InvalidOwnerBytesLength",type:"error"},{inputs:[],name:"LastOwner",type:"error"},{inputs:[{name:"index",type:"uint256"}],name:"NoOwnerAtIndex",type:"error"},{inputs:[{name:"ownersRemaining",type:"uint256"}],name:"NotLastOwner",type:"error"},{inputs:[{name:"selector",type:"bytes4"}],name:"SelectorNotAllowed",type:"error"},{inputs:[],name:"Unauthorized",type:"error"},{inputs:[],name:"UnauthorizedCallContext",type:"error"},{inputs:[],name:"UpgradeFailed",type:"error"},{inputs:[{name:"index",type:"uint256"},{name:"expectedOwner",type:"bytes"},{name:"actualOwner",type:"bytes"}],name:"WrongOwnerAtIndex",type:"error"},{anonymous:!1,inputs:[{indexed:!0,name:"index",type:"uint256"},{indexed:!1,name:"owner",type:"bytes"}],name:"AddOwner",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"index",type:"uint256"},{indexed:!1,name:"owner",type:"bytes"}],name:"RemoveOwner",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{stateMutability:"payable",type:"fallback"},{inputs:[],name:"REPLAYABLE_NONCE_KEY",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"owner",type:"address"}],name:"addOwnerAddress",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"x",type:"bytes32"},{name:"y",type:"bytes32"}],name:"addOwnerPublicKey",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"functionSelector",type:"bytes4"}],name:"canSkipChainIdValidation",outputs:[{name:"",type:"bool"}],stateMutability:"pure",type:"function"},{inputs:[],name:"domainSeparator",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"entryPoint",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{name:"target",type:"address"},{name:"value",type:"uint256"},{name:"data",type:"bytes"}],name:"execute",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"target",type:"address"},{name:"value",type:"uint256"},{name:"data",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"executeBatch",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{name:"calls",type:"bytes[]"}],name:"executeWithoutChainIdValidation",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"sender",type:"address"},{name:"nonce",type:"uint256"},{name:"initCode",type:"bytes"},{name:"callData",type:"bytes"},{name:"callGasLimit",type:"uint256"},{name:"verificationGasLimit",type:"uint256"},{name:"preVerificationGas",type:"uint256"},{name:"maxFeePerGas",type:"uint256"},{name:"maxPriorityFeePerGas",type:"uint256"},{name:"paymasterAndData",type:"bytes"},{name:"signature",type:"bytes"}],name:"userOp",type:"tuple"}],name:"getUserOpHashWithoutChainId",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"implementation",outputs:[{name:"$",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{name:"owners",type:"bytes[]"}],name:"initialize",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{name:"account",type:"address"}],name:"isOwnerAddress",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"account",type:"bytes"}],name:"isOwnerBytes",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"x",type:"bytes32"},{name:"y",type:"bytes32"}],name:"isOwnerPublicKey",outputs:[{name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{name:"hash",type:"bytes32"},{name:"signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"result",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[],name:"nextOwnerIndex",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"index",type:"uint256"}],name:"ownerAtIndex",outputs:[{name:"",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[],name:"ownerCount",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"proxiableUUID",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{name:"index",type:"uint256"},{name:"owner",type:"bytes"}],name:"removeLastOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"index",type:"uint256"},{name:"owner",type:"bytes"}],name:"removeOwnerAtIndex",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"removedOwnersCount",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"hash",type:"bytes32"}],name:"replaySafeHash",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{name:"newImplementation",type:"address"},{name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{name:"sender",type:"address"},{name:"nonce",type:"uint256"},{name:"initCode",type:"bytes"},{name:"callData",type:"bytes"},{name:"callGasLimit",type:"uint256"},{name:"verificationGasLimit",type:"uint256"},{name:"preVerificationGas",type:"uint256"},{name:"maxFeePerGas",type:"uint256"},{name:"maxPriorityFeePerGas",type:"uint256"},{name:"paymasterAndData",type:"bytes"},{name:"signature",type:"bytes"}],name:"userOp",type:"tuple"},{name:"userOpHash",type:"bytes32"},{name:"missingAccountFunds",type:"uint256"}],name:"validateUserOp",outputs:[{name:"validationData",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],_r=[{inputs:[{name:"implementation_",type:"address"}],stateMutability:"payable",type:"constructor"},{inputs:[],name:"OwnerRequired",type:"error"},{inputs:[{name:"owners",type:"bytes[]"},{name:"nonce",type:"uint256"}],name:"createAccount",outputs:[{name:"account",type:"address"}],stateMutability:"payable",type:"function"},{inputs:[{name:"owners",type:"bytes[]"},{name:"nonce",type:"uint256"}],name:"getAddress",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"implementation",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initCodeHash",outputs:[{name:"",type:"bytes32"}],stateMutability:"view",type:"function"}];async function L(e,t){let{publicKeys:r}=g.getState(),n=r[t];if(!n)throw new Error("No public key found for passkey credential.");let a=[Vr({credential:{id:t,publicKey:n}})];return await $({client:e,owners:a})}import{bytesToHex as tn,hashMessage as rn}from"viem";import{sign as nn}from"webauthn-p256";import{bytesToHex as Qr,hexToBytes as Ye}from"webauthn-p256";import{concatBytes as Yr,utf8ToBytes as $r}from"@noble/curves/abstract/utils";async function j(e){let{authenticatorData:t,challengeIndex:r,clientDataJSON:n,typeIndex:o,userVerificationRequired:a}=e,s=o||n.indexOf('"type"'),c=r||n.indexOf('"challenge"'),l=Ye(t);if(l.length<37)throw new Error("Invalid authenticatorData");let i=l[32];if((i&1)!==1)throw new Error("Invalid authenticatorData");if(a&&(i&4)!==4)throw new Error("Invalid authenticatorData");if((i&8)!==8&&(i&16)===16)throw new Error("Invalid authenticatorData");let d='"type":"webauthn.get"';if(d!==n.slice(Number(s),d.length+1))throw new Error("Invalid clientDataJSON");if(!n.slice(Number(c)).match(/^"challenge":"(.*?)"/))throw new Error("Invalid clientDataJSON");let u=new Uint8Array(await crypto.subtle.digest("SHA-256",$r(n))),m=new Uint8Array(await crypto.subtle.digest("SHA-256",Yr(Ye(t),u)));return Qr(m)}import{sign as Xr}from"webauthn-p256";import{parseSignature as jr,serializePublicKey as $e}from"webauthn-p256";import{secp256r1 as je}from"@noble/curves/p256";function he(e){let{r:t,s:r}=jr(e.signatureHex),n=new je.Signature(t,r).addRecoveryBit(1).recoverPublicKey(e.messageHash.slice(2)),o=new je.Signature(t,r).addRecoveryBit(0).recoverPublicKey(e.messageHash.slice(2));return[$e(n),$e(o)]}import{hashMessage as Jr}from"viem";function Zr([e,t]){return en([...he(e),...he(t)])}async function Xe(e){let t=Jr(e.signatureHex),{signature:r,webauthn:n,raw:o}=await Xr({credentialId:e.credentialId,hash:t}),a=await j(n),s=Zr([e,{signatureHex:r,messageHash:a}]);if(s)return{publicKey:s,credential:o}}function en(e){let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}}async function we(){let e=tn(crypto.getRandomValues(new Uint8Array(256))),t=rn(e),{signature:r,webauthn:n,raw:o}=await nn({hash:t}),a=await(async()=>{let s=g.getState().publicKeys[o.id];if(s)return s;let c=await j(n),l=await Xe({credentialId:o.id,messageHash:c,signatureHex:r});if(!l)throw new Error("recovery failed");if(l.credential.id!==o.id)throw new Error("wrong credential");return g.setState(i=>({publicKeys:{...i.publicKeys,[o.id]:l.publicKey}})),l.publicKey})();return console.log("recovered passkey",o.id,a),g.setState(()=>({activeCredential:o.id})),{id:o.id,publicKey:a,raw:o}}import{createCredential as on}from"webauthn-p256";async function Je(){let e=await on({name:"MUD Account"});return console.log("created passkey",e),g.setState(t=>({activeCredential:e.id,publicKeys:{...t.publicKeys,[e.id]:e.publicKey}})),e}import{resourceToHex as an}from"@latticexyz/common";import{parseAbi as sn}from"viem";import cn from"@latticexyz/world/mud.config";var X={pollingInterval:250},U=an({type:"system",namespace:"",name:"unlimited"}),Ze=cn.namespaces.world.tables,et=sn(["function registerDelegation(address delegatee, bytes32 delegationControlId, bytes initCallData)"]);import{createBundlerClient as dn}from"viem/account-abstraction";var pn=new Set([31337,17420,17069,690]);function J({paymasterAddress:e,...t}){let r=t.chain??t.client?.chain;return dn({...X,paymaster:{getPaymasterData:async()=>({paymaster:e,paymasterData:"0x"})},userOperation:{estimateFeesPerGas:r&&pn.has(r.id)?async()=>({maxFeePerGas:100000n,maxPriorityFeePerGas:0n}):void 0},...t})}import{observer as zn}from"@latticexyz/explorer/observer";import{transactionQueue as An}from"@latticexyz/common/actions";import{createClient as kn,fallback as Sn,http as it,webSocket as Pn}from"viem";import{privateKeyToAccount as Rn,generatePrivateKey as On}from"viem/accounts";import{createTransport as xn,numberToHex as vn}from"viem";import{entryPoint07Address as nt}from"viem/account-abstraction";import{formatUserOperationRequest as ln}from"viem/account-abstraction";async function Z(e){return ln({callGasLimit:1000000n,preVerificationGas:100000n,verificationGasLimit:1000000n,paymasterVerificationGasLimit:100000n,paymasterPostOpGasLimit:100000n})}import{parseEther as un}from"viem";import{formatUserOperation as mn,toPackedUserOperation as fn,getUserOperationHash as yn,entryPoint07Address as tt,entryPoint07Abi as gn}from"viem/account-abstraction";import{setBalance as hn,writeContract as wn}from"viem/actions";import{getAction as bn}from"viem/utils";async function rt({executor:e,rpcUserOp:t}){e.chain.id===31337&&await hn(e.extend(()=>({mode:"anvil"})),{address:e.account.address,value:un("100")});let r=mn(t),n=r.preVerificationGas+r.verificationGasLimit+(r.paymasterVerificationGasLimit??0n)+(r.paymasterPostOpGasLimit??0n)+r.callGasLimit,o=fn(r),a=yn({userOperation:r,chainId:e.chain.id,entryPointVersion:"0.7",entryPointAddress:tt}),s=await bn(e,wn,"writeContract")({abi:gn,address:tt,functionName:"handleOps",args:[[o],e.account.address],chain:e.chain,account:e.account,gas:n});return{success:!0,userOpHash:a,receipt:{transactionHash:s}}}function ot({executor:e}){return()=>{let t=new Map;return xn({key:"userOpExecutor",type:"userOpExecutor",name:"User Operation Executor Transport",request:async({method:n,params:o})=>{if(n==="eth_chainId")return vn(e.chain.id);if(n==="eth_supportedEntryPoints")return[nt];if(n==="eth_sendUserOperation"){let[a,s]=o;if(s===nt){let c=await rt({executor:e,rpcUserOp:a});return t.set(c.userOpHash,c),c.userOpHash}}if(n==="eth_getUserOperationReceipt"){let[a]=o;return t.get(a)??null}if(n==="eth_estimateUserOperationGas")return await Z(o);throw new Error("Not implemented")}})}}function at(e){return t=>{let{request:r,...n}=e(t);return{request:async({method:a,params:s},c)=>a==="eth_estimateUserOperationGas"?Z(s):r({method:a,params:s},c),...n}}}import{http as Cn}from"viem";function O(e){return t=>{let r=t.chain?.rpcUrls&&"wiresaw"in t.chain.rpcUrls?Cn(t.chain.rpcUrls.wiresaw.http[0]):void 0;if(!r)return e(t);let n=e(t),o=r(t),a=null,s=new Map,c=new Map;return{...n,request:async({method:i,params:d},p)=>{if(i==="eth_chainId")return a??(a=await n.request({method:i,params:d},p));if(i==="eth_call")return o.request({method:"wiresaw_call",params:d});if(i==="eth_getTransactionReceipt"){let[u]=d,m=s.get(u)??await n.request({method:i,params:d});return!s.has(u)&&m&&s.set(u,m),m}if(i==="eth_sendUserOperation"){let u=await o.request({method:"wiresaw_sendUserOperation",params:d});return c.set(u.userOpHash,{success:!0,userOpHash:u.userOpHash,receipt:{transactionHash:u.txHash}}),u.userOpHash}if(i==="eth_getUserOperationReceipt"){let[u]=d,m=c.get(u)??await n.request({method:i,params:d});return!c.has(u)&&m&&c.set(u,m),m}return await n.request({method:i,params:d},p)}}}}function ee(e){let t=e.rpcUrls.bundler?.http[0],r=e.rpcUrls.bundler?.http[0]?O(at(it(t))):e.id===31337?ot({executor:kn({chain:e,transport:Sn([Pn(),it()]),account:Rn(On())}).extend(An())}):null;if(!r)throw new Error(`Chain ${e.id} config did not include a bundler RPC URL.`);return r}I.type="passkey";function I({chainId:e}){return Hn(t=>{if(!t.transports)throw new Error("Wagmi must be configured with transports to use the passkey connector.");let r=t.chains.find(i=>i.id===e);if(!r)throw new Error(`Could not find configured chain for chain ID ${e}.`);let n=t.transports[r.id];if(!n)throw new Error(`Could not find configured transport for chain ID ${e}.`);let o=O(n),a=W(r),s=ee(r),c=In({...X,chain:r,transport:o}),l=g.getState().activeCredential!=null;return{id:"passkey",type:I.type,name:"Passkey",async createPasskey(){let{id:i}=await Je(),d=await L(c,i);this.onAccountsChanged([d.address]),this.onConnect?.({chainId:st(e)})},async reusePasskey(){let{id:i}=await we(),d=await L(c,i);this.onAccountsChanged([d.address]),this.onConnect?.({chainId:st(e)})},hasPasskey(){return Object.keys(g.getState().publicKeys).length>0},async connect(i){if(console.log("connect"),i?.chainId!=null&&i.chainId!==e)throw new Error(`Can't connect to chain ${i.chainId}. Passkey connector is bound to chain ${e}.`);!g.getState().activeCredential&&!i?.isReconnecting&&await we();let d=await this.getAccounts();return l=d.length>0,{accounts:d,chainId:e}},async disconnect(){console.log("disconnect"),l=!1,g.setState({activeCredential:null})},async getAccounts(){console.log("getAccounts");let i=g.getState().activeCredential;if(!i)return[];try{console.log("getting account for credential",i);let d=await L(c,i);return console.log("got account",d),[d.address]}catch{console.log("could not get address for credential ID",i)}return[]},async getChainId(){return e},async isAuthorized(){return console.log("isAuthorized"),l?(await this.getAccounts()).length>0:!1},async switchChain(i){if(i.chainId!==e)throw new Error(`Can't connect to chain ${i.chainId}. Passkey connector is bound to chain ${e}.`);let d=t.chains.find(p=>p.id===i.chainId);if(!d)throw new Nn(new En);return d},onAccountsChanged(i){console.log("onAccountsChanged"),i.length>0?t.emitter.emit("change",{accounts:i.map(d=>Tn(d))}):this.onDisconnect()},onChainChanged(i){console.log("onChainChanged"),t.emitter.emit("change",{chainId:Number(i)})},async onConnect(i){console.log("onConnect");let d=await this.getAccounts();t.emitter.emit("connect",{accounts:d,chainId:e})},async onDisconnect(i){console.log("onDisconnect"),t.emitter.emit("disconnect"),l=!1},async getClient(i){console.log("passkeyConnector.getClient",i);let d=g.getState().activeCredential;if(!d)throw new Error("Not connected.");let p=await L(c,d);return J({paymasterAddress:a,transport:s,client:c,account:p}).extend(Dn()).extend(zn())},async getProvider(i){return Mn({request:c.transport.request})({retryCount:0})}}})}function ct(){let t=qn().find(r=>r.type===I.type);if(!t)throw new Error("Could not find passkey connector. Did you configure Wagmi with the EntryKit passkey connector or passkey wallet?");return t}import{twMerge as Ln}from"tailwind-merge";import{jsx as be,jsxs as Un}from"react/jsx-runtime";function k({className:e,...t}){return Un("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 8 8",fill:"currentColor",shapeRendering:"crispEdges",className:Ln("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...t,children:[be("path",{d:"M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z"}),be("path",{d:"M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z",opacity:".5"}),be("path",{d:"M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z"})]})}function dt(){let{appInfo:e}=f(),t=e?.name??document.title,r=location.host,n=e?.icon??document.querySelector("link[rel~='icon']")?.getAttribute("href")??"/favico.ico",o=e?.image;return{appName:t,appOrigin:r,appIcon:n,appImage:o}}import{useQuery as Kn}from"@tanstack/react-query";function te(e){return Kn({enabled:!!e,retry:!1,retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,queryKey:["preloadImage",e],queryFn:()=>new Promise((t,r)=>{if(!e)throw new Error("usePreloadImage: Must provide `url` to preload image.");let n=new Image;n.onload=()=>t(n),n.onerror=()=>r(new Error(`usePreloadImage: Could not load image.
1439
+ `;import{useResizeObserver as $t}from"usehooks-ts";import{mergeRefs as Jt}from"react-merge-refs";import{createContext as Bt,useContext as qt}from"react";import{jsx as Wt}from"react/jsx-runtime";var Ce=Bt(null);function ke({frame:e,children:t}){if(qt(Ce))throw new Error("`FrameProvider` can only be used once.");return Wt(Ce.Provider,{value:{frame:e},children:t})}import{useMediaQuery as _t}from"usehooks-ts";import"@rainbow-me/rainbowkit/styles.css";import{createContext as Qt,useContext as Ne}from"react";import{RainbowKitProvider as Ut,lightTheme as Ae,midnightTheme as Se}from"@rainbow-me/rainbowkit";import{useChains as Vt}from"wagmi";import{getChainContractAddress as Gt}from"viem";function F(e){return Gt({chain:e,contract:"quarryPaymaster"})}import{jsx as Pe}from"react/jsx-runtime";var ne=Qt(null);function Ee({config:e,children:t}){if(Ne(ne))throw new Error("`EntryKitProvider` can only be used once.");let n=Vt().find(({id:s})=>s===e.chainId);if(!n)throw new Error(`Could not find configured chain for chain ID ${e.chainId}.`);let a=F(n);return Pe(Ut,{initialChain:0,appInfo:{appName:e.appName},theme:e.theme==="light"?Ae({borderRadius:"none"}):e.theme==="dark"?Se({borderRadius:"none"}):{lightMode:Ae({borderRadius:"none"}),darkMode:Se({borderRadius:"none"})},children:Pe(ne.Provider,{value:{...e,chain:n,paymasterAddress:a},children:t})})}function p(){let e=Ne(ne);if(!e)throw new Error("`useEntryKitConfig` can only be used within a `EntryKitProvider`.");return e}function Ie(){let{theme:e}=p(),t=_t("(prefers-color-scheme: dark)");return e??(t?"dark":"light")}import{jsx as I,jsxs as er}from"react/jsx-runtime";function Zt({onSize:e,...t}){let r=Te(null);return $t({ref:r,onResize:e}),I("div",{ref:r,...t,style:{...t.style,display:"inline-grid"}})}var L=Yt(function({mode:t,children:r},o){let n=Te(null),[a,s]=Me(!1),d=a?n.current:null,[l,i]=Me({width:void 0,height:void 0}),c=d?.contentDocument,m=Ie();jt(()=>{c&&c.body.setAttribute("data-theme",m)},[c,m]);let g=t==="modal"?{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"2147483646"}:l.width&&l.height?{all:"unset",display:"inline-grid",width:`${l.width}px`,height:`${l.height}px`}:{all:"unset",display:"block",position:"fixed",inset:"0",width:"100%",height:"100%",opacity:0,pointerEvents:"none"};return I("iframe",{ref:Jt([o,n]),style:g,onLoad:()=>s(!0),srcDoc:"<!doctype html><title>\u2026</title>",children:c?Xt.createPortal(er(ke,{frame:d,children:[I("div",{children:t==="modal"?r:I(Zt,{onSize:i,children:r})}),I("style",{dangerouslySetInnerHTML:{__html:ve}})]}),c.body):null})});import{twMerge as He}from"tailwind-merge";import{jsx as A,jsxs as nr}from"react/jsx-runtime";function ze({open:e,onOpenChange:t,children:r}){return A(tr,{open:e,onOpenChange:t,children:A(rr,{children:nr(L,{mode:"modal",children:[A("div",{className:He("fixed inset-0","bg-neutral-800/85","animate-in animate-duration-300 fade-in")}),A("div",{className:He("fixed inset-0","grid items-end sm:items-center","animate-in animate-duration-300 fade-in slide-in-from-bottom-16"),children:A("div",{children:A(or,{className:"outline-none w-full max-w-[26rem] mx-auto","aria-describedby":void 0,onOpenAutoFocus:o=>{o.preventDefault()},children:r})})})]})})})}import{useCallback as ae,useMemo as ar}from"react";import{useStore as ir}from"zustand";import{createStore as sr}from"zustand/vanilla";var B=sr(()=>({open:!1}));function w(){let e=ir(B,n=>n.open),t=ae(()=>{B.setState({open:!0})},[]),r=ae(()=>{B.setState({open:!1})},[]),o=ae(n=>{B.setState({open:n})},[]);return ar(()=>({accountModalOpen:e,openAccountModal:t,closeAccountModal:r,toggleAccountModal:o}),[e,t,r,o])}import{twMerge as Nt}from"tailwind-merge";import{useAccount as vn,useConnectorClient as Cn}from"wagmi";import{useAccount as oo}from"wagmi";import{twMerge as T}from"tailwind-merge";import{twMerge as cr}from"tailwind-merge";import{jsx as Re,jsxs as dr}from"react/jsx-runtime";function v({className:e,...t}){return dr("svg",{className:cr("-my-[0.125em] h-[1.25em] w-[1.25em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",...t,children:[Re("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),Re("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}import{jsx as M,jsxs as pr}from"react/jsx-runtime";var lr=({variant:e="secondary"}={})=>T("group/button self-center leading-none outline-none border-4 border-transparent","transition hover:brightness-125 active:brightness-150","focus:border-orange-500","aria-disabled:pointer-events-none aria-busy:pointer-events-none","aria-disabled:opacity-50","p-[.75em] font-medium",{primary:T("bg-orange-600 text-white focus:border-yellow-400"),secondary:T("bg-neutral-700 text-white focus:border-orange-500"),tertiary:T("bg-neutral-800 text-white focus:border-orange-500")}[e]),y=({pending:e,variant:t,type:r,className:o,children:n,disabled:a,...s})=>M("button",{type:r||"button",className:T(lr({variant:t,pending:e}),o),"aria-busy":e,"aria-disabled":a,disabled:a||e,...s,children:pr("span",{className:"grid grid-cols-[1fr_auto_1fr] gap-2",children:[M("span",{className:"flex items-center justify-end text-[.75em]",children:M("span",{className:"transition opacity-0 translate-x-2 group-aria-busy/button:opacity-100 group-aria-busy/button:translate-x-0 duration-100 group-aria-busy/button:duration-300",children:M(v,{})})}),M("span",{children:n})]})});import{useConnectModal as no}from"@rainbow-me/rainbowkit";import{useMutation as _e}from"@tanstack/react-query";import{useConnectors as Jr}from"wagmi";import{createClient as Gr,custom as Qr,getAddress as Ur,numberToHex as Ge,SwitchChainError as Vr}from"viem";import{ChainNotConfiguredError as _r,createConnector as Yr}from"wagmi";import{createStore as mr}from"zustand/vanilla";import{persist as ur}from"zustand/middleware";var f=mr(ur(()=>({publicKeys:{},activeCredential:null}),{name:"mud:passkey:cache"}));function fr(e){e.key===f.persist.getOptions().name&&f.persist.rehydrate()}window.addEventListener("storage",fr);import{smartAccountActions as jr}from"permissionless/clients";import{toWebAuthnAccount as gr}from"viem/account-abstraction";import{toCoinbaseSmartAccount as hr}from"@latticexyz/common/accounts";async function H(e,t){let{publicKeys:r}=f.getState(),o=r[t];if(!o)throw new Error("No public key found for passkey credential.");let a=[gr({credential:{id:t,publicKey:o}})];return await hr({client:e,owners:a})}import{bytesToHex as Sr,hashMessage as Pr}from"viem";import{sign as Nr}from"webauthn-p256";import{bytesToHex as wr,hexToBytes as Ke}from"webauthn-p256";import{concatBytes as yr,utf8ToBytes as br}from"@noble/curves/abstract/utils";async function q(e){let{authenticatorData:t,challengeIndex:r,clientDataJSON:o,typeIndex:n,userVerificationRequired:a}=e,s=n||o.indexOf('"type"'),d=r||o.indexOf('"challenge"'),l=Ke(t);if(l.length<37)throw new Error("Invalid authenticatorData");let i=l[32];if((i&1)!==1)throw new Error("Invalid authenticatorData");if(a&&(i&4)!==4)throw new Error("Invalid authenticatorData");if((i&8)!==8&&(i&16)===16)throw new Error("Invalid authenticatorData");let c='"type":"webauthn.get"';if(c!==o.slice(Number(s),c.length+1))throw new Error("Invalid clientDataJSON");if(!o.slice(Number(d)).match(/^"challenge":"(.*?)"/))throw new Error("Invalid clientDataJSON");let g=new Uint8Array(await crypto.subtle.digest("SHA-256",br(o))),h=new Uint8Array(await crypto.subtle.digest("SHA-256",yr(Ke(t),g)));return wr(h)}import{sign as vr}from"webauthn-p256";import{parseSignature as xr,serializePublicKey as Oe}from"webauthn-p256";import{secp256r1 as De}from"@noble/curves/p256";function ie(e){let{r:t,s:r}=xr(e.signatureHex),o=new De.Signature(t,r).addRecoveryBit(1).recoverPublicKey(e.messageHash.slice(2)),n=new De.Signature(t,r).addRecoveryBit(0).recoverPublicKey(e.messageHash.slice(2));return[Oe(o),Oe(n)]}import{hashMessage as Cr}from"viem";function kr([e,t]){return Ar([...ie(e),...ie(t)])}async function Fe(e){let t=Cr(e.signatureHex),{signature:r,webauthn:o,raw:n}=await vr({credentialId:e.credentialId,hash:t}),a=await q(o),s=kr([e,{signatureHex:r,messageHash:a}]);if(s)return{publicKey:s,credential:n}}function Ar(e){let t=new Set;for(let r of e){if(t.has(r))return r;t.add(r)}}async function se(){let e=Sr(crypto.getRandomValues(new Uint8Array(256))),t=Pr(e),{signature:r,webauthn:o,raw:n}=await Nr({hash:t}),a=await(async()=>{let s=f.getState().publicKeys[n.id];if(s)return s;let d=await q(o),l=await Fe({credentialId:n.id,messageHash:d,signatureHex:r});if(!l)throw new Error("recovery failed");if(l.credential.id!==n.id)throw new Error("wrong credential");return f.setState(i=>({publicKeys:{...i.publicKeys,[n.id]:l.publicKey}})),l.publicKey})();return console.log("recovered passkey",n.id,a),f.setState(()=>({activeCredential:n.id})),{id:n.id,publicKey:a,raw:n}}import{createCredential as Er}from"webauthn-p256";async function Le(){let e=await Er({name:"MUD Account"});return console.log("created passkey",e),f.setState(t=>({activeCredential:e.id,publicKeys:{...t.publicKeys,[e.id]:e.publicKey}})),e}import{resourceToHex as Ir}from"@latticexyz/common";import{parseAbi as Mr}from"viem";import Tr from"@latticexyz/world/mud.config";var W={pollingInterval:250},z=Ir({type:"system",namespace:"",name:"unlimited"}),Be=Tr.namespaces.world.tables,qe=Mr(["function registerDelegation(address delegatee, bytes32 delegationControlId, bytes initCallData)"]);import{createBundlerClient as Hr}from"viem/account-abstraction";var zr=new Set([31337,17420,17069,690]);function G({paymasterAddress:e,...t}){let r=t.chain??t.client?.chain;return Hr({...W,paymaster:{getPaymasterData:async()=>({paymaster:e,paymasterData:"0x"})},userOperation:{estimateFeesPerGas:r&&zr.has(r.id)?async()=>({maxFeePerGas:100000n,maxPriorityFeePerGas:0n}):void 0},...t})}import{observer as Xr}from"@latticexyz/explorer/observer";import{transactionQueue as Rr}from"@latticexyz/common/actions";import{createClient as Kr,fallback as Or,http as We,webSocket as Dr}from"viem";import{privateKeyToAccount as Fr,generatePrivateKey as Lr}from"viem/accounts";import{wiresaw as Br}from"@latticexyz/wiresaw/internal";import{gasEstimator as qr,userOpExecutor as Wr}from"@latticexyz/paymaster/internal";function Q(e){let t=e.rpcUrls.bundler?.http[0],r=t?qr(Br(We(t))):e.id===31337?Wr({executor:Kr({chain:e,transport:Or([Dr(),We()]),account:Fr(Lr())}).extend(Rr())}):null;if(!r)throw new Error(`Chain ${e.id} config did not include a bundler RPC URL.`);return r}import{wiresaw as $r}from"@latticexyz/wiresaw/internal";S.type="passkey";function S({chainId:e}){return Yr(t=>{if(!t.transports)throw new Error("Wagmi must be configured with transports to use the passkey connector.");let r=t.chains.find(i=>i.id===e);if(!r)throw new Error(`Could not find configured chain for chain ID ${e}.`);let o=t.transports[r.id];if(!o)throw new Error(`Could not find configured transport for chain ID ${e}.`);let n=$r(o),a=F(r),s=Q(r),d=Gr({...W,chain:r,transport:n}),l=f.getState().activeCredential!=null;return{id:"passkey",type:S.type,name:"Passkey",async createPasskey(){let{id:i}=await Le(),c=await H(d,i);this.onAccountsChanged([c.address]),this.onConnect?.({chainId:Ge(e)})},async reusePasskey(){let{id:i}=await se(),c=await H(d,i);this.onAccountsChanged([c.address]),this.onConnect?.({chainId:Ge(e)})},hasPasskey(){return Object.keys(f.getState().publicKeys).length>0},async connect(i){if(console.log("connect"),i?.chainId!=null&&i.chainId!==e)throw new Error(`Can't connect to chain ${i.chainId}. Passkey connector is bound to chain ${e}.`);!f.getState().activeCredential&&!i?.isReconnecting&&await se();let c=await this.getAccounts();return l=c.length>0,{accounts:c,chainId:e}},async disconnect(){console.log("disconnect"),l=!1,f.setState({activeCredential:null})},async getAccounts(){console.log("getAccounts");let i=f.getState().activeCredential;if(!i)return[];try{console.log("getting account for credential",i);let c=await H(d,i);return console.log("got account",c),[c.address]}catch{console.log("could not get address for credential ID",i)}return[]},async getChainId(){return e},async isAuthorized(){return console.log("isAuthorized"),l?(await this.getAccounts()).length>0:!1},async switchChain(i){if(i.chainId!==e)throw new Error(`Can't connect to chain ${i.chainId}. Passkey connector is bound to chain ${e}.`);let c=t.chains.find(m=>m.id===i.chainId);if(!c)throw new Vr(new _r);return c},onAccountsChanged(i){console.log("onAccountsChanged"),i.length>0?t.emitter.emit("change",{accounts:i.map(c=>Ur(c))}):this.onDisconnect()},onChainChanged(i){console.log("onChainChanged"),t.emitter.emit("change",{chainId:Number(i)})},async onConnect(i){console.log("onConnect");let c=await this.getAccounts();t.emitter.emit("connect",{accounts:c,chainId:e})},async onDisconnect(i){console.log("onDisconnect"),t.emitter.emit("disconnect"),l=!1},async getClient(i){console.log("passkeyConnector.getClient",i);let c=f.getState().activeCredential;if(!c)throw new Error("Not connected.");let m=await H(d,c);return G({paymasterAddress:a,transport:s,client:d,account:m}).extend(jr()).extend(Xr())},async getProvider(i){return Qr({request:d.transport.request})({retryCount:0})}}})}function Qe(){let t=Jr().find(r=>r.type===S.type);if(!t)throw new Error("Could not find passkey connector. Did you configure Wagmi with the EntryKit passkey connector or passkey wallet?");return t}import{twMerge as Zr}from"tailwind-merge";import{jsx as ce,jsxs as eo}from"react/jsx-runtime";function C({className:e,...t}){return eo("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 8 8",fill:"currentColor",shapeRendering:"crispEdges",className:Zr("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...t,children:[ce("path",{d:"M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z"}),ce("path",{d:"M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z",opacity:".5"}),ce("path",{d:"M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z"})]})}function Ue(){let{appInfo:e}=p(),t=e?.name??document.title,r=location.host,o=e?.icon??document.querySelector("link[rel~='icon']")?.getAttribute("href")??"/favico.ico",n=e?.image;return{appName:t,appOrigin:r,appIcon:o,appImage:n}}import{useQuery as to}from"@tanstack/react-query";function U(e){return to({enabled:!!e,retry:!1,retryOnMount:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,queryKey:["preloadImage",e],queryFn:()=>new Promise((t,r)=>{if(!e)throw new Error("usePreloadImage: Must provide `url` to preload image.");let o=new Image;o.onload=()=>t(o),o.onerror=()=>r(new Error(`usePreloadImage: Could not load image.
1440
1440
 
1441
- URL: ${e}`)),n.src=e})})}import{jsx as re,jsxs as Bn}from"react/jsx-runtime";function pt(){let{appName:e,appIcon:t}=dt(),{data:r,isLoading:n}=te(t);return Bn("div",{className:"flex-grow flex flex-col items-center justify-center gap-2",children:[re("div",{className:"w-16 h-16 m-2",children:n?null:r?re("img",{src:t,className:"w-full h-full object-cover"}):re(k,{className:"w-full h-full text-orange-500 dark:bg-neutral-800"})}),re("div",{className:"text-2xl text-white text-center",children:e})]})}import{twMerge as Wn}from"tailwind-merge";import{jsx as K,jsxs as ut}from"react/jsx-runtime";function mt(){let e=Fn(),{accountModalOpen:t}=w(),{openConnectModal:r,connectModalOpen:n}=Gn(),o=ct(),a=lt({onError:i=>console.error(i),mutationKey:["createPasskey",o.id,t,n,e.status],mutationFn:()=>o.createPasskey()}),s=lt({onError:i=>console.error(i),mutationKey:["reusePasskey",o.id,t,n,e.status],mutationFn:()=>o.reusePasskey()}),c=o.hasPasskey(),l=[K(b,{variant:c?"tertiary":"secondary",className:"self-auto flex justify-center",pending:a.status==="pending"||a.status==="success",onClick:()=>a.mutate(),autoFocus:!c,children:"Create account"},"create"),K(b,{variant:c?"secondary":"tertiary",className:"self-auto flex justify-center",pending:s.status==="pending"||s.status==="success",onClick:()=>s.mutate(),autoFocus:c,children:"Sign in"},"signin")];return c&&l.reverse(),ut("div",{className:Wn("flex flex-col gap-6 p-6","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:[K("div",{className:"p-4",children:K(pt,{})}),ut("div",{className:"self-center flex flex-col gap-2 w-60",children:[l,K("button",{className:"text-sm self-center transition text-neutral-500 hover:text-white p-2",disabled:e.status==="connecting",onClick:r,children:"Already have a wallet?"})]})]})}import{useEffect as na,useMemo as oa,useRef as aa,useState as ia}from"react";import{twMerge as Ie}from"tailwind-merge";import{parseEther as _n}from"viem";var ne=_n("0.01");import{useClient as ro}from"wagmi";import{queryOptions as no,useQuery as oo}from"@tanstack/react-query";import{defineStore as Vn}from"@latticexyz/store";import{parseAbi as Qn}from"viem";var xe=Qn(["error SpenderSystem_AlreadyRegistered(address spender, address user)","error SpenderSystem_HasOwnBalance(address spender)","function registerSpender(address spender)"]),Yn=Vn({namespaces:{root:{namespace:"",tables:{Allowance:{schema:{user:"address",allowance:"uint256"},key:["user"]},Grantor:{schema:{grantor:"address",allowance:"uint256"},key:["grantor"]},PassHolder:{schema:{user:"address",passId:"bytes32",lastRenewed:"uint256",lastClaimed:"uint256"},key:["user","passId"]},PassConfig:{schema:{passId:"bytes32",claimAmount:"uint256",claimInterval:"uint256",validityPeriod:"uint256",grantor:"address"},key:["passId"]},Spender:{schema:{spender:"address",user:"address"},key:["spender"]},SystemConfig:{schema:{entryPoint:"address"},key:[]}}}}}),oe=Yn.namespaces.root.tables;import{decodeValueArgs as $n,getKeyTuple as jn,getSchemaTypes as Xn,getValueSchema as Jn}from"@latticexyz/protocol-parser/internal";import{readContract as Zn}from"viem/actions";import{getAction as eo}from"viem/utils";async function S(e,{address:t,table:r,key:n,blockTag:o}){let[a,s,c]=await eo(e,Zn,"readContract")({address:t,abi:to,functionName:"getRecord",args:[r.tableId,jn(r,n)],blockTag:o});return{...n,...$n(Xn(Jn(r)),{staticData:a,encodedLengths:s,dynamicData:c})}}var to=[{type:"function",name:"getRecord",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"staticData",type:"bytes",internalType:"bytes"},{name:"encodedLengths",type:"bytes32",internalType:"EncodedLengths"},{name:"dynamicData",type:"bytes",internalType:"bytes"}],stateMutability:"view"}];async function ft({client:e,paymasterAddress:t,userAddress:r}){return(await S(e,{address:t,table:oe.Allowance,key:{user:r},blockTag:"pending"})).allowance}function ve({client:e,paymasterAddress:t,userAddress:r}){let n=["getAllowance",e?.chain.id,t,r];return no(e&&r?{queryKey:n,queryFn:()=>ft({client:e,paymasterAddress:t,userAddress:r})}:{queryKey:n,enabled:!1})}function yt(e){let{chainId:t,paymasterAddress:r}=f(),n=ro({chainId:t});return oo(ve({client:n,paymasterAddress:r,userAddress:e}))}import{useClient as Qd}from"wagmi";import{queryOptions as ao,useQuery as $d}from"@tanstack/react-query";async function gt({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n}){return(await S(e,{address:t,table:oe.Spender,key:{spender:n},blockTag:"pending"})).user.toLowerCase()===r.toLowerCase()}function ht({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n}){let o=["getSpender",e?.chain.id,t,r,n];return ao(e&&r&&n?{queryKey:o,queryFn:()=>gt({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n})}:{queryKey:o,enabled:!1})}import{useClient as np}from"wagmi";import{queryOptions as io,useQuery as ap}from"@tanstack/react-query";async function wt({client:e,worldAddress:t,userAddress:r,sessionAddress:n}){return(await S(e,{address:t,table:Ze.UserDelegationControl,key:{delegator:r,delegatee:n},blockTag:"pending"})).delegationControlId===U}function bt({client:e,worldAddress:t,userAddress:r,sessionAddress:n}){let o=["getDelegation",e?.chain.id,t,r,n];return io(e&&r&&n?{queryKey:o,queryFn:()=>wt({client:e,worldAddress:t,userAddress:r,sessionAddress:n})}:{queryKey:o,enabled:!1})}import{queryOptions as go,useQuery as ho,useQueryClient as wo}from"@tanstack/react-query";import{useClient as bo}from"wagmi";import{useClient as mo}from"wagmi";import{queryOptions as fo,useQuery as yo}from"@tanstack/react-query";import{createStore as so}from"zustand/vanilla";import{persist as co}from"zustand/middleware";var B=so(co(()=>({signers:{}}),{name:"mud:entrykit",partialize:({signers:e})=>({signers:e})}));function po(e){e.key===B.persist.getOptions().name&&B.persist.rehydrate()}window.addEventListener("storage",po);import{generatePrivateKey as lo,privateKeyToAccount as uo}from"viem/accounts";function xt(e){let t=B.getState().signers[e]??(()=>{let r=lo();return B.setState(n=>({signers:{...n.signers,[e]:r}})),r})();return uo(t)}async function vt({client:e,userAddress:t}){let r=xt(t);return await $({client:e,owners:[r]})}function Ce({client:e,userAddress:t}){let r=["getSessionAccount",e?.chain.id,t];return fo(e&&t?{queryKey:r,queryFn:()=>vt({client:e,userAddress:t}),staleTime:1/0}:{queryKey:r,enabled:!1})}function Ct(e){let{chainId:t}=f(),r=mo({chainId:t});return yo(Ce({userAddress:e,client:r}))}function xo({queryClient:e,client:t,userAddress:r,paymasterAddress:n,worldAddress:o}){let a=["getPrerequisites",t?.chain.id,r];return go(t&&r?{queryKey:a,queryFn:async()=>{let{address:s}=await e.fetchQuery(Ce({client:t,userAddress:r})),[c,l,i]=await Promise.all([e.fetchQuery(ve({client:t,paymasterAddress:n,userAddress:r})),e.fetchQuery(ht({client:t,paymasterAddress:n,userAddress:r,sessionAddress:s})),e.fetchQuery(bt({client:t,worldAddress:o,userAddress:r,sessionAddress:s}))]),d=c>=ne;return{hasAllowance:d,isSpender:l,hasDelegation:i,complete:d&&l&&i}}}:{queryKey:a,enabled:!1})}function M(e){let t=wo(),{chainId:r,paymasterAddress:n,worldAddress:o}=f(),a=bo({chainId:r});return ho(xo({queryClient:t,client:a,userAddress:e,paymasterAddress:n,worldAddress:o}),t)}import{useDisconnect as Ao}from"wagmi";import{useQuery as vo}from"@tanstack/react-query";function ae(e){let t=e?.toLowerCase();return vo({enabled:!!t,queryKey:["ens",t],queryFn:async()=>{let r=await fetch(`https://api.ensideas.com/ens/resolve/${t}`).then(n=>n.json());return{address:r.address??void 0,name:r.name??void 0,displayName:r.displayName??void 0,avatar:r.avatar??void 0}}})}import{jsx as Ae,jsxs as Co}from"react/jsx-runtime";function ie({hex:e}){return e.length<=10?Ae("span",{title:e,children:e}):Co("span",{title:e,children:[Ae("span",{className:"after:select-none after:content-['\u2026']",children:e.slice(0,6)}),Ae("span",{className:"tracking-[-1ch] text-transparent",children:e.slice(6,-4)}),e.slice(-4)]})}import{jsx as F,jsxs as ke}from"react/jsx-runtime";function At({isActive:e,isExpanded:t,userAddress:r}){let{data:n}=ae(r),{disconnect:o,isPending:a}=Ao(),{closeAccountModal:s}=w();return ke("div",{className:"flex flex-col gap-4",children:[ke("div",{className:"flex justify-between gap-4",children:[ke("div",{children:[F("div",{children:"Account"}),F("div",{className:"font-mono text-white",children:n?.name??F(ie,{hex:r})})]}),F(b,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:a,onClick:()=>{s(),o()},children:"Sign out"})]}),t?F("p",{className:"text-sm",children:"Each of your onchain actions in this app is associated with your account."}):null]})}import{useMutation as So,useQueryClient as Po}from"@tanstack/react-query";import{http as ko}from"viem";function kt(){return({chain:e})=>{if(!e)throw new Error("No chain provided to issuer transport.");let t="quarryPassIssuer"in e.rpcUrls?e.rpcUrls.quarryPassIssuer.http[0]:void 0;if(!t)throw new Error(`No \`quarryPassIssuer\` RPC URL found for chain ${e.id}.`);return ko(t)({chain:e,retryCount:0})}}function St(){let e=Po(),{chain:t}=f(),r=["claimGasPass",t.id];return So({mutationKey:r,onError:n=>console.error(n),mutationFn:async n=>{let o=kt()({chain:t});await o.request({method:"quarry_issuePass",params:["0x01",n]}),await o.request({method:"quarry_claimAllowance",params:["0x01",n]}),await Promise.all([e.invalidateQueries({queryKey:["getAllowance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{twMerge as Ro}from"tailwind-merge";import{jsx as se,jsxs as Oo}from"react/jsx-runtime";function Pt({className:e,...t}){return Oo("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 263 428",fill:"currentColor",className:Ro("w-[0.6em] h-[1em]",e),...t,children:[se("path",{d:"M132 321V428L263 243L132 321Z"}),se("path",{d:"M0 243L132 321V428",fillOpacity:"0.5"}),se("path",{d:"M132 0V296L263 218"}),se("path",{d:"M0 218L132 296V0L0 218Z",fillOpacity:"0.5"})]})}import{formatEther as Io}from"viem";function Rt(e){let t=Io(e),r=Math.floor(parseFloat(t)).toString().length;return parseFloat(t).toLocaleString("en-US",{maximumFractionDigits:Math.max(0,6-r)})}import{jsx as Mo,jsxs as To}from"react/jsx-runtime";function Ot({wei:e}){return To("span",{className:"inline-flex items-center gap-1",children:[Rt(e)," ",Mo(Pt,{})]})}import{useEffect as No}from"react";import{jsx as T,jsxs as Se}from"react/jsx-runtime";function It({isActive:e,isExpanded:t,userAddress:r}){let n=yt(r),o=St();return No(()=>{let a=setTimeout(()=>{e&&o.status==="idle"&&n.isSuccess&&n.data<ne&&o.mutate(r)});return()=>clearTimeout(a)},[n.data,n.isSuccess,o,e,r]),Se("div",{className:"flex flex-col gap-4",children:[Se("div",{className:"flex justify-between gap-4",children:[Se("div",{children:[T("div",{children:"Allowance"}),T("div",{className:"font-mono text-white",children:n.data!=null?T(Ot,{wei:n.data}):T(A,{className:"text-sm"})})]}),T(b,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:n.status==="pending"||o.status==="pending",onClick:()=>o.mutate(r),children:"Top up"})]}),t?T("p",{className:"text-sm",children:"Your allowance is used to pay for onchain computation."}):null]})}import{encodeFunctionData as Tt}from"viem";import{useMutation as Fo,useQueryClient as Go}from"@tanstack/react-query";import{getAction as Re}from"viem/utils";import{sendUserOperation as Wo,waitForUserOperationReceipt as _o}from"viem/account-abstraction";import{waitForTransactionReceipt as Vo}from"viem/actions";import{useClient as Qo}from"wagmi";import{resourceToHex as Nt}from"@latticexyz/common";import Yo from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";import{writeContract as Uo}from"viem/actions";import{getAction as Ko}from"viem/utils";import{toHex as Eo}from"viem";import{signTypedData as Ho}from"viem/actions";import{callWithSignatureTypes as Do}from"@latticexyz/world/internal";import zo from"@latticexyz/world-modules/internal/mud.config";import{hexToResource as qo}from"@latticexyz/common";import{getAction as Lo}from"viem/utils";async function Mt({userClient:e,worldAddress:t,systemId:r,callData:n,nonce:o,client:a}){let s=o??(a?(await S(a,{address:t,table:zo.tables.CallWithSignatureNonces,key:{signer:e.account.address},blockTag:"pending"})).nonce:0n),{namespace:c,name:l}=qo(r);return await Lo(e,Ho,"signTypedData")({account:e.account,domain:{verifyingContract:t,salt:Eo(e.chain.id,{size:32})},types:Do,primaryType:"Call",message:{signer:e.account.address,systemNamespace:c,systemName:l,callData:n,nonce:s}})}import Bo from"@latticexyz/world-modules/out/Unstable_CallWithSignatureSystem.sol/Unstable_CallWithSignatureSystem.abi.json";async function Pe({sessionClient:e,...t}){let r=await Mt(t);return Ko(e,Uo,"writeContract")({address:t.worldAddress,abi:Bo,functionName:"callWithSignature",args:[t.userClient.account.address,t.systemId,t.callData,r]})}function Et({userClient:e}){let t=Go(),{chainId:r,worldAddress:n,paymasterAddress:o}=f(),a=Qo({chainId:r}),s=["setupSession",a?.chain.id,e.account.address];return Fo({mutationKey:s,onError:c=>console.error(c),mutationFn:async({sessionClient:c,registerSpender:l,registerDelegation:i})=>{if(!a)throw new Error("Client not ready.");let d=c.account.address;if(console.log("setting up session"),e.account.type!=="smart"){let p=[];if(l){console.log("registering spender");let u=await Pe({client:a,userClient:e,sessionClient:c,worldAddress:o,systemId:Nt({type:"system",namespace:"",name:"SpenderSystem"}),callData:Tt({abi:xe,functionName:"registerSpender",args:[d]})});console.log("got spender tx",u),p.push(u)}if(i){console.log("registering delegation");let u=await Pe({client:a,userClient:e,sessionClient:c,worldAddress:n,systemId:Nt({type:"system",namespace:"",name:"Registration"}),callData:Tt({abi:Yo,functionName:"registerDelegation",args:[d,U,"0x"]})});console.log("got delegation tx",u),p.push(u)}if(!p.length)return;console.log("waiting for",p.length,"receipts");for(let u of p){let m=await Re(a,Vo,"waitForTransactionReceipt")({hash:u});console.log("got tx receipt",m),m.status==="reverted"&&console.error("tx reverted?",m)}}else{let p=[];if(l&&(console.log("registering spender"),p.push({to:o,abi:xe,functionName:"registerSpender",args:[d]})),i&&(console.log("registering delegation"),p.push({to:n,abi:et,functionName:"registerDelegation",args:[d,U,"0x"]})),!p.length)return;console.log("setting up account with",p,e);let u=await Re(e,Wo,"sendUserOperation")({calls:p});console.log("got user op hash",u);let m=await Re(e,_o,"waitForUserOperationReceipt")({hash:u});console.log("got user op receipt",m),m.success||console.error("not successful?",m)}await Promise.all([t.invalidateQueries({queryKey:["getSpender"]}),t.invalidateQueries({queryKey:["getDelegation"]}),t.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{useEffect as ra}from"react";import{useClient as Jo}from"wagmi";import{queryOptions as Zo,useQuery as ea}from"@tanstack/react-query";import{smartAccountActions as $o}from"permissionless";import{callFrom as jo}from"@latticexyz/world/internal";import{observer as Xo}from"@latticexyz/explorer/observer";async function Ht({client:e,userAddress:t,sessionAccount:r,worldAddress:n,paymasterAddress:o}){let a=ee(e.chain);return J({paymasterAddress:o,transport:a,client:e,account:r}).extend($o()).extend(jo({worldAddress:n,delegatorAddress:t,publicClient:e})).extend(Xo()).extend(()=>({userAddress:t}))}function ta({sessionAccount:e,client:t,userAddress:r,worldAddress:n,paymasterAddress:o}){let a=["getSessionClient",t?.uid,r,e?.address,n];return Zo(t&&r&&e?{queryKey:a,queryFn:()=>Ht({sessionAccount:e,client:t,userAddress:r,worldAddress:n,paymasterAddress:o}),staleTime:1/0}:{queryKey:a,enabled:!1})}function ce(e){let{chainId:t,worldAddress:r,paymasterAddress:n}=f(),o=Jo({chainId:t}),{data:a}=Ct(e);return ea(ta({sessionAccount:a,userAddress:e,client:o,worldAddress:r,paymasterAddress:n}))}import{jsx as G,jsxs as Oe}from"react/jsx-runtime";function Dt({isActive:e,isExpanded:t,userClient:r,registerSpender:n,registerDelegation:o}){let{data:a}=ce(r.account.address),s=Et({userClient:r}),c=!o&&!o;return ra(()=>{let l=setTimeout(()=>{e&&s.status==="idle"&&a&&!c&&s.mutate({sessionClient:a,registerSpender:n,registerDelegation:o})});return()=>clearTimeout(l)},[c,e,o,n,a,s]),Oe("div",{className:"flex flex-col gap-4",children:[Oe("div",{className:"flex justify-between gap-4",children:[Oe("div",{children:[G("div",{children:"Session"}),G("div",{className:"font-mono text-white",children:c?"Enabled":"Set up"})]}),c?G(b,{variant:"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,disabled:!0,children:"Enabled"}):G(b,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:!a||s.status==="pending",onClick:a?()=>s.mutate({sessionClient:a,registerSpender:n,registerDelegation:o}):void 0,children:"Enable"})]}),t?G("p",{className:"text-sm",children:"You can perform actions in this app without interruptions for approvals."}):null]})}import{jsx as N}from"react/jsx-runtime";function zt({userClient:e,initialUserAddress:t}){let r=e.account.address,{data:n}=M(r),{closeAccountModal:o}=w(),a=r!==t,s=aa(n);na(()=>{n!=null&&(s.current==null&&(s.current=n),n.complete&&(a||!s.current.complete)&&o())},[o,a,n]);let{hasAllowance:c,isSpender:l,hasDelegation:i}=n??{},d=oa(()=>r?[{id:"wallet",isComplete:!0,content:y=>N(At,{...y,userAddress:r})},{id:"allowance",isComplete:!!c,content:y=>N(It,{...y,userAddress:r})},{id:"session",isComplete:!!l&&!!i,content:y=>N(Dt,{...y,userClient:e,registerSpender:!l,registerDelegation:!i})}]:[{id:"wallet",isComplete:!1,content:()=>null}],[c,i,l,r,e]),[p]=ia(null),u=d.find(y=>y.content!=null&&!y.isComplete),m=d.filter(y=>y.isComplete),h=(p!=null?d.find(y=>y.id===p):null)??u??(m.length<d.length?m.at(-1):null),C=h?d.indexOf(h):-1;return N("div",{className:Ie("min-h-[26rem] px-8 flex flex-col divide-y divide-neutral-800","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:d.map((y,ue)=>{let E=y===h,er=E||m.length===d.length,tr=!y.isComplete&&C!==-1&&ue>C;return N("div",{className:Ie("py-8 flex flex-col justify-center",E?"flex-grow":null),children:N("div",{className:Ie("flex flex-col",tr?"opacity-30 pointer-events-none":null),children:y.content({isActive:E,isExpanded:er})})},y.id)})})}import{useRef as da}from"react";import{jsx as qt}from"react/jsx-runtime";function Lt(){let{chainId:e}=f(),t=ca({chainId:e}),{address:r}=sa(),n=da(r);return t.status!=="success"?qt(mt,{}):qt(zt,{userClient:t.data,initialUserAddress:n.current})}import{useState as fa}from"react";import{ErrorBoundary as ya}from"react-error-boundary";import{twMerge as pa}from"tailwind-merge";import{BaseError as la,UserRejectedRequestError as ua}from"viem";import{jsx as Ut,jsxs as ma}from"react/jsx-runtime";function Kt({title:e,error:t}){if(!t||t instanceof la&&t.walk(o=>o instanceof ua)!=null)return null;let r=e??"Error",n=typeof t=="string"?t:t instanceof Error?String(t):"Something unexpected happened.";return ma("div",{className:pa("text-sm border-l-4 border-red-500","bg-red-100 text-red-900","dark:bg-red-900 dark:text-red-50"),children:[Ut("div",{className:"p-3 font-semibold",children:r}),Ut("div",{className:"px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll",children:n})]})}import{wait as ga}from"@latticexyz/common/utils";import{twMerge as ha}from"tailwind-merge";import{useIsMounted as wa}from"usehooks-ts";import{jsx as de,jsxs as Bt}from"react/jsx-runtime";function Ft({children:e}){let t=wa(),[r,n]=fa(1);return de(ya,{fallbackRender:({error:o,resetErrorBoundary:a})=>Bt("div",{className:ha("flex-grow flex flex-col justify-center p-5 gap-2"),children:[de(Kt,{error:o instanceof Error?o.stack??o.message:o}),r>0?Bt("button",{type:"button",onClick:async s=>{s.currentTarget.ariaBusy="true",await ga(1e3),a(),t()&&(n(c=>c-1),s.currentTarget.ariaBusy=null)},className:"group aria-busy:pointer-events-none self-end flex items-center gap-1",children:[de(A,{className:"transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400"}),de("span",{className:"text-sm text-neutral-500 dark:text-neutral-400 group-hover:text-black dark:group-hover:text-white",children:"Retry?"})]}):null]}),children:e})}import{DialogClose as va,DialogTitle as Ca}from"@radix-ui/react-dialog";import{twMerge as ba}from"tailwind-merge";import{jsx as xa}from"react/jsx-runtime";function Gt({className:e,children:t,...r}){return xa("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:ba("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...r,children:t})}import{jsx as Wt}from"react/jsx-runtime";function _t(e){return Wt(Gt,{strokeWidth:"2",stroke:"currentColor",...e,children:Wt("path",{d:"M6 18L18 6M6 6L18 18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as x,jsxs as Me}from"react/jsx-runtime";function Qt(){let{accountModalOpen:e,toggleAccountModal:t}=w();return Me(Ge,{open:e,onOpenChange:t,children:[x(Ca,{className:"sr-only",children:"Connect with EntryKit"}),e?Me("div",{className:Vt("relative py-2 ring-1","bg-neutral-900 text-neutral-400 ring-neutral-700/50 divide-neutral-700","links:font-medium links:underline links:underline-offset-4","links:text-white","links:decoration-neutral-500 hover:links:decoration-orange-500"),children:[x(Ft,{children:x(Lt,{})}),Me("a",{href:"https://mud.dev",target:"_blank",rel:"noreferrer noopener",className:"group self-center p-3 flex items-center justify-center gap-2 links-unset text-sm font-mono transition text-neutral-400 hover:text-white",children:[x("span",{className:"block w-4 h-4",children:x(k,{className:"w-full h-full text-orange-500 group-hover:rotate-90 transition duration-300"})}),x("span",{children:"Powered by MUD"})]}),x("div",{className:"absolute top-0 right-0",children:x(va,{className:Vt("pointer-events-auto leading-none p-2 transition","text-neutral-700 hover:text-neutral-500"),title:"Close",children:x(_t,{className:"m-0"})})})]}):null]})}import{jsx as ka,jsxs as Sa}from"react/jsx-runtime";function Aa({config:e,children:t}){return Sa(Le,{config:e,children:[t,ka(Qt,{})]})}import{useAccount as Ra}from"wagmi";import{twMerge as P}from"tailwind-merge";import{twMerge as Yt}from"tailwind-merge";import{Fragment as Pa,jsx as pe,jsxs as $t}from"react/jsx-runtime";function jt({address:e}){let{data:t}=ae(e),r=te(t?.avatar);return $t(Pa,{children:[$t("span",{className:"flex-shrink-0 w-6 h-6 -my-1 -mx-0.5 grid place-items-center",children:[pe("img",{src:t?.avatar&&r.isSuccess?t.avatar:void 0,className:Yt("col-start-1 row-start-1","inline-flex w-full h-full rounded-full bg-black/10 dark:bg-white/10 bg-cover bg-no-repeat bg-center","transtion duration-300",r.isSuccess?"opacity-100":"opacity-0")}),pe(k,{className:Yt("col-start-1 row-start-1 text-orange-500","transition duration-300",t&&(!t.avatar||r.isError)?"opacity-100":"opacity-0")})]}),pe("span",{className:"flex-grow",children:t?.name??pe(ie,{hex:e})})]})}import{useRef as Oa}from"react";import{jsx as v,jsxs as Jt}from"react/jsx-runtime";var Xt=P("w-48 p-3 inline-flex outline-none transition","border border-transparent","text-base leading-none"),Ia=P("bg-neutral-100 border-neutral-300 text-black","dark:bg-neutral-800 dark:border-neutral-700 dark:text-white"),Ma=P("cursor-pointer outline-none hover:bg-neutral-200 data-[highlighted]:bg-neutral-200 dark:hover:bg-neutral-700");function Ta(){let{openAccountModal:e,accountModalOpen:t}=w(),{status:r,address:n}=Ra(),o=Oa(n),a=M(n),s=r==="connected"||r==="reconnecting"&&n,c=n!==o.current,l=a.isSuccess?a.data.complete:c?!1:s,i=(()=>{if(a.isSuccess){if(!a.data.hasAllowance)return"Top up";if(!a.data.hasDelegation||!a.data.isSpender)return"Set up"}return"Sign in"})();return v(_,{mode:"child",children:l?v("button",{type:"button",className:P(Xt,Ia,Ma),onClick:e,children:v("span",{className:"flex-grow inline-flex gap-2.5 items-center text-left font-medium",children:n?v(jt,{address:n}):null})},"connected"):Jt("button",{type:"button",className:P(Xt,"group","items-center justify-center gap-2.5","bg-orange-500 text-white font-medium","hover:bg-orange-400","active:bg-orange-600"),"aria-busy":t,onClick:e,children:[Jt("span",{className:"pointer-events-none inline-grid place-items-center -ml-3",children:[v("span",{className:P("col-start-1 row-start-1 leading-none","scale-100 opacity-100 transition duration-300","group-aria-busy:scale-125 group-aria-busy:opacity-0"),children:v(k,{})}),v("span",{"aria-hidden":!0,className:P("col-start-1 row-start-1","scale-50 opacity-0 transition duration-300 delay-50","group-aria-busy:scale-100 group-aria-busy:opacity-100"),children:v(A,{})})]}),v("span",{className:"font-medium",children:i})]},"sign in")})}import{useConnectorClient as Na}from"wagmi";function Ea(){let{chainId:e}=f(),t=Na({chainId:e});t.error&&console.error("Error retrieving user client",t.error);let r=t.data?.account.address,n=M(r),o=ce(r);return t.isSuccess?!n.isSuccess||!n.data.complete?{...n,data:void 0}:o:{...t,data:void 0}}import{connectorsForWallets as Da,getDefaultWallets as za}from"@rainbow-me/rainbowkit";import{createConfig as qa}from"wagmi";var Ha=`data:image/svg+xml;base64,${btoa('<svg xmlns="http://www.w3.org/2000/svg" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd" width="512" height="512" viewBox="-64 -32 608 512"><path d="M6.206 425.469A6.202 6.202 0 010 419.263c0-1.771.235-3.517.663-5.245 9.95-78.847 57.22-96.006 100.964-107.256 21.008-5.412 62.901-26.489 57.822-53.668-10.596-9.819-21.113-23.39-22.946-43.63l-1.274.026c-2.932-.044-5.778-.716-8.422-2.217-5.848-3.325-9.051-9.697-10.596-16.958-3.238-22.186-4.058-33.515 7.768-38.464l.096-.035c-1.467-27.37 3.159-67.64-24.944-76.141C154.622 7.1 218.597-30.203 266.627 30.805c53.519 2.801 77.389 78.611 44.154 121.046h-1.405c11.826 4.949 10.045 17.674 7.767 38.464-1.544 7.261-4.747 13.633-10.595 16.958-2.645 1.501-5.481 2.173-8.422 2.217l-1.275-.026c-1.833 20.24-12.376 33.811-22.972 43.63-4.459 23.871 27.275 43.011 49.33 50.997a139.442 139.442 0 004.268 5.525c-7.2 9.941-8.771 22.797-4.564 34.038-17.002 8.763-24.255 29.334-16.479 46.86-11.966 7.55-18.258 21.305-16.609 34.955H6.206zm419.058-105.362a86.778 86.778 0 0019.446-1.641c29.36-5.822 53.152-27.467 62.657-55.823 3.596-10.544 5.071-21.663 4.521-33.341-1.179-23.46-12.193-46.633-29.631-62.369-17.107-15.361-38.342-23.574-61.383-23.042-22.841.507-45.359 11.216-60.187 28.593-14.977 17.551-22.003 39.144-20.921 62.133.585 11.661 3.482 23.016 8.737 34.074 7.741 16.303 19.934 29.735 35.391 39.048l-22.457 20.711 13.232 27.86-29.413 13.973 13.991 29.456-26.769 12.717 16.81 35.374 35.601-16.915 40.375-110.808zm15.239-129.364c13.685 4.869 20.824 19.908 15.954 33.593-4.87 13.685-19.908 20.833-33.593 15.963-13.685-4.87-20.834-19.917-15.963-33.602 4.87-13.685 19.917-20.825 33.602-15.954z"/></svg>')}`,le=e=>()=>({id:"passkey",name:"Passkey",iconUrl:Ha,iconBackground:"#fec",createConnector:t=>r=>({...I(e)(r),...t})});import{mapObject as La}from"@latticexyz/common/utils";function Ua(e){let{wallets:t}=za(),r=[{groupName:"Recommended",wallets:[le({chainId:e.chainId})]},...t],n=Da(r,{appName:e.appName,projectId:e.walletConnectProjectId});return qa({connectors:n,chains:e.chains,transports:La(e.transports,o=>O(o)),pollingInterval:e.pollingInterval})}function Zm(e){return e!=null&&"__isCoinbaseSmartAccount"in e&&e.__isCoinbaseSmartAccount===!0}import{connectorsForWallets as Ba}from"@rainbow-me/rainbowkit";import{getDefaultWallets as Ka}from"@rainbow-me/rainbowkit";function Zt(e){let{wallets:t}=Ka();return[{groupName:"Recommended",wallets:[le({chainId:e.chainId})]},...t]}function c0({wallets:e,...t}){return Ba(e??Zt(t),{appName:t.appName,projectId:t.walletConnectProjectId})}export{Ta as AccountButton,Aa as EntryKitProvider,Y as abi,Ua as createWagmiConfig,rr as defineConfig,c0 as getConnectors,Zt as getWallets,Zm as isCoinbaseSmartAccount,I as passkeyConnector,le as passkeyWallet,Q as sign,$ as toCoinbaseSmartAccount,ge as toReplaySafeHash,Wr as toWebAuthnSignature,w as useAccountModal,f as useEntryKitConfig,Ea as useSessionClient,O as wiresaw,q as wrapSignature};
1441
+ URL: ${e}`)),o.src=e})})}import{jsx as V,jsxs as ro}from"react/jsx-runtime";function Ve(){let{appName:e,appIcon:t}=Ue(),{data:r,isLoading:o}=U(t);return ro("div",{className:"flex-grow flex flex-col items-center justify-center gap-2",children:[V("div",{className:"w-16 h-16 m-2",children:o?null:r?V("img",{src:t,className:"w-full h-full object-cover"}):V(C,{className:"w-full h-full text-orange-500 dark:bg-neutral-800"})}),V("div",{className:"text-2xl text-white text-center",children:e})]})}import{twMerge as ao}from"tailwind-merge";import{jsx as R,jsxs as Ye}from"react/jsx-runtime";function je(){let e=oo(),{accountModalOpen:t}=w(),{openConnectModal:r,connectModalOpen:o}=no(),n=Qe(),a=_e({onError:i=>console.error(i),mutationKey:["createPasskey",n.id,t,o,e.status],mutationFn:()=>n.createPasskey()}),s=_e({onError:i=>console.error(i),mutationKey:["reusePasskey",n.id,t,o,e.status],mutationFn:()=>n.reusePasskey()}),d=n.hasPasskey(),l=[R(y,{variant:d?"tertiary":"secondary",className:"self-auto flex justify-center",pending:a.status==="pending"||a.status==="success",onClick:()=>a.mutate(),autoFocus:!d,children:"Create account"},"create"),R(y,{variant:d?"secondary":"tertiary",className:"self-auto flex justify-center",pending:s.status==="pending"||s.status==="success",onClick:()=>s.mutate(),autoFocus:d,children:"Sign in"},"signin")];return d&&l.reverse(),Ye("div",{className:ao("flex flex-col gap-6 p-6","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:[R("div",{className:"p-4",children:R(Ve,{})}),Ye("div",{className:"self-center flex flex-col gap-2 w-60",children:[l,R("button",{className:"text-sm self-center transition text-neutral-500 hover:text-white p-2",disabled:e.status==="connecting",onClick:r,children:"Already have a wallet?"})]})]})}import{useEffect as wn,useMemo as yn,useRef as bn,useState as xn}from"react";import{twMerge as ye}from"tailwind-merge";import{parseEther as io}from"viem";var _=io("0.01");import{useClient as mo}from"wagmi";import{queryOptions as uo,useQuery as fo}from"@tanstack/react-query";import{defineStore as so}from"@latticexyz/store";import{parseAbi as co}from"viem";var de=co(["error SpenderSystem_AlreadyRegistered(address spender, address user)","error SpenderSystem_HasOwnBalance(address spender)","function registerSpender(address spender)"]),lo=so({namespaces:{root:{namespace:"",tables:{Allowance:{schema:{user:"address",allowance:"uint256"},key:["user"]},Grantor:{schema:{grantor:"address",allowance:"uint256"},key:["grantor"]},PassHolder:{schema:{user:"address",passId:"bytes32",lastRenewed:"uint256",lastClaimed:"uint256"},key:["user","passId"]},PassConfig:{schema:{passId:"bytes32",claimAmount:"uint256",claimInterval:"uint256",validityPeriod:"uint256",grantor:"address"},key:["passId"]},Spender:{schema:{spender:"address",user:"address"},key:["spender"]},SystemConfig:{schema:{entryPoint:"address"},key:[]}}}}}),Y=lo.namespaces.root.tables;import{getRecord as po}from"@latticexyz/store/internal";async function Xe({client:e,paymasterAddress:t,userAddress:r}){return(await po(e,{address:t,table:Y.Allowance,key:{user:r},blockTag:"pending"})).allowance}function le({client:e,paymasterAddress:t,userAddress:r}){let o=["getAllowance",e?.chain.id,t,r];return uo(e&&r?{queryKey:o,queryFn:()=>Xe({client:e,paymasterAddress:t,userAddress:r})}:{queryKey:o,enabled:!1})}function $e(e){let{chainId:t,paymasterAddress:r}=p(),o=mo({chainId:t});return fo(le({client:o,paymasterAddress:r,userAddress:e}))}import{useClient as nc}from"wagmi";import{queryOptions as ho,useQuery as ic}from"@tanstack/react-query";import{getRecord as go}from"@latticexyz/store/internal";async function Je({client:e,paymasterAddress:t,userAddress:r,sessionAddress:o}){return(await go(e,{address:t,table:Y.Spender,key:{spender:o},blockTag:"pending"})).user.toLowerCase()===r.toLowerCase()}function Ze({client:e,paymasterAddress:t,userAddress:r,sessionAddress:o}){let n=["getSpender",e?.chain.id,t,r,o];return ho(e&&r&&o?{queryKey:n,queryFn:()=>Je({client:e,paymasterAddress:t,userAddress:r,sessionAddress:o})}:{queryKey:n,enabled:!1})}import{useClient as fc}from"wagmi";import{queryOptions as yo,useQuery as hc}from"@tanstack/react-query";import{getRecord as wo}from"@latticexyz/store/internal";async function et({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){return(await wo(e,{address:t,table:Be.UserDelegationControl,key:{delegator:r,delegatee:o},blockTag:"pending"})).delegationControlId===z}function tt({client:e,worldAddress:t,userAddress:r,sessionAddress:o}){let n=["getDelegation",e?.chain.id,t,r,o];return yo(e&&r&&o?{queryKey:n,queryFn:()=>et({client:e,worldAddress:t,userAddress:r,sessionAddress:o})}:{queryKey:n,enabled:!1})}import{queryOptions as Eo,useQuery as Io,useQueryClient as Mo}from"@tanstack/react-query";import{useClient as To}from"wagmi";import{useClient as So}from"wagmi";import{queryOptions as Po,useQuery as No}from"@tanstack/react-query";import{toCoinbaseSmartAccount as Ao}from"@latticexyz/common/accounts";import{createStore as bo}from"zustand/vanilla";import{persist as xo}from"zustand/middleware";var K=bo(xo(()=>({signers:{}}),{name:"mud:entrykit",partialize:({signers:e})=>({signers:e})}));function vo(e){e.key===K.persist.getOptions().name&&K.persist.rehydrate()}window.addEventListener("storage",vo);import{generatePrivateKey as Co,privateKeyToAccount as ko}from"viem/accounts";function rt(e){let t=K.getState().signers[e]??(()=>{let r=Co();return K.setState(o=>({signers:{...o.signers,[e]:r}})),r})();return ko(t)}async function ot({client:e,userAddress:t}){let r=rt(t);return await Ao({client:e,owners:[r]})}function pe({client:e,userAddress:t}){let r=["getSessionAccount",e?.chain.id,t];return Po(e&&t?{queryKey:r,queryFn:()=>ot({client:e,userAddress:t}),staleTime:1/0}:{queryKey:r,enabled:!1})}function nt(e){let{chainId:t}=p(),r=So({chainId:t});return No(pe({userAddress:e,client:r}))}function Ho({queryClient:e,client:t,userAddress:r,paymasterAddress:o,worldAddress:n}){let a=["getPrerequisites",t?.chain.id,r];return Eo(t&&r?{queryKey:a,queryFn:async()=>{let{address:s}=await e.fetchQuery(pe({client:t,userAddress:r})),[d,l,i]=await Promise.all([e.fetchQuery(le({client:t,paymasterAddress:o,userAddress:r})),e.fetchQuery(Ze({client:t,paymasterAddress:o,userAddress:r,sessionAddress:s})),e.fetchQuery(tt({client:t,worldAddress:n,userAddress:r,sessionAddress:s}))]),c=d>=_;return{hasAllowance:c,isSpender:l,hasDelegation:i,complete:c&&l&&i}}}:{queryKey:a,enabled:!1})}function P(e){let t=Mo(),{chainId:r,paymasterAddress:o,worldAddress:n}=p(),a=To({chainId:r});return Io(Ho({queryClient:t,client:a,userAddress:e,paymasterAddress:o,worldAddress:n}),t)}import{useDisconnect as Ko}from"wagmi";import{useQuery as zo}from"@tanstack/react-query";function j(e){let t=e?.toLowerCase();return zo({enabled:!!t,queryKey:["ens",t],queryFn:async()=>{let r=await fetch(`https://api.ensideas.com/ens/resolve/${t}`).then(o=>o.json());return{address:r.address??void 0,name:r.name??void 0,displayName:r.displayName??void 0,avatar:r.avatar??void 0}}})}import{jsx as me,jsxs as Ro}from"react/jsx-runtime";function X({hex:e}){return e.length<=10?me("span",{title:e,children:e}):Ro("span",{title:e,children:[me("span",{className:"after:select-none after:content-['\u2026']",children:e.slice(0,6)}),me("span",{className:"tracking-[-1ch] text-transparent",children:e.slice(6,-4)}),e.slice(-4)]})}import{jsx as O,jsxs as ue}from"react/jsx-runtime";function at({isActive:e,isExpanded:t,userAddress:r}){let{data:o}=j(r),{disconnect:n,isPending:a}=Ko(),{closeAccountModal:s}=w();return ue("div",{className:"flex flex-col gap-4",children:[ue("div",{className:"flex justify-between gap-4",children:[ue("div",{children:[O("div",{children:"Account"}),O("div",{className:"font-mono text-white",children:o?.name??O(X,{hex:r})})]}),O(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:a,onClick:()=>{s(),n()},children:"Sign out"})]}),t?O("p",{className:"text-sm",children:"Each of your onchain actions in this app is associated with your account."}):null]})}import{useMutation as Oo,useQueryClient as Do}from"@tanstack/react-query";import{claimGasPass as Fo}from"@latticexyz/paymaster/internal";function it(){let e=Do(),{chain:t}=p(),r=["claimGasPass",t.id];return Oo({mutationKey:r,onError:o=>console.error(o),mutationFn:async o=>{await Fo({chain:t,userAddress:o}),await Promise.all([e.invalidateQueries({queryKey:["getAllowance"]}),e.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{twMerge as Lo}from"tailwind-merge";import{jsx as $,jsxs as Bo}from"react/jsx-runtime";function st({className:e,...t}){return Bo("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 263 428",fill:"currentColor",className:Lo("w-[0.6em] h-[1em]",e),...t,children:[$("path",{d:"M132 321V428L263 243L132 321Z"}),$("path",{d:"M0 243L132 321V428",fillOpacity:"0.5"}),$("path",{d:"M132 0V296L263 218"}),$("path",{d:"M0 218L132 296V0L0 218Z",fillOpacity:"0.5"})]})}import{formatEther as qo}from"viem";function ct(e){let t=qo(e),r=Math.floor(parseFloat(t)).toString().length;return parseFloat(t).toLocaleString("en-US",{maximumFractionDigits:Math.max(0,6-r)})}import{jsx as Wo,jsxs as Go}from"react/jsx-runtime";function dt({wei:e}){return Go("span",{className:"inline-flex items-center gap-1",children:[ct(e)," ",Wo(st,{})]})}import{useEffect as Qo}from"react";import{jsx as N,jsxs as fe}from"react/jsx-runtime";function lt({isActive:e,isExpanded:t,userAddress:r}){let o=$e(r),n=it();return Qo(()=>{let a=setTimeout(()=>{e&&n.status==="idle"&&o.isSuccess&&o.data<_&&n.mutate(r)});return()=>clearTimeout(a)},[o.data,o.isSuccess,n,e,r]),fe("div",{className:"flex flex-col gap-4",children:[fe("div",{className:"flex justify-between gap-4",children:[fe("div",{children:[N("div",{children:"Allowance"}),N("div",{className:"font-mono text-white",children:o.data!=null?N(dt,{wei:o.data}):N(v,{className:"text-sm"})})]}),N(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e||t,pending:o.status==="pending"||n.status==="pending",onClick:()=>n.mutate(r),children:"Top up"})]}),t?N("p",{className:"text-sm",children:"Your allowance is used to pay for onchain computation."}):null]})}import{encodeFunctionData as mt}from"viem";import{useMutation as tn,useQueryClient as rn}from"@tanstack/react-query";import{getAction as he}from"viem/utils";import{sendUserOperation as on,waitForUserOperationReceipt as nn}from"viem/account-abstraction";import{waitForTransactionReceipt as an}from"viem/actions";import{useClient as sn}from"wagmi";import{resourceToHex as ut}from"@latticexyz/common";import cn from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";import{writeContract as Jo}from"viem/actions";import{getAction as Zo}from"viem/utils";import{toHex as Uo}from"viem";import{signTypedData as Vo}from"viem/actions";import{callWithSignatureTypes as _o}from"@latticexyz/world/internal";import{getRecord as Yo}from"@latticexyz/store/internal";import jo from"@latticexyz/world-modules/internal/mud.config";import{hexToResource as Xo}from"@latticexyz/common";import{getAction as $o}from"viem/utils";async function pt({userClient:e,worldAddress:t,systemId:r,callData:o,nonce:n,client:a}){let s=n??(a?(await Yo(a,{address:t,table:jo.tables.CallWithSignatureNonces,key:{signer:e.account.address},blockTag:"pending"})).nonce:0n),{namespace:d,name:l}=Xo(r);return await $o(e,Vo,"signTypedData")({account:e.account,domain:{verifyingContract:t,salt:Uo(e.chain.id,{size:32})},types:_o,primaryType:"Call",message:{signer:e.account.address,systemNamespace:d,systemName:l,callData:o,nonce:s}})}import en from"@latticexyz/world-modules/out/Unstable_CallWithSignatureSystem.sol/Unstable_CallWithSignatureSystem.abi.json";async function ge({sessionClient:e,...t}){let r=await pt(t);return Zo(e,Jo,"writeContract")({address:t.worldAddress,abi:en,functionName:"callWithSignature",args:[t.userClient.account.address,t.systemId,t.callData,r]})}function ft({userClient:e}){let t=rn(),{chainId:r,worldAddress:o,paymasterAddress:n}=p(),a=sn({chainId:r}),s=["setupSession",a?.chain.id,e.account.address];return tn({mutationKey:s,onError:d=>console.error(d),mutationFn:async({sessionClient:d,registerSpender:l,registerDelegation:i})=>{if(!a)throw new Error("Client not ready.");let c=d.account.address;if(console.log("setting up session"),e.account.type!=="smart"){let m=[];if(l){console.log("registering spender");let g=await ge({client:a,userClient:e,sessionClient:d,worldAddress:n,systemId:ut({type:"system",namespace:"",name:"SpenderSystem"}),callData:mt({abi:de,functionName:"registerSpender",args:[c]})});console.log("got spender tx",g),m.push(g)}if(i){console.log("registering delegation");let g=await ge({client:a,userClient:e,sessionClient:d,worldAddress:o,systemId:ut({type:"system",namespace:"",name:"Registration"}),callData:mt({abi:cn,functionName:"registerDelegation",args:[c,z,"0x"]})});console.log("got delegation tx",g),m.push(g)}if(!m.length)return;console.log("waiting for",m.length,"receipts");for(let g of m){let h=await he(a,an,"waitForTransactionReceipt")({hash:g});console.log("got tx receipt",h),h.status==="reverted"&&console.error("tx reverted?",h)}}else{let m=[];if(l&&(console.log("registering spender"),m.push({to:n,abi:de,functionName:"registerSpender",args:[c]})),i&&(console.log("registering delegation"),m.push({to:o,abi:qe,functionName:"registerDelegation",args:[c,z,"0x"]})),!m.length)return;console.log("setting up account with",m,e);let g=await he(e,on,"sendUserOperation")({calls:m});console.log("got user op hash",g);let h=await he(e,nn,"waitForUserOperationReceipt")({hash:g});console.log("got user op receipt",h),h.success||console.error("not successful?",h)}await Promise.all([t.invalidateQueries({queryKey:["getSpender"]}),t.invalidateQueries({queryKey:["getDelegation"]}),t.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{useEffect as hn}from"react";import{useClient as mn}from"wagmi";import{queryOptions as un,useQuery as fn}from"@tanstack/react-query";import{smartAccountActions as dn}from"permissionless";import{callFrom as ln}from"@latticexyz/world/internal";import{observer as pn}from"@latticexyz/explorer/observer";async function gt({client:e,userAddress:t,sessionAccount:r,worldAddress:o,paymasterAddress:n}){let a=Q(e.chain);return G({paymasterAddress:n,transport:a,client:e,account:r}).extend(dn()).extend(ln({worldAddress:o,delegatorAddress:t,publicClient:e})).extend(pn()).extend(()=>({userAddress:t}))}function gn({sessionAccount:e,client:t,userAddress:r,worldAddress:o,paymasterAddress:n}){let a=["getSessionClient",t?.uid,r,e?.address,o];return un(t&&r&&e?{queryKey:a,queryFn:()=>gt({sessionAccount:e,client:t,userAddress:r,worldAddress:o,paymasterAddress:n}),staleTime:1/0}:{queryKey:a,enabled:!1})}function J(e){let{chainId:t,worldAddress:r,paymasterAddress:o}=p(),n=mn({chainId:t}),{data:a}=nt(e);return fn(gn({sessionAccount:a,userAddress:e,client:n,worldAddress:r,paymasterAddress:o}))}import{jsx as D,jsxs as we}from"react/jsx-runtime";function ht({isActive:e,isExpanded:t,userClient:r,registerSpender:o,registerDelegation:n}){let{data:a}=J(r.account.address),s=ft({userClient:r}),d=!n&&!n;return hn(()=>{let l=setTimeout(()=>{e&&s.status==="idle"&&a&&!d&&s.mutate({sessionClient:a,registerSpender:o,registerDelegation:n})});return()=>clearTimeout(l)},[d,e,n,o,a,s]),we("div",{className:"flex flex-col gap-4",children:[we("div",{className:"flex justify-between gap-4",children:[we("div",{children:[D("div",{children:"Session"}),D("div",{className:"font-mono text-white",children:d?"Enabled":"Set up"})]}),d?D(y,{variant:"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,disabled:!0,children:"Enabled"}):D(y,{variant:e?"primary":"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,pending:!a||s.status==="pending",onClick:a?()=>s.mutate({sessionClient:a,registerSpender:o,registerDelegation:n}):void 0,children:"Enable"})]}),t?D("p",{className:"text-sm",children:"You can perform actions in this app without interruptions for approvals."}):null]})}import{jsx as E}from"react/jsx-runtime";function wt({userClient:e,initialUserAddress:t}){let r=e.account.address,{data:o}=P(r),{closeAccountModal:n}=w(),a=r!==t,s=bn(o);wn(()=>{o!=null&&(s.current==null&&(s.current=o),o.complete&&(a||!s.current.complete)&&n())},[n,a,o]);let{hasAllowance:d,isSpender:l,hasDelegation:i}=o??{},c=yn(()=>r?[{id:"wallet",isComplete:!0,content:u=>E(at,{...u,userAddress:r})},{id:"allowance",isComplete:!!d,content:u=>E(lt,{...u,userAddress:r})},{id:"session",isComplete:!!l&&!!i,content:u=>E(ht,{...u,userClient:e,registerSpender:!l,registerDelegation:!i})}]:[{id:"wallet",isComplete:!1,content:()=>null}],[d,i,l,r,e]),[m]=xn(null),g=c.find(u=>u.content!=null&&!u.isComplete),h=c.filter(u=>u.isComplete),re=(m!=null?c.find(u=>u.id===m):null)??g??(h.length<c.length?h.at(-1):null),xe=re?c.indexOf(re):-1;return E("div",{className:ye("min-h-[26rem] px-8 flex flex-col divide-y divide-neutral-800","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:c.map((u,Kt)=>{let oe=u===re,Ot=oe||h.length===c.length,Dt=!u.isComplete&&xe!==-1&&Kt>xe;return E("div",{className:ye("py-8 flex flex-col justify-center",oe?"flex-grow":null),children:E("div",{className:ye("flex flex-col",Dt?"opacity-30 pointer-events-none":null),children:u.content({isActive:oe,isExpanded:Ot})})},u.id)})})}import{useRef as kn}from"react";import{jsx as yt}from"react/jsx-runtime";function bt(){let{chainId:e}=p(),t=Cn({chainId:e}),{address:r}=vn(),o=kn(r);return t.status!=="success"?yt(je,{}):yt(wt,{userClient:t.data,initialUserAddress:o.current})}import{useState as En}from"react";import{ErrorBoundary as In}from"react-error-boundary";import{twMerge as An}from"tailwind-merge";import{BaseError as Sn,UserRejectedRequestError as Pn}from"viem";import{jsx as xt,jsxs as Nn}from"react/jsx-runtime";function vt({title:e,error:t}){if(!t||t instanceof Sn&&t.walk(n=>n instanceof Pn)!=null)return null;let r=e??"Error",o=typeof t=="string"?t:t instanceof Error?String(t):"Something unexpected happened.";return Nn("div",{className:An("text-sm border-l-4 border-red-500","bg-red-100 text-red-900","dark:bg-red-900 dark:text-red-50"),children:[xt("div",{className:"p-3 font-semibold",children:r}),xt("div",{className:"px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll",children:o})]})}import{wait as Mn}from"@latticexyz/common/utils";import{twMerge as Tn}from"tailwind-merge";import{useIsMounted as Hn}from"usehooks-ts";import{jsx as Z,jsxs as Ct}from"react/jsx-runtime";function kt({children:e}){let t=Hn(),[r,o]=En(1);return Z(In,{fallbackRender:({error:n,resetErrorBoundary:a})=>Ct("div",{className:Tn("flex-grow flex flex-col justify-center p-5 gap-2"),children:[Z(vt,{error:n instanceof Error?n.stack??n.message:n}),r>0?Ct("button",{type:"button",onClick:async s=>{s.currentTarget.ariaBusy="true",await Mn(1e3),a(),t()&&(o(d=>d-1),s.currentTarget.ariaBusy=null)},className:"group aria-busy:pointer-events-none self-end flex items-center gap-1",children:[Z(v,{className:"transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400"}),Z("span",{className:"text-sm text-neutral-500 dark:text-neutral-400 group-hover:text-black dark:group-hover:text-white",children:"Retry?"})]}):null]}),children:e})}import{DialogClose as Kn,DialogTitle as On}from"@radix-ui/react-dialog";import{twMerge as zn}from"tailwind-merge";import{jsx as Rn}from"react/jsx-runtime";function At({className:e,children:t,...r}){return Rn("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:zn("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...r,children:t})}import{jsx as St}from"react/jsx-runtime";function Pt(e){return St(At,{strokeWidth:"2",stroke:"currentColor",...e,children:St("path",{d:"M6 18L18 6M6 6L18 18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as b,jsxs as be}from"react/jsx-runtime";function Et(){let{accountModalOpen:e,toggleAccountModal:t}=w();return be(ze,{open:e,onOpenChange:t,children:[b(On,{className:"sr-only",children:"Connect with EntryKit"}),e?be("div",{className:Nt("relative py-2 ring-1","bg-neutral-900 text-neutral-400 ring-neutral-700/50 divide-neutral-700","links:font-medium links:underline links:underline-offset-4","links:text-white","links:decoration-neutral-500 hover:links:decoration-orange-500"),children:[b(kt,{children:b(bt,{})}),be("a",{href:"https://mud.dev",target:"_blank",rel:"noreferrer noopener",className:"group self-center p-3 flex items-center justify-center gap-2 links-unset text-sm font-mono transition text-neutral-400 hover:text-white",children:[b("span",{className:"block w-4 h-4",children:b(C,{className:"w-full h-full text-orange-500 group-hover:rotate-90 transition duration-300"})}),b("span",{children:"Powered by MUD"})]}),b("div",{className:"absolute top-0 right-0",children:b(Kn,{className:Nt("pointer-events-auto leading-none p-2 transition","text-neutral-700 hover:text-neutral-500"),title:"Close",children:b(Pt,{className:"m-0"})})})]}):null]})}import{jsx as Fn,jsxs as Ln}from"react/jsx-runtime";function Dn({config:e,children:t}){return Ln(Ee,{config:e,children:[t,Fn(Et,{})]})}import{useAccount as qn}from"wagmi";import{twMerge as k}from"tailwind-merge";import{twMerge as It}from"tailwind-merge";import{Fragment as Bn,jsx as ee,jsxs as Mt}from"react/jsx-runtime";function Tt({address:e}){let{data:t}=j(e),r=U(t?.avatar);return Mt(Bn,{children:[Mt("span",{className:"flex-shrink-0 w-6 h-6 -my-1 -mx-0.5 grid place-items-center",children:[ee("img",{src:t?.avatar&&r.isSuccess?t.avatar:void 0,className:It("col-start-1 row-start-1","inline-flex w-full h-full rounded-full bg-black/10 dark:bg-white/10 bg-cover bg-no-repeat bg-center","transtion duration-300",r.isSuccess?"opacity-100":"opacity-0")}),ee(C,{className:It("col-start-1 row-start-1 text-orange-500","transition duration-300",t&&(!t.avatar||r.isError)?"opacity-100":"opacity-0")})]}),ee("span",{className:"flex-grow",children:t?.name??ee(X,{hex:e})})]})}import{useRef as Wn}from"react";import{jsx as x,jsxs as zt}from"react/jsx-runtime";var Ht=k("w-48 p-3 inline-flex outline-none transition","border border-transparent","text-base leading-none"),Gn=k("bg-neutral-100 border-neutral-300 text-black","dark:bg-neutral-800 dark:border-neutral-700 dark:text-white"),Qn=k("cursor-pointer outline-none hover:bg-neutral-200 data-[highlighted]:bg-neutral-200 dark:hover:bg-neutral-700");function Un(){let{openAccountModal:e,accountModalOpen:t}=w(),{status:r,address:o}=qn(),n=Wn(o),a=P(o),s=r==="connected"||r==="reconnecting"&&o,d=o!==n.current,l=a.isSuccess?a.data.complete:d?!1:s,i=(()=>{if(a.isSuccess){if(!a.data.hasAllowance)return"Top up";if(!a.data.hasDelegation||!a.data.isSpender)return"Set up"}return"Sign in"})();return x(L,{mode:"child",children:l?x("button",{type:"button",className:k(Ht,Gn,Qn),onClick:e,children:x("span",{className:"flex-grow inline-flex gap-2.5 items-center text-left font-medium",children:o?x(Tt,{address:o}):null})},"connected"):zt("button",{type:"button",className:k(Ht,"group","items-center justify-center gap-2.5","bg-orange-500 text-white font-medium","hover:bg-orange-400","active:bg-orange-600"),"aria-busy":t,onClick:e,children:[zt("span",{className:"pointer-events-none inline-grid place-items-center -ml-3",children:[x("span",{className:k("col-start-1 row-start-1 leading-none","scale-100 opacity-100 transition duration-300","group-aria-busy:scale-125 group-aria-busy:opacity-0"),children:x(C,{})}),x("span",{"aria-hidden":!0,className:k("col-start-1 row-start-1","scale-50 opacity-0 transition duration-300 delay-50","group-aria-busy:scale-100 group-aria-busy:opacity-100"),children:x(v,{})})]}),x("span",{className:"font-medium",children:i})]},"sign in")})}import{useConnectorClient as Vn}from"wagmi";function _n(){let{chainId:e}=p(),t=Vn({chainId:e});t.error&&console.error("Error retrieving user client",t.error);let r=t.data?.account.address,o=P(r),n=J(r);return t.isSuccess?!o.isSuccess||!o.data.complete?{...o,data:void 0}:n:{...t,data:void 0}}import{connectorsForWallets as jn,getDefaultWallets as Xn}from"@rainbow-me/rainbowkit";import{createConfig as $n}from"wagmi";var Yn=`data:image/svg+xml;base64,${btoa('<svg xmlns="http://www.w3.org/2000/svg" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd" width="512" height="512" viewBox="-64 -32 608 512"><path d="M6.206 425.469A6.202 6.202 0 010 419.263c0-1.771.235-3.517.663-5.245 9.95-78.847 57.22-96.006 100.964-107.256 21.008-5.412 62.901-26.489 57.822-53.668-10.596-9.819-21.113-23.39-22.946-43.63l-1.274.026c-2.932-.044-5.778-.716-8.422-2.217-5.848-3.325-9.051-9.697-10.596-16.958-3.238-22.186-4.058-33.515 7.768-38.464l.096-.035c-1.467-27.37 3.159-67.64-24.944-76.141C154.622 7.1 218.597-30.203 266.627 30.805c53.519 2.801 77.389 78.611 44.154 121.046h-1.405c11.826 4.949 10.045 17.674 7.767 38.464-1.544 7.261-4.747 13.633-10.595 16.958-2.645 1.501-5.481 2.173-8.422 2.217l-1.275-.026c-1.833 20.24-12.376 33.811-22.972 43.63-4.459 23.871 27.275 43.011 49.33 50.997a139.442 139.442 0 004.268 5.525c-7.2 9.941-8.771 22.797-4.564 34.038-17.002 8.763-24.255 29.334-16.479 46.86-11.966 7.55-18.258 21.305-16.609 34.955H6.206zm419.058-105.362a86.778 86.778 0 0019.446-1.641c29.36-5.822 53.152-27.467 62.657-55.823 3.596-10.544 5.071-21.663 4.521-33.341-1.179-23.46-12.193-46.633-29.631-62.369-17.107-15.361-38.342-23.574-61.383-23.042-22.841.507-45.359 11.216-60.187 28.593-14.977 17.551-22.003 39.144-20.921 62.133.585 11.661 3.482 23.016 8.737 34.074 7.741 16.303 19.934 29.735 35.391 39.048l-22.457 20.711 13.232 27.86-29.413 13.973 13.991 29.456-26.769 12.717 16.81 35.374 35.601-16.915 40.375-110.808zm15.239-129.364c13.685 4.869 20.824 19.908 15.954 33.593-4.87 13.685-19.908 20.833-33.593 15.963-13.685-4.87-20.834-19.917-15.963-33.602 4.87-13.685 19.917-20.825 33.602-15.954z"/></svg>')}`,te=e=>()=>({id:"passkey",name:"Passkey",iconUrl:Yn,iconBackground:"#fec",createConnector:t=>r=>({...S(e)(r),...t})});import{mapObject as Jn}from"@latticexyz/common/utils";import{wiresaw as Zn}from"@latticexyz/wiresaw/internal";function ea(e){let{wallets:t}=Xn(),r=[{groupName:"Recommended",wallets:[te({chainId:e.chainId})]},...t],o=jn(r,{appName:e.appName,projectId:e.walletConnectProjectId});return $n({connectors:o,chains:e.chains,transports:Jn(e.transports,n=>Zn(n)),pollingInterval:e.pollingInterval})}import{connectorsForWallets as ra}from"@rainbow-me/rainbowkit";import{getDefaultWallets as ta}from"@rainbow-me/rainbowkit";function Rt(e){let{wallets:t}=ta();return[{groupName:"Recommended",wallets:[te({chainId:e.chainId})]},...t]}function pm({wallets:e,...t}){return ra(e??Rt(t),{appName:t.appName,projectId:t.walletConnectProjectId})}export{Un as AccountButton,Dn as EntryKitProvider,ea as createWagmiConfig,Ft as defineConfig,pm as getConnectors,Rt as getWallets,S as passkeyConnector,te as passkeyWallet,w as useAccountModal,p as useEntryKitConfig,_n as useSessionClient};
1442
1442
  //# sourceMappingURL=internal.js.map