Skip to content

Commit

Permalink
feat: pass provider to SIWE (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
horsefacts authored Dec 20, 2023
1 parent 216aa3c commit 0101fe6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/actions/app/verifySignInMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const verifySignInMessage = async (
): VerifySignInMessageResponse => {
const result = await verify(message, signature, {
getFid: client.ethereum.getFid,
provider: client.ethereum.provider,
});
if (result.isErr()) {
throw result.error;
Expand Down
12 changes: 12 additions & 0 deletions packages/connect/src/clients/ethereum/viem.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Hex, createPublicClient, http } from "viem";
import { optimism } from "viem/chains";
import { JsonRpcProvider } from "ethers";
import { ID_REGISTRY_ADDRESS, idRegistryABI } from "@farcaster/hub-web";

export interface Ethereum {
getFid: (custody: Hex) => Promise<BigInt>;
provider: JsonRpcProvider;
}

interface ViemConfigArgs {
Expand All @@ -25,7 +27,17 @@ export const viem = (args?: ViemConfigArgs): Ethereum => {
});
};

const getProvider = () => {
const { chain, transport } = publicClient;
const network = {
chainId: chain.id,
name: chain.name,
};
return new JsonRpcProvider(transport.url, network);
};

return {
getFid,
provider: getProvider(),
};
};
4 changes: 2 additions & 2 deletions test/client/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("clients", () => {
response: pendingStatusResponse,
data: { state: pendingState },
} = await appClient.status({ channelToken });
expect(pendingStatusResponse.status).toBe(200);
expect(pendingStatusResponse.status).toBe(202);
expect(pendingState).toBe("pending");

// 3. Auth client generates a sign in message
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("clients", () => {
signature: sig,
...userData,
});
expect(authResponse.status).toBe(200);
expect(authResponse.status).toBe(201);

// 4. App client polls channel status
const {
Expand Down

0 comments on commit 0101fe6

Please sign in to comment.