@cowprotocol/sdk-cow-shed 0.1.0-monorepo.3 → 0.1.1

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/README.md CHANGED
@@ -10,8 +10,6 @@ In essence, CoW Shed acts as a user owned smart contract (1/1 multisig if you wi
10
10
 
11
11
  ## Usage
12
12
 
13
- ### Individual Package Usage
14
-
15
13
  ```ts
16
14
  import { ethers } from 'ethers'
17
15
  import { CowShedSdk, ICoWShedCall, SupportedChainId } from '@cowprotocol/cow-shed'
@@ -54,7 +52,7 @@ const preAuthorizedCall = await cowShedSdk.signCalls({
54
52
  })
55
53
 
56
54
  // Get the details of the pre-authorized call you need to send
57
- const { signedMulticall, gasLimit, cowShedAccount } = preAuthorizedCall
55
+ const { signedMulticall, gasLimit } = preAuthorizedCall
58
56
  const { to, data, value } = signedMulticall
59
57
 
60
58
  // Execute the transaction using any wallet. The calldata has been pre-authed, so you don't need any
@@ -86,57 +84,3 @@ const adapter = new EthersV6Adapter({ provider, signer: wallet })
86
84
  const cowShedSdk = new CowShedSdk(adapter) // adapter is optional - will use global adapter if not provided
87
85
  // ... rest of the usage remains the same
88
86
  ```
89
-
90
- ### Using with CowSdk Umbrella
91
-
92
- For a unified experience with all CoW Protocol modules:
93
-
94
- ```ts
95
- import { ethers } from 'ethers'
96
- import { CowSdk, SupportedChainId, ICoWShedCall } from '@cowprotocol/cow-sdk'
97
- import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
98
- import { JsonRpcProvider, Wallet } from 'ethers'
99
-
100
- // Proper adapter initialization
101
- const provider = new JsonRpcProvider('YOUR_RPC_URL')
102
- const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
103
- const adapter = new EthersV6Adapter({ provider, signer: wallet })
104
-
105
- const cowSdk = new CowSdk({
106
- adapter,
107
- chainId: SupportedChainId.MAINNET,
108
- })
109
-
110
- // Access cowShed through the umbrella SDK
111
- const cowShedSdk = cowSdk.cowShed
112
-
113
- // Prepare the calls you want to execute using the cow-shed account
114
- const calls: ICoWShedCall[] = [
115
- {
116
- target: '<contract-address-1>',
117
- callData: 'call-data-1',
118
- value: 0n,
119
- isDelegateCall: true,
120
- allowFailure: false,
121
- },
122
- ]
123
-
124
- // Sign the calls
125
- const preAuthorizedCall = await cowShedSdk.signCalls({
126
- chainId: SupportedChainId.MAINNET,
127
- calls,
128
- signer: '<privateKeyOrEthersSigner>', // signer is optional - will use global adapter's signer if not provided
129
- })
130
-
131
- // Execute the transaction using any wallet
132
- const { signedMulticall, gasLimit } = preAuthorizedCall
133
- const { to, data, value } = signedMulticall
134
-
135
- let anotherWallet = new ethers.Wallet('<another-private-key>')
136
- const tx = await anotherWallet.sendTransaction({
137
- to,
138
- data,
139
- value,
140
- gasLimit,
141
- })
142
- ```
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
- infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): {
54
- domain: unknown;
55
- types: {
56
- ExecuteHooks: {
57
- type: string;
58
- name: string;
59
- }[];
60
- Call: {
61
- type: string;
62
- name: string;
63
- }[];
64
- };
65
- message: {
66
- calls: ICoWShedCall[];
67
- nonce: string;
68
- deadline: bigint;
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 {
@@ -97,7 +106,7 @@ interface SignAndEncodeTxArgs {
97
106
  /**
98
107
  * Deadline to use for the transaction. If not provided, the maximum uint256 will be used.
99
108
  */
100
- deadline: bigint;
109
+ deadline?: bigint;
101
110
  /**
102
111
  * If value is provided, gas won't be estimated and will use the value
103
112
  */
@@ -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
- infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): {
54
- domain: unknown;
55
- types: {
56
- ExecuteHooks: {
57
- type: string;
58
- name: string;
59
- }[];
60
- Call: {
61
- type: string;
62
- name: string;
63
- }[];
64
- };
65
- message: {
66
- calls: ICoWShedCall[];
67
- nonce: string;
68
- deadline: bigint;
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 {
@@ -97,7 +106,7 @@ interface SignAndEncodeTxArgs {
97
106
  /**
98
107
  * Deadline to use for the transaction. If not provided, the maximum uint256 will be used.
99
108
  */
100
- deadline: bigint;
109
+ deadline?: bigint;
101
110
  /**
102
111
  * If value is provided, gas won't be estimated and will use the value
103
112
  */
@@ -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,19 +265,53 @@ 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 { domain, types, message } = this.infoToSign(calls, nonce, deadline, proxy);
244
- return await (0, import_sdk_contracts_ts.ecdsaSignTypedData)(signingScheme, domain, types, message, signer);
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 = {
248
312
  calls,
249
313
  nonce,
250
- deadline
314
+ deadline: deadline.toString()
251
315
  };
252
316
  return { domain: this.getDomain(proxy), types: COW_SHED_712_TYPES, message };
253
317
  }
@@ -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 { ecdsaSignTypedData } from "@cowprotocol/sdk-contracts-ts";
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,19 +236,53 @@ 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 { domain, types, message } = this.infoToSign(calls, nonce, deadline, proxy);
213
- return await ecdsaSignTypedData(signingScheme, domain, types, message, signer);
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 = {
217
283
  calls,
218
284
  nonce,
219
- deadline
285
+ deadline: deadline.toString()
220
286
  };
221
287
  return { domain: this.getDomain(proxy), types: COW_SHED_712_TYPES, message };
222
288
  }
@@ -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.1.0-monorepo.3",
3
+ "version": "0.1.1",
4
4
  "description": "CowProtocol Cow Shed package",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -13,27 +13,12 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
- "scripts": {
17
- "build": "tsup src/index.ts --format esm,cjs --dts",
18
- "lint": "eslint src/**/*.ts --quiet",
19
- "test": "jest",
20
- "test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
21
- "test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
22
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
23
- "typecheck": "tsc --noEmit",
24
- "publish": "npm publish --access public",
25
- "prepublishOnly": "npm run build"
26
- },
27
16
  "dependencies": {
28
- "@cowprotocol/sdk-config": "workspace:*",
29
- "@cowprotocol/sdk-common": "workspace:*",
30
- "@cowprotocol/sdk-contracts-ts": "workspace:*"
17
+ "@cowprotocol/sdk-config": "0.1.0",
18
+ "@cowprotocol/sdk-contracts-ts": "0.1.1",
19
+ "@cowprotocol/sdk-common": "0.1.0"
31
20
  },
32
21
  "devDependencies": {
33
- "@cow-sdk/typescript-config": "workspace:*",
34
- "@cowprotocol/sdk-ethers-v5-adapter": "workspace:*",
35
- "@cowprotocol/sdk-ethers-v6-adapter": "workspace:*",
36
- "@cowprotocol/sdk-viem-adapter": "workspace:*",
37
22
  "@types/jest": "^29.4.0",
38
23
  "@types/node": "^20.17.31",
39
24
  "@types/semver-sort": "^0.0.1",
@@ -47,6 +32,19 @@
47
32
  "ts-jest": "^29.0.0",
48
33
  "tsup": "^7.2.0",
49
34
  "tsx": "^4.19.4",
50
- "typescript": "^5.2.2"
35
+ "typescript": "^5.2.2",
36
+ "@cow-sdk/typescript-config": "0.0.0-beta.0",
37
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.1.0",
38
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.1.0",
39
+ "@cowprotocol/sdk-viem-adapter": "0.1.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup src/index.ts --format esm,cjs --dts",
43
+ "lint": "eslint src/**/*.ts --quiet",
44
+ "test": "jest",
45
+ "test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
46
+ "test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
47
+ "typecheck": "tsc --noEmit",
48
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
51
49
  }
52
- }
50
+ }