Java SDK

The Java account client is in java/MesgdAuth.java in mesgd-sdk. Use it to enroll an account, obtain a session, and manage public keys independently of the PKI layer. The examples use an existing account named alice; passwords and authenticator codes come from the application rather than literals in source.

Support status

CapabilityCurrent support
Account operationsAvailable: signup, confirmation, login, reset, keys, key updates, and logout
HTTPSPending built-in transport; the application must supply verified HTTPS
WSSPending supported SDK message client; experimental samples are not current-server integration

The account adapter is available, but a built-in HTTPS transport is still pending. The transport argument in the examples is application code, not a missing SDK constructor.

Completeness position: 9 of 18. Local JWK/PKI and cross-language fixture tests; HTTPS transport and account-runner coverage remain pending. The language matrix explains the ranking criteria and comparable tiers. WSS readiness is listed separately; no SDK currently provides a complete, validated encrypted messaging workflow against this server.

Setup and transport

Compile MesgdAuth.java with java/lib/json.jar on the classpath. The account API uses org.json.JSONObject and JSONArray. The examples assume these classes and the SDK class are available to the application.

Supply a MesgdAuth.Transport implementation with send(method, path, body, token). It returns new MesgdAuth.Reply(status, decodedObject). The SDK does not ship a Java HTTPS transport, so the example receives one from the application.

A custom transport must serialize JSON, attach Authorization: Bearer TOKEN only when a token is supplied, verify the certificate and hostname, reject redirects, and use a finite timeout. Its origin is an HTTPS URL, such as https://mesgd.example.com, rather than a WebSocket URL.

Log in, read keys, and log out

Pass the current authenticator code as a six-digit string, preserving leading zeroes. This example reads the account's published keys and ends the session on its successful path. Applications that retain a session can keep the bearer until logout or expiry instead.

import org.json.JSONObject;

final class AccountExample {
    static JSONObject readKeys(MesgdAuth.Transport transport,
                               String password, String otp) throws Exception {
        MesgdAuth client = new MesgdAuth(transport);
        JSONObject session = client.login("alice", password, otp);
        String token = session.getString("access_token");
        try {
            return client.keys(token);
        } finally {
            client.logout(token);
        }
    }
}

Methods return JSONObject and can throw checked exceptions. MesgdAuth.AuthException.status identifies an HTTP rejection. Signup requires an explicit JSONArray, even when there are no public keys. The repository's Java Makefile contains a machine-specific JDK path; set JAVA and JAVAC to your own tools before using it.

Enroll a new account

The following fragment uses an existing client or transport from the example above. Signup returns a pending enrollment. Display qr_png_base64 or otpauth_uri, let the person configure the authenticator, then collect a code to confirm it. These calls are separate application steps, with user interaction between them.

JSONObject enrollment = client.signup("alice", "alice@example.com",
                                      password, new org.json.JSONArray());
// Display enrollment before obtaining enrollmentOtp.
JSONObject session = client.confirm("alice",
    enrollment.getString("enrollment_token"), enrollmentOtp);
org.json.JSONArray recoveryCodes = session.getJSONArray("recovery_codes");

Confirmation returns the first session and eight recovery codes. Display the recovery codes for separate safekeeping. A code accepted for confirmation cannot be reused for login or a key update; wait for a new authenticator step before another operation that consumes a code.

Account operations

OperationFunction or methodHTTP endpoint
Create a pending accountsignupPOST /auth/signup
Confirm authenticator enrollmentconfirmPOST /auth/signup/confirm
Log inloginPOST /auth/login
Reset a forgotten passwordresetPasswordPOST /auth/password/reset
Read account public keyskeysGET /auth/keys
Replace account public keyssetKeysPUT /auth/keys
End the current sessionlogoutPOST /auth/logout

A key update takes the session token, current password, a fresh authenticator code, and an array containing only public JWKs. An empty array clears the linked keys. A password reset takes the username, a saved recovery code, a new password, and a fresh authenticator code; success replaces the recovery codes and revokes existing sessions without returning a new session.

The shared authentication reference documents argument order, response fields, and transport behavior. Session refresh is available through the HTTP API but is not wrapped by these seven SDK operations.

Local signing and encryption

This example exercises the local PKI implementation without opening a network connection. It signs a short message, verifies it with the same identity, and encrypts and decrypts it locally. It demonstrates the primitives rather than a complete peer-to-peer exchange.

PKI.init("pki_keys.json");
String signature = PKI.sign("hello");
if (!PKI.verify("hello", signature)) throw new IllegalStateException("signature rejected");
String ciphertext = PKI.encrypt("hello");
if (!PKI.decrypt(ciphertext).equals("hello")) throw new IllegalStateException("round trip failed");

Compile pki.java alongside the application with org.json available. Run this fragment inside a method that declares or handles the implementation's checked exceptions.

For a different recipient, use that recipient's public encryption key rather than the local identity's encryption key. Public-key export and interoperability coverage vary by implementation; see Keys and Languages. Private key files are not account credentials and must not be sent to PUT /auth/keys.

Message connections

Account login does not establish a message connection. The current server accepts JSON WebSocket frames and can authenticate an upgrade with a login session or an issued grant token. Login sessions carry identity without path restrictions; grants limit routing to assigned patterns. See WebSocket and Routing.

The encrypted registration handshake in the ping/pong samples is not implemented by the current mesgd listener. Treat those samples as experimental cryptographic examples, with compatibility limits described in Samples.

Validation

This account module is not included in the shared auth contract runner. Check it with the application's own toolchain and transport before deployment. The presence of source examples does not imply that live HTTPS or cross-language cryptographic behavior has been validated for this implementation. Languages lists the repository's current test coverage.