OZContextRuleManager

Manages context rules for OpenZeppelin Smart Accounts.

Context rules define authorization requirements for different types of operations. Each rule specifies:

  • Context type: What operations does this rule apply to (default, call contract, create contract)

  • Name: A human-readable identifier for the rule

  • Signers: Who can authorize operations matching this context

  • Policies: What constraints apply (spending limits, time locks, multi-sig thresholds, etc.)

  • Valid until: Optional expiration ledger number

The smart account evaluates transactions against context rules to determine:

  1. Which signers are required to authorize the transaction

  2. Which policies must be satisfied for the transaction to execute

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.

Contract limits:

  • Maximum 15 signers per context rule

  • Maximum 5 policies per context rule

Example usage:

val contextMgr = kit.contextRuleManager

// Add a rule for token transfers requiring 2-of-3 multi-sig
val result = contextMgr.addContextRule(
contextType = ContextRuleType.CallContract(tokenContractAddress),
name = "TokenTransfers",
validUntil = null,
signers = listOf(signer1, signer2, signer3),
policies = mapOf(
thresholdPolicyAddress to thresholdScVal
)
)

// Get total count of context rules
val count = contextMgr.getContextRulesCount()

// Remove a context rule
val removeResult = contextMgr.removeContextRule(id = ruleId)

Functions

Link copied to clipboard
suspend fun addContextRule(contextType: ContextRuleType, name: String, validUntil: UInt? = null, signers: List<SmartAccountSigner>, policies: Map<String, SCValXdr> = emptyMap(), selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Adds a new context rule to the smart account.

Link copied to clipboard
suspend fun getAllContextRules(maxScanId: UInt = kit.config.maxContextRuleScanId): List<SCValXdr>

Retrieves all active context rules as raw ScVal objects.

Link copied to clipboard
suspend fun getContextRule(id: UInt): SCValXdr

Retrieves a specific context rule by its ID.

Link copied to clipboard
suspend fun getContextRulesCount(): UInt

Retrieves the total number of context rules in the smart account.

Link copied to clipboard
suspend fun listContextRules(maxScanId: UInt = kit.config.maxContextRuleScanId): List<ParsedContextRule>

Lists all active context rules as parsed objects.

Link copied to clipboard
suspend fun removeContextRule(id: UInt, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Removes a context rule from the smart account.

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

Updates the name of an existing context rule.

Link copied to clipboard
suspend fun updateValidUntil(id: UInt, validUntil: UInt?, selectedSigners: List<SelectedSigner> = emptyList(), forceMethod: SubmissionMethod? = null): TransactionResult

Updates the expiration ledger of an existing context rule.