et’s break down and address both of your questions, one at a time:
Question 1: Signing with ETH_SIGN_TYPED_DATAko
// Hash the typed data
const hashedMessage = _TypedDataEncoder.hash(domain, types, value);
// Sign the hashed message using eth_sign
let signature = await safeErc4337Pack.protocolKit.signMessage(hashedMessage);
If signMessage doesn’t work, another approach would be using safe-core-sdk to submit the typed data in a transaction or finding another method of signature delegation if eth_signTypedData is crucial for your use case.
Question 2: Validating a Transaction with safeErc4337Pack
You’re trying to check if a transaction is valid using the method protocolKit.isValidTransaction, but you’re getting an error saying "Safe is not deployed," despite the Safe being deployed.
Here’s why this might be happening and how to address it:
Error Cause: The error suggests that the safeErc4337Pack instance does not recognize that the Safe has been deployed. Even though the Safe has had transactions and is deployed, the instance you're working with might not have the correct reference to the Safe or could be missing some deployment checks internally.
Potential Causes:
Incorrect Safe Address in the Instance: Ensure that the Safe address you are using with safeErc4337Pack is the correct one and corresponds to the deployed Safe.
Initialization Problem: Sometimes, you need to initialize or validate the Safe instance before performing certain actions.
Backend Deployment Checks: The isValidTransaction method might be querying the backend or blockchain for Safe deployment status, which could be failing for some reason (e.g., network issues, missing Safe in the backend).
Solution:
Check if the Safe is deployed in the contract: Before calling isValidTransaction, you can directly check if the Safe is deployed by calling a method like isSafeDeployed() (assuming it exists) or manually checking on-chain if the Safe exists at that address.
Check Safe Address Initialization: Make sure that the instance of safeErc4337Pack is properly initialized with the correct Safe address. Here’s a simple check to see if the Safe is initialized:
js
const safeInstance = safeErc4337Pack.safeSdk;
const isDeployed = await safeInstance.isSafeDeployed(); // Check if the Safe is deployed
console.log("Safe deployed:", isDeployed);
Check the Correct Transaction Type: Ensure that the transaction being validated (signedSafeOperation) matches the type of transaction the Safe expects. Safe transactions often involve complex multi-signature setups or batch operations, so the method you’re using might not recognize the structure if it’s incomplete.
Network Issues or Sync Delays: If your Safe was recently deployed, there might be network issues or a delay in syncing the deployment status on some backends. You could try waiting for a few more blocks or verifying the deployment manually on a block explorer.
Example Validation Check:
If you’re still having trouble with isValidTransaction, consider wrapping the call in a try-catch block and logging the complete error for better debugging:
js
try {
const isValid = await safeErc4337Pack.protocolKit.isValidTransaction(signedSafeOperation);
console.log("Transaction is valid:", isValid);
} catch (error) {
console.error("Error validating transaction:", error);
}
Summary:
For signing ETH_SIGN_TYPED_DATA_V4 with a Gnosis Safe Passkey Wallet, you’ll likely need to hash the typed data and use a simpler signing method (like eth_sign). Typed data signing is often unsupported by passkey-based signers.
For checking if a transaction is valid with safeErc4337Pack, ensure that the Safe instance is correctly initialized and deployed. You can verify the deployment on-chain manually if needed, or debug the Safe address being used to ensure it’s the correct one.