@cowprotocol/sdk-cow-shed 0.2.6-beta.0 → 0.3.0-beta.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 +29 -20
- package/dist/index.d.ts +29 -20
- package/dist/index.js +75 -4
- package/dist/index.mjs +77 -4
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SupportedChainId, EvmCall } from '@cowprotocol/sdk-config';
|
|
2
2
|
import { ContractsEcdsaSigningScheme } from '@cowprotocol/sdk-contracts-ts';
|
|
3
|
-
import { AbstractProviderAdapter, SignerLike, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
3
|
+
import { AbstractProviderAdapter, SignerLike, TypedDataContext, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
4
4
|
|
|
5
5
|
interface ICoWShedOptions {
|
|
6
6
|
factoryAddress: string;
|
|
@@ -31,6 +31,23 @@ declare const COW_SHED_PROXY_INIT_CODE: {
|
|
|
31
31
|
readonly "1.0.0": "0x60a034608e57601f61037138819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b490816100bd8239608051818181608f01526101720152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610018575b3661019457610194565b6000803560e01c908163025b22bc1461003b575063f851a4400361000e5761010d565b3461010a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261010a5773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610106577f0000000000000000000000000000000000000000000000000000000000000000163314600014610101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023d565b8380fd5b80fd5b346101645760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610164576020610146610169565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b333003610101577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ef575b1561023d5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101c0565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e1561027a573d90f35b3d90fdfea2646970667358221220c7c26ff3040b96a28e96d6d27b743972943aeaef81cc821544c5fe1e24f9b17264736f6c63430008190033";
|
|
32
32
|
readonly "1.0.1": "0x60a03461009557601f61033d38819003918201601f19168301916001600160401b0383118484101761009957808492604094855283398101031261009557610052602061004b836100ad565b92016100ad565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5560405161027b90816100c28239608051818181608b01526101750152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100955756fe60806040526004361015610018575b3661019757610197565b5f3560e01c8063025b22bc146100375763f851a4400361000e57610116565b346101125760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101125760043573ffffffffffffffffffffffffffffffffffffffff81169081810361011257337f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff160361010d577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2005b61023d565b5f80fd5b34610112575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011257602061014e61016c565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b33300361010d577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101f0575b1561023d577ff92ee8a9000000000000000000000000000000000000000000000000000000005f5260045ffd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000005f351614156101c3565b5f807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54368280378136915af43d5f803e15610277573d5ff35b3d5ffd";
|
|
33
33
|
};
|
|
34
|
+
declare const EIP1271_VALID_SIGNATURE_ABI: {
|
|
35
|
+
inputs: {
|
|
36
|
+
internalType: string;
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
39
|
+
}[];
|
|
40
|
+
name: string;
|
|
41
|
+
outputs: {
|
|
42
|
+
internalType: string;
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
}[];
|
|
46
|
+
stateMutability: string;
|
|
47
|
+
type: string;
|
|
48
|
+
}[];
|
|
49
|
+
declare class CoWShedEip1271SignatureInvalid extends Error {
|
|
50
|
+
}
|
|
34
51
|
|
|
35
52
|
declare const COW_SHED_712_TYPES: {
|
|
36
53
|
ExecuteHooks: {
|
|
@@ -49,29 +66,21 @@ declare class CowShedHooks {
|
|
|
49
66
|
constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
|
|
50
67
|
proxyOf(user: string): string;
|
|
51
68
|
encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* @throws CoWShedEip1271SignatureInvalid
|
|
71
|
+
*/
|
|
52
72
|
signCalls(calls: ICoWShedCall[], nonce: string, deadline: bigint, signingScheme: ContractsEcdsaSigningScheme, owner?: SignerLike): Promise<string>;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}[];
|
|
60
|
-
Call: {
|
|
61
|
-
type: string;
|
|
62
|
-
name: string;
|
|
63
|
-
}[];
|
|
64
|
-
};
|
|
65
|
-
message: {
|
|
66
|
-
calls: ICoWShedCall[];
|
|
67
|
-
nonce: string;
|
|
68
|
-
deadline: string;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
73
|
+
/**
|
|
74
|
+
* Verifies EIP1271 signature
|
|
75
|
+
* It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
|
|
76
|
+
*/
|
|
77
|
+
verifyEip1271Signature(account: string, signature: string, typedDataContext: TypedDataContext): Promise<boolean>;
|
|
78
|
+
infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): TypedDataContext;
|
|
71
79
|
getDomain(proxy: string): TypedDataDomain;
|
|
72
80
|
proxyCreationCode(): string;
|
|
73
81
|
getFactoryAddress(): string;
|
|
74
82
|
getImplementationAddress(): string;
|
|
83
|
+
private doesAccountHaveCode;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
interface SignAndEncodeTxArgs {
|
|
@@ -144,4 +153,4 @@ declare class CowShedSdk {
|
|
|
144
153
|
protected static getNonce(): string;
|
|
145
154
|
}
|
|
146
155
|
|
|
147
|
-
export { COW_SHED_1_0_0_VERSION, COW_SHED_1_0_1_VERSION, COW_SHED_712_TYPES, COW_SHED_FACTORY, COW_SHED_IMPLEMENTATION, COW_SHED_LATEST_VERSION, COW_SHED_PROXY_INIT_CODE, type CoWShedVersion, type CowShedCall, CowShedHooks, CowShedSdk, type CowShedSdkOptions, type ICoWShedCall, type ICoWShedOptions, type SignAndEncodeTxArgs };
|
|
156
|
+
export { COW_SHED_1_0_0_VERSION, COW_SHED_1_0_1_VERSION, COW_SHED_712_TYPES, COW_SHED_FACTORY, COW_SHED_IMPLEMENTATION, COW_SHED_LATEST_VERSION, COW_SHED_PROXY_INIT_CODE, CoWShedEip1271SignatureInvalid, type CoWShedVersion, type CowShedCall, CowShedHooks, CowShedSdk, type CowShedSdkOptions, EIP1271_VALID_SIGNATURE_ABI, type ICoWShedCall, type ICoWShedOptions, type SignAndEncodeTxArgs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SupportedChainId, EvmCall } from '@cowprotocol/sdk-config';
|
|
2
2
|
import { ContractsEcdsaSigningScheme } from '@cowprotocol/sdk-contracts-ts';
|
|
3
|
-
import { AbstractProviderAdapter, SignerLike, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
3
|
+
import { AbstractProviderAdapter, SignerLike, TypedDataContext, TypedDataDomain } from '@cowprotocol/sdk-common';
|
|
4
4
|
|
|
5
5
|
interface ICoWShedOptions {
|
|
6
6
|
factoryAddress: string;
|
|
@@ -31,6 +31,23 @@ declare const COW_SHED_PROXY_INIT_CODE: {
|
|
|
31
31
|
readonly "1.0.0": "0x60a034608e57601f61037138819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b490816100bd8239608051818181608f01526101720152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610018575b3661019457610194565b6000803560e01c908163025b22bc1461003b575063f851a4400361000e5761010d565b3461010a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261010a5773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610106577f0000000000000000000000000000000000000000000000000000000000000000163314600014610101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023d565b8380fd5b80fd5b346101645760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610164576020610146610169565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b333003610101577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ef575b1561023d5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101c0565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e1561027a573d90f35b3d90fdfea2646970667358221220c7c26ff3040b96a28e96d6d27b743972943aeaef81cc821544c5fe1e24f9b17264736f6c63430008190033";
|
|
32
32
|
readonly "1.0.1": "0x60a03461009557601f61033d38819003918201601f19168301916001600160401b0383118484101761009957808492604094855283398101031261009557610052602061004b836100ad565b92016100ad565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5560405161027b90816100c28239608051818181608b01526101750152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100955756fe60806040526004361015610018575b3661019757610197565b5f3560e01c8063025b22bc146100375763f851a4400361000e57610116565b346101125760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101125760043573ffffffffffffffffffffffffffffffffffffffff81169081810361011257337f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff160361010d577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2005b61023d565b5f80fd5b34610112575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011257602061014e61016c565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b33300361010d577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101f0575b1561023d577ff92ee8a9000000000000000000000000000000000000000000000000000000005f5260045ffd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000005f351614156101c3565b5f807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54368280378136915af43d5f803e15610277573d5ff35b3d5ffd";
|
|
33
33
|
};
|
|
34
|
+
declare const EIP1271_VALID_SIGNATURE_ABI: {
|
|
35
|
+
inputs: {
|
|
36
|
+
internalType: string;
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
39
|
+
}[];
|
|
40
|
+
name: string;
|
|
41
|
+
outputs: {
|
|
42
|
+
internalType: string;
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
}[];
|
|
46
|
+
stateMutability: string;
|
|
47
|
+
type: string;
|
|
48
|
+
}[];
|
|
49
|
+
declare class CoWShedEip1271SignatureInvalid extends Error {
|
|
50
|
+
}
|
|
34
51
|
|
|
35
52
|
declare const COW_SHED_712_TYPES: {
|
|
36
53
|
ExecuteHooks: {
|
|
@@ -49,29 +66,21 @@ declare class CowShedHooks {
|
|
|
49
66
|
constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
|
|
50
67
|
proxyOf(user: string): string;
|
|
51
68
|
encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* @throws CoWShedEip1271SignatureInvalid
|
|
71
|
+
*/
|
|
52
72
|
signCalls(calls: ICoWShedCall[], nonce: string, deadline: bigint, signingScheme: ContractsEcdsaSigningScheme, owner?: SignerLike): Promise<string>;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}[];
|
|
60
|
-
Call: {
|
|
61
|
-
type: string;
|
|
62
|
-
name: string;
|
|
63
|
-
}[];
|
|
64
|
-
};
|
|
65
|
-
message: {
|
|
66
|
-
calls: ICoWShedCall[];
|
|
67
|
-
nonce: string;
|
|
68
|
-
deadline: string;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
73
|
+
/**
|
|
74
|
+
* Verifies EIP1271 signature
|
|
75
|
+
* It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
|
|
76
|
+
*/
|
|
77
|
+
verifyEip1271Signature(account: string, signature: string, typedDataContext: TypedDataContext): Promise<boolean>;
|
|
78
|
+
infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): TypedDataContext;
|
|
71
79
|
getDomain(proxy: string): TypedDataDomain;
|
|
72
80
|
proxyCreationCode(): string;
|
|
73
81
|
getFactoryAddress(): string;
|
|
74
82
|
getImplementationAddress(): string;
|
|
83
|
+
private doesAccountHaveCode;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
interface SignAndEncodeTxArgs {
|
|
@@ -144,4 +153,4 @@ declare class CowShedSdk {
|
|
|
144
153
|
protected static getNonce(): string;
|
|
145
154
|
}
|
|
146
155
|
|
|
147
|
-
export { COW_SHED_1_0_0_VERSION, COW_SHED_1_0_1_VERSION, COW_SHED_712_TYPES, COW_SHED_FACTORY, COW_SHED_IMPLEMENTATION, COW_SHED_LATEST_VERSION, COW_SHED_PROXY_INIT_CODE, type CoWShedVersion, type CowShedCall, CowShedHooks, CowShedSdk, type CowShedSdkOptions, type ICoWShedCall, type ICoWShedOptions, type SignAndEncodeTxArgs };
|
|
156
|
+
export { COW_SHED_1_0_0_VERSION, COW_SHED_1_0_1_VERSION, COW_SHED_712_TYPES, COW_SHED_FACTORY, COW_SHED_IMPLEMENTATION, COW_SHED_LATEST_VERSION, COW_SHED_PROXY_INIT_CODE, CoWShedEip1271SignatureInvalid, type CoWShedVersion, type CowShedCall, CowShedHooks, CowShedSdk, type CowShedSdkOptions, EIP1271_VALID_SIGNATURE_ABI, type ICoWShedCall, type ICoWShedOptions, type SignAndEncodeTxArgs };
|
package/dist/index.js
CHANGED
|
@@ -27,8 +27,10 @@ __export(src_exports, {
|
|
|
27
27
|
COW_SHED_IMPLEMENTATION: () => COW_SHED_IMPLEMENTATION,
|
|
28
28
|
COW_SHED_LATEST_VERSION: () => COW_SHED_LATEST_VERSION,
|
|
29
29
|
COW_SHED_PROXY_INIT_CODE: () => COW_SHED_PROXY_INIT_CODE,
|
|
30
|
+
CoWShedEip1271SignatureInvalid: () => CoWShedEip1271SignatureInvalid,
|
|
30
31
|
CowShedHooks: () => CowShedHooks,
|
|
31
|
-
CowShedSdk: () => CowShedSdk
|
|
32
|
+
CowShedSdk: () => CowShedSdk,
|
|
33
|
+
EIP1271_VALID_SIGNATURE_ABI: () => EIP1271_VALID_SIGNATURE_ABI
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(src_exports);
|
|
34
36
|
|
|
@@ -188,6 +190,34 @@ var COW_SHED_PROXY_INIT_CODE = {
|
|
|
188
190
|
[COW_SHED_1_0_0_VERSION]: "0x60a034608e57601f61037138819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b490816100bd8239608051818181608f01526101720152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610018575b3661019457610194565b6000803560e01c908163025b22bc1461003b575063f851a4400361000e5761010d565b3461010a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261010a5773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610106577f0000000000000000000000000000000000000000000000000000000000000000163314600014610101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023d565b8380fd5b80fd5b346101645760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610164576020610146610169565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b333003610101577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ef575b1561023d5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101c0565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e1561027a573d90f35b3d90fdfea2646970667358221220c7c26ff3040b96a28e96d6d27b743972943aeaef81cc821544c5fe1e24f9b17264736f6c63430008190033",
|
|
189
191
|
[COW_SHED_1_0_1_VERSION]: "0x60a03461009557601f61033d38819003918201601f19168301916001600160401b0383118484101761009957808492604094855283398101031261009557610052602061004b836100ad565b92016100ad565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5560405161027b90816100c28239608051818181608b01526101750152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100955756fe60806040526004361015610018575b3661019757610197565b5f3560e01c8063025b22bc146100375763f851a4400361000e57610116565b346101125760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101125760043573ffffffffffffffffffffffffffffffffffffffff81169081810361011257337f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff160361010d577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2005b61023d565b5f80fd5b34610112575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011257602061014e61016c565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b33300361010d577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101f0575b1561023d577ff92ee8a9000000000000000000000000000000000000000000000000000000005f5260045ffd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000005f351614156101c3565b5f807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54368280378136915af43d5f803e15610277573d5ff35b3d5ffd"
|
|
190
192
|
};
|
|
193
|
+
var EIP1271_VALID_SIGNATURE_ABI = [
|
|
194
|
+
{
|
|
195
|
+
inputs: [
|
|
196
|
+
{
|
|
197
|
+
internalType: "bytes32",
|
|
198
|
+
name: "_hash",
|
|
199
|
+
type: "bytes32"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
internalType: "bytes",
|
|
203
|
+
name: "signature",
|
|
204
|
+
type: "bytes"
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
name: "isValidSignature",
|
|
208
|
+
outputs: [
|
|
209
|
+
{
|
|
210
|
+
internalType: "bytes4",
|
|
211
|
+
name: "magic",
|
|
212
|
+
type: "bytes4"
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
stateMutability: "view",
|
|
216
|
+
type: "function"
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
var CoWShedEip1271SignatureInvalid = class extends Error {
|
|
220
|
+
};
|
|
191
221
|
|
|
192
222
|
// src/contracts/CoWShedHooks.ts
|
|
193
223
|
var COW_SHED_712_TYPES = {
|
|
@@ -235,13 +265,47 @@ var CowShedHooks = class {
|
|
|
235
265
|
signature
|
|
236
266
|
]);
|
|
237
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* @throws CoWShedEip1271SignatureInvalid
|
|
270
|
+
*/
|
|
238
271
|
async signCalls(calls, nonce, deadline, signingScheme, owner) {
|
|
239
272
|
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
240
273
|
const signer = owner ? adapter.createSigner(owner) : adapter.signer;
|
|
241
274
|
const user = await signer.getAddress();
|
|
242
275
|
const proxy = this.proxyOf(user);
|
|
243
|
-
const
|
|
244
|
-
|
|
276
|
+
const typedDataContext = this.infoToSign(calls, nonce, deadline, proxy);
|
|
277
|
+
const { domain, types, message } = typedDataContext;
|
|
278
|
+
const signature = await (0, import_sdk_contracts_ts.ecdsaSignTypedData)(signingScheme, domain, types, message, signer);
|
|
279
|
+
const isAccountSmartContract = await this.doesAccountHaveCode(user);
|
|
280
|
+
const shouldValidateEip1271Signature = isAccountSmartContract && signingScheme === import_sdk_contracts_ts.ContractsSigningScheme.EIP712;
|
|
281
|
+
if (shouldValidateEip1271Signature) {
|
|
282
|
+
const isEip1271SignatureValid = await this.verifyEip1271Signature(user, signature, typedDataContext);
|
|
283
|
+
if (!isEip1271SignatureValid) {
|
|
284
|
+
throw new CoWShedEip1271SignatureInvalid("EIP1271 signature is invalid for CoW Shed");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return signature;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Verifies EIP1271 signature
|
|
291
|
+
* It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
|
|
292
|
+
*/
|
|
293
|
+
async verifyEip1271Signature(account, signature, typedDataContext) {
|
|
294
|
+
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
295
|
+
const { domain, types, message } = typedDataContext;
|
|
296
|
+
const hash = adapter.utils.hashTypedData(domain, types, message);
|
|
297
|
+
try {
|
|
298
|
+
const result = await adapter.readContract({
|
|
299
|
+
address: account,
|
|
300
|
+
abi: EIP1271_VALID_SIGNATURE_ABI,
|
|
301
|
+
functionName: "isValidSignature",
|
|
302
|
+
args: [hash, signature]
|
|
303
|
+
});
|
|
304
|
+
return result === import_sdk_contracts_ts.EIP1271_MAGICVALUE;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error("CoWShedHooks.verifyEip1271Signature", error);
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
245
309
|
}
|
|
246
310
|
infoToSign(calls, nonce, deadline, proxy) {
|
|
247
311
|
const message = {
|
|
@@ -268,6 +332,11 @@ var CowShedHooks = class {
|
|
|
268
332
|
getImplementationAddress() {
|
|
269
333
|
return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
|
|
270
334
|
}
|
|
335
|
+
async doesAccountHaveCode(account) {
|
|
336
|
+
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
337
|
+
const userAccountCode = await adapter.getCode(account);
|
|
338
|
+
return !!userAccountCode && userAccountCode !== "0x";
|
|
339
|
+
}
|
|
271
340
|
};
|
|
272
341
|
|
|
273
342
|
// src/CowShedSdk.ts
|
|
@@ -354,6 +423,8 @@ var CowShedSdk = class _CowShedSdk {
|
|
|
354
423
|
COW_SHED_IMPLEMENTATION,
|
|
355
424
|
COW_SHED_LATEST_VERSION,
|
|
356
425
|
COW_SHED_PROXY_INIT_CODE,
|
|
426
|
+
CoWShedEip1271SignatureInvalid,
|
|
357
427
|
CowShedHooks,
|
|
358
|
-
CowShedSdk
|
|
428
|
+
CowShedSdk,
|
|
429
|
+
EIP1271_VALID_SIGNATURE_ABI
|
|
359
430
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/contracts/CoWShedHooks.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ContractsSigningScheme,
|
|
4
|
+
ecdsaSignTypedData,
|
|
5
|
+
EIP1271_MAGICVALUE
|
|
6
|
+
} from "@cowprotocol/sdk-contracts-ts";
|
|
3
7
|
import {
|
|
4
8
|
getGlobalAdapter,
|
|
5
9
|
setGlobalAdapter
|
|
@@ -157,6 +161,34 @@ var COW_SHED_PROXY_INIT_CODE = {
|
|
|
157
161
|
[COW_SHED_1_0_0_VERSION]: "0x60a034608e57601f61037138819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b490816100bd8239608051818181608f01526101720152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610018575b3661019457610194565b6000803560e01c908163025b22bc1461003b575063f851a4400361000e5761010d565b3461010a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261010a5773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610106577f0000000000000000000000000000000000000000000000000000000000000000163314600014610101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023d565b8380fd5b80fd5b346101645760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610164576020610146610169565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b333003610101577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ef575b1561023d5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101c0565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e1561027a573d90f35b3d90fdfea2646970667358221220c7c26ff3040b96a28e96d6d27b743972943aeaef81cc821544c5fe1e24f9b17264736f6c63430008190033",
|
|
158
162
|
[COW_SHED_1_0_1_VERSION]: "0x60a03461009557601f61033d38819003918201601f19168301916001600160401b0383118484101761009957808492604094855283398101031261009557610052602061004b836100ad565b92016100ad565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5560405161027b90816100c28239608051818181608b01526101750152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100955756fe60806040526004361015610018575b3661019757610197565b5f3560e01c8063025b22bc146100375763f851a4400361000e57610116565b346101125760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101125760043573ffffffffffffffffffffffffffffffffffffffff81169081810361011257337f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff160361010d577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2005b61023d565b5f80fd5b34610112575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011257602061014e61016c565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b33300361010d577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101f0575b1561023d577ff92ee8a9000000000000000000000000000000000000000000000000000000005f5260045ffd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000005f351614156101c3565b5f807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54368280378136915af43d5f803e15610277573d5ff35b3d5ffd"
|
|
159
163
|
};
|
|
164
|
+
var EIP1271_VALID_SIGNATURE_ABI = [
|
|
165
|
+
{
|
|
166
|
+
inputs: [
|
|
167
|
+
{
|
|
168
|
+
internalType: "bytes32",
|
|
169
|
+
name: "_hash",
|
|
170
|
+
type: "bytes32"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
internalType: "bytes",
|
|
174
|
+
name: "signature",
|
|
175
|
+
type: "bytes"
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
name: "isValidSignature",
|
|
179
|
+
outputs: [
|
|
180
|
+
{
|
|
181
|
+
internalType: "bytes4",
|
|
182
|
+
name: "magic",
|
|
183
|
+
type: "bytes4"
|
|
184
|
+
}
|
|
185
|
+
],
|
|
186
|
+
stateMutability: "view",
|
|
187
|
+
type: "function"
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
var CoWShedEip1271SignatureInvalid = class extends Error {
|
|
191
|
+
};
|
|
160
192
|
|
|
161
193
|
// src/contracts/CoWShedHooks.ts
|
|
162
194
|
var COW_SHED_712_TYPES = {
|
|
@@ -204,13 +236,47 @@ var CowShedHooks = class {
|
|
|
204
236
|
signature
|
|
205
237
|
]);
|
|
206
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* @throws CoWShedEip1271SignatureInvalid
|
|
241
|
+
*/
|
|
207
242
|
async signCalls(calls, nonce, deadline, signingScheme, owner) {
|
|
208
243
|
const adapter = getGlobalAdapter();
|
|
209
244
|
const signer = owner ? adapter.createSigner(owner) : adapter.signer;
|
|
210
245
|
const user = await signer.getAddress();
|
|
211
246
|
const proxy = this.proxyOf(user);
|
|
212
|
-
const
|
|
213
|
-
|
|
247
|
+
const typedDataContext = this.infoToSign(calls, nonce, deadline, proxy);
|
|
248
|
+
const { domain, types, message } = typedDataContext;
|
|
249
|
+
const signature = await ecdsaSignTypedData(signingScheme, domain, types, message, signer);
|
|
250
|
+
const isAccountSmartContract = await this.doesAccountHaveCode(user);
|
|
251
|
+
const shouldValidateEip1271Signature = isAccountSmartContract && signingScheme === ContractsSigningScheme.EIP712;
|
|
252
|
+
if (shouldValidateEip1271Signature) {
|
|
253
|
+
const isEip1271SignatureValid = await this.verifyEip1271Signature(user, signature, typedDataContext);
|
|
254
|
+
if (!isEip1271SignatureValid) {
|
|
255
|
+
throw new CoWShedEip1271SignatureInvalid("EIP1271 signature is invalid for CoW Shed");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return signature;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Verifies EIP1271 signature
|
|
262
|
+
* It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
|
|
263
|
+
*/
|
|
264
|
+
async verifyEip1271Signature(account, signature, typedDataContext) {
|
|
265
|
+
const adapter = getGlobalAdapter();
|
|
266
|
+
const { domain, types, message } = typedDataContext;
|
|
267
|
+
const hash = adapter.utils.hashTypedData(domain, types, message);
|
|
268
|
+
try {
|
|
269
|
+
const result = await adapter.readContract({
|
|
270
|
+
address: account,
|
|
271
|
+
abi: EIP1271_VALID_SIGNATURE_ABI,
|
|
272
|
+
functionName: "isValidSignature",
|
|
273
|
+
args: [hash, signature]
|
|
274
|
+
});
|
|
275
|
+
return result === EIP1271_MAGICVALUE;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error("CoWShedHooks.verifyEip1271Signature", error);
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
214
280
|
}
|
|
215
281
|
infoToSign(calls, nonce, deadline, proxy) {
|
|
216
282
|
const message = {
|
|
@@ -237,6 +303,11 @@ var CowShedHooks = class {
|
|
|
237
303
|
getImplementationAddress() {
|
|
238
304
|
return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
|
|
239
305
|
}
|
|
306
|
+
async doesAccountHaveCode(account) {
|
|
307
|
+
const adapter = getGlobalAdapter();
|
|
308
|
+
const userAccountCode = await adapter.getCode(account);
|
|
309
|
+
return !!userAccountCode && userAccountCode !== "0x";
|
|
310
|
+
}
|
|
240
311
|
};
|
|
241
312
|
|
|
242
313
|
// src/CowShedSdk.ts
|
|
@@ -330,6 +401,8 @@ export {
|
|
|
330
401
|
COW_SHED_IMPLEMENTATION,
|
|
331
402
|
COW_SHED_LATEST_VERSION,
|
|
332
403
|
COW_SHED_PROXY_INIT_CODE,
|
|
404
|
+
CoWShedEip1271SignatureInvalid,
|
|
333
405
|
CowShedHooks,
|
|
334
|
-
CowShedSdk
|
|
406
|
+
CowShedSdk,
|
|
407
|
+
EIP1271_VALID_SIGNATURE_ABI
|
|
335
408
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-cow-shed",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.0",
|
|
4
4
|
"description": "CowProtocol Cow Shed package",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@cowprotocol/sdk-config": "0.3.3-beta.0",
|
|
18
|
-
"@cowprotocol/sdk-contracts-ts": "2.
|
|
19
|
-
"@cowprotocol/sdk-common": "0.
|
|
18
|
+
"@cowprotocol/sdk-contracts-ts": "2.3.0-beta.0",
|
|
19
|
+
"@cowprotocol/sdk-common": "0.5.0-beta.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/jest": "^29.4.0",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"tsx": "^4.19.4",
|
|
35
35
|
"typescript": "^5.2.2",
|
|
36
36
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
37
|
-
"@cowprotocol/sdk-ethers-
|
|
38
|
-
"@cowprotocol/sdk-
|
|
39
|
-
"@cowprotocol/sdk-
|
|
37
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.2.5-beta.0",
|
|
38
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.2.5-beta.0",
|
|
39
|
+
"@cowprotocol/sdk-viem-adapter": "0.3.1-beta.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|