UNPKG

@cowprotocol/cow-sdk

Version:

<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>

3 lines (2 loc) 2.62 kB
import{C as e,_ as t,a as n,E as r}from"./index-6765c808.js";import{domain as i,hashOrder as o,packOrderUidParams as s,IntChainIdTypedDataV4Signer as a,TypedDataVersionedSigner as c,signOrder as d,signOrderCancellation as u,signOrderCancellations as l,SigningScheme as h}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";import"ethers";import"@openzeppelin/merkle-tree";import"ethers/lib/utils";import"@ethersproject/abstract-signer";import"@cowprotocol/app-data";const g=-32603,p=-32601,m=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,v=/eth_signTypedData_v3 does not exist/i,w=/RPC request failed/i,y=/provided chainid .* must match the active chainid/i,I={[r.EIP712]:h.EIP712,[r.ETHSIGN]:h.ETHSIGN};async function S(e){const{chainId:t,signer:n,order:r,signingScheme:i}=e,o=U(t);return d(o,r,n,I[i])}async function _(e){const{chainId:t,signer:n,signingScheme:r,orderUid:i}=e,o=U(t);return u(o,i,n,I[r])}async function E(e){const{chainId:t,signer:n,signingScheme:r,orderUids:i}=e,o=U(t);return l(o,i,n,I[r])}async function T(n,i,o,s="v4"){var d;const u="eth_sign"===s?r.ETHSIGN:r.EIP712;let l,h=null;try{switch(s){case"default":case"v3":l=new c(o);break;case"int_v4":l=new a(o);break;default:l=o}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{h=await i(t({},n,{signer:l,signingScheme:u}))}catch(e){if(void 0===(I=e).code&&void 0===I.message)throw console.error(e),e;const t=[m,w].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==p&&!t){if(y.test(e.message))return T(n,i,o,"int_v4");if(e.code===g)return T(n,i,o,"eth_sign");if(f.test(e.message))return T(n,i,o,"v3");if(v.test(e.message))return T(n,i,o,"eth_sign");throw console.error(e),e}switch(s){case"v4":return T(n,i,o,"default");case"default":return T(n,i,o,"v3");case"v3":return T(n,i,o,"eth_sign");default:throw e}}var I;const S=null==(d=h)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:u}}async function b(e,t,n){return T({order:e,chainId:t},S,n)}async function k(e,t,n){return T({orderUid:e,chainId:t},_,n)}async function x(e,t,n){return T({orderUids:e,chainId:t},E,n)}function U(t){const r=n[t];if(!r)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,r)}async function C(e,n,r){const i=await U(e),a=o(i,n);return{orderId:s(t({},r,{orderDigest:a,validTo:n.validTo})),orderDigest:a}}export{C as generateOrderId,U as getDomain,b as signOrder,k as signOrderCancellation,x as signOrderCancellations}; //# sourceMappingURL=utils-6c0b6c4e.js.map