我已经创建了使用 Alchemy 的 API 执行 UserOperation 的代码。
为了对UserOperation进行签名,我创建了以下代码对其进行签名,以及以下执行结果
需要帮助。
Code: -32507
Message: Invalid UserOp signature or paymaster signature
实现代码
public static String signUserOperation(String userOperationHash) {
ECKeyPair ecKeyPair = ECKeyPair.create(Numeric.hexStringToByteArray(privateKey));
SignatureData org.web3j.crypto.signedMessage = signMessage(userOperationHash.getBytes(StandardCharsets.UTF_8),
ecKeyPair);
return signatureDataToHex(signedMessage);
}
public static String signatureDataToHex(SignatureData signature) {
// Convert R, S, and V to hex strings, respectively
String r = Numeric.toHexString(signature.getR());
String s = Numeric.toHexString(signature.getS());
String v = Numeric.toHexString(signature.getV());
// strip 0x (if present)
r = stripHexPrefix(r);
s = stripHexPrefix(s);
v = stripHexPrefix(v);
// concatenate r, s, v and return
return r + s + v;
}
private static String stripHexPrefix(String hexString) {
if (hexString.startsWith("0x")) {
return hexString.substring(2);
}
return hexString;
}
override fun sign(data: ByteArray): ByteArray {
val signature = Sign.signPrefixedMessage(data, credentials.ecKeyPair)
return KeystoreAccountService.bytesFromSignature(signature)
}