AssociationState
TheAssociationState represents the current state of all associations for an inbox:
state.rs:57-63 for the struct definition.
Querying State
state.rs:115-218 for method implementations.
Creating State
Create a new state from a wallet:state.rs:252-267 for the new method.
MemberIdentifier
MemberIdentifier represents any entity that can be associated with an inbox:
member.rs:20-26 for the enum definition.
Creating Identifiers
Querying Identifiers
member.rs:70-112 for accessor methods.
Member
TheMember struct contains metadata about an association:
member.rs:345-382 for the struct definition.
Member Hierarchy
Members form a tree structure:Association Rules
The system enforces specific rules for associations:Allowed Associations
| Existing Member | Can Add |
|---|---|
| Wallet | Wallet, Installation, Passkey |
| Installation | Wallet, Passkey |
| Passkey | Wallet, Installation, Passkey |
association_log.rs:431-445 for the validation logic.
Signature Requirements
| Member Kind | Required Signature |
|---|---|
| Ethereum | ERC-191, ERC-1271, LegacyDelegated |
| Installation | InstallationKey (Ed25519) |
| Passkey | P256 (WebAuthn) |
association_log.rs:448-470 for signature validation.
SignatureRequest Builder
TheSignatureRequestBuilder provides a fluent API for creating identity updates:
builder.rs:48-52 for the struct definition.
Creating Requests
Create Inbox
builder.rs:64-80 for the create_inbox method.
Add Association
builder.rs:82-99 for the add_association method.
Revoke Association
builder.rs:101-117 for the revoke_association method.
Change Recovery Address
builder.rs:119-135 for the change_recovery_address method.
Chaining Actions
Multiple actions can be combined in a single update:SignatureRequest
Once built, aSignatureRequest collects signatures before publishing:
builder.rs:176-183 for the struct definition.
Managing Signatures
builder.rs:200-312 for the implementation.
Signature Flow
Identity Updates
Update Actions
Each action modifies the association state:CreateInbox
association_log.rs:69-75 for the struct definition.
Rules:
- Can only be applied to a non-existent state
- Signature must match the account identifier
- Legacy signatures only allowed with nonce 0
AddAssociation
association_log.rs:116-122 for the struct definition.
Rules:
- Both members must sign
- Existing member must be in current state or be recovery address
- New member signature must match new member identifier
- Installation cannot add installation
- Legacy signatures only with nonce 0 inboxes
RevokeAssociation
association_log.rs:220-224 for the struct definition.
Rules:
- Only recovery address can revoke
- Cannot use legacy signatures
- Revokes member and all child installations
- Idempotent (can revoke already-revoked member)
ChangeRecoveryIdentity
association_log.rs:280-284 for the struct definition.
Rules:
- Only current recovery address can change
- Cannot use legacy signatures
- Does not revoke old recovery address (still in state)
Applying Updates
mod.rs:20-39 for the helper functions.
IdentityUpdate Structure
association_log.rs:360-366 and association_log.rs:321-328 for the definitions.
AssociationStateDiff
Track changes between two states:state.rs:23-55 for the struct definition.
Computing Diffs
state.rs:220-250 for the diff method.
Convert State to Diff
Replay Protection
The system prevents signature replay attacks:IdentityUpdate are automatically added to the seen set after successful application.
See state.rs:141-150 for the replay protection methods.
Smart Contract Wallets
Smart contract wallets (SCW) require special handling:Chain ID Binding
SCW signatures are bound to a specific chain ID:association_log.rs:472-484 for chain ID verification.
Block Number Verification
SCW signatures need the block number for verification:builder.rs:217-245 for SCW signature handling.
Error Handling
association_log.rs:9-48 for all error types.
Best Practices
- Validate before applying - Check signatures and state before publishing updates
- Use the builder pattern -
SignatureRequestBuilderensures correct request structure - Collect all signatures - Check
is_ready()before publishing - Handle async signatures - Wallet signatures may require user interaction
- Respect association rules - Installations cannot add installations
- Track state diffs - Use diffs for efficient member change tracking
- Verify chain IDs - Ensure SCW signatures use consistent chain IDs
- Implement replay protection - Always check
has_seen()for signatures
Related Pages
- Overview - Identity system concepts
- Inbox Management - Working with inboxes and installations
References
- XIP-46: Identity Association State
- Source:
crates/xmtp_id/src/associations/ - Source:
crates/xmtp_mls/src/identity_updates.rs
