Wallet Automatic Approvals #567
hayes-mysten
started this conversation in
Technical Discussions
Replies: 1 comment 10 replies
-
|
Using JSON schema seems like a good idea for this. I might have missed it, but are the definitions, validation constraints, etc etc published already or is this just a starting point for defining things like that? |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Wallet automatic approvals (auto-approvals) will enable users and applications to securely opt into
auto-approval of specific types of transactions with user-defined limits and budgets.
Demo
compressed_screen_recording.mp4
Goals
automatically approve.
dapps to integrate.
choose to display the user with an approval prompt.
How It Works
Applications Define Their Operations: Understanding the intent behind a Transaction is a hard
problem. Rather than wallets guessing what a transaction does, applications will publish a policy
that describes the different types of operations it might perform, and what types of assets those
operations use. A game might declare that it performs "character moves" that require gas fees and
modify player objects. A DEX might declare that it performs "token swaps" using any coin type. These
policies are public, auditable, and serve as contracts with users about what the application will
do.
Wallets Detect Policies: Wallets will detect when an application has configured an auto-approval
policy, and may prompt the user to enable auto-approvals. It is up to each wallet to decide how and
when to implement this flow, but could be done when the user is first prompted for a transaction
covered by the auto-approval policy.
Users Configure Settings They Control: When the wallet prompts a user to opt into
auto-approvals, they will be presented with descriptions of the different operations an application
supports, and what assets they need to access. They can select what operations are auto approved, as
well as what limits to enforce on those operations. They might allow 100 game moves using up to 1
SUI for gas, expiring after 2 hours. Or 50 token swaps up to $500 total value, expiring after their
trading session. These limits are enforced by the wallet, not the application, ensuring no
application can exceed what users have approved.
Wallets Determine What Gets Auto-Approved: Applications simply request signatures on
transactions through the existing wallet-standard methods, and won't know if the user is using
auto-approvals. The wallet can evaluate if the transaction matches the application's policy and if
the user's settings would allow the transaction to be automatically approved. If the policy and
settings allow for auto-approval, the wallet may automatically sign the transaction.
How Applications Support Auto-Approvals
Applications support auto-approvals through two simple steps: publishing a policy document and
tagging their transactions with an operation type.
The system is intentionally designed so that applications have no knowledge of whether
auto-approvals are enabled, and instead applications always provide wallets enough information to
enable auto-approvals if the user opts in. Applications don't need to check for support, handle
different code paths, or worry about compatibility. They simply publish their policy, tag their
transactions, and let wallets handle everything else. This clean separation of concerns means
applications can adopt auto-approvals with confidence that they won't break anything for existing
users.
Creating Policy Documents
The policy document is a JSON file that describes the different types of operations an application
performs. Each operation represents a category of transactions that share similar characteristics -
for example, "game actions", "marketplace trades", or "governance votes". The policy tells wallets
what objects transactions need to access, what coins they might spend, and how they interact with
the blockchain.
When designing operations, applications consider how users interact with them. They group related
actions together when they require similar permissions, but separate them when users might want
different approval settings. For instance, they might separate "gameplay" operations from
"marketplace" operations, since users might be comfortable auto-approving routine game moves but
want to manually approve each marketplace transaction.
The permissions applications declare should be as specific as possible while still covering their
needs. If a game only needs to modify the player's character object, it should only declare that
specific object type. If it only spends SUI for gas, it should only declare SUI rather than using
anyBalance. This specificity helps users trust the application and makes them more likely toenable auto-approvals.
Example: Complete Policy Structure
{ "schemaVersion": "1.0.0", "operations": [ { "id": "gameplay", "description": "Regular gameplay actions like moving, attacking, and using items", "permissions": { // Coins needed for transactions "balances": [ { "$kind": "CoinBalance", "coinType": "0x2::sui::SUI", "description": "Gas fees for gameplay transactions" } ], // Objects the user owns that we need to access "ownedObjects": [ { "$kind": "ObjectType", "objectType": "0xgame::character::Character", "accessLevel": "mutate", "description": "Update character stats and position" }, { "$kind": "ObjectType", "objectType": "0xgame::inventory::Item", "accessLevel": "transfer", "description": "Use and trade items from inventory" } ] } }, { "id": "marketplace", "description": "Buy and sell items on the marketplace", "permissions": { // Can use any coin type for marketplace transactions "anyBalance": { "$kind": "AnyBalance", "description": "Use any token for marketplace purchases" }, "ownedObjects": [ { "$kind": "ObjectType", "objectType": "0xgame::marketplace::Listing", "accessLevel": "transfer", "description": "Create and manage marketplace listings" } ] } } ] }Permission Types Explained
{ "permissions": { // balances: Specific coin types your transactions use "balances": [ { "$kind": "CoinBalance", "coinType": "0x2::sui::SUI", // Full type name "description": "Human-readable explanation" } ], // anyBalance: For apps that work with any coin type (DEXes, marketplaces) "anyBalance": { "$kind": "AnyBalance", "description": "Why you need any coin type" }, // ownedObjects: Objects the user owns that you need to access "ownedObjects": [ { "$kind": "ObjectType", "objectType": "0xpackage::module::Type", "accessLevel": "read", // Pass by reference (&T) to Move functions "accessLevel": "mutate", // Pass by mutable reference (&mut T) to Move functions "accessLevel": "transfer", // Pass by value (T) to Move functions "description": "What you do with this object" } ] } }Hosting Policies
Once applications have created their policy document, they need to host it at a well-known location
where wallets can find it. The URL pattern is standardized so wallets know exactly where to look
without any configuration or registration process. The policy should be served as a static file - it
shouldn't be dynamically generated or personalized per user. Wallets may cache policies, or fetch
policies through their own backends to prevent serving policies tailored to specific users.
The URL follows this pattern:
https://yourdomain.com/.well-known/sui/{network}/automatic-approval-policy.jsonApplications must serve their policy with appropriate CORS headers to allow wallets to fetch it.
Some wallets may be web-based and need to fetch policies from their own origin.
Tagging Transactions
The final step in supporting auto-approvals is tagging transactions with the appropriate operation
ID. This is done using the
operationTypefunction, which adds a special intent to the transactionthat tells wallets which operation from the policy this transaction represents.
Example: Adding Operation Type to Transaction
The tagging process is completely transparent to wallets that don't support auto-approvals. The tags
are automatically stripped out before being sent to any wallet that does not advertise supporting
the intent, so the transaction executes normally without any compatibility issues.
How Auto-Approvals Work for Users
The specific flows used to enable and configure automatic approvals are up to each wallet, but they
should be an entirely optional enhancement to the normal transaction signing flows users are already
familiar with. When users encounter an application that supports auto-approvals, they see the same
signing dialogs they're used to, with the option to enable auto-approvals if they choose. Users can
completely ignore the feature and continue using their wallet exactly as before, or they can opt in
when they want the convenience of automatic signing for trusted applications.
Core functionality any auto-approval implementation should support:
How Wallets Implement Auto-Approvals
Because the application side of auto-approvals is very simple, wallets do not need to use any
specific libraries or standards to support auto approvals, but we are releasing a new
@mysten/wallet-sdkpackage which will include tools that significantly simplify theimplementation.
The wallet SDK includes two main components to help with auto approvals: the TransactionAnalyzer for
understanding transactions, and the AutoApprovalManager for managing state and policy enforcement.
These components work together to provide an easy-to-use foundation to build auto-approvals on.
Transaction Analysis
The TransactionAnalyzer examines transactions to understand what they do, what objects they access,
how they use coins, and what operation type they represent. The output of this analysis is an object
with normalized and easy to use data representing all the different aspects of a Transaction. It is
intended to be used as the foundation for all Transaction approval flows that show users what a
transaction does.
The analyzer is designed to be extended with custom data. While it comes with comprehensive built-in
analyzers for understanding transaction structure, coin flows, and object access patterns, you can
add your own analyzers for wallet-specific needs. For auto-approvals, the base analyzer is extended
with the
operationTypeAnalyzerto extract the operation type that applications embed intransactions, and the
coinValueAnalyzerto calculate coin values in a normalized currency forbudget tracking.
Example: Basic Transaction Analysis
The TransactionAnalyzer should handle all data-loading and async work required to analyze and
display a transaction, including building the transaction to bytes. This pattern guarantees that the
analysis that determines if a Transaction can be auto approved is run against a fully resolved
Transaction with fixed object versions, and will be the exact transaction that is eventually
executed. Co-locating all the data loading should also enable batching and caching of certain
lookups.
The AutoApprovalManager
The AutoApprovalManager is the brain of the auto-approval system. It's a fully synchronous state
machine that manages everything related to auto-approvals for a specific application. When you
create a manager instance, you provide it with the application's policy and any previously saved
state for the application.
The manager handles policy evaluation, budget tracking, and user settings. The manager has a few
core methods:
getSettings(): Gets the user's settingsupdateSettings(): Updates the user's settingsreset(): Clears the user's settings and stateexport(): Exports the manager state as a stringcheckTransaction(analysis): Checks the transaction against the application's policy and theuser's settings, returning detailed information about any issues
commitTransaction(analysis): Updates the user's budgets and settings with the predicted effectsof the transaction
revertTransaction(analysis): Reverts the changes from a commitTransactionapplyTransactionEffects(analysis, result): Reverts the predicted effects, and applies the realeffects of a transaction
User Settings
The AutoApprovalManager maintains user settings, which are the user-configured preferences that
control when transactions can be auto-approved. The current settings include:
large numbers)
when there is no specific budgets for a coinType.
Example: Settings Structure
Settings are updated in three ways:
transactions and budget
Persistence and Recovery
The manager's state should be persisted after making changes to settings, invoking methods like
commitTransactionorapplyTransactionEffectsthat mutate th managers state. Theexport()andconstructor methods handle serialization and deserialization:
Example: State Persistence
Example: Complete Auto-Approval Flow
Beta Was this translation helpful? Give feedback.
All reactions