fix: align charge module with draft-stellar-charge-00 spec#25
Merged
marcelosalloum merged 5 commits intomainfrom Mar 27, 2026
Merged
fix: align charge module with draft-stellar-charge-00 spec#25marcelosalloum merged 5 commits intomainfrom
marcelosalloum merged 5 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns the Stellar charge method’s credential and request structures with the draft-stellar-charge-00 spec and related mppx conventions, while extending server-side verification/settlement behavior.
Changes:
- Move toward spec-compliant credential/request fields (top-level
source, CAIP-2 network identifiers). - Add new constants and public exports (CAIP-2 mappings, ledger timing defaults,
SettlementError). - Expand test coverage across unit + integration tests for the updated structures and mappings.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/src/shared/errors.ts | Adds SettlementError error type for settlement/broadcast/confirmation failures. |
| sdk/src/index.ts | Re-exports CAIP-2 + default constants and exposes SettlementError publicly. |
| sdk/src/constants.ts | Introduces CAIP-2 network mapping constants and ledger/challenge timing defaults. |
| sdk/src/charge/server/Charge.ts | Updates request transform to CAIP-2, adds settlement error typing, and adds simulation/auth/timebounds validations. |
| sdk/src/charge/server/Charge.test.ts | Adds tests for request() transform (CAIP-2 network + feePayer behavior) and updates hash-credential setup. |
| sdk/src/charge/integration.test.ts | Updates mocked challenge network to CAIP-2 and adds spec-compliance tests for credential structure/source field placement. |
| sdk/src/charge/client/Charge.ts | Updates client network parsing to CAIP-2, adds DID-PKH source to credentials, and attempts to derive timebounds from challenge.expires. |
| sdk/src/charge/client/Charge.test.ts | Adds tests for missing key inputs, CAIP-2 mapping, and DID-PKH formatting. |
| sdk/src/charge/Methods.ts | Updates request schema methodDetails to require CAIP-2 network (and optional feePayer). |
| sdk/src/charge/Methods.test.ts | Adjusts schema tests for CAIP-2 network and refines payload discriminated union assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Type CAIP2_TO_NETWORK as Record<string, NetworkId | undefined> to accurately reflect that unknown CAIP-2 keys return undefined (#1) - Replace (builder as any).timeBounds mutation with setTimebounds() public API; the internal property is `timebounds` (lowercase) so the cast was a no-op, causing setTimeout(0) to set maxTime=now and immediately expire sponsored and unsponsored transactions (#2, #3) - Derive DID-PKH network component from resolved NetworkId, not raw CAIP-2 string, so source stays consistent when unknown identifiers fall back (#6, #7) - Replace inline Promise.race simulation with shared simulateCall() to get proper timer cleanup; map SimulationContractError → PaymentVerificationError (#4)
d4480ad to
eb38823
Compare
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.
What
stellar:testnet/stellar:pubnet) inmethodDetails.networkand credentialsourcefield; addCAIP2_NETWORK/CAIP2_TO_NETWORKconstants exported from root indexreferenceandmemofields frommethodDetailsschemasource(DID-PKH) from insidepayloadto the top-level credential fieldSettlementError(exported) to distinguish broadcast/confirmation failures from verification errorsinvokeHostFunctionoperationchallenge.expirestimeBounds.maxTimemust not exceedchallenge.expireson unsponsored pathchallenge.expiresinstead of a fixed timeoutDEFAULT_LEDGER_CLOSE_TIMEandDEFAULT_CHALLENGE_EXPIRYconstantsWhy
The charge module had several gaps relative to
draft-stellar-charge-00. This PR closes them to improve interoperability and security: CAIP-2 is the spec's standard chain reference format; the DID-PKHsourcemust be a top-level credential field (themppxCredentialtype already modeled this correctly but the client was placing it insidepayload); the server must validate transaction structure and auth entries before broadcasting to prevent abuse.API changes (before → after)
methodDetails.network— CAIP-2 formatCredential
sourcefield — moved to top levelNew error class
New constants