Fix WalletConnect SIWE connection

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-05-18 15:45:47 +02:00
committed by Alexis Sellier
parent 41b82decfe
commit cf371e31ed
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -51,13 +51,13 @@ export class WalletConnectSigner extends ethers.Signer {
const prefix = ethers.utils.toUtf8Bytes(
`\x19Ethereum Signed Message:\n${message.length}`
);
const data = ((typeof(message) === "string") ? ethers.utils.toUtf8Bytes(message): message);
const data = ((typeof (message) === "string") ? ethers.utils.toUtf8Bytes(message) : message);
const msg = ethers.utils.concat([prefix, data]);
const address = await this.getAddress();
const keccakMessage = ethers.utils.keccak256(msg);
const signature = await this.walletConnect.signMessage([
address.toLowerCase(),
address,
keccakMessage,
]);
+7 -2
View File
@@ -4,6 +4,7 @@ import { Request, type Host } from '@app/api';
import type { Config } from "@app/config";
import { connectSeed } from "@app/session";
import type { Seed } from "@app/base/seeds/Seed";
import { ethers } from "ethers";
export interface SeedSession {
domain: string;
@@ -45,9 +46,13 @@ export async function signInWithEthereum(seed: Seed, config: Config): Promise<{
return null;
}
const result = await createUnauthorizedSession(seed.api);
const address = await config.signer.getAddress();
const message = createSiweMessage(seed, address, result.nonce, config);
// We convert the address to a checksummed address, since WalletConnect returns a lowercase address.
// We need a checksummed address to verify it on the seed node.
const checksummedAddress = ethers.utils.getAddress(address);
const result = await createUnauthorizedSession(seed.api);
const message = createSiweMessage(seed, checksummedAddress, result.nonce, config);
const signature = await config.signer.signMessage(message);
const auth: {