1import"./N9GT256q.js";import{B as e,C as t,D as s}from"./BYTFuITp.js";import"./gunKTr2l.js";import"./DGa90K1v.js";const a=()=>"9.1.0",n=e=>e.toString(16).padStart(2,"0");class i{}var r,o,c;i.makeRequest=(e,t)=>({id:"undefined"!=typeof window?(()=>{const e=new Uint8Array(5);return window.crypto.getRandomValues(e),Array.from(e,n).join("")})():(new Date).getTime().toString(36),method:e,params:t,env:{sdkVersion:"9.1.0"}}),i.makeResponse=(e,t,s)=>({id:e,success:!0,version:s,data:t}),i.makeErrorResponse=(e,t,s)=>({id:e,success:!1,error:t,version:s}),(o=r||(r={})).sendTransactions="sendTransactions",o.rpcCall="rpcCall",o.getChainInfo="getChainInfo",o.getSafeInfo="getSafeInfo",o.getTxBySafeTxHash="getTxBySafeTxHash",o.getSafeBalances="getSafeBalances",o.signMessage="signMessage",o.signTypedMessage="signTypedMessage",o.getEnvironmentInfo="getEnvironmentInfo",o.getOffChainSignature="getOffChainSignature",o.requestAddressBook="requestAddressBook",o.wallet_getPermissions="wallet_getPermissions",o.wallet_requestPermissions="wallet_requestPermissions",(c||(c={})).requestAddressBook="requestAddressBook";class l{constructor(e=null,t=!1){this.allowedOrigins=null,this.callbacks=new Map,this.debugMode=!1,this.isServer="undefined"==typeof window,this.isValidMessage=({origin:e,data:t,source:s})=>{const a=!t,n=!this.isServer&&s===window.parent,i=void 0!==t.version&&parseInt(t.version.split(".")[0]),r="number"==typeof i&&i>=1;let o=!0;return Array.isArray(this.allowedOrigins)&&(o=void 0!==this.allowedOrigins.find(t=>t.test(e))),!a&&n&&r&&o},this.logIncomingMessage=e=>{console.info(`Safe Apps SDK v1: A message was received from origin ${e.origin}. `,e.data)},this.onParentMessage=e=>{this.isValidMessage(e)&&(this.debugMode&&this.logIncomingMessage(e),this.handleIncomingMessage(e.data))},this.handleIncomingMessage=e=>{const{id:t}=e,s=this.callbacks.get(t);s&&(s(e),this.callbacks.delete(t))},this.send=(e,t)=>{const s=i.makeRequest(e,t);if(this.isServer)throw new Error("Window doesn't exist");return window.parent.postMessage(s,"*"),new Promise((e,t)=>{this.callbacks.set(s.id,s=>{s.success?e(s):t(new Error(s.error))})})},this.allowedOrigins=e,this.debugMode=t,this.isServer||window.addEventListener("message",this.onParentMessage)}}const u=e=>"object"==typeof e&&null!=e&&"domain"in e&&"types"in e&&"message"in e;class h{constructor(e){this.communicator=e}async getBySafeTxHash(e){if(!e)throw new Error("Invalid safeTxHash");return(await this.communicator.send(r.getTxBySafeTxHash,{safeTxHash:e})).data}async signMessage(e){const t={message:e};return(await this.communicator.send(r.signMessage,t)).data}async signTypedMessage(e){if(!u(e))throw new Error("Invalid typed data");return(await this.communicator.send(r.signTypedMessage,{typedData:e})).data}async send({txs:e,params:t}){if(!e||!e.length)throw new Error("No transactions were passed");const s={txs:e,params:t};return(await this.communicator.send(r.sendTransactions,s)).data}}const d={eth_call:"eth_call",eth_gasPrice:"eth_gasPrice",eth_getLogs:"eth_getLogs",eth_getBalance:"eth_getBalance",eth_getCode:"eth_getCode",eth_getBlockByHash:"eth_getBlockByHash",eth_getBlockByNumber:"eth_getBlockByNumber",eth_getStorageAt:"eth_getStorageAt",eth_getTransactionByHash:"eth_getTransactionByHash",eth_getTransactionReceipt:"eth_getTransactionReceipt",eth_getTransactionCount:"eth_getTransactionCount",eth_estimateGas:"eth_estimateGas",safe_setSettings:"safe_setSettings"},g={defaultBlockParam:(e="latest")=>e,returnFullTxObjectParam:(e=!1)=>e,blockNumberToHex:e=>Number.isInteger(e)?`0x${e.toString(16)}`:e};class m{constructor(e){this.communicator=e,this.call=this.buildRequest({call:d.eth_call,formatters:[null,g.defaultBlockParam]}),this.getBalance=this.buildRequest({call:d.eth_getBalance,formatters:[null,g.defaultBlockParam]}),this.getCode=this.buildRequest({call:d.eth_getCode,formatters:[null,g.defaultBlockParam]}),this.getStorageAt=this.buildRequest({call:d.eth_getStorageAt,formatters:[null,g.blockNumberToHex,g.defaultBlockParam]}),this.getPastLogs=this.buildRequest({call:d.eth_getLogs}),this.getBlockByHash=this.buildRequest({call:d.eth_getBlockByHash,formatters:[null,g.returnFullTxObjectParam]}),this.getBlockByNumber=this.buildRequest({call:d.eth_getBlockByNumber,formatters:[g.blockNumberToHex,g.returnFullTxObjectParam]}),this.getTransactionByHash=this.buildRequest({call:d.eth_getTransactionByHash}),this.getTransactionReceipt=this.buildRequest({call:d.eth_getTransactionReceipt}),this.getTransactionCount=this.buildRequest({call:d.eth_getTransactionCount,formatters:[null,g.defaultBlockParam]}),this.getGasPrice=this.buildRequest({call:d.eth_gasPrice}),this.getEstimateGas=e=>this.buildRequest({call:d.eth_estimateGas})([e]),this.setSafeSettings=this.buildRequest({call:d.safe_setSettings})}buildRequest(e){const{call:t,formatters:s}=e;return async e=>
1{s&&Array.isArray(e)&&s.forEach((t,s)=>{t&&(e[s]=t(e[s]))});const a={call:t,params:e||[]};return(await this.communicator.send(r.rpcCall,a)).data}}}const y=4001;class f extends Error{constructor(e,t,s){super(e),this.code=t,this.data=s,Object.setPrototypeOf(this,f.prototype)}}class p{constructor(e){this.communicator=e}async getPermissions(){return(await this.communicator.send(r.wallet_getPermissions,void 0)).data}async requestPermissions(e){if(!this.isPermissionRequestValid(e))throw new f("Permissions request is invalid",y);try{return(await this.communicator.send(r.wallet_requestPermissions,e)).data}catch{throw new f("Permissions rejected",y)}}isPermissionRequestValid(e){return e.every(e=>"object"==typeof e&&Object.keys(e).every(e=>!!Object.values(c).includes(e)))}}const w=(e,t)=>t.some(t=>t.parentCapability===e);class b{constructor(e){this.communicator=e}async getChainInfo(){return(await this.communicator.send(r.getChainInfo,void 0)).data}async getInfo(){return(await this.communicator.send(r.getSafeInfo,void 0)).data}async experimental_getBalances({currency:e="usd"}={}){return(await this.communicator.send(r.getSafeBalances,{currency:e})).data}async check1271Signature(t,s="0x"){const a=await this.getInfo(),n=e({abi:[{constant:!1,inputs:[{name:"_dataHash",type:"bytes32"},{name:"_signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"",type:"bytes4"}],payable:!1,stateMutability:"nonpayable",type:"function"}],functionName:"isValidSignature",args:[t,s]}),i={call:d.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return"0x1626ba7e"===(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()}catch(o){return!1}}async check1271SignatureBytes(t,s="0x"){const a=await this.getInfo(),n=e({abi:[{constant:!1,inputs:[{name:"_data",type:"bytes"},{name:"_signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"",type:"bytes4"}],payable:!1,stateMutability:"nonpayable",type:"function"}],functionName:"isValidSignature",args:[t,s]}),i={call:d.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return"0x20c13b0b"===(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()}catch(o){return!1}}calculateMessageHash(e){return t(e)}calculateTypedMessageHash(e){const t="object"==typeof e.domain.chainId?e.domain.chainId.toNumber():Number(e.domain.chainId);let a=e.primaryType;if(!a){const t=Object.values(e.types),s=Object.keys(e.types).filter(e=>t.every(t=>t.every(({type:t})=>t.replace("[","").replace("]","")!==e)));if(0===s.length||s.length>1)throw new Error("Please specify primaryType");a=s[0]}return s({message:e.message,domain:{...e.domain,chainId:t,verifyingContract:e.domain.verifyingContract,salt:e.domain.salt},types:e.types,primaryType:a})}async getOffChainSignature(e){return(await this.communicator.send(r.getOffChainSignature,e)).data}async isMessageSigned(e,t="0x"){let s;if("string"==typeof e&&(s=async()=>{const s=this.calculateMessageHash(e);return await this.isMessageHashSigned(s,t)}),u(e)&&(s=async()=>{const s=this.calculateTypedMessageHash(e);return await this.isMessageHashSigned(s,t)}),s)return await s();throw new Error("Invalid message type")}async isMessageHashSigned(e,t="0x"){const s=[this.check1271Signature.bind(this),this.check1271SignatureBytes.bind(this)];for(const a of s)if(await a(e,t))return!0;return!1}async getEnvironmentInfo(){return(await this.communicator.send(r.getEnvironmentInfo,void 0)).data}async requestAddressBook(){return(await this.communicator.send(r.requestAddressBook,void 0)).data}}!function(e,t,s,a){var n,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,s):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,s,a);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(r=(i<3?n(r):i>3?n(t,s,r):n(t,s))||r);i>3&&r&&Object.defineProperty(t,s,r)}([(e,t,s)=>{const a=s.value;return s.value=async function(){const e=new p(this.communicator);let s=await e.getPermissions();if(w(t,s)||(s=await e.requestPermissions([{[t]:{}}])),!w(t,s))throw new f("Permissions rejected",y);return a.apply(this)},s}],b.prototype,"requestAddressBook",null);class _{constructor(e={}){const{allowedDomains:t=null,debug:s=!1}=e;this.communicator=new l(t,s),this.eth=new m(this.communicator),this.txs=new h(this.communicator),this.safe=new b(this.communicator),this.wallet=new p(this.communicator)}}export{i as MessageFormatter,r as Methods,d as RPC_CALLS,c as RestrictedMethods,_ as default,a as getSDKVersion,u as isObjectEIP712TypedData}
vendor: 2 bytes, line 1
1;
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.