|
| 1 | +# Wallet Auto-Approval System |
| 2 | + |
| 3 | +The Wallet Auto-Approval System enables users to authorize automatic signing of specific transaction |
| 4 | +types, reducing friction for trusted applications while maintaining security and user control |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +This system provides a standard implementation for wallets to automatically approve transactions |
| 9 | +based on predefined policies. It consists of three main components: |
| 10 | + |
| 11 | +- **AutoApprovalPolicy**: Application-hosted policies defining approved transaction types |
| 12 | +- **AutoApprovalManager**: SDK class for policy management and transaction evaluation |
| 13 | +- **AutoApprovalIntent**: Optional hints from applications about which policy rule sets to apply |
| 14 | + |
| 15 | +## Architecture |
| 16 | + |
| 17 | +### Policy Discovery |
| 18 | + |
| 19 | +Applications host their `AutoApprovalPolicy` at: |
| 20 | + |
| 21 | +``` |
| 22 | +/.well-known/sui/automatic-approval-policy.json |
| 23 | +``` |
| 24 | + |
| 25 | +This well-known location enables wallets to discover policies without requiring explicit |
| 26 | +advertising, making policies easier to mange for wallets, easier to audit and harder to change |
| 27 | +frequently or generate dynamically to target specific users. |
| 28 | + |
| 29 | +### Policy Structure |
| 30 | + |
| 31 | +An `AutoApprovalPolicy` contains: |
| 32 | + |
| 33 | +- **ruleSets**: Collections of rules describing allowed asset interactions |
| 34 | +- **suggestedSettings**: Recommended user configurations (budgets, limits, etc.) |
| 35 | +- **defaultRuleSet**: Must be null - auto-approvals require explicit rule set selection |
| 36 | + |
| 37 | +### Rule Types |
| 38 | + |
| 39 | +Each ruleset specifies rules for different asset access patterns: |
| 40 | + |
| 41 | +- **ownedObjects**: Access to specific object types the user owns |
| 42 | +- **sessionCreatedObjects**: Access to objects created during the current session |
| 43 | +- **balances**: Access to specific coin type balances |
| 44 | +- **allBalances**: Access to all coin balances |
| 45 | + |
| 46 | +### Policy Settings |
| 47 | + |
| 48 | +User-controlled limits applied to approved policies. These are controlled by the wallet and can be |
| 49 | +configured by the user. |
| 50 | + |
| 51 | +- **remainingTransactions**: Maximum transactions per session |
| 52 | +- **expiration**: Session expiration timestamp |
| 53 | +- **approvedRuleSets**: Currently active rulesets |
| 54 | +- **usdBudget**: USD spending limit across all coins |
| 55 | +- **coinBudgets**: Per-coin-type spending limits |
| 56 | + |
| 57 | +## Usage Flow |
| 58 | + |
| 59 | +1. **Transaction Construction**: Applications build transactions normally, adding |
| 60 | + `tx.add(autoApproval(ruleSetId))` to request auto-approval with a specific rule set |
| 61 | + |
| 62 | +2. **Policy Evaluation**: Wallet loads the AutoApprovalManager and analyzes the transaction against |
| 63 | + current policy state |
| 64 | + |
| 65 | +3. **Auto-Approval Decision**: If approved, wallet signs automatically; otherwise, falls back to |
| 66 | + standard user confirmation |
| 67 | + |
| 68 | +4. **State Updates**: On signing, the manager deducts balances and policy settings. After execution, |
| 69 | + transaction effects can be applied to track new objects and increase balances in the policy |
| 70 | + settings. |
| 71 | + |
| 72 | +## Implementation |
| 73 | + |
| 74 | +### AutoApprovalManager Class |
| 75 | + |
| 76 | +The core SDK class manages policy state and transaction analysis: |
| 77 | + |
| 78 | +```typescript |
| 79 | +class AutoApprovalManager { |
| 80 | + constructor(options: AutoApprovalManagerOptions); |
| 81 | + analyzeTransaction(tx: Transaction): Promise<TransactionAnalysis>; |
| 82 | + commitTransaction(analysis: TransactionAnalysis): void; |
| 83 | + applyTransactionEffects(analysis: TransactionAnalysis, effects: TransactionEffects): void; |
| 84 | + update(policy: AutoApprovalPolicy, settings: AutoApprovalPolicySettings): void; |
| 85 | + approve(): void; |
| 86 | + reset(): void; |
| 87 | + export(): string; |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +### State Management |
| 92 | + |
| 93 | +The manager maintains an `AutoApprovalState` tracking: |
| 94 | + |
| 95 | +- Current policy and settings |
| 96 | +- Balance changes and transaction history |
| 97 | +- Created objects from approved transactions |
| 98 | +- Approved and pending transaction digests |
| 99 | + |
| 100 | +## Design Decisions |
| 101 | + |
| 102 | +### Limited API Surface |
| 103 | + |
| 104 | +Applications have no visibility into auto-approval state, ensuring: |
| 105 | + |
| 106 | +- Simple adoption (just publish a policy) |
| 107 | +- Compatibility with non-supporting wallets |
| 108 | +- Graceful degradation when users opt out |
| 109 | + |
| 110 | +### User Control |
| 111 | + |
| 112 | +All limits and permissions remain under user control: |
| 113 | + |
| 114 | +- Policies only describe what _may_ be auto-approved |
| 115 | +- Users set actual budgets and transaction limits |
| 116 | +- Access can be revoked at any time without breaking functionality |
| 117 | + |
| 118 | +### Security |
| 119 | + |
| 120 | +Well-known policy locations and structured rules provide: |
| 121 | + |
| 122 | +- Auditability of application intentions |
| 123 | +- Protection against dynamic policy manipulation |
0 commit comments