1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{29040:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>P});var r=n(47093),s=n(52472),i=n(34545),o=n(84738),c=n(67979),a=n(24772),l=n(98390),d=class extends a.Q{#t;#e=void 0;#n;#r;constructor(t,e){super(),this.#t=t,this.setOptions(e),this.bindMethods(),this.#s()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){let e=this.options;this.options=this.#t.defaultMutationOptions(t),(0,l.f8)(this.options,e)||this.#t.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#n,observer:this}),e?.mutationKey&&this.options.mutationKey&&(0,l.EN)(e.mutationKey)!==(0,l.EN)(this.options.mutationKey)?this.reset():this.#n?.state.status==="pending"&&this.#n.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(t){this.#s(),this.#i(t)}getCurrentResult(){return this.#e}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#s(),this.#i()}mutate(t,e){return this.#r=e,this.#n?.removeObserver(this),this.#n=this.#t.getMutationCache().build(this.#t,this.options),this.#n.addObserver(this),this.#n.execute(t)}#s(){let t=this.#n?.state??(0,o.$)();this.#e={...t,isPending:"pending"===t.status,isSuccess:"success"===t.status,isError:"error"===t.status,isIdle:"idle"===t.status,mutate:this.mutate,reset:this.reset}}#i(t){c.j.batch(()=>{if(this.#r&&this.hasListeners()){let e=this.#e.variables,n=this.#e.context;t?.type==="success"?(this.#r.onSuccess?.(t.data,e,n),this.#r.onSettled?.(t.data,null,e,n)):t?.type==="error"&&(this.#r.onError?.(t.error,e,n),this.#r.onSettled?.(void 0,t.error,e,n))}this.listeners.forEach(t=>{t(this.#e)})})}},u=n(74926),h=n(58041);function m(t,e){let n=(0,u.jE)(e),[r]=i.useState(()=>new d(n,t));i.useEffect(()=>{r.setOptions(t)},[r,t]);let s=i.useSyncExternalStore(i.useCallback(t=>r.subscribe(c.j.batchCalls(t)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),o=i.useCallback((t,e)=>{r.mutate(t,e).catch(h.l)},[r]);if(s.error&&(0,h.G)(r.options.throwOnError,[s.error]))throw s.error;return{...s,mutate:o,mutateAsync:s.mutate}}var p=n(4123);async function g(t,e){let n;if((n="function"==typeof e.connector?t._internal.connectors.setup(e.connector):e.connector).uid===t.state.current)throw new p.nM;try{t.setState(t=>({...t,status:"connecting"})),n.emitter.emit("message",{type:"connecting"});let{connector:r,...s}=e,i=await n.connect(s),o=i.accounts;return n.emitter.off("connect",t._internal.events.connect),n.emitter.on("change",t._internal.events.change),n.emitter.on("disconnect",t._internal.events.disconnect),await t.storage?.setItem("recentConnectorId",n.id),t.setState(t=>({...t,connections:new Map(t.connections).set(n.uid,{accounts:o,chainId:i.chainId,connector:n}),current:n.uid,status:"connected"})),{accounts:o,chainId:i.chainId}}catch(e){throw t.setState(t=>({...t,status:t.current?"connected":"disconnected"})),e}}var y=n(2975),b=n(53293);let f=[];function x(t){let e=t.connectors;return(0,b.b)(f,e)?f:(f=e,e)}async function j(t,e={}){let n;if(e.connector)n=e.connector;else{let{connections:e,current:r}=t.state,s=e.get(r);n=s?.connector}let r=t.state.connections;n&&(await n.disconnect(),n.emitter.off("change",t._internal.events.change),n.emitter.off("disconnect",t._internal.events.disconnect),n.emitter.on("connect",t._internal.events.connect),r.delete(n.uid)),t.setState(t=>{if(0===r.size)return{...t,connections:new Map,current:null,status:"disconnected"};let e=r.values().next().value;return{...t,connections:new Map(r),current:e.connector.uid}});{let e=t.state.current;if(!e)return;let n=t.state.connections.get(e)?.connector;if(!n)return;await t.storage?.setItem("recentConnectorId",n.id)}}let v=[];function w(t){let e=[...t.state.connections.values()];return"reconnecting"===t.state.status||(0,b.b)(v,e)?v:(v=e,e)}var C=n(28593),S=n(48528),k=n(39230),R=n(29334);function E(t){return"0x"+t.toString(16).padStart(64,"0")}async function M(t){let{BrowserProvider:e}=await Promise.all([n.e(790),n.e(693)]).then(n.bind(n,12693)),r=new e(t);return await r.getSigner()}async function D(t,e,r){let{Contract:s}=await Promise.all([n.e(790),n.e(693)]).then(n.bind(n,12693));return new s(t,e,r)}function N(t){return"localhost"===t?k.fL:R.Tf}function O(t){return"localhost"===t?k.Yv:R.O}async function I(t,e,n,r,s){let i=N(r),o=await M(s),c=await D(i.address,i.abi,o),a=await c["public"===n?"incrementPublic":"increment"](t,e);await a.wait()}async function T(t){let e=N(t),r=O(t),{Contract:s,JsonRpcProvider:i}=await Promise.all([n.e(790),n.e(693)]).then(n.bind(n,12693)),o=new i(r),c=new s(e.address,e.abi,o);return E(await c.getCount())}async function z(t){let e=N(t),r=O(t),{Contract:s,JsonRpcProvider:i}=await Promise.all([n.e(790),n.e(693)]).then(n.bind(n,12693)),o=new i(r),c=new s(e.address,e.abi,o);return E(await c.getPublicCount())}function P(){let{address:t,isConnected:e,chain:n}=(0,s.F)(),{connect:o,connectors:c}=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{mutation:e}=t,n=(0,y.U)(t),{mutate:r,mutateAsync:s,...o}=m({...e,mutationFn:t=>g(n,t),mutationKey:["connect"]});return(0,i.useEffect)(()=>n.subscribe(t=>{let{status:e}=t;return e},(t,e)=>{"connected"===e&&"disconnected"===t&&o.reset()}),[n,o.reset]),{...o,connect:r,connectAsync:s,connectors:function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(0,y.U)(t);return(0,i.useSyncExternalStore)(t=>(function(t,e){let{onChange:n}=e;return t._internal.connectors.subscribe((t,e)=>{n(Object.values(t),e)})})(e,{onChange:t}),()=>x(e),()=>x(e))}({config:n})}}(),{disconnect:a}=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{mutation:e}=t,n=(0,y.U)(t),{mutate:r,mutateAsync:s,...o}=m({...e,mutationFn:t=>j(n,t),mutationKey:["disconnect"]});return{...o,connectors:(function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(0,y.U)(t);return(0,i.useSyncExternalStore)(t=>(function(t,e){let{onChange:n}=e;return t.subscribe(()=>w(t),n,{equalityFn:b.b})})(e,{onChange:t}),()=>w(e),()=>w(e))})({config:n}).map(t=>t.connector),disconnect:r,disconnectAsync:s}}(),{data:l}=(0,C.G)(),{client:d,status:u,isReady:h,network:p}=(0,S.wP)(),f="localhost"===p?k.sM:R.sQ,{createInput:v}=(0,S.lk)({contractAddress:f}),{decrypt:E}=(0,S.QE)(),{decrypt:M,clearCache:D}=(0,S.O)({contractAddress:f,cacheType:S.fK.Persistent}),[N,O]=(0,i.useState)("-"),[P,B]=(0,i.useState)("-"),[_,A]=(0,i.useState)(""),[F,K]=(0,i.useState)(""),[W,U]=(0,i.useState)(!1),H="localhost"===p?31337:0xaa36a7,L=e&&n&&n.id!==H,V=async()=>{await D(),a()},Y=async e=>{if(d&&t&&l){A("increment-".concat(e)),K("â³ Encrypting value..."),await new Promise(t=>setTimeout(t,0));try{let n=v(t);n.add32(1);
1let r=await n.encrypt();K("â³ Sending transaction..."),await I(r.handles[0],r.inputProof,e,p,l),K("â ".concat("user"===e?"User":"Public"," counter incremented successfully!")),setTimeout(()=>K(""),3e3)}catch(t){console.error("Increment error:",t),K("â Transaction failed"),setTimeout(()=>K(""),3e3)}finally{A("")}}},Q=async()=>{if(d&&t){A("decrypt-user"),O("â³ Decrypting...");try{let t=await T(p),e=await M(t);O(e.toString())}catch(t){console.error("Decrypt error:",t),O("â Error")}finally{A("")}}},q=async()=>{if(d){A("decrypt-public"),B("â³ Decrypting...");try{let t=await z(p),e=await E(t);B(e.toString())}catch(t){console.error("Decrypt error:",t),B("â Error")}finally{A("")}}};return(0,r.jsx)("main",{className:"container",children:(0,r.jsxs)("div",{className:"card",children:[(0,r.jsx)("h1",{style:{textAlign:"center"},children:"FHEVM SDK Next.js Demo"}),(0,r.jsx)("p",{className:"subtitle",children:"Build confidential applications with Fully Homomorphic Encryption"}),(0,r.jsxs)("p",{style:{textAlign:"center",fontSize:"0.875rem",opacity:.7,marginTop:"0.5rem"},children:["Network: ",(0,r.jsx)("strong",{children:"sepolia"===p?"Sepolia Testnet":"Localhost"})]}),(0,r.jsxs)("section",{className:"section",children:[(0,r.jsx)("h2",{children:"1. Connect Wallet"}),e?(0,r.jsxs)("div",{className:"wallet-info",children:[(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("p",{style:{marginBottom:"0.25rem",fontSize:"0.875rem",opacity:.7},children:"Connected Address"}),(0,r.jsxs)("p",{className:"wallet-address",children:[null==t?void 0:t.slice(0,8),"...",null==t?void 0:t.slice(-6)]})]}),(0,r.jsx)("button",{onClick:V,className:"btn-secondary",children:"Disconnect"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>U(!0),className:"btn-primary",children:"Connect Wallet"}),W&&(0,r.jsx)("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>U(!1),children:(0,r.jsxs)("div",{style:{backgroundColor:"#1d1d1b",padding:"2rem",borderRadius:"12px",minWidth:"300px",maxWidth:"400px"},onClick:t=>t.stopPropagation(),children:[(0,r.jsx)("h3",{style:{marginTop:0,marginBottom:"1.5rem",textAlign:"center",color:"#ffffff"},children:"Select Wallet"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:c.map(t=>(0,r.jsx)("button",{onClick:()=>{o({connector:t}),U(!1)},style:{padding:"1rem",backgroundColor:"#2d2d2b",border:"1px solid #ffd209",borderRadius:"8px",color:"#ffd209",cursor:"pointer",fontSize:"1rem",fontWeight:500,transition:"all 0.2s"},onMouseEnter:t=>{t.currentTarget.style.backgroundColor="#ffd209",t.currentTarget.style.color="#1d1d1b"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="#2d2d2b",t.currentTarget.style.color="#ffd209"},children:t.name},t.id))}),(0,r.jsx)("button",{onClick:()=>U(!1),style:{marginTop:"1rem",width:"100%",padding:"0.75rem",backgroundColor:"transparent",border:"1px solid #ffd209",borderRadius:"8px",color:"#ffd209",cursor:"pointer",fontSize:"0.9rem",transition:"all 0.2s"},onMouseEnter:t=>{t.currentTarget.style.backgroundColor="#ffd209",t.currentTarget.style.color="#1d1d1b"},onMouseLeave:t=>{t.currentTarget.style.backgroundColor="transparent",t.currentTarget.style.color="#ffd209"},children:"Cancel"})]})})]})]}),L&&(0,r.jsxs)("div",{style:{padding:"1rem",marginBottom:"1.5rem",backgroundColor:"rgba(244, 67, 54, 0.1)",border:"2px solid #f44336",borderRadius:"12px"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.5rem"},children:[(0,r.jsx)("span",{style:{fontSize:"1.5rem"},children:"â ï¸"}),(0,r.jsx)("strong",{style:{fontSize:"1.125rem",color:"#f44336"},children:"Wrong Network Detected"})]}),(0,r.jsxs)("p",{style:{marginBottom:"0.75rem",fontSize:"0.95rem"},children:["You're connected to ",(0,r.jsx)("strong",{children:(null==n?void 0:n.name)||"Unknown Network"})," (Chain ID: ",null==n?void 0:n.id,").",(0,r.jsx)("br",{}),"This app requires ",(0,r.jsx)("strong",{children:"localhost"===p?"Localhost (31337)":"Sepolia Testnet"}),"."]}),(0,r.jsx)("p",{style:{marginBottom:"0.75rem",fontSize:"0.95rem"},children:"Please disconnect and reconnect with the correct network selected in your wallet."}),(0,r.jsx)("button",{onClick:V,className:"btn-primary",style:{fontSize:"0.95rem",padding:"0.75rem 1.5rem"},children:"Disconnect Wallet"})]}),e&&!L&&(0,r.jsxs)("section",{className:"section",children:[(0,r.jsx)("h2",{children:"2. FHEVM Initialization"}),(0,r.jsxs)("div",{className:"status-badge",children:[(0,r.jsx)("span",{style:{fontSize:"1.25rem"},children:u===S.KH.READY?"â":u===S.KH.ERROR?"â":"â³"}),(0,r.jsx)("span",{className:u===S.KH.READY?"status-ready":"status-loading",children:u===S.KH.READY?"Ready":u===S.KH.ERROR?"Error":"Loading..."})]})]}),e&&!L&&h&&(0,r.jsxs)("section",{className:"section",children:[(0,r.jsx)("h2",{children:"3. Encrypted Counter Demo"}),(0,r.jsx)("p",{style:{marginBottom:"1.5rem",fontSize:"0.95rem"},children:"Interact with encrypted data on the blockchain using FHE."}),F&&(0,r.jsx)("div",{style:{padding:"1rem",marginBottom:"1.5rem",backgroundColor:F.startsWith("â")?"rgba(76, 175, 80, 0.1)":F.startsWith("â")?"rgba(244, 67, 54, 0.1)":"rgba(255, 193, 7, 0.1)",border:"2px s
1olid ".concat(F.startsWith("â")?"#4CAF50":F.startsWith("â")?"#f44336":"#FFC107"),borderRadius:"8px",textAlign:"center",fontWeight:500},children:F}),(0,r.jsxs)("div",{style:{marginBottom:"2rem",padding:"1.5rem",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"8px"},children:[(0,r.jsx)("h3",{style:{marginTop:0,marginBottom:"0.5rem"},children:"\uD83D\uDC64 User Counter (Private)"}),(0,r.jsxs)("p",{style:{fontSize:"0.875rem",opacity:.8,marginBottom:"1rem"},children:["Only you can decrypt this value using ",(0,r.jsx)("code",{style:{backgroundColor:"rgba(0,0,0,0.2)",padding:"2px 6px",borderRadius:"4px"},children:"userDecrypt()"})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"0.75rem",alignItems:"center",marginBottom:"1rem"},children:[(0,r.jsx)("button",{className:"btn-primary",onClick:()=>Y("user"),disabled:"increment-user"===_,children:"increment-user"===_?"Incrementing...":"Increment User Counter"}),(0,r.jsx)("button",{className:"btn-secondary",onClick:Q,disabled:"decrypt-user"===_,children:"decrypt-user"===_?"Decrypting...":"Decrypt My Value"})]}),(0,r.jsx)("div",{style:{padding:"1rem",backgroundColor:"rgba(255,255,255,0.1)",borderRadius:"6px"},children:(0,r.jsxs)("p",{style:{margin:0,fontSize:"0.875rem"},children:["Decrypted Value: ",(0,r.jsx)("strong",{style:{fontSize:"1.25rem"},children:N})]})})]}),(0,r.jsxs)("div",{style:{padding:"1.5rem",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"8px"},children:[(0,r.jsx)("h3",{style:{marginTop:0,marginBottom:"0.5rem"},children:"\uD83C\uDF0D Public Counter"}),(0,r.jsxs)("p",{style:{fontSize:"0.875rem",opacity:.8,marginBottom:"1rem"},children:["Anyone can decrypt this value using ",(0,r.jsx)("code",{style:{backgroundColor:"rgba(0,0,0,0.2)",padding:"2px 6px",borderRadius:"4px"},children:"publicDecrypt()"})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"0.75rem",alignItems:"center",marginBottom:"1rem"},children:[(0,r.jsx)("button",{className:"btn-primary",onClick:()=>Y("public"),disabled:"increment-public"===_,children:"increment-public"===_?"Incrementing...":"Increment Public Counter"}),(0,r.jsx)("button",{className:"btn-secondary",onClick:q,disabled:"decrypt-public"===_,children:"decrypt-public"===_?"Decrypting...":"Decrypt Public Value"})]}),(0,r.jsx)("div",{style:{padding:"1rem",backgroundColor:"rgba(255,255,255,0.1)",borderRadius:"6px"},children:(0,r.jsxs)("p",{style:{margin:0,fontSize:"0.875rem"},children:["Decrypted Value: ",(0,r.jsx)("strong",{style:{fontSize:"1.25rem"},children:P})]})})]})]})]})})}},83172:(t,e,n)=>{Promise.resolve().then(n.bind(n,29040))}},t=>{var e=e=>t(t.s=e);t.O(0,[58,330,335,550,358],()=>e(83172)),_N_E=t.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.