struct TokenPair {
address token; // token contract address
uint256 tokenId; // token id (if applicable)
uint256 amount; // token amount (if applicable)
uint8 kind; // token kind (721/1151/mint)
bytes mintData; // mint data (if applicable)
}
struct Detail {
bytes32 intentionHash;
address signer;
uint256 txDeadline;
bytes32 salt;
uint256 id;
uint8 opcode;
address caller;
IERC20 currency;
uint256 price;
uint256 incentiveRate;
Settlement settlement;
TokenPair[] bundle;
uint256 deadline;
}
struct Settlement {
uint256[] coupons;
uint256 feeRate;
uint256 royaltyRate;
uint256 buyerCashbackRate;
address feeAddress;
address royaltyAddress;
}
function run(
Detail calldata detail,
bytes calldata sigDetail
) public pure returns (bool) {
return isSignatureValid(sigDetail, keccak256(abi.encode(detail)), detail.signer);
}
function isSignatureValid(
bytes memory signature,
bytes32 hash,
address signer
) public pure returns (bool) {
// verify hash signed via `personal_sign`
return ECDSA.recover(ECDSA.toEthSignedMessageHash(hash), signature) == signer;
}
我自己解决了,贴了下代码,开袋即食
String inputstr = TypeEncoder.encode(new DynamicStruct(new Address("address"), new Uint256(2)));
byte[] decode = Hash.sha3(Hex.decode(inputstr));
ECKeyPair keyPair = ECKeyPair.create(Hex.decode("privateKey"));
Sign.SignatureData signatureData = Sign.signPrefixedMessage(decode, keyPair);
String sign = "0x" + new String(Hex.encode(signatureData.getR())) + new String(Hex.encode(signatureData.getS())) + new String(Hex.encode(signatureData.getV()));
System.out.println(sign);