OZIndexerClient
public class OZIndexerClient : @unchecked Sendable
Client for interacting with the OpenZeppelin Smart Account indexer service.
The indexer maps WebAuthn credential IDs and signer addresses to deployed smart account contract addresses, enabling discovery-style flows for users with existing wallets and detailed introspection of any deployed contract.
Example:
let client = try OZIndexerClient(indexerUrl: "https://indexer.example.com")
let credentialResponse = try await client.lookupByCredentialId(credentialId: "abc123...")
print("Found \(credentialResponse.count) contracts")
let addressResponse = try await client.lookupByAddress(address: "GABC123...")
print("Signer is registered in \(addressResponse.count) contracts")
let contractDetails = try await client.getContract(contractId: "CABC123...")
print("Contract has \(contractDetails.contextRules.count) context rules")
client.close()
The client validates its indexerUrl argument at construction. HTTPS is required,
with http://localhost allowed for development. After use, call close() to
invalidate the owned URLSession. When a custom urlSession is supplied (for
testing) the caller retains ownership.
Subclassing contract: subclassable inside the SDK (and from @testable
consumers); not designed for outside-module subclassing — inject a custom
URLSession instead.
-
Default indexer URLs by Stellar network passphrase. Consulted by
OZSmartAccountConfig.effectiveIndexerUrl()when noindexerUrlis supplied.Declaration
Swift
public static let defaultIndexerUrls: [String : String] -
Returns the default indexer URL for the supplied network passphrase, or
nilwhen no default is configured for that network.Declaration
Swift
public static func getDefaultUrl(networkPassphrase: String) -> String?Parameters
networkPassphraseThe Stellar network passphrase to look up.
Return Value
The default indexer URL string, or
nil. -
Creates an
OZIndexerClientconfigured for a specific Stellar network using the SDK’s default indexer endpoint for that network.Declaration
Swift
public static func forNetwork( networkPassphrase: String, timeoutMs: Int64 = OZConstants.defaultIndexerTimeoutMs, urlSession: URLSession? = nil ) -> OZIndexerClient?Parameters
networkPassphraseThe Stellar network passphrase. Use
Network.testnet.passphraseorNetwork.public.passphrasefor the built-in networks.timeoutMsRequest timeout in milliseconds.
urlSessionOptional injected
URLSession. Whennil, the client owns a freshly created session and invalidates it onclose().Return Value
A configured
OZIndexerClient, ornilif no default URL is configured for the network.
-
Creates a new
OZIndexerClient.Throws
SmartAccountConfigurationException.InvalidConfigwhen the URL is blank or does not satisfy the HTTPS / localhost constraint.Declaration
Swift
public init( indexerUrl: String, timeoutMs: Int64 = OZConstants.defaultIndexerTimeoutMs, urlSession: URLSession? = nil ) throwsParameters
indexerUrlThe indexer endpoint URL. Must start with
https://orhttp://localhost(with optional port and path).timeoutMsRequest timeout in milliseconds. Defaults to
OZConstants.defaultIndexerTimeoutMs(10 seconds).urlSessionOptional pre-configured
URLSession. Use this to inject a test mock OR to apply production transport configuration such as certificate pinning, proxy settings, or request inspection. Whennil, the client builds an ephemeral session whose redirect handler denies all 3xx redirects to protect signed payloads and pinned identification headers; the owned session is invalidated onclose(). When an injected session is supplied, the redirect-handling policy of that session is the caller’s responsibility.
-
lookupByCredentialId(credentialId:Asynchronous) Looks up smart account contracts by WebAuthn credential ID.
Throws
SmartAccountValidationException.InvalidInputwhen the credential ID is not valid base64url.SmartAccountIndexerException.RequestFailedon network failure, non-2xx response, or decoding failure.SmartAccountIndexerException.Timeoutwhen the request exceeds the configured timeout.Declaration
Swift
public func lookupByCredentialId(credentialId: String) async throws -> OZCredentialLookupResponseParameters
credentialIdThe credential ID to look up, base64url-encoded with no padding. The client converts it to hex before contacting the indexer.
Return Value
The decoded
OZCredentialLookupResponse. -
lookupByAddress(address:Asynchronous) Looks up smart account contracts by signer address.
Throws
SmartAccountValidationException.InvalidAddresswhen the address is malformed.SmartAccountIndexerException.RequestFailedon network failure, non-2xx response, or decoding failure.SmartAccountIndexerException.Timeouton per-request timeout.Declaration
Swift
public func lookupByAddress(address: String) async throws -> OZAddressLookupResponseParameters
addressA
G…account orC…contract address.Return Value
The decoded
OZAddressLookupResponse. -
getContract(contractId:Asynchronous) Gets detailed information about a smart account contract.
Throws
SmartAccountValidationException.InvalidAddresswhen the contract ID is malformed.SmartAccountIndexerException.RequestFailedon network failure, non-2xx response, or decoding failure.SmartAccountIndexerException.Timeouton per-request timeout.Declaration
Swift
public func getContract(contractId: String) async throws -> OZContractDetailsResponseParameters
contractIdThe contract ID (
C…strkey).Return Value
The decoded
OZContractDetailsResponse. -
getStats()AsynchronousGets aggregate statistics from the indexer.
Throws
SmartAccountIndexerException.RequestFailedon network failure, non-2xx response, or decoding failure.SmartAccountIndexerException.Timeouton per-request timeout.Declaration
Swift
public func getStats() async throws -> OZIndexerStatsResponseReturn Value
The decoded
OZIndexerStatsResponse. -
isHealthy()AsynchronousChecks if the indexer service is reachable and healthy.
Performs a lightweight
GET /and returnstrueonly when the server responds with HTTP 2xx AND a parsedHealthCheckResponsewhosestatusequals"ok". Any other outcome — non-2xx status, decode failure, network error, or timeout — returnsfalse. This method does NOT throw.Declaration
Swift
public func isHealthy() async -> BoolReturn Value
trueif the indexer is healthy and reachable;falseotherwise. -
Releases the owned
URLSessionand marks the client as closed.When the client was constructed with a caller-supplied
urlSession, the caller retains ownership and the session is NOT invalidated. Afterclose()completes the client must not be used again; subsequent calls toclose()are safe no-ops.Subclasses overriding this method MUST call
super.close()(orperformCloseInternal()directly) to invalidate the ownedURLSession; otherwise the underlying transport leaks.Declaration
Swift
public func close() -
Performs the canonical close sequence: idempotent state flip plus
URLSessioninvalidation when the session is owned.Subclasses that override
close()should call this helper from their override so the resource teardown remains correct even if the override is reordered or augmented with additional bookkeeping.Declaration
Swift
public final func performCloseInternal()
View on GitHub
Install in Dash