1import{j as v,g as H}from"./index-D7MYvDwL.js";import{e as y}from"./index-D6S5a7UO.js";import{e as C}from"./events-Dl1YOmJ1.js";function A(r,n){for(var o=0;o<n.length;o++){const e=n[o];if(typeof e!="string"&&!Array.isArray(e)){for(const h in e)if(h!=="default"&&!(h in r)){const g=Object.getOwnPropertyDescriptor(e,h);g&&Object.defineProperty(r,h,g.get?g:{enumerable:!0,get:()=>e[h]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var _={},x={};const I=v(y);var m={};Object.defineProperty(m,"__esModule",{value:!0});m.numberToHex=m.getLowerCase=void 0;function P(r){return r&&r.toLowerCase()}m.getLowerCase=P;function E(r){return`0x${r.toString(16)}`}m.numberToHex=E;Object.defineProperty(x,"__esModule",{value:!0});x.SafeAppProvider=void 0;const p=I,L=C,i=m;class N extends L.EventEmitter{constructor(n,o){super(),this.submittedTxs=new Map,this.safe=n,this.sdk=o}async connect(){this.emit("connect",{chainId:this.chainId})}async disconnect(){}get chainId(){return this.safe.chainId}async request(n){var h,g,b,k;const{method:o,params:e=[]}=n;switch(o){case"eth_accounts":return[this.safe.safeAddress];case"net_version":case"eth_chainId":return(0,i.numberToHex)(this.chainId);case"personal_sign":{const[t,s]=e;if(this.safe.safeAddress.toLowerCase()!==s.toLowerCase())throw new Error("The address or message hash is invalid");const a=await this.sdk.txs.signMessage(t);return("signature"in a?a.signature:void 0)||"0x"}case"eth_sign":{const[t,s]=e;if(this.safe.safeAddress.toLowerCase()!==t.toLowerCase()||!s.startsWith("0x"))throw new Error("The address or message hash is invalid");const a=await this.sdk.txs.signMessage(s);return("signature"in a?a.signature:void 0)||"0x"}case"eth_signTypedData":case"eth_signTypedData_v4":{const[t,s]=e,a=typeof s=="string"?JSON.parse(s):s;if(this.safe.safeAddress.toLowerCase()!==t.toLowerCase())throw new Error("The address is invalid");const c=await this.sdk.txs.signTypedMessage(a);return("signature"in c?c.signature:void 0)||"0x"}case"eth_sendTransaction":const d={...e[0],value:e[0].value||"0",data:e[0].data||"0x"};typeof d.gas=="string"&&d.gas.startsWith("0x")&&(d.gas=parseInt(d.gas,16));const w=await this.sdk.txs.send({txs:[d],params:{safeTxGas:d.gas}});return this.submittedTxs.set(w.safeTxHash,{from:this.safe.safeAddress,hash:w.safeTxHash,gas:0,gasPrice:"0x00",nonce:0,input:d.data,value:d.value,to:d.to,blockHash:null,blockNumber:null,transactionIndex:null}),w.safeTxHash;case"eth_blockNumber":return(await this.sdk.eth.getBlockByNumber(["latest"])).number;case"eth_getBalance":return this.sdk.eth.getBalance([(0,i.getLowerCase)(e[0]),e[1]]);case"eth_getCode":return this.sdk.eth.getCode([(0,i.getLowerCase)(e[0]),e[1]]);case"eth_getTransactionCount":return this.sdk.eth.getTransactionCount([(0,i.getLowerCase)(e[0]),e[1]]);case"eth_getStorageAt":return this.sdk.eth.getStorageAt([(0,i.getLowerCase)(e[0]),e[1],e[2]]);case"eth_getBlockByNumber":return this.sdk.eth.getBlockByNumber([e[0],e[1]]);case"eth_getBlockByHash":return this.sdk.eth.getBlockByHash([e[0],e[1]]);case"eth_getTransactionByHash":let l=e[0];try{l=(await this.sdk.txs.getBySafeTxHash(l)).txHash||l}catch{}return this.submittedTxs.has(l)?this.submittedTxs.get(l):this.sdk.eth.getTransactionByHash([l]).then(t=>(t&&(t.hash=e[0]),t));case"eth_getTransactionReceipt":{let t=e[0];try{t=(await this.sdk.txs.getBySafeTxHash(t)).txHash||t}catch{}return this.sdk.eth.getTransactionReceipt([t]).then(s=>(s&&(s.transactionHash=e[0]),s))}case"eth_estimateGas":return this.sdk.eth.getEstimateGas(e[0]);case"eth_call":return this.sdk.eth.call([e[0],e[1]]);case"eth_getLogs":return this.sdk.eth.getPastLogs([e[0]]);case"eth_gasPrice":return this.sdk.eth.getGasPrice();case"wallet_getPermissions":return this.sdk.wallet.getPermissions();case"wallet_requestPermissions":return this.sdk.wallet.requestPermissions(e[0]);case"safe_setSettings":return this.sdk.eth.setSafeSettings([e[0]]);case"wallet_sendCalls":{const{from:t,calls:s,chainId:a}=e[0];if(a!==(0,i.numberToHex)(this.chainId))throw new Error(`Safe is not on chain ${a}`);if(t!==this.safe.safeAddress)throw Error("Invalid from address");const c=s.map((f,T)=>{if(!f.to)throw new Error(`Invalid call #${T}: missing "to" field`);return{to:f.to,data:f.data??"0x",value:f.value??(0,i.numberToHex)(0)}}),{safeTxHash:u}=await this.sdk.txs.send({txs:c});return{id:u}}case"wallet_getCallsStatus":{const t=e[0],s={[p.TransactionStatus.AWAITING_CONFIRMATIONS]:100,[p.TransactionStatus.AWAITING_EXECUTION]:100,[p.TransactionStatus.SUCCESS]:200,[p.TransactionStatus.CANCELLED]:400,[p.TransactionStatus.FAILED]:500},a=await this.sdk.txs.getBySafeTxHash(t),c={version:"1.0",id:t,chainId:(0,i.numberToHex)(this.chainId),status:s[a.txStatus]};if(!a.txHash)return c;const u=await this.sdk.eth.getTransactionReceipt([a.txHash]);if(!u)return c;const S=((g=(h=a.txData)==null?void 0:h.dataDecoded)==null?void 0:g.method)!=="multiSend"?1:((k=(b=a.txData.dataDecoded.parameters)==null?void 0:b[0].valueDecoded)==null?void 0:k.length)??1,f=Number(u.blockNumber),T=Number(u.gasUsed);return c.receipts=Array(S).fill({logs:u.logs,status:(0,i.numberToHex)(a.txStatus===p.TransactionStatus.SUCCESS?1:0),blockHash:u.blockHash,blockNumber:(0,i.numberToHex)(f),gasUsed:(0,i.numberToHex)(T),transactionHash:a.txHash}),c}case"wallet_showCallsStatus":throw new Error(`"${n.method}" not supported`);case"wallet_getCapabilities":return{[(0,i.numberToHex)(this.chainId)]:{atomicBatch:{supported:!0}
1}};default:throw Error(`"${n.method}" not implemented`)}}send(n,o){n||o("Undefined request"),this.request(n).then(e=>o(null,{jsonrpc:"2.0",id:n.id,result:e})).catch(e=>o(e,null))}}x.SafeAppProvider=N;(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.SafeAppProvider=void 0;var n=x;Object.defineProperty(r,"SafeAppProvider",{enumerable:!0,get:function(){return n.SafeAppProvider}})})(_);const B=H(_),U=A({__proto__:null,default:B},[_]);export{U as i};
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.