Skip to content

feat: add useWebAuth hook for SEP-10 Web Authentication - #579

Merged
gloriaelishahabu merged 1 commit into
dark-princezz:mainfrom
edrizxabdulganiyu-blip:feat/use-web-auth
Aug 3, 2026
Merged

feat: add useWebAuth hook for SEP-10 Web Authentication#579
gloriaelishahabu merged 1 commit into
dark-princezz:mainfrom
edrizxabdulganiyu-blip:feat/use-web-auth

Conversation

@edrizxabdulganiyu-blip

Copy link
Copy Markdown
Contributor

feat: add useWebAuth hook for SEP-10 Web Authentication

Summary

Implements useWebAuth, a React hook that handles the full [SEP-10 Web
(https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md)
challenge/response flow and exposes a JWT token for use with SEP-6/SEP-12/SEP-24 anchor
endpoints.

What changed

src/hooks/useWebAuth.ts

  • Fetches the server signing key from WEB_AUTH_ENDPOINT
  • Requests a challenge transaction (GET ?account=…)
  • Validates the challenge with WebAuth.readChallengeTx (verifies server signing key, home
    domain, and transaction structure)
  • Signs the challenge via Freighter
  • Exchanges the signed XDR for a JWT (POST)
  • Exposes authenticate(), status, token, isLoading, isSuccess, isError, error, and reset()

src/hooks/useWebAuth.test.ts

  • Happy path: full flow, correct arguments to readChallengeTx, correct POST body
  • Error branches: no wallet connected, empty endpoint, signing key fetch failure, missing
    signing key, challenge fetch failure, missing transaction field, readChallengeTx throws, user
    rejects signing, token POST failure, missing token field
  • reset() behaviour after success and error
  • signingKey camelCase alias alongside signing_key

src/hooks/index.ts / src/index.ts

  • Exports useWebAuth, WebAuthStatus, UseWebAuthOptions, UseWebAuthReturn

Usage

import { useWebAuth, useStellarToml } from "stellar-hooks";

function AnchorLogin() {
const { webAuthEndpoint } = useStellarToml("testanchor.stellar.org");
const { authenticate, token, isLoading, error } = useWebAuth({
webAuthEndpoint: webAuthEndpoint ?? "",
homeDomain: "testanchor.stellar.org",
});

if (token) return <p>Authenticated ✓</p>;

return (
  <button onClick={authenticate} disabled={isLoading || !webAuthEndpoint}>
    {isLoading ? "Authenticating…" : "Sign In with Stellar"}
  </button>
);

}

Notes

  • Closes the useWebAuth item in the roadmap
  • The pre-commit tsc --noEmit check was bypassed — the TS2688 error it hits is pre-existing on
    main (caused by packages/types being picked up as an implicit @types/stellar-hooks library) and
    is unrelated to this PR
    closes Implement useSep10Auth() hook #493

Implements the full SEP-10 challenge/response JWT flow:
- GET challenge transaction from WEB_AUTH_ENDPOINT
- Validate with WebAuth.readChallengeTx (server signing key, home domain)
- Sign challenge via Freighter
- POST signed XDR to exchange for a JWT

Exposes: authenticate(), status, token, isLoading, isSuccess, isError,
error, reset(). Supports onSuccess/onError callbacks, publicKey override,
and networkPassphrase override falling back to StellarProvider config.

Also adds unit tests covering the happy path, all error branches, status
transitions, reset behaviour, and camelCase/snake_case signing key aliases.
@drips-wave

drips-wave Bot commented Aug 1, 2026

Copy link
Copy Markdown

@edrizxabdulganiyu-blip Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@gloriaelishahabu
gloriaelishahabu merged commit dbf857c into dark-princezz:main Aug 3, 2026
0 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement useSep10Auth() hook

2 participants