@dev.sail.money/sailor 0.0.2-21 → 0.0.2-23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/package.json +1 -1
  2. package/packages/cli/dist/index.cjs +2454 -2057
  3. package/packages/cli/dist/server.cjs +166 -156
  4. package/packages/sdk/dist/deployments.d.ts +14 -7
  5. package/packages/sdk/dist/deployments.d.ts.map +1 -1
  6. package/packages/sdk/dist/deployments.js +132 -141
  7. package/packages/sdk/dist/deployments.js.map +1 -1
  8. package/packages/sdk/dist/intelligence.d.ts +1 -1
  9. package/packages/sdk/dist/intelligence.js +1 -1
  10. package/packages/ui/dist/assets/{add-BzRDG6go.js → add-BcGCle88.js} +1 -1
  11. package/packages/ui/dist/assets/{all-wallets-C6juL2cm.js → all-wallets-8Jcfw5Qj.js} +1 -1
  12. package/packages/ui/dist/assets/{app-store-DSJ1ow5G.js → app-store-R1-af7b6.js} +1 -1
  13. package/packages/ui/dist/assets/{apple-CUEgIX9k.js → apple-Cxitz1aK.js} +1 -1
  14. package/packages/ui/dist/assets/{arrow-bottom-circle-C4CzuHiR.js → arrow-bottom-circle-BGQ9w6zi.js} +1 -1
  15. package/packages/ui/dist/assets/{arrow-bottom-BOhBj1Je.js → arrow-bottom-n-1aGCMa.js} +1 -1
  16. package/packages/ui/dist/assets/{arrow-left-BTD8zZ12.js → arrow-left-BngH26cQ.js} +1 -1
  17. package/packages/ui/dist/assets/{arrow-right-qcOukPwm.js → arrow-right-Bd1vyPNZ.js} +1 -1
  18. package/packages/ui/dist/assets/{arrow-top-C0f2945G.js → arrow-top-nst6Ttr2.js} +1 -1
  19. package/packages/ui/dist/assets/{bank-BSWzLP3R.js → bank-3aeQOng_.js} +1 -1
  20. package/packages/ui/dist/assets/{basic-DGTBsmnG.js → basic-Ds-ESc-H.js} +1 -1
  21. package/packages/ui/dist/assets/{browser-DJNepafc.js → browser-COcw6X9p.js} +1 -1
  22. package/packages/ui/dist/assets/{card-u08LJx43.js → card-B8clsijS.js} +1 -1
  23. package/packages/ui/dist/assets/{ccip-DcWZjG37.js → ccip-SgLYYQWq.js} +1 -1
  24. package/packages/ui/dist/assets/{checkmark-DVD-obDl.js → checkmark-CxpPWG40.js} +1 -1
  25. package/packages/ui/dist/assets/{checkmark-bold-CSXDqIAx.js → checkmark-bold-3THr8VIu.js} +1 -1
  26. package/packages/ui/dist/assets/{chevron-bottom-Be7f0gi2.js → chevron-bottom-HfWcF1bE.js} +1 -1
  27. package/packages/ui/dist/assets/{chevron-left-v8cgKRhQ.js → chevron-left-CkXbcOst.js} +1 -1
  28. package/packages/ui/dist/assets/{chevron-right-B0ux2X-3.js → chevron-right-Bt7ATlLQ.js} +1 -1
  29. package/packages/ui/dist/assets/{chevron-top-De-a8tmA.js → chevron-top-BZc4xycM.js} +1 -1
  30. package/packages/ui/dist/assets/{chrome-store-BIIIRGPA.js → chrome-store-IT1ftwJy.js} +1 -1
  31. package/packages/ui/dist/assets/{clock-8d5kvRPQ.js → clock-DpBvmJiH.js} +1 -1
  32. package/packages/ui/dist/assets/{close-BSSJkFv0.js → close-BoRwHijk.js} +1 -1
  33. package/packages/ui/dist/assets/{coinPlaceholder-CLJaQiUO.js → coinPlaceholder-Dba1nosr.js} +1 -1
  34. package/packages/ui/dist/assets/{compass-CR1zP0b-.js → compass-D4QnmoWi.js} +1 -1
  35. package/packages/ui/dist/assets/{copy-CGkuIFo6.js → copy-iBRvR2f1.js} +1 -1
  36. package/packages/ui/dist/assets/{core-ea860JM2.js → core-B0JxSbAV.js} +3 -3
  37. package/packages/ui/dist/assets/cursor-D3cYdnOt.js +3 -0
  38. package/packages/ui/dist/assets/{cursor-transparent-C8s5LY_P.js → cursor-transparent-Djp2Lulv.js} +1 -1
  39. package/packages/ui/dist/assets/{desktop-CQyixryE.js → desktop-DF6t43QS.js} +1 -1
  40. package/packages/ui/dist/assets/{disconnect-Ct0234l0.js → disconnect-BUeUrh3r.js} +1 -1
  41. package/packages/ui/dist/assets/{discord-haYPGMDl.js → discord-DWtvIwBI.js} +1 -1
  42. package/packages/ui/dist/assets/{etherscan-BTLrS1KK.js → etherscan-CrPMVPiO.js} +1 -1
  43. package/packages/ui/dist/assets/{events-wdo_D3Zy.js → events-DC84dMPF.js} +1 -1
  44. package/packages/ui/dist/assets/{exclamation-triangle-CMlYpOat.js → exclamation-triangle-9IcrwUru.js} +1 -1
  45. package/packages/ui/dist/assets/{extension-CNGBCbo8.js → extension-_qe-89Jo.js} +1 -1
  46. package/packages/ui/dist/assets/{external-link-DmYJSKcL.js → external-link-Bsar6cmv.js} +1 -1
  47. package/packages/ui/dist/assets/{facebook-F0iMVTem.js → facebook-CZnM2tIe.js} +1 -1
  48. package/packages/ui/dist/assets/{fallback-BqeFDEuW.js → fallback-BOfZ_bwu.js} +1 -1
  49. package/packages/ui/dist/assets/{farcaster-CYr9I6UA.js → farcaster-DyBlkt7c.js} +1 -1
  50. package/packages/ui/dist/assets/{filters-CxE97nqU.js → filters-DwCepBxH.js} +1 -1
  51. package/packages/ui/dist/assets/{github-CjRht-Wv.js → github-DgFcdJPt.js} +1 -1
  52. package/packages/ui/dist/assets/{google-3G0o4pR9.js → google-Csj-pWAm.js} +1 -1
  53. package/packages/ui/dist/assets/{help-circle-C5gNChqZ.js → help-circle-CF8XrZBx.js} +1 -1
  54. package/packages/ui/dist/assets/{id-C6_zK0Tb.js → id-YqFg_Hnr.js} +1 -1
  55. package/packages/ui/dist/assets/{image-DsU8Irlu.js → image-DvX7Dg9U.js} +1 -1
  56. package/packages/ui/dist/assets/{index-DQ44LBvq.js → index-3OLndEW6.js} +3 -3
  57. package/packages/ui/dist/assets/{index-CjvcQefO.js → index-BR_6qS4k.js} +1 -1
  58. package/packages/ui/dist/assets/{index-c8ZmMTds.js → index-BiN726SD.js} +1 -1
  59. package/packages/ui/dist/assets/index-DCnJ64lX.css +1 -0
  60. package/packages/ui/dist/assets/{index-Drc17uEc.js → index-Da0fOMbp.js} +1 -1
  61. package/packages/ui/dist/assets/{index-D1lgDFZV.js → index-DsS2DJdh.js} +1 -1
  62. package/packages/ui/dist/assets/index-yQSvDbVa.js +1775 -0
  63. package/packages/ui/dist/assets/{index.es-BhDQmlR4.js → index.es-BiIWW5o1.js} +4 -4
  64. package/packages/ui/dist/assets/{info-circle-CHV1idfy.js → info-circle-poBAGMBs.js} +1 -1
  65. package/packages/ui/dist/assets/{info-CAKKH6T2.js → info-zvmQXfcd.js} +1 -1
  66. package/packages/ui/dist/assets/{lightbulb-ew10LUMl.js → lightbulb-Dce_oD8K.js} +1 -1
  67. package/packages/ui/dist/assets/{mail-CACYeWXj.js → mail-dmvvhqN6.js} +1 -1
  68. package/packages/ui/dist/assets/{metamask-sdk-BUYu4RDE.js → metamask-sdk-BnCx3I3r.js} +1 -1
  69. package/packages/ui/dist/assets/{mobile-DX601q1y.js → mobile-B8JxvnR1.js} +1 -1
  70. package/packages/ui/dist/assets/{more-CQGeX45N.js → more-BwL7SLTo.js} +1 -1
  71. package/packages/ui/dist/assets/{network-placeholder-BQw8E4X-.js → network-placeholder-BGXRLaM_.js} +1 -1
  72. package/packages/ui/dist/assets/{nftPlaceholder-CifJ2CzA.js → nftPlaceholder-YKLlOwZU.js} +1 -1
  73. package/packages/ui/dist/assets/{off-B6oUArCZ.js → off-BdCZJUYq.js} +1 -1
  74. package/packages/ui/dist/assets/{parseSignature-DjWIdHkx.js → parseSignature-D9i4CKzP.js} +1 -1
  75. package/packages/ui/dist/assets/{play-store-Kq51oh3r.js → play-store-3UXzYs09.js} +1 -1
  76. package/packages/ui/dist/assets/{plus-BxZxVpff.js → plus-42VUC7wg.js} +1 -1
  77. package/packages/ui/dist/assets/{qr-code-CSBFpyhP.js → qr-code-W99JyxAx.js} +1 -1
  78. package/packages/ui/dist/assets/{recycle-horizontal-D0HyLkot.js → recycle-horizontal-B2t10e4m.js} +1 -1
  79. package/packages/ui/dist/assets/{refresh-BAQo228i.js → refresh-DEFqVlG3.js} +1 -1
  80. package/packages/ui/dist/assets/{reown-logo-DeUbwRp6.js → reown-logo-BpYt7vTo.js} +1 -1
  81. package/packages/ui/dist/assets/{search-C8Sd0Mpz.js → search-C38Hy_cf.js} +1 -1
  82. package/packages/ui/dist/assets/{secp256k1-BujG3JoP.js → secp256k1-IKD5pd64.js} +1 -1
  83. package/packages/ui/dist/assets/{send-B0JwUp6Q.js → send-gSwkftFg.js} +1 -1
  84. package/packages/ui/dist/assets/{swapHorizontal-B2k5yDqc.js → swapHorizontal-C1XbgPr5.js} +1 -1
  85. package/packages/ui/dist/assets/{swapHorizontalBold-yQqq0yPi.js → swapHorizontalBold-CtEf5r93.js} +1 -1
  86. package/packages/ui/dist/assets/{swapHorizontalMedium-NafYmdDj.js → swapHorizontalMedium-CHP_nvzn.js} +1 -1
  87. package/packages/ui/dist/assets/{swapHorizontalRoundedBold-BUn0GwEK.js → swapHorizontalRoundedBold-Crnco-Af.js} +1 -1
  88. package/packages/ui/dist/assets/{swapVertical-Be1m6suD.js → swapVertical-Ozkl0BQE.js} +1 -1
  89. package/packages/ui/dist/assets/{telegram-D-u7QHT5.js → telegram-BdfzLFDW.js} +1 -1
  90. package/packages/ui/dist/assets/{three-dots-B6Y4DFOR.js → three-dots-H2XRHPIG.js} +1 -1
  91. package/packages/ui/dist/assets/{twitch-DSy1rhWQ.js → twitch-DvbgB-BL.js} +1 -1
  92. package/packages/ui/dist/assets/{twitterIcon-tac1plSa.js → twitterIcon-BBsTYQzn.js} +1 -1
  93. package/packages/ui/dist/assets/{verify-6MylluBY.js → verify-3A_7IJxL.js} +1 -1
  94. package/packages/ui/dist/assets/{verify-filled-CZc0otb8.js → verify-filled-B4sP0yi_.js} +1 -1
  95. package/packages/ui/dist/assets/{w3m-modal-DbT03Pyz.js → w3m-modal-Bfua7kiP.js} +1 -1
  96. package/packages/ui/dist/assets/{wallet-473-ObZE.js → wallet-BbJ989Xh.js} +1 -1
  97. package/packages/ui/dist/assets/{wallet-placeholder-B9h3WvTk.js → wallet-placeholder-CQ2v8t-c.js} +1 -1
  98. package/packages/ui/dist/assets/{walletconnect-5GHIf5FR.js → walletconnect-BuShZt17.js} +1 -1
  99. package/packages/ui/dist/assets/{warning-circle-8A009Dx3.js → warning-circle-DMs8QNCr.js} +1 -1
  100. package/packages/ui/dist/assets/{x-B4jK8e8X.js → x-DzP75KD1.js} +1 -1
  101. package/packages/ui/dist/index.html +2 -2
  102. package/templates/default/AGENTS.md +3 -1
  103. package/packages/ui/dist/assets/cursor-DCRoxgSY.js +0 -3
  104. package/packages/ui/dist/assets/index-BCb0Nju4.js +0 -1775
  105. package/packages/ui/dist/assets/index-DDKDa0s2.css +0 -1
@@ -1 +1 @@
1
- import"./index-CjvcQefO.js";import{ch as y,d0 as T,d2 as k}from"./index-BCb0Nju4.js";const I=()=>"9.1.0",q=t=>t.toString(16).padStart(2,"0"),v=t=>{const e=new Uint8Array(t/2);return window.crypto.getRandomValues(e),Array.from(e,q).join("")},C=()=>typeof window<"u"?v(10):new Date().getTime().toString(36);class g{}g.makeRequest=(t,e)=>({id:C(),method:t,params:e,env:{sdkVersion:I()}});g.makeResponse=(t,e,s)=>({id:t,success:!0,version:s,data:e});g.makeErrorResponse=(t,e,s)=>({id:t,success:!1,error:e,version:s});var r;(function(t){t.sendTransactions="sendTransactions",t.rpcCall="rpcCall",t.getChainInfo="getChainInfo",t.getSafeInfo="getSafeInfo",t.getTxBySafeTxHash="getTxBySafeTxHash",t.getSafeBalances="getSafeBalances",t.signMessage="signMessage",t.signTypedMessage="signTypedMessage",t.getEnvironmentInfo="getEnvironmentInfo",t.getOffChainSignature="getOffChainSignature",t.requestAddressBook="requestAddressBook",t.wallet_getPermissions="wallet_getPermissions",t.wallet_requestPermissions="wallet_requestPermissions"})(r||(r={}));var m;(function(t){t.requestAddressBook="requestAddressBook"})(m||(m={}));class R{constructor(e=null,s=!1){this.allowedOrigins=null,this.callbacks=new Map,this.debugMode=!1,this.isServer=typeof window>"u",this.isValidMessage=({origin:a,data:n,source:i})=>{const o=!n,l=!this.isServer&&i===window.parent,u=typeof n.version<"u"&&parseInt(n.version.split(".")[0]),B=typeof u=="number"&&u>=1;let p=!0;return Array.isArray(this.allowedOrigins)&&(p=this.allowedOrigins.find(P=>P.test(a))!==void 0),!o&&l&&B&&p},this.logIncomingMessage=a=>{console.info(`Safe Apps SDK v1: A message was received from origin ${a.origin}. `,a.data)},this.onParentMessage=a=>{this.isValidMessage(a)&&(this.debugMode&&this.logIncomingMessage(a),this.handleIncomingMessage(a.data))},this.handleIncomingMessage=a=>{const{id:n}=a,i=this.callbacks.get(n);i&&(i(a),this.callbacks.delete(n))},this.send=(a,n)=>{const i=g.makeRequest(a,n);if(this.isServer)throw new Error("Window doesn't exist");return window.parent.postMessage(i,"*"),new Promise((o,l)=>{this.callbacks.set(i.id,u=>{if(!u.success){l(new Error(u.error));return}o(u)})})},this.allowedOrigins=e,this.debugMode=s,this.isServer||window.addEventListener("message",this.onParentMessage)}}const b=t=>typeof t=="object"&&t!=null&&"domain"in t&&"types"in t&&"message"in t;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 s={message:e};return(await this.communicator.send(r.signMessage,s)).data}async signTypedMessage(e){if(!b(e))throw new Error("Invalid typed data");return(await this.communicator.send(r.signTypedMessage,{typedData:e})).data}async send({txs:e,params:s}){if(!e||!e.length)throw new Error("No transactions were passed");const a={txs:e,params:s};return(await this.communicator.send(r.sendTransactions,a)).data}}const c={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"},h={defaultBlockParam:(t="latest")=>t,returnFullTxObjectParam:(t=!1)=>t,blockNumberToHex:t=>Number.isInteger(t)?`0x${t.toString(16)}`:t};class E{constructor(e){this.communicator=e,this.call=this.buildRequest({call:c.eth_call,formatters:[null,h.defaultBlockParam]}),this.getBalance=this.buildRequest({call:c.eth_getBalance,formatters:[null,h.defaultBlockParam]}),this.getCode=this.buildRequest({call:c.eth_getCode,formatters:[null,h.defaultBlockParam]}),this.getStorageAt=this.buildRequest({call:c.eth_getStorageAt,formatters:[null,h.blockNumberToHex,h.defaultBlockParam]}),this.getPastLogs=this.buildRequest({call:c.eth_getLogs}),this.getBlockByHash=this.buildRequest({call:c.eth_getBlockByHash,formatters:[null,h.returnFullTxObjectParam]}),this.getBlockByNumber=this.buildRequest({call:c.eth_getBlockByNumber,formatters:[h.blockNumberToHex,h.returnFullTxObjectParam]}),this.getTransactionByHash=this.buildRequest({call:c.eth_getTransactionByHash}),this.getTransactionReceipt=this.buildRequest({call:c.eth_getTransactionReceipt}),this.getTransactionCount=this.buildRequest({call:c.eth_getTransactionCount,formatters:[null,h.defaultBlockParam]}),this.getGasPrice=this.buildRequest({call:c.eth_gasPrice}),this.getEstimateGas=s=>this.buildRequest({call:c.eth_estimateGas})([s]),this.setSafeSettings=this.buildRequest({call:c.safe_setSettings})}buildRequest(e){const{call:s,formatters:a}=e;return async n=>{a&&Array.isArray(n)&&a.forEach((l,u)=>{l&&(n[u]=l(n[u]))});const i={call:s,params:n||[]};return(await this.communicator.send(r.rpcCall,i)).data}}}const A="0x1626ba7e",x="0x20c13b0b",f=4001;class d extends Error{constructor(e,s,a){super(e),this.code=s,this.data=a,Object.setPrototypeOf(this,d.prototype)}}class S{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 d("Permissions request is invalid",f);try{return(await this.communicator.send(r.wallet_requestPermissions,e)).data}catch{throw new d("Permissions rejected",f)}}isPermissionRequestValid(e){return e.every(s=>typeof s=="object"?Object.keys(s).every(a=>!!Object.values(m).includes(a)):!1)}}const w=(t,e)=>e.some(s=>s.parentCapability===t),O=()=>(t,e,s)=>{const a=s.value;return s.value=async function(){const n=new S(this.communicator);let i=await n.getPermissions();if(w(e,i)||(i=await n.requestPermissions([{[e]:{}}])),!w(e,i))throw new d("Permissions rejected",f);return a.apply(this)},s};var V=function(t,e,s,a){var n=arguments.length,i=n<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,s):a,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,s,a);else for(var l=t.length-1;l>=0;l--)(o=t[l])&&(i=(n<3?o(i):n>3?o(e,s,i):o(e,s))||i);return n>3&&i&&Object.defineProperty(e,s,i),i};class _{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(e,s="0x"){const a=await this.getInfo(),n=y({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:[e,s]}),i={call:c.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()===A}catch{return!1}}async check1271SignatureBytes(e,s="0x"){const a=await this.getInfo(),n=y({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:[e,s]}),i={call:c.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()===x}catch{return!1}}calculateMessageHash(e){return T(e)}calculateTypedMessageHash(e){const s=typeof e.domain.chainId=="object"?e.domain.chainId.toNumber():Number(e.domain.chainId);let a=e.primaryType;if(!a){const n=Object.values(e.types),i=Object.keys(e.types).filter(o=>n.every(l=>l.every(({type:u})=>u.replace("[","").replace("]","")!==o)));if(i.length===0||i.length>1)throw new Error("Please specify primaryType");a=i[0]}return k({message:e.message,domain:{...e.domain,chainId:s,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,s="0x"){let a;if(typeof e=="string"&&(a=async()=>{const n=this.calculateMessageHash(e);return await this.isMessageHashSigned(n,s)}),b(e)&&(a=async()=>{const n=this.calculateTypedMessageHash(e);return await this.isMessageHashSigned(n,s)}),a)return await a();throw new Error("Invalid message type")}async isMessageHashSigned(e,s="0x"){const a=[this.check1271Signature.bind(this),this.check1271SignatureBytes.bind(this)];for(const n of a)if(await n(e,s))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}}V([O()],_.prototype,"requestAddressBook",null);class N{constructor(e={}){const{allowedDomains:s=null,debug:a=!1}=e;this.communicator=new R(s,a),this.eth=new E(this.communicator),this.txs=new H(this.communicator),this.safe=new _(this.communicator),this.wallet=new S(this.communicator)}}export{g as MessageFormatter,r as Methods,c as RPC_CALLS,m as RestrictedMethods,N as default,I as getSDKVersion,b as isObjectEIP712TypedData};
1
+ import"./index-BR_6qS4k.js";import{ch as y,d0 as T,d2 as k}from"./index-yQSvDbVa.js";const I=()=>"9.1.0",q=t=>t.toString(16).padStart(2,"0"),v=t=>{const e=new Uint8Array(t/2);return window.crypto.getRandomValues(e),Array.from(e,q).join("")},C=()=>typeof window<"u"?v(10):new Date().getTime().toString(36);class g{}g.makeRequest=(t,e)=>({id:C(),method:t,params:e,env:{sdkVersion:I()}});g.makeResponse=(t,e,s)=>({id:t,success:!0,version:s,data:e});g.makeErrorResponse=(t,e,s)=>({id:t,success:!1,error:e,version:s});var r;(function(t){t.sendTransactions="sendTransactions",t.rpcCall="rpcCall",t.getChainInfo="getChainInfo",t.getSafeInfo="getSafeInfo",t.getTxBySafeTxHash="getTxBySafeTxHash",t.getSafeBalances="getSafeBalances",t.signMessage="signMessage",t.signTypedMessage="signTypedMessage",t.getEnvironmentInfo="getEnvironmentInfo",t.getOffChainSignature="getOffChainSignature",t.requestAddressBook="requestAddressBook",t.wallet_getPermissions="wallet_getPermissions",t.wallet_requestPermissions="wallet_requestPermissions"})(r||(r={}));var m;(function(t){t.requestAddressBook="requestAddressBook"})(m||(m={}));class R{constructor(e=null,s=!1){this.allowedOrigins=null,this.callbacks=new Map,this.debugMode=!1,this.isServer=typeof window>"u",this.isValidMessage=({origin:a,data:n,source:i})=>{const o=!n,l=!this.isServer&&i===window.parent,u=typeof n.version<"u"&&parseInt(n.version.split(".")[0]),B=typeof u=="number"&&u>=1;let p=!0;return Array.isArray(this.allowedOrigins)&&(p=this.allowedOrigins.find(P=>P.test(a))!==void 0),!o&&l&&B&&p},this.logIncomingMessage=a=>{console.info(`Safe Apps SDK v1: A message was received from origin ${a.origin}. `,a.data)},this.onParentMessage=a=>{this.isValidMessage(a)&&(this.debugMode&&this.logIncomingMessage(a),this.handleIncomingMessage(a.data))},this.handleIncomingMessage=a=>{const{id:n}=a,i=this.callbacks.get(n);i&&(i(a),this.callbacks.delete(n))},this.send=(a,n)=>{const i=g.makeRequest(a,n);if(this.isServer)throw new Error("Window doesn't exist");return window.parent.postMessage(i,"*"),new Promise((o,l)=>{this.callbacks.set(i.id,u=>{if(!u.success){l(new Error(u.error));return}o(u)})})},this.allowedOrigins=e,this.debugMode=s,this.isServer||window.addEventListener("message",this.onParentMessage)}}const b=t=>typeof t=="object"&&t!=null&&"domain"in t&&"types"in t&&"message"in t;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 s={message:e};return(await this.communicator.send(r.signMessage,s)).data}async signTypedMessage(e){if(!b(e))throw new Error("Invalid typed data");return(await this.communicator.send(r.signTypedMessage,{typedData:e})).data}async send({txs:e,params:s}){if(!e||!e.length)throw new Error("No transactions were passed");const a={txs:e,params:s};return(await this.communicator.send(r.sendTransactions,a)).data}}const c={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"},h={defaultBlockParam:(t="latest")=>t,returnFullTxObjectParam:(t=!1)=>t,blockNumberToHex:t=>Number.isInteger(t)?`0x${t.toString(16)}`:t};class E{constructor(e){this.communicator=e,this.call=this.buildRequest({call:c.eth_call,formatters:[null,h.defaultBlockParam]}),this.getBalance=this.buildRequest({call:c.eth_getBalance,formatters:[null,h.defaultBlockParam]}),this.getCode=this.buildRequest({call:c.eth_getCode,formatters:[null,h.defaultBlockParam]}),this.getStorageAt=this.buildRequest({call:c.eth_getStorageAt,formatters:[null,h.blockNumberToHex,h.defaultBlockParam]}),this.getPastLogs=this.buildRequest({call:c.eth_getLogs}),this.getBlockByHash=this.buildRequest({call:c.eth_getBlockByHash,formatters:[null,h.returnFullTxObjectParam]}),this.getBlockByNumber=this.buildRequest({call:c.eth_getBlockByNumber,formatters:[h.blockNumberToHex,h.returnFullTxObjectParam]}),this.getTransactionByHash=this.buildRequest({call:c.eth_getTransactionByHash}),this.getTransactionReceipt=this.buildRequest({call:c.eth_getTransactionReceipt}),this.getTransactionCount=this.buildRequest({call:c.eth_getTransactionCount,formatters:[null,h.defaultBlockParam]}),this.getGasPrice=this.buildRequest({call:c.eth_gasPrice}),this.getEstimateGas=s=>this.buildRequest({call:c.eth_estimateGas})([s]),this.setSafeSettings=this.buildRequest({call:c.safe_setSettings})}buildRequest(e){const{call:s,formatters:a}=e;return async n=>{a&&Array.isArray(n)&&a.forEach((l,u)=>{l&&(n[u]=l(n[u]))});const i={call:s,params:n||[]};return(await this.communicator.send(r.rpcCall,i)).data}}}const A="0x1626ba7e",x="0x20c13b0b",f=4001;class d extends Error{constructor(e,s,a){super(e),this.code=s,this.data=a,Object.setPrototypeOf(this,d.prototype)}}class S{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 d("Permissions request is invalid",f);try{return(await this.communicator.send(r.wallet_requestPermissions,e)).data}catch{throw new d("Permissions rejected",f)}}isPermissionRequestValid(e){return e.every(s=>typeof s=="object"?Object.keys(s).every(a=>!!Object.values(m).includes(a)):!1)}}const w=(t,e)=>e.some(s=>s.parentCapability===t),O=()=>(t,e,s)=>{const a=s.value;return s.value=async function(){const n=new S(this.communicator);let i=await n.getPermissions();if(w(e,i)||(i=await n.requestPermissions([{[e]:{}}])),!w(e,i))throw new d("Permissions rejected",f);return a.apply(this)},s};var V=function(t,e,s,a){var n=arguments.length,i=n<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,s):a,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,s,a);else for(var l=t.length-1;l>=0;l--)(o=t[l])&&(i=(n<3?o(i):n>3?o(e,s,i):o(e,s))||i);return n>3&&i&&Object.defineProperty(e,s,i),i};class _{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(e,s="0x"){const a=await this.getInfo(),n=y({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:[e,s]}),i={call:c.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()===A}catch{return!1}}async check1271SignatureBytes(e,s="0x"){const a=await this.getInfo(),n=y({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:[e,s]}),i={call:c.eth_call,params:[{to:a.safeAddress,data:n},"latest"]};try{return(await this.communicator.send(r.rpcCall,i)).data.slice(0,10).toLowerCase()===x}catch{return!1}}calculateMessageHash(e){return T(e)}calculateTypedMessageHash(e){const s=typeof e.domain.chainId=="object"?e.domain.chainId.toNumber():Number(e.domain.chainId);let a=e.primaryType;if(!a){const n=Object.values(e.types),i=Object.keys(e.types).filter(o=>n.every(l=>l.every(({type:u})=>u.replace("[","").replace("]","")!==o)));if(i.length===0||i.length>1)throw new Error("Please specify primaryType");a=i[0]}return k({message:e.message,domain:{...e.domain,chainId:s,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,s="0x"){let a;if(typeof e=="string"&&(a=async()=>{const n=this.calculateMessageHash(e);return await this.isMessageHashSigned(n,s)}),b(e)&&(a=async()=>{const n=this.calculateTypedMessageHash(e);return await this.isMessageHashSigned(n,s)}),a)return await a();throw new Error("Invalid message type")}async isMessageHashSigned(e,s="0x"){const a=[this.check1271Signature.bind(this),this.check1271SignatureBytes.bind(this)];for(const n of a)if(await n(e,s))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}}V([O()],_.prototype,"requestAddressBook",null);class N{constructor(e={}){const{allowedDomains:s=null,debug:a=!1}=e;this.communicator=new R(s,a),this.eth=new E(this.communicator),this.txs=new H(this.communicator),this.safe=new _(this.communicator),this.wallet=new S(this.communicator)}}export{g as MessageFormatter,r as Methods,c as RPC_CALLS,m as RestrictedMethods,N as default,I as getSDKVersion,b as isObjectEIP712TypedData};