diff --git a/.changeset/four-months-decide.md b/.changeset/four-months-decide.md new file mode 100644 index 0000000..97e0eb4 --- /dev/null +++ b/.changeset/four-months-decide.md @@ -0,0 +1,5 @@ +--- +"@farcaster/auth-relay": patch +--- + +feat: add fallback hub diff --git a/apps/relay/package.json b/apps/relay/package.json index bf97867..61bb492 100644 --- a/apps/relay/package.json +++ b/apps/relay/package.json @@ -16,7 +16,7 @@ "node": ">=18" }, "dependencies": { - "@farcaster/core": "^0.13.4", + "@farcaster/core": "^0.14.8", "@fastify/cors": "^8.4.2", "@fastify/rate-limit": "^9.0.1", "axios": "^1.6.2", diff --git a/apps/relay/src/addresses.ts b/apps/relay/src/addresses.ts index 12cd1c2..9906244 100644 --- a/apps/relay/src/addresses.ts +++ b/apps/relay/src/addresses.ts @@ -6,7 +6,7 @@ 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"; +import { HUB_URL, HUB_FALLBACK_URL, OPTIMISM_RPC_URL } from "./env"; interface VerificationAddAddressBody { address: Hex; @@ -75,16 +75,29 @@ export class AddressService { async verifications(fid?: number): RelayAsyncResult { const url = `${HUB_URL}/v1/verificationsByFid?fid=${fid}`; - return ResultAsync.fromPromise(this.http.get(url), (error) => { + const fallbackUrl = `${HUB_FALLBACK_URL}/v1/verificationsByFid?fid=${fid}`; + + return ResultAsync.fromPromise(this.http.get(url, { timeout: 1500 }), (error) => { return new RelayError("unknown", error as Error); - }).andThen((res) => { - return ok( - res.data.messages.map((message) => { - return ( - message.data?.verificationAddAddressBody?.address || message.data?.verificationAddEthAddressBody?.address - ); - }), - ); - }); + }) + .orElse(() => { + return ResultAsync.fromPromise( + this.http.get(fallbackUrl, { + timeout: 3500, + }), + (error) => { + return new RelayError("unknown", error as Error); + }, + ); + }) + .andThen((res) => { + return ok( + res.data.messages.map((message) => { + return ( + message.data?.verificationAddAddressBody?.address || message.data?.verificationAddEthAddressBody?.address + ); + }), + ); + }); } } diff --git a/apps/relay/src/env.ts b/apps/relay/src/env.ts index fc28805..58100cc 100644 --- a/apps/relay/src/env.ts +++ b/apps/relay/src/env.ts @@ -13,6 +13,7 @@ export const URL_BASE = process.env["URL_BASE"] || process.env["CONNECT_URI_BASE"] || "https://warpcast.com/~/sign-in-with-farcaster"; export const HUB_URL = process.env["HUB_URL"] || "https://nemes.farcaster.xyz:2281"; +export const HUB_FALLBACK_URL = process.env["HUB_FALLBACK_URL"] || "https://hoyt.farcaster.xyz:2281"; export const OPTIMISM_RPC_URL = process.env["OPTIMISM_RPC_URL"] || "https://mainnet.optimism.io"; diff --git a/yarn.lock b/yarn.lock index 3d90768..9d67cec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1146,16 +1146,15 @@ resolved "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz#ef20350fec605a7f7035a01764731b2de0f3782b" integrity sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A== -"@farcaster/core@^0.13.4": - version "0.13.4" - resolved "https://registry.npmjs.org/@farcaster/core/-/core-0.13.4.tgz#18df168e024186f084f0cd7c5f29fd051964a7f5" - integrity sha512-cvQLzD+r4/1kI763jox0ZtU5BkmYQjOvvabcYVvJAfIJUsQfwpcVJOEliLuO94a2pyZSp7/CLQN0In0RUIVKlQ== +"@farcaster/core@^0.14.8": + version "0.14.8" + resolved "https://registry.npmjs.org/@farcaster/core/-/core-0.14.8.tgz#c8e63d58af6b45b6e95149a41238a08451a01a51" + integrity sha512-vMN0InOXgzwzgsurcp1rlJaALfZJ6v82QEZS9Do5XZYnB636wfBugHiQD7u+Zdw5EMkEWlVBdNJ9yjAixP2kmA== dependencies: "@noble/curves" "^1.0.0" "@noble/hashes" "^1.3.0" - ffi-napi "^4.0.3" + bs58 "^5.0.0" neverthrow "^6.0.0" - ref-napi "^3.0.3" viem "^1.12.2" "@fastify/ajv-compiler@^3.5.0": @@ -2763,6 +2762,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base-x@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" + integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== + base64-js@^1.3.1: version "1.5.1" resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -2927,6 +2931,13 @@ browserslist@^4.21.9, browserslist@^4.22.2: node-releases "^2.0.14" update-browserslist-db "^1.0.13" +bs58@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279" + integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ== + dependencies: + base-x "^4.0.0" + bser@2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05" @@ -3393,13 +3404,6 @@ debug@4.3.4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3. dependencies: ms "2.1.2" -debug@^3.1.0: - version "3.2.7" - resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" - integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ== - dependencies: - ms "^2.1.1" - decamelize-keys@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.1.tgz#04a2d523b2f18d80d0158a43b895d56dff8d19d8" @@ -4190,18 +4194,6 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -ffi-napi@^4.0.3: - version "4.0.3" - resolved "https://registry.npmjs.org/ffi-napi/-/ffi-napi-4.0.3.tgz#27a8d42a8ea938457154895c59761fbf1a10f441" - integrity sha512-PMdLCIvDY9mS32RxZ0XGb95sonPRal8aqRhLbeEtWKZTe2A87qRFG9HjOhvG8EX2UmQw5XNRMIOT+1MYlWmdeg== - dependencies: - debug "^4.1.1" - get-uv-event-loop-napi-h "^1.0.5" - node-addon-api "^3.0.0" - node-gyp-build "^4.2.1" - ref-napi "^2.0.1 || ^3.0.2" - ref-struct-di "^1.1.0" - file-entry-cache@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" @@ -4440,18 +4432,6 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -get-symbol-from-current-process-h@^1.0.1, get-symbol-from-current-process-h@^1.0.2: - version "1.0.2" - resolved "https://registry.npmjs.org/get-symbol-from-current-process-h/-/get-symbol-from-current-process-h-1.0.2.tgz#510af52eaef873f7028854c3377f47f7bb200265" - integrity sha512-syloC6fsCt62ELLrr1VKBM1ggOpMdetX9hTrdW77UQdcApPHLmf7CI7OKcN1c9kYuNxKcDe4iJ4FY9sX3aw2xw== - -get-uv-event-loop-napi-h@^1.0.5: - version "1.0.6" - resolved "https://registry.npmjs.org/get-uv-event-loop-napi-h/-/get-uv-event-loop-napi-h-1.0.6.tgz#42b0b06b74c3ed21fbac8e7c72845fdb7a200208" - integrity sha512-t5c9VNR84nRoF+eLiz6wFrEp1SE2Acg0wS+Ysa2zF0eROes+LzOfuTaVHxGy8AbS8rq7FHEJzjnCZo1BupwdJg== - dependencies: - get-symbol-from-current-process-h "^1.0.1" - glob-parent@^5.1.2, glob-parent@~5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" @@ -5944,11 +5924,6 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@^2.1.1: - version "2.1.3" - resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" - integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== - muggle-string@^0.3.1: version "0.3.1" resolved "https://registry.npmjs.org/muggle-string/-/muggle-string-0.3.1.tgz#e524312eb1728c63dd0b2ac49e3282e6ed85963a" @@ -5978,16 +5953,6 @@ neverthrow@^6.0.0, neverthrow@^6.1.0: resolved "https://registry.npmjs.org/neverthrow/-/neverthrow-6.1.0.tgz#51a6e9ce2e06600045b3c1b37aecc536d267bf95" integrity sha512-xNbNjp/6M5vUV+mststgneJN9eJeJCDSYSBTaf3vxgvcKooP+8L0ATFpM8DGfmH7UWKJeoa24Qi33tBP9Ya3zA== -node-addon-api@^3.0.0: - version "3.2.1" - resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" - integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== - -node-gyp-build@^4.2.1: - version "4.8.0" - resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz#3fee9c1731df4581a3f9ead74664369ff00d26dd" - integrity sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og== - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -6744,23 +6709,6 @@ redis-parser@^3.0.0: dependencies: redis-errors "^1.0.0" -"ref-napi@^2.0.1 || ^3.0.2", ref-napi@^3.0.3: - version "3.0.3" - resolved "https://registry.npmjs.org/ref-napi/-/ref-napi-3.0.3.tgz#e259bfc2bbafb3e169e8cd9ba49037dd00396b22" - integrity sha512-LiMq/XDGcgodTYOMppikEtJelWsKQERbLQsYm0IOOnzhwE9xYZC7x8txNnFC9wJNOkPferQI4vD4ZkC0mDyrOA== - dependencies: - debug "^4.1.1" - get-symbol-from-current-process-h "^1.0.2" - node-addon-api "^3.0.0" - node-gyp-build "^4.2.1" - -ref-struct-di@^1.1.0: - version "1.1.1" - resolved "https://registry.npmjs.org/ref-struct-di/-/ref-struct-di-1.1.1.tgz#5827b1d3b32372058f177547093db1fe1602dc10" - integrity sha512-2Xyn/0Qgz89VT+++WP0sTosdm9oeowLP23wRJYhG4BFdMUrLj3jhwHZNEytYNYgtPKLNTP3KJX4HEgBvM1/Y2g== - dependencies: - debug "^3.1.0" - regenerator-runtime@^0.14.0: version "0.14.0" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45"