Skip to content

Build Soroban contract auth entry builder with simulation pre-check #458

Description

@Kingsman-99

Description

Building SorobanAuthorizationEntry objects for complex multi-party Soroban invocations requires correctly assembling nested auth trees and pre-populating signatures, which is error-prone and under-documented. This issue adds a ContractAuthBuilder that constructs valid auth entries from a high-level AuthSpec descriptor, runs a simulation to validate the entry before submission, and returns the fully signed SorobanAuthorizedInvocation ready for the transaction envelope.

Technical Context

  • New file: src/auth/ContractAuthBuilder.ts; types: AuthSpec, AuthEntry, AuthBuildResult in src/types/auth.ts
  • AuthSpec: { contractId: string; functionName: string; args: xdr.ScVal[]; signers: SignerSpec[] } where SignerSpec is { keypair?: Keypair; publicKey: string; weight: number }
  • The builder uses SorobanRpc.Server.simulateTransaction() to obtain the sorobanData and the pre-authorized entries, then merges them with the provided signers
  • If simulation returns error, the builder throws AuthSimulationError with the diagnostic events from the simulation response
  • ContractAuthBuilder.build(spec, networkPassphrase): Promise<AuthBuildResult> is the primary API; AuthBuildResult includes the entry XDR and simulation cost

Acceptance Criteria

  • build() produces a valid SorobanAuthorizationEntry that can be included in a transaction envelope and accepted by the Soroban sandbox without auth errors
  • When simulation returns an error, AuthSimulationError is thrown with the full diagnostic event list attached
  • Multi-signer specs where the total weight meets the threshold produce an entry with all signer signatures included
  • The builder correctly handles nested invocations (contract A calling contract B) by recursively building auth entries for each callee
  • Integration tests run against a local Soroban sandbox with a deployed test contract
  • All CI checks (npm test, npm run build, ESLint) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions