docs(trustline): design trustline validation support for issued asset payment flows (Closes #167)#225
Merged
El-swaggerito merged 1 commit intoJul 23, 2026
Conversation
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.
Description
Closes #167
Designs and documents pre-flight trustline validation support for issued asset payment flows on the Stellar network.
Issued asset payments (e.g. USDC, EURT, or custom project tokens) fail on-chain if the recipient account does not have an active, authorized trustline with sufficient capacity. This feature introduces a two-tiered validation model (local pre-flight format validation + network Horizon account inspection) to detect missing or invalid trustlines before building and submitting transactions.
Changes Included
1. Types (
src/types/index.ts)StellarAssetSpec: Represents native XLM or issued asset (code,issuer).TrustlineStatus: Status discriminant (valid,native_xlm,missing_trustline,not_authorized,limit_exceeded,account_not_found).TrustlineCheckResult: Detailed validation outcome containing capacity, authorization status, and recovery messages.TrustlineCheckOptions: Options for amount checking and SDK config overrides.2. Implementation (
src/payments/trustline.ts&src/payments/index.ts)validateAssetSpec(asset): Pure local validation for asset code format (1-12 alphanumeric chars) and issuer key format.checkDestinationTrustline(destination, asset, options?): Network check looking up recipient balances on Horizon for existence, trustline match, issuer authorization, and capacity (limit - balance >= amount).safeCheckDestinationTrustline(...): Non-throwing wrapper returningPocketPayResult<TrustlineCheckResult>.verifyPaymentTrustlineOrThrow(...): Pre-flight helper throwing structuredPocketPayErroron invalid trustlines.3. Documentation
docs/adr/0003-trustline-validation.md: Architecture Decision Record detailing decision rationale and consequences.docs/trustline-validation.md: User & developer guide with flowcharts, taxonomy, recovery hints, and failure scenario code examples.README.md&docs/adr/README.md.4. Tests (
tests/trustline.test.ts)Verification
npm run verify(tsc --noEmit, circular dependency check, vitest suite, build). All 534 unit tests pass cleanly.