feat: add hosted-API auth and per-chain routing to clients - #325
Conversation
No API Breaking Changes DetectedThe PR title signals breaking changes, but |
|
Heads-up for reconciliation when this merges: PR #327 (benchmark gateway auth, branch |
tamaralipows
left a comment
There was a problem hiding this comment.
Thanks for this - just one question/request
| ("arbitrum", 42161), | ||
| ("bsc", 56), | ||
| ("polygon", 137), | ||
| ("unichain", 130), |
There was a problem hiding this comment.
Does it really make sense to add Plasma here since we don't have a hosted Tycho for Plasma? 🤔
The hosted gateway at fynd-api.propellerheads.xyz requires a bearer
token and per-chain request paths (/v1/{chain}/quote). Neither typed
client could produce those requests, forcing users onto raw curl/fetch.
Adds with_api_key/with_chain to the Rust FyndClientBuilder (HostedConfig
struct) and apiKey/chain/headers to the TypeScript FyndClientOptions.
The TS chain routing is an openapi-fetch middleware that rewrites /v1/
to /v1/{chain}/, keeping call sites typed against the schema literals.
createFyndClient and the Middleware type are now re-exported from the
package root.
Also fixes a signing bug: build_quote_only hardcoded chain_id 1, so a
quote-only client on a non-mainnet chain would sign transactions
stamped for mainnet whenever SigningHints supplied nonce, fees, and
gas. The chain ID is now derived from the chain slug. build() checks
the slug against the chain the RPC node reports.
Both options are opt-in; unset, they reproduce the previous
unauthenticated requests to unprefixed paths.
The deployed ph-nginx-auth gateway matches the entire raw Authorization header value against user_tokens.token, with no Bearer stripping. Verified against the live prod gateway with an admin key: a raw key returns 200 while `Authorization: Bearer <key>` returns 401. Send the key verbatim (Rust and TypeScript clients) and update the doc comments and header assertions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
e30aa42 to
688eef3
Compare
688eef3 to
4d63aaa
Compare
|
This PR is included in version 0.95.0 🎉 |
What
Adds hosted-API authentication and per-chain request routing to both typed Fynd clients (Rust + TypeScript), so they work out-of-the-box against the hosted gateway at
fynd-api.propellerheads.xyzinstead of forcing users onto rawcurl/fetch.fynd-client): newFyndClientBuilder::with_api_key+with_chain, backed by aHostedConfigstruct. The API key is sent asAuthorization: Bearer ***; the chain slug rewrites request paths to/v1/{chain}/quote|health|infoand derives the EVMchain_idused for signing.@kayibal/fynd-client): newapiKey/chain/headersonFyndClientOptions. Chain routing is implemented as anopenapi-fetchmiddleware that rewrites/v1/→/v1/{chain}/, so call sites stay typed against the generated schema literals.createFyndClientand theMiddlewaretype are now re-exported from the package root (resolves the long-standing feat: implement TychoFeedBuilder for TychoFeed creation and configuration #12 export gap).Why
The hosted gateway requires a bearer token and per-chain paths (
/v1/{chain}/quote). Neither client could produce those requests.Bundled fix:
build_quote_onlyhardcodedchain_id: 1, so a quote-only client on a non-mainnet chain would sign transactions stamped for mainnet wheneverSigningHintssupplied nonce, fees, and gas. The chain ID is now derived from the chain slug, andbuild()cross-checks the slug against the RPC-reported chain ID.Backward compatibility
Both options are opt-in. Unset, the clients reproduce the previous unauthenticated requests to the unprefixed
/v1/…paths — self-hosted Fynd users see zero behavior change.Supported chains
ethereum(1),base(8453),arbitrum(42161),bsc(56),polygon(137),unichain(130). Unknown slugs fail at build time with aConfigerror listing the accepted set.Validation
cargo check --package fynd-clientcargo clippy --workspace --all-targets --all-featurescargo +nightly fmt --all --checkcargo test -p fynd-clienttypecheck/lint/testNew tests were mutation-tested (suppressing the bearer header, middleware, and chain_id derivation failed 6 Rust + 5 TS tests; the 2 TS tests that stayed green assert absence of the new behavior, which is correct).