OZWalletOperations
public final class OZWalletOperations : OZManagerHelpers, @unchecked Sendable
Wallet-lifecycle operations for OpenZeppelin Smart Accounts.
Handles wallet creation (WebAuthn registration + deterministic contract derivation + deploy-transaction build and submission), wallet connection (session restore, storage → derivation → indexer cascade, ambiguous-multi- contract handling), standalone passkey authentication, and retry of a previously deferred or failed deployment.
Instances are constructed by OZSmartAccountKit and accessed through
kit.walletOperations.
-
Creates a new smart-account wallet backed by a fresh WebAuthn credential.
Registers a passkey, derives the deterministic contract address, builds and signs the deploy transaction, and optionally submits it. The signed deploy XDR is always present in the result for deferred submission.
Declaration
Swift
public func createWallet( userName: String = "Smart Account User", autoSubmit: Bool = false, autoFund: Bool = false, nativeTokenContract: String? = nil, forceMethod: OZSubmissionMethod? = nil, policies: [String: SCValXDR]? = nil ) async throws -> OZCreateWalletResultParameters
userNameDisplay name persisted with the credential.
autoSubmitWhen
true, submits the deploy transaction immediately (defaultfalse). ThesignedTransactionXdrfield of the result carries the signed envelope for later external submission regardless.autoFundFund the freshly deployed wallet via Friendbot (testnet only). Requires
autoSubmit = trueandnativeTokenContract != nil.nativeTokenContractNative token (XLM SAC) contract address used when
autoFund = true.forceMethodOptional submission-method override.
policiesPolicies to install on the new wallet’s default context rule at deploy time, keyed by policy contract address with the install-param ScVal as the value.
nil(default) usesdefaultPolicies; a non-nilmap overrides it. Validated before the passkey ceremony. MaximummaxPolicies.Return Value
OZCreateWalletResultdescribing the new wallet. -
connectWallet(options:Asynchronous) Connects to an existing smart-account wallet.
Returns
OZConnectWalletResulton success, ornilwhen no valid session exists andoptions.prompt == false. The non-nilresult is either anconnected(credentialId:contractId:restoredFromSession:)arm (single contract resolved, kit state set, session saved) or aambiguous(credentialId:candidates:)arm (indexer reported multiple contracts — kit state NOT set, caller must let the user pick).Throws
WebAuthnException(prompt path),SmartAccountWalletException(no contract resolved),SmartAccountValidationException(options validation),SmartAccountTransactionException(RPC failure),SmartAccountIndexerException(indexer transport failure).Declaration
Swift
public func connectWallet( options: OZConnectWalletOptions = OZConnectWalletOptions() ) async throws -> OZConnectWalletResult?Parameters
optionsConnect-wallet options. Defaults to a silent session-only restore.
Return Value
OZConnectWalletResultornil. -
connectToContract(contractId:Asynchronous) Connects the kit to an already-deployed smart account by contract address, with no passkey credential.
Intended for headless callers — an autonomous signer (the reference agent) or a backend service — that operate the account through the multi-signer / external-signer pipeline (non-empty
selectedSigners) and never present a passkey. UnlikeconnectWallet(options:), this does not run a WebAuthn ceremony, does not consult the credential manager, and does not persist a session; it also clears any previously saved session so a later silent reconnect cannot resurrect a stale passkey session.After a headless connect the single-passkey paths (
submit(hostFunction:auth:forceMethod:resolveContextRuleIds:),transfer(tokenContract:recipient:amount:decimals:forceMethod:),contractCall(target:targetFn:targetArgs:forceMethod:resolveContextRuleIds:),executeAndSubmit(target:targetFn:targetArgs:forceMethod:resolveContextRuleIds:), and any manager call left at the default emptyselectedSigners) are NOT usable: they require a passkey credential and throw a clear error from the headless guard. Operate throughkit.multiSignerManageror the sibling managers with an explicit non-emptyselectedSignerslist.The contract address is validated and its on-chain existence is verified before the connected state is set.
Throws
InvalidAddresswhencontractIdis not a valid contract address;NotFoundwhen no contract instance exists at the address;SmartAccountTransactionExceptionwhen the RPC existence check fails for transport reasons.Declaration
Swift
public func connectToContract(contractId: String) async throws -> OZConnectToContractResultParameters
contractIdSmart account contract address (
C…strkey).Return Value
OZConnectToContractResultcarrying the verifiedcontractId. -
authenticatePasskey(challenge:AsynchronouscredentialIds: ) Authenticates with a passkey without connecting to a wallet.
Used to authenticate the user before contract selection (for example to discover deployed contracts via the indexer) or for multi-signer operations that do not require a fully-connected kit state.
Throws
WebAuthnException(authentication failure / no provider),SmartAccountValidationException(signature normalisation failure).Declaration
Swift
public func authenticatePasskey( challenge: Data? = nil, credentialIds: [String]? = nil ) async throws -> OZAuthenticatePasskeyResultParameters
challengeOptional challenge bytes to sign. When
nil, a fresh 32-byte random challenge is generated.credentialIdsOptional list of allowed credential ids (Base64URL-encoded). When provided, only those credentials may be used by the authenticator.
Return Value
OZAuthenticatePasskeyResultcarrying the credential id, normalised signature, and stored public key (when available). -
deployPendingCredential(credentialId:AsynchronousautoSubmit: autoFund: nativeTokenContract: forceMethod: policies: ) Deploys a wallet from a previously created pending credential.
Used to retry a failed deployment or to submit a wallet created with
createWallet(autoSubmit: false). The credential must exist in storage with a validpublicKeyandcontractId.Declaration
Swift
public func deployPendingCredential( credentialId: String, autoSubmit: Bool = true, autoFund: Bool = false, nativeTokenContract: String? = nil, forceMethod: OZSubmissionMethod? = nil, policies: [String: SCValXDR]? = nil ) async throws -> OZDeployPendingResultParameters
credentialIdBase64URL-encoded credential identifier of the credential to deploy.
autoSubmitWhether to submit the deploy transaction. Defaults to
true(this entry point is typically used to retry a failed deploy so callers usually want submission).autoFundWhether to fund the freshly deployed wallet using Friendbot (testnet only). Requires
autoSubmit = true.nativeTokenContractNative token contract address used when
autoFund = true.forceMethodOptional submission-method override.
policiesPolicies to install on the default context rule at deploy time, keyed by policy contract address with the install-param ScVal as the value.
nil(default) usesdefaultPolicies; a non-nilmap overrides it. MaximummaxPolicies.Return Value
OZDeployPendingResultdescribing the deployment.
View on GitHub
Install in Dash