0

I am using Java and Web3j to create code to execute a UserOperation using Alchemy's API.
In order to sign the UserOperation, the following code was created and signed, resulting in the following execution.
Need help.

Code: -32507
Message: Invalid UserOp signature or paymaster signature

Implemented Code

  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;
  }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.