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
Description
Building
SorobanAuthorizationEntryobjects 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 aContractAuthBuilderthat constructs valid auth entries from a high-levelAuthSpecdescriptor, runs a simulation to validate the entry before submission, and returns the fully signedSorobanAuthorizedInvocationready for the transaction envelope.Technical Context
src/auth/ContractAuthBuilder.ts; types:AuthSpec,AuthEntry,AuthBuildResultinsrc/types/auth.tsAuthSpec:{ contractId: string; functionName: string; args: xdr.ScVal[]; signers: SignerSpec[] }whereSignerSpecis{ keypair?: Keypair; publicKey: string; weight: number }SorobanRpc.Server.simulateTransaction()to obtain thesorobanDataand the pre-authorized entries, then merges them with the providedsignerserror, the builder throwsAuthSimulationErrorwith the diagnostic events from the simulation responseContractAuthBuilder.build(spec, networkPassphrase): Promise<AuthBuildResult>is the primary API;AuthBuildResultincludes the entry XDR and simulation costAcceptance Criteria
build()produces a validSorobanAuthorizationEntrythat can be included in a transaction envelope and accepted by the Soroban sandbox without auth errorsAuthSimulationErroris thrown with the full diagnostic event list attached