waku-lab/buddybook/assets/index-BnSaZ_jt.js

3 lines
30 KiB
JavaScript
Raw Normal View History

2024-11-14 13:56:45 +00:00
import{B as G,s as xe,k as A,c as $,e as K,t as X,n as et,i as tt,I as nt,b as j,d as st,f as V,h as it,j as p,l as q}from"./index-CBcRH9LY.js";const at=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,rt=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;class ct extends G{constructor({domain:t}){super(`Invalid domain "${xe(t)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class ot extends G{constructor({primaryType:t,types:n}){super(`Invalid primary type \`${t}\` must be one of \`${JSON.stringify(Object.keys(n))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class ut extends G{constructor({type:t}){super(`Struct type "${t}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}function dt(e){const{domain:t={},message:n,primaryType:s}=e,c={EIP712Domain:Et({domain:t}),...e.types};ht({domain:t,message:n,primaryType:s,types:c});const i=["0x1901"];return t&&i.push(lt({domain:t,types:c})),s!=="EIP712Domain"&&i.push(Q({data:n,primaryType:s,types:c})),A($(i))}function lt({domain:e,types:t}){return Q({data:e,primaryType:"EIP712Domain",types:t})}function Q({data:e,primaryType:t,types:n}){const s=z({data:e,primaryType:t,types:n});return A(s)}function z({data:e,primaryType:t,types:n}){const s=[{type:"bytes32"}],c=[ft({primaryType:t,types:n})];for(const i of n[t]){const[u,l]=Y({types:n,name:i.name,type:i.type,value:e[i.name]});s.push(u),c.push(l)}return K(s,c)}function ft({primaryType:e,types:t}){const n=X(gt({primaryType:e,types:t}));return A(n)}function gt({primaryType:e,types:t}){let n="";const s=J({primaryType:e,types:t});s.delete(e);const c=[e,...Array.from(s).sort()];for(const i of c)n+=`${i}(${t[i].map(({name:u,type:l})=>`${l} ${u}`).join(",")})`;return n}function J({primaryType:e,types:t},n=new Set){const s=e.match(/^\w*/u),c=s==null?void 0:s[0];if(n.has(c)||t[c]===void 0)return n;n.add(c);for(const i of t[c])J({primaryType:i.type,types:t},n);return n}function Y({types:e,name:t,type:n,value:s}){if(e[n]!==void 0)return[{type:"bytes32"},A(z({data:s,primaryType:n,types:e}))];if(n==="bytes")return s=`0x${(s.length%2?"0":"")+s.slice(2)}`,[{type:"bytes32"},A(s)];if(n==="string")return[{type:"bytes32"},A(X(s))];if(n.lastIndexOf("]")===n.length-1){const c=n.slice(0,n.lastIndexOf("[")),i=s.map(u=>Y({name:t,type:c,types:e,value:u}));return[{type:"bytes32"},A(K(i.map(([u])=>u),i.map(([,u])=>u)))]}return[{type:n},s]}function ht(e){const{domain:t,message:n,primaryType:s,types:c}=e,i=(u,l)=>{for(const h of u){const{name:v,type:f}=h,E=l[v],D=f.match(rt);if(D&&(typeof E=="number"||typeof E=="bigint")){const[B,S,H]=D;et(E,{signed:S==="int",size:Number.parseInt(H)/8})}if(f==="address"&&typeof E=="string"&&!tt(E))throw new nt({address:E});const w=f.match(at);if(w){const[B,S]=w;if(S&&j(E)!==Number.parseInt(S))throw new st({expectedSize:Number.parseInt(S),givenSize:j(E)})}const P=c[f];P&&(yt(f),i(P,E))}};if(c.EIP712Domain&&t){if(typeof t!="object")throw new ct({domain:t});i(c.EIP712Domain,t)}if(s!=="EIP712Domain")if(c[s])i(c[s],n);else throw new ot({primaryType:s,types:c})}function Et({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"&&{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 yt(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new ut({type:e})}const _t=`Ethereum Signed Message:
2024-11-14 07:02:08 +00:00
`;function Tt(e){const t=typeof e=="string"?V(e):typeof e.raw=="string"?e.raw:it(e.raw),n=V(`${_t}${j(t)}`);return $([n,t])}function vt(e,t){return A(Tt(e),t)}const Z=()=>"9.1.0",It=e=>e.toString(16).padStart(2,"0"),mt=e=>{const t=new Uint8Array(e/2);return window.crypto.getRandomValues(t),Array.from(t,It).join("")},At=()=>typeof window<"u"?mt(10):new Date().getTime().toString(36);class C{}C.makeRequest=(e,t)=>({id:At(),method:e,params:t,env:{sdkVersion:Z()}});C.makeResponse=(e,t,n)=>({id:e,success:!0,version:n,data:t});C.makeErrorResponse=(e,t,n)=>({id:e,success:!1,error:t,version:n});var g;(function(e){e.sendTransactions="sendTransactions",e.rpcCall="rpcCall",e.getChainInfo="getChainInfo",e.getSafeInfo="getSafeInfo",e.getTxBySafeTxHash="getTxBySafeTxHash",e.getSafeBalances="getSafeBalances",e.signMessage="signMessage",e.signTypedMessage="signTypedMessage",e.getEnvironmentInfo="getEnvironmentInfo",e.getOffChainSignature="getOffChainSignature",e.requestAddressBook="requestAddressBook",e.wallet_getPermissions="wallet_getPermissions",e.wallet_requestPermissions="wallet_requestPermissions"})(g||(g={}));var R;(function(e){e.requestAddressBook="requestAddressBook"})(R||(R={}));class St{constructor(t=null,n=!1){this.allowedOrigins=null,this.callbacks=new Map,this.debugMode=!1,this.isServer=typeof window>"u",this.isValidMessage=({origin:s,data:c,source:i})=>{const u=!c,l=!this.isServer&&i===window.parent,h=typeof c.version<"u"&&parseInt(c.version.split(".")[0]),v=typeof h=="number"&&h>=1;let f=!0;return Array.isArray(this.allowedOrigins)&&(f=this.allowedOrigins.find(E=>E.test(s))!==void 0),!u&&l&&v&&f},this.logIncomingMessage=s=>{console.info(`Safe Apps SDK v1: A message was received from origin ${s.origin}. `,s.data)},this.onParentMessage=s=>{this.isValidMessage(s)&&(this.debugMode&&this.logIncomingMessage(s),this.handleIncomingMessage(s.data))},this.handleIncomingMessage=s=>{const{id:c}=s,i=this.callbacks.get(c);i&&(i(s),this.callbacks.delete(c))},this.send=(s,c)=>{const i=C.makeRequest(s,c);if(this.isServer)throw new Error("Window doesn't exist");return window.parent.postMessage(i,"*"),new Promise((u,l)=>{this.callbacks.set(i.id,h=>{if(!h.success){l(new Error(h.error));return}u(h)})})},this.allowedOrigins=t,this.debugMode=n,this.isServer||window.addEventListener("message",this.onParentMessage)}}const W=e=>typeof e=="object"&&e!=null&&"domain"in e&&"types"in e&&"message"in e;var b={},_={},T={},k=p&&p.__awaiter||function(e,t,n,s){function c(i){return i instanceof n?i:new n(function(u){u(i)})}return new(n||(n=Promise))(function(i,u){function l(f){try{v(s.next(f))}catch(E){u(E)}}function h(f){try{v(s.throw(f))}catch(E){u(E)}}function v(f){f.done?i(f.value):c(f.value).then(l,h)}v((s=s.apply(e,t||[])).next())})};Object.defineProperty(T,"__esModule",{value:!0});T.getData=T.fetchData=T.stringifyQuery=T.insertParams=void 0;const Ot=e=>typeof e=="object"&&e!==null&&"code"in e&&"message"in e;function pt(e,t,n){return e.replace(new RegExp(`\\{${t}\\}`,"g"),n)}function bt(e,t){return t?Object.keys(t).reduce((n,s)=>pt(n,s,String(t[s])),e):e}T.insertParams=bt;function Nt(e){if(!e)return"";const t=new URLSearchParams;Object.keys(e).forEach(s=>{e[s]!=null&&t.append(s,String(e[s]))});const n=t.toString();return n?`?${n}`:""}T.stringifyQuery=Nt;function x(e){return k(this,void 0,void 0,function*(){let t;try{t=yield e.json()}catch{t={}}if(!e.ok){const n=Ot(t)?`CGW error - ${t.code}: ${t.message}`:`CGW error - status ${e.statusText}`;throw new Error(n)}return t})}function Ct(e,t,n,s,c){return k(this,void 0,void 0,function*(){const i=Object.assign({"Content-Type":"application/json"},s),u={method:t??"POST",headers:i};c&&(u.credentials=c),n!=null&&(u.body=typeof n=="string"?n:JSON.stringify(n));const l=yield fetch(e,u);return x(l)})}T.fetchData=Ct;function Dt(e,t,n){return k(this,void 0,void 0,function*(){const s={method:"GET"};t&&(s.headers=Object.assign(Object.assign({},t),{"Content-Type":"application/json"})),n&&(s.credentials=n);const c=yield fetch(e,s);return x(c)})}T.getData=Dt;Object.defineProperty(_,"__esModule",{value:!0});_.getEndpoint=_