test-isol-01 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,9 +28,7 @@ interface ITransferAuthorize {
28
28
  uint256 validAfter,
29
29
  uint256 validBefore,
30
30
  bytes32 nonce,
31
- uint8 v,
32
- bytes32 r,
33
- bytes32 s
31
+ bytes calldata signature
34
32
  ) external;
35
33
 
36
34
  /// @notice Execute a "transfer with authorization" - typically any relayer may submit
@@ -41,9 +39,7 @@ interface ITransferAuthorize {
41
39
  uint256 validAfter,
42
40
  uint256 validBefore,
43
41
  bytes32 nonce,
44
- uint8 v,
45
- bytes32 r,
46
- bytes32 s
42
+ bytes calldata signature
47
43
  ) external;
48
44
 
49
45
  // ++
@@ -55,9 +51,7 @@ interface ITransferAuthorize {
55
51
  uint256 validAfter,
56
52
  uint256 validBefore,
57
53
  bytes32 nonce,
58
- uint8 v,
59
- bytes32 r,
60
- bytes32 s
54
+ bytes calldata signature
61
55
  ) external;
62
56
 
63
57
  // ++
@@ -69,9 +63,7 @@ interface ITransferAuthorize {
69
63
  uint256 validAfter,
70
64
  uint256 validBefore,
71
65
  bytes32 nonce,
72
- uint8 v,
73
- bytes32 r,
74
- bytes32 s
66
+ bytes calldata signature
75
67
  ) external;
76
68
 
77
69
  /// @notice Execute a "approve with authorization" - typically any relayer may submit
@@ -82,9 +74,7 @@ interface ITransferAuthorize {
82
74
  uint256 validAfter,
83
75
  uint256 validBefore,
84
76
  bytes32 nonce,
85
- uint8 v,
86
- bytes32 r,
87
- bytes32 s
77
+ bytes calldata signature
88
78
  ) external;
89
79
 
90
80
  /// @notice Standard ERC20 approve
@@ -56,38 +56,47 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
56
56
  emit AuthorizeUsed(authorizer, nonce);
57
57
  }
58
58
 
59
- /// @dev Verify an EIP-712 typed signature and return the recovered signer
60
- /// @param typehash the type hash for the struct (RECEIVE_TYPEHASH or TRANSFER_TYPEHASH)
61
- /// @param from authorizer (the account that signed)
62
- /// @param to recipient
63
- /// @param value amount
64
- /// @param validAfter earliest valid timestamp (inclusive)
65
- /// @param validBefore latest valid timestamp (inclusive)
66
- /// @param nonce nonce value
67
- /// @param v signature v
68
- /// @param r signature r
69
- /// @param s signature s
70
- /// @return signer recovered address
71
- function _verify(
72
- bytes32 typehash,
59
+ /// @dev Verify an EIP-712 typed signature for ReceiveWithAuthorize and return the recovered signer
60
+ function _verifyReceive(
73
61
  address from,
74
62
  address to,
75
63
  uint256 value,
76
64
  uint256 validAfter,
77
65
  uint256 validBefore,
78
66
  bytes32 nonce,
79
- uint8 v,
80
- bytes32 r,
81
- bytes32 s
67
+ bytes calldata signature
82
68
  ) internal view returns (address signer) {
83
- // Validate time: require validAfter <= validBefore
84
69
  require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
85
70
  require(block.timestamp <= validBefore, "TransferAuthorize: expired");
71
+ bytes32 structHash = keccak256(
72
+ abi.encode(
73
+ RECEIVE_TYPEHASH,
74
+ from,
75
+ to,
76
+ value,
77
+ validAfter,
78
+ validBefore,
79
+ nonce
80
+ )
81
+ );
82
+ signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
83
+ }
86
84
 
87
- // Hash the struct per EIP-712
85
+ /// @dev Verify an EIP-712 typed signature for TransferWithAuthorize and return the recovered signer
86
+ function _verifyTransfer(
87
+ address from,
88
+ address to,
89
+ uint256 value,
90
+ uint256 validAfter,
91
+ uint256 validBefore,
92
+ bytes32 nonce,
93
+ bytes calldata signature
94
+ ) internal view returns (address signer) {
95
+ require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
96
+ require(block.timestamp <= validBefore, "TransferAuthorize: expired");
88
97
  bytes32 structHash = keccak256(
89
98
  abi.encode(
90
- typehash,
99
+ TRANSFER_TYPEHASH,
91
100
  from,
92
101
  to,
93
102
  value,
@@ -96,8 +105,84 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
96
105
  nonce
97
106
  )
98
107
  );
108
+ signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
109
+ }
99
110
 
100
- // Recover the signer from the domain-separated digest
101
- signer = _hashTypedDataV4(structHash).recover(v, r, s);
111
+ /// @dev Verify an EIP-712 typed signature for TransferFromWithAuthorize and return the recovered signer
112
+ function _verifyTransferFrom(
113
+ address from,
114
+ address to,
115
+ uint256 value,
116
+ uint256 validAfter,
117
+ uint256 validBefore,
118
+ bytes32 nonce,
119
+ bytes calldata signature
120
+ ) internal view returns (address signer) {
121
+ require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
122
+ require(block.timestamp <= validBefore, "TransferAuthorize: expired");
123
+ bytes32 structHash = keccak256(
124
+ abi.encode(
125
+ TRANSFERFROM_TYPEHASH,
126
+ from,
127
+ to,
128
+ value,
129
+ validAfter,
130
+ validBefore,
131
+ nonce
132
+ )
133
+ );
134
+ signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
135
+ }
136
+
137
+ /// @dev Verify an EIP-712 typed signature for ApproveWithAuthorize and return the recovered signer
138
+ function _verifyApprove(
139
+ address from,
140
+ address to,
141
+ uint256 value,
142
+ uint256 validAfter,
143
+ uint256 validBefore,
144
+ bytes32 nonce,
145
+ bytes calldata signature
146
+ ) internal view returns (address signer) {
147
+ require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
148
+ require(block.timestamp <= validBefore, "TransferAuthorize: expired");
149
+ bytes32 structHash = keccak256(
150
+ abi.encode(
151
+ APPROVE_TYPEHASH,
152
+ from,
153
+ to,
154
+ value,
155
+ validAfter,
156
+ validBefore,
157
+ nonce
158
+ )
159
+ );
160
+ signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
161
+ }
162
+
163
+ /// @dev Verify an EIP-712 typed signature for BurnWithAuthorize and return the recovered signer
164
+ function _verifyBurn(
165
+ address from,
166
+ address to,
167
+ uint256 value,
168
+ uint256 validAfter,
169
+ uint256 validBefore,
170
+ bytes32 nonce,
171
+ bytes calldata signature
172
+ ) internal view returns (address signer) {
173
+ require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
174
+ require(block.timestamp <= validBefore, "TransferAuthorize: expired");
175
+ bytes32 structHash = keccak256(
176
+ abi.encode(
177
+ BURN_TYPEHASH,
178
+ from,
179
+ to,
180
+ value,
181
+ validAfter,
182
+ validBefore,
183
+ nonce
184
+ )
185
+ );
186
+ signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
102
187
  }
103
188
  }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
6
+
7
+ abstract contract BasexERC20 is ERC20, ReentrancyGuard {
8
+ constructor(string memory name, string memory symbol)
9
+ ERC20(name, symbol)
10
+ {}
11
+ }
@@ -24,31 +24,20 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
24
24
  uint256 validAfter,
25
25
  uint256 validBefore,
26
26
  bytes32 nonce,
27
- uint8 v,
28
- bytes32 r,
29
- bytes32 s
27
+ bytes calldata signature
30
28
  ) external override nonReentrant {
31
- // Only the recipient should be able to call this helper
32
29
  require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
33
-
34
- // Recover signer and validate
35
- address signer = _verify(
36
- RECEIVE_TYPEHASH,
30
+ address signer = _verifyReceive(
37
31
  from,
38
32
  to,
39
33
  value,
40
34
  validAfter,
41
35
  validBefore,
42
36
  nonce,
43
- v,
44
- r,
45
- s
37
+ signature
46
38
  );
47
39
  require(signer == from, "ERC20TransferAuthorize: invalid signature");
48
-
49
- // Mark nonce as used
50
40
  _useAuthorize(from, nonce);
51
- // Execute the token transfer
52
41
  _transfer(from, to, value);
53
42
  }
54
43
 
@@ -61,30 +50,20 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
61
50
  uint256 validAfter,
62
51
  uint256 validBefore,
63
52
  bytes32 nonce,
64
- uint8 v,
65
- bytes32 r,
66
- bytes32 s
53
+ bytes calldata signature
67
54
  ) external override nonReentrant {
68
- // Recover signer and validate
69
- address signer = _verify(
70
- TRANSFER_TYPEHASH,
55
+ address signer = _verifyTransfer(
71
56
  from,
72
57
  to,
73
58
  value,
74
59
  validAfter,
75
60
  validBefore,
76
61
  nonce,
77
- v,
78
- r,
79
- s
62
+ signature
80
63
  );
81
64
  require(signer == from, "ERC20TransferAuthorize: invalid signature");
82
-
83
- // Mark nonce as used
84
65
  _useAuthorize(from, nonce);
85
- // Execute the token transfer
86
66
  _transfer(from, to, value);
87
- // transfer(to, value);
88
67
  }
89
68
 
90
69
  /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
@@ -96,29 +75,19 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
96
75
  uint256 validAfter,
97
76
  uint256 validBefore,
98
77
  bytes32 nonce,
99
- uint8 v,
100
- bytes32 r,
101
- bytes32 s
78
+ bytes calldata signature
102
79
  ) external override nonReentrant {
103
- // Recover signer and validate
104
- address signer = _verify(
105
- TRANSFERFROM_TYPEHASH,
80
+ address signer = _verifyTransferFrom(
106
81
  from,
107
82
  to,
108
83
  value,
109
84
  validAfter,
110
85
  validBefore,
111
86
  nonce,
112
- v,
113
- r,
114
- s
87
+ signature
115
88
  );
116
89
  require(signer == from, "ERC20TransferAuthorize: invalid signature");
117
-
118
- // Mark nonce as used
119
90
  _useAuthorize(from, nonce);
120
- // Execute the token transfer
121
- // transferFrom(from, to, value); // xxx msg.sender xxx
122
91
  _spendAllowance(from, to, value);
123
92
  _transfer(from, to, value);
124
93
  }
@@ -132,28 +101,19 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
132
101
  uint256 validAfter,
133
102
  uint256 validBefore,
134
103
  bytes32 nonce,
135
- uint8 v,
136
- bytes32 r,
137
- bytes32 s
104
+ bytes calldata signature
138
105
  ) external override nonReentrant {
139
- // Recover signer and validate
140
- address signer = _verify(
141
- APPROVE_TYPEHASH,
106
+ address signer = _verifyApprove(
142
107
  from,
143
108
  to,
144
109
  value,
145
110
  validAfter,
146
111
  validBefore,
147
112
  nonce,
148
- v,
149
- r,
150
- s
113
+ signature
151
114
  );
152
115
  require(signer == from, "ERC20TransferAuthorize: invalid signature");
153
-
154
- // Mark nonce as used
155
116
  _useAuthorize(from, nonce);
156
- // Execute the token approval
157
117
  _approve(from, to, value);
158
118
  }
159
119
 
@@ -166,28 +126,19 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
166
126
  uint256 validAfter,
167
127
  uint256 validBefore,
168
128
  bytes32 nonce,
169
- uint8 v,
170
- bytes32 r,
171
- bytes32 s
129
+ bytes calldata signature
172
130
  ) external override nonReentrant {
173
- // Recover signer and validate
174
- address signer = _verify(
175
- BURN_TYPEHASH,
131
+ address signer = _verifyBurn(
176
132
  from,
177
133
  to,
178
134
  value,
179
135
  validAfter,
180
136
  validBefore,
181
137
  nonce,
182
- v,
183
- r,
184
- s
138
+ signature
185
139
  );
186
140
  require(signer == from, "ERC20TransferAuthorize: invalid signature");
187
-
188
- // Mark nonce as used
189
141
  _useAuthorize(from, nonce);
190
- // Execute the token approval
191
142
  _burn(from, value);
192
143
  }
193
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {