From 4755c6d5f6f76abf9d90c32ce81d976d6d8914ff Mon Sep 17 00:00:00 2001 From: horsefacts <109845214+horsefacts@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:24:24 -0700 Subject: [PATCH] feat: pass siwe params in channel body (#201) ## Motivation Simplify SIWF QR codes by passing SIWE parameters in the channel body. ## Change Summary Add `signatureParams` to channel body and `/status` response. ## Merge Checklist _Choose all relevant options below by adding an `x` now or at any time before submitting for review_ - [x] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard - [x] PR has a changeset - [x] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore) - [ ] PR includes documentation if necessary - [x] All commits have been signed --- .changeset/fifty-experts-love.md | 6 ++++++ apps/relay/src/handlers.ts | 2 ++ apps/relay/src/server.test.ts | 7 ++++++- packages/auth-client/src/actions/app/status.test.ts | 4 ++++ packages/auth-client/src/actions/app/status.ts | 11 ++++++++++- .../components/AuthKitProvider/AuthKitProvider.tsx | 2 +- 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .changeset/fifty-experts-love.md diff --git a/.changeset/fifty-experts-love.md b/.changeset/fifty-experts-love.md new file mode 100644 index 0000000..c2b429b --- /dev/null +++ b/.changeset/fifty-experts-love.md @@ -0,0 +1,6 @@ +--- +"@farcaster/auth-client": patch +"@farcaster/auth-relay": patch +--- + +feat: add SIWE params to channel body diff --git a/apps/relay/src/handlers.ts b/apps/relay/src/handlers.ts index f28cd42..33748b2 100644 --- a/apps/relay/src/handlers.ts +++ b/apps/relay/src/handlers.ts @@ -37,6 +37,7 @@ export type RelaySession = { pfpUrl?: string; verifications?: string[]; custody?: Hex; + signatureParams: CreateChannelRequest; }; const constructUrl = (channelToken: string, nonce: string, extraParams: CreateChannelRequest): string => { @@ -57,6 +58,7 @@ export async function createChannel(request: FastifyRequest<{ Body: CreateChanne nonce, url, connectUri: url, + signatureParams: request.body, }); if (update.isOk()) { return reply.code(201).send({ channelToken, url, connectUri: url, nonce }); diff --git a/apps/relay/src/server.test.ts b/apps/relay/src/server.test.ts index 220910e..2940d10 100644 --- a/apps/relay/src/server.test.ts +++ b/apps/relay/src/server.test.ts @@ -372,7 +372,12 @@ describe("relay server", () => { const { state, nonce, ...rest } = response.data; expect(state).toBe("pending"); expect(nonce).toMatch(/[a-zA-Z0-9]{16}/); - expect(rest).toStrictEqual({}); + expect(rest).toStrictEqual({ + signatureParams: { + domain: "example.com", + siweUri: "https://example.com", + }, + }); }); test("GET with invalid token", async () => { diff --git a/packages/auth-client/src/actions/app/status.test.ts b/packages/auth-client/src/actions/app/status.test.ts index f16e9b6..1472b47 100644 --- a/packages/auth-client/src/actions/app/status.test.ts +++ b/packages/auth-client/src/actions/app/status.test.ts @@ -16,6 +16,10 @@ describe("status", () => { state: "pending", nonce: "abcd1234", url: "https://warpcast.com/~/sign-in-with-farcaster?nonce=abcd1234[...]", + signatureParams: { + domain: "example.com", + siweUri: "https://example.com/login", + }, }; test("constructs API request", async () => { diff --git a/packages/auth-client/src/actions/app/status.ts b/packages/auth-client/src/actions/app/status.ts index af387a9..68d0dfd 100644 --- a/packages/auth-client/src/actions/app/status.ts +++ b/packages/auth-client/src/actions/app/status.ts @@ -20,8 +20,17 @@ export interface StatusAPIResponse { bio?: string; displayName?: string; pfpUrl?: string; - verifications?: Hex[]; + verifications?: string[]; custody?: Hex; + signatureParams: { + siweUri: string; + domain: string; + nonce?: string; + notBefore?: string; + expirationTime?: string; + requestId?: string; + redirectUrl?: string; + }; } const path = "channel/status"; diff --git a/packages/auth-kit/src/components/AuthKitProvider/AuthKitProvider.tsx b/packages/auth-kit/src/components/AuthKitProvider/AuthKitProvider.tsx index b5d8c7b..5721d89 100644 --- a/packages/auth-kit/src/components/AuthKitProvider/AuthKitProvider.tsx +++ b/packages/auth-kit/src/components/AuthKitProvider/AuthKitProvider.tsx @@ -19,7 +19,7 @@ export interface Profile { displayName?: string; bio?: string; custody?: `0x${string}`; - verifications?: `0x${string}`[]; + verifications?: string[]; } export interface SignInMessage {