OZPolicy Manager
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:
Deploy policy contract to network
Add policy to context rule with installation parameters
Policy is initialized on the smart account contract
Policy is evaluated during transaction authorization
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.
Functions
Adds a policy to a context rule with custom installation parameters.
Adds a simple threshold policy to a context rule.
Adds a spending limit policy to a context rule.
Adds a weighted threshold policy to a context rule.
Removes a policy from a context rule by matching the policy contract address.
Removes a policy from a context rule by its ID.