Skip to content

feat: v2 relay session handoff — replace cloudflared tunnel with Durable Object relay + 6-digit code#63

Open
JamesLawton wants to merge 14 commits intomainfrom
feat/v2-relay-session
Open

feat: v2 relay session handoff — replace cloudflared tunnel with Durable Object relay + 6-digit code#63
JamesLawton wants to merge 14 commits intomainfrom
feat/v2-relay-session

Conversation

@JamesLawton
Copy link
Copy Markdown
Collaborator

Summary

  • Adds packages/shared — new @polygonlabs/agent-shared workspace package with pure-JS X25519 ECDH + HKDF-SHA256 + XChaCha20-Poly1305 crypto protocol (works in both Node.js 20+ and Cloudflare Workers)
  • Replaces cloudflared tunnel + local HTTP server in the CLI with a Cloudflare Durable Object relay: the browser encrypts the session with the CLI's public key and posts it to the relay; the CLI retrieves it after the user enters a 6-digit out-of-band code
  • Updates connector-ui SPA: fetches CLI public key from relay, encrypts session, posts ciphertext, displays 6-digit code on new CodeDisplay screen; adds SessionRelay Durable Object + /api/relay/* route handlers to the Worker

Test Plan

  • packages/shared crypto round-trip tests pass (4/4)
  • pnpm typecheck clean across all packages
  • pnpm build (connector-ui) produces clean dist/
  • Wrangler local dev smoke test: relay API /request, /status, /session, /retrieve all return correct responses and state transitions
  • Deploy to staging with npx wrangler deploy --env staging and verify end-to-end flow with a real wallet

Removes cloudflared/HTTP server machinery from wallet create and replaces
it with X25519 key exchange through the connector-ui relay API. The new
flow registers a CLI public key with the relay, polls for browser approval,
then prompts for a 6-digit out-of-band code to decrypt the session payload.
Adds RelayClient, RelayCodeError, and sessionPayloadToWalletSession helpers;
updates wallet import to support both relay-code and legacy ciphertext modes.
Comment on lines +455 to +459
const relayRes = await fetch(`/api/relay/session/${rid}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(encrypted)
});

Check warning

Code scanning / CodeQL

Client-side request forgery Medium

The
URL
of this request depends on a
user-provided value
.
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.

1 participant