whatsmeowgo.mau.fi/whatsmeow/socket Index | Files

package socket

import "go.mau.fi/whatsmeow/socket"

Package socket implements a subset of the Noise protocol framework on top of websockets as used by WhatsApp.

There shouldn't be any need to manually interact with this package. The Client struct in the top-level whatsmeow package handles everything.

Index

Constants

const (
	// Origin is the Origin header for all WhatsApp websocket connections
	Origin = "https://web.whatsapp.com"
	// URL is the websocket URL for the new multidevice protocol
	URL = "wss://web.whatsapp.com/ws/chat"
)
const (
	NoiseStartPattern = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00"

	WAMagicValue = 6
)
const (
	FrameMaxSize    = 2 << 23
	FrameLengthSize = 3
)

Variables

var (
	ErrFrameTooLarge     = errors.New("frame too large")
	ErrSocketClosed      = errors.New("frame socket is closed")
	ErrSocketAlreadyOpen = errors.New("frame socket is already open")
)
var WAConnHeader = []byte{'W', 'A', WAMagicValue, token.DictVersion}

Types

type DisconnectHandler

type DisconnectHandler func(socket *NoiseSocket, remote bool)

type FrameHandler

type FrameHandler func([]byte)

type FrameSocket

type FrameSocket struct {
	URL         string
	HTTPHeaders http.Header

	Frames       chan []byte
	OnDisconnect func(remote bool)
	WriteTimeout time.Duration

	Header []byte
	Dialer websocket.Dialer
	// contains filtered or unexported fields
}

func NewFrameSocket

func NewFrameSocket(log waLog.Logger, dialer websocket.Dialer) *FrameSocket

func (*FrameSocket) Close

func (fs *FrameSocket) Close(code int)

func (*FrameSocket) Connect

func (fs *FrameSocket) Connect() error

func (*FrameSocket) Context

func (fs *FrameSocket) Context() context.Context

func (*FrameSocket) IsConnected

func (fs *FrameSocket) IsConnected() bool

func (*FrameSocket) SendFrame

func (fs *FrameSocket) SendFrame(data []byte) error

type NoiseHandshake

type NoiseHandshake struct {
	// contains filtered or unexported fields
}

func NewNoiseHandshake

func NewNoiseHandshake() *NoiseHandshake

func (*NoiseHandshake) Authenticate

func (nh *NoiseHandshake) Authenticate(data []byte)

func (*NoiseHandshake) Decrypt

func (nh *NoiseHandshake) Decrypt(ciphertext []byte) (plaintext []byte, err error)

func (*NoiseHandshake) Encrypt

func (nh *NoiseHandshake) Encrypt(plaintext []byte) []byte

func (*NoiseHandshake) Finish

func (nh *NoiseHandshake) Finish(fs *FrameSocket, frameHandler FrameHandler, disconnectHandler DisconnectHandler) (*NoiseSocket, error)

func (*NoiseHandshake) MixIntoKey

func (nh *NoiseHandshake) MixIntoKey(data []byte) error

func (*NoiseHandshake) MixSharedSecretIntoKey

func (nh *NoiseHandshake) MixSharedSecretIntoKey(priv, pub [32]byte) error

func (*NoiseHandshake) Start

func (nh *NoiseHandshake) Start(pattern string, header []byte)

type NoiseSocket

type NoiseSocket struct {
	// contains filtered or unexported fields
}

func (*NoiseSocket) Context

func (ns *NoiseSocket) Context() context.Context

func (*NoiseSocket) IsConnected

func (ns *NoiseSocket) IsConnected() bool

func (*NoiseSocket) SendFrame

func (ns *NoiseSocket) SendFrame(plaintext []byte) error

func (*NoiseSocket) Stop

func (ns *NoiseSocket) Stop(disconnect bool)

Source Files

constants.go framesocket.go noisehandshake.go noisesocket.go

Version
v0.0.0-20250326122532-6680c9a6e9a7 (latest)
Published
Mar 26, 2025
Platform
linux/amd64
Imports
17 packages
Last checked
5 hours ago

Tools for package owners.