Skip to content

Add Stellar federation address resolver with TOML caching #459

Description

@Kingsman-99

Description

Stellar federation allows users to pay to human-readable addresses like alice*example.com instead of raw public keys. The SDK's formatAmount and related helpers work with public keys directly but have no support for resolving federation addresses before payment, requiring consumers to implement this outside the SDK. This issue adds a FederationResolver that looks up *-format addresses via SEP-2 federation servers with response caching to reduce redundant DNS and HTTP calls.

Technical Context

  • New file: src/federation/FederationResolver.ts; uses @stellar/stellar-sdk's StellarSdk.FederationServer.resolve() under the hood
  • Resolved entries are cached with a TTL (default: 300 000 ms) in the standard SDK storage abstraction keyed as fed:{address}
  • FederationResolver.resolve(address: string): Promise<FederationRecord> accepts both federation format (*) and raw public keys (passed through as-is)
  • FederationRecord: { stellarAddress: string; accountId: string; memoType?: string; memoValue?: string }
  • SplitClient.createInvoice() and addRecipient() accept federation addresses and resolve them transparently before writing to the invoice

Acceptance Criteria

  • resolve('alice*example.com') returns the correct accountId from a mocked federation HTTP response
  • Raw public key inputs (G...) are returned as-is without an HTTP call being made
  • A second call to resolve('alice*example.com') within the TTL window uses the cache and makes zero HTTP requests
  • A cache entry past its TTL triggers a fresh HTTP call and updates the cache
  • createInvoice() with a federation address recipient resolves to the underlying public key before writing the Invoice object
  • All CI checks (npm test, npm run build, ESLint) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions