-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return custody and verified addresses (#119)
- Loading branch information
1 parent
8303558
commit cfd30e4
Showing
12 changed files
with
259 additions
and
37 deletions.
There are no files selected for viewing
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,8 @@ | ||
--- | ||
"@farcaster/auth-client": patch | ||
"@farcaster/auth-kit": patch | ||
"client-test": patch | ||
"@farcaster/auth-relay": patch | ||
--- | ||
|
||
Return custody address and verifications |
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,10 +1,12 @@ | ||
import { FastifyRequest as DefaultFastifyRequest } from "fastify"; | ||
import { RelaySession } from "./src/handlers"; | ||
import { ChannelStore } from "./src/channels"; | ||
import { AddressService } from "./src/addresses"; | ||
|
||
declare module "fastify" { | ||
export interface FastifyRequest extends DefaultFastifyRequest { | ||
channelToken: string; | ||
channels: ChannelStore<RelaySession>; | ||
addresses: AddressService; | ||
} | ||
} |
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,76 @@ | ||
import axios, { AxiosInstance } from "axios"; | ||
import { ResultAsync, err, ok } from "neverthrow"; | ||
import { createPublicClient, http } from "viem"; | ||
import type { PublicClient, HttpTransport, Hex } from "viem"; | ||
import { optimism } from "viem/chains"; | ||
import { ID_REGISTRY_ADDRESS, idRegistryABI } from "@farcaster/core"; | ||
|
||
import { RelayAsyncResult, RelayError } from "./errors"; | ||
import { HUB_URL, OPTIMISM_RPC_URL } from "./env"; | ||
|
||
interface VerificationAddEthAddressBody { | ||
address: Hex; | ||
} | ||
|
||
interface VerificationMessageData { | ||
verificationAddEthAddressBody: VerificationAddEthAddressBody; | ||
} | ||
|
||
interface VerificationMessage { | ||
data: VerificationMessageData; | ||
} | ||
|
||
interface VerificationsAPIResponse { | ||
messages: VerificationMessage[]; | ||
} | ||
|
||
export class AddressService { | ||
private http: AxiosInstance; | ||
private publicClient: PublicClient<HttpTransport, typeof optimism>; | ||
|
||
constructor() { | ||
this.http = axios.create(); | ||
this.publicClient = createPublicClient({ | ||
chain: optimism, | ||
transport: http(OPTIMISM_RPC_URL), | ||
}); | ||
} | ||
|
||
async getAddresses(fid?: number): RelayAsyncResult<{ custody: Hex; verifications: Hex[] }> { | ||
const custody = await this.custody(fid); | ||
if (custody.isErr()) { | ||
return err(custody.error); | ||
} | ||
const verifications = await this.verifications(fid); | ||
if (verifications.isErr()) { | ||
return err(verifications.error); | ||
} | ||
return ok({ | ||
custody: custody.value, | ||
verifications: verifications.value, | ||
}); | ||
} | ||
|
||
async custody(fid?: number): RelayAsyncResult<Hex> { | ||
return ResultAsync.fromPromise( | ||
this.publicClient.readContract({ | ||
address: ID_REGISTRY_ADDRESS, | ||
abi: idRegistryABI, | ||
functionName: "custodyOf", | ||
args: [BigInt(fid ?? 0)], | ||
}), | ||
(error) => { | ||
return new RelayError("unknown", error as Error); | ||
}, | ||
); | ||
} | ||
|
||
async verifications(fid?: number): RelayAsyncResult<Hex[]> { | ||
const url = `${HUB_URL}/v1/verificationsByFid?fid=${fid}`; | ||
return ResultAsync.fromPromise(this.http.get<VerificationsAPIResponse>(url), (error) => { | ||
return new RelayError("unknown", error as Error); | ||
}).andThen((res) => { | ||
return ok(res.data.messages.map((message) => message.data.verificationAddEthAddressBody.address)); | ||
}); | ||
} | ||
} |
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
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
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
Oops, something went wrong.