Skip to content

Commit 56514d8

Browse files
committed
add demo
1 parent c7ebf5f commit 56514d8

99 files changed

Lines changed: 10174 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# AGENTS.md
2+
3+
## Build/Test/Lint Commands
4+
- `pnpm build` - Build all packages with Turbo
5+
- `pnpm test` - Run unit tests for all packages
6+
- `pnpm --filter @mysten/sui vitest run path/to/test.spec.ts` - Run single test file
7+
- `pnpm lint` - Check ESLint + Prettier
8+
- `pnpm lint:fix` - Auto-fix linting issues
9+
- `pnpm changeset` - Add changeset for version updates
10+
11+
## Architecture
12+
- **Monorepo**: TypeScript SDKs for Sui blockchain, uses pnpm workspaces + Turbo
13+
- **Core packages**: typescript/ (main SDK), dapp-kit/ (React hooks), wallet-standard/, signers/ (AWS/GCP KMS, Ledger)
14+
- **Services**: deepbook/ (DEX), suins/ (name service), zksend/, walrus/
15+
- **Build**: ESM/CJS outputs to `dist/`, dependency-aware builds via Turbo
16+
- **Tests**: Vitest for unit tests, separate e2e configs, Docker for integration tests
17+
18+
## Code Style
19+
- **Headers**: Apache-2.0 license headers required (`header/header` rule)
20+
- **Imports**: Consistent type imports (`@typescript-eslint/consistent-type-imports`), require extensions
21+
- **TypeScript**: Strict typing, no `any` in production, prefer `type` imports
22+
- **Naming**: Underscore prefix for unused vars (`argsIgnorePattern: '^_'`)
23+
- **Modules**: Subpath exports pattern (`@mysten/sui/client`, `@mysten/sui/bcs`)
24+
- **No Buffer**: Banned in packages for web compatibility

packages/enoki-connect/demo-dapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@mysten/wallet-standard": "workspace:*",
1717
"@radix-ui/colors": "^3.0.0",
1818
"@radix-ui/react-icons": "^1.3.0",
19-
"@radix-ui/themes": "^3.1.1",
19+
"@radix-ui/themes": "^3.1.6",
2020
"@tanstack/react-query": "^5.87.1",
2121
"react": "^18.3.1",
2222
"react-dom": "^18.3.1"
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
# Move build artifacts
27+
**/build/
28+
package_summaries/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
*.min.js
4+
*.map
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Wallet SDK Demo App
2+
3+
This demo app showcases two key components side by side:
4+
5+
1. **Demo Wallet**: A simple wallet implementation based on the wallet-standard that shows what
6+
transactions are being signed and allows approve/reject actions
7+
2. **Demo dApp**: A counter example app that uses dapp-kit-react to interact with the wallet
8+
9+
## Features
10+
11+
### Demo Wallet
12+
13+
- Creates an in-browser wallet using Ed25519 keypair
14+
- Registers with the wallet-standard
15+
- Shows signing requests with details
16+
- Allows users to approve or reject transactions
17+
- Displays the wallet address
18+
19+
### Demo dApp
20+
21+
- Simple counter application
22+
- Uses dapp-kit-react hooks
23+
- Creates, increments, and resets a counter
24+
- Demonstrates wallet connectivity
25+
26+
## Development
27+
28+
```bash
29+
# Install dependencies
30+
pnpm install
31+
32+
# Start development server
33+
pnpm dev
34+
35+
# Build for production
36+
pnpm build
37+
```
38+
39+
## Configuration
40+
41+
To use the counter functionality, update the `COUNTER_PACKAGE_ID` constant in `src/DemoApp.tsx` with
42+
your deployed counter package ID.
43+
44+
## Architecture
45+
46+
The demo uses:
47+
48+
- Vite for bundling
49+
- React for UI
50+
- @mysten/dapp-kit for dApp functionality
51+
- @mysten/wallet-standard for wallet implementation
52+
- @radix-ui/themes for styling
53+
- @tanstack/react-query for data fetching
54+
55+
The wallet implementation shows a placeholder for future wallet-sdk integration, with a UI that
56+
displays what users are signing before approving transactions.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Wallet SDK Demo App</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# @generated by Move, please check-in and do not edit manually.
2+
3+
[move]
4+
version = 3
5+
manifest_digest = "08D7316957B1A037CF595F048A68951A7170111D758800E544B4CE2943ED9D97"
6+
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
7+
dependencies = [
8+
{ id = "Sui", name = "Sui" },
9+
]
10+
11+
[[move.package]]
12+
id = "MoveStdlib"
13+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }
14+
15+
[[move.package]]
16+
id = "Sui"
17+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }
18+
19+
dependencies = [
20+
{ id = "MoveStdlib", name = "MoveStdlib" },
21+
]
22+
23+
[move.toolchain-version]
24+
compiler-version = "1.51.1"
25+
edition = "2024.beta"
26+
flavor = "sui"
27+
28+
[env]
29+
30+
[env.testnet]
31+
chain-id = "4c78adac"
32+
original-published-id = "0x58a6d7dccd124b7e0bb9756dc309f5d5b9e2bc38a05261177970e96d0d3911f1"
33+
latest-published-id = "0x58a6d7dccd124b7e0bb9756dc309f5d5b9e2bc38a05261177970e96d0d3911f1"
34+
published-version = "1"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "counter"
3+
version = "0.0.1"
4+
edition = "2024.beta"
5+
6+
[dependencies]
7+
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
8+
9+
[addresses]
10+
counter = "0x0"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
/// This example demonstrates a basic use of a shared object.
5+
/// Rules:
6+
/// - anyone can create and share a counter
7+
/// - everyone can increment a counter by 1
8+
/// - the owner of the counter can reset it to any value
9+
module counter::counter {
10+
/// A shared counter.
11+
public struct Counter has key {
12+
id: UID,
13+
owner: address,
14+
value: u64
15+
}
16+
17+
/// Create and share a Counter object.
18+
public fun create(ctx: &mut TxContext) {
19+
transfer::share_object(Counter {
20+
id: object::new(ctx),
21+
owner: ctx.sender(),
22+
value: 0
23+
})
24+
}
25+
26+
/// Increment a counter by 1.
27+
public fun increment(counter: &mut Counter) {
28+
counter.value = counter.value + 1;
29+
}
30+
31+
/// Set value (only runnable by the Counter owner)
32+
public fun set_value(counter: &mut Counter, value: u64, ctx: &TxContext) {
33+
assert!(counter.owner == ctx.sender(), 0);
34+
counter.value = value;
35+
}
36+
}

0 commit comments

Comments
 (0)