@ocash/sdk 0.1.0 → 0.1.1

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.
package/README.md CHANGED
@@ -1,4 +1,161 @@
1
1
  # @ocash/sdk
2
2
 
3
- - [English](README_en.md)
4
- - [中文](README_zh.md)
3
+ [![npm version](https://img.shields.io/npm/v/@ocash/sdk)](https://www.npmjs.com/package/@ocash/sdk)
4
+ [![CI](https://github.com/PolyhedraZK/ocash-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/PolyhedraZK/ocash-sdk/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
6
+
7
+ TypeScript ZKP SDK for privacy-preserving token operations — deposit, transfer, and withdraw via UTXO model and zk-SNARK proofs.
8
+
9
+ [Documentation](https://docs.o.cash) | [中文文档](https://docs.o.cash/zh/)
10
+
11
+ ## Features
12
+
13
+ - **Zero-Knowledge Proofs** — Groth16 zk-SNARK via Go WASM for on-chain privacy
14
+ - **UTXO Model** — Poseidon2 commitments, Merkle trees, nullifiers
15
+ - **Multi-Environment** — Browser, Node.js, Electron/Tauri
16
+ - **Modular** — Factory pattern with event-driven modules, compose what you need
17
+ - **4 Storage Adapters** — Memory, IndexedDB, File, KV
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pnpm add @ocash/sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```ts
28
+ import { createSdk, SEPOLIA_TESTNET } from '@ocash/sdk';
29
+
30
+ const sdk = createSdk({
31
+ chains: [SEPOLIA_TESTNET],
32
+ onEvent: console.log,
33
+ });
34
+
35
+ await sdk.core.ready();
36
+ await sdk.wallet.open({ seed: 'your-secret-seed-phrase' });
37
+ await sdk.sync.syncOnce();
38
+
39
+ const balance = await sdk.wallet.getBalance({
40
+ chainId: SEPOLIA_TESTNET.chainId,
41
+ assetId: SEPOLIA_TESTNET.tokens![0]!.id,
42
+ });
43
+ ```
44
+
45
+ Pre-configured chain presets exported from `@ocash/sdk`:
46
+
47
+ | Preset | Chain | Chain ID |
48
+ | --- | --- | --- |
49
+ | `ETH_MAINNET` | Ethereum | 1 |
50
+ | `BSC_MAINNET` | BNB Chain | 56 |
51
+ | `BASE_MAINNET` | Base | 8453 |
52
+ | `SEPOLIA_TESTNET` | Sepolia | 11155111 |
53
+ | `BSC_TESTNET` | BSC Testnet | 97 |
54
+
55
+ Also available: `MAINNET_CHAINS` and `TESTNET_CHAINS` arrays.
56
+
57
+ ## Entry Points
58
+
59
+ | Import | Environment | Extra |
60
+ | -------------------- | ----------- | ------------------ |
61
+ | `@ocash/sdk` | Universal | `MemoryStore` |
62
+ | `@ocash/sdk/browser` | Browser | + `IndexedDbStore` |
63
+ | `@ocash/sdk/node` | Node.js | + `FileStore` |
64
+
65
+ ## SDK Modules
66
+
67
+ ```
68
+ sdk.core — WASM & circuit initialization
69
+ sdk.keys — BabyJubjub key derivation
70
+ sdk.crypto — Commitments, nullifiers, memo encryption
71
+ sdk.assets — Chain / token / relayer configuration
72
+ sdk.storage — Persistence adapter
73
+ sdk.wallet — Session, UTXOs, balance
74
+ sdk.sync — Memo / nullifier / Merkle sync
75
+ sdk.merkle — Merkle proofs & membership witnesses
76
+ sdk.planner — Coin selection, fee estimation
77
+ sdk.zkp — zk-SNARK proof generation
78
+ sdk.tx — Relayer request builder
79
+ sdk.ops — End-to-end orchestration
80
+ ```
81
+
82
+ ## Operations
83
+
84
+ ### Transfer
85
+
86
+ ```ts
87
+ const keyPair = sdk.keys.deriveKeyPair(seed);
88
+ const prepared = await sdk.ops.prepareTransfer({
89
+ chainId,
90
+ assetId,
91
+ amount,
92
+ to: recipientAddress,
93
+ ownerKeyPair: keyPair,
94
+ publicClient,
95
+ });
96
+ const result = await sdk.ops.submitRelayerRequest({ prepared, publicClient });
97
+ const txHash = await result.waitRelayerTxHash;
98
+ ```
99
+
100
+ ### Withdraw
101
+
102
+ ```ts
103
+ const prepared = await sdk.ops.prepareWithdraw({
104
+ chainId,
105
+ assetId,
106
+ amount,
107
+ recipient: evmAddress,
108
+ ownerKeyPair: keyPair,
109
+ publicClient,
110
+ });
111
+ const result = await sdk.ops.submitRelayerRequest({ prepared, publicClient });
112
+ ```
113
+
114
+ ### Deposit
115
+
116
+ ```ts
117
+ const ownerPub = sdk.keys.getPublicKeyBySeed(seed);
118
+ const prepared = await sdk.ops.prepareDeposit({
119
+ chainId,
120
+ assetId,
121
+ amount,
122
+ ownerPublicKey: ownerPub,
123
+ account: walletAddress,
124
+ publicClient,
125
+ });
126
+ if (prepared.approveNeeded) {
127
+ await walletClient.writeContract(prepared.approveRequest);
128
+ }
129
+ await walletClient.writeContract(prepared.depositRequest);
130
+ ```
131
+
132
+ ## Lifecycle
133
+
134
+ ```
135
+ createSdk(config) → Initialize
136
+ sdk.core.ready() → Load WASM & circuits
137
+ sdk.wallet.open({ seed }) → Derive keys, open storage
138
+ sdk.sync.start() → Background sync (or syncOnce)
139
+ sdk.ops.prepareTransfer() → Plan, prove, build request
140
+ sdk.wallet.close() → Release keys, flush storage
141
+ ```
142
+
143
+ ## Requirements
144
+
145
+ - **Node.js** >= 20.19.0
146
+ - **Browser**: WebAssembly + crypto.getRandomValues + fetch
147
+
148
+ ## Development
149
+
150
+ ```bash
151
+ pnpm install
152
+ pnpm run build
153
+ pnpm run test # Run tests
154
+ pnpm run dev # Browser demo
155
+ pnpm run demo:node # Node.js demo
156
+ pnpm run docs:dev # Documentation dev server
157
+ ```
158
+
159
+ ## License
160
+
161
+ [MIT](./LICENSE)