@cowprotocol/sdk-order-signing 0.1.6 → 0.1.7
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 +36 -5
- package/dist/index.d.ts +36 -5
- package/dist/index.js +78 -20
- package/dist/index.mjs +76 -20
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -56,6 +56,17 @@ interface SignOrderCancellationsParams {
|
|
|
56
56
|
signingScheme: EcdsaSigningScheme;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
declare const ORDER_PRIMARY_TYPE: "Order";
|
|
60
|
+
/**
|
|
61
|
+
* The EIP-712 types used for signing a GPv2Order.Data struct. This is useful for when
|
|
62
|
+
* signing orders using smart contracts, whereby this SDK cannot do the EIP-1271 signing for you.
|
|
63
|
+
*/
|
|
64
|
+
declare const COW_EIP712_TYPES: {
|
|
65
|
+
Order: {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
59
70
|
/**
|
|
60
71
|
* Utility class for signing order intents and cancellations.
|
|
61
72
|
*
|
|
@@ -146,12 +157,32 @@ declare class OrderSigningUtils {
|
|
|
146
157
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
147
158
|
*/
|
|
148
159
|
static getDomainSeparator(chainId: SupportedChainId): Promise<string>;
|
|
160
|
+
static getEIP712Types(): typeof COW_EIP712_TYPES;
|
|
149
161
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
162
|
+
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
|
163
|
+
*
|
|
164
|
+
* @remarks This method encodes the order data and ECDSA signature into a format suitable for
|
|
165
|
+
* EIP-1271 signature verification by smart contracts. The order struct is ABI-encoded
|
|
166
|
+
* as a tuple along with the ECDSA signature bytes. String fields in the order are
|
|
167
|
+
* hashed using keccak256 before encoding.
|
|
168
|
+
*
|
|
169
|
+
* @param {UnsignedOrder} orderToSign The unsigned order to encode for EIP-1271 verification.
|
|
170
|
+
* @param {string} ecdsaSignature The ECDSA signature (typically 65 bytes hex-encoded) to include in the encoding.
|
|
171
|
+
* @returns {string} The ABI-encoded order struct and signature, ready for EIP-1271 verification.
|
|
172
|
+
*
|
|
173
|
+
* @see https://eips.ethereum.org/EIPS/eip-1271
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const orderToSign: UnsignedOrder = { ... }
|
|
178
|
+
* const ecdsaSignature = '0x...' // 65 bytes signature from signing the order
|
|
179
|
+
*
|
|
180
|
+
* const eip1271Signature = OrderSigningUtils.getEip1271Signature(orderToSign, ecdsaSignature)
|
|
181
|
+
* // Use eip1271Signature with a smart contract wallet that implements EIP-1271
|
|
182
|
+
* ```
|
|
153
183
|
*/
|
|
154
|
-
static
|
|
184
|
+
static getEip1271Signature(orderToSign: UnsignedOrder, ecdsaSignature: string): string;
|
|
185
|
+
static encodeUnsignedOrder(orderToSign: UnsignedOrder): Record<string, string>;
|
|
155
186
|
}
|
|
156
187
|
|
|
157
|
-
export { OrderSigningUtils, type SignOrderCancellationParams, type SignOrderCancellationsParams, type SignOrderParams, type SigningResult, type UnsignedOrder };
|
|
188
|
+
export { COW_EIP712_TYPES, ORDER_PRIMARY_TYPE, OrderSigningUtils, type SignOrderCancellationParams, type SignOrderCancellationsParams, type SignOrderParams, type SigningResult, type UnsignedOrder };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,17 @@ interface SignOrderCancellationsParams {
|
|
|
56
56
|
signingScheme: EcdsaSigningScheme;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
declare const ORDER_PRIMARY_TYPE: "Order";
|
|
60
|
+
/**
|
|
61
|
+
* The EIP-712 types used for signing a GPv2Order.Data struct. This is useful for when
|
|
62
|
+
* signing orders using smart contracts, whereby this SDK cannot do the EIP-1271 signing for you.
|
|
63
|
+
*/
|
|
64
|
+
declare const COW_EIP712_TYPES: {
|
|
65
|
+
Order: {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
59
70
|
/**
|
|
60
71
|
* Utility class for signing order intents and cancellations.
|
|
61
72
|
*
|
|
@@ -146,12 +157,32 @@ declare class OrderSigningUtils {
|
|
|
146
157
|
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
147
158
|
*/
|
|
148
159
|
static getDomainSeparator(chainId: SupportedChainId): Promise<string>;
|
|
160
|
+
static getEIP712Types(): typeof COW_EIP712_TYPES;
|
|
149
161
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
162
|
+
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
|
163
|
+
*
|
|
164
|
+
* @remarks This method encodes the order data and ECDSA signature into a format suitable for
|
|
165
|
+
* EIP-1271 signature verification by smart contracts. The order struct is ABI-encoded
|
|
166
|
+
* as a tuple along with the ECDSA signature bytes. String fields in the order are
|
|
167
|
+
* hashed using keccak256 before encoding.
|
|
168
|
+
*
|
|
169
|
+
* @param {UnsignedOrder} orderToSign The unsigned order to encode for EIP-1271 verification.
|
|
170
|
+
* @param {string} ecdsaSignature The ECDSA signature (typically 65 bytes hex-encoded) to include in the encoding.
|
|
171
|
+
* @returns {string} The ABI-encoded order struct and signature, ready for EIP-1271 verification.
|
|
172
|
+
*
|
|
173
|
+
* @see https://eips.ethereum.org/EIPS/eip-1271
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const orderToSign: UnsignedOrder = { ... }
|
|
178
|
+
* const ecdsaSignature = '0x...' // 65 bytes signature from signing the order
|
|
179
|
+
*
|
|
180
|
+
* const eip1271Signature = OrderSigningUtils.getEip1271Signature(orderToSign, ecdsaSignature)
|
|
181
|
+
* // Use eip1271Signature with a smart contract wallet that implements EIP-1271
|
|
182
|
+
* ```
|
|
153
183
|
*/
|
|
154
|
-
static
|
|
184
|
+
static getEip1271Signature(orderToSign: UnsignedOrder, ecdsaSignature: string): string;
|
|
185
|
+
static encodeUnsignedOrder(orderToSign: UnsignedOrder): Record<string, string>;
|
|
155
186
|
}
|
|
156
187
|
|
|
157
|
-
export { OrderSigningUtils, type SignOrderCancellationParams, type SignOrderCancellationsParams, type SignOrderParams, type SigningResult, type UnsignedOrder };
|
|
188
|
+
export { COW_EIP712_TYPES, ORDER_PRIMARY_TYPE, OrderSigningUtils, type SignOrderCancellationParams, type SignOrderCancellationsParams, type SignOrderParams, type SigningResult, type UnsignedOrder };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
COW_EIP712_TYPES: () => COW_EIP712_TYPES,
|
|
24
|
+
ORDER_PRIMARY_TYPE: () => ORDER_PRIMARY_TYPE,
|
|
23
25
|
OrderSigningUtils: () => OrderSigningUtils
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -150,7 +152,25 @@ async function generateOrderId(chainId, order, params) {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// src/orderSigningUtils.ts
|
|
153
|
-
var
|
|
155
|
+
var import_sdk_order_book2 = require("@cowprotocol/sdk-order-book");
|
|
156
|
+
var ORDER_PRIMARY_TYPE = "Order";
|
|
157
|
+
var COW_EIP712_TYPES = {
|
|
158
|
+
[ORDER_PRIMARY_TYPE]: [
|
|
159
|
+
{ name: "sellToken", type: "address" },
|
|
160
|
+
{ name: "buyToken", type: "address" },
|
|
161
|
+
{ name: "receiver", type: "address" },
|
|
162
|
+
{ name: "sellAmount", type: "uint256" },
|
|
163
|
+
{ name: "buyAmount", type: "uint256" },
|
|
164
|
+
{ name: "validTo", type: "uint32" },
|
|
165
|
+
{ name: "appData", type: "bytes32" },
|
|
166
|
+
{ name: "feeAmount", type: "uint256" },
|
|
167
|
+
{ name: "kind", type: "string" },
|
|
168
|
+
{ name: "partiallyFillable", type: "bool" },
|
|
169
|
+
{ name: "sellTokenBalance", type: "string" },
|
|
170
|
+
{ name: "buyTokenBalance", type: "string" }
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
var OrderSigningUtils = class _OrderSigningUtils {
|
|
154
174
|
/**
|
|
155
175
|
* Sign the order intent with the specified signer.
|
|
156
176
|
*
|
|
@@ -218,31 +238,69 @@ var OrderSigningUtils = class {
|
|
|
218
238
|
];
|
|
219
239
|
return adapter.utils.hashDomain(getDomain(chainId), types);
|
|
220
240
|
}
|
|
241
|
+
static getEIP712Types() {
|
|
242
|
+
return COW_EIP712_TYPES;
|
|
243
|
+
}
|
|
221
244
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @
|
|
245
|
+
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
|
246
|
+
*
|
|
247
|
+
* @remarks This method encodes the order data and ECDSA signature into a format suitable for
|
|
248
|
+
* EIP-1271 signature verification by smart contracts. The order struct is ABI-encoded
|
|
249
|
+
* as a tuple along with the ECDSA signature bytes. String fields in the order are
|
|
250
|
+
* hashed using keccak256 before encoding.
|
|
251
|
+
*
|
|
252
|
+
* @param {UnsignedOrder} orderToSign The unsigned order to encode for EIP-1271 verification.
|
|
253
|
+
* @param {string} ecdsaSignature The ECDSA signature (typically 65 bytes hex-encoded) to include in the encoding.
|
|
254
|
+
* @returns {string} The ABI-encoded order struct and signature, ready for EIP-1271 verification.
|
|
255
|
+
*
|
|
256
|
+
* @see https://eips.ethereum.org/EIPS/eip-1271
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const orderToSign: UnsignedOrder = { ... }
|
|
261
|
+
* const ecdsaSignature = '0x...' // 65 bytes signature from signing the order
|
|
262
|
+
*
|
|
263
|
+
* const eip1271Signature = OrderSigningUtils.getEip1271Signature(orderToSign, ecdsaSignature)
|
|
264
|
+
* // Use eip1271Signature with a smart contract wallet that implements EIP-1271
|
|
265
|
+
* ```
|
|
225
266
|
*/
|
|
226
|
-
static
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
{
|
|
241
|
-
]
|
|
267
|
+
static getEip1271Signature(orderToSign, ecdsaSignature) {
|
|
268
|
+
const adapter = (0, import_sdk_common2.getGlobalAdapter)();
|
|
269
|
+
const EIP712Types = COW_EIP712_TYPES[ORDER_PRIMARY_TYPE];
|
|
270
|
+
const components = EIP712Types.map((component) => ({
|
|
271
|
+
name: component.name,
|
|
272
|
+
type: component.type === "string" ? "bytes32" : component.type
|
|
273
|
+
}));
|
|
274
|
+
const values = Object.values(_OrderSigningUtils.encodeUnsignedOrder(orderToSign));
|
|
275
|
+
return adapter.utils.encodeAbi(
|
|
276
|
+
[
|
|
277
|
+
{
|
|
278
|
+
components,
|
|
279
|
+
type: "tuple"
|
|
280
|
+
},
|
|
281
|
+
{ type: "bytes" }
|
|
282
|
+
],
|
|
283
|
+
[values, ecdsaSignature]
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
static encodeUnsignedOrder(orderToSign) {
|
|
287
|
+
const order = {
|
|
288
|
+
...orderToSign,
|
|
289
|
+
sellTokenBalance: orderToSign.sellTokenBalance ?? import_sdk_order_book2.SellTokenSource.ERC20,
|
|
290
|
+
buyTokenBalance: orderToSign.buyTokenBalance ?? import_sdk_order_book2.BuyTokenDestination.ERC20
|
|
242
291
|
};
|
|
292
|
+
const adapter = (0, import_sdk_common2.getGlobalAdapter)();
|
|
293
|
+
const EIP712Types = COW_EIP712_TYPES[ORDER_PRIMARY_TYPE];
|
|
294
|
+
return EIP712Types.reduce((acc, { name, type }) => {
|
|
295
|
+
const value = order[name];
|
|
296
|
+
acc[name] = type === "string" ? String(adapter.utils.id(value)) : value;
|
|
297
|
+
return acc;
|
|
298
|
+
}, {});
|
|
243
299
|
}
|
|
244
300
|
};
|
|
245
301
|
// Annotate the CommonJS export names for ESM import in node:
|
|
246
302
|
0 && (module.exports = {
|
|
303
|
+
COW_EIP712_TYPES,
|
|
304
|
+
ORDER_PRIMARY_TYPE,
|
|
247
305
|
OrderSigningUtils
|
|
248
306
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -134,7 +134,25 @@ async function generateOrderId(chainId, order, params) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// src/orderSigningUtils.ts
|
|
137
|
-
|
|
137
|
+
import { BuyTokenDestination, SellTokenSource } from "@cowprotocol/sdk-order-book";
|
|
138
|
+
var ORDER_PRIMARY_TYPE = "Order";
|
|
139
|
+
var COW_EIP712_TYPES = {
|
|
140
|
+
[ORDER_PRIMARY_TYPE]: [
|
|
141
|
+
{ name: "sellToken", type: "address" },
|
|
142
|
+
{ name: "buyToken", type: "address" },
|
|
143
|
+
{ name: "receiver", type: "address" },
|
|
144
|
+
{ name: "sellAmount", type: "uint256" },
|
|
145
|
+
{ name: "buyAmount", type: "uint256" },
|
|
146
|
+
{ name: "validTo", type: "uint32" },
|
|
147
|
+
{ name: "appData", type: "bytes32" },
|
|
148
|
+
{ name: "feeAmount", type: "uint256" },
|
|
149
|
+
{ name: "kind", type: "string" },
|
|
150
|
+
{ name: "partiallyFillable", type: "bool" },
|
|
151
|
+
{ name: "sellTokenBalance", type: "string" },
|
|
152
|
+
{ name: "buyTokenBalance", type: "string" }
|
|
153
|
+
]
|
|
154
|
+
};
|
|
155
|
+
var OrderSigningUtils = class _OrderSigningUtils {
|
|
138
156
|
/**
|
|
139
157
|
* Sign the order intent with the specified signer.
|
|
140
158
|
*
|
|
@@ -202,30 +220,68 @@ var OrderSigningUtils = class {
|
|
|
202
220
|
];
|
|
203
221
|
return adapter.utils.hashDomain(getDomain(chainId), types);
|
|
204
222
|
}
|
|
223
|
+
static getEIP712Types() {
|
|
224
|
+
return COW_EIP712_TYPES;
|
|
225
|
+
}
|
|
205
226
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* @
|
|
227
|
+
* Encodes an order and ECDSA signature for EIP-1271 smart contract signature verification.
|
|
228
|
+
*
|
|
229
|
+
* @remarks This method encodes the order data and ECDSA signature into a format suitable for
|
|
230
|
+
* EIP-1271 signature verification by smart contracts. The order struct is ABI-encoded
|
|
231
|
+
* as a tuple along with the ECDSA signature bytes. String fields in the order are
|
|
232
|
+
* hashed using keccak256 before encoding.
|
|
233
|
+
*
|
|
234
|
+
* @param {UnsignedOrder} orderToSign The unsigned order to encode for EIP-1271 verification.
|
|
235
|
+
* @param {string} ecdsaSignature The ECDSA signature (typically 65 bytes hex-encoded) to include in the encoding.
|
|
236
|
+
* @returns {string} The ABI-encoded order struct and signature, ready for EIP-1271 verification.
|
|
237
|
+
*
|
|
238
|
+
* @see https://eips.ethereum.org/EIPS/eip-1271
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const orderToSign: UnsignedOrder = { ... }
|
|
243
|
+
* const ecdsaSignature = '0x...' // 65 bytes signature from signing the order
|
|
244
|
+
*
|
|
245
|
+
* const eip1271Signature = OrderSigningUtils.getEip1271Signature(orderToSign, ecdsaSignature)
|
|
246
|
+
* // Use eip1271Signature with a smart contract wallet that implements EIP-1271
|
|
247
|
+
* ```
|
|
209
248
|
*/
|
|
210
|
-
static
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
{
|
|
225
|
-
]
|
|
249
|
+
static getEip1271Signature(orderToSign, ecdsaSignature) {
|
|
250
|
+
const adapter = getGlobalAdapter();
|
|
251
|
+
const EIP712Types = COW_EIP712_TYPES[ORDER_PRIMARY_TYPE];
|
|
252
|
+
const components = EIP712Types.map((component) => ({
|
|
253
|
+
name: component.name,
|
|
254
|
+
type: component.type === "string" ? "bytes32" : component.type
|
|
255
|
+
}));
|
|
256
|
+
const values = Object.values(_OrderSigningUtils.encodeUnsignedOrder(orderToSign));
|
|
257
|
+
return adapter.utils.encodeAbi(
|
|
258
|
+
[
|
|
259
|
+
{
|
|
260
|
+
components,
|
|
261
|
+
type: "tuple"
|
|
262
|
+
},
|
|
263
|
+
{ type: "bytes" }
|
|
264
|
+
],
|
|
265
|
+
[values, ecdsaSignature]
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
static encodeUnsignedOrder(orderToSign) {
|
|
269
|
+
const order = {
|
|
270
|
+
...orderToSign,
|
|
271
|
+
sellTokenBalance: orderToSign.sellTokenBalance ?? SellTokenSource.ERC20,
|
|
272
|
+
buyTokenBalance: orderToSign.buyTokenBalance ?? BuyTokenDestination.ERC20
|
|
226
273
|
};
|
|
274
|
+
const adapter = getGlobalAdapter();
|
|
275
|
+
const EIP712Types = COW_EIP712_TYPES[ORDER_PRIMARY_TYPE];
|
|
276
|
+
return EIP712Types.reduce((acc, { name, type }) => {
|
|
277
|
+
const value = order[name];
|
|
278
|
+
acc[name] = type === "string" ? String(adapter.utils.id(value)) : value;
|
|
279
|
+
return acc;
|
|
280
|
+
}, {});
|
|
227
281
|
}
|
|
228
282
|
};
|
|
229
283
|
export {
|
|
284
|
+
COW_EIP712_TYPES,
|
|
285
|
+
ORDER_PRIMARY_TYPE,
|
|
230
286
|
OrderSigningUtils
|
|
231
287
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-order-signing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "TypeScript order signing for CoW Protocol SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@cowprotocol/sdk-common": "0.2.
|
|
18
|
-
"@cowprotocol/sdk-config": "0.
|
|
19
|
-
"@cowprotocol/sdk-
|
|
20
|
-
"@cowprotocol/sdk-
|
|
17
|
+
"@cowprotocol/sdk-common": "0.2.2",
|
|
18
|
+
"@cowprotocol/sdk-config": "0.2.0",
|
|
19
|
+
"@cowprotocol/sdk-contracts-ts": "0.4.1",
|
|
20
|
+
"@cowprotocol/sdk-order-book": "0.1.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/jest": "^29.5.5",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"tsup": "^7.2.0",
|
|
32
32
|
"typescript": "^5.2.2",
|
|
33
33
|
"viem": "^2.28.4",
|
|
34
|
-
"@cowprotocol/sdk-ethers-v5-adapter": "0.1.
|
|
35
|
-
"@cowprotocol/sdk-ethers-v6-adapter": "0.1.
|
|
34
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.1.3",
|
|
35
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.1.3",
|
|
36
36
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
37
|
-
"@cowprotocol/sdk-viem-adapter": "0.1.
|
|
37
|
+
"@cowprotocol/sdk-viem-adapter": "0.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|