Design SDK offline transaction preparation model#245
Merged
Conversation
…ion account validation strategy for payment flows.
…r offline transaction preparation.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #237
Implementation Summary
A complete module for preparing transactions offline with clear network dependencies:
Network Dependencies Identified:
Can be prepared offline: Transaction operations, memos, asset specifications, timebounds, input validation
Requires network state: Source account sequence number (CRITICAL), account balance verification, fee estimation, trustline verification
Core Functions:
prepareTransactionOffline() - Prepare transaction without network access
fetchNetworkState() - Fetch sequence number and account data from Horizon
updateWithNetworkState() - Add sequence number to prepared transaction
buildUnsignedTransaction() - Build unsigned transaction ready for signing
signTransaction() - Sign with secret key (offline-capable)
signTransactionWithSigner() - Sign with Signer interface (hardware wallet support)
submitSignedTransaction() - Submit signed transaction to Horizon
prepareAndSignTransaction() - Complete workflow helper
prepareTransactionWithManualSequence() - Fully offline with manual sequence
2. Type Definitions
Comprehensive type system for offline preparation:
OfflineTransactionParams - Preparation parameters
OfflinePaymentOperation - Payment operation structure
NetworkState - Required network state (sequence number is critical)
PreparedTransaction - Prepared but not yet built
UnsignedTransaction - Built but unsigned
SignedTransaction - Signed and ready for submission
SubmissionResult - Submission outcome
3. Integration
Exported all functions and types from index.ts for public API access.
Complete guide covering:
Network dependencies (what can be done offline vs. requires network)
Step-by-step workflow with code examples
Use cases: air-gapped signing, multi-party coordination, hardware wallets, transaction queuing
Prepared transaction shapes and type definitions
Signing and submission boundaries
Limitations and considerations (sequence number management, timebounds, fees, trustlines)
Error handling patterns
Safe wrappers for error-safe operations
Security best practices
Key Features
✅ Clear Boundaries - Explicitly separates what can be done offline from what requires network access
✅ Critical Dependency Identification - Sequence number is identified as the critical network dependency
✅ Flexible Workflow - Supports step-by-step preparation or complete workflow helper
✅ Hardware Wallet Support - Signer interface integration for external signers
✅ Manual Sequence Mode - Supports fully offline preparation when sequence number is known
✅ Safe Wrappers - Non-throwing variants for error-safe integration
✅ Comprehensive Error Handling - Clear error codes for missing sequence, account not found, key mismatch, submission failures
✅ Security Considerations - Documentation covers secret key protection, transaction verification, replay protection
Use Cases Enabled
Air-gapped signing: Prepare online, sign offline, submit online
Multi-party coordination: Prepare transaction, collect signatures from multiple parties
Delayed submission: Prepare now, submit when network is available
Transaction queuing: Prepare multiple transactions, submit in batch
Hardware wallet integration: Use external signers for enhanced security