Skip to content

Add Delegate Auth example for CAP-71 delegation#2519

Open
leighmcculloch wants to merge 9 commits into
mainfrom
claude/awesome-gates-ildx8c
Open

Add Delegate Auth example for CAP-71 delegation#2519
leighmcculloch wants to merge 9 commits into
mainfrom
claude/awesome-gates-ildx8c

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Jun 17, 2026

Copy link
Copy Markdown
Member

What

Add a Delegate Auth example page documenting the CAP-71 auth delegation APIs introduced in soroban-sdk v27, mirroring the runnable modular_account crate in stellar/soroban-examples#407. The ModularAccount contract verifies no signature of its own and forwards its __check_auth context to registered delegate signers via get_delegated_signers and delegate_auth; the page walks through the storage layout, constructor, the get/verify/forward delegation flow, and the set_auths + SorobanAddressCredentialsWithDelegates testing pattern. The new page is linked from the Complex Account example and registered in routes.txt.

Why

soroban-sdk v27 ships auth delegation, and the modular account pattern is distinct enough from the multisig and spend-limit accounts in complex-account.mdx to warrant its own example page rather than a subsection. It pairs with the companion stellar/soroban-examples#407, which provides the runnable crate the page points to.

Copilot AI review requested due to automatic review settings June 17, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Soroban “complex account” documentation by adding a new section describing CAP-71 auth delegation APIs introduced in soroban-sdk v27+, including guidance on a modular-account delegation flow and a representative __check_auth example.

Changes:

  • Adds a new “Auth Delegation (v27+)” section between Authorization policy and Tests.
  • Documents env.custom_account().get_delegated_signers() and env.custom_account().delegate_auth(...) and their constraints.
  • Includes a Rust example illustrating a delegation loop inside __check_auth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


- **`get_delegated_signers() -> Vec<Address>`** — Returns the list of delegate addresses that the user attached to the auth entry when building the transaction. These are user-supplied and are not sanitized by the host; the contract must verify that each address is actually a registered delegate before acting on it.

- **`delegate_auth(&address)`** — Forwards the current `__check_auth` authorization context to the given address. The delegate runs its own auth check for the same context. Unlike `require_auth`, this does not count as a new contract invocation and does not require a separate auth entry in the transaction. Delegation can be nested recursively.
Comment on lines +385 to +409
fn __check_auth(
env: Env,
signature_payload: Hash<32>,
signature: BytesN<64>,
auth_contexts: Vec<Context>,
) -> Result<(), ModularAccountError> {
// Perform the account's own verification if needed.
let public_key: BytesN<32> = env.storage().instance().get(&DataKey::PublicKey).unwrap();
env.crypto()
.ed25519_verify(&public_key, &signature_payload.into(), &signature);

// Retrieve the delegate addresses the user attached to the auth entry.
let delegates = env.custom_account().get_delegated_signers();
let signers: Vec<Address> = env.storage().instance().get(&DataKey::Signers).unwrap();

for delegate in delegates.iter() {
// Reject any delegate that is not registered with this account.
if !signers.contains(&delegate) {
return Err(ModularAccountError::UnknownDelegate);
}
// Forward the current authorization context to the verified delegate.
env.custom_account().delegate_auth(&delegate);
}
Ok(())
}
Comment on lines +370 to +372
Auth delegation, introduced in soroban-sdk v27 via CAP-71, allows a custom account contract to forward its `__check_auth` verification context to other registered addresses. This enables "modular" account contracts that do not perform all authentication themselves but instead delegate to one or more external signers (either G- or C-type addresses) that carry out the actual auth logic.

Two new methods are available on `env.custom_account()`, and both may only be called from within `__check_auth`. Calling them outside of `__check_auth` will panic.
@stellar-jenkins-ci

Copy link
Copy Markdown

@leighmcculloch leighmcculloch marked this pull request as draft June 17, 2026 15:18
…ation

- Add docs/build/smart-contracts/example-contracts/modular-account.mdx as a
  standalone example covering auth delegation (soroban-sdk v27+).
- Remove the auth delegation section that was added to complex-account.mdx and
  replace it with a link to the new Modular Account page.
- Source contract code is taken from the SDK test in
  soroban-sdk/src/tests/delegate_auth.rs.

Claude-Session: https://claude.ai/code/session_01GgpDVzaPCuCzUVUUyvdAke
@leighmcculloch leighmcculloch changed the title docs: add CAP-71 auth delegation docs for soroban-sdk v27 docs(soroban): add Modular Account example for CAP-71 auth delegation (soroban-sdk v27) Jun 17, 2026
@stellar-jenkins-ci

Copy link
Copy Markdown

…ample

- Add the modular-account route to routes.txt (build job).
- Remove the extra blank line in complex-account.mdx (mdx-format job).
- Point the page at the new runnable modular_account example in
  soroban-examples, adding a "Run the Example" section and source-file
  titles on the code blocks.
- Correct the DelegateAccount error type to soroban_sdk::Error and note
  it is defined as a test fixture (a single Wasm exports one __check_auth).
- Explain the record_authorized_calls test-observability helper.

Claude-Session: https://claude.ai/code/session_01EgjfKqQ1RMvtwQUSx3iDzh
@stellar-jenkins-ci

Copy link
Copy Markdown

@leighmcculloch leighmcculloch force-pushed the claude/awesome-gates-ildx8c branch from e9be6e4 to 2c839a0 Compare June 17, 2026 21:48
@stellar-jenkins-ci

Copy link
Copy Markdown

@leighmcculloch leighmcculloch linked an issue Jun 18, 2026 that may be closed by this pull request
…mples PR #407

- Rename modular-account.mdx → delegate-auth.mdx (title: "Delegate Auth")
- Rewrite code section to use the canonical lib.rs from soroban-examples PR #407:
  #![no_std], mod test; split, inline comments matching the example repo
- Add Run the Example section pointing to soroban-examples/modular_account
- Add Build the Contract section with expected wasm output path
- Update complex-account.mdx Further Reading link to new filename

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GgpDVzaPCuCzUVUUyvdAke
@leighmcculloch leighmcculloch changed the title docs(soroban): add Modular Account example for CAP-71 auth delegation (soroban-sdk v27) docs(soroban): add Delegate Auth example for CAP-71 auth delegation (soroban-sdk v27) Jun 18, 2026
@stellar-jenkins-ci

Copy link
Copy Markdown

@stellar-jenkins-ci

Copy link
Copy Markdown

@stellar-jenkins-ci

Copy link
Copy Markdown

@stellar-jenkins-ci

Copy link
Copy Markdown

@leighmcculloch leighmcculloch changed the title docs(soroban): add Delegate Auth example for CAP-71 auth delegation (soroban-sdk v27) Add Delegate Auth example for CAP-71 auth delegation (soroban-sdk v27) Jun 18, 2026
@leighmcculloch leighmcculloch marked this pull request as ready for review June 18, 2026 04:41
@stellar-jenkins-ci

Copy link
Copy Markdown

@leighmcculloch leighmcculloch changed the title Add Delegate Auth example for CAP-71 auth delegation (soroban-sdk v27) Add Delegate Auth example for CAP-71 delegation Jun 18, 2026


Update delegate-auth.mdx to match the canonical example in
stellar/soroban-examples#407 rather than the SDK unit test:

- type Signature = () — account carries no own signature, relies
  entirely on delegates
- Per-signer persistent storage (Signer(Address) key) instead of a
  stored Vec<Address>
- Constructor takes only signers, no public key
- Two-pass __check_auth: validate all delegates first, then forward
- Test section updated to match the simpler DelegateAccount fixture
  (Signature = (), always approves, stores ApprovedContexts)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GgpDVzaPCuCzUVUUyvdAke
@stellar-jenkins-ci

Copy link
Copy Markdown

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.

Auth delegation example

2 participants