import{c7 as I,c5 as z,bN as g,bG as T,cl as p,a3 as l,cw as D,j3 as j,c6 as k,bv as H,a2 as N,j4 as A,W as C,bn as E,c8 as x}from"./BC4hLSsA.js";const O=`Ethereum Signed Message: `;function W(e){const t=typeof e=="string"?I(e):typeof e.raw=="string"?e.raw:z(e.raw),s=I(`${O}${g(t)}`);return T([s,t])}function Q(e,t){return p(W(e),t)}class B extends l{constructor({domain:t}){super(`Invalid domain "${D(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class R extends l{constructor({primaryType:t,types:s}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(s))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class F extends l{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function U(e){const{domain:t,message:s,primaryType:n,types:r}=e,a=(h,m)=>{const c={...m};for(const o of h){const{name:y,type:d}=o;d==="address"&&(c[y]=c[y].toLowerCase())}return c},i=r.EIP712Domain?t?a(r.EIP712Domain,t):{}:{},f=(()=>{if(n!=="EIP712Domain")return a(r[n],s)})();return D({domain:i,message:f,primaryType:n,types:r})}function V(e){const{domain:t,message:s,primaryType:n,types:r}=e,a=(i,f)=>{for(const h of i){const{name:m,type:c}=h,o=f[m],y=c.match(j);if(y&&(typeof o=="number"||typeof o=="bigint")){const[M,u,$]=y;k(o,{signed:u==="int",size:Number.parseInt($,10)/8})}if(c==="address"&&typeof o=="string"&&!H(o))throw new N({address:o});const d=c.match(A);if(d){const[M,u]=d;if(u&&g(o)!==Number.parseInt(u,10))throw new C({expectedSize:Number.parseInt(u,10),givenSize:g(o)})}const b=r[c];b&&(G(c),a(b,o))}};if(r.EIP712Domain&&t){if(typeof t!="object")throw new B({domain:t});a(r.EIP712Domain,t)}if(n!=="EIP712Domain")if(r[n])a(r[n],s);else throw new R({primaryType:n,types:r})}function _({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function G(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new F({type:e})}function X(e){const{domain:t={},message:s,primaryType:n}=e,r={EIP712Domain:_({domain:t}),...e.types};V({domain:t,message:s,primaryType:n,types:r});const a=["0x1901"];return t&&a.push(J({domain:t,types:r})),n!=="EIP712Domain"&&a.push(v({data:s,primaryType:n,types:r})),p(T(a))}function J({domain:e,types:t}){return v({data:e,primaryType:"EIP712Domain",types:t})}function v({data:e,primaryType:t,types:s}){const n=w({data:e,primaryType:t,types:s});return p(n)}function w({data:e,primaryType:t,types:s}){const n=[{type:"bytes32"}],r=[L({primaryType:t,types:s})];for(const a of s[t]){const[i,f]=S({types:s,name:a.name,type:a.type,value:e[a.name]});n.push(i),r.push(f)}return E(n,r)}function L({primaryType:e,types:t}){const s=x(q({primaryType:e,types:t}));return p(s)}function q({primaryType:e,types:t}){let s="";const n=P({primaryType:e,types:t});n.delete(e);const r=[e,...Array.from(n).sort()];for(const a of r)s+=`${a}(${t[a].map(({name:i,type:f})=>`${f} ${i}`).join(",")})`;return s}function P({primaryType:e,types:t},s=new Set){const n=e.match(/^\w*/u),r=n==null?void 0:n[0];if(s.has(r)||t[r]===void 0)return s;s.add(r);for(const a of t[r])P({primaryType:a.type,types:t},s);return s}function S({types:e,name:t,type:s,value:n}){if(e[s]!==void 0)return[{type:"bytes32"},p(w({data:n,primaryType:s,types:e}))];if(s==="bytes")return n=`0x${(n.length%2?"0":"")+n.slice(2)}`,[{type:"bytes32"},p(n)];if(s==="string")return[{type:"bytes32"},p(x(n))];if(s.lastIndexOf("]")===s.length-1){const r=s.slice(0,s.lastIndexOf("[")),a=n.map(i=>S({name:t,type:r,types:e,value:i}));return[{type:"bytes32"},p(E(a.map(([i])=>i),a.map(([,i])=>i)))]}return[{type:s},n]}export{B as I,R as a,F as b,J as c,v as d,X as e,_ as g,Q as h,O as p,U as s,W as t,V as v};