Skip to content

Commit

Permalink
feat: pass siwe params in channel body (#201)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
horsefacts committed Aug 19, 2024
1 parent 0741739 commit 4755c6d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/fifty-experts-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@farcaster/auth-client": patch
"@farcaster/auth-relay": patch
---

feat: add SIWE params to channel body
2 changes: 2 additions & 0 deletions apps/relay/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type RelaySession = {
pfpUrl?: string;
verifications?: string[];
custody?: Hex;
signatureParams: CreateChannelRequest;
};

const constructUrl = (channelToken: string, nonce: string, extraParams: CreateChannelRequest): string => {
Expand All @@ -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 });
Expand Down
7 changes: 6 additions & 1 deletion apps/relay/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/auth-client/src/actions/app/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/auth-client/src/actions/app/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Profile {
displayName?: string;
bio?: string;
custody?: `0x${string}`;
verifications?: `0x${string}`[];
verifications?: string[];
}

export interface SignInMessage {
Expand Down

0 comments on commit 4755c6d

Please sign in to comment.