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.

Configuration

  • Default indexer URLs by Stellar network passphrase. Consulted by OZSmartAccountConfig.effectiveIndexerUrl() when no indexerUrl is supplied.

    Declaration

    Swift

    public static let defaultIndexerUrls: [String : String]
  • Returns the default indexer URL for the supplied network passphrase, or nil when no default is configured for that network.

    Declaration

    Swift

    public static func getDefaultUrl(networkPassphrase: String) -> String?

    Parameters

    networkPassphrase

    The Stellar network passphrase to look up.

    Return Value

    The default indexer URL string, or nil.

  • Creates an OZIndexerClient configured 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

    networkPassphrase

    The Stellar network passphrase. Use Network.testnet.passphrase or Network.public.passphrase for the built-in networks.

    timeoutMs

    Request timeout in milliseconds.

    urlSession

    Optional injected URLSession. When nil, the client owns a freshly created session and invalidates it on close().

    Return Value

    A configured OZIndexerClient, or nil if no default URL is configured for the network.

Initialization

  • Creates a new OZIndexerClient.

    Throws

    SmartAccountConfigurationException.InvalidConfig when 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
    ) throws

    Parameters

    indexerUrl

    The indexer endpoint URL. Must start with https:// or http://localhost (with optional port and path).

    timeoutMs

    Request timeout in milliseconds. Defaults to OZConstants.defaultIndexerTimeoutMs (10 seconds).

    urlSession

    Optional 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. When nil, 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 on close(). When an injected session is supplied, the redirect-handling policy of that session is the caller’s responsibility.

Public methods