@latticexyz/entrykit 2.2.15-entrykit-07c5b562497802c5296541b07435eaa39fc3e483 → 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 tr(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 Ke,useState as Le}from"react";import mr from"react-dom";var Ie=`*, ::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 nr,useContext as or}from"react";import{jsx as ar}from"react/jsx-runtime";var Te=nr(null);function Ne({frame:e,children:t}){if(or(Te))throw new Error("`FrameProvider` can only be used once.");return ar(Te.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 ze}from"react";import{RainbowKitProvider as cr,lightTheme as He,midnightTheme as Ee}from"@rainbow-me/rainbowkit";import{useChains as dr}from"wagmi";import{getChainContractAddress as ir}from"viem";function G(e){return ir({chain:e,contract:"quarryPaymaster"})}import{jsx as De}from"react/jsx-runtime";var ue=sr(null);function Ue({config:e,children:t}){if(ze(ue))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=G(o);return De(cr,{initialChain:0,appInfo:{appName:e.appName},theme:e.theme==="light"?He({borderRadius:"none"}):e.theme==="dark"?Ee({borderRadius:"none"}):{lightMode:He({borderRadius:"none"}),darkMode:Ee({borderRadius:"none"})},children:De(ue.Provider,{value:{...e,chain:o,paymasterAddress:a},children:t})})}function y(){let e=ze(ue);if(!e)throw new Error("`useEntryKitConfig` can only be used within a `EntryKitProvider`.");return e}function qe(){let{theme:e}=y(),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=Ke(null);return fr({ref:r,onResize:e}),H("div",{ref:r,...t,style:{...t.style,display:"inline-grid"}})}var W=lr(function({mode:t,children:r},n){let o=Ke(null),[a,s]=Le(!1),p=a?o.current:null,[l,i]=Le({width:void 0,height:void 0}),c=p?.contentDocument,d=qe();ur(()=>{c&&c.body.setAttribute("data-theme",d)},[c,d]);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:c?mr.createPortal(hr(Ne,{frame:p,children:[H("div",{children:t==="modal"?r:H(gr,{onSize:i,children:r})}),H("style",{dangerouslySetInnerHTML:{__html:Ie}})]}),c.body):null})});import{twMerge as Be}from"tailwind-merge";import{jsx as P,jsxs as vr}from"react/jsx-runtime";function Fe({open:e,onOpenChange:t,children:r}){return P(wr,{open:e,onOpenChange:t,children:P(br,{children:vr(W,{mode:"modal",children:[P("div",{className:Be("fixed inset-0","bg-neutral-800/85","animate-in animate-duration-300 fade-in")}),P("div",{className:Be("fixed inset-0","grid items-end sm:items-center","animate-in animate-duration-300 fade-in slide-in-from-bottom-16"),children:P("div",{children:P(xr,{className:"outline-none w-full max-w-[26rem] mx-auto","aria-describedby":void 0,onOpenAutoFocus:n=>{n.preventDefault()},children:r})})})]})})})}import{useCallback as me,useMemo as Cr}from"react";import{useStore as Ar}from"zustand";import{createStore as kr}from"zustand/vanilla";var _=kr(()=>({open:!1}));function b(){let e=Ar(_,o=>o.open),t=me(()=>{_.setState({open:!0})},[]),r=me(()=>{_.setState({open:!1})},[]),n=me(o=>{_.setState({open:o})},[]);return Cr(()=>({accountModalOpen:e,openAccountModal:t,closeAccountModal:r,toggleAccountModal:n}),[e,t,r,n])}import{twMerge as _t}from"tailwind-merge";import{useAccount as oa,useConnectorClient as aa}from"wagmi";import{useAccount as Fn}from"wagmi";import{twMerge as D}from"tailwind-merge";import{twMerge as Sr}from"tailwind-merge";import{jsx as Ge,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:[Ge("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),Ge("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 E,jsxs as Or}from"react/jsx-runtime";var Rr=({variant:e="secondary"}={})=>D("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:D("bg-orange-600 text-white focus:border-yellow-400"),secondary:D("bg-neutral-700 text-white focus:border-orange-500"),tertiary:D("bg-neutral-800 text-white focus:border-orange-500")}[e]),x=({pending:e,variant:t,type:r,className:n,children:o,disabled:a,...s})=>E("button",{type:r||"button",className:D(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:[E("span",{className:"flex items-center justify-end text-[.75em]",children:E("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:E(A,{})})}),E("span",{children:o})]})});import{useConnectModal as Gn}from"@rainbow-me/rainbowkit";import{useMutation as pt}from"@tanstack/react-query";import{useConnectors as Un}from"wagmi";import{createClient as Mn,custom as In,getAddress as Tn,numberToHex as it,SwitchChainError as Nn}from"viem";import{ChainNotConfiguredError as Hn,createConnector as En}from"wagmi";import{createStore as Mr}from"zustand/vanilla";import{persist as Ir}from"zustand/middleware";var h=Mr(Ir(()=>({publicKeys:{},activeCredential:null}),{name:"mud:passkey:cache"}));function Tr(e){e.key===h.persist.getOptions().name&&h.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 fe,hashMessage as Hr,hashTypedData as _e,encodeAbiParameters as Ve,stringToHex as Er,size as Dr,encodePacked as zr,parseSignature as Ur,BaseError as qr}from"viem";import{entryPoint07Abi as Lr,entryPoint07Address as Kr,getUserOperationHash as Br,toSmartAccount as Fr}from"viem/account-abstraction";import{readContract as We}from"viem/actions";import{parseSignature as Gr}from"webauthn-p256";async function Y(e){let{client:t,owners:r,nonce:n=0n}=e,o=e.address,a={abi:Lr,address:Kr,version:"0.7"},s={abi:_r,address:"0x356336adA1619BeC1Ae4E6D94Dd9c0490DA414a8"};if(!r.length)throw new Error("`owners` must have at least one account.");function p(d){return d.type==="webAuthn"?d.publicKey:Nr(d.address)}let l=e.signer??r[0],i=r.indexOf(l);if(i===-1)throw new Error("`signer` must be one of `owners`.");let c=0n;return Fr({client:t,entryPoint:a,extend:{__isCoinbaseSmartAccount:!0,abi:Q,factory:s,signer:l},async encodeCalls(d){return d.length===1?fe({abi:Q,functionName:"execute",args:[d[0].to,d[0].value??0n,d[0].data??"0x"]}):fe({abi:Q,functionName:"executeBatch",args:[d.map(u=>({data:u.data??"0x",target:u.to,value:u.value??0n}))]})},async getAddress(){return o??=await We(t,{...s,functionName:"getAddress",args:[r.map(p),n]}),o},async getNonce(){let d=8n;return c=(c+1n)%(1n<<d),(BigInt(Date.now())<<d)+c<<64n},async getFactoryArgs(){let d=fe({abi:s.abi,functionName:"createAccount",args:[r.map(p),n]});return{factory:s.address,factoryData:d}},async getStubSignature(){return l.type==="webAuthn"?"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001949fc7c88032b9fcb5f6efc7a7b8c63668eae9871b765e23123bb473ff57aa831a7c0d9276168ebcc29f2875a0239cffdf2a9cd1c2007c5c77c071db9264df1d000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2273496a396e6164474850596759334b7156384f7a4a666c726275504b474f716d59576f4d57516869467773222c226f726967696e223a2268747470733a2f2f7369676e2e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73657d00000000000000000000000000000000000000000000":z({signature:"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",ownerIndex:i})},async sign(d){let u=await this.getAddress(),f=ye({address:u,chainId:t.chain.id,hash:d.hash}),w=await V({hash:f,owner:l});return z({signature:w,ownerIndex:i})},async signMessage(d){let{message:u}=d,f=await this.getAddress(),w=ye({address:f,chainId:t.chain.id,hash:Hr(u)}),g=await V({hash:w,owner:l});return z({signature:g,ownerIndex:i})},async signTypedData(d){let{domain:u,types:f,primaryType:w,message:g}=d,m=await this.getAddress(),le=ye({address:m,chainId:t.chain.id,hash:_e({domain:u,message:g,primaryType:w,types:f})}),N=await V({hash:le,owner:l});return z({signature:N,ownerIndex:i})},async signUserOperation(d){let{chainId:u=t.chain.id,...f}=d,w=await this.getAddress(),g=Br({chainId:u,entryPointAddress:a.address,entryPointVersion:a.version,userOperation:{...f,sender:w}}),m=await V({hash:g,owner:l});return z({signature:m,ownerIndex:i})},userOperation:{async estimateGas(d){if(l.type==="webAuthn")return{verificationGasLimit:BigInt(Math.max(Number(d.verificationGasLimit??0n),8e5))}}},async isOwner(d){return await We(t,{abi:Q,address:await this.getAddress(),functionName:"isOwnerBytes",args:[p(d)]})}})}async function V({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 qr("`owner` does not support raw sign.")}function ye({address:e,chainId:t,hash:r}){return _e({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 Ve([{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:Er(e.clientDataJSON),challengeIndex:BigInt(e.challengeIndex),typeIndex:BigInt(e.typeIndex),r,s:n}])}function z(e){let{ownerIndex:t}=e,r=(()=>{if(Dr(e.signature)!==65)return e.signature;let n=Ur(e.signature);return zr(["bytes32","bytes32","uint8"],[n.r,n.s,n.yParity===0?27:28])})();return Ve([{components:[{name:"ownerIndex",type:"uint8"},{name:"signatureData",type:"bytes"}],type:"tuple"}],[{ownerIndex:t,signatureData:r}])}var Q=[{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 U(e,t){let{publicKeys:r}=h.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 Y({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 Qe}from"webauthn-p256";import{concatBytes as Yr,utf8ToBytes as jr}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"'),p=r||n.indexOf('"challenge"'),l=Qe(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!==n.slice(Number(s),c.length+1))throw new Error("Invalid clientDataJSON");if(!n.slice(Number(p)).match(/^"challenge":"(.*?)"/))throw new Error("Invalid clientDataJSON");let u=new Uint8Array(await crypto.subtle.digest("SHA-256",jr(n))),f=new Uint8Array(await crypto.subtle.digest("SHA-256",Yr(Qe(t),u)));return Qr(f)}import{sign as Xr}from"webauthn-p256";import{parseSignature as $r,serializePublicKey as Ye}from"webauthn-p256";import{secp256r1 as je}from"@noble/curves/p256";function ge(e){let{r:t,s:r}=$r(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[Ye(n),Ye(o)]}import{hashMessage as Jr}from"viem";function Zr([e,t]){return en([...ge(e),...ge(t)])}async function $e(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 he(){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=h.getState().publicKeys[o.id];if(s)return s;let p=await j(n),l=await $e({credentialId:o.id,messageHash:p,signatureHex:r});if(!l)throw new Error("recovery failed");if(l.credential.id!==o.id)throw new Error("wrong credential");return h.setState(i=>({publicKeys:{...i.publicKeys,[o.id]:l.publicKey}})),l.publicKey})();return console.log("recovered passkey",o.id,a),h.setState(()=>({activeCredential:o.id})),{id:o.id,publicKey:a,raw:o}}import{createCredential as on}from"webauthn-p256";async function Xe(){let e=await on({name:"MUD Account"});return console.log("created passkey",e),h.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 $={pollingInterval:250},q=an({type:"system",namespace:"",name:"unlimited"}),Je=cn.namespaces.world.tables,Ze=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 X({paymasterAddress:e,...t}){let r=t.chain??t.client?.chain;return dn({...$,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 at,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 rt}from"viem/account-abstraction";import{formatUserOperationRequest as ln}from"viem/account-abstraction";async function J(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 et,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 tt({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:et}),s=await bn(e,wn,"writeContract")({abi:gn,address:et,functionName:"handleOps",args:[[o],e.account.address],chain:e.chain,account:e.account,gas:n});return{success:!0,userOpHash:a,receipt:{transactionHash:s}}}function nt({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[rt];if(n==="eth_sendUserOperation"){let[a,s]=o;if(s===rt){let p=await tt({executor:e,rpcUserOp:a});return t.set(p.userOpHash,p),p.userOpHash}}if(n==="eth_getUserOperationReceipt"){let[a]=o;return t.get(a)??null}if(n==="eth_estimateUserOperationGas")return await J(o);throw new Error("Not implemented")}})}}function ot(e){return t=>{let{request:r,...n}=e(t);return{request:async({method:a,params:s},p)=>a==="eth_estimateUserOperationGas"?J(s):r({method:a,params:s},p),...n}}}import{http as Cn}from"viem";function R(e){let t=new Map;function r(n){let o=t.get(n)??{receipts:new Map,userOpReceipts:new Map};return t.has(n)||t.set(n,o),o}return n=>{let o=n.chain?.rpcUrls&&"wiresaw"in n.chain.rpcUrls?Cn(n.chain.rpcUrls.wiresaw.http[0]):void 0;if(!o)return e(n);let a=e(n),s=o(n),p=null;async function l(){return p??=await a.request({method:"eth_chainId"})}return{...a,request:async({method:c,params:d},u)=>{let{receipts:f,userOpReceipts:w}=r(await l());if(c==="eth_chainId")return await l();if(c==="eth_call")return s.request({method:"wiresaw_call",params:d});if(c==="eth_getTransactionReceipt"){let[g]=d,m=f.get(g)??await a.request({method:c,params:d});return!f.has(g)&&m&&f.set(g,m),m}if(c==="eth_sendUserOperation"){let g=await s.request({method:"wiresaw_sendUserOperation",params:d});return w.set(g.userOpHash,{success:!0,userOpHash:g.userOpHash,receipt:{transactionHash:g.txHash}}),g.userOpHash}if(c==="eth_getUserOperationReceipt"){let[g]=d,m=w.get(g)??await a.request({method:c,params:d});return!w.has(g)&&m&&w.set(g,m),m}return await a.request({method:c,params:d},u)}}}}function Z(e){let t=e.rpcUrls.bundler?.http[0],r=e.rpcUrls.bundler?.http[0]?R(ot(at(t))):e.id===31337?nt({executor:kn({chain:e,transport:Sn([Pn(),at()]),account:Rn(On())}).extend(An())}):null;if(!r)throw new Error(`Chain ${e.id} config did not include a bundler RPC URL.`);return r}O.type="passkey";function O({chainId:e}){return En(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=R(n),a=G(r),s=Z(r),p=Mn({...$,chain:r,transport:o}),l=h.getState().activeCredential!=null;return{id:"passkey",type:O.type,name:"Passkey",async createPasskey(){let{id:i}=await Xe(),c=await U(p,i);this.onAccountsChanged([c.address]),this.onConnect?.({chainId:it(e)})},async reusePasskey(){let{id:i}=await he(),c=await U(p,i);this.onAccountsChanged([c.address]),this.onConnect?.({chainId:it(e)})},hasPasskey(){return Object.keys(h.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}.`);!h.getState().activeCredential&&!i?.isReconnecting&&await he();let c=await this.getAccounts();return l=c.length>0,{accounts:c,chainId:e}},async disconnect(){console.log("disconnect"),l=!1,h.setState({activeCredential:null})},async getAccounts(){console.log("getAccounts");let i=h.getState().activeCredential;if(!i)return[];try{console.log("getting account for credential",i);let c=await U(p,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(d=>d.id===i.chainId);if(!c)throw new Nn(new Hn);return c},onAccountsChanged(i){console.log("onAccountsChanged"),i.length>0?t.emitter.emit("change",{accounts:i.map(c=>Tn(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=h.getState().activeCredential;if(!c)throw new Error("Not connected.");let d=await U(p,c);return X({paymasterAddress:a,transport:s,client:p,account:d}).extend(Dn()).extend(zn())},async getProvider(i){return In({request:p.transport.request})({retryCount:0})}}})}function st(){let t=Un().find(r=>r.type===O.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 qn}from"tailwind-merge";import{jsx as we,jsxs as Ln}from"react/jsx-runtime";function k({className:e,...t}){return Ln("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 8 8",fill:"currentColor",shapeRendering:"crispEdges",className:qn("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...t,children:[we("path",{d:"M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z"}),we("path",{d:"M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z",opacity:".5"}),we("path",{d:"M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z"})]})}function ct(){let{appInfo:e}=y(),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 ee(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 te,jsxs as Bn}from"react/jsx-runtime";function dt(){let{appName:e,appIcon:t}=ct(),{data:r,isLoading:n}=ee(t);return Bn("div",{className:"flex-grow flex flex-col items-center justify-center gap-2",children:[te("div",{className:"w-16 h-16 m-2",children:n?null:r?te("img",{src:t,className:"w-full h-full object-cover"}):te(k,{className:"w-full h-full text-orange-500 dark:bg-neutral-800"})}),te("div",{className:"text-2xl text-white text-center",children:e})]})}import{twMerge as Wn}from"tailwind-merge";import{jsx as L,jsxs as lt}from"react/jsx-runtime";function ut(){let e=Fn(),{accountModalOpen:t}=b(),{openConnectModal:r,connectModalOpen:n}=Gn(),o=st(),a=pt({onError:i=>console.error(i),mutationKey:["createPasskey",o.id,t,n,e.status],mutationFn:()=>o.createPasskey()}),s=pt({onError:i=>console.error(i),mutationKey:["reusePasskey",o.id,t,n,e.status],mutationFn:()=>o.reusePasskey()}),p=o.hasPasskey(),l=[L(x,{variant:p?"tertiary":"secondary",className:"self-auto flex justify-center",pending:a.status==="pending"||a.status==="success",onClick:()=>a.mutate(),autoFocus:!p,children:"Create account"},"create"),L(x,{variant:p?"secondary":"tertiary",className:"self-auto flex justify-center",pending:s.status==="pending"||s.status==="success",onClick:()=>s.mutate(),autoFocus:p,children:"Sign in"},"signin")];return p&&l.reverse(),lt("div",{className:Wn("flex flex-col gap-6 p-6","animate-in animate-duration-300 fade-in slide-in-from-bottom-8"),children:[L("div",{className:"p-4",children:L(dt,{})}),lt("div",{className:"self-center flex flex-col gap-2 w-60",children:[l,L("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 ea,useMemo as ta,useRef as ra,useState as na}from"react";import{twMerge as Oe}from"tailwind-merge";import{parseEther as _n}from"viem";var re=_n("0.01");import{useClient as $n}from"wagmi";import{queryOptions as Xn,useQuery as Jn}from"@tanstack/react-query";import{defineStore as Vn}from"@latticexyz/store";import{parseAbi as Qn}from"viem";var be=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:[]}}}}}),ne=Yn.namespaces.root.tables;import{getRecord as jn}from"@latticexyz/store/internal";async function mt({client:e,paymasterAddress:t,userAddress:r}){return(await jn(e,{address:t,table:ne.Allowance,key:{user:r},blockTag:"pending"})).allowance}function xe({client:e,paymasterAddress:t,userAddress:r}){let n=["getAllowance",e?.chain.id,t,r];return Xn(e&&r?{queryKey:n,queryFn:()=>mt({client:e,paymasterAddress:t,userAddress:r})}:{queryKey:n,enabled:!1})}function ft(e){let{chainId:t,paymasterAddress:r}=y(),n=$n({chainId:t});return Jn(xe({client:n,paymasterAddress:r,userAddress:e}))}import{useClient as Kd}from"wagmi";import{queryOptions as eo,useQuery as Fd}from"@tanstack/react-query";import{getRecord as Zn}from"@latticexyz/store/internal";async function yt({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n}){return(await Zn(e,{address:t,table:ne.Spender,key:{spender:n},blockTag:"pending"})).user.toLowerCase()===r.toLowerCase()}function gt({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n}){let o=["getSpender",e?.chain.id,t,r,n];return eo(e&&r&&n?{queryKey:o,queryFn:()=>yt({client:e,paymasterAddress:t,userAddress:r,sessionAddress:n})}:{queryKey:o,enabled:!1})}import{useClient as $d}from"wagmi";import{queryOptions as ro,useQuery as Jd}from"@tanstack/react-query";import{getRecord as to}from"@latticexyz/store/internal";async function ht({client:e,worldAddress:t,userAddress:r,sessionAddress:n}){return(await to(e,{address:t,table:Je.UserDelegationControl,key:{delegator:r,delegatee:n},blockTag:"pending"})).delegationControlId===q}function wt({client:e,worldAddress:t,userAddress:r,sessionAddress:n}){let o=["getDelegation",e?.chain.id,t,r,n];return ro(e&&r&&n?{queryKey:o,queryFn:()=>ht({client:e,worldAddress:t,userAddress:r,sessionAddress:n})}:{queryKey:o,enabled:!1})}import{queryOptions as uo,useQuery as mo,useQueryClient as fo}from"@tanstack/react-query";import{useClient as yo}from"wagmi";import{useClient as co}from"wagmi";import{queryOptions as po,useQuery as lo}from"@tanstack/react-query";import{createStore as no}from"zustand/vanilla";import{persist as oo}from"zustand/middleware";var K=no(oo(()=>({signers:{}}),{name:"mud:entrykit",partialize:({signers:e})=>({signers:e})}));function ao(e){e.key===K.persist.getOptions().name&&K.persist.rehydrate()}window.addEventListener("storage",ao);import{generatePrivateKey as io,privateKeyToAccount as so}from"viem/accounts";function bt(e){let t=K.getState().signers[e]??(()=>{let r=io();return K.setState(n=>({signers:{...n.signers,[e]:r}})),r})();return so(t)}async function xt({client:e,userAddress:t}){let r=bt(t);return await Y({client:e,owners:[r]})}function ve({client:e,userAddress:t}){let r=["getSessionAccount",e?.chain.id,t];return po(e&&t?{queryKey:r,queryFn:()=>xt({client:e,userAddress:t}),staleTime:1/0}:{queryKey:r,enabled:!1})}function vt(e){let{chainId:t}=y(),r=co({chainId:t});return lo(ve({userAddress:e,client:r}))}function go({queryClient:e,client:t,userAddress:r,paymasterAddress:n,worldAddress:o}){let a=["getPrerequisites",t?.chain.id,r];return uo(t&&r?{queryKey:a,queryFn:async()=>{let{address:s}=await e.fetchQuery(ve({client:t,userAddress:r})),[p,l,i]=await Promise.all([e.fetchQuery(xe({client:t,paymasterAddress:n,userAddress:r})),e.fetchQuery(gt({client:t,paymasterAddress:n,userAddress:r,sessionAddress:s})),e.fetchQuery(wt({client:t,worldAddress:o,userAddress:r,sessionAddress:s}))]),c=p>=re;return{hasAllowance:c,isSpender:l,hasDelegation:i,complete:c&&l&&i}}}:{queryKey:a,enabled:!1})}function M(e){let t=fo(),{chainId:r,paymasterAddress:n,worldAddress:o}=y(),a=yo({chainId:r});return mo(go({queryClient:t,client:a,userAddress:e,paymasterAddress:n,worldAddress:o}),t)}import{useDisconnect as bo}from"wagmi";import{useQuery as ho}from"@tanstack/react-query";function oe(e){let t=e?.toLowerCase();return ho({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 Ce,jsxs as wo}from"react/jsx-runtime";function ae({hex:e}){return e.length<=10?Ce("span",{title:e,children:e}):wo("span",{title:e,children:[Ce("span",{className:"after:select-none after:content-['\u2026']",children:e.slice(0,6)}),Ce("span",{className:"tracking-[-1ch] text-transparent",children:e.slice(6,-4)}),e.slice(-4)]})}import{jsx as B,jsxs as Ae}from"react/jsx-runtime";function Ct({isActive:e,isExpanded:t,userAddress:r}){let{data:n}=oe(r),{disconnect:o,isPending:a}=bo(),{closeAccountModal:s}=b();return Ae("div",{className:"flex flex-col gap-4",children:[Ae("div",{className:"flex justify-between gap-4",children:[Ae("div",{children:[B("div",{children:"Account"}),B("div",{className:"font-mono text-white",children:n?.name??B(ae,{hex:r})})]}),B(x,{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?B("p",{className:"text-sm",children:"Each of your onchain actions in this app is associated with your account."}):null]})}import{useMutation as vo,useQueryClient as Co}from"@tanstack/react-query";import{http as xo}from"viem";function At(){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 xo(t)({chain:e,retryCount:0})}}function kt(){let e=Co(),{chain:t}=y(),r=["claimGasPass",t.id];return vo({mutationKey:r,onError:n=>console.error(n),mutationFn:async n=>{let o=At()({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 Ao}from"tailwind-merge";import{jsx as ie,jsxs as ko}from"react/jsx-runtime";function St({className:e,...t}){return ko("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 263 428",fill:"currentColor",className:Ao("w-[0.6em] h-[1em]",e),...t,children:[ie("path",{d:"M132 321V428L263 243L132 321Z"}),ie("path",{d:"M0 243L132 321V428",fillOpacity:"0.5"}),ie("path",{d:"M132 0V296L263 218"}),ie("path",{d:"M0 218L132 296V0L0 218Z",fillOpacity:"0.5"})]})}import{formatEther as So}from"viem";function Pt(e){let t=So(e),r=Math.floor(parseFloat(t)).toString().length;return parseFloat(t).toLocaleString("en-US",{maximumFractionDigits:Math.max(0,6-r)})}import{jsx as Po,jsxs as Ro}from"react/jsx-runtime";function Rt({wei:e}){return Ro("span",{className:"inline-flex items-center gap-1",children:[Pt(e)," ",Po(St,{})]})}import{useEffect as Oo}from"react";import{jsx as I,jsxs as ke}from"react/jsx-runtime";function Ot({isActive:e,isExpanded:t,userAddress:r}){let n=ft(r),o=kt();return Oo(()=>{let a=setTimeout(()=>{e&&o.status==="idle"&&n.isSuccess&&n.data<re&&o.mutate(r)});return()=>clearTimeout(a)},[n.data,n.isSuccess,o,e,r]),ke("div",{className:"flex flex-col gap-4",children:[ke("div",{className:"flex justify-between gap-4",children:[ke("div",{children:[I("div",{children:"Allowance"}),I("div",{className:"font-mono text-white",children:n.data!=null?I(Rt,{wei:n.data}):I(A,{className:"text-sm"})})]}),I(x,{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?I("p",{className:"text-sm",children:"Your allowance is used to pay for onchain computation."}):null]})}import{encodeFunctionData as It}from"viem";import{useMutation as Lo,useQueryClient as Ko}from"@tanstack/react-query";import{getAction as Pe}from"viem/utils";import{sendUserOperation as Bo,waitForUserOperationReceipt as Fo}from"viem/account-abstraction";import{waitForTransactionReceipt as Go}from"viem/actions";import{useClient as Wo}from"wagmi";import{resourceToHex as Tt}from"@latticexyz/common";import _o from"@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json";import{writeContract as zo}from"viem/actions";import{getAction as Uo}from"viem/utils";import{toHex as Mo}from"viem";import{signTypedData as Io}from"viem/actions";import{callWithSignatureTypes as To}from"@latticexyz/world/internal";import{getRecord as No}from"@latticexyz/store/internal";import Ho from"@latticexyz/world-modules/internal/mud.config";import{hexToResource as Eo}from"@latticexyz/common";import{getAction as Do}from"viem/utils";async function Mt({userClient:e,worldAddress:t,systemId:r,callData:n,nonce:o,client:a}){let s=o??(a?(await No(a,{address:t,table:Ho.tables.CallWithSignatureNonces,key:{signer:e.account.address},blockTag:"pending"})).nonce:0n),{namespace:p,name:l}=Eo(r);return await Do(e,Io,"signTypedData")({account:e.account,domain:{verifyingContract:t,salt:Mo(e.chain.id,{size:32})},types:To,primaryType:"Call",message:{signer:e.account.address,systemNamespace:p,systemName:l,callData:n,nonce:s}})}import qo from"@latticexyz/world-modules/out/Unstable_CallWithSignatureSystem.sol/Unstable_CallWithSignatureSystem.abi.json";async function Se({sessionClient:e,...t}){let r=await Mt(t);return Uo(e,zo,"writeContract")({address:t.worldAddress,abi:qo,functionName:"callWithSignature",args:[t.userClient.account.address,t.systemId,t.callData,r]})}function Nt({userClient:e}){let t=Ko(),{chainId:r,worldAddress:n,paymasterAddress:o}=y(),a=Wo({chainId:r}),s=["setupSession",a?.chain.id,e.account.address];return Lo({mutationKey:s,onError:p=>console.error(p),mutationFn:async({sessionClient:p,registerSpender:l,registerDelegation:i})=>{if(!a)throw new Error("Client not ready.");let c=p.account.address;if(console.log("setting up session"),e.account.type!=="smart"){let d=[];if(l){console.log("registering spender");let u=await Se({client:a,userClient:e,sessionClient:p,worldAddress:o,systemId:Tt({type:"system",namespace:"",name:"SpenderSystem"}),callData:It({abi:be,functionName:"registerSpender",args:[c]})});console.log("got spender tx",u),d.push(u)}if(i){console.log("registering delegation");let u=await Se({client:a,userClient:e,sessionClient:p,worldAddress:n,systemId:Tt({type:"system",namespace:"",name:"Registration"}),callData:It({abi:_o,functionName:"registerDelegation",args:[c,q,"0x"]})});console.log("got delegation tx",u),d.push(u)}if(!d.length)return;console.log("waiting for",d.length,"receipts");for(let u of d){let f=await Pe(a,Go,"waitForTransactionReceipt")({hash:u});console.log("got tx receipt",f),f.status==="reverted"&&console.error("tx reverted?",f)}}else{let d=[];if(l&&(console.log("registering spender"),d.push({to:o,abi:be,functionName:"registerSpender",args:[c]})),i&&(console.log("registering delegation"),d.push({to:n,abi:Ze,functionName:"registerDelegation",args:[c,q,"0x"]})),!d.length)return;console.log("setting up account with",d,e);let u=await Pe(e,Bo,"sendUserOperation")({calls:d});console.log("got user op hash",u);let f=await Pe(e,Fo,"waitForUserOperationReceipt")({hash:u});console.log("got user op receipt",f),f.success||console.error("not successful?",f)}await Promise.all([t.invalidateQueries({queryKey:["getSpender"]}),t.invalidateQueries({queryKey:["getDelegation"]}),t.invalidateQueries({queryKey:["getPrerequisites"]})])},retry:0})}import{useEffect as Zo}from"react";import{useClient as jo}from"wagmi";import{queryOptions as $o,useQuery as Xo}from"@tanstack/react-query";import{smartAccountActions as Vo}from"permissionless";import{callFrom as Qo}from"@latticexyz/world/internal";import{observer as Yo}from"@latticexyz/explorer/observer";async function Ht({client:e,userAddress:t,sessionAccount:r,worldAddress:n,paymasterAddress:o}){let a=Z(e.chain);return X({paymasterAddress:o,transport:a,client:e,account:r}).extend(Vo()).extend(Qo({worldAddress:n,delegatorAddress:t,publicClient:e})).extend(Yo()).extend(()=>({userAddress:t}))}function Jo({sessionAccount:e,client:t,userAddress:r,worldAddress:n,paymasterAddress:o}){let a=["getSessionClient",t?.uid,r,e?.address,n];return $o(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 se(e){let{chainId:t,worldAddress:r,paymasterAddress:n}=y(),o=jo({chainId:t}),{data:a}=vt(e);return Xo(Jo({sessionAccount:a,userAddress:e,client:o,worldAddress:r,paymasterAddress:n}))}import{jsx as F,jsxs as Re}from"react/jsx-runtime";function Et({isActive:e,isExpanded:t,userClient:r,registerSpender:n,registerDelegation:o}){let{data:a}=se(r.account.address),s=Nt({userClient:r}),p=!o&&!o;return Zo(()=>{let l=setTimeout(()=>{e&&s.status==="idle"&&a&&!p&&s.mutate({sessionClient:a,registerSpender:n,registerDelegation:o})});return()=>clearTimeout(l)},[p,e,o,n,a,s]),Re("div",{className:"flex flex-col gap-4",children:[Re("div",{className:"flex justify-between gap-4",children:[Re("div",{children:[F("div",{children:"Session"}),F("div",{className:"font-mono text-white",children:p?"Enabled":"Set up"})]}),p?F(x,{variant:"tertiary",className:"flex-shrink-0 text-sm p-1 w-28",autoFocus:e,disabled:!0,children:"Enabled"}):F(x,{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?F("p",{className:"text-sm",children:"You can perform actions in this app without interruptions for approvals."}):null]})}import{jsx as T}from"react/jsx-runtime";function Dt({userClient:e,initialUserAddress:t}){let r=e.account.address,{data:n}=M(r),{closeAccountModal:o}=b(),a=r!==t,s=ra(n);ea(()=>{n!=null&&(s.current==null&&(s.current=n),n.complete&&(a||!s.current.complete)&&o())},[o,a,n]);let{hasAllowance:p,isSpender:l,hasDelegation:i}=n??{},c=ta(()=>r?[{id:"wallet",isComplete:!0,content:m=>T(Ct,{...m,userAddress:r})},{id:"allowance",isComplete:!!p,content:m=>T(Ot,{...m,userAddress:r})},{id:"session",isComplete:!!l&&!!i,content:m=>T(Et,{...m,userClient:e,registerSpender:!l,registerDelegation:!i})}]:[{id:"wallet",isComplete:!1,content:()=>null}],[p,i,l,r,e]),[d]=na(null),u=c.find(m=>m.content!=null&&!m.isComplete),f=c.filter(m=>m.isComplete),w=(d!=null?c.find(m=>m.id===d):null)??u??(f.length<c.length?f.at(-1):null),g=w?c.indexOf(w):-1;return T("div",{className:Oe("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((m,le)=>{let N=m===w,Zt=N||f.length===c.length,er=!m.isComplete&&g!==-1&&le>g;return T("div",{className:Oe("py-8 flex flex-col justify-center",N?"flex-grow":null),children:T("div",{className:Oe("flex flex-col",er?"opacity-30 pointer-events-none":null),children:m.content({isActive:N,isExpanded:Zt})})},m.id)})})}import{useRef as ia}from"react";import{jsx as zt}from"react/jsx-runtime";function Ut(){let{chainId:e}=y(),t=aa({chainId:e}),{address:r}=oa(),n=ia(r);return t.status!=="success"?zt(ut,{}):zt(Dt,{userClient:t.data,initialUserAddress:n.current})}import{useState as la}from"react";import{ErrorBoundary as ua}from"react-error-boundary";import{twMerge as sa}from"tailwind-merge";import{BaseError as ca,UserRejectedRequestError as da}from"viem";import{jsx as qt,jsxs as pa}from"react/jsx-runtime";function Lt({title:e,error:t}){if(!t||t instanceof ca&&t.walk(o=>o instanceof da)!=null)return null;let r=e??"Error",n=typeof t=="string"?t:t instanceof Error?String(t):"Something unexpected happened.";return pa("div",{className:sa("text-sm border-l-4 border-red-500","bg-red-100 text-red-900","dark:bg-red-900 dark:text-red-50"),children:[qt("div",{className:"p-3 font-semibold",children:r}),qt("div",{className:"px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll",children:n})]})}import{wait as ma}from"@latticexyz/common/utils";import{twMerge as fa}from"tailwind-merge";import{useIsMounted as ya}from"usehooks-ts";import{jsx as ce,jsxs as Kt}from"react/jsx-runtime";function Bt({children:e}){let t=ya(),[r,n]=la(1);return ce(ua,{fallbackRender:({error:o,resetErrorBoundary:a})=>Kt("div",{className:fa("flex-grow flex flex-col justify-center p-5 gap-2"),children:[ce(Lt,{error:o instanceof Error?o.stack??o.message:o}),r>0?Kt("button",{type:"button",onClick:async s=>{s.currentTarget.ariaBusy="true",await ma(1e3),a(),t()&&(n(p=>p-1),s.currentTarget.ariaBusy=null)},className:"group aria-busy:pointer-events-none self-end flex items-center gap-1",children:[ce(A,{className:"transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400"}),ce("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 wa,DialogTitle as ba}from"@radix-ui/react-dialog";import{twMerge as ga}from"tailwind-merge";import{jsx as ha}from"react/jsx-runtime";function Ft({className:e,children:t,...r}){return ha("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:ga("-my-[0.125em] h-[1.25em] w-[1.25em]",e),...r,children:t})}import{jsx as Gt}from"react/jsx-runtime";function Wt(e){return Gt(Ft,{strokeWidth:"2",stroke:"currentColor",...e,children:Gt("path",{d:"M6 18L18 6M6 6L18 18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}import{jsx as v,jsxs as Me}from"react/jsx-runtime";function Vt(){let{accountModalOpen:e,toggleAccountModal:t}=b();return Me(Fe,{open:e,onOpenChange:t,children:[v(ba,{className:"sr-only",children:"Connect with EntryKit"}),e?Me("div",{className:_t("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:[v(Bt,{children:v(Ut,{})}),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:[v("span",{className:"block w-4 h-4",children:v(k,{className:"w-full h-full text-orange-500 group-hover:rotate-90 transition duration-300"})}),v("span",{children:"Powered by MUD"})]}),v("div",{className:"absolute top-0 right-0",children:v(wa,{className:_t("pointer-events-auto leading-none p-2 transition","text-neutral-700 hover:text-neutral-500"),title:"Close",children:v(Wt,{className:"m-0"})})})]}):null]})}import{jsx as va,jsxs as Ca}from"react/jsx-runtime";function xa({config:e,children:t}){return Ca(Ue,{config:e,children:[t,va(Vt,{})]})}import{useAccount as ka}from"wagmi";import{twMerge as S}from"tailwind-merge";import{twMerge as Qt}from"tailwind-merge";import{Fragment as Aa,jsx as de,jsxs as Yt}from"react/jsx-runtime";function jt({address:e}){let{data:t}=oe(e),r=ee(t?.avatar);return Yt(Aa,{children:[Yt("span",{className:"flex-shrink-0 w-6 h-6 -my-1 -mx-0.5 grid place-items-center",children:[de("img",{src:t?.avatar&&r.isSuccess?t.avatar:void 0,className:Qt("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")}),de(k,{className:Qt("col-start-1 row-start-1 text-orange-500","transition duration-300",t&&(!t.avatar||r.isError)?"opacity-100":"opacity-0")})]}),de("span",{className:"flex-grow",children:t?.name??de(ae,{hex:e})})]})}import{useRef as Sa}from"react";import{jsx as C,jsxs as Xt}from"react/jsx-runtime";var $t=S("w-48 p-3 inline-flex outline-none transition","border border-transparent","text-base leading-none"),Pa=S("bg-neutral-100 border-neutral-300 text-black","dark:bg-neutral-800 dark:border-neutral-700 dark:text-white"),Ra=S("cursor-pointer outline-none hover:bg-neutral-200 data-[highlighted]:bg-neutral-200 dark:hover:bg-neutral-700");function Oa(){let{openAccountModal:e,accountModalOpen:t}=b(),{status:r,address:n}=ka(),o=Sa(n),a=M(n),s=r==="connected"||r==="reconnecting"&&n,p=n!==o.current,l=a.isSuccess?a.data.complete:p?!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 C(W,{mode:"child",children:l?C("button",{type:"button",className:S($t,Pa,Ra),onClick:e,children:C("span",{className:"flex-grow inline-flex gap-2.5 items-center text-left font-medium",children:n?C(jt,{address:n}):null})},"connected"):Xt("button",{type:"button",className:S($t,"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:[Xt("span",{className:"pointer-events-none inline-grid place-items-center -ml-3",children:[C("span",{className:S("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:C(k,{})}),C("span",{"aria-hidden":!0,className:S("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:C(A,{})})]}),C("span",{className:"font-medium",children:i})]},"sign in")})}import{useConnectorClient as Ma}from"wagmi";function Ia(){let{chainId:e}=y(),t=Ma({chainId:e});t.error&&console.error("Error retrieving user client",t.error);let r=t.data?.account.address,n=M(r),o=se(r);return t.isSuccess?!n.isSuccess||!n.data.complete?{...n,data:void 0}:o:{...t,data:void 0}}import{connectorsForWallets as Na,getDefaultWallets as Ha}from"@rainbow-me/rainbowkit";import{createConfig as Ea}from"wagmi";var Ta=`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>')}`,pe=e=>()=>({id:"passkey",name:"Passkey",iconUrl:Ta,iconBackground:"#fec",createConnector:t=>r=>({...O(e)(r),...t})});import{mapObject as Da}from"@latticexyz/common/utils";function za(e){let{wallets:t}=Ha(),r=[{groupName:"Recommended",wallets:[pe({chainId:e.chainId})]},...t],n=Na(r,{appName:e.appName,projectId:e.walletConnectProjectId});return Ea({connectors:n,chains:e.chains,transports:Da(e.transports,o=>R(o)),pollingInterval:e.pollingInterval})}function Vm(e){return e!=null&&"__isCoinbaseSmartAccount"in e&&e.__isCoinbaseSmartAccount===!0}import{connectorsForWallets as qa}from"@rainbow-me/rainbowkit";import{getDefaultWallets as Ua}from"@rainbow-me/rainbowkit";function Jt(e){let{wallets:t}=Ua();return[{groupName:"Recommended",wallets:[pe({chainId:e.chainId})]},...t]}function t0({wallets:e,...t}){return qa(e??Jt(t),{appName:t.appName,projectId:t.walletConnectProjectId})}export{Oa as AccountButton,xa as EntryKitProvider,Q as abi,za as createWagmiConfig,tr as defineConfig,t0 as getConnectors,Jt as getWallets,Vm as isCoinbaseSmartAccount,O as passkeyConnector,pe as passkeyWallet,V as sign,Y as toCoinbaseSmartAccount,ye as toReplaySafeHash,Wr as toWebAuthnSignature,b as useAccountModal,y as useEntryKitConfig,Ia as useSessionClient,R as wiresaw,z 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