@cowprotocol/sdk-cow-shed 0.2.0-beta.0 → 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/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: {
@@ -46,32 +63,26 @@ declare class CowShedHooks {
46
63
  private chainId;
47
64
  private customOptions?;
48
65
  readonly version: CoWShedVersion;
66
+ private eip1271SignatureCache;
67
+ private accountCodeCache;
49
68
  constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
50
69
  proxyOf(user: string): string;
51
70
  encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
71
+ /**
72
+ * @throws CoWShedEip1271SignatureInvalid
73
+ */
52
74
  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: string;
69
- };
70
- };
75
+ /**
76
+ * Verifies EIP1271 signature
77
+ * It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
78
+ */
79
+ verifyEip1271Signature(account: string, signature: string, typedDataContext: TypedDataContext): Promise<boolean>;
80
+ infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): TypedDataContext;
71
81
  getDomain(proxy: string): TypedDataDomain;
72
82
  proxyCreationCode(): string;
73
83
  getFactoryAddress(): string;
74
84
  getImplementationAddress(): string;
85
+ private doesAccountHaveCode;
75
86
  }
76
87
 
77
88
  interface SignAndEncodeTxArgs {
@@ -144,4 +155,4 @@ declare class CowShedSdk {
144
155
  protected static getNonce(): string;
145
156
  }
146
157
 
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 };
158
+ 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: {
@@ -46,32 +63,26 @@ declare class CowShedHooks {
46
63
  private chainId;
47
64
  private customOptions?;
48
65
  readonly version: CoWShedVersion;
66
+ private eip1271SignatureCache;
67
+ private accountCodeCache;
49
68
  constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
50
69
  proxyOf(user: string): string;
51
70
  encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
71
+ /**
72
+ * @throws CoWShedEip1271SignatureInvalid
73
+ */
52
74
  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: string;
69
- };
70
- };
75
+ /**
76
+ * Verifies EIP1271 signature
77
+ * It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
78
+ */
79
+ verifyEip1271Signature(account: string, signature: string, typedDataContext: TypedDataContext): Promise<boolean>;
80
+ infoToSign(calls: ICoWShedCall[], nonce: string, deadline: bigint, proxy: string): TypedDataContext;
71
81
  getDomain(proxy: string): TypedDataDomain;
72
82
  proxyCreationCode(): string;
73
83
  getFactoryAddress(): string;
74
84
  getImplementationAddress(): string;
85
+ private doesAccountHaveCode;
75
86
  }
76
87
 
77
88
  interface SignAndEncodeTxArgs {
@@ -144,4 +155,4 @@ declare class CowShedSdk {
144
155
  protected static getNonce(): string;
145
156
  }
146
157
 
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 };
158
+ 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 = {
@@ -204,6 +234,7 @@ var COW_SHED_712_TYPES = {
204
234
  { type: "bool", name: "isDelegateCall" }
205
235
  ]
206
236
  };
237
+ var FIVE_MINUTES = 5 * 60 * 1e3;
207
238
  var CowShedHooks = class {
208
239
  constructor(chainId, customOptions, version = COW_SHED_LATEST_VERSION, adapter) {
209
240
  this.chainId = chainId;
@@ -212,7 +243,11 @@ var CowShedHooks = class {
212
243
  if (adapter) {
213
244
  (0, import_sdk_common.setGlobalAdapter)(adapter);
214
245
  }
246
+ this.eip1271SignatureCache = new import_sdk_common.TTLCache("cowshed-eip1271-signature", true, FIVE_MINUTES);
247
+ this.accountCodeCache = new import_sdk_common.TTLCache("cowshed-account-code", true, FIVE_MINUTES);
215
248
  }
249
+ eip1271SignatureCache;
250
+ accountCodeCache;
216
251
  proxyOf(user) {
217
252
  const adapter = (0, import_sdk_common.getGlobalAdapter)();
218
253
  const salt = adapter.utils.encodeAbi(["address"], [user]);
@@ -235,13 +270,54 @@ var CowShedHooks = class {
235
270
  signature
236
271
  ]);
237
272
  }
273
+ /**
274
+ * @throws CoWShedEip1271SignatureInvalid
275
+ */
238
276
  async signCalls(calls, nonce, deadline, signingScheme, owner) {
239
277
  const adapter = (0, import_sdk_common.getGlobalAdapter)();
240
278
  const signer = owner ? adapter.createSigner(owner) : adapter.signer;
241
279
  const user = await signer.getAddress();
242
280
  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);
281
+ const typedDataContext = this.infoToSign(calls, nonce, deadline, proxy);
282
+ const { domain, types, message } = typedDataContext;
283
+ const signature = await (0, import_sdk_contracts_ts.ecdsaSignTypedData)(signingScheme, domain, types, message, signer);
284
+ const isAccountSmartContract = await this.doesAccountHaveCode(user);
285
+ const shouldValidateEip1271Signature = isAccountSmartContract && signingScheme === import_sdk_contracts_ts.ContractsSigningScheme.EIP712;
286
+ if (shouldValidateEip1271Signature) {
287
+ const isEip1271SignatureValid = await this.verifyEip1271Signature(user, signature, typedDataContext);
288
+ if (!isEip1271SignatureValid) {
289
+ throw new CoWShedEip1271SignatureInvalid("EIP1271 signature is invalid for CoW Shed");
290
+ }
291
+ }
292
+ return signature;
293
+ }
294
+ /**
295
+ * Verifies EIP1271 signature
296
+ * It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
297
+ */
298
+ async verifyEip1271Signature(account, signature, typedDataContext) {
299
+ const adapter = (0, import_sdk_common.getGlobalAdapter)();
300
+ const { domain, types, message } = typedDataContext;
301
+ const hash = adapter.utils.hashTypedData(domain, types, message);
302
+ const cacheKey = `${account}:${signature}:${hash}`;
303
+ const cachedResult = this.eip1271SignatureCache.get(cacheKey);
304
+ if (cachedResult !== void 0) {
305
+ return cachedResult;
306
+ }
307
+ try {
308
+ const result = await adapter.readContract({
309
+ address: account,
310
+ abi: EIP1271_VALID_SIGNATURE_ABI,
311
+ functionName: "isValidSignature",
312
+ args: [hash, signature]
313
+ });
314
+ const isValid = result === import_sdk_contracts_ts.EIP1271_MAGICVALUE;
315
+ this.eip1271SignatureCache.set(cacheKey, isValid);
316
+ return isValid;
317
+ } catch (error) {
318
+ console.error("CoWShedHooks.verifyEip1271Signature", error);
319
+ return false;
320
+ }
245
321
  }
246
322
  infoToSign(calls, nonce, deadline, proxy) {
247
323
  const message = {
@@ -268,6 +344,17 @@ var CowShedHooks = class {
268
344
  getImplementationAddress() {
269
345
  return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
270
346
  }
347
+ async doesAccountHaveCode(account) {
348
+ const cachedResult = this.accountCodeCache.get(account);
349
+ if (cachedResult !== void 0) {
350
+ return cachedResult;
351
+ }
352
+ const adapter = (0, import_sdk_common.getGlobalAdapter)();
353
+ const userAccountCode = await adapter.getCode(account);
354
+ const hasCode = !!userAccountCode && userAccountCode !== "0x";
355
+ this.accountCodeCache.set(account, hasCode);
356
+ return hasCode;
357
+ }
271
358
  };
272
359
 
273
360
  // src/CowShedSdk.ts
@@ -354,6 +441,8 @@ var CowShedSdk = class _CowShedSdk {
354
441
  COW_SHED_IMPLEMENTATION,
355
442
  COW_SHED_LATEST_VERSION,
356
443
  COW_SHED_PROXY_INIT_CODE,
444
+ CoWShedEip1271SignatureInvalid,
357
445
  CowShedHooks,
358
- CowShedSdk
446
+ CowShedSdk,
447
+ EIP1271_VALID_SIGNATURE_ABI
359
448
  });
package/dist/index.mjs CHANGED
@@ -1,8 +1,13 @@
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
- setGlobalAdapter
9
+ setGlobalAdapter,
10
+ TTLCache
6
11
  } from "@cowprotocol/sdk-common";
7
12
 
8
13
  // src/abi/CowShedFactoryAbi.ts
@@ -157,6 +162,34 @@ var COW_SHED_PROXY_INIT_CODE = {
157
162
  [COW_SHED_1_0_0_VERSION]: "0x60a034608e57601f61037138819003918201601f19168301916001600160401b038311848410176093578084926040948552833981010312608e57604b602060458360a9565b920160a9565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc556040516102b490816100bd8239608051818181608f01526101720152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203608e5756fe60806040526004361015610018575b3661019457610194565b6000803560e01c908163025b22bc1461003b575063f851a4400361000e5761010d565b3461010a5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261010a5773ffffffffffffffffffffffffffffffffffffffff60043581811691828203610106577f0000000000000000000000000000000000000000000000000000000000000000163314600014610101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8280a280f35b61023d565b8380fd5b80fd5b346101645760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610164576020610146610169565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b600080fd5b333003610101577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101ef575b1561023d5760046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000006000351614156101c0565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546000808092368280378136915af43d82803e1561027a573d90f35b3d90fdfea2646970667358221220c7c26ff3040b96a28e96d6d27b743972943aeaef81cc821544c5fe1e24f9b17264736f6c63430008190033",
158
163
  [COW_SHED_1_0_1_VERSION]: "0x60a03461009557601f61033d38819003918201601f19168301916001600160401b0383118484101761009957808492604094855283398101031261009557610052602061004b836100ad565b92016100ad565b6080527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5560405161027b90816100c28239608051818181608b01526101750152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100955756fe60806040526004361015610018575b3661019757610197565b5f3560e01c8063025b22bc146100375763f851a4400361000e57610116565b346101125760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101125760043573ffffffffffffffffffffffffffffffffffffffff81169081810361011257337f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff160361010d577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a2005b61023d565b5f80fd5b34610112575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011257602061014e61016c565b73ffffffffffffffffffffffffffffffffffffffff60405191168152f35b33300361010d577f000000000000000000000000000000000000000000000000000000000000000090565b60ff7f68df44b1011761f481358c0f49a711192727fb02c377d697bcb0ea8ff8393ac0541615806101f0575b1561023d577ff92ee8a9000000000000000000000000000000000000000000000000000000005f5260045ffd5b507f400ada75000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000005f351614156101c3565b5f807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54368280378136915af43d5f803e15610277573d5ff35b3d5ffd"
159
164
  };
165
+ var EIP1271_VALID_SIGNATURE_ABI = [
166
+ {
167
+ inputs: [
168
+ {
169
+ internalType: "bytes32",
170
+ name: "_hash",
171
+ type: "bytes32"
172
+ },
173
+ {
174
+ internalType: "bytes",
175
+ name: "signature",
176
+ type: "bytes"
177
+ }
178
+ ],
179
+ name: "isValidSignature",
180
+ outputs: [
181
+ {
182
+ internalType: "bytes4",
183
+ name: "magic",
184
+ type: "bytes4"
185
+ }
186
+ ],
187
+ stateMutability: "view",
188
+ type: "function"
189
+ }
190
+ ];
191
+ var CoWShedEip1271SignatureInvalid = class extends Error {
192
+ };
160
193
 
161
194
  // src/contracts/CoWShedHooks.ts
162
195
  var COW_SHED_712_TYPES = {
@@ -173,6 +206,7 @@ var COW_SHED_712_TYPES = {
173
206
  { type: "bool", name: "isDelegateCall" }
174
207
  ]
175
208
  };
209
+ var FIVE_MINUTES = 5 * 60 * 1e3;
176
210
  var CowShedHooks = class {
177
211
  constructor(chainId, customOptions, version = COW_SHED_LATEST_VERSION, adapter) {
178
212
  this.chainId = chainId;
@@ -181,7 +215,11 @@ var CowShedHooks = class {
181
215
  if (adapter) {
182
216
  setGlobalAdapter(adapter);
183
217
  }
218
+ this.eip1271SignatureCache = new TTLCache("cowshed-eip1271-signature", true, FIVE_MINUTES);
219
+ this.accountCodeCache = new TTLCache("cowshed-account-code", true, FIVE_MINUTES);
184
220
  }
221
+ eip1271SignatureCache;
222
+ accountCodeCache;
185
223
  proxyOf(user) {
186
224
  const adapter = getGlobalAdapter();
187
225
  const salt = adapter.utils.encodeAbi(["address"], [user]);
@@ -204,13 +242,54 @@ var CowShedHooks = class {
204
242
  signature
205
243
  ]);
206
244
  }
245
+ /**
246
+ * @throws CoWShedEip1271SignatureInvalid
247
+ */
207
248
  async signCalls(calls, nonce, deadline, signingScheme, owner) {
208
249
  const adapter = getGlobalAdapter();
209
250
  const signer = owner ? adapter.createSigner(owner) : adapter.signer;
210
251
  const user = await signer.getAddress();
211
252
  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);
253
+ const typedDataContext = this.infoToSign(calls, nonce, deadline, proxy);
254
+ const { domain, types, message } = typedDataContext;
255
+ const signature = await ecdsaSignTypedData(signingScheme, domain, types, message, signer);
256
+ const isAccountSmartContract = await this.doesAccountHaveCode(user);
257
+ const shouldValidateEip1271Signature = isAccountSmartContract && signingScheme === ContractsSigningScheme.EIP712;
258
+ if (shouldValidateEip1271Signature) {
259
+ const isEip1271SignatureValid = await this.verifyEip1271Signature(user, signature, typedDataContext);
260
+ if (!isEip1271SignatureValid) {
261
+ throw new CoWShedEip1271SignatureInvalid("EIP1271 signature is invalid for CoW Shed");
262
+ }
263
+ }
264
+ return signature;
265
+ }
266
+ /**
267
+ * Verifies EIP1271 signature
268
+ * It will return true only when isValidSignature() returns EIP1271_MAGICVALUE
269
+ */
270
+ async verifyEip1271Signature(account, signature, typedDataContext) {
271
+ const adapter = getGlobalAdapter();
272
+ const { domain, types, message } = typedDataContext;
273
+ const hash = adapter.utils.hashTypedData(domain, types, message);
274
+ const cacheKey = `${account}:${signature}:${hash}`;
275
+ const cachedResult = this.eip1271SignatureCache.get(cacheKey);
276
+ if (cachedResult !== void 0) {
277
+ return cachedResult;
278
+ }
279
+ try {
280
+ const result = await adapter.readContract({
281
+ address: account,
282
+ abi: EIP1271_VALID_SIGNATURE_ABI,
283
+ functionName: "isValidSignature",
284
+ args: [hash, signature]
285
+ });
286
+ const isValid = result === EIP1271_MAGICVALUE;
287
+ this.eip1271SignatureCache.set(cacheKey, isValid);
288
+ return isValid;
289
+ } catch (error) {
290
+ console.error("CoWShedHooks.verifyEip1271Signature", error);
291
+ return false;
292
+ }
214
293
  }
215
294
  infoToSign(calls, nonce, deadline, proxy) {
216
295
  const message = {
@@ -237,6 +316,17 @@ var CowShedHooks = class {
237
316
  getImplementationAddress() {
238
317
  return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
239
318
  }
319
+ async doesAccountHaveCode(account) {
320
+ const cachedResult = this.accountCodeCache.get(account);
321
+ if (cachedResult !== void 0) {
322
+ return cachedResult;
323
+ }
324
+ const adapter = getGlobalAdapter();
325
+ const userAccountCode = await adapter.getCode(account);
326
+ const hasCode = !!userAccountCode && userAccountCode !== "0x";
327
+ this.accountCodeCache.set(account, hasCode);
328
+ return hasCode;
329
+ }
240
330
  };
241
331
 
242
332
  // src/CowShedSdk.ts
@@ -330,6 +420,8 @@ export {
330
420
  COW_SHED_IMPLEMENTATION,
331
421
  COW_SHED_LATEST_VERSION,
332
422
  COW_SHED_PROXY_INIT_CODE,
423
+ CoWShedEip1271SignatureInvalid,
333
424
  CowShedHooks,
334
- CowShedSdk
425
+ CowShedSdk,
426
+ EIP1271_VALID_SIGNATURE_ABI
335
427
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-cow-shed",
3
- "version": "0.2.0-beta.0",
3
+ "version": "0.2.0",
4
4
  "description": "CowProtocol Cow Shed package",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -13,26 +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
- "typecheck": "tsc --noEmit",
23
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
24
- "prepublishOnly": "npm run build"
25
- },
26
16
  "dependencies": {
27
- "@cowprotocol/sdk-config": "workspace:*",
28
- "@cowprotocol/sdk-common": "workspace:*",
29
- "@cowprotocol/sdk-contracts-ts": "workspace:*"
17
+ "@cowprotocol/sdk-common": "0.3.0",
18
+ "@cowprotocol/sdk-config": "0.3.0",
19
+ "@cowprotocol/sdk-contracts-ts": "0.5.0"
30
20
  },
31
21
  "devDependencies": {
32
- "@cow-sdk/typescript-config": "workspace:*",
33
- "@cowprotocol/sdk-ethers-v5-adapter": "workspace:*",
34
- "@cowprotocol/sdk-ethers-v6-adapter": "workspace:*",
35
- "@cowprotocol/sdk-viem-adapter": "workspace:*",
36
22
  "@types/jest": "^29.4.0",
37
23
  "@types/node": "^20.17.31",
38
24
  "@types/semver-sort": "^0.0.1",
@@ -46,6 +32,19 @@
46
32
  "ts-jest": "^29.0.0",
47
33
  "tsup": "^7.2.0",
48
34
  "tsx": "^4.19.4",
49
- "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.2.0",
38
+ "@cowprotocol/sdk-viem-adapter": "0.2.0",
39
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.2.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"
50
49
  }
51
- }
50
+ }