Skip to content

Add HTTP relay transport for browser-to-NHP-server communication - #8

Merged
fengyily merged 2 commits into
mainfrom
feature/nhp-relay
Apr 23, 2026
Merged

Add HTTP relay transport for browser-to-NHP-server communication#8
fengyily merged 2 commits into
mainfrom
feature/nhp-relay

Conversation

@fengyily

Copy link
Copy Markdown
Contributor

No description provided.

Implement the nhp-relay transport path that enables browser-based NHP
agents to communicate with the NHP server via an intermediary HTTP relay
service, removing the dependency on WebRTC signaling.

Transport layer:
- Add HttpRelayTransport (src/transport/relay.ts) that sends raw NHP
  packets via HTTP POST and receives ACK/COK responses in the HTTP
  response body
- Register 'relay' transport type in NHPAgent with relayUrl config

Protocol fixes for Go server interoperability:
- Fix Noise chain key continuity: Go server/agent clear chainKey in
  encryptBody/decryptBody defer blocks, so ACK encryption effectively
  starts from all-zeros chain key. JS agent now passes zero-filled
  prevChainKey when parsing ACK responses to match this behavior
- Save last build chain key in packet.ts for potential future use
  (consumeLastBuildChainKey), with fallback retry logic in NHPAgent
- Fix errCode "0" incorrectly treated as error — in NHP protocol "0"
  means success

GMSM cipher scheme:
- Both build and parse paths for SM2/SM3/SM4 now support prevChainKey
  parameter for Noise chain continuation
- resetGlobalCounter() also clears lastBuildChainKeyMap for test
  isolation

Documentation:
- Update README.md with verified end-to-end relay flow diagram showing
  Browser -> Relay -> NHP Server -> AC with actual packet sizes
- Add Noise chain key continuity explanation
- Add system architecture diagram with AC participant
- Update transport selection table (relay as browser default)
- Add relay-specific troubleshooting in Common Issues
- Update CLAUDE.md with relay transport and known gotchas

Tests:
- Add NHPAgent.test.ts with knock success/error/event tests
- Add protocol/header.test.ts for NHPHeader/NHPHeaderEx
- Add protocol/packet.test.ts with GMSM round-trip, COK/RNK flow,
  anti-replay, and compression tests
- All 116 tests passing
- Fetch ./config.json on startup and populate empty form fields so
  deployments can ship live keys/URLs without editing source. Respects
  user edits saved in localStorage.
- Add importmap for @noble/{ciphers,curves,hashes} which the SDK build
  leaves as external specifiers; required when served as a static page.
- Ignore config.json at repo root (rendered at deploy time, may carry
  demo-grade private key).
@fengyily
fengyily merged commit a1c7a9d into main Apr 23, 2026
3 of 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.

1 participant