OZPolicyManager

Manager for policy operations on OpenZeppelin Smart Accounts.

Provides functionality to add and remove policies on context rules. Policies define authorization rules that must be satisfied for transactions to execute.

A context rule can have multiple policies (up to OZConstants.MAX_POLICIES), and all policies must be satisfied for a transaction to succeed.

All state-changing methods accept an optional selectedSigners parameter for multi-signer authorization. When empty (default), the operation uses single-signer auth with the connected passkey. When non-empty, signatures are collected from all listed signers via OZMultiSignerManager.submitWithMultipleSigners.

Policy lifecycle:

  1. Deploy policy contract to network

  2. Add policy to context rule with installation parameters

  3. Policy is initialized on the smart account contract

  4. Policy is evaluated during transaction authorization

  5. Remove policy when no longer needed

This manager is typically accessed via OZSmartAccountKit rather than instantiated directly.

Three convenience methods are provided for built-in policy types: addSimpleThreshold, addWeightedThreshold, and addSpendingLimit. For custom policy contracts, use addPolicy directly with policy-specific installation parameters encoded as SCValXdr.

Example usage:

val kit = OZSmartAccountKit.create(config)
val policyManager = kit.policyManager

// Add a simple threshold policy (2-of-3, single-signer)
val result = policyManager.addSimpleThreshold(
contextRuleId = 0u,
policyAddress = "CBCD1234...",
threshold = 2u
)

// Add a custom policy with multi-signer authorization
val customResult = policyManager.addPolicy(
contextRuleId = 0u,
policyAddress = "CBCD5678...",
installParams = myCustomPolicyParams,
selectedSigners = listOf(
SelectedSigner.Passkey(credentialId = cred1, credentialIdBytes = cred1Bytes, keyData = key1),
SelectedSigner.Wallet("GA7Q...")
)
)

if (result.success) {
println("Policy added successfully")
}

// Remove a policy by its ID (ID available from ParsedContextRule.policyIds)
val removeResult = policyManager.removePolicy(
contextRuleId = 0u,
policyId = 1u
)

Thread Safety: This class is thread-safe. All operations are async and can be called from any coroutine context.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun addPolicy(contextRuleId: UInt, policyAddress: String, installParams: SCValXdr, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Adds a policy to a context rule with custom installation parameters.

Link copied to clipboard
suspend fun addSimpleThreshold(contextRuleId: UInt, policyAddress: String, threshold: UInt, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Adds a simple threshold policy to a context rule.

Link copied to clipboard
suspend fun addSpendingLimit(contextRuleId: UInt, policyAddress: String, spendingLimit: String, periodLedgers: UInt, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Adds a spending limit policy to a context rule.

Link copied to clipboard
suspend fun addWeightedThreshold(contextRuleId: UInt, policyAddress: String, signerWeights: Map<SmartAccountSigner, UInt>, threshold: UInt, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Adds a weighted threshold policy to a context rule.

Link copied to clipboard
suspend fun removePolicy(contextRuleId: UInt, policyAddress: String, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Removes a policy from a context rule by matching the policy contract address.

suspend fun removePolicy(contextRuleId: UInt, policyId: UInt, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Removes a policy from a context rule by its ID.