@cowprotocol/cow-sdk 5.0.0 → 5.2.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 (30) hide show
  1. package/dist/{index-35b5803e.js → index-a464ca2c.js} +5 -5
  2. package/dist/index-a464ca2c.js.map +1 -0
  3. package/dist/index.js +3 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.mjs +1 -1
  6. package/dist/index.module.js +4 -4
  7. package/dist/index.module.js.map +1 -1
  8. package/dist/order-book/generated/index.d.ts +6 -1
  9. package/dist/order-book/generated/models/Auction.d.ts +2 -2
  10. package/dist/order-book/generated/models/AuctionOrder.d.ts +86 -0
  11. package/dist/order-book/generated/models/FeePolicy.d.ts +7 -0
  12. package/dist/order-book/generated/models/InteractionData.d.ts +11 -0
  13. package/dist/order-book/generated/models/OrderPostError.d.ts +8 -7
  14. package/dist/order-book/generated/models/OrderQuoteRequest.d.ts +0 -4
  15. package/dist/order-book/generated/models/OrderQuoteResponse.d.ts +5 -0
  16. package/dist/order-book/generated/models/PriceImprovement.d.ts +7 -0
  17. package/dist/order-book/generated/models/PriceQuality.d.ts +1 -1
  18. package/dist/order-book/generated/models/Surplus.d.ts +7 -0
  19. package/dist/order-book/generated/models/Volume.d.ts +6 -0
  20. package/dist/package.json +2 -2
  21. package/dist/subgraph/graphql.d.ts +7 -0
  22. package/dist/{utils-88601eb2.js → utils-61d4384b.js} +1 -1
  23. package/dist/{utils-88601eb2.js.map → utils-61d4384b.js.map} +1 -1
  24. package/dist/{utils-33f6a4bd.js → utils-6c8740d2.js} +2 -2
  25. package/dist/{utils-33f6a4bd.js.map → utils-6c8740d2.js.map} +1 -1
  26. package/dist/{utils-89a3986d.js → utils-d4ac1aa5.js} +1 -1
  27. package/dist/{utils-89a3986d.js.map → utils-d4ac1aa5.js.map} +1 -1
  28. package/package.json +2 -2
  29. package/dist/index-35b5803e.js.map +0 -1
  30. package/dist/order-book/generated/models/ReplaceOrderError.d.ts +0 -29
@@ -3,6 +3,7 @@ export type { AppData } from './models/AppData';
3
3
  export type { AppDataHash } from './models/AppDataHash';
4
4
  export type { AppDataObject } from './models/AppDataObject';
5
5
  export type { Auction } from './models/Auction';
6
+ export type { AuctionOrder } from './models/AuctionOrder';
6
7
  export type { AuctionPrices } from './models/AuctionPrices';
7
8
  export type { BigUint } from './models/BigUint';
8
9
  export { BuyTokenDestination } from './models/BuyTokenDestination';
@@ -11,6 +12,8 @@ export type { CompetitionAuction } from './models/CompetitionAuction';
11
12
  export type { EcdsaSignature } from './models/EcdsaSignature';
12
13
  export { EcdsaSigningScheme } from './models/EcdsaSigningScheme';
13
14
  export type { EthflowData } from './models/EthflowData';
15
+ export type { FeePolicy } from './models/FeePolicy';
16
+ export type { InteractionData } from './models/InteractionData';
14
17
  export type { NativePriceResponse } from './models/NativePriceResponse';
15
18
  export { OnchainOrderData } from './models/OnchainOrderData';
16
19
  export type { Order } from './models/Order';
@@ -32,16 +35,18 @@ export type { OrderQuoteValidity } from './models/OrderQuoteValidity';
32
35
  export { OrderStatus } from './models/OrderStatus';
33
36
  export type { PreSignature } from './models/PreSignature';
34
37
  export { PriceEstimationError } from './models/PriceEstimationError';
38
+ export type { PriceImprovement } from './models/PriceImprovement';
35
39
  export { PriceQuality } from './models/PriceQuality';
36
40
  export type { ProtocolAppData } from './models/ProtocolAppData';
37
- export { ReplaceOrderError } from './models/ReplaceOrderError';
38
41
  export { SellTokenSource } from './models/SellTokenSource';
39
42
  export type { Signature } from './models/Signature';
40
43
  export { SigningScheme } from './models/SigningScheme';
41
44
  export type { SolverCompetitionResponse } from './models/SolverCompetitionResponse';
42
45
  export type { SolverSettlement } from './models/SolverSettlement';
46
+ export type { Surplus } from './models/Surplus';
43
47
  export type { TokenAmount } from './models/TokenAmount';
44
48
  export type { TotalSurplus } from './models/TotalSurplus';
45
49
  export type { Trade } from './models/Trade';
46
50
  export type { TransactionHash } from './models/TransactionHash';
47
51
  export type { UID } from './models/UID';
52
+ export type { Volume } from './models/Volume';
@@ -1,5 +1,5 @@
1
+ import type { AuctionOrder } from './AuctionOrder';
1
2
  import type { AuctionPrices } from './AuctionPrices';
2
- import type { Order } from './Order';
3
3
  /**
4
4
  * A batch auction for solving.
5
5
  *
@@ -28,6 +28,6 @@ export type Auction = {
28
28
  * The solvable orders included in the auction.
29
29
  *
30
30
  */
31
- orders?: Array<Order>;
31
+ orders?: Array<AuctionOrder>;
32
32
  prices?: AuctionPrices;
33
33
  };
@@ -0,0 +1,86 @@
1
+ import type { Address } from './Address';
2
+ import type { AppDataHash } from './AppDataHash';
3
+ import type { BuyTokenDestination } from './BuyTokenDestination';
4
+ import type { FeePolicy } from './FeePolicy';
5
+ import type { InteractionData } from './InteractionData';
6
+ import type { OrderClass } from './OrderClass';
7
+ import type { OrderKind } from './OrderKind';
8
+ import type { SellTokenSource } from './SellTokenSource';
9
+ import type { Signature } from './Signature';
10
+ import type { TokenAmount } from './TokenAmount';
11
+ import type { UID } from './UID';
12
+ /**
13
+ * A solvable order included in the current batch auction. Contains the data forwarded to solvers for solving.
14
+ *
15
+ */
16
+ export type AuctionOrder = {
17
+ uid: UID;
18
+ /**
19
+ * see `OrderParameters::sellToken`
20
+ */
21
+ sellToken: Address;
22
+ /**
23
+ * see `OrderParameters::buyToken`
24
+ */
25
+ buyToken: Address;
26
+ /**
27
+ * see `OrderParameters::sellAmount`
28
+ */
29
+ sellAmount: TokenAmount;
30
+ /**
31
+ * see `OrderParameters::buyAmount`
32
+ */
33
+ buyAmount: TokenAmount;
34
+ /**
35
+ * see `OrderParameters::feeAmount`
36
+ */
37
+ userFee: TokenAmount;
38
+ /**
39
+ * see `OrderParameters::validTo`
40
+ */
41
+ validTo: number;
42
+ /**
43
+ * see `OrderParameters::kind`
44
+ */
45
+ kind: OrderKind;
46
+ /**
47
+ * see `OrderParameters::receiver`
48
+ */
49
+ receiver: Address | null;
50
+ owner: Address;
51
+ /**
52
+ * see `OrderParameters::partiallyFillable`
53
+ */
54
+ partiallyFillable: boolean;
55
+ /**
56
+ * Currently executed amount of sell/buy token, depending on the order kind.
57
+ *
58
+ */
59
+ executed: TokenAmount;
60
+ /**
61
+ * The pre-interactions that need to be executed before the first execution of the order.
62
+ *
63
+ */
64
+ preInteractions: Array<InteractionData>;
65
+ /**
66
+ * The post-interactions that need to be executed after the execution of the order.
67
+ *
68
+ */
69
+ postInteractions: Array<InteractionData>;
70
+ /**
71
+ * see `OrderParameters::sellTokenBalance`
72
+ */
73
+ sellTokenBalance: SellTokenSource;
74
+ /**
75
+ * see `OrderParameters::buyTokenBalance`
76
+ */
77
+ buyTokenBalance: BuyTokenDestination;
78
+ class: OrderClass;
79
+ appData: AppDataHash;
80
+ signature: Signature;
81
+ /**
82
+ * The fee policies that are used to compute the protocol fees for this order.
83
+ *
84
+ */
85
+ protocolFees: Array<FeePolicy>;
86
+ };
@@ -0,0 +1,7 @@
1
+ import type { PriceImprovement } from './PriceImprovement';
2
+ import type { Surplus } from './Surplus';
3
+ import type { Volume } from './Volume';
4
+ /**
5
+ * Defines the ways to calculate the protocol fee.
6
+ */
7
+ export type FeePolicy = (Surplus | Volume | PriceImprovement);
@@ -0,0 +1,11 @@
1
+ import type { Address } from './Address';
2
+ import type { CallData } from './CallData';
3
+ import type { TokenAmount } from './TokenAmount';
4
+ export type InteractionData = {
5
+ target?: Address;
6
+ value?: TokenAmount;
7
+ /**
8
+ * The call data to be used for the interaction.
9
+ */
10
+ call_data?: Array<CallData>;
11
+ };
@@ -13,21 +13,22 @@ export declare namespace OrderPostError {
13
13
  INSUFFICIENT_BALANCE = "InsufficientBalance",
14
14
  INSUFFICIENT_ALLOWANCE = "InsufficientAllowance",
15
15
  INVALID_SIGNATURE = "InvalidSignature",
16
- INSUFFICIENT_FEE = "InsufficientFee",
17
16
  SELL_AMOUNT_OVERFLOW = "SellAmountOverflow",
18
17
  TRANSFER_SIMULATION_FAILED = "TransferSimulationFailed",
19
18
  ZERO_AMOUNT = "ZeroAmount",
20
19
  INCOMPATIBLE_SIGNING_SCHEME = "IncompatibleSigningScheme",
21
- TOO_MANY_LIMIT_ORDERS_UNSUPPORTED_BUY_TOKEN_DESTINATION = "TooManyLimitOrders UnsupportedBuyTokenDestination",
20
+ TOO_MANY_LIMIT_ORDERS = "TooManyLimitOrders",
21
+ TOO_MUCH_GAS = "TooMuchGas",
22
+ UNSUPPORTED_BUY_TOKEN_DESTINATION = "UnsupportedBuyTokenDestination",
22
23
  UNSUPPORTED_SELL_TOKEN_SOURCE = "UnsupportedSellTokenSource",
23
24
  UNSUPPORTED_ORDER_TYPE = "UnsupportedOrderType",
24
25
  INSUFFICIENT_VALID_TO = "InsufficientValidTo",
25
26
  EXCESSIVE_VALID_TO = "ExcessiveValidTo",
26
- TRANSFER_ETH_TO_CONTRACT = "TransferEthToContract",
27
- INVALID_NATIVE_SELL_TOKEN_SAME_BUY_AND_SELL_TOKEN = "InvalidNativeSellToken SameBuyAndSellToken",
28
- UNSUPPORTED_SIGNATURE = "UnsupportedSignature",
27
+ INVALID_NATIVE_SELL_TOKEN = "InvalidNativeSellToken",
28
+ SAME_BUY_AND_SELL_TOKEN = "SameBuyAndSellToken",
29
29
  UNSUPPORTED_TOKEN = "UnsupportedToken",
30
- UNSUPPORTED_CUSTOM_INTERACTION_INVALID_APP_DATA = "UnsupportedCustomInteraction InvalidAppData",
31
- APP_DATA_HASH_MISMATCH = "AppDataHashMismatch"
30
+ INVALID_APP_DATA = "InvalidAppData",
31
+ APP_DATA_HASH_MISMATCH = "AppDataHashMismatch",
32
+ APPDATA_FROM_MISMATCH = "AppdataFromMismatch"
32
33
  }
33
34
  }
@@ -40,10 +40,6 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
40
40
  *
41
41
  */
42
42
  appDataHash?: AppDataHash;
43
- /**
44
- * Is the order fill-or-kill or partially fillable?
45
- */
46
- partiallyFillable?: boolean;
47
43
  sellTokenBalance?: SellTokenSource;
48
44
  buyTokenBalance?: BuyTokenDestination;
49
45
  from: Address;
@@ -20,4 +20,9 @@ export type OrderQuoteResponse = {
20
20
  *
21
21
  */
22
22
  id?: number;
23
+ /**
24
+ * Whether it was possible to verify that the quoted amounts are accurate using a simulation.
25
+ *
26
+ */
27
+ verified: boolean;
23
28
  };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The protocol fee is taken as a percent of the order price improvement which is a difference between the executed price and the best quote.
3
+ */
4
+ export type PriceImprovement = {
5
+ factor: number;
6
+ maxVolumeFactor: number;
7
+ };
@@ -5,7 +5,7 @@
5
5
  * Optimal: The price estimate is chosen among all price estimates.
6
6
  * Verified: The price estimate is chosen among all verified/simulated price estimates.
7
7
  *
8
- * **NOTE**: Orders are supposed to be created from `verified` price estimates.
8
+ * **NOTE**: Orders are supposed to be created from `verified` or `optimal` price estimates.
9
9
  *
10
10
  */
11
11
  export declare enum PriceQuality {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The protocol fee is taken as a percent of the surplus.
3
+ */
4
+ export type Surplus = {
5
+ factor: number;
6
+ maxVolumeFactor: number;
7
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The protocol fee is taken as a percent of the order volume.
3
+ */
4
+ export type Volume = {
5
+ factor: number;
6
+ };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/cow-sdk",
3
- "version": "5.0.0",
3
+ "version": "5.2.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.227.1/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.252.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/composable/generated './abi/*.json'"
32
32
  },
33
33
  "dependencies": {
@@ -22,7 +22,12 @@ export type Scalars = {
22
22
  BigInt: any;
23
23
  Bytes: any;
24
24
  Int8: any;
25
+ Timestamp: any;
25
26
  };
27
+ export declare enum Aggregation_Interval {
28
+ Day = "day",
29
+ Hour = "hour"
30
+ }
26
31
  export type BlockChangedFilter = {
27
32
  number_gte: Scalars['Int'];
28
33
  };
@@ -3130,6 +3135,8 @@ export type _Block_ = {
3130
3135
  hash?: Maybe<Scalars['Bytes']>;
3131
3136
  /** The block number */
3132
3137
  number: Scalars['Int'];
3138
+ /** The hash of the parent block */
3139
+ parentHash?: Maybe<Scalars['Bytes']>;
3133
3140
  /** Integer representation of the timestamp stored in blocks for the chain */
3134
3141
  timestamp?: Maybe<Scalars['Int']>;
3135
3142
  };
@@ -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");const n=function(t,i,o,l="v4"){try{let f;function m(e){if(f)return e;const r=v?.data;return{signature:r?.toString()||"",signingScheme:S}}const S="eth_sign"===l?r.EcdsaSigningScheme.ETHSIGN:r.EcdsaSigningScheme.EIP712;let p,v=null;try{switch(l){case"default":case"v3":p=new e.TypedDataVersionedSigner(o);break;case"int_v4":p=new e.IntChainIdTypedDataV4Signer(o);break;default:p=o}}catch(w){throw console.error("Wallet not supported:",w),new r.CowError("Wallet not supported")}const E=function(e,r){try{var n=Promise.resolve(i({...t,signer:p,signingScheme:S})).then(function(e){v=e})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){if(void 0===(r=e).code&&void 0===r.message)throw console.error(e),e;var r;const m=[a,g].some(r=>[e.message,e.toString()].some(e=>r.test(e)));if(e.code!==c&&!m){if(h.test(e.message)){const e=n(t,i,o,"int_v4");return f=1,e}if(e.code===s){const e=n(t,i,o,"eth_sign");return f=1,e}if(d.test(e.message)){const e=n(t,i,o,"v3");return f=1,e}if(u.test(e.message)){const e=n(t,i,o,"eth_sign");return f=1,e}throw console.error(e),e}switch(l){case"v4":const r=n(t,i,o,"default");return f=1,r;case"default":const s=n(t,i,o,"v3");return f=1,s;case"v3":const c=n(t,i,o,"eth_sign");return f=1,c;default:throw e}});return Promise.resolve(E&&E.then?E.then(m):m(E))}catch(I){return Promise.reject(I)}},t=function(r){try{const{chainId:n,signer:t,signingScheme:i,orderUids:o}=r,s=m(n);return Promise.resolve(e.signOrderCancellations(s,o,t,l[i]))}catch(e){return Promise.reject(e)}},i=function(r){try{const{chainId:n,signer:t,signingScheme:i,orderUid:o}=r,s=m(n);return Promise.resolve(e.signOrderCancellation(s,o,t,l[i]))}catch(e){return Promise.reject(e)}},o=function(r){try{const{chainId:n,signer:t,order:i,signingScheme:o}=r,s=m(n);return Promise.resolve(e.signOrder(s,i,t,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,g=/RPC request failed/i,h=/provided chainid .* must match the active chainid/i,l={[r.EcdsaSigningScheme.EIP712]:e.SigningScheme.EIP712,[r.EcdsaSigningScheme.ETHSIGN]:e.SigningScheme.ETHSIGN};function m(n){const t=r.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[n];if(!t)throw new r.CowError("Unsupported network. Settlement contract is not deployed");return e.domain(n,t)}exports.getDomain=m,exports.signOrder=function(e,r,t){return n({order:e,chainId:r},o,t)},exports.signOrderCancellation=function(e,r,t){return n({orderUid:e,chainId:r},i,t)},exports.signOrderCancellations=function(e,r,i){return n({orderUids:e,chainId:r},t,i)};
2
- //# sourceMappingURL=utils-88601eb2.js.map
2
+ //# sourceMappingURL=utils-61d4384b.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-88601eb2.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"names":["_signPayload","payload","signFn","signer","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_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","reject","_signOrderCancellations","params","chainId","orderUids","domain","getDomain","signOrderCancellationsGp","signOrderCancellations","mapSigningSchema","_signOrderCancellation","orderUid","signOrderCancellationGp","_signOrder","order","signOrderGp","signOrder","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"oOAgNsB,MA/HPA,EAAYA,SACzBC,EAEAC,EACAC,EACAC,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,EAAAA,mBAAmBC,QAAUD,EAAAA,mBAAmBE,OACjF,IAEIC,EAFAN,EAA8B,KAGlC,IACE,OAAQL,GACN,IAAK,UACL,IAAK,KACHW,EAAU,IAAIC,EAAAA,yBAAyBb,GACvC,MACF,IAAK,SACHY,EAAU,IAAIE,EAA2BA,4BAACd,GAC1C,MACF,QACEY,EAAUZ,EAEf,CAAC,MAAOe,GAEP,MADAC,QAAQC,MAAM,wBAAyBF,GAC7B,IAAAG,EAAAA,SAAS,uBACpB,CAAA,MAAAC,0BAEGC,QAAAC,QACiBtB,EAAO,IAAKD,EAASE,OAAQY,EAASJ,mBAAgBc,cAAAC,GAAzEjB,EAASiB,CAAmF,4DAH7FC,CAEG,EAGH,SAAQT,GACP,QA5D0CU,KADlBR,EA6DAF,GA5DSW,WAA8DD,IAAvCR,EAA2BU,QA+DjF,MADAX,QAAQC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D,gCAU2C,SACzC0D,EACAR,EACAlD,GAEA,OAAOH,EAAa,CAAE6D,WAAUR,WAAWO,EAAwBzD,EACrE,iCAW4CuD,SAC1CJ,EACAD,EACAlD,GAEA,OAAOH,EAAa,CAAEsD,YAAWD,WAAWF,EAAyBhD,EACvE"}
1
+ {"version":3,"file":"utils-61d4384b.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"names":["_signPayload","payload","signFn","signer","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_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","reject","_signOrderCancellations","params","chainId","orderUids","domain","getDomain","signOrderCancellationsGp","signOrderCancellations","mapSigningSchema","_signOrderCancellation","orderUid","signOrderCancellationGp","_signOrder","order","signOrderGp","signOrder","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"oOAgNsB,MA/HPA,EAAYA,SACzBC,EAEAC,EACAC,EACAC,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,EAAAA,mBAAmBC,QAAUD,EAAAA,mBAAmBE,OACjF,IAEIC,EAFAN,EAA8B,KAGlC,IACE,OAAQL,GACN,IAAK,UACL,IAAK,KACHW,EAAU,IAAIC,EAAAA,yBAAyBb,GACvC,MACF,IAAK,SACHY,EAAU,IAAIE,EAA2BA,4BAACd,GAC1C,MACF,QACEY,EAAUZ,EAEf,CAAC,MAAOe,GAEP,MADAC,QAAQC,MAAM,wBAAyBF,GAC7B,IAAAG,EAAAA,SAAS,uB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AA2C,EAAUH,GAExB,MAAMe,EAAqBC,EAAwCA,yCAAChB,GAEpE,IAAKe,EACH,MAAM,IAAI/C,EAAAA,SAAS,4DAGrB,OAAOiD,EAAAA,OAASjB,EAASe,EAC3B,uCAxD+B,SAC7BJ,EACAX,EACAlD,GAEA,OAAOH,EAAa,CAAEgE,QAAOX,WAAWU,EAAY5D,EACtD,gCAU2C,SACzC0D,EACAR,EACAlD,GAEA,OAAOH,EAAa,CAAE6D,WAAUR,WAAWO,EAAwBzD,EACrE,iCAW4CuD,SAC1CJ,EACAD,EACAlD,GAEA,OAAOH,EAAa,CAAEsD,YAAWD,WAAWF,EAAyBhD,EACvE"}
@@ -1,2 +1,2 @@
1
- import{C as e,_ as t,a as n,E as r}from"./index-35b5803e.js";import{domain as i,IntChainIdTypedDataV4Signer as o,TypedDataVersionedSigner as s,signOrder as a,signOrderCancellation as c,signOrderCancellations as d,SigningScheme as u}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";import"ethers";import"@openzeppelin/merkle-tree";const l=-32603,h=-32601,g=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,m=/eth_signTypedData_v3 does not exist/i,p=/RPC request failed/i,v=/provided chainid .* must match the active chainid/i,w={[r.EIP712]:u.EIP712,[r.ETHSIGN]:u.ETHSIGN};async function y(e){const{chainId:t,signer:n,order:r,signingScheme:i}=e,o=T(t);return a(o,r,n,w[i])}async function I(e){const{chainId:t,signer:n,signingScheme:r,orderUid:i}=e,o=T(t);return c(o,i,n,w[r])}async function S(e){const{chainId:t,signer:n,signingScheme:r,orderUids:i}=e,o=T(t);return d(o,i,n,w[r])}async function _(n,i,a,c="v4"){var d;const u="eth_sign"===c?r.ETHSIGN:r.EIP712;let w,y=null;try{switch(c){case"default":case"v3":w=new s(a);break;case"int_v4":w=new o(a);break;default:w=a}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{y=await i(t({},n,{signer:w,signingScheme:u}))}catch(e){if(void 0===(I=e).code&&void 0===I.message)throw console.error(e),e;const t=[g,p].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==h&&!t){if(v.test(e.message))return _(n,i,a,"int_v4");if(e.code===l)return _(n,i,a,"eth_sign");if(f.test(e.message))return _(n,i,a,"v3");if(m.test(e.message))return _(n,i,a,"eth_sign");throw console.error(e),e}switch(c){case"v4":return _(n,i,a,"default");case"default":return _(n,i,a,"v3");case"v3":return _(n,i,a,"eth_sign");default:throw e}}var I;const S=null==(d=y)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:u}}async function E(e,t,n){return _({order:e,chainId:t},y,n)}async function k(e,t,n){return _({orderUid:e,chainId:t},I,n)}async function x(e,t,n){return _({orderUids:e,chainId:t},S,n)}function T(t){const r=n[t];if(!r)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,r)}export{T as getDomain,E as signOrder,k as signOrderCancellation,x as signOrderCancellations};
2
- //# sourceMappingURL=utils-33f6a4bd.js.map
1
+ import{C as e,_ as t,a as n,E as r}from"./index-a464ca2c.js";import{domain as i,IntChainIdTypedDataV4Signer as o,TypedDataVersionedSigner as s,signOrder as a,signOrderCancellation as c,signOrderCancellations as d,SigningScheme as u}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";import"ethers";import"@openzeppelin/merkle-tree";const l=-32603,h=-32601,g=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,m=/eth_signTypedData_v3 does not exist/i,p=/RPC request failed/i,v=/provided chainid .* must match the active chainid/i,w={[r.EIP712]:u.EIP712,[r.ETHSIGN]:u.ETHSIGN};async function y(e){const{chainId:t,signer:n,order:r,signingScheme:i}=e,o=T(t);return a(o,r,n,w[i])}async function I(e){const{chainId:t,signer:n,signingScheme:r,orderUid:i}=e,o=T(t);return c(o,i,n,w[r])}async function S(e){const{chainId:t,signer:n,signingScheme:r,orderUids:i}=e,o=T(t);return d(o,i,n,w[r])}async function _(n,i,a,c="v4"){var d;const u="eth_sign"===c?r.ETHSIGN:r.EIP712;let w,y=null;try{switch(c){case"default":case"v3":w=new s(a);break;case"int_v4":w=new o(a);break;default:w=a}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{y=await i(t({},n,{signer:w,signingScheme:u}))}catch(e){if(void 0===(I=e).code&&void 0===I.message)throw console.error(e),e;const t=[g,p].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==h&&!t){if(v.test(e.message))return _(n,i,a,"int_v4");if(e.code===l)return _(n,i,a,"eth_sign");if(f.test(e.message))return _(n,i,a,"v3");if(m.test(e.message))return _(n,i,a,"eth_sign");throw console.error(e),e}switch(c){case"v4":return _(n,i,a,"default");case"default":return _(n,i,a,"v3");case"v3":return _(n,i,a,"eth_sign");default:throw e}}var I;const S=null==(d=y)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:u}}async function E(e,t,n){return _({order:e,chainId:t},y,n)}async function k(e,t,n){return _({orderUid:e,chainId:t},I,n)}async function x(e,t,n){return _({orderUids:e,chainId:t},S,n)}function T(t){const r=n[t];if(!r)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,r)}export{T as getDomain,E as signOrder,k as signOrderCancellation,x as signOrderCancellations};
2
+ //# sourceMappingURL=utils-6c8740d2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-33f6a4bd.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"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"],"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,MAAMwC,EAAqBC,EAAyCzC,GAEpE,IAAKwC,EACH,UAAUf,EAAS,4DAGrB,OAAOiB,EAAS1C,EAASwC,EAC3B"}
1
+ {"version":3,"file":"utils-6c8740d2.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"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"],"mappings":"uZA2BA,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,EAA4BD,EAAQT,EAAiBW,GAClF,CAEAN,eAAeU,EAAuBR,GACpC,MAAMC,QAAEA,EAAOC,OAAEA,EAAME,cAAEA,EAAaK,SAAEA,GAAaT,EAE/CK,EAASC,EAAUL,GAEzB,OAAOS,EAAwBL,EAAQI,EAAUP,EAAQT,EAAiBW,GAC5E,CAEAN,eAAea,EAAwBX,GACrC,MAAMC,QAAEA,EAAOC,OAAEA,EAAME,cAAEA,EAAaQ,UAAEA,GAAcZ,EAEhDK,EAASC,EAAUL,GAEzB,OAAOY,EAAyBR,EAAQO,EAAWV,EAAQT,EAA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OY,EAAaC,EAASC,EAAQd,EAAQ,YAC/C,QACE,MAAMqB,EAuBb,CA3GH,IAA4BE,EA6G1B,MAAMY,EAAyB,OAArBnB,EAAYE,QAAS,EAATF,EAAWmB,KAEjC,MAAO,CAAEjB,WAAWiB,MAAAA,OAAAA,EAAAA,EAAMH,aAAc,GAAI9B,gBAC9C,CAUsBN,eAAAwC,EACpBnC,EACAF,EACAC,GAEA,OAAOY,EAAa,CAAEX,QAAOF,WAAWF,EAAYG,EACtD,gBAUsBqC,EACpB9B,EACAR,EACAC,GAEA,OAAOY,EAAa,CAAEL,WAAUR,WAAWO,EAAwBN,EACrE,gBAWsBsC,EACpB5B,EACAX,EACAC,GAEA,OAAOY,EAAa,CAAEF,YAAWX,WAAWU,EAAyBT,EACvE,CAQM,SAAUI,EAAUL,GAExB,MAAMwC,EAAqBC,EAAyCzC,GAEpE,IAAKwC,EACH,UAAUf,EAAS,4DAGrB,OAAOiB,EAAS1C,EAASwC,EAC3B"}
@@ -1,2 +1,2 @@
1
1
  import{IntChainIdTypedDataV4Signer as e,TypedDataVersionedSigner as t,signOrderCancellations as r,signOrderCancellation as n,signOrder as o,SigningScheme as i,domain as s}from"@cowprotocol/contracts";import{EcdsaSigningScheme as c,CowError as a,COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS as u}from"./index.module.js";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";import"ethers";import"@openzeppelin/merkle-tree";const d=function(e,t,r){return m({orderUids:e,chainId:t},f,r)},h=function(e,t,r){return m({orderUid:e,chainId:t},g,r)},l=function(e,t,r){return m({order:e,chainId:t},p,r)},m=function(r,n,o,i="v4"){try{let u;function s(e){if(u)return e;const t=l?.data;return{signature:t?.toString()||"",signingScheme:d}}const d="eth_sign"===i?c.ETHSIGN:c.EIP712;let h,l=null;try{switch(i){case"default":case"v3":h=new t(o);break;case"int_v4":h=new e(o);break;default:h=o}}catch(g){throw console.error("Wallet not supported:",g),new a("Wallet not supported")}const f=function(e,t){try{var o=Promise.resolve(n({...r,signer:h,signingScheme:d})).then(function(e){l=e})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){if(void 0===(t=e).code&&void 0===t.message)throw console.error(e),e;var t;const s=[P,y].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==w&&!s){if(_.test(e.message)){const e=m(r,n,o,"int_v4");return u=1,e}if(e.code===v){const e=m(r,n,o,"eth_sign");return u=1,e}if(I.test(e.message)){const e=m(r,n,o,"v3");return u=1,e}if(S.test(e.message)){const e=m(r,n,o,"eth_sign");return u=1,e}throw console.error(e),e}switch(i){case"v4":const t=m(r,n,o,"default");return u=1,t;case"default":const i=m(r,n,o,"v3");return u=1,i;case"v3":const s=m(r,n,o,"eth_sign");return u=1,s;default:throw e}});return Promise.resolve(f&&f.then?f.then(s):s(f))}catch(p){return Promise.reject(p)}},f=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderUids:i}=e,s=j(t);return Promise.resolve(r(s,i,n,E[o]))}catch(e){return Promise.reject(e)}},g=function(e){try{const{chainId:t,signer:r,signingScheme:o,orderUid:i}=e,s=j(t);return Promise.resolve(n(s,i,r,E[o]))}catch(e){return Promise.reject(e)}},p=function(e){try{const{chainId:t,signer:r,order:n,signingScheme:i}=e,s=j(t);return Promise.resolve(o(s,n,r,E[i]))}catch(e){return Promise.reject(e)}},v=-32603,w=-32601,P=/Method not found/i,I=/eth_signTypedData_v4 does not exist/i,S=/eth_signTypedData_v3 does not exist/i,y=/RPC request failed/i,_=/provided chainid .* must match the active chainid/i,E={[c.EIP712]:i.EIP712,[c.ETHSIGN]:i.ETHSIGN};function j(e){const t=u[e];if(!t)throw new a("Unsupported network. Settlement contract is not deployed");return s(e,t)}export{j as getDomain,l as signOrder,h as signOrderCancellation,d as signOrderCancellations};
2
- //# sourceMappingURL=utils-89a3986d.js.map
2
+ //# sourceMappingURL=utils-d4ac1aa5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-89a3986d.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"names":["signOrderCancellations","orderUids","chainId","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderUid","_signOrderCancellation","signOrder","order","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_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","reject","params","domain","getDomain","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"6cAgNsB,MAAAA,EAAsBA,SAC1CC,EACAC,EACAC,GAEA,OAAOC,EAAa,CAAEH,YAAWC,WAAWG,EAAyBF,EACvE,EAvBsBG,EAAqB,SACzCC,EACAL,EACAC,GAEA,OAAOC,EAAa,CAAEG,WAAUL,WAAWM,EAAwBL,EACrE,EAtBsBM,EAAS,SAC7BC,EACAR,EACAC,GAEA,OAAOC,EAAa,CAAEM,QAAOR,WAAWS,EAAYR,EACtD,EApGeC,EAAYA,SACzBQ,EAEAC,EACAV,EACAW,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,IAAK,UACL,IAAK,KACHW,EAAU,IAAIC,EAAyBvB,GACvC,MACF,IAAK,SACHsB,EAAU,IAAIE,EAA4BxB,GAC1C,MACF,QACEsB,EAAUtB,EAEf,CAAC,MAAOyB,GAEP,MADAC,QAAQ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,SAuL9B,SAAAwC,EAAU7D,GAExB,MAAMmE,EAAqBC,EAAyCpE,GAEpE,IAAKmE,EACH,MAAM,IAAItC,EAAS,4DAGrB,OAAOwC,EAASrE,EAASmE,EAC3B"}
1
+ {"version":3,"file":"utils-d4ac1aa5.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\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 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"],"names":["signOrderCancellations","orderUids","chainId","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderUid","_signOrderCancellation","signOrder","order","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_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","reject","params","domain","getDomain","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"6cAgNsB,MAAAA,EAAsBA,SAC1CC,EACAC,EACAC,GAEA,OAAOC,EAAa,CAAEH,YAAWC,WAAWG,EAAyBF,EACvE,EAvBsBG,EAAqB,SACzCC,EACAL,EACAC,GAEA,OAAOC,EAAa,CAAEG,WAAUL,WAAWM,EAAwBL,EACrE,EAtBsBM,EAAS,SAC7BC,EACAR,EACAC,GAEA,OAAOC,EAAa,CAAEM,QAAOR,WAAWS,EAAYR,EACtD,EApGeC,EAAYA,SACzBQ,EAEAC,EACAV,EACAW,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,O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EAAmC,oBACnCW,EAAqB,uCACrBE,EAAqB,uCACrBZ,EAA2B,sBAC3BM,EAAgC,qDAEhCgB,EAA2E,CAC/E,CAAC3C,EAAmBE,QAAS4C,EAAc5C,OAC3C,CAACF,EAAmBC,SAAU6C,EAAc7C,SAuL9B,SAAAwC,EAAU7D,GAExB,MAAMmE,EAAqBC,EAAyCpE,GAEpE,IAAKmE,EACH,MAAM,IAAItC,EAAS,4DAGrB,OAAOwC,EAASrE,EAASmE,EAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/cow-sdk",
3
- "version": "5.0.0",
3
+ "version": "5.2.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.227.1/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.252.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/composable/generated './abi/*.json'"
32
32
  },
33
33
  "dependencies": {