EIP-1271 設計一種方式可以讓合約錢包可以去調用需要傳入簽名的函式且能正常使用。
bytes4 private constant _EIP_1271_MAGIC_VALUE = 0x1626ba7e;
function verifyEIP1271Signature(
address wallet,
bytes32 digest,
bytes calldata signature
) external view override returns (bool isValid) {
address vwOwner = walletOwner[wallet];
if (Address.isContract(vwOwner)) {
isValid = IWalletOwner(vwOwner).isValidSignature(digest, signature);
} else {
if(signature.length > 225){
bytes32 signedDigest = _getSignedDigest(
digest,
uint256(bytes32(signature[:32])),
bytes32(signature[32:64]),
bytes32(signature[64:96]),
bytes32(signature[96:128]),
bytes32(signature[128:160])
);
isValid = SignLibrary.verifyEIP1271Signature(vwOwner, signedDigest, signature[160:]);
} else {
if(uint8(bytes1(signature[64:65])) == 100){
(bytes32 orderHash, uint256 srcChain, bytes memory realSignature) = abi.decode(
eip1271Info[bytes32(signature[:32])],
(bytes32,uint256,bytes)
);
(bytes32 dappDomainSeparator, bytes32 DAPPTYPEHASH, bytes32 SEPARATORTYPEHASH) = abi.decode(
eip1271Info[bytes32(signature[32:64])],
(bytes32,bytes32,bytes32)
);
bytes32 signedDigest = _getSignedDigest(
digest,
srcChain,
orderHash,
dappDomainSeparator,
SEPARATORTYPEHASH,
DAPPTYPEHASH
);
isValid = SignLibrary.verifyEIP1271Signature(vwOwner, signedDigest, realSignature);
} else {
isValid = SignLibrary.verifyEIP1271Signature(vwOwner, digest, signature);
}
}
}
}