Samples
The ping/pong programs show how each language assembles a signed, encrypted exchange. They are useful for tracing the cryptographic operations and comparing implementations, but their registration handshake is not supported by the current mesgd listener. Each program follows roughly the same sequence:
PKI.init()loads or generates the key file.PKI.register()seals the public keys to an RSA public key you supply.- Connect a WebSocket and send that ciphertext as the first frame.
- Sign and encrypt, send, receive, decrypt and verify.
mesgd expects JSON text frames and does not decrypt the initial registration frame. The /mesgd/pki mount also returns an empty response rather than storing a registration. To run an exchange, you need a test service that implements the sample protocol; a generic echo server is sufficient only for an implementation whose receive path can open its own echoed ciphertext. For working account integration, use the auth client and PUT /auth/keys. See Running the samples for language commands.
The first run writes pki_keys.json with an ECDSA P-256 signing pair and an RSA-2048 encryption pair. Forth is local cryptography only. It has no WebSocket sample. The Swift sample runs on Apple platforms.
| Directory | Language | Experimental WebSocket source |
|---|---|---|
01-python | Python | Present; integration pending |
02-javascript | JavaScript | Present; integration pending |
03-java | Java | Present; integration pending |
04-c | C | Present; integration pending |
05-cpp | C++ | Present; integration pending |
06-csharp | C# | Present; integration pending |
07-go | Go | Present; integration pending |
08-rust | Rust | Present; integration pending |
09-php | PHP | Present; integration pending |
10-swift | Swift | Apple only; integration pending |
11-ruby | Ruby | Present; integration pending |
12-erlang | Erlang | Present; integration pending |
13-perl | Perl | Present; integration pending |
14-haskell | Haskell | Present; integration pending |
15-lua | Lua | Present; integration pending |
16-ocaml | OCaml | Present; integration pending |
17-forth | Forth | No |
Each sample README has the install and run lines for that language.
Several sample programs also reference SDK wrappers that are absent from this checkout, so protocol compatibility is not their only limitation. Python, JavaScript, C, C++, Go, Lua, and OCaml have missing message-client modules, headers, or package wiring. Consult the individual language guides before treating a sample command as runnable. Kotlin has an account adapter but no ping/pong sample; Forth provides local cryptography only.
The public key you encrypt to
The sample encrypts to an RSA public JWK (kty, n, e). Point MESGD_PUB_JWK at that file, or place mesgd_pub.json in the working directory.
The sample READMEs refer to https://mesgd.org/.well-known/mesgd-pub.json, but neither the current server nor the website supplies that file. Obtain the public encryption JWK from the operator of the test service. For a key generated by make keys, extract only the public RSA fields kty, n, and e from keys/mesgd.json. The complete file contains private keys and must remain private.
| Variable | When unset |
|---|---|
MESGD_URL | wss://echo.mesgd.org/ws |
MESGD_PUB_JWK | mesgd_pub.json |
For an auth client, MESGD_URL is the HTTPS origin, not the WebSocket URL. Live auth tests skip unless that origin is set. The sample programs and the auth tests read the same variable for different schemes. Set the one the program you are running expects.
Registering keys on a user account is PUT /auth/keys, documented in Account API. The sample register step seals keys into a message. It does not replace that HTTP call. /mesgd/pki only logs the request.