add Context Rule
Adds a new context rule to the smart account.
Creates a context rule that defines authorization requirements for operations matching the specified context type. The rule includes signers who can authorize matching operations and policies that constrain how operations can be executed.
Flow:
Validates inputs (name, signers count, policies count, policy addresses)
Builds contract invocation for add_context_rule
Simulates to get auth entries
Signs auth entries (requires user interaction)
Submits transaction
Polls for confirmation
Contract limits enforced:
Maximum 15 signers per context rule
Maximum 5 policies per context rule
IMPORTANT: This is a state-changing operation requiring smart account authorization. The user will be prompted for biometric authentication.
Return
TransactionResult indicating success or failure
Parameters
The type of context this rule applies to
A human-readable name for the rule (e.g., "DefaultRule", "TokenTransfers")
Optional ledger number when this rule expires (null = no expiration)
List of signers who can authorize operations matching this context
Map of policy contract addresses to their installation parameters
Optional list of signers for multi-signer authorization. When empty (default), uses single-signer auth with the connected passkey. When non-empty, coordinates signatures from all listed signers.
Optional submission method override. When null (default), uses the configured submission method (relayer if available, RPC otherwise).
Throws
if validation fails
if transaction submission fails
Example:
val result = contextMgr.addContextRule(
contextType = ContextRuleType.CallContract("CBCD1234..."),
name = "TokenOps",
validUntil = 12345678u,
signers = listOf(webAuthnSigner, delegatedSigner),
policies = mapOf(
thresholdPolicyAddress to Scv.toU32(2u),
spendingLimitPolicyAddress to limitScVal
)
)
if (result.success) {
println("Context rule added. Hash: ${result.hash ?: ""}")
}