2026-03-02 14:22:35 -08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
pragma solidity ^0.8.20;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @title DBIS_EIP712Lib
|
2026-03-04 02:00:09 -08:00
|
|
|
* @notice External library for EIP-712 hashing and ecrecover (delegatecall = own stack).
|
2026-03-02 14:22:35 -08:00
|
|
|
*/
|
|
|
|
|
library DBIS_EIP712Lib {
|
2026-03-04 02:00:09 -08:00
|
|
|
function hashAddressArray(address[] calldata arr) external pure returns (bytes32) {
|
2026-03-02 14:22:35 -08:00
|
|
|
bytes32[] memory hashes = new bytes32[](arr.length);
|
|
|
|
|
for (uint256 i = 0; i < arr.length; i++) {
|
|
|
|
|
hashes[i] = keccak256(abi.encode(arr[i]));
|
|
|
|
|
}
|
|
|
|
|
return keccak256(abi.encodePacked(hashes));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 02:00:09 -08:00
|
|
|
function hashUint256Array(uint256[] calldata arr) external pure returns (bytes32) {
|
2026-03-02 14:22:35 -08:00
|
|
|
bytes32[] memory hashes = new bytes32[](arr.length);
|
|
|
|
|
for (uint256 i = 0; i < arr.length; i++) {
|
|
|
|
|
hashes[i] = keccak256(abi.encode(arr[i]));
|
|
|
|
|
}
|
|
|
|
|
return keccak256(abi.encodePacked(hashes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMintAuthStructHash(
|
|
|
|
|
bytes32 typeHash,
|
|
|
|
|
bytes32 messageId,
|
|
|
|
|
bytes32 isoType,
|
|
|
|
|
bytes32 isoHash,
|
|
|
|
|
bytes32 accountingRef,
|
|
|
|
|
uint8 fundsStatus,
|
|
|
|
|
bytes32 corridor,
|
|
|
|
|
uint8 assetClass,
|
|
|
|
|
bytes32 recipientsHash,
|
|
|
|
|
bytes32 amountsHash,
|
|
|
|
|
uint64 notBefore,
|
|
|
|
|
uint64 expiresAt,
|
|
|
|
|
uint256 chainId,
|
|
|
|
|
address verifyingContract
|
2026-03-04 02:00:09 -08:00
|
|
|
) external pure returns (bytes32) {
|
2026-03-02 14:22:35 -08:00
|
|
|
return keccak256(abi.encode(
|
|
|
|
|
typeHash,
|
|
|
|
|
messageId,
|
|
|
|
|
isoType,
|
|
|
|
|
isoHash,
|
|
|
|
|
accountingRef,
|
|
|
|
|
fundsStatus,
|
|
|
|
|
corridor,
|
|
|
|
|
assetClass,
|
|
|
|
|
recipientsHash,
|
|
|
|
|
amountsHash,
|
|
|
|
|
notBefore,
|
|
|
|
|
expiresAt,
|
|
|
|
|
chainId,
|
|
|
|
|
verifyingContract
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 02:00:09 -08:00
|
|
|
function getDigest(bytes32 domainSeparator, bytes32 structHash) external pure returns (bytes32) {
|
2026-03-02 14:22:35 -08:00
|
|
|
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 02:00:09 -08:00
|
|
|
function recover(bytes32 digest, bytes calldata signature) external pure returns (address) {
|
2026-03-02 14:22:35 -08:00
|
|
|
require(signature.length == 65, "DBIS: sig length");
|
|
|
|
|
bytes32 r;
|
|
|
|
|
bytes32 s;
|
|
|
|
|
uint8 v;
|
|
|
|
|
assembly {
|
|
|
|
|
r := calldataload(signature.offset)
|
|
|
|
|
s := calldataload(add(signature.offset, 32))
|
|
|
|
|
v := byte(0, calldataload(add(signature.offset, 64)))
|
|
|
|
|
}
|
|
|
|
|
if (v < 27) v += 27;
|
|
|
|
|
require(v == 27 || v == 28, "DBIS: invalid v");
|
|
|
|
|
return ecrecover(digest, v, r, s);
|
|
|
|
|
}
|
|
|
|
|
}
|