AuthSocket WebSocket Protocol 1.0.0

AsyncAPI 3.0 specification for the AuthSocketServer / AuthSocket WebSocket channel used by the BSV MessageBox Server.

Transport layer

AuthSocketServer wraps Socket.IO and sits on top of an HTTP server. All Socket.IO events are standard Socket.IO framing; this spec describes the application-level event names and payload shapes that flow over the Socket.IO connection.

BRC-103 mutual authentication

Every Socket.IO connection undergoes BRC-103 (Peer) handshake before application events are exchanged. The handshake is carried on the authMessage event using the AuthMessage envelope defined in the @bsv/sdk Transport interface.

Once the handshake succeeds the peer's identityKey (compressed secp256k1 public key, 66-char hex) is known server-side and stored in memory for the lifetime of the connection.

Application events

After authentication the server emits and listens for the events described below. All application payloads are serialized as JSON inside the BRC-103 general message (Peer.toPeer). The transport layer (SocketServerTransport) wraps them in an { eventName, data } envelope before signing.

Source of truth:

  • packages/messaging/authsocket/src/AuthSocketServer.ts
  • packages/messaging/authsocket/src/SocketServerTransport.ts
  • packages/messaging/message-box-server/src/index.ts

Servers

  • wss://messagebox.babbage.systems/wssproduction

    Production MessageBox WebSocket endpoint (Socket.IO over WSS).

  • ws://localhost:{port}/wslocal

    Local development Socket.IO server.

    object
    string
    required

    HTTP port the MessageBox Server listens on.

Operations

  • RECEIVE authMessage

    Low-level Socket.IO event used by SocketServerTransport to carry BRC-103 AuthMessage frames. This event is NOT an application event; it is emitted and received transparently by the Peer class from @bsv/sdk. Application developers do not interact with this channel directly — they use the typed events below.

    See packages/messaging/authsocket/src/SocketServerTransport.ts.

    Server receives an AuthMessage frame from the client during BRC-103 handshake.

    Operation IDreceiveAuthMessage

    Available only on servers:

    Accepts the following message:

    BRC-103 auth frame (both directions — client and server).

    Message IDauthMessageFrame
    object

    BRC-103 auth envelope as defined in @bsv/sdk. Carried on the low-level authMessage Socket.IO event. Not an application-level event.

    Examples

  • SEND authMessage

    Low-level Socket.IO event used by SocketServerTransport to carry BRC-103 AuthMessage frames. This event is NOT an application event; it is emitted and received transparently by the Peer class from @bsv/sdk. Application developers do not interact with this channel directly — they use the typed events below.

    See packages/messaging/authsocket/src/SocketServerTransport.ts.

    Server sends an AuthMessage frame to the client during BRC-103 handshake.

    Operation IDsendAuthMessage

    Available only on servers:

    Accepts the following message:

    BRC-103 auth frame (both directions — client and server).

    Message IDauthMessageFrame
    object

    BRC-103 auth envelope as defined in @bsv/sdk. Carried on the low-level authMessage Socket.IO event. Not an application-level event.

    Examples

  • RECEIVE authenticated

    Fallback authentication event. The client emits this when its identity key was not included in the Socket.IO handshake. The server validates the key, updates its in-memory authenticatedSockets map, and emits authenticationSuccess or authenticationFailed in response.

    Server receives the client's identity key on the 'authenticated' event.

    Operation IDreceiveAuthenticated

    Available only on servers:

    Accepts the following message:

    Client sends its identity key for post-connection auth.

    Message IDauthenticateMessage
    object

    Sent by the client on the authenticated event when the identity key was not available at connection time (fallback path). The server validates the key and responds with authenticationSuccess or authenticationFailed.

    Examples

  • SEND authenticationSuccess

    Emitted by the server after successful identity key validation.

    Server confirms successful identity key validation.

    Operation IDsendAuthenticationSuccess

    Available only on servers:

    Accepts the following message:

    Message IDauthSuccessMessage
    object

    Examples

  • SEND authenticationFailed

    Emitted by the server when identity key validation fails.

    Server rejects an invalid identity key.

    Operation IDsendAuthenticationFailed

    Available only on servers:

    Accepts the following message:

    Message IDauthFailedMessage
    object

    Examples

  • RECEIVE joinRoom

    Client requests to subscribe to a room. Only authenticated sockets may join rooms. The server responds with joinedRoom on success or joinFailed on error.

    Room ID convention: <recipientIdentityKey>-<messageBoxType>.

    Server receives a room join request.

    Operation IDreceiveJoinRoom

    Available only on servers:

    Accepts the following message:

    Room ID string to join.

    Message IDjoinRoomMessage
    Payloadstring

    The room ID string sent by the client on the joinRoom event. Room IDs use the convention <recipientKey>-<messageBoxType>. Example: 028d37b9...-payment_inbox.

    Examples

  • SEND joinedRoom

    Server confirms the client has joined the specified room.

    Server confirms room join.

    Operation IDsendJoinedRoom

    Available only on servers:

    Accepts the following message:

    Message IDjoinedRoomMessage
    object

    Examples

  • SEND joinFailed

    Emitted when joinRoom fails (unauthenticated or invalid roomId).

    Server signals room join failure.

    Operation IDsendJoinFailed

    Available only on servers:

    Accepts the following message:

    Message IDjoinFailedMessage
    object

    Examples

  • RECEIVE leaveRoom

    Client requests to leave a room.

    Server receives a room leave request.

    Operation IDreceiveLeaveRoom

    Available only on servers:

    Accepts the following message:

    Room ID string to leave.

    Message IDleaveRoomMessage
    Payloadstring

    The room ID string sent by the client on the leaveRoom event.

    Examples

  • SEND leftRoom

    Server confirms the client has left the room.

    Server confirms room leave.

    Operation IDsendLeftRoom

    Available only on servers:

    Accepts the following message:

    Message IDleftRoomMessage
    object

    Examples

  • SEND leaveFailed

    Emitted when leaveRoom fails.

    Server signals room leave failure.

    Operation IDsendLeaveFailed

    Available only on servers:

    Accepts the following message:

    Message IDleaveFailedMessage
    object

    Examples

  • RECEIVE sendMessage

    Client sends a message to a recipient via WebSocket. The server:

    1. Validates the sender is authenticated.
    2. Validates roomId and message.
    3. Creates the message box if it does not exist.
    4. Inserts the message into the database (with ON CONFLICT IGNORE dedup).
    5. Emits sendMessageAck-{roomId} back to the sender.
    6. Broadcasts sendMessage-{roomId} to all connections in the room.

    Server receives a message from the client to deliver to a recipient.

    Operation IDreceiveSendMessage

    Available only on servers:

    Accepts the following message:

    Message IDsendMessageMessage
    object

    Payload for the client-to-server sendMessage event.

    Examples

  • SEND sendMessageAck-{roomId}

    Per-room acknowledgement emitted to the sender only after the message is stored. The event name is sendMessageAck-<roomId> where roomId matches the value in the originating sendMessage payload.

    Server acknowledges delivery of a message to the sender.

    Operation IDsendSendMessageAck

    Available only on servers:

    object
    roomIdstring
    required

    The room ID from the originating sendMessage request.

    Accepts the following message:

    Message IDsendMessageAckMessage
    object

    Acknowledgement emitted by the server on sendMessageAck-{roomId} after a successful sendMessage. Note: the event name is dynamic and includes the room ID used in the originating request.

    Examples

  • SEND sendMessage-{roomId}

    Broadcast emitted to all connections subscribed to roomId after a successful sendMessage. The event name is sendMessage-<roomId>.

    Server broadcasts a new message to all room subscribers.

    Operation IDsendSendMessageBroadcast

    Available only on servers:

    object
    roomIdstring
    required

    The target room ID.

    Accepts the following message:

    Message IDsendMessageBroadcastMessage
    object

    Broadcast emitted by the server on sendMessage-{roomId} to all connections in the room (including the sender). Note: the event name is dynamic.

    Examples

  • SEND messageFailed

    Emitted to the sender when sendMessage processing fails.

    Server signals message delivery failure.

    Operation IDsendMessageFailed

    Available only on servers:

    Accepts the following message:

    Message IDmessageFailedMessage
    object

    Examples

  • SEND paymentFailed

    Emitted to unauthenticated sockets that attempt to send a message (same event name reused from older payment-gate logic).

    Server signals auth/payment gate rejection.

    Operation IDsendPaymentFailed

    Available only on servers:

    Accepts the following message:

    Message IDpaymentFailedMessage
    object

    Examples

  • RECEIVE disconnect

    Standard Socket.IO disconnect event. The server removes the socket from the authenticatedSockets map and the peers map in AuthSocketServer.

    Client disconnects; server cleans up in-memory state.

    Operation IDreceiveDisconnect

    Available only on servers:

    Accepts the following message:

    Message IDdisconnectMessage
    Payloadstring

    The Socket.IO disconnect reason string (e.g. transport close, server namespace disconnect).

    Examples

Schemas

  • string

    Compressed secp256k1 public key, 66 hex characters.

  • object

    BRC-103 auth envelope as defined in @bsv/sdk. Carried on the low-level authMessage Socket.IO event. Not an application-level event.

  • object

    Application-level wrapper JSON-encoded inside the BRC-103 general message payload. The SocketServerTransport encodes/decodes this transparently; application code only sees eventName and data.

  • object

    Sent by the client on the authenticated event when the identity key was not available at connection time (fallback path). The server validates the key and responds with authenticationSuccess or authenticationFailed.

  • object
  • object
  • JoinRoomPayloadstring

    The room ID string sent by the client on the joinRoom event. Room IDs use the convention <recipientKey>-<messageBoxType>. Example: 028d37b9...-payment_inbox.

  • object
  • object
  • LeaveRoomPayloadstring

    The room ID string sent by the client on the leaveRoom event.

  • object
  • object
  • object

    Payload for the client-to-server sendMessage event.

  • object

    Acknowledgement emitted by the server on sendMessageAck-{roomId} after a successful sendMessage. Note: the event name is dynamic and includes the room ID used in the originating request.

  • object

    Broadcast emitted by the server on sendMessage-{roomId} to all connections in the room (including the sender). Note: the event name is dynamic.

  • object
  • object
  • DisconnectPayloadstring

    The Socket.IO disconnect reason string (e.g. transport close, server namespace disconnect).