-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ec3e60
commit dcd7d49
Showing
23 changed files
with
570 additions
and
620 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/connect/src/actions/connect.test.ts → ...s/connect/src/actions/app/connect.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/connect/src/actions/status.test.ts → ...es/connect/src/actions/app/status.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Client } from "../../clients/createClient"; | ||
import { SignInResponse, verify } from "../../messages/verify"; | ||
|
||
export interface VerifySignInMessageArgs { | ||
message: string; | ||
signature: `0x${string}`; | ||
} | ||
|
||
export type VerifySignInMessageResponse = Promise<SignInResponse>; | ||
|
||
export const verifySignInMessage = async ( | ||
_client: Client, | ||
{ message, signature }: VerifySignInMessageArgs, | ||
): VerifySignInMessageResponse => { | ||
const result = await verify(message, signature); | ||
if (result.isErr()) { | ||
throw result.error; | ||
} else { | ||
return result.value; | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
.../connect/src/actions/authenticate.test.ts → ...ect/src/actions/auth/authenticate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { StatusResponse } from "../app/status"; | ||
import { post, AsyncHttpResponse } from "../../clients/transports/http"; | ||
import { Client } from "../../clients/createClient"; | ||
|
||
export interface AuthenticateArgs extends AuthenticateRequest { | ||
channelToken: string; | ||
} | ||
|
||
export type AuthenticateResponse = AsyncHttpResponse<AuthenticateAPIResponse>; | ||
|
||
interface AuthenticateRequest { | ||
message: string; | ||
signature: `0x${string}`; | ||
fid: number; | ||
username: string; | ||
bio: string; | ||
displayName: string; | ||
pfpUrl: string; | ||
} | ||
|
||
type AuthenticateAPIResponse = StatusResponse; | ||
|
||
const path = "connect/authenticate"; | ||
|
||
export const authenticate = async ( | ||
client: Client, | ||
{ channelToken, ...request }: AuthenticateArgs, | ||
): AuthenticateResponse => { | ||
return post<AuthenticateRequest, AuthenticateAPIResponse>(client, path, request, { authToken: channelToken }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Client } from "clients/createClient"; | ||
import { build, SignInMessageParams } from "../../messages/build"; | ||
import { SiweMessage } from "siwe"; | ||
|
||
export type BuildSignInMessageArgs = SignInMessageParams; | ||
export type BuildSignInMessageResponse = SiweMessage; | ||
|
||
export const buildSignInMessage = (_client: Client, args: BuildSignInMessageArgs): BuildSignInMessageResponse => { | ||
const result = build(args); | ||
if (result.isErr()) { | ||
throw result.error; | ||
} else { | ||
return result.value; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { authenticate, AuthenticateArgs, AuthenticateResponse } from "../actions/authenticate"; | ||
import { authenticate, AuthenticateArgs, AuthenticateResponse } from "../actions/auth/authenticate"; | ||
import { | ||
buildSignInMessage, | ||
BuildSignInMessageArgs, | ||
BuildSignInMessageResponse, | ||
} from "../actions/auth/buildSignInMessage"; | ||
import { Client, ClientConfig, createClient } from "./createClient"; | ||
import { AsyncHttpResponse } from "./transports/http"; | ||
|
||
export interface AuthClient extends Client { | ||
authenticate: (args: AuthenticateArgs) => AsyncHttpResponse<AuthenticateResponse>; | ||
authenticate: (args: AuthenticateArgs) => AuthenticateResponse; | ||
buildSignInMessage: (args: BuildSignInMessageArgs) => BuildSignInMessageResponse; | ||
} | ||
|
||
export const createAuthClient = (config: ClientConfig): AuthClient => { | ||
const client = createClient(config); | ||
return { | ||
...client, | ||
authenticate: (args: AuthenticateArgs) => authenticate(client, args), | ||
buildSignInMessage: (args: BuildSignInMessageArgs) => buildSignInMessage(client, args), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from "./errors"; | ||
export * from "./messages"; | ||
export * from "./clients"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { build } from "./build"; | ||
|
||
const siweParams = { | ||
domain: "example.com", | ||
address: "0x63C378DDC446DFf1d831B9B96F7d338FE6bd4231", | ||
uri: "https://example.com/login", | ||
version: "1", | ||
nonce: "12345678", | ||
issuedAt: "2023-10-01T00:00:00.000Z", | ||
}; | ||
|
||
describe("build", () => { | ||
test("adds connect-specific parameters", () => { | ||
const result = build({ | ||
...siweParams, | ||
fid: 5678, | ||
}); | ||
expect(result.isOk()).toBe(true); | ||
expect(result._unsafeUnwrap()).toMatchObject({ | ||
...siweParams, | ||
statement: "Farcaster Connect", | ||
chainId: 10, | ||
resources: ["farcaster://fid/5678"], | ||
}); | ||
}); | ||
|
||
test("handles additional resources", () => { | ||
const result = build({ | ||
...siweParams, | ||
fid: 5678, | ||
resources: ["https://example.com/resource"], | ||
}); | ||
expect(result.isOk()).toBe(true); | ||
expect(result._unsafeUnwrap()).toMatchObject({ | ||
...siweParams, | ||
statement: "Farcaster Connect", | ||
chainId: 10, | ||
resources: ["farcaster://fid/5678", "https://example.com/resource"], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SiweMessage } from "siwe"; | ||
import { ConnectResult } from "../errors"; | ||
import { validate } from "./validate"; | ||
import { STATEMENT, CHAIN_ID } from "./constants"; | ||
|
||
export type FarcasterResourceParams = { | ||
fid: number; | ||
}; | ||
export type SignInMessageParams = Partial<SiweMessage> & FarcasterResourceParams; | ||
|
||
export const build = (params: SignInMessageParams): ConnectResult<SiweMessage> => { | ||
const { fid, ...siweParams } = params; | ||
const resources = siweParams.resources ?? []; | ||
siweParams.statement = STATEMENT; | ||
siweParams.chainId = CHAIN_ID; | ||
siweParams.resources = [buildFidResource(fid), ...resources]; | ||
return validate(siweParams); | ||
}; | ||
|
||
const buildFidResource = (fid: number): string => { | ||
return `farcaster://fid/${fid}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const STATEMENT = "Farcaster Connect"; | ||
export const CHAIN_ID = 10; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.