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) 3.22 kB
var e=require("@cowprotocol/contracts"),r=require("./index.js");require("cross-fetch/polyfill"),require("limiter"),require("exponential-backoff"),require("graphql-request"),require("ethers"),require("@openzeppelin/merkle-tree"),require("ethers/lib/utils"),require("@ethersproject/abstract-signer"),require("@cowprotocol/app-data");const t=function(n,i,o,l="v4"){try{let f;function m(e){if(f)return e;const r=v?.data;return{signature:r?.toString()||"",signingScheme:p}}const p="eth_sign"===l?r.EcdsaSigningScheme.ETHSIGN:r.EcdsaSigningScheme.EIP712;let S,v=null;try{switch(l){case"default":case"v3":S=new e.TypedDataVersionedSigner(o);break;case"int_v4":S=new e.IntChainIdTypedDataV4Signer(o);break;default:S=o}}catch(w){throw console.error("Wallet not supported:",w),new r.CowError("Wallet not supported")}const P=function(e,r){try{var t=Promise.resolve(i({...n,signer:S,signingScheme:p})).then(function(e){v=e})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){if(void 0===(r=e).code&&void 0===r.message)throw console.error(e),e;var r;const m=[a,h].some(r=>[e.message,e.toString()].some(e=>r.test(e)));if(e.code!==c&&!m){if(g.test(e.message)){const e=t(n,i,o,"int_v4");return f=1,e}if(e.code===s){const e=t(n,i,o,"eth_sign");return f=1,e}if(d.test(e.message)){const e=t(n,i,o,"v3");return f=1,e}if(u.test(e.message)){const e=t(n,i,o,"eth_sign");return f=1,e}throw console.error(e),e}switch(l){case"v4":const r=t(n,i,o,"default");return f=1,r;case"default":const s=t(n,i,o,"v3");return f=1,s;case"v3":const c=t(n,i,o,"eth_sign");return f=1,c;default:throw e}});return Promise.resolve(P&&P.then?P.then(m):m(P))}catch(E){return Promise.reject(E)}},n=function(r){try{const{chainId:t,signer:n,signingScheme:i,orderUids:o}=r,s=m(t);return Promise.resolve(e.signOrderCancellations(s,o,n,l[i]))}catch(e){return Promise.reject(e)}},i=function(r){try{const{chainId:t,signer:n,signingScheme:i,orderUid:o}=r,s=m(t);return Promise.resolve(e.signOrderCancellation(s,o,n,l[i]))}catch(e){return Promise.reject(e)}},o=function(r){try{const{chainId:t,signer:n,order:i,signingScheme:o}=r,s=m(t);return Promise.resolve(e.signOrder(s,i,n,l[o]))}catch(e){return Promise.reject(e)}},s=-32603,c=-32601,a=/Method not found/i,d=/eth_signTypedData_v4 does not exist/i,u=/eth_signTypedData_v3 does not exist/i,h=/RPC request failed/i,g=/provided chainid .* must match the active chainid/i,l={[r.EcdsaSigningScheme.EIP712]:e.SigningScheme.EIP712,[r.EcdsaSigningScheme.ETHSIGN]:e.SigningScheme.ETHSIGN};function m(t){const n=r.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[t];if(!n)throw new r.CowError("Unsupported network. Settlement contract is not deployed");return e.domain(t,n)}exports.generateOrderId=function(r,t,n){try{return Promise.resolve(m(r)).then(function(r){const i=e.hashOrder(r,t);return{orderId:e.packOrderUidParams({...n,orderDigest:i,validTo:t.validTo}),orderDigest:i}})}catch(e){return Promise.reject(e)}},exports.getDomain=m,exports.signOrder=function(e,r,n){return t({order:e,chainId:r},o,n)},exports.signOrderCancellation=function(e,r,n){return t({orderUid:e,chainId:r},i,n)},exports.signOrderCancellations=function(e,r,i){return t({orderUids:e,chainId:r},n,i)}; //# sourceMappingURL=utils-80ccd45c.js.map