diff options
| author | Gab Virebent <gabriel1@virebent.art> | 2026-07-11 13:37:23 +0200 |
|---|---|---|
| committer | Gab Virebent <gabriel1@virebent.art> | 2026-07-11 13:37:23 +0200 |
| commit | bec3734676faf3868ea225e0316e77ad5a7e4421 (patch) | |
| tree | 78bc62532fcdb9f42eb92c41f0841b5fdeeb063d /internal/nym/address_test.go | |
| parent | f21e4d8781c06c0686f4a8697ce0697f9bf6a5cc (diff) | |
| download | nymdrop-bec3734676faf3868ea225e0316e77ad5a7e4421.tar.gz nymdrop-bec3734676faf3868ea225e0316e77ad5a7e4421.tar.xz nymdrop-bec3734676faf3868ea225e0316e77ad5a7e4421.zip | |
Switch Nym WS transport to nym-client's binary protocol, drop second base64 layer
Client.Send now speaks nym-client's native binary websocket protocol
(tag || recipient || conn_id || data_len || data) instead of wrapping
the ciphertext in a JSON text message, which required base64-encoding
it a second time on top of the browser's own base64 layer.
The reader's self-address query also switched to the binary protocol:
nym-client picks text-vs-binary for every later "received" push based
on the format of the last request seen on a connection, so leaving the
reader in JSON/text mode would have made nym-client run a lossy UTF-8
conversion over the now-unencoded binary payload, corrupting it. Fixed
the binary Received-frame parsing along the way (previous code assumed
a fixed 16-byte tag with no length prefix, which never matched the real
protocol and was never exercised while the connection stayed text-mode).
Verified end-to-end against the real embedded nym-client 1.1.76 binary,
with the exact wire format cross-checked against upstream nym source at
the pinned build commit.
Diffstat (limited to 'internal/nym/address_test.go')
| -rw-r--r-- | internal/nym/address_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/nym/address_test.go b/internal/nym/address_test.go new file mode 100644 index 0000000..d73210a --- /dev/null +++ b/internal/nym/address_test.go @@ -0,0 +1,68 @@ +package nym + +import "testing" + +func TestParseRecipient(t *testing.T) { + // Real nymdrop-inbox address (see project session.md). + addr := "5xme8W448FjvSG69GaNWNkSwYpurgzmLrooPMt6XWThU.GpKLJHB2oiSqRsG5u55t4h2D25tA7BNSfvCQbfup3j1k@6mMs1GQkDRa7rPPtzG9vkFscmEBmAvQX4zjLSoaDg9Wa" + + got, err := ParseRecipient(addr) + if err != nil { + t.Fatalf("parseRecipient: %v", err) + } + if len(got) != RecipientLen { + t.Fatalf("expected %d bytes, got %d", RecipientLen, len(got)) + } +} + +func TestParseRecipientRustTestVector(t *testing.T) { + // Same address used in nym-client's own Rust unit tests + // (websocket-requests/src/requests.rs: send_request_serialization_works). + addr := "CytBseW6yFXUMzz4SGAKdNLGR7q3sJLLYxyBGvutNEQV.4QXYyEVc5fUDjmmi8PrHN9tdUFV4PCvSJE1278cHyvoe@4sBbL1ngf1vtNqykydQKTFh26sQCw888GpUqvPvyNB4f" + + got, err := ParseRecipient(addr) + if err != nil { + t.Fatalf("parseRecipient: %v", err) + } + if len(got) != RecipientLen { + t.Fatalf("expected %d bytes, got %d", RecipientLen, len(got)) + } +} + +func TestParseRecipientMalformed(t *testing.T) { + cases := []string{ + "", + "no-at-sign", + "a@b@c", + "nodot@gateway", + "id.enc@0OIl", // invalid base58 chars + } + for _, addr := range cases { + if _, err := ParseRecipient(addr); err == nil { + t.Errorf("ParseRecipient(%q): expected error, got none", addr) + } + } +} + +func TestMakeSendRequestLayout(t *testing.T) { + c := &Client{recipient: make([]byte, RecipientLen)} + for i := range c.recipient { + c.recipient[i] = byte(i) + } + payload := []byte("hello mixnet") + + req := make([]byte, 0, 1+len(c.recipient)+8+8+len(payload)) + req = append(req, ReqSend) + req = append(req, c.recipient...) + req = append(req, 0, 0, 0, 0, 0, 0, 0, 0) // connection_id = 0 + req = append(req, 0, 0, 0, 0, 0, 0, 0, byte(len(payload))) + req = append(req, payload...) + + wantLen := 1 + RecipientLen + 8 + 8 + len(payload) + if len(req) != wantLen { + t.Fatalf("expected length %d, got %d", wantLen, len(req)) + } + if req[0] != 0x00 { + t.Fatalf("expected tag 0x00, got 0x%02x", req[0]) + } +} |
