Skip to content

feat: challenge-response cryptographic handshake auth hook (#4)#89

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/web3-auth-handshake
Jun 26, 2026
Merged

feat: challenge-response cryptographic handshake auth hook (#4)#89
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/web3-auth-handshake

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

Challenge-Response Cryptographic Handshake Hook Lifecycle (#4)

Closes #4

Changes

File Responsibility
src/utils/web3Auth.ts (new) generateChallenge (random challenge + nonce), handshakeMessage, signMessage, verifyHandshake (against the public key), performHandshake (sign → verify → session token; throws on verification failure), isSessionValid, and token-only persistence: saveSession strips any secret, loadSession purges expired/corrupt tokens, clearSession also removes the legacy secret key.
src/hooks/useWeb3Auth.ts (rewritten) The keypair (secret) lives only in a useRef and is never serialized. connect runs the verified handshake and persists only {address, network, signature, expiresAt}. A timer force-expires the session at CHALLENGE_DURATION_MS (30 min). signChallenge requires a live keypair and the hook exposes needsReChallenge after a reload (token restored, but signing needs a fresh handshake). disconnect wipes context + storage. The existing account/isConnected/connect/disconnect surface is preserved.
tests/unit/web3Auth.test.ts Real ed25519 handshake/verify/persistence.
tests/hooks/useWeb3Auth.test.ts Hook orchestration: connect/disconnect, restore-on-mount, expiry, re-challenge, sign-requires-keypair.
tests/setup.ts Guards window access so node-env suites can run.

…rotocol#4)

Replaces the insecure auth hook (plaintext secret in localStorage, no signature
verification, no expiry) with a proper challenge-response handshake.

- utils/web3Auth.ts: generateChallenge (random challenge + nonce), handshake
  message, signMessage, verifyHandshake (against the public key), performHandshake
  (sign → verify → session token, throws if verification fails), isSessionValid,
  and token-only persistence (saveSession strips any secret; loadSession purges
  expired/corrupt tokens; clearSession also removes the legacy secret key)
- hooks/useWeb3Auth.ts: keypair (secret) lives ONLY in a useRef and is never
  serialized; connect runs the verified handshake and stores only
  {address, network, signature, expiresAt}; a timer expires the session at
  CHALLENGE_DURATION_MS (30 min); signChallenge requires a live keypair and
  surfaces needsReChallenge after a reload; disconnect wipes context + storage.
  Preserves the existing account/isConnected/connect/disconnect surface
- tests: real ed25519 handshake/verify/persistence (node env, since jsdom's
  Uint8Array realm breaks Keypair.random) + hook orchestration (jsdom, util
  mocked); guards tests/setup.ts window access for node-env suites
@elizabetheonoja-art elizabetheonoja-art merged commit 756e4ef into Utility-Protocol:main Jun 26, 2026
4 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.

Issue 4: Challenge-Response Cryptographic Handshake Hook Lifecycle Architecture

2 participants