Skip to content

Add Protocol 27 (CAP-71) Soroban authorization support#94

Merged
christian-rogobete merged 6 commits into
mainfrom
p27-prep
Jun 18, 2026
Merged

Add Protocol 27 (CAP-71) Soroban authorization support#94
christian-rogobete merged 6 commits into
mainfrom
p27-prep

Conversation

@christian-rogobete

@christian-rogobete christian-rogobete commented Jun 14, 2026

Copy link
Copy Markdown
Member

Adds the hand-written Protocol 27 (CAP-71) layer on top of the generated XDR: the new Soroban authorization credential types and delegated account authorization. All additions are additive and opt-in; the legacy SOROBAN_CREDENTIALS_ADDRESS credential remains the default and fully valid.

Credentials and XDR

  • SorobanCredentials models all four arms (source-account, legacy ADDRESS, ADDRESS_V2, ADDRESS_WITH_DELEGATES); fromXdr/toXdr round-trip every arm and fail fast on unknown arms.
  • New SorobanAddressCredentialsWithDelegates, SorobanDelegateSignature, and SorobanDelegateDescriptor, plus forAddressCredentialsV2 and forAddressWithDelegates factories.
  • The address-bound preimage binds the signature payload to the top-level credential address.

Authorization

  • SorobanAuthorizationEntry::buildPreimage and sign() with an optional forAddress that routes a signature into matching top-level or delegate nodes; the credential arm is preserved on write-back.
  • withDelegates tree builder with XDR-byte sorting and within-array duplicate rejection.
  • AssembledTransaction and SEP-45 web auth handle all credential arms; a delegates-only entry passes the send precheck with a void top-level signature.

Hardening

  • Recursive XDR decode is bounded (depth 128) to prevent stack exhaustion from a hostile, deeply nested delegate tree, with fail-closed caps on the tree-walk helpers.

Tooling

  • The agent-skill API-reference generator is added under tools/skill-generator, and the API reference is regenerated.

Defaults and protocol gating

  • The legacy ADDRESS credential remains the default; the new arms are opt-in and only valid on Protocol 27+.

Source compatibility

  • The SorobanCredentials constructor's first parameter was renamed from $addressCredentials to $credentialType (now int|SorobanAddressCredentials). Positional callers are unaffected. Callers that used the named argument addressCredentials: should switch to credentialType: or to the forAddressCredentials() factory: the old named call still compiles but now binds to a different parameter and yields source-account credentials.

Closes #93.

The generated XDR layer was already at the Protocol 27 commit (55a00d9); this
adds the hand-written layer (#93):

- Soroban credential wrappers now model all four arms (source-account, legacy
  ADDRESS, ADDRESS_V2, ADDRESS_WITH_DELEGATES); SorobanCredentials fromXdr/toXdr
  round-trip every arm (fixing the prior silent data loss) with fail-fast on
  unknown arms; new SorobanAddressCredentialsWithDelegates / SorobanDelegateSignature
  / SorobanDelegateDescriptor classes and forAddressCredentialsV2 /
  forAddressWithDelegates factories
- Arm-aware signing through one preimage builder: SorobanAuthorizationEntry
  buildPreimage, sign() with an optional forAddress that routes into matching
  top-level or delegate nodes, and the withDelegates tree builder (XDR-byte
  sort, duplicate rejection)
- Opt-in authV2 flag on SimulateTransactionRequest and MethodOptions (key
  omitted when false; old RPCs silently ignore it and return legacy entries)
- AssembledTransaction and SEP-45 web auth handle all credential arms;
  delegates-only entries pass the send precheck
- Bounded recursive XDR decode (depth 128) to prevent stack exhaustion from
  hostile delegate trees, with fail-closed caps on the tree-walk helpers
- Tests incl. byte-exact golden vectors and a testnet integration test that
  activates on Protocol 27; documentation and agent-skill updates
- Port the skill API-reference generator into tools/skill-generator and
  regenerate skills/stellar-php-sdk/references/api_reference.md

Legacy ADDRESS remains the default and fully valid; the new arms are opt-in
and only valid on Protocol 27+.
signAuthEntries (AssembledTransaction) and signAuthorizationEntries
(WebAuthForContracts) stamped signatureExpirationLedger only on the direct
signing paths, not before invoking the signing callback, so a callback-signed
entry kept the wrong expiration and was rejected on submission. Stamp the
expiration before the callback, as the direct paths already do.

Also strengthen the Protocol 27 unit tests: assert the stamped expiration on
the callback paths, verify produced signatures against the rebuilt preimage,
and tighten weak assertions.
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.64244% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.74%. Comparing base (184f252) to head (376e420).

Files with missing lines Patch % Lines
...ellarSDK/Soroban/Contract/AssembledTransaction.php 93.84% 8 Missing ⚠️
...o/StellarSDK/Soroban/SorobanAuthorizationEntry.php 97.82% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main      #94      +/-   ##
============================================
+ Coverage     92.63%   92.74%   +0.10%     
- Complexity    20806    20960     +154     
============================================
  Files           987      990       +3     
  Lines         49713    50119     +406     
============================================
+ Hits          46050    46481     +431     
+ Misses         3663     3638      -25     
Files with missing lines Coverage Δ
...DK/SEP/WebAuthForContracts/WebAuthForContracts.php 78.61% <100.00%> (-0.40%) ⬇️
...Soroban/SorobanAddressCredentialsWithDelegates.php 100.00% <100.00%> (ø)
Soneso/StellarSDK/Soroban/SorobanCredentials.php 100.00% <100.00%> (ø)
...o/StellarSDK/Soroban/SorobanDelegateDescriptor.php 100.00% <100.00%> (ø)
...so/StellarSDK/Soroban/SorobanDelegateSignature.php 100.00% <100.00%> (ø)
Soneso/StellarSDK/Xdr/XdrBuffer.php 98.83% <100.00%> (+0.15%) ⬆️
Soneso/StellarSDK/Xdr/XdrSorobanCredentials.php 100.00% <100.00%> (ø)
...eso/StellarSDK/Xdr/XdrSorobanDelegateSignature.php 94.18% <100.00%> (+0.13%) ⬆️
...o/StellarSDK/Soroban/SorobanAuthorizationEntry.php 98.01% <97.82%> (+0.40%) ⬆️
...ellarSDK/Soroban/Contract/AssembledTransaction.php 79.34% <93.84%> (+23.34%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@christian-rogobete christian-rogobete merged commit 1909e25 into main Jun 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK Updates for Protocol 27 Compatibility

1 participant