Session Management
Every dWallet protocol operation (DKG, presign, sign, future sign) requires a unique SessionIdentifier. This ensures each operation is processed exactly once and prevents replay attacks.
What is a SessionIdentifier?
A SessionIdentifier is a registered unique identifier that:
- Prevents duplicate operations
- Enables the network to track and correlate requests with responses
- Provides cryptographic binding between requests and results
Creating Session Identifiers
Pattern 1: Using Fresh Object Address (Recommended)
The most common pattern uses Sui's transaction context to generate unique bytes:
This approach:
- Guarantees uniqueness within the transaction
- Uses Sui's built-in randomness
- Is simple and reliable
Pattern 2: Custom Bytes
You can also provide custom bytes (must be unique):
Uniqueness Required
If you use custom bytes, you must ensure they are unique across all operations. Duplicate session identifiers will cause the operation to fail.
Using Session Identifiers
Session identifiers are consumed by protocol operations:
DKG
Presign
Sign
Future Sign
Helper Function Pattern
Create a reusable helper in your contract:
TypeScript SDK Integration
When calling Move functions that need session identifiers, you have two options:
Option 1: Create in Move (Recommended)
Let your Move contract create the session identifier:
Option 2: Pass from TypeScript
For more control, create and pass the identifier:
Then in Move:
Best Practices
- Create Just Before Use: Create session identifiers immediately before the operation that uses them
- Don't Reuse: Each operation needs its own session identifier
- Use Fresh Object Address: The
ctx.fresh_object_address().to_bytes()pattern is simple and reliable - Helper Functions: Create a helper function in your contract for consistency
Common Errors
| Error | Cause | Solution |
|---|---|---|
| Session already exists | Reusing session bytes | Generate new unique bytes |
| Invalid session | Session not registered | Call register_session_identifier first |
Next Steps
- Learn about Payment Handling for managing protocol fees