@permissionless-technologies/upp-sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +105 -145
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,193 +2,153 @@
2
2
 
3
3
  Privacy-preserving token operations for any ERC20 token.
4
4
 
5
- ## Features
6
-
7
- - **Multi-token support**: Shield any ERC20 into a single privacy pool
8
- - **Large anonymity set**: All token users share one Merkle tree
9
- - **Compliance-ready**: ASP-based whitelists with ragequit protection
10
- - **Modern stack**: Built on viem, not ethers.js
11
-
12
- ## Package Structure
13
-
14
- The SDK is published as a single npm package with subpath exports:
15
-
16
- ```typescript
17
- // Core crypto and utilities
18
- import { poseidon, computeSharedSecret } from '@upp/sdk/core'
19
-
20
- // Key derivation
21
- import { deriveKeysFromSignature } from '@upp/sdk/keys'
5
+ **[Documentation](https://permissionless-technologies.com/docs/upp/quickstart)** | **[Learn more](https://permissionless-technologies.com/upp)**
22
6
 
23
- // React hooks (requires React 18+)
24
- import { UPPAccountProvider, useUPPAccount } from '@upp/sdk/react'
25
-
26
- // Indexer for note scanning
27
- import { makeRpcIndexer } from '@upp/sdk/indexer'
28
- ```
29
-
30
- **Why not separate packages?**
31
-
32
- We considered splitting into `@upp/core`, `@upp/react`, etc. (like Kohaku), but chose a single package because:
33
-
34
- 1. **Same developer experience** - Subpath exports work identically to separate packages
35
- 2. **Tree-shaking works** - Modern bundlers only include what you import
36
- 3. **Simpler versioning** - No cross-package dependency management
37
- 4. **Prototype-appropriate** - Less operational overhead
7
+ ## Features
38
8
 
39
- The internal architecture maintains clean boundaries, so splitting later is straightforward if needed.
9
+ - **Multi-token support** Shield any ERC20 into a single privacy pool
10
+ - **Large anonymity set** — All token users share one Merkle tree
11
+ - **Compliance-ready** — Pluggable ASP (Association Set Provider) with ragequit fallback
12
+ - **Pluggable architecture** — Bring your own account adapter, ASP provider, storage backend
13
+ - **SNARK + STARK** — Dual proof system support (BN254 + Circle STARK)
14
+ - **Modern stack** — Built on viem, TypeScript strict mode, ESM-first
40
15
 
41
16
  ## Installation
42
17
 
43
18
  ```bash
44
- npm install @upp/sdk viem
19
+ npm install @permissionless-technologies/upp-sdk viem
45
20
  ```
46
21
 
47
- ## Quick Start
22
+ ## Subpath Exports
48
23
 
49
24
  ```typescript
50
- import { createUPPClient } from '@upp/sdk'
51
- import { createPublicClient, createWalletClient, http } from 'viem'
52
- import { sepolia } from 'viem/chains'
53
-
54
- // Create viem clients
55
- const publicClient = createPublicClient({
56
- chain: sepolia,
57
- transport: http(),
58
- })
25
+ // Everything
26
+ import { ... } from '@permissionless-technologies/upp-sdk'
59
27
 
60
- const walletClient = createWalletClient({
61
- chain: sepolia,
62
- transport: http(),
63
- })
28
+ // Core: notes, proofs, stealth addresses, transfers
29
+ import { ... } from '@permissionless-technologies/upp-sdk/core'
64
30
 
65
- // Create UPP client
66
- const upp = createUPPClient({
67
- publicClient,
68
- walletClient,
69
- poolAddress: '0x...',
70
- aspHubAddress: '0x...',
71
- })
31
+ // Keys: derivation, viewing keys
32
+ import { ... } from '@permissionless-technologies/upp-sdk/keys'
72
33
 
73
- // Shield tokens
74
- const { commitment, note } = await upp.shield({
75
- token: '0xUSDC...',
76
- amount: 1000n * 10n ** 6n,
77
- })
34
+ // React hooks (requires React 18+ and wagmi)
35
+ import { ... } from '@permissionless-technologies/upp-sdk/react'
78
36
 
79
- // Transfer privately
80
- await upp.transfer({
81
- note: myNote,
82
- recipient: recipientStealthAddress,
83
- amount: 500n * 10n ** 6n,
84
- })
37
+ // Indexer: note scanning, storage adapters
38
+ import { ... } from '@permissionless-technologies/upp-sdk/indexer'
85
39
 
86
- // Withdraw
87
- await upp.withdraw({
88
- note: myNote,
89
- amount: 500n * 10n ** 6n,
90
- recipient: '0xMyAddress...',
91
- aspId: 1,
92
- })
40
+ // Utilities: poseidon, babyjubjub, merkle trees
41
+ import { ... } from '@permissionless-technologies/upp-sdk/utils'
93
42
  ```
94
43
 
95
- ## Local Development
96
-
97
- ### Prerequisites
98
-
99
- - [Foundry](https://book.getfoundry.sh/getting-started/installation) for contract compilation and deployment
100
- - [Node.js](https://nodejs.org/) 18+
101
- - Local Ethereum node (Anvil recommended)
102
-
103
- ### Starting a Local Node
104
-
105
- ```bash
106
- # Start Anvil with auto-mining
107
- anvil
108
- ```
109
-
110
- ### Deploying Contracts
111
-
112
- The SDK includes deployment scripts and automatic address extraction:
113
-
114
- ```bash
115
- # 1. Deploy contracts to local Anvil
116
- forge script src/contracts/script/DeployUPP.s.sol:DeployUPPLocal \
117
- --rpc-url http://localhost:8545 \
118
- --broadcast \
119
- --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
44
+ ## Quick Start
120
45
 
121
- # 2. Extract addresses to SDK deployment JSON
122
- node scripts/extract-deployment.js 31337
46
+ ### React Application
123
47
 
124
- # 3. Rebuild SDK to include new addresses
125
- npm run build
126
- ```
48
+ ```tsx
49
+ import { UPPAccountProvider, useUPPAccount, useShield } from '@permissionless-technologies/upp-sdk/react'
50
+ import { getDeployment } from '@permissionless-technologies/upp-sdk'
127
51
 
128
- After deployment, addresses are written to `src/deployments/31337.json`:
52
+ const deployment = getDeployment(11155111) // Sepolia
129
53
 
130
- ```json
131
- {
132
- "UniversalPrivatePool": "0x2279b7a0a67db372996a5fab50d91eaa73d2ebe6",
133
- "ASPRegistryHub": "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512",
134
- "TestToken": "0x610178da211fef7d417bc0e6fed39f05609ad788",
135
- "verifiers": { ... },
136
- "deployBlock": 2
54
+ function App() {
55
+ return (
56
+ <UPPAccountProvider chainId={11155111} ethAddress={address}>
57
+ <ShieldForm />
58
+ </UPPAccountProvider>
59
+ )
137
60
  }
138
61
  ```
139
62
 
140
- ### Using Deployment Addresses
141
-
142
- The SDK provides helpers to load deployment addresses:
63
+ ### Standalone (Node.js / Custom Frontend)
143
64
 
144
65
  ```typescript
145
- import { getDeployment, getDeploymentOrThrow } from '@upp/sdk'
66
+ import {
67
+ getDeployment,
68
+ registerDeployment,
69
+ NoteStore,
70
+ DirectAccountAdapter,
71
+ } from '@permissionless-technologies/upp-sdk'
72
+ import { makeRpcIndexer, createAutoAdapter } from '@permissionless-technologies/upp-sdk/indexer'
73
+
74
+ // Load deployment addresses
75
+ const deployment = getDeployment(11155111)
76
+
77
+ // Or register your own chain
78
+ registerDeployment(8453, {
79
+ UniversalPrivatePool: '0x...',
80
+ ASPRegistryHub: '0x...',
81
+ verifiers: { TransferVerifier: '0x...', MergeVerifier: '0x...', WithdrawVerifier: '0x...' },
82
+ chainId: 8453,
83
+ deployBlock: 12345678,
84
+ })
146
85
 
147
- // Get deployment for chain (returns null if not found)
148
- const deployment = getDeployment(31337)
86
+ // Note storage (pluggable: IndexedDB, localStorage, memory, custom)
87
+ const storage = createAutoAdapter('my-app')
88
+ const noteStore = new NoteStore(storage)
89
+ await noteStore.load()
90
+ ```
149
91
 
150
- // Or throw if not found
151
- const deployment = getDeploymentOrThrow(31337)
92
+ ## Architecture
152
93
 
153
- // Access addresses
154
- const poolAddress = deployment.UniversalPrivatePool
155
- const tokenAddress = deployment.TestToken // local dev
156
- // or
157
- const tokenAddress = deployment.USSC // production
94
+ ```
95
+ @permissionless-technologies/upp-sdk
96
+ ├── core/ # Notes, proofs, stealth addresses, transfers
97
+ ├── keys/ # Key derivation (signature, direct, custom)
98
+ ├── react/ # React hooks (useUPPAccount, useShield, etc.)
99
+ ├── indexer/ # Note scanning + pluggable storage
100
+ ├── utils/ # Poseidon, BabyJubJub, Merkle trees
101
+ ├── contracts/ # ABIs + Solidity interfaces
102
+ └── deployments/ # Per-chain contract addresses
158
103
  ```
159
104
 
160
- ### TestStableToken (TST)
161
-
162
- The local deployment includes a test ERC20 token with an ETH-to-token swap:
105
+ ### Pluggable Interfaces
163
106
 
164
- ```typescript
165
- // Mint TST by sending ETH (1 ETH = 3000 TST)
166
- await walletClient.sendTransaction({
167
- to: deployment.TestToken,
168
- value: parseEther('1'),
169
- data: encodeFunctionData({
170
- abi: USSC_ABI,
171
- functionName: 'mintWithEth',
172
- }),
173
- })
174
- ```
107
+ | Interface | Purpose | Built-in |
108
+ |-----------|---------|----------|
109
+ | `IAccountAdapter` | Key derivation source | `DirectAccountAdapter`, signature-based |
110
+ | `IASPProvider` | Compliance layer | Optional (ragequit always available) |
111
+ | `StorageAdapter` | Note persistence | IndexedDB, localStorage, memory |
112
+ | `NoteStore` | Note state management | Dedup, balance, status tracking |
175
113
 
176
114
  ## Contract ABIs
177
115
 
178
- The SDK exports ABIs for all contracts:
179
-
180
116
  ```typescript
181
117
  import {
182
118
  UNIVERSAL_PRIVATE_POOL_ABI,
183
119
  ASP_REGISTRY_HUB_ABI,
184
- USSC_ABI,
185
- } from '@upp/sdk'
120
+ TEST_STABLE_TOKEN_ABI,
121
+ } from '@permissionless-technologies/upp-sdk'
122
+ ```
123
+
124
+ Solidity interfaces are included for integration:
125
+
126
+ ```
127
+ node_modules/@permissionless-technologies/upp-sdk/src/contracts/interfaces/
128
+ ├── IUniversalPrivatePool.sol
129
+ ├── IASPRegistry.sol
130
+ └── IVerifiers.sol
186
131
  ```
187
132
 
188
- ## Documentation
133
+ ## Deployments
189
134
 
190
- See [CLAUDE.md](./CLAUDE.md) for detailed API documentation and architecture.
135
+ | Chain | Chain ID | Status |
136
+ |-------|----------|--------|
137
+ | Anvil (local) | 31337 | Built-in |
138
+ | Sepolia | 11155111 | Built-in |
139
+
140
+ Custom chains: use `registerDeployment()` at app initialization.
141
+
142
+ ## Local Development
143
+
144
+ ```bash
145
+ npm install # Install dependencies
146
+ npm run build # Build (ESM + CJS)
147
+ npm run dev # Watch mode
148
+ npm test # Run tests (176 passing)
149
+ npm run deploy:local # Deploy to local Anvil
150
+ ```
191
151
 
192
152
  ## License
193
153
 
194
- MIT
154
+ [AGPL-3.0-or-later](./LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@permissionless-technologies/upp-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Universal Private Pool SDK - Privacy-preserving token operations for any ERC20",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",