microchipAdvanced

Advanced Features & Concepts for Vector SDK

Advanced Documentation

This document covers advanced features and concepts in the Vector SDK.


Table of Contents


Message Layer Security (MLS)

Vector SDK integrates with the nostr-mlsarrow-up-right protocol for secure group messaging.

Overview

MLS provides:

  • End-to-end encryption for group messages

  • Forward secrecy through ephemeral keys

  • Efficient key management for groups

  • Secure group membership changes

Group Lifecycle

Creating a Group

Joining a Group

Sending Group Messages

Sending Files in Groups

Group Metadata

Groups store metadata including:

  • group_id: Wire identifier used on relays

  • engine_group_id: Internal engine identifier

  • creator_pubkey: Public key of group creator

  • name: Group display name

  • avatar_ref: Reference to group avatar

  • created_at: Unix timestamp of creation

  • updated_at: Unix timestamp of last update

  • evicted: Flag indicating if user was evicted


Typing Indicators

Typing indicators provide real-time feedback about message composition.

Implementation Details

  • Protocol: NIP-40 (Application-Specific Data)

  • Kind: Kind::ApplicationSpecificData (31999)

  • Content: String "typing"

  • Expiration: 30 seconds from creation

  • Tags:

    • d tag with value "vector" for namespace

    • ms tag with millisecond precision timestamp

    • expiration tag for relay cleanup

Usage

Direct Messages

Groups


Proxy Configuration

Vector SDK supports proxy configuration for .onion relays.

Configuration Options

Using Tor

To use the embedded Tor client instead of a SOCKS proxy:


Error Handling

Vector SDK provides comprehensive error handling through the VectorBotError enum.

Error Types

Handling Errors

Converting Errors


Debugging

Logging Setup

Configure logging in your application:

Log Levels

  • Error: Critical errors that need attention

  • Warn: Potential issues or deprecated features

  • Info: Important operational messages

  • Debug: Detailed debugging information

  • Trace: Very detailed tracing information

Debugging Tips

  1. Enable verbose logging:

  2. Check relay connections:

  3. Inspect events:

  4. Monitor uploads:


Logging Configuration

Custom Log Format

Structured Logging

For applications that need structured logging:


Custom Metadata

Vector SDK supports custom metadata fields through the builder pattern.

Using the Metadata Builder

Adding Custom Fields


Group Management

Checking Group Messages

Processing Incoming Messages


File Handling

File Type Detection

Vector SDK automatically detects file types from bytes:

Image Metadata

For image files, additional metadata is extracted:

File Hashing

Files are hashed using SHA-256 for integrity verification:


Performance Considerations

Upload Performance

  • Chunk Size: Default 64KB chunks for streaming uploads

  • Retry Strategy: Configurable retry count and spacing

  • Progress Tracking: Periodic progress callbacks (every 100ms)

  • Stall Detection: Detects stalled uploads after 20 seconds

Configuration Options

Memory Management

  • Streaming Uploads: Files are streamed in chunks to minimize memory usage

  • Encryption: Data is encrypted in-place when possible

  • Cleanup: Temporary data is cleared after processing

Concurrent Operations

Vector SDK is designed to work with Tokio's async runtime:

  • Multiple uploads can run concurrently

  • Messages can be sent while uploads are in progress

  • Group operations are non-blocking

Last updated