invite

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TokenSize = 10

TokenSize is the byte length of an invite token.

Variables

This section is empty.

Functions

func Encode

func Encode(token []byte) (string, error)

Encode encodes a raw token (10 bytes, 80 bits) into an invite code. Format: KXMT-9FWR-PBLZ-4YAN (16 base36 chars, ~82.7 bits capacity).

func GenerateToken

func GenerateToken() ([]byte, error)

GenerateToken creates a cryptographically random 10-byte token.

func ReadPublicKey

func ReadPublicKey(r io.Reader) ([]byte, error)

ReadPublicKey reads a 32-byte X25519 public key from r.

Types

type InviteData

type InviteData struct {
	Token []byte // invite token (10 bytes)
}

InviteData holds the payload encoded in an invite code.

func Decode

func Decode(code string) (*InviteData, error)

Decode parses a dash-separated invite code back into InviteData.

type PAKESession

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

PAKESession holds the state for one side of a PAKE handshake.

func NewPAKESession

func NewPAKESession() (*PAKESession, error)

NewPAKESession creates a new PAKE session with a fresh ephemeral X25519 key pair.

func (*PAKESession) Complete

func (s *PAKESession) Complete(remotePub []byte, salt []byte, channelBinding ...[]byte) error

Complete performs the DH exchange and derives the AEAD key. remotePub is the other side's 32-byte X25519 public key. salt is the invite token (shared secret). Optional channelBinding binds the session to a specific relay peer ID, preventing relay swap attacks (PAKE fails if redirected to a different relay).

func (*PAKESession) ConfirmationMAC

func (s *PAKESession) ConfirmationMAC(role string) []byte

ConfirmationMAC computes a MAC over the role label using the session key. Both sides compute MACs with different labels ("inviter" vs "joiner") and exchange them for explicit key confirmation.

func (*PAKESession) Decrypt

func (s *PAKESession) Decrypt(r io.Reader) ([]byte, error)

Decrypt reads a length-prefixed encrypted message from r and decrypts it.

func (*PAKESession) Encrypt

func (s *PAKESession) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext with the derived session key using XChaCha20-Poly1305. Returns length-prefixed ciphertext suitable for writing to a stream.

func (*PAKESession) PublicKey

func (s *PAKESession) PublicKey() []byte

PublicKey returns the session's ephemeral X25519 public key (32 bytes).

func (*PAKESession) WriteEncrypted

func (s *PAKESession) WriteEncrypted(w io.Writer, plaintext []byte) error

WriteEncrypted encrypts plaintext and writes it to w.

func (*PAKESession) WritePublicKey

func (s *PAKESession) WritePublicKey(w io.Writer) error

WritePublicKey writes the session's public key to w (32 bytes).

Jump to

Keyboard shortcuts

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