Open CedarMist opened 2 months ago
A suggestion was made on how to implement this cleanly with Viem:
import {
keccak256,
serializeTransaction,
type TransactionSerializable,
type Hex,
type Signature,
} from "viem";
import { sign, privateKeyToAccount, toAccount } from "viem/accounts";
async function serializerAsync(
transaction: TransactionSerializable,
signature?: Signature | undefined,
): Promise<Hex> {
// ... perform async operations
return serializeTransaction(transaction, signature);
}
const privateKey = "0x..." as const;
const account = toAccount({
...privateKeyToAccount(privateKey),
async signTransaction(transaction) {
const signature = await sign({
hash: keccak256(await serializerAsync(transaction)),
privateKey,
});
return serializerAsync(transaction, signature);
},
});
Currently the Viem integration has a workaround to fetch the calldata public keys in the background because the transaction serializer isn't async:
However, this isn't ideal.
There are other sore-spots in the Viem & Wagmi integrations:
eth_call
and eth_estimateGas
wouldn't be encrypted as they aren't wrapped.Overall, we can't just focus on Viem, need to make sure it works well with Wagmi in the way people commonly use it, and with the third-party RPC providers & SDKs like WalletConnect & RainbowKit
As per: https://github.com/wevm/viem/discussions/2696
Tried to fix upstream