@cowprotocol/cow-sdk 5.9.0 → 5.10.0-RC.0

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 (35) hide show
  1. package/README.md +44 -3
  2. package/dist/README.md +44 -3
  3. package/dist/{index-d7269169.js → index-f4e68213.js} +3 -3
  4. package/dist/index-f4e68213.js.map +1 -0
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.modern.mjs +1 -1
  8. package/dist/index.module.js +2 -2
  9. package/dist/index.module.js.map +1 -1
  10. package/dist/order-book/generated/index.d.ts +0 -1
  11. package/dist/order-book/generated/models/Auction.d.ts +1 -10
  12. package/dist/order-book/generated/models/AuctionPrices.d.ts +1 -4
  13. package/dist/order-book/generated/models/CompetitionOrderStatus.d.ts +4 -2
  14. package/dist/order-book/generated/models/ExecutedProtocolFee.d.ts +0 -6
  15. package/dist/order-book/generated/models/OnchainOrderData.d.ts +3 -9
  16. package/dist/order-book/generated/models/OrderCreation.d.ts +4 -12
  17. package/dist/order-book/generated/models/OrderMetaData.d.ts +20 -17
  18. package/dist/order-book/generated/models/OrderParameters.d.ts +1 -2
  19. package/dist/order-book/generated/models/OrderQuoteRequest.d.ts +11 -7
  20. package/dist/order-book/generated/models/OrderQuoteResponse.d.ts +1 -2
  21. package/dist/order-book/generated/models/OrderQuoteSide.d.ts +1 -2
  22. package/dist/order-book/generated/models/PriceQuality.d.ts +4 -3
  23. package/dist/order-book/generated/models/SolverSettlement.d.ts +6 -1
  24. package/dist/order-book/generated/models/UID.d.ts +4 -3
  25. package/dist/package.json +2 -2
  26. package/dist/schemas/trading/SwapAdvancedSettings.ts +2 -2
  27. package/dist/{utils-7f502e5c.js → utils-43555783.js} +1 -1
  28. package/dist/{utils-7f502e5c.js.map → utils-43555783.js.map} +1 -1
  29. package/dist/{utils-be09ebbf.js → utils-9d1e9d0e.js} +2 -2
  30. package/dist/{utils-be09ebbf.js.map → utils-9d1e9d0e.js.map} +1 -1
  31. package/dist/{utils-83038876.js → utils-dc9c9d10.js} +1 -1
  32. package/dist/{utils-83038876.js.map → utils-dc9c9d10.js.map} +1 -1
  33. package/package.json +2 -2
  34. package/dist/index-d7269169.js.map +0 -1
  35. package/dist/order-book/generated/models/ProtocolAppData.d.ts +0 -1
@@ -40,7 +40,6 @@ export type { PreSignature } from './models/PreSignature';
40
40
  export { PriceEstimationError } from './models/PriceEstimationError';
41
41
  export type { PriceImprovement } from './models/PriceImprovement';
42
42
  export { PriceQuality } from './models/PriceQuality';
43
- export type { ProtocolAppData } from './models/ProtocolAppData';
44
43
  export type { Quote } from './models/Quote';
45
44
  export { SellTokenSource } from './models/SellTokenSource';
46
45
  export type { Signature } from './models/Signature';
@@ -12,19 +12,10 @@ export type Auction = {
12
12
  */
13
13
  id?: number;
14
14
  /**
15
- * The block number for the auction. Orders and prices are guaranteed to be valid on this
16
- * block. Proposed settlements should be valid for this block as well.
15
+ * The block number for the auction. Orders and prices are guaranteed to be valid on this block. Proposed settlements should be valid for this block as well.
17
16
  *
18
17
  */
19
18
  block?: number;
20
- /**
21
- * The latest block on which a settlement has been processed.
22
- *
23
- * **NOTE**: Under certain conditions it is possible for a settlement to have been mined as
24
- * part of `block` but not have yet been processed.
25
- *
26
- */
27
- latestSettlementBlock?: number;
28
19
  /**
29
20
  * The solvable orders included in the auction.
30
21
  *
@@ -1,9 +1,6 @@
1
1
  import type { BigUint } from './BigUint';
2
2
  /**
3
- * The reference prices for all traded tokens in the auction as a mapping from token
4
- * addresses to a price denominated in native token (i.e. 1e18 represents a token that
5
- * trades one to one with the native token). These prices are used for solution competition
6
- * for computing surplus and converting fees to native token.
3
+ * The reference prices for all traded tokens in the auction as a mapping from token addresses to a price denominated in native token (i.e. 1e18 represents a token that trades one to one with the native token). These prices are used for solution competition for computing surplus and converting fees to native token.
7
4
  *
8
5
  */
9
6
  export type AuctionPrices = Record<string, BigUint>;
@@ -2,9 +2,11 @@ import type { ExecutedAmounts } from './ExecutedAmounts';
2
2
  export type CompetitionOrderStatus = {
3
3
  type: CompetitionOrderStatus.type;
4
4
  /**
5
- * A list of solvers who participated in the latest competition, sorted by score in ascending order, where the last element is the winner.
6
- * The presence of executed amounts defines whether the solver provided a solution for the desired order.
5
+ * A list of solvers who participated in the latest competition, sorted
6
+ * by score in ascending order, where the last element is the winner.
7
7
  *
8
+ * The presence of executed amounts defines whether the solver provided
9
+ * a solution for the desired order.
8
10
  */
9
11
  value?: Array<{
10
12
  /**
@@ -3,12 +3,6 @@ import type { FeePolicy } from './FeePolicy';
3
3
  import type { TokenAmount } from './TokenAmount';
4
4
  export type ExecutedProtocolFee = {
5
5
  policy?: FeePolicy;
6
- /**
7
- * Fee amount taken
8
- */
9
6
  amount?: TokenAmount;
10
- /**
11
- * The token in which the fee is taken
12
- */
13
7
  token?: Address;
14
8
  };
@@ -1,25 +1,19 @@
1
1
  import type { Address } from './Address';
2
2
  export type OnchainOrderData = {
3
3
  /**
4
- * If orders are placed as on-chain orders, the owner of the order might
5
- * be a smart contract, but not the user placing the order. The
6
- * actual user will be provided in this field.
4
+ * If orders are placed as on-chain orders, the owner of the order might be a smart contract, but not the user placing the order. The actual user will be provided in this field.
7
5
  *
8
6
  */
9
7
  sender: Address;
10
8
  /**
11
- * Describes the error, if the order placement was not successful. This could
12
- * happen, for example, if the `validTo` is too high, or no valid quote was
13
- * found or generated.
9
+ * Describes the error, if the order placement was not successful. This could happen, for example, if the `validTo` is too high, or no valid quote was found or generated.
14
10
  *
15
11
  */
16
12
  placementError?: OnchainOrderData.placementError;
17
13
  };
18
14
  export declare namespace OnchainOrderData {
19
15
  /**
20
- * Describes the error, if the order placement was not successful. This could
21
- * happen, for example, if the `validTo` is too high, or no valid quote was
22
- * found or generated.
16
+ * Describes the error, if the order placement was not successful. This could happen, for example, if the `validTo` is too high, or no valid quote was found or generated.
23
17
  *
24
18
  */
25
19
  enum placementError {
@@ -58,30 +58,22 @@ export type OrderCreation = {
58
58
  signingScheme: SigningScheme;
59
59
  signature: Signature;
60
60
  /**
61
- * If set, the backend enforces that this address matches what is decoded as the *signer* of
62
- * the signature. This helps catch errors with invalid signature encodings as the backend
63
- * might otherwise silently work with an unexpected address that for example does not have
64
- * any balance.
61
+ * If set, the backend enforces that this address matches what is decoded as the *signer* of the signature. This helps catch errors with invalid signature encodings as the backend might otherwise silently work with an unexpected address that for example does not have any balance.
65
62
  *
66
63
  */
67
64
  from?: Address | null;
68
65
  /**
69
- * Orders can optionally include a quote ID. This way the order can be linked to a quote
70
- * and enable providing more metadata when analysing order slippage.
66
+ * Orders can optionally include a quote ID. This way the order can be linked to a quote and enable providing more metadata when analysing order slippage.
71
67
  *
72
68
  */
73
69
  quoteId?: number | null;
74
70
  /**
75
- * This field comes in two forms for backward compatibility. The hash form will eventually
76
- * stop being accepted.
71
+ * This field comes in two forms for backward compatibility. The hash form will eventually stop being accepted.
77
72
  *
78
73
  */
79
74
  appData: (AppData | AppDataHash);
80
75
  /**
81
- * May be set for debugging purposes. If set, this field is compared to what the backend
82
- * internally calculates as the app data hash based on the contents of `appData`. If the
83
- * hash does not match, an error is returned. If this field is set, then `appData` **MUST** be
84
- * a string encoding of a JSON object.
76
+ * May be set for debugging purposes. If set, this field is compared to what the backend internally calculates as the app data hash based on the contents of `appData`. If the hash does not match, an error is returned. If this field is set, then `appData` **MUST** be a string encoding of a JSON object.
85
77
  *
86
78
  */
87
79
  appDataHash?: AppDataHash | null;
@@ -7,8 +7,7 @@ import type { OrderStatus } from './OrderStatus';
7
7
  import type { TokenAmount } from './TokenAmount';
8
8
  import type { UID } from './UID';
9
9
  /**
10
- * Extra order data that is returned to users when querying orders but not provided by users
11
- * when creating orders.
10
+ * Extra order data that is returned to users when querying orders but not provided by users when creating orders.
12
11
  *
13
12
  */
14
13
  export type OrderMetaData = {
@@ -57,40 +56,44 @@ export type OrderMetaData = {
57
56
  */
58
57
  fullFeeAmount?: TokenAmount;
59
58
  /**
60
- * Liquidity orders are functionally the same as normal smart contract orders but are not
61
- * placed with the intent of actively getting traded. Instead they facilitate the
62
- * trade of normal orders by allowing them to be matched against liquidity orders which
63
- * uses less gas and can have better prices than external liquidity.
64
- *
65
- * As such liquidity orders will only be used in order to improve settlement of normal
66
- * orders. They should not be expected to be traded otherwise and should not expect to get
67
- * surplus.
59
+ * Liquidity orders are functionally the same as normal smart contract
60
+ * orders but are not placed with the intent of actively getting
61
+ * traded. Instead they facilitate the trade of normal orders by
62
+ * allowing them to be matched against liquidity orders which uses less
63
+ * gas and can have better prices than external liquidity.
68
64
  *
65
+ * As such liquidity orders will only be used in order to improve
66
+ * settlement of normal orders. They should not be expected to be
67
+ * traded otherwise and should not expect to get surplus.
69
68
  */
70
69
  isLiquidityOrder?: boolean;
71
70
  ethflowData?: EthflowData;
72
71
  /**
73
72
  * This represents the actual trader of an on-chain order.
74
- *
75
73
  * ### ethflow orders
76
- *
77
74
  * In this case, the `owner` would be the `EthFlow` contract and *not* the actual trader.
78
75
  *
79
76
  */
80
77
  onchainUser?: Address;
81
78
  /**
82
- * There is some data only available for orders that are placed on-chain. This data
83
- * can be found in this object.
79
+ * There is some data only available for orders that are placed on-chain. This data can be found in this object.
84
80
  *
85
81
  */
86
82
  onchainOrderData?: OnchainOrderData;
87
83
  /**
88
84
  * Surplus fee that the limit order was executed with.
89
85
  */
90
- executedSurplusFee?: BigUint | null;
86
+ executedSurplusFee?: BigUint;
87
+ /**
88
+ * Total fee charged for execution of the order. Contains network fee and protocol fees.
89
+ */
90
+ executedFee?: BigUint;
91
+ /**
92
+ * Token the executed fee was captured in.
93
+ */
94
+ executedFeeToken?: Address;
91
95
  /**
92
- * Full `appData`, which the contract-level `appData` is a hash of. See `OrderCreation`
93
- * for more information.
96
+ * Full `appData`, which the contract-level `appData` is a hash of. See `OrderCreation` for more information.
94
97
  *
95
98
  */
96
99
  fullAppData?: string | null;
@@ -18,8 +18,7 @@ export type OrderParameters = {
18
18
  */
19
19
  buyToken: Address;
20
20
  /**
21
- * An optional Ethereum address to receive the proceeds of the trade instead
22
- * of the owner (i.e. the order signer).
21
+ * An optional Ethereum address to receive the proceeds of the trade instead of the owner (i.e. the order signer).
23
22
  *
24
23
  */
25
24
  receiver?: Address | null;
@@ -27,17 +27,22 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
27
27
  receiver?: Address | null;
28
28
  /**
29
29
  * AppData which will be assigned to the order.
30
- * Expects either a string JSON doc as defined on [AppData](https://github.com/cowprotocol/app-data) or a
31
- * hex encoded string for backwards compatibility.
32
- * When the first format is used, it's possible to provide the derived appDataHash field.
33
30
  *
31
+ * Expects either a string JSON doc as defined on
32
+ * [AppData](https://github.com/cowprotocol/app-data) or a hex
33
+ * encoded string for backwards compatibility.
34
+ *
35
+ * When the first format is used, it's possible to provide the
36
+ * derived appDataHash field.
34
37
  */
35
38
  appData?: (AppData | AppDataHash);
36
39
  /**
37
40
  * The hash of the stringified JSON appData doc.
38
- * If present, `appData` field must be set with the aforementioned data where this hash is derived from.
39
- * In case they differ, the call will fail.
40
41
  *
42
+ * If present, `appData` field must be set with the aforementioned
43
+ * data where this hash is derived from.
44
+ *
45
+ * In case they differ, the call will fail.
41
46
  */
42
47
  appDataHash?: AppDataHash;
43
48
  sellTokenBalance?: SellTokenSource;
@@ -46,8 +51,7 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
46
51
  priceQuality?: PriceQuality;
47
52
  signingScheme?: SigningScheme;
48
53
  /**
49
- * Flag to signal whether the order is intended for on-chain order placement. Only valid
50
- * for non ECDSA-signed orders."
54
+ * Flag to signal whether the order is intended for on-chain order placement. Only valid for non ECDSA-signed orders."
51
55
  *
52
56
  */
53
57
  onchainOrder?: any;
@@ -15,8 +15,7 @@ export type OrderQuoteResponse = {
15
15
  */
16
16
  expiration: string;
17
17
  /**
18
- * Quote ID linked to a quote to enable providing more metadata when analysing
19
- * order slippage.
18
+ * Quote ID linked to a quote to enable providing more metadata when analysing order slippage.
20
19
  *
21
20
  */
22
21
  id?: number;
@@ -7,8 +7,7 @@ import type { TokenAmount } from './TokenAmount';
7
7
  export type OrderQuoteSide = ({
8
8
  kind: OrderQuoteSideKindSell;
9
9
  /**
10
- * The total amount that is available for the order. From this value, the fee
11
- * is deducted and the buy amount is calculated.
10
+ * The total amount that is available for the order. From this value, the fee is deducted and the buy amount is calculated.
12
11
  *
13
12
  */
14
13
  sellAmountBeforeFee: TokenAmount;
@@ -3,10 +3,11 @@
3
3
  *
4
4
  * Fast: The price estimate is chosen among the fastest N price estimates.
5
5
  * Optimal: The price estimate is chosen among all price estimates.
6
- * Verified: The price estimate is chosen among all verified/simulated price estimates.
7
- *
8
- * **NOTE**: Orders are supposed to be created from `verified` or `optimal` price estimates.
6
+ * Verified: The price estimate is chosen among all verified/simulated
7
+ * price estimates.
9
8
  *
9
+ * **NOTE**: Orders are supposed to be created from `verified` or `optimal`
10
+ * price estimates.
10
11
  */
11
12
  export declare enum PriceQuality {
12
13
  FAST = "fast",
@@ -7,8 +7,9 @@ export type SolverSettlement = {
7
7
  solver?: string;
8
8
  /**
9
9
  * The address used by the solver to execute the settlement on-chain.
10
- * This field is missing for old settlements, the zero address has been used instead.
11
10
  *
11
+ * This field is missing for old settlements, the zero address has been
12
+ * used instead.
12
13
  */
13
14
  solverAddress?: string;
14
15
  objective?: {
@@ -39,4 +40,8 @@ export type SolverSettlement = {
39
40
  id?: UID;
40
41
  executedAmount?: BigUint;
41
42
  }>;
43
+ /**
44
+ * whether the solution is a winner (received the right to get executed) or not
45
+ */
46
+ isWinner?: boolean;
42
47
  };
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Unique identifier for the order: 56 bytes encoded as hex with `0x` prefix.
3
- * Bytes 0..32 are the order digest, bytes 30..52 the owner address and bytes
4
- * 52..56 the expiry (`validTo`) as a `uint32` unix epoch timestamp.
2
+ * Unique identifier for the order: 56 bytes encoded as hex with `0x`
3
+ * prefix.
5
4
  *
5
+ * Bytes 0..32 are the order digest, bytes 30..52 the owner address and
6
+ * bytes 52..56 the expiry (`validTo`) as a `uint32` unix epoch timestamp.
6
7
  */
7
8
  export type UID = string;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/cow-sdk",
3
- "version": "5.9.0",
3
+ "version": "5.10.0-RC.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "files": [
6
6
  "/dist"
@@ -27,7 +27,7 @@
27
27
  "prepare": "npm run build",
28
28
  "prepublishOnly": "npm test && npm run lint",
29
29
  "graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
30
- "swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.285.0/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false",
30
+ "swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.291.0/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false",
31
31
  "typechain:codegen": "typechain --target ethers-v5 --out-dir ./src/common/generated './abi/*.json'",
32
32
  "trading:generateSchemas": "ts-node scripts/generateTradingSchemas.ts"
33
33
  },
@@ -44,11 +44,11 @@ export default {
44
44
  "description": "32 bytes encoded as hex with `0x` prefix. It's expected to be the hash of the stringified JSON object representing the `appData`."
45
45
  }
46
46
  ],
47
- "description": "AppData which will be assigned to the order. Expects either a string JSON doc as defined on [AppData](https://github.com/cowprotocol/app-data) or a hex encoded string for backwards compatibility. When the first format is used, it's possible to provide the derived appDataHash field."
47
+ "description": "AppData which will be assigned to the order.\n\nExpects either a string JSON doc as defined on [AppData](https://github.com/cowprotocol/app-data) or a hex encoded string for backwards compatibility.\n\nWhen the first format is used, it's possible to provide the derived appDataHash field."
48
48
  },
49
49
  "appDataHash": {
50
50
  "type": "string",
51
- "description": "The hash of the stringified JSON appData doc. If present, `appData` field must be set with the aforementioned data where this hash is derived from. In case they differ, the call will fail."
51
+ "description": "The hash of the stringified JSON appData doc.\n\nIf present, `appData` field must be set with the aforementioned data where this hash is derived from.\n\nIn case they differ, the call will fail."
52
52
  },
53
53
  "sellTokenBalance": {
54
54
  "type": "string",
@@ -1,2 +1,2 @@
1
1
  import{hashOrder as e,packOrderUidParams as t,IntChainIdTypedDataV4Signer as r,TypedDataVersionedSigner as n,signOrderCancellations as o,signOrderCancellation as i,signOrder as s,SigningScheme as c,domain as a}from"@cowprotocol/contracts";import{EcdsaSigningScheme as d,CowError as u,COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS as h}from"./index.module.js";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 l=function(r,n,o){try{return Promise.resolve(k(r)).then(function(r){const i=e(r,n);return{orderId:t({...o,orderDigest:i,validTo:n.validTo}),orderDigest:i}})}catch(e){return Promise.reject(e)}},m=function(e,t,r){return p({orderUids:e,chainId:t},v,r)},f=function(e,t,r){return p({orderUid:e,chainId:t},P,r)},g=function(e,t,r){return p({order:e,chainId:t},w,r)},p=function(e,t,o,i="v4"){try{let c;function s(e){if(c)return e;const t=l?.data;return{signature:t?.toString()||"",signingScheme:a}}const a="eth_sign"===i?d.ETHSIGN:d.EIP712;let h,l=null;try{switch(i){case"default":case"v3":h=new n(o);break;case"int_v4":h=new r(o);break;default:h=o}}catch(f){throw console.error("Wallet not supported:",f),new u("Wallet not supported")}const m=function(r,n){try{var o=Promise.resolve(t({...e,signer:h,signingScheme:a})).then(function(e){l=e})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(r){if(void 0===(n=r).code&&void 0===n.message)throw console.error(r),r;var n;const s=[S,T].some(e=>[r.message,r.toString()].some(t=>e.test(t)));if(r.code!==y&&!s){if(E.test(r.message)){const r=p(e,t,o,"int_v4");return c=1,r}if(r.code===I){const r=p(e,t,o,"eth_sign");return c=1,r}if(_.test(r.message)){const r=p(e,t,o,"v3");return c=1,r}if(j.test(r.message)){const r=p(e,t,o,"eth_sign");return c=1,r}throw console.error(r),r}switch(i){case"v4":const n=p(e,t,o,"default");return c=1,n;case"default":const i=p(e,t,o,"v3");return c=1,i;case"v3":const s=p(e,t,o,"eth_sign");return c=1,s;default:throw r}});return Promise.resolve(m&&m.then?m.then(s):s(m))}catch(g){return Promise.reject(g)}},v=function(e){try{const{chainId:t,signer:r,signingScheme:n,orderUids:i}=e,s=k(t);return Promise.resolve(o(s,i,r,b[n]))}catch(e){return Promise.reject(e)}},P=function(e){try{const{chainId:t,signer:r,signingScheme:n,orderUid:o}=e,s=k(t);return Promise.resolve(i(s,o,r,b[n]))}catch(e){return Promise.reject(e)}},w=function(e){try{const{chainId:t,signer:r,order:n,signingScheme:o}=e,i=k(t);return Promise.resolve(s(i,n,r,b[o]))}catch(e){return Promise.reject(e)}},I=-32603,y=-32601,S=/Method not found/i,_=/eth_signTypedData_v4 does not exist/i,j=/eth_signTypedData_v3 does not exist/i,T=/RPC request failed/i,E=/provided chainid .* must match the active chainid/i,b={[d.EIP712]:c.EIP712,[d.ETHSIGN]:c.ETHSIGN};function k(e){const t=h[e];if(!t)throw new u("Unsupported network. Settlement contract is not deployed");return a(e,t)}export{l as generateOrderId,k as getDomain,g as signOrder,f as signOrderCancellation,m as signOrderCancellations};
2
- //# sourceMappingURL=utils-7f502e5c.js.map
2
+ //# sourceMappingURL=utils-43555783.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-7f502e5c.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n Order,\n OrderUidParams,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n hashOrder,\n packOrderUidParams,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SignOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SignOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch wallet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SignOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SignOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as unknown as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SignOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUid } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderUid, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SignOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n * @param {string} orderUid The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderUid: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUid, chainId }, _signOrderCancellation, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellations with the signing scheme encoded\n * into the signature.\n *\n * @param {string[]} orderUids The unique identifiers of the orders being cancelled.\n * @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.\n * @param {Signer} signer The owner that had placed the orders used to sign.\n * @returns {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\n/**\n * Returns the TypedDataDomain used for signing for the specified chainId.\n * @param {SupportedChainId} chainId The chain Id\n * @return {*} The TypedDataDomain for the specified chainId.\n * @throws {CowError} If the chainId is not supported.\n */\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n\n/**\n * Generate a deterministic order ID for the specified order.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Order} order order to sign\n * @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.\n */\nexport async function generateOrderId(\n chainId: SupportedChainId,\n order: Order,\n params: Pick<OrderUidParams, 'owner'>\n): Promise<{ orderId: string; orderDigest: string }> {\n const domain = await getDomain(chainId)\n const orderDigest = hashOrder(domain, order)\n // Generate the orderId from owner, orderDigest, and max validTo\n const orderId = packOrderUidParams({\n ...params,\n orderDigest,\n // Different validTo when signing because EthFlow contract expects it to be max for all orders\n validTo: order.validTo,\n })\n\n return { orderId, orderDigest }\n}\n"],"names":["generateOrderId","chainId","order","params","Promise","resolve","getDomain","then","domain","orderDigest","hashOrder","orderId","packOrderUidParams","validTo","e","reject","signOrderCancellations","orderUids","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderUid","_signOrderCancellation","signOrder","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","console","error","CowError","_temp","_signFn","_catch","undefined","code","message","regexErrorCheck","METHOD_NOT_FOUND_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","some","regex","msg","test","METHOD_NOT_FOUND_ERROR_CODE","METAMASK_STRING_CHAINID_REGEX","_signPayload5","METAMASK_SIGNATURE_ERROR_CODE","_signPayload6","V4_ERROR_MSG_REGEX","_signPayload7","V3_ERROR_MSG_REGEX","_signPayload8","_signPayload2","_signPayload3","_signPayload4","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"klBAmPsB,MAAAA,EAAeA,SACnCC,EACAC,EACAC,GAAqC,IAAAC,OAAAA,QAAAC,QAEhBC,EAAUL,IAAQM,KAAA,SAAjCC,GACN,MAAMC,EAAcC,EAAUF,EAAQN,GAStC,MAAO,CAAES,QAPOC,EAAmB,IAC9BT,EACHM,cAEAI,QAASX,EAAMW,UAGCJ,cAAa,EACjC,CAAC,MAAAK,GAAA,OAAAV,QAAAW,OAAAD,EAAA,CAAA,EA/CqBE,EAAsB,SAC1CC,EACAhB,EACAiB,GAEA,OAAOC,EAAa,CAAEF,YAAWhB,WAAWmB,EAAyBF,EACvE,EAvBsBG,EAAqB,SACzCC,EACArB,EACAiB,GAEA,OAAOC,EAAa,CAAEG,WAAUrB,WAAWsB,EAAwBL,EACrE,EAtBsBM,EAAS,SAC7BtB,EACAD,EACAiB,GAEA,OAAOC,EAAa,CAAEjB,QAAOD,WAAWwB,EAAYP,EACtD,EApGeC,EAAYA,SACzBO,EAEAC,EACAT,EACAU,EAAiE,M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,GAAuB,IAC/C,MAAMF,QAAEA,EAAOiB,OAAEA,EAAMhB,MAAEA,EAAKiC,cAAEA,GAAkBhC,EAE5CK,EAASF,EAAUL,GAEzB,OAAAG,QAAAC,QAAOoE,EAAYjE,EAAQN,EAAuCgB,EAAQqD,EAAiBpC,IAC7F,CAAC,MAAArB,GAAA,OAAAV,QAAAW,OAAAD,EAAA,CAAA,EApCK+C,GAAiC,MACjCH,GAA+B,MAG/BN,EAAmC,oBACnCW,EAAqB,uCACrBE,EAAqB,uCACrBZ,EAA2B,sBAC3BM,EAAgC,qDAEhCY,EAA2E,CAC/E,CAACnC,EAAmBE,QAASoC,EAAcpC,OAC3C,CAACF,EAAmBC,SAAUqC,EAAcrC,SAuL9B,SAAA/B,EAAUL,GAExB,MAAM0E,EAAqBC,EAAyC3E,GAEpE,IAAK0E,EACH,MAAU,IAAA/B,EAAS,4DAGrB,OAAOiC,EAAS5E,EAAS0E,EAC3B"}
1
+ {"version":3,"file":"utils-43555783.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n Order,\n OrderUidParams,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n hashOrder,\n packOrderUidParams,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SignOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SignOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch wallet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SignOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SignOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as unknown as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SignOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUid } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderUid, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SignOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n * @param {string} orderUid The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderUid: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUid, chainId }, _signOrderCancellation, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellations with the signing scheme encoded\n * into the signature.\n *\n * @param {string[]} orderUids The unique identifiers of the orders being cancelled.\n * @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.\n * @param {Signer} signer The owner that had placed the orders used to sign.\n * @returns {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\n/**\n * Returns the TypedDataDomain used for signing for the specified chainId.\n * @param {SupportedChainId} chainId The chain Id\n * @return {*} The TypedDataDomain for the specified chainId.\n * @throws {CowError} If the chainId is not supported.\n */\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n\n/**\n * Generate a deterministic order ID for the specified order.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Order} order order to sign\n * @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.\n */\nexport async function generateOrderId(\n chainId: SupportedChainId,\n order: Order,\n params: Pick<OrderUidParams, 'owner'>\n): Promise<{ orderId: string; orderDigest: string }> {\n const domain = await getDomain(chainId)\n const orderDigest = hashOrder(domain, order)\n // Generate the orderId from owner, orderDigest, and max validTo\n const orderId = packOrderUidParams({\n ...params,\n orderDigest,\n // Different validTo when signing because EthFlow contract expects it to be max for all orders\n validTo: order.validTo,\n })\n\n return { orderId, orderDigest }\n}\n"],"names":["generateOrderId","chainId","order","params","Promise","resolve","getDomain","then","domain","orderDigest","hashOrder","orderId","packOrderUidParams","validTo","e","reject","signOrderCancellations","orderUids","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderUid","_signOrderCancellation","signOrder","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","console","error","CowError","_temp","_signFn","_catch","undefined","code","message","regexErrorCheck","METHOD_NOT_FOUND_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","some","regex","msg","test","METHOD_NOT_FOUND_ERROR_CODE","METAMASK_STRING_CHAINID_REGEX","_signPayload5","METAMASK_SIGNATURE_ERROR_CODE","_signPayload6","V4_ERROR_MSG_REGEX","_signPayload7","V3_ERROR_MSG_REGEX","_signPayload8","_signPayload2","_signPayload3","_signPayload4","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"klBAmPsB,MAAAA,EAAeA,SACnCC,EACAC,EACAC,GAAqC,IAAAC,OAAAA,QAAAC,QAEhBC,EAAUL,IAAQM,KAAA,SAAjCC,GACN,MAAMC,EAAcC,EAAUF,EAAQN,GAStC,MAAO,CAAES,QAPOC,EAAmB,IAC9BT,EACHM,cAEAI,QAASX,EAAMW,UAGCJ,cAAa,EACjC,CAAC,MAAAK,GAAA,OAAAV,QAAAW,OAAAD,EAAA,CAAA,EA/CqBE,EAAsB,SAC1CC,EACAhB,EACAiB,GAEA,OAAOC,EAAa,CAAEF,YAAWhB,WAAWmB,EAAyBF,EACvE,EAvBsBG,EAAqB,SACzCC,EACArB,EACAiB,GAEA,OAAOC,EAAa,CAAEG,WAAUrB,WAAWsB,EAAwBL,EACrE,EAtBsBM,EAAS,SAC7BtB,EACAD,EACAiB,GAEA,OAAOC,EAAa,CAAEjB,QAAOD,WAAWwB,EAAYP,EACtD,EApGeC,EAAYA,SACzBO,EAEAC,EACAT,EACAU,EAAiE,MAAI,IAAAC,IAAAA,EAAAC,SAAAA,EAAAC,GAAA,GAAAF,EAAA,OAAAE,EA4ErE,MAAMC,EAAgBC,GAAWD,KAEjC,MAAO,CAAEC,UAAWD,GAAME,YAAc,GAAIC,gBAAe,CA5E3D,MAAMA,EACc,aAAlBP,EAA+BQ,EAAmBC,QAAUD,EAAmBE,OACjF,IAEIC,EAFAN,EAA8B,KAGlC,IACE,OAAQL,GACN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AA+B,MAG/BN,EAAmC,oBACnCW,EAAqB,uCACrBE,EAAqB,uCACrBZ,EAA2B,sBAC3BM,EAAgC,qDAEhCY,EAA2E,CAC/E,CAACnC,EAAmBE,QAASoC,EAAcpC,OAC3C,CAACF,EAAmBC,SAAUqC,EAAcrC,SAuL9B,SAAA/B,EAAUL,GAExB,MAAM0E,EAAqBC,EAAyC3E,GAEpE,IAAK0E,EACH,MAAU,IAAA/B,EAAS,4DAGrB,OAAOiC,EAAS5E,EAAS0E,EAC3B"}
@@ -1,2 +1,2 @@
1
- import{C as e,_ as t,a as n,E as r}from"./index-d7269169.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};
2
- //# sourceMappingURL=utils-be09ebbf.js.map
1
+ import{C as e,_ as t,a as n,E as r}from"./index-f4e68213.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,f=/Method not found/i,m=/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=[f,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(m.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};
2
+ //# sourceMappingURL=utils-9d1e9d0e.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-be09ebbf.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n Order,\n OrderUidParams,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n hashOrder,\n packOrderUidParams,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SignOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SignOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch wallet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SignOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SignOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as unknown as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SignOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUid } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderUid, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SignOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n * @param {string} orderUid The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderUid: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUid, chainId }, _signOrderCancellation, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellations with the signing scheme encoded\n * into the signature.\n *\n * @param {string[]} orderUids The unique identifiers of the orders being cancelled.\n * @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.\n * @param {Signer} signer The owner that had placed the orders used to sign.\n * @returns {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\n/**\n * Returns the TypedDataDomain used for signing for the specified chainId.\n * @param {SupportedChainId} chainId The chain Id\n * @return {*} The TypedDataDomain for the specified chainId.\n * @throws {CowError} If the chainId is not supported.\n */\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n\n/**\n * Generate a deterministic order ID for the specified order.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Order} order order to sign\n * @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.\n */\nexport async function generateOrderId(\n chainId: SupportedChainId,\n order: Order,\n params: Pick<OrderUidParams, 'owner'>\n): Promise<{ orderId: string; orderDigest: string }> {\n const domain = await getDomain(chainId)\n const orderDigest = hashOrder(domain, order)\n // Generate the orderId from owner, orderDigest, and max validTo\n const orderId = packOrderUidParams({\n ...params,\n orderDigest,\n // Different validTo when signing because EthFlow contract expects it to be max for all orders\n validTo: order.validTo,\n })\n\n return { orderId, orderDigest }\n}\n"],"names":["METAMASK_SIGNATURE_ERROR_CODE","METHOD_NOT_FOUND_ERROR_CODE","METHOD_NOT_FOUND_ERROR_MSG_REGEX","V4_ERROR_MSG_REGEX","V3_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","METAMASK_STRING_CHAINID_REGEX","mapSigningSchema","EcdsaSigningScheme","EIP712","SigningScheme","ETHSIGN","async","_signOrder","params","chainId","signer","order","signingScheme","domain","getDomain","signOrderGp","_signOrderCancellation","orderUid","signOrderCancellationGp","_signOrderCancellations","orderUids","signOrderCancellationsGp","_signPayload","payload","signFn","signingMethod","_signature","_signer","signature","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_extends","undefined","code","message","regexErrorCheck","some","regex","toString","msg","test","data","signOrder","signOrderCancellation","signOrderCancellations","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp","generateOrderId","orderDigest","hashOrder","orderId","packOrderUidParams","validTo"],"mappings":"4hBA+BA,MAAMA,GAAiC,MACjCC,GAA+B,MAG/BC,EAAmC,oBACnCC,EAAqB,uCACrBC,EAAqB,uCACrBC,EAA2B,sBAC3BC,EAAgC,qDAEhCC,EAA2E,CAC/E,CAACC,EAAmBC,QAASC,EAAcD,OAC3C,CAACD,EAAmBG,SAAUD,EAAcC,SAkB9CC,eAAeC,EAAWC,GACxB,MAAMC,QAAEA,EAAOC,OAAEA,EAAMC,MAAEA,EAAKC,cAAEA,GAAkBJ,EAE5CK,EAASC,EAAUL,GAEzB,OAAOM,EAAYF,EAAQF,EAAuCD,EAAQT,EAAiBW,GAC7F,CAEAN,eAAeU,EAAuBR,GACpC,MAAMC,QAAEA,EAAOC,OAAEA,EAAME,cAAEA,EAAaK,SAAEA,GAAaT,EAE/CK,EAASC,EAA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AAEO,SAEnC,OAAOhB,EAAaC,EAASC,EAAQd,EAAQ,YAI7C,MADAsB,QAAQC,MAAMF,GACRA,CACP,CA9BC,OAAQN,GACN,IAAK,KACH,OAAOH,EAAaC,EAASC,EAAQd,EAAQ,WAC/C,IAAK,UACH,OAAOY,EAAaC,EAASC,EAAQd,EAAQ,MAC/C,IAAK,KACH,OAAOY,EAAaC,EAASC,EAAQd,EAAQ,YAC/C,QACE,MAAMqB,EAuBb,CA3GH,IAA4BE,EA6G1B,MAAMY,EAAyB,OAArBnB,EAAYE,QAAS,EAATF,EAAWmB,KAEjC,MAAO,CAAEjB,WAAe,MAAJiB,OAAI,EAAJA,EAAMH,aAAc,GAAI9B,gBAC9C,CAUsBN,eAAAwC,EACpBnC,EACAF,EACAC,GAEA,OAAOY,EAAa,CAAEX,QAAOF,WAAWF,EAAYG,EACtD,CAUsBJ,eAAAyC,EACpB9B,EACAR,EACAC,GAEA,OAAOY,EAAa,CAAEL,WAAUR,WAAWO,EAAwBN,EACrE,CAWOJ,eAAe0C,EACpB5B,EACAX,EACAC,GAEA,OAAOY,EAAa,CAAEF,YAAWX,WAAWU,EAAyBT,EACvE,CAQM,SAAUI,EAAUL,GAExB,MAAMwC,EAAqBC,EAAyCzC,GAEpE,IAAKwC,EACH,MAAU,IAAAf,EAAS,4DAGrB,OAAOiB,EAAS1C,EAASwC,EAC3B,CAQsB3C,eAAA8C,EACpB3C,EACAE,EACAH,GAEA,MAAMK,QAAeC,EAAUL,GACzB4C,EAAcC,EAAUzC,EAAQF,GAStC,MAAO,CAAE4C,QAPOC,EAAkBrB,EAAA,CAAA,EAC7B3B,EAAM,CACT6C,cAEAI,QAAS9C,EAAM8C,WAGCJ,cACpB"}
1
+ {"version":3,"file":"utils-9d1e9d0e.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n Order,\n OrderUidParams,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n hashOrder,\n packOrderUidParams,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SignOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SignOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch wallet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SignOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SignOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as unknown as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SignOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUid } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderUid, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SignOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n * @param {string} orderUid The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderUid: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUid, chainId }, _signOrderCancellation, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellations with the signing scheme encoded\n * into the signature.\n *\n * @param {string[]} orderUids The unique identifiers of the orders being cancelled.\n * @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.\n * @param {Signer} signer The owner that had placed the orders used to sign.\n * @returns {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\n/**\n * Returns the TypedDataDomain used for signing for the specified chainId.\n * @param {SupportedChainId} chainId The chain Id\n * @return {*} The TypedDataDomain for the specified chainId.\n * @throws {CowError} If the chainId is not supported.\n */\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n\n/**\n * Generate a deterministic order ID for the specified order.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Order} order order to sign\n * @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.\n */\nexport async function generateOrderId(\n chainId: SupportedChainId,\n order: Order,\n params: Pick<OrderUidParams, 'owner'>\n): Promise<{ orderId: string; orderDigest: string }> {\n const domain = await getDomain(chainId)\n const orderDigest = hashOrder(domain, order)\n // Generate the orderId from owner, orderDigest, and max validTo\n const orderId = packOrderUidParams({\n ...params,\n orderDigest,\n // Different validTo when signing because EthFlow contract expects it to be max for all orders\n validTo: order.validTo,\n })\n\n return { orderId, orderDigest }\n}\n"],"names":["METAMASK_SIGNATURE_ERROR_CODE","METHOD_NOT_FOUND_ERROR_CODE","METHOD_NOT_FOUND_ERROR_MSG_REGEX","V4_ERROR_MSG_REGEX","V3_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","METAMASK_STRING_CHAINID_REGEX","mapSigningSchema","EcdsaSigningScheme","EIP712","SigningScheme","ETHSIGN","async","_signOrder","params","chainId","signer","order","signingScheme","domain","getDomain","signOrderGp","_signOrderCancellation","orderUid","signOrderCancellationGp","_signOrderCancellations","orderUids","signOrderCancellationsGp","_signPayload","payload","signFn","signingMethod","_signature","_signer","signature","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_extends","undefined","code","message","regexErrorCheck","some","regex","toString","msg","test","data","signOrder","signOrderCancellation","signOrderCancellations","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp","generateOrderId","orderDigest","hashOrder","orderId","packOrderUidParams","validTo"],"mappings":"4hBA+BA,MAAMA,GAAiC,MACjCC,GAA+B,MAG/BC,EAAmC,oBACnCC,EAAqB,uCACrBC,EAAqB,uCACrBC,EAA2B,sBAC3BC,EAAgC,qDAEhCC,EAA2E,CAC/E,CAACC,EAAmBC,QAASC,EAAcD,OAC3C,CAACD,EAAmBG,SAAUD,EAAcC,SAkB9CC,eAAeC,EAAWC,GACxB,MAAMC,QAAEA,EAAOC,OAAEA,EAAMC,MAAEA,EAAKC,cAAEA,GAAkBJ,EAE5CK,EAASC,EAAUL,GAEzB,OAAOM,EAAYF,EAAQF,EAAuCD,EAAQT,EAAiBW,GAC7F,CAEAN,eAAeU,EAAuBR,GACpC,MAAMC,QAAEA,EAAOC,OAAEA,EAAME,cAAEA,EAAaK,SAAEA,GAAaT,EAE/CK,EAASC,EAAUL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EO,SAEnC,OAAOhB,EAAaC,EAASC,EAAQd,EAAQ,YAI7C,MADAsB,QAAQC,MAAMF,GACRA,CACP,CA9BC,OAAQN,GACN,IAAK,KACH,OAAOH,EAAaC,EAASC,EAAQd,EAAQ,WAC/C,IAAK,UACH,OAAOY,EAAaC,EAASC,EAAQd,EAAQ,MAC/C,IAAK,KACH,OAAOY,EAAaC,EAASC,EAAQd,EAAQ,YAC/C,QACE,MAAMqB,EAuBb,CA3GH,IAA4BE,EA6G1B,MAAMY,EAAyB,OAArBnB,EAAYE,QAAS,EAATF,EAAWmB,KAEjC,MAAO,CAAEjB,WAAe,MAAJiB,OAAI,EAAJA,EAAMH,aAAc,GAAI9B,gBAC9C,CAUsBN,eAAAwC,EACpBnC,EACAF,EACAC,GAEA,OAAOY,EAAa,CAAEX,QAAOF,WAAWF,EAAYG,EACtD,CAUsBJ,eAAAyC,EACpB9B,EACAR,EACAC,GAEA,OAAOY,EAAa,CAAEL,WAAUR,WAAWO,EAAwBN,EACrE,CAWOJ,eAAe0C,EACpB5B,EACAX,EACAC,GAEA,OAAOY,EAAa,CAAEF,YAAWX,WAAWU,EAAyBT,EACvE,CAQM,SAAUI,EAAUL,GAExB,MAAMwC,EAAqBC,EAAyCzC,GAEpE,IAAKwC,EACH,MAAU,IAAAf,EAAS,4DAGrB,OAAOiB,EAAS1C,EAASwC,EAC3B,CAQsB3C,eAAA8C,EACpB3C,EACAE,EACAH,GAEA,MAAMK,QAAeC,EAAUL,GACzB4C,EAAcC,EAAUzC,EAAQF,GAStC,MAAO,CAAE4C,QAPOC,EAAkBrB,EAAA,CAAA,EAC7B3B,EAAM,CACT6C,cAEAI,QAAS9C,EAAM8C,WAGCJ,cACpB"}
@@ -1,2 +1,2 @@
1
1
  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)};
2
- //# sourceMappingURL=utils-83038876.js.map
2
+ //# sourceMappingURL=utils-dc9c9d10.js.map