Go SDK

The Go account client is in go/auth.go 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
HTTPSAvailable: built-in verified HTTPS transport, covered by the live auth runner
WSSPending supported SDK message client; experimental samples are not current-server integration

Completeness position: 2 of 18. Verified HTTPS, explicit identity instances, JWK import/export, and tested peer encryption and signature verification. 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

The Go module is named mesgd-sdk, and its package is pki. Account operations use the standard library. An application can reference the local go directory with a Go module replace directive while developing against this checkout.

HTTPSAuthTransport returns a verified net/http transport with a 15-second timeout and redirects disabled. It uses the runtime's normal certificate trust configuration.

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.

package example

import pki "mesgd-sdk"

func ReadKeys(password, otp string) (map[string]interface{}, error) {
    transport, err := pki.HTTPSAuthTransport("https://mesgd.example.com")
    if err != nil { return nil, err }
    client := pki.AuthClient{Transport: transport}
    session, err := client.Login("alice", password, otp)
    if err != nil { return nil, err }
    token := session["access_token"].(string)
    keys, readErr := client.Keys(token)
    _, logoutErr := client.Logout(token)
    if readErr != nil { return nil, readErr }
    return keys, logoutErr
}

Calls return a decoded map[string]interface{} and an error. Use errors.As with *pki.AuthError to read an HTTP status. PubJWK() returns one map containing signing_pub and encrypting_pub, rather than two return values.

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.

enrollment, err := client.Signup("alice", "alice@example.com", password, nil)
if err != nil { return err }
// Display enrollment, then obtain enrollmentOTP from the configured authenticator.
session, err := client.Confirm("alice", enrollment["enrollment_token"].(string), enrollmentOTP)
if err != nil { return err }
recoveryCodes := session["recovery_codes"]
_ = recoveryCodes // Hand these to the application's recovery-code display.

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.

identity, err := pki.Init("pki_keys.json")
if err != nil { return err }
signature, err := identity.Sign("hello")
if err != nil { return err }
valid, err := identity.Verify("hello", signature)
if err != nil { return err }
if !valid { return fmt.Errorf("signature rejected") }
ciphertext, err := identity.Encrypt("hello")
if err != nil { return err }
plaintext, err := identity.Decrypt(ciphertext)
if err != nil { return err }
if plaintext != "hello" { return fmt.Errorf("round trip failed") }
publicKeys := identity.PubJWK()
_ = publicKeys

This fragment belongs inside an error-returning function with the pki import above and fmt imported for the round-trip checks.

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

The Go ping/pong sample imports mesgd-sdk/pki and mesgd-sdk/mesgd, but the current Go module exposes package pki at the module root and contains no mesgd client package. Its transport wiring therefore requires implementation work.

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

From the mesgd-sdk repository root, run the account contract suite for this language:

python3 tests/test_auth.py --language go

This is an offline request-contract check. Missing toolchains are reported as skips. See Languages for live HTTPS and PKI test coverage.