@cowprotocol/sdk-order-signing 0.1.38 → 0.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.
- package/dist/index.d.mts +13 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.js +32 -28
- package/dist/index.mjs +36 -29
- package/package.json +28 -22
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedChainId } from '@cowprotocol/sdk-config';
|
|
1
|
+
import { SupportedChainId, CowEnv, AddressPerChain, ProtocolOptions } from '@cowprotocol/sdk-config';
|
|
2
2
|
import { ContractsOrder, OrderUidParams } from '@cowprotocol/sdk-contracts-ts';
|
|
3
3
|
import { SignerLike, Signer, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
4
4
|
import { OrderParameters, EcdsaSigningScheme } from '@cowprotocol/sdk-order-book';
|
|
@@ -28,6 +28,8 @@ interface SignOrderParams {
|
|
|
28
28
|
signer: SignerLike;
|
|
29
29
|
order: UnsignedOrder;
|
|
30
30
|
signingScheme: EcdsaSigningScheme;
|
|
31
|
+
env?: CowEnv;
|
|
32
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Parameters for signing an order cancellation.
|
|
@@ -41,6 +43,8 @@ interface SignOrderCancellationParams {
|
|
|
41
43
|
signer: SignerLike;
|
|
42
44
|
orderUid: string;
|
|
43
45
|
signingScheme: EcdsaSigningScheme;
|
|
46
|
+
env?: CowEnv;
|
|
47
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
50
|
* Parameters for signing multiple bulk order cancellations.
|
|
@@ -54,6 +58,8 @@ interface SignOrderCancellationsParams {
|
|
|
54
58
|
signer: SignerLike;
|
|
55
59
|
orderUids: string[];
|
|
56
60
|
signingScheme: EcdsaSigningScheme;
|
|
61
|
+
env?: CowEnv;
|
|
62
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
declare const ORDER_PRIMARY_TYPE: "Order";
|
|
@@ -117,7 +123,7 @@ declare class OrderSigningUtils {
|
|
|
117
123
|
* @param {Signer} signer The signer who is placing the order intent.
|
|
118
124
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the order.
|
|
119
125
|
*/
|
|
120
|
-
static signOrder(order: UnsignedOrder, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
126
|
+
static signOrder(order: UnsignedOrder, chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
121
127
|
/**
|
|
122
128
|
* Sign a cancellation message of an order intent with the specified signer.
|
|
123
129
|
* @param {string} orderUid The unique identifier of the order to cancel.
|
|
@@ -125,7 +131,7 @@ declare class OrderSigningUtils {
|
|
|
125
131
|
* @param {Signer} signer The signer who initially placed the order intent.
|
|
126
132
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
127
133
|
*/
|
|
128
|
-
static signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
134
|
+
static signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
129
135
|
/**
|
|
130
136
|
* Sign a cancellation message of multiple order intents with the specified signer.
|
|
131
137
|
* @param {string[]} orderUids An array of `orderUid` to cancel.
|
|
@@ -133,21 +139,21 @@ declare class OrderSigningUtils {
|
|
|
133
139
|
* @param {Signer} signer The signer who initially placed the order intents.
|
|
134
140
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
135
141
|
*/
|
|
136
|
-
static signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
142
|
+
static signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
137
143
|
/**
|
|
138
144
|
* Get the EIP-712 typed domain data being used for signing.
|
|
139
145
|
* @param {SupportedChainId} chainId The CoW Protocol `chainId` context that's being used.
|
|
140
146
|
* @return The EIP-712 typed domain data.
|
|
141
147
|
* @see https://eips.ethereum.org/EIPS/eip-712
|
|
142
148
|
*/
|
|
143
|
-
static getDomain(chainId: SupportedChainId): Promise<TypedDataDomain>;
|
|
149
|
+
static getDomain(chainId: SupportedChainId, options?: ProtocolOptions): Promise<TypedDataDomain>;
|
|
144
150
|
/**
|
|
145
151
|
* Hashes the order intent and generate deterministic order ID.
|
|
146
152
|
* @param {SupportedChainId} chainId The CoW Protocol `chainId` context that's being used.
|
|
147
153
|
* @param {Order} order order to sign
|
|
148
154
|
* @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.
|
|
149
155
|
*/
|
|
150
|
-
static generateOrderId(chainId: SupportedChainId, order: ContractsOrder, params: Pick<OrderUidParams, 'owner'
|
|
156
|
+
static generateOrderId(chainId: SupportedChainId, order: ContractsOrder, params: Pick<OrderUidParams, 'owner'>, options?: ProtocolOptions): Promise<{
|
|
151
157
|
orderId: string;
|
|
152
158
|
orderDigest: string;
|
|
153
159
|
}>;
|
|
@@ -156,7 +162,7 @@ declare class OrderSigningUtils {
|
|
|
156
162
|
* @param chainId {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
157
163
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
158
164
|
*/
|
|
159
|
-
static getDomainSeparator(chainId: SupportedChainId): Promise<string>;
|
|
165
|
+
static getDomainSeparator(chainId: SupportedChainId, options?: ProtocolOptions): Promise<string>;
|
|
160
166
|
static getEIP712Types(): typeof COW_EIP712_TYPES;
|
|
161
167
|
/**
|
|
162
168
|
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedChainId } from '@cowprotocol/sdk-config';
|
|
1
|
+
import { SupportedChainId, CowEnv, AddressPerChain, ProtocolOptions } from '@cowprotocol/sdk-config';
|
|
2
2
|
import { ContractsOrder, OrderUidParams } from '@cowprotocol/sdk-contracts-ts';
|
|
3
3
|
import { SignerLike, Signer, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
4
4
|
import { OrderParameters, EcdsaSigningScheme } from '@cowprotocol/sdk-order-book';
|
|
@@ -28,6 +28,8 @@ interface SignOrderParams {
|
|
|
28
28
|
signer: SignerLike;
|
|
29
29
|
order: UnsignedOrder;
|
|
30
30
|
signingScheme: EcdsaSigningScheme;
|
|
31
|
+
env?: CowEnv;
|
|
32
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Parameters for signing an order cancellation.
|
|
@@ -41,6 +43,8 @@ interface SignOrderCancellationParams {
|
|
|
41
43
|
signer: SignerLike;
|
|
42
44
|
orderUid: string;
|
|
43
45
|
signingScheme: EcdsaSigningScheme;
|
|
46
|
+
env?: CowEnv;
|
|
47
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
50
|
* Parameters for signing multiple bulk order cancellations.
|
|
@@ -54,6 +58,8 @@ interface SignOrderCancellationsParams {
|
|
|
54
58
|
signer: SignerLike;
|
|
55
59
|
orderUids: string[];
|
|
56
60
|
signingScheme: EcdsaSigningScheme;
|
|
61
|
+
env?: CowEnv;
|
|
62
|
+
settlementContractOverride?: Partial<AddressPerChain>;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
declare const ORDER_PRIMARY_TYPE: "Order";
|
|
@@ -117,7 +123,7 @@ declare class OrderSigningUtils {
|
|
|
117
123
|
* @param {Signer} signer The signer who is placing the order intent.
|
|
118
124
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the order.
|
|
119
125
|
*/
|
|
120
|
-
static signOrder(order: UnsignedOrder, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
126
|
+
static signOrder(order: UnsignedOrder, chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
121
127
|
/**
|
|
122
128
|
* Sign a cancellation message of an order intent with the specified signer.
|
|
123
129
|
* @param {string} orderUid The unique identifier of the order to cancel.
|
|
@@ -125,7 +131,7 @@ declare class OrderSigningUtils {
|
|
|
125
131
|
* @param {Signer} signer The signer who initially placed the order intent.
|
|
126
132
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
127
133
|
*/
|
|
128
|
-
static signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
134
|
+
static signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
129
135
|
/**
|
|
130
136
|
* Sign a cancellation message of multiple order intents with the specified signer.
|
|
131
137
|
* @param {string[]} orderUids An array of `orderUid` to cancel.
|
|
@@ -133,21 +139,21 @@ declare class OrderSigningUtils {
|
|
|
133
139
|
* @param {Signer} signer The signer who initially placed the order intents.
|
|
134
140
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
135
141
|
*/
|
|
136
|
-
static signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
142
|
+
static signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer, options?: ProtocolOptions): Promise<SigningResult>;
|
|
137
143
|
/**
|
|
138
144
|
* Get the EIP-712 typed domain data being used for signing.
|
|
139
145
|
* @param {SupportedChainId} chainId The CoW Protocol `chainId` context that's being used.
|
|
140
146
|
* @return The EIP-712 typed domain data.
|
|
141
147
|
* @see https://eips.ethereum.org/EIPS/eip-712
|
|
142
148
|
*/
|
|
143
|
-
static getDomain(chainId: SupportedChainId): Promise<TypedDataDomain>;
|
|
149
|
+
static getDomain(chainId: SupportedChainId, options?: ProtocolOptions): Promise<TypedDataDomain>;
|
|
144
150
|
/**
|
|
145
151
|
* Hashes the order intent and generate deterministic order ID.
|
|
146
152
|
* @param {SupportedChainId} chainId The CoW Protocol `chainId` context that's being used.
|
|
147
153
|
* @param {Order} order order to sign
|
|
148
154
|
* @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.
|
|
149
155
|
*/
|
|
150
|
-
static generateOrderId(chainId: SupportedChainId, order: ContractsOrder, params: Pick<OrderUidParams, 'owner'
|
|
156
|
+
static generateOrderId(chainId: SupportedChainId, order: ContractsOrder, params: Pick<OrderUidParams, 'owner'>, options?: ProtocolOptions): Promise<{
|
|
151
157
|
orderId: string;
|
|
152
158
|
orderDigest: string;
|
|
153
159
|
}>;
|
|
@@ -156,7 +162,7 @@ declare class OrderSigningUtils {
|
|
|
156
162
|
* @param chainId {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
157
163
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
158
164
|
*/
|
|
159
|
-
static getDomainSeparator(chainId: SupportedChainId): Promise<string>;
|
|
165
|
+
static getDomainSeparator(chainId: SupportedChainId, options?: ProtocolOptions): Promise<string>;
|
|
160
166
|
static getEIP712Types(): typeof COW_EIP712_TYPES;
|
|
161
167
|
/**
|
|
162
168
|
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
package/dist/index.js
CHANGED
|
@@ -49,18 +49,18 @@ function isProviderRpcError(error) {
|
|
|
49
49
|
return error.code !== void 0 || error.message !== void 0;
|
|
50
50
|
}
|
|
51
51
|
async function _signOrder(params) {
|
|
52
|
-
const { chainId, signer, order, signingScheme } = params;
|
|
53
|
-
const domain = getDomain(chainId);
|
|
52
|
+
const { chainId, signer, order, signingScheme, env, settlementContractOverride } = params;
|
|
53
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
54
54
|
return (0, import_sdk_contracts_ts.signOrder)(domain, order, mapSigningSchema[signingScheme], signer);
|
|
55
55
|
}
|
|
56
56
|
async function _signOrderCancellation(params) {
|
|
57
|
-
const { chainId, signer, signingScheme, orderUid } = params;
|
|
58
|
-
const domain = getDomain(chainId);
|
|
57
|
+
const { chainId, signer, signingScheme, orderUid, env, settlementContractOverride } = params;
|
|
58
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
59
59
|
return (0, import_sdk_contracts_ts.signOrderCancellation)(domain, orderUid, mapSigningSchema[signingScheme], signer);
|
|
60
60
|
}
|
|
61
61
|
async function _signOrderCancellations(params) {
|
|
62
|
-
const { chainId, signer, signingScheme, orderUids } = params;
|
|
63
|
-
const domain = getDomain(chainId);
|
|
62
|
+
const { chainId, signer, signingScheme, orderUids, env, settlementContractOverride } = params;
|
|
63
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
64
64
|
return (0, import_sdk_contracts_ts.signOrderCancellations)(domain, orderUids, mapSigningSchema[signingScheme], signer);
|
|
65
65
|
}
|
|
66
66
|
async function _signPayload(payload, signFn, signer, signingMethod = "v4") {
|
|
@@ -123,24 +123,28 @@ async function _signPayload(payload, signFn, signer, signingMethod = "v4") {
|
|
|
123
123
|
const data = signature?.data;
|
|
124
124
|
return { signature: data?.toString() || "", signingScheme };
|
|
125
125
|
}
|
|
126
|
-
async function signOrder(order, chainId, signer) {
|
|
127
|
-
|
|
126
|
+
async function signOrder(order, chainId, signer, options) {
|
|
127
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
128
|
+
return _signPayload({ order, chainId, env, settlementContractOverride }, _signOrder, signer);
|
|
128
129
|
}
|
|
129
|
-
async function signOrderCancellation(orderUid, chainId, signer) {
|
|
130
|
-
|
|
130
|
+
async function signOrderCancellation(orderUid, chainId, signer, options) {
|
|
131
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
132
|
+
return _signPayload({ orderUid, chainId, env, settlementContractOverride }, _signOrderCancellation, signer);
|
|
131
133
|
}
|
|
132
|
-
async function signOrderCancellations(orderUids, chainId, signer) {
|
|
133
|
-
|
|
134
|
+
async function signOrderCancellations(orderUids, chainId, signer, options) {
|
|
135
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
136
|
+
return _signPayload({ orderUids, chainId, env, settlementContractOverride }, _signOrderCancellations, signer);
|
|
134
137
|
}
|
|
135
|
-
function getDomain(chainId) {
|
|
136
|
-
const
|
|
138
|
+
function getDomain(chainId, options) {
|
|
139
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
140
|
+
const settlementContract = settlementContractOverride?.[chainId] ?? (env === "staging" ? import_sdk_config.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS_STAGING[chainId] : import_sdk_config.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]);
|
|
137
141
|
if (!settlementContract) {
|
|
138
142
|
throw new import_sdk_common.CowError("Unsupported network. Settlement contract is not deployed");
|
|
139
143
|
}
|
|
140
144
|
return import_sdk_contracts_ts.ContractsTs.domain(chainId, settlementContract);
|
|
141
145
|
}
|
|
142
|
-
async function generateOrderId(chainId, order, params) {
|
|
143
|
-
const domain = await getDomain(chainId);
|
|
146
|
+
async function generateOrderId(chainId, order, params, options) {
|
|
147
|
+
const domain = await getDomain(chainId, options);
|
|
144
148
|
const orderDigest = (0, import_sdk_contracts_ts.hashOrder)(domain, order);
|
|
145
149
|
const orderId = (0, import_sdk_contracts_ts.packOrderUidParams)({
|
|
146
150
|
...params,
|
|
@@ -182,8 +186,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
182
186
|
* @param {Signer} signer The signer who is placing the order intent.
|
|
183
187
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the order.
|
|
184
188
|
*/
|
|
185
|
-
static async signOrder(order, chainId, signer) {
|
|
186
|
-
return signOrder(order, chainId, signer);
|
|
189
|
+
static async signOrder(order, chainId, signer, options) {
|
|
190
|
+
return signOrder(order, chainId, signer, options);
|
|
187
191
|
}
|
|
188
192
|
/**
|
|
189
193
|
* Sign a cancellation message of an order intent with the specified signer.
|
|
@@ -192,8 +196,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
192
196
|
* @param {Signer} signer The signer who initially placed the order intent.
|
|
193
197
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
194
198
|
*/
|
|
195
|
-
static async signOrderCancellation(orderUid, chainId, signer) {
|
|
196
|
-
return signOrderCancellation(orderUid, chainId, signer);
|
|
199
|
+
static async signOrderCancellation(orderUid, chainId, signer, options) {
|
|
200
|
+
return signOrderCancellation(orderUid, chainId, signer, options);
|
|
197
201
|
}
|
|
198
202
|
/**
|
|
199
203
|
* Sign a cancellation message of multiple order intents with the specified signer.
|
|
@@ -202,8 +206,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
202
206
|
* @param {Signer} signer The signer who initially placed the order intents.
|
|
203
207
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
204
208
|
*/
|
|
205
|
-
static async signOrderCancellations(orderUids, chainId, signer) {
|
|
206
|
-
return signOrderCancellations(orderUids, chainId, signer);
|
|
209
|
+
static async signOrderCancellations(orderUids, chainId, signer, options) {
|
|
210
|
+
return signOrderCancellations(orderUids, chainId, signer, options);
|
|
207
211
|
}
|
|
208
212
|
/**
|
|
209
213
|
* Get the EIP-712 typed domain data being used for signing.
|
|
@@ -211,8 +215,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
211
215
|
* @return The EIP-712 typed domain data.
|
|
212
216
|
* @see https://eips.ethereum.org/EIPS/eip-712
|
|
213
217
|
*/
|
|
214
|
-
static async getDomain(chainId) {
|
|
215
|
-
return getDomain(chainId);
|
|
218
|
+
static async getDomain(chainId, options) {
|
|
219
|
+
return getDomain(chainId, options);
|
|
216
220
|
}
|
|
217
221
|
/**
|
|
218
222
|
* Hashes the order intent and generate deterministic order ID.
|
|
@@ -220,15 +224,15 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
220
224
|
* @param {Order} order order to sign
|
|
221
225
|
* @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.
|
|
222
226
|
*/
|
|
223
|
-
static async generateOrderId(chainId, order, params) {
|
|
224
|
-
return generateOrderId(chainId, order, params);
|
|
227
|
+
static async generateOrderId(chainId, order, params, options) {
|
|
228
|
+
return generateOrderId(chainId, order, params, options);
|
|
225
229
|
}
|
|
226
230
|
/**
|
|
227
231
|
* Get the domain separator hash for the EIP-712 typed domain data being used for signing.
|
|
228
232
|
* @param chainId {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
229
233
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
230
234
|
*/
|
|
231
|
-
static async getDomainSeparator(chainId) {
|
|
235
|
+
static async getDomainSeparator(chainId, options) {
|
|
232
236
|
const adapter = (0, import_sdk_common2.getGlobalAdapter)();
|
|
233
237
|
const types = [
|
|
234
238
|
{ name: "name", type: "string" },
|
|
@@ -236,7 +240,7 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
236
240
|
{ name: "chainId", type: "uint256" },
|
|
237
241
|
{ name: "verifyingContract", type: "address" }
|
|
238
242
|
];
|
|
239
|
-
return adapter.utils.hashDomain(getDomain(chainId), types);
|
|
243
|
+
return adapter.utils.hashDomain(getDomain(chainId, options), types);
|
|
240
244
|
}
|
|
241
245
|
static getEIP712Types() {
|
|
242
246
|
return COW_EIP712_TYPES;
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
} from "@cowprotocol/sdk-contracts-ts";
|
|
16
16
|
import { CowError } from "@cowprotocol/sdk-common";
|
|
17
17
|
import { EcdsaSigningScheme } from "@cowprotocol/sdk-order-book";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS,
|
|
20
|
+
COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS_STAGING
|
|
21
|
+
} from "@cowprotocol/sdk-config";
|
|
19
22
|
var METAMASK_SIGNATURE_ERROR_CODE = -32603;
|
|
20
23
|
var METHOD_NOT_FOUND_ERROR_CODE = -32601;
|
|
21
24
|
var METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i;
|
|
@@ -31,18 +34,18 @@ function isProviderRpcError(error) {
|
|
|
31
34
|
return error.code !== void 0 || error.message !== void 0;
|
|
32
35
|
}
|
|
33
36
|
async function _signOrder(params) {
|
|
34
|
-
const { chainId, signer, order, signingScheme } = params;
|
|
35
|
-
const domain = getDomain(chainId);
|
|
37
|
+
const { chainId, signer, order, signingScheme, env, settlementContractOverride } = params;
|
|
38
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
36
39
|
return signOrderGp(domain, order, mapSigningSchema[signingScheme], signer);
|
|
37
40
|
}
|
|
38
41
|
async function _signOrderCancellation(params) {
|
|
39
|
-
const { chainId, signer, signingScheme, orderUid } = params;
|
|
40
|
-
const domain = getDomain(chainId);
|
|
42
|
+
const { chainId, signer, signingScheme, orderUid, env, settlementContractOverride } = params;
|
|
43
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
41
44
|
return signOrderCancellationGp(domain, orderUid, mapSigningSchema[signingScheme], signer);
|
|
42
45
|
}
|
|
43
46
|
async function _signOrderCancellations(params) {
|
|
44
|
-
const { chainId, signer, signingScheme, orderUids } = params;
|
|
45
|
-
const domain = getDomain(chainId);
|
|
47
|
+
const { chainId, signer, signingScheme, orderUids, env, settlementContractOverride } = params;
|
|
48
|
+
const domain = getDomain(chainId, { env, settlementContractOverride });
|
|
46
49
|
return signOrderCancellationsGp(domain, orderUids, mapSigningSchema[signingScheme], signer);
|
|
47
50
|
}
|
|
48
51
|
async function _signPayload(payload, signFn, signer, signingMethod = "v4") {
|
|
@@ -105,24 +108,28 @@ async function _signPayload(payload, signFn, signer, signingMethod = "v4") {
|
|
|
105
108
|
const data = signature?.data;
|
|
106
109
|
return { signature: data?.toString() || "", signingScheme };
|
|
107
110
|
}
|
|
108
|
-
async function signOrder(order, chainId, signer) {
|
|
109
|
-
|
|
111
|
+
async function signOrder(order, chainId, signer, options) {
|
|
112
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
113
|
+
return _signPayload({ order, chainId, env, settlementContractOverride }, _signOrder, signer);
|
|
110
114
|
}
|
|
111
|
-
async function signOrderCancellation(orderUid, chainId, signer) {
|
|
112
|
-
|
|
115
|
+
async function signOrderCancellation(orderUid, chainId, signer, options) {
|
|
116
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
117
|
+
return _signPayload({ orderUid, chainId, env, settlementContractOverride }, _signOrderCancellation, signer);
|
|
113
118
|
}
|
|
114
|
-
async function signOrderCancellations(orderUids, chainId, signer) {
|
|
115
|
-
|
|
119
|
+
async function signOrderCancellations(orderUids, chainId, signer, options) {
|
|
120
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
121
|
+
return _signPayload({ orderUids, chainId, env, settlementContractOverride }, _signOrderCancellations, signer);
|
|
116
122
|
}
|
|
117
|
-
function getDomain(chainId) {
|
|
118
|
-
const
|
|
123
|
+
function getDomain(chainId, options) {
|
|
124
|
+
const { env, settlementContractOverride } = options ?? {};
|
|
125
|
+
const settlementContract = settlementContractOverride?.[chainId] ?? (env === "staging" ? COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS_STAGING[chainId] : COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]);
|
|
119
126
|
if (!settlementContract) {
|
|
120
127
|
throw new CowError("Unsupported network. Settlement contract is not deployed");
|
|
121
128
|
}
|
|
122
129
|
return ContractsTs.domain(chainId, settlementContract);
|
|
123
130
|
}
|
|
124
|
-
async function generateOrderId(chainId, order, params) {
|
|
125
|
-
const domain = await getDomain(chainId);
|
|
131
|
+
async function generateOrderId(chainId, order, params, options) {
|
|
132
|
+
const domain = await getDomain(chainId, options);
|
|
126
133
|
const orderDigest = hashOrder(domain, order);
|
|
127
134
|
const orderId = packOrderUidParams({
|
|
128
135
|
...params,
|
|
@@ -164,8 +171,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
164
171
|
* @param {Signer} signer The signer who is placing the order intent.
|
|
165
172
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the order.
|
|
166
173
|
*/
|
|
167
|
-
static async signOrder(order, chainId, signer) {
|
|
168
|
-
return signOrder(order, chainId, signer);
|
|
174
|
+
static async signOrder(order, chainId, signer, options) {
|
|
175
|
+
return signOrder(order, chainId, signer, options);
|
|
169
176
|
}
|
|
170
177
|
/**
|
|
171
178
|
* Sign a cancellation message of an order intent with the specified signer.
|
|
@@ -174,8 +181,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
174
181
|
* @param {Signer} signer The signer who initially placed the order intent.
|
|
175
182
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
176
183
|
*/
|
|
177
|
-
static async signOrderCancellation(orderUid, chainId, signer) {
|
|
178
|
-
return signOrderCancellation(orderUid, chainId, signer);
|
|
184
|
+
static async signOrderCancellation(orderUid, chainId, signer, options) {
|
|
185
|
+
return signOrderCancellation(orderUid, chainId, signer, options);
|
|
179
186
|
}
|
|
180
187
|
/**
|
|
181
188
|
* Sign a cancellation message of multiple order intents with the specified signer.
|
|
@@ -184,8 +191,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
184
191
|
* @param {Signer} signer The signer who initially placed the order intents.
|
|
185
192
|
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
186
193
|
*/
|
|
187
|
-
static async signOrderCancellations(orderUids, chainId, signer) {
|
|
188
|
-
return signOrderCancellations(orderUids, chainId, signer);
|
|
194
|
+
static async signOrderCancellations(orderUids, chainId, signer, options) {
|
|
195
|
+
return signOrderCancellations(orderUids, chainId, signer, options);
|
|
189
196
|
}
|
|
190
197
|
/**
|
|
191
198
|
* Get the EIP-712 typed domain data being used for signing.
|
|
@@ -193,8 +200,8 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
193
200
|
* @return The EIP-712 typed domain data.
|
|
194
201
|
* @see https://eips.ethereum.org/EIPS/eip-712
|
|
195
202
|
*/
|
|
196
|
-
static async getDomain(chainId) {
|
|
197
|
-
return getDomain(chainId);
|
|
203
|
+
static async getDomain(chainId, options) {
|
|
204
|
+
return getDomain(chainId, options);
|
|
198
205
|
}
|
|
199
206
|
/**
|
|
200
207
|
* Hashes the order intent and generate deterministic order ID.
|
|
@@ -202,15 +209,15 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
202
209
|
* @param {Order} order order to sign
|
|
203
210
|
* @param {Pick<OrderUidParams, 'owner'>} params order unique identifier parameters.
|
|
204
211
|
*/
|
|
205
|
-
static async generateOrderId(chainId, order, params) {
|
|
206
|
-
return generateOrderId(chainId, order, params);
|
|
212
|
+
static async generateOrderId(chainId, order, params, options) {
|
|
213
|
+
return generateOrderId(chainId, order, params, options);
|
|
207
214
|
}
|
|
208
215
|
/**
|
|
209
216
|
* Get the domain separator hash for the EIP-712 typed domain data being used for signing.
|
|
210
217
|
* @param chainId {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
211
218
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
212
219
|
*/
|
|
213
|
-
static async getDomainSeparator(chainId) {
|
|
220
|
+
static async getDomainSeparator(chainId, options) {
|
|
214
221
|
const adapter = getGlobalAdapter();
|
|
215
222
|
const types = [
|
|
216
223
|
{ name: "name", type: "string" },
|
|
@@ -218,7 +225,7 @@ var OrderSigningUtils = class _OrderSigningUtils {
|
|
|
218
225
|
{ name: "chainId", type: "uint256" },
|
|
219
226
|
{ name: "verifyingContract", type: "address" }
|
|
220
227
|
];
|
|
221
|
-
return adapter.utils.hashDomain(getDomain(chainId), types);
|
|
228
|
+
return adapter.utils.hashDomain(getDomain(chainId, options), types);
|
|
222
229
|
}
|
|
223
230
|
static getEIP712Types() {
|
|
224
231
|
return COW_EIP712_TYPES;
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-order-signing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript order signing for CoW Protocol SDK",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/cowprotocol/cow-sdk.git",
|
|
8
|
+
"directory": "packages/order-signing"
|
|
9
|
+
},
|
|
5
10
|
"main": "./dist/index.js",
|
|
6
11
|
"module": "./dist/index.mjs",
|
|
7
12
|
"types": "./dist/index.d.ts",
|
|
@@ -13,13 +18,29 @@
|
|
|
13
18
|
"publishConfig": {
|
|
14
19
|
"access": "public"
|
|
15
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
24
|
+
"lint": "eslint src/**/*.ts",
|
|
25
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "jest --watch",
|
|
28
|
+
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
|
|
29
|
+
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
16
33
|
"dependencies": {
|
|
17
|
-
"@cowprotocol/sdk-common": "
|
|
18
|
-
"@cowprotocol/sdk-config": "
|
|
19
|
-
"@cowprotocol/sdk-
|
|
20
|
-
"@cowprotocol/sdk-
|
|
34
|
+
"@cowprotocol/sdk-common": "workspace:*",
|
|
35
|
+
"@cowprotocol/sdk-config": "workspace:*",
|
|
36
|
+
"@cowprotocol/sdk-contracts-ts": "workspace:*",
|
|
37
|
+
"@cowprotocol/sdk-order-book": "workspace:*"
|
|
21
38
|
},
|
|
22
39
|
"devDependencies": {
|
|
40
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "workspace:*",
|
|
41
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "workspace:*",
|
|
42
|
+
"@cow-sdk/typescript-config": "workspace:*",
|
|
43
|
+
"@cowprotocol/sdk-viem-adapter": "workspace:*",
|
|
23
44
|
"@types/jest": "^29.5.5",
|
|
24
45
|
"@types/node": "^20.17.31",
|
|
25
46
|
"coveralls": "^3.1.1",
|
|
@@ -30,21 +51,6 @@
|
|
|
30
51
|
"eslint": "^8.48.0",
|
|
31
52
|
"tsup": "^7.2.0",
|
|
32
53
|
"typescript": "^5.2.2",
|
|
33
|
-
"viem": "^2.28.4"
|
|
34
|
-
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.11",
|
|
35
|
-
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.11",
|
|
36
|
-
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
37
|
-
"@cowprotocol/sdk-viem-adapter": "0.3.11"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
41
|
-
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
42
|
-
"lint": "eslint src/**/*.ts",
|
|
43
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
44
|
-
"test": "jest",
|
|
45
|
-
"test:watch": "jest --watch",
|
|
46
|
-
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
|
|
47
|
-
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
48
|
-
"typecheck": "tsc --noEmit"
|
|
54
|
+
"viem": "^2.28.4"
|
|
49
55
|
}
|
|
50
|
-
}
|
|
56
|
+
}
|