🏗️ Starting the Meeting
Creating an MLS Group
In 15 minutes: Learn to create your first MLS group
Prerequisite: Welcome messages
🎯 The Simple Story
Alice wants to create a secure group chat with MLS.
She's like creating a "Secret Meeting Room" where:
- She's the first one inside
- She decides who can join
- She has the master key
Let's see how this works
🧠 Mental Model
Hold this picture in your head:
Creating an MLS Group:
Step 1: Alice prepares (key package)
└─ Generate key package (ID card)
Step 2: Alice creates room
└─ Initialize MLS manager (create group)
Step 3: Room is ready
└─ Has ratchet tree, group secret, epoch 0
└─ Alice inside (index 0)
Step 4: Alice waits for others
└─ Can send messages to empty room?
└─ Or wait for members to join
Result: Secret meeting room created
📊 See It Happen
🎭 Code: Creating a Group
Step 1: Initialize MLS Manager
import { MLSManager } from 'ts-mls';
// Alice's code
const alice = new MLSManager('alice@example.com');
// Step 1: Initialize with ciphersuite
await alice.initialize();
What this does:
- Creates MLS manager for Alice
- Chooses ciphersuite (crypto algorithm)
- Sets up crypto provider
Step 2: Generate Key Package
// Step 2: Generate key package (Alice's ID card)
const aliceKeyPackage = await alice.generateKeyPackage();
// Alice shares her key package public part
const aliceKeyPackagePublic = aliceKeyPackage.publicPackage;
What this does:
- Generates key package for Alice
- Public part: Can share with anyone
- Private part: Alice keeps secret
- Used by others to encrypt for Alice
Step 3: Create the Group
// Step 3: Create the group
const groupInfo = await alice.createGroup('team-chat');
console.log('Group created');
console.log('Group ID:', groupInfo.groupId);
console.log('Epoch:', groupInfo.epoch);
console.log('Members:', groupInfo.members);
What this does:
- Creates empty group
- Alice is the first member (index 0)
- Generates group secret K₀
- Sets up ratchet tree
- Epoch 0 starts
Step 4: What Happens Behind the Scenes?
createGroup(team-chat) does:
1. Create group ID
team-chat → group_id (bytes)
2. Initialize ratchet tree
Tree: [Alice (leaf 0)]
└─ GroupSecret (root)
3. Generate group secret
K₀ = random 32 bytes
4. Create group context
├─ group_id
├─ epoch = 0
├─ tree_hash
└─ ciphersuite
5. Store state
alice.groups.set(team-chat, ClientState)