SmartAccountAuth

Authentication utilities for Smart Account authorization entries.

Provides functions to sign authorization entries and build authentication payload hashes for Smart Account transactions. These utilities handle the complex XDR encoding and signature map construction required by the Soroban authorization protocol.

Key responsibilities:

  • Building Soroban authorization payload hashes for WebAuthn challenges

  • Signing authorization entries with Smart Account signers

  • Managing signature expiration and map entry ordering

  • Double XDR encoding of signature values

Example usage:

// Build payload hash for WebAuthn signing
val payloadHash = SmartAccountAuth.buildAuthPayloadHash(
entry = authEntry,
expirationLedger = currentLedger + 100u,
networkPassphrase = Network.TESTNET.networkPassphrase
)

// Compute the signature over the payload hash, then attach it to the entry
val signedEntry = SmartAccountAuth.signAuthEntry(
entry = authEntry,
signer = webAuthnSigner,
signature = webAuthnSignature,
expirationLedger = currentLedger + 100u
)

Functions

Link copied to clipboard
fun addRawSignatureMapEntry(entry: SorobanAuthorizationEntryXdr, signerKey: SCValXdr, signatureValue: SCValXdr, contextRuleIds: List<UInt> = emptyList()): SorobanAuthorizationEntryXdr

Adds a raw key/value entry to the auth entry's signature map.

Link copied to clipboard
suspend fun buildAuthDigest(signaturePayload: ByteArray, contextRuleIds: List<UInt>): ByteArray

Computes the auth digest that binds context rule IDs to the signature payload.

Link copied to clipboard
suspend fun buildAuthPayloadHash(entry: SorobanAuthorizationEntryXdr, expirationLedger: UInt, networkPassphrase: String): ByteArray

Builds the authorization payload hash for signing.

Link copied to clipboard
suspend fun buildSourceAccountAuthPayloadHash(entry: SorobanAuthorizationEntryXdr, nonce: Int64Xdr, expirationLedger: UInt, networkPassphrase: String): ByteArray

Builds the authorization payload hash for source_account credentials.

Link copied to clipboard
suspend fun signAuthEntry(entry: SorobanAuthorizationEntryXdr, signer: SmartAccountSigner, signature: SmartAccountSignature, expirationLedger: UInt, contextRuleIds: List<UInt> = emptyList()): SorobanAuthorizationEntryXdr

Attaches a pre-computed signature to an authorization entry.