go-wmp

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: BSD-2-Clause

README

go-wmp

CI Go Reference Quality Gate OpenSSF Scorecard Go Version License

Go library for the Wallet Messaging Protocol (WMP) — a JSON-RPC 2.0 based multi-party messaging protocol with optional MLS end-to-end encryption.

Installation

go get github.com/sirosfoundation/go-wmp

Package Structure

Package Import Path Description
wmp github.com/sirosfoundation/go-wmp/pkg/wmp Core types, JSON-RPC codec, handler interface, peer, session management
ws github.com/sirosfoundation/go-wmp/pkg/wmp/ws WebSocket transport (wmp.v1 subprotocol)
httpsse github.com/sirosfoundation/go-wmp/pkg/wmp/httpsse HTTPS POST + Server-Sent Events transport

Usage

Server Side (handling incoming WMP connections)
import (
    "github.com/sirosfoundation/go-wmp/pkg/wmp"
    "github.com/sirosfoundation/go-wmp/pkg/wmp/ws"
)

// Implement the Handler interface (embed BaseHandler for defaults):
type myHandler struct {
    wmp.BaseHandler
    sessions wmp.SessionStore
}

func (h *myHandler) SessionCreate(ctx context.Context, params *wmp.SessionCreateParams) (*wmp.SessionCreateResult, error) {
    sess := &wmp.Session{
        ID:           "ses-" + generateID(),
        Participants: params.Participants,
        Capabilities: params.CapabilitiesOffered,
        Security:     params.Security,
        CreatedAt:    time.Now(),
        ExpiresAt:    time.Now().Add(time.Duration(params.TTL) * time.Second),
    }
    h.sessions.Create(sess)
    return &wmp.SessionCreateResult{
        WMP:          wmp.Metadata{Version: wmp.Version, SessionID: sess.ID},
        Capabilities: sess.Capabilities,
        Security:     sess.Security,
    }, nil
}

func (h *myHandler) FlowStart(ctx context.Context, params *wmp.FlowStartParams) (*wmp.FlowStartResult, error) {
    // Handle flow start...
}

// In your HTTP handler:
func handleWMP(w http.ResponseWriter, r *http.Request) {
    transport, err := ws.Upgrade(w, r)
    if err != nil { return }

    peer := wmp.NewPeer(transport, &myHandler{
        sessions: wmp.NewMemorySessionStore(),
    })
    peer.Serve(r.Context())
}
Client Side (connecting to a WMP endpoint)
import (
    "github.com/sirosfoundation/go-wmp/pkg/wmp"
    "github.com/sirosfoundation/go-wmp/pkg/wmp/ws"
)

// Connect:
transport, _, err := ws.Dial(ctx, "wss://example.com/wmp", nil)
if err != nil { log.Fatal(err) }

peer := wmp.NewPeer(transport, &myClientHandler{})
go peer.Serve(ctx)

// Create session:
var result wmp.SessionCreateResult
err = peer.Call(ctx, wmp.MethodSessionCreate, wmp.SessionCreateParams{
    WMP:      wmp.Metadata{Version: wmp.Version, Sender: "did:web:me.example.com"},
    Security: wmp.SecurityMode{Mode: "tls"},
    TTL:      3600,
}, &result)

// Send a message:
peer.Notify(ctx, wmp.MethodMessageDeliver, wmp.MessageDeliverParams{
    WMP:         wmp.Metadata{Version: wmp.Version, SessionID: result.WMP.SessionID},
    ContentType: "application/json",
    Body:        json.RawMessage(`{"text":"Hello"}`),
})

Phase 1 Scope

This initial release covers:

  • Core types — All WMP message types, metadata, capabilities, security modes
  • JSON-RPC 2.0 codec — Request/response/notification/batch encoding
  • Handler interface — With BaseHandler for embedding
  • Peer — Bidirectional JSON-RPC over any transport (Call, Notify, Serve)
  • Session management — Session type + in-memory store
  • WebSocket transport — gorilla/websocket with wmp.v1 subprotocol
  • HTTPS+SSE transport — Client and server-side HTTP transport

Not yet implemented: MLS encryption, eDelivery profile, evidence profile.

OpenSSF Scorecard

License

Apache 2.0

Directories

Path Synopsis
cmd
wmp-cli command
Command wmp-cli is a minimal WMP messaging client for debugging and interop testing.
Command wmp-cli is a minimal WMP messaging client for debugging and interop testing.
examples
echo command
Package main demonstrates a minimal WMP echo server over WebSocket.
Package main demonstrates a minimal WMP echo server over WebSocket.
pkg
wmp
Package wmp defines the core types for the Wallet Messaging Protocol.
Package wmp defines the core types for the Wallet Messaging Protocol.
wmp/httpsse
Package httpsse provides an HTTPS+SSE transport for WMP.
Package httpsse provides an HTTPS+SSE transport for WMP.
wmp/mls
Package mls defines WMP MLS types, method constants, and the MLSHandler interface for MLS group lifecycle operations per the wmp-mls spec.
Package mls defines WMP MLS types, method constants, and the MLSHandler interface for MLS group lifecycle operations per the wmp-mls spec.
wmp/openid4x
Package openid4x implements the WMP OpenID4x profile as a wmp.Profile plugin.
Package openid4x implements the WMP OpenID4x profile as a wmp.Profile plugin.
wmp/relay
Package relay implements the WMP relay profile — a rendezvous point for wallet-to-wallet messaging per wmp-transport.md §6.2–6.5.
Package relay implements the WMP relay profile — a rendezvous point for wallet-to-wallet messaging per wmp-transport.md §6.2–6.5.
wmp/schema
Package schema provides WMP JSON Schema validation.
Package schema provides WMP JSON Schema validation.
wmp/stdio
Package stdio implements WMP transport over stdin/stdout using NDJSON (newline-delimited JSON).
Package stdio implements WMP transport over stdin/stdout using NDJSON (newline-delimited JSON).
wmp/ws
Package ws provides a WebSocket transport for WMP using the wmp.v1 subprotocol.
Package ws provides a WebSocket transport for WMP using the wmp.v1 subprotocol.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL