@bloxchain/contracts 1.0.0-alpha.17 → 1.0.0-alpha.18
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/abi/EngineBlox.abi.json +3 -29
- package/core/lib/EngineBlox.sol +60 -27
- package/package.json +1 -1
package/abi/EngineBlox.abi.json
CHANGED
|
@@ -689,38 +689,12 @@
|
|
|
689
689
|
},
|
|
690
690
|
{
|
|
691
691
|
"inputs": [],
|
|
692
|
-
"name": "
|
|
692
|
+
"name": "VERSION",
|
|
693
693
|
"outputs": [
|
|
694
694
|
{
|
|
695
|
-
"internalType": "
|
|
696
|
-
"name": "",
|
|
697
|
-
"type": "uint8"
|
|
698
|
-
}
|
|
699
|
-
],
|
|
700
|
-
"stateMutability": "view",
|
|
701
|
-
"type": "function"
|
|
702
|
-
},
|
|
703
|
-
{
|
|
704
|
-
"inputs": [],
|
|
705
|
-
"name": "VERSION_MINOR",
|
|
706
|
-
"outputs": [
|
|
707
|
-
{
|
|
708
|
-
"internalType": "uint8",
|
|
695
|
+
"internalType": "string",
|
|
709
696
|
"name": "",
|
|
710
|
-
"type": "
|
|
711
|
-
}
|
|
712
|
-
],
|
|
713
|
-
"stateMutability": "view",
|
|
714
|
-
"type": "function"
|
|
715
|
-
},
|
|
716
|
-
{
|
|
717
|
-
"inputs": [],
|
|
718
|
-
"name": "VERSION_PATCH",
|
|
719
|
-
"outputs": [
|
|
720
|
-
{
|
|
721
|
-
"internalType": "uint8",
|
|
722
|
-
"name": "",
|
|
723
|
-
"type": "uint8"
|
|
697
|
+
"type": "string"
|
|
724
698
|
}
|
|
725
699
|
],
|
|
726
700
|
"stateMutability": "view",
|
package/core/lib/EngineBlox.sol
CHANGED
|
@@ -32,9 +32,7 @@ import "./interfaces/IEventForwarder.sol";
|
|
|
32
32
|
library EngineBlox {
|
|
33
33
|
// ============ VERSION INFORMATION ============
|
|
34
34
|
bytes32 public constant PROTOCOL_NAME_HASH = keccak256("Bloxchain");
|
|
35
|
-
|
|
36
|
-
uint8 public constant VERSION_MINOR = 0;
|
|
37
|
-
uint8 public constant VERSION_PATCH = 0;
|
|
35
|
+
string public constant VERSION = "1.0.0";
|
|
38
36
|
|
|
39
37
|
// ============ SYSTEM SAFETY LIMITS ============
|
|
40
38
|
// These constants define the safety range limits for system operations
|
|
@@ -206,8 +204,25 @@ library EngineBlox {
|
|
|
206
204
|
bytes32 public constant NATIVE_TRANSFER_OPERATION = keccak256("NATIVE_TRANSFER");
|
|
207
205
|
|
|
208
206
|
// EIP-712 Type Hashes (selective meta-tx payload: MetaTxRecord = txId + params + payment only)
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
// These follow the canonical EIP-712 convention so that eth_signTypedData_v4 and equivalent
|
|
208
|
+
// wallet typed-data signers can reproduce the same hashes when given matching type definitions.
|
|
209
|
+
//
|
|
210
|
+
// Canonical primary type string for MetaTransaction (primary type + all referenced types,
|
|
211
|
+
// appended in alphabetical order by type name
|
|
212
|
+
bytes32 private constant META_TX_TYPE_HASH = keccak256(
|
|
213
|
+
"MetaTransaction(MetaTxRecord txRecord,MetaTxParams params,bytes data)"
|
|
214
|
+
"MetaTxParams(uint256 chainId,uint256 nonce,address handlerContract,bytes4 handlerSelector,uint8 action,uint256 deadline,uint256 maxGasPrice,address signer)"
|
|
215
|
+
"MetaTxRecord(uint256 txId,TxParams params,PaymentDetails payment)"
|
|
216
|
+
"PaymentDetails(address recipient,uint256 nativeTokenAmount,address erc20TokenAddress,uint256 erc20TokenAmount)"
|
|
217
|
+
"TxParams(address requester,address target,uint256 value,uint256 gasLimit,bytes32 operationType,bytes4 executionSelector,bytes executionParams)"
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Canonical primary type string for MetaTxRecord (primary type + its referenced types).
|
|
221
|
+
bytes32 private constant META_TX_RECORD_TYPE_HASH = keccak256(
|
|
222
|
+
"MetaTxRecord(uint256 txId,TxParams params,PaymentDetails payment)"
|
|
223
|
+
"PaymentDetails(address recipient,uint256 nativeTokenAmount,address erc20TokenAddress,uint256 erc20TokenAmount)"
|
|
224
|
+
"TxParams(address requester,address target,uint256 value,uint256 gasLimit,bytes32 operationType,bytes4 executionSelector,bytes executionParams)"
|
|
225
|
+
);
|
|
211
226
|
bytes32 private constant TX_PARAMS_TYPE_HASH = keccak256("TxParams(address requester,address target,uint256 value,uint256 gasLimit,bytes32 operationType,bytes4 executionSelector,bytes executionParams)");
|
|
212
227
|
bytes32 private constant META_TX_PARAMS_TYPE_HASH = keccak256("MetaTxParams(uint256 chainId,uint256 nonce,address handlerContract,bytes4 handlerSelector,uint8 action,uint256 deadline,uint256 maxGasPrice,address signer)");
|
|
213
228
|
bytes32 private constant PAYMENT_DETAILS_TYPE_HASH = keccak256("PaymentDetails(address recipient,uint256 nativeTokenAmount,address erc20TokenAddress,uint256 erc20TokenAmount)");
|
|
@@ -1690,27 +1705,36 @@ library EngineBlox {
|
|
|
1690
1705
|
|
|
1691
1706
|
/**
|
|
1692
1707
|
* @dev Generates the EIP-712 message hash for the meta-transaction.
|
|
1693
|
-
* Uses selective MetaTxRecord (txId, params, payment only)
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1696
|
-
*
|
|
1697
|
-
*
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
*
|
|
1708
|
+
* Uses selective MetaTxRecord (txId, params, payment only) with standard EIP-712 type hashes
|
|
1709
|
+
* so that eth_signTypedData_v4 (and equivalent) can reproduce the same digest when given
|
|
1710
|
+
* matching domain + types:
|
|
1711
|
+
*
|
|
1712
|
+
* - primaryType: MetaTransaction
|
|
1713
|
+
* - domain: { name: "Bloxchain", version: "1.0.0", chainId, verifyingContract }
|
|
1714
|
+
* - types: MetaTransaction, MetaTxRecord, TxParams, MetaTxParams, PaymentDetails
|
|
1715
|
+
*
|
|
1716
|
+
* Integrators MAY:
|
|
1717
|
+
* - use typed-data signing (eth_signTypedData_v4 / signTypedData) with the above domain/types, or
|
|
1718
|
+
* - sign the resulting digest as a raw hash (e.g. account.sign({ hash: contractDigest })).
|
|
1719
|
+
*
|
|
1720
|
+
* In all cases, on-chain verification uses recoverSigner(messageHash, signature) which applies
|
|
1721
|
+
* ecrecover(messageHash, v, r, s) with no personal_sign / EIP-191 prefix.
|
|
1722
|
+
*
|
|
1723
|
+
* The resulting digest is also written into the `message` field of helper-built `MetaTransaction`
|
|
1724
|
+
* structs so integrators can use it directly without recomputing the hash client-side.
|
|
1703
1725
|
* @param metaTx The meta-transaction to generate the hash for
|
|
1704
1726
|
* @return The EIP-712 digest (no prefix; use standard recovery)
|
|
1705
1727
|
*/
|
|
1706
1728
|
function generateMessageHash(MetaTransaction memory metaTx) private view returns (bytes32) {
|
|
1707
|
-
bytes32 domainSeparator = keccak256(
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1729
|
+
bytes32 domainSeparator = keccak256(
|
|
1730
|
+
abi.encode(
|
|
1731
|
+
DOMAIN_SEPARATOR_TYPE_HASH,
|
|
1732
|
+
PROTOCOL_NAME_HASH,
|
|
1733
|
+
keccak256(bytes(VERSION)),
|
|
1734
|
+
block.chainid,
|
|
1735
|
+
address(this)
|
|
1736
|
+
)
|
|
1737
|
+
);
|
|
1714
1738
|
|
|
1715
1739
|
TxParams memory tp = metaTx.txRecord.params;
|
|
1716
1740
|
bytes32 txParamsStructHash = keccak256(abi.encode(
|
|
@@ -1769,11 +1793,20 @@ library EngineBlox {
|
|
|
1769
1793
|
|
|
1770
1794
|
/**
|
|
1771
1795
|
* @dev Recovers the signer from the EIP-712 digest and signature. Uses standard EIP-712 recovery (no message prefix).
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1775
|
-
*
|
|
1776
|
-
*
|
|
1796
|
+
*
|
|
1797
|
+
* Integrators have two equivalent options:
|
|
1798
|
+
* - Use typed-data signing (eth_signTypedData_v4 / signTypedData) with:
|
|
1799
|
+
* - primaryType: MetaTransaction
|
|
1800
|
+
* - domain: { name: "Bloxchain", version: "1.0.0", chainId, verifyingContract }
|
|
1801
|
+
* - types: MetaTransaction, MetaTxRecord, TxParams, MetaTxParams, PaymentDetails
|
|
1802
|
+
* In this case the wallet computes the same digest as generateMessageHash and signs it.
|
|
1803
|
+
* - Sign the digest returned by generateMessageHash as a raw hash—e.g.
|
|
1804
|
+
* account.sign({ hash: contractDigest }) or equivalent raw-hash signing API—with no
|
|
1805
|
+
* EIP-191/personal prefix.
|
|
1806
|
+
*
|
|
1807
|
+
* In all cases, this function applies ecrecover(messageHash, v, r, s) over the raw EIP-712 digest.
|
|
1808
|
+
* personal_sign / EIP-191-prefixed signatures remain incompatible.
|
|
1809
|
+
*
|
|
1777
1810
|
* @param messageHash The EIP-712 digest (keccak256("\x19\x01" || domainSeparator || structHash))
|
|
1778
1811
|
* @param signature The signature (r, s, v)
|
|
1779
1812
|
* @return The address of the signer
|