This source candidate declares SDK peer ^2.4.1 || ^3.0.0. SDK3 remains
a coordinated proposal; see the qualification and migration limits
before adopting it.
Client-side BRC-103 mutual authentication wrapper for socket.io-client. Signs all outbound messages and verifies inbound messages using a wallet, enabling authenticated peer-to-peer WebSocket communication.
npm install @bsv/authsocket-clientimport { AuthSocketClient } from '@bsv/authsocket-client'
import { PrivateKey, ProtoWallet } from '@bsv/sdk'
const clientWallet = new ProtoWallet(
PrivateKey.fromHex('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef')
)
const socket = AuthSocketClient('http://localhost:3000', { wallet: clientWallet })
socket.on('connect', () => {
console.log('Socket.IO transport connected. Socket ID:', socket.id)
socket.emit('chatMessage', { text: 'Hello from client!' })
})
socket.on('chatMessage', msg => {
console.log('Server says:', msg)
})
socket.on('disconnect', () => {
console.log('Disconnected')
})connect and connected describe the raw Socket.IO transport, not a completed
BRC-103 identity proof. Outbound application events complete the handshake
before their signed payload is sent, and inbound application callbacks receive
only verified general messages. When local behavior requires a known server,
set expectedServerIdentityKey and wait for a verified application event.
.on(), .emit(), .id, .connect(), .disconnect()import { AuthSocketClient } from '@bsv/authsocket-client'
import { PrivateKey, ProtoWallet } from '@bsv/sdk'
const wallet = new ProtoWallet(
PrivateKey.fromHex('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef')
)
const socket = AuthSocketClient('http://localhost:3000', { wallet })
socket.on('connect', () => {
console.log('Transport connected; the first emit performs BRC-103 authentication')
socket.emit('joinRoom', 'general')
})
socket.on('message', data => {
console.log('Received:', data)
})const socket = AuthSocketClient('http://localhost:3000', {
wallet: myWallet,
managerOptions: {
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: 5
}
})const socket = AuthSocketClient('http://localhost:3000', {
wallet,
maxPendingAuthMessages: 32,
onError: (error, context) => {
console.error(context.phase, context.eventName, error)
}
})Malformed server authentication traffic and application callback failures are
contained before they can become unhandled rejections. The error context does
not include remote payloads or wallet material, and an onError handler that
throws or rejects is also contained.
@bsv/authsocket)@bsv/auth-express-middleware@bsv/message-box-client insteadPeer and Transport abstractions from SDKsign() and verify() methods@bsv/authsocket or implement BRC-103 Peer yourselfconnect is transport state — wait for a verified application event before treating an unpinned server as authenticatedAuthSocketClient for live message delivery