I'm trying to validate signatures created by a Safe wallet using ISignatureValidator.isValidSignature
. However, the validation fails with the error GS026
. Below is the code I am using to generate and validate the signature.
Code
Signing the Message
I am using the following code to generate a signature with a Safe wallet:
import { ethers } from "ethers";
import EthSafeMessage from "@safe-global/protocol-kit/dist/src/utils/messages/SafeMessage";
import { SigningMethod } from "@safe-global/protocol-kit/dist/src/types/signing";
// Prepare the message
const channelId = "0x...";
const timestamp = Date.now();
const initialMessage: Uint8Array = messageToSignForChannelUpdate(channelId, 0, timestamp, [], []);
const messageHex = ethers.utils.hexlify(initialMessage);
// Sign the message using Safe wallet
const ethSafeMessage = await safe.signMessage(
new EthSafeMessage(messageHex),
SigningMethod.ETH_SIGN,
safeWalletAddress
);
// Get the encoded signature
const userSignature = ethSafeMessage.encodedSignatures();
Validating the Signature
I am using the following code to validate the signature on-chain using ISignatureValidator.isValidSignature
:
import { ethers } from "ethers";
const messageHash = ethers.utils.keccak256(initialMessage);
const ethSignedMessageHash = ethers.utils.hashMessage(messageHash);
const expectedSigner = safeWalletAddress.toLowerCase();
const iSignatureValidator = ISignatureValidator__factory.connect(expectedSigner, provider);
let isSignatureValid: boolean;
try {
const result = await iSignatureValidator.isValidSignature(ethSignedMessageHash, userSignature);
isSignatureValid = result === "0x1626ba7e"; // ERC1271_MAGICVALUE
} catch (error) {
console.error("Failed to validate signature", error);
isSignatureValid = false;
}
if (!isSignatureValid) {
throw new Error("Invalid user signature");
}
Error
I receive the following error when trying to validate the signature:
[Nest] ERROR [OpenchannelService] failed to validate signature
[Nest] ERROR [OpenchannelService] Error: execution reverted: "GS026" (action="call", data="0x08c379a...", reason="GS026", transaction={ ... }, invocation=null, revert={ "args": [ "GS026" ], "name": "Error", "signature": "Error(string)" }, code=CALL_EXCEPTION, version=6.13.2)
Environment
- Ethers.js Version: 6.13.2
- Safe SDK Version: 4.0.3
- Solidity Version: 0.8.x
Question
How can I correctly validate a signature created by a Safe wallet using ISignatureValidator.isValidSignature
? Am I missing something in the message signing or validation process?