@midnight-ntwrk/wallet-sdk-shielded 1.0.0-beta.17 → 1.0.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 +131 -0
  2. package/package.json +9 -9
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @midnight-ntwrk/wallet-sdk-shielded
2
+
3
+ Manages shielded tokens on the Midnight network using zero-knowledge proofs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @midnight-ntwrk/wallet-sdk-shielded
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ The Shielded Wallet handles private token operations where transaction values and addresses are hidden from observers
14
+ while maintaining verifiability. It provides:
15
+
16
+ - Zero-knowledge proof generation
17
+ - Coin commitment tracking
18
+ - Encrypted output decryption
19
+ - Shielded transfer transactions
20
+ - Transaction balancing for shielded tokens
21
+
22
+ ## Usage
23
+
24
+ ### Starting the Wallet
25
+
26
+ ```typescript
27
+ import { ShieldedWallet } from '@midnight-ntwrk/wallet-sdk-shielded';
28
+ import * as ledger from '@midnight-ntwrk/ledger-v7';
29
+ import { randomBytes } from 'node:crypto';
30
+
31
+ // Configuration for the wallet
32
+ const configuration = {
33
+ networkId: 'preview',
34
+ provingServerUrl: new URL('http://localhost:6300'),
35
+ relayURL: new URL('ws://localhost:9944'),
36
+ indexerClientConnection: {
37
+ indexerHttpUrl: 'http://localhost:8088/api/v3/graphql',
38
+ indexerWsUrl: 'ws://localhost:8088/api/v3/graphql/ws',
39
+ },
40
+ };
41
+
42
+ // Create secret keys from a shielded seed
43
+ const seed = randomBytes(32);
44
+ const shieldedSecretKeys = ledger.ZswapSecretKeys.fromSeed(seed);
45
+
46
+ // Create and start the wallet
47
+ const shieldedWallet = ShieldedWallet(configuration).startWithSecretKeys(shieldedSecretKeys);
48
+
49
+ // Start syncing with the network
50
+ await shieldedWallet.start(shieldedSecretKeys);
51
+ ```
52
+
53
+ ### Alternative: Start with Seed Directly
54
+
55
+ ```typescript
56
+ // Start directly with a shielded seed
57
+ const shieldedWallet = ShieldedWallet(configuration).startWithShieldedSeed(seed);
58
+ await shieldedWallet.start(ledger.ZswapSecretKeys.fromSeed(seed));
59
+ ```
60
+
61
+ ### Restoring from Serialized State
62
+
63
+ ```typescript
64
+ // Restore a wallet from previously serialized state
65
+ const shieldedWallet = ShieldedWallet(configuration).restore(serializedState);
66
+ await shieldedWallet.start(shieldedSecretKeys);
67
+ ```
68
+
69
+ ### Observing State
70
+
71
+ ```typescript
72
+ wallet.state.subscribe((state) => {
73
+ console.log('Progress:', state.state.progress);
74
+ console.log('Coins:', state.state.coins);
75
+ });
76
+ ```
77
+
78
+ ### Creating Transfer Transactions
79
+
80
+ ```typescript
81
+ const tx = await wallet.transferTransaction(shieldedSecretKeys, [
82
+ { type: 'NIGHT', receiverAddress: 'mn_shield-addr1...', amount: 1000n },
83
+ ]);
84
+ ```
85
+
86
+ ### Balancing Transactions
87
+
88
+ ```typescript
89
+ const balancingTx = await wallet.balanceTransaction(shieldedSecretKeys, transactionToBalance);
90
+ ```
91
+
92
+ ### Finalizing Transactions
93
+
94
+ ```typescript
95
+ // Generates ZK proofs and finalizes the transaction
96
+ const finalizedTx = await wallet.finalizeTransaction(unprovenTx);
97
+ ```
98
+
99
+ ### Creating Swap Offers
100
+
101
+ ```typescript
102
+ const swapTx = await wallet.initSwap(
103
+ shieldedSecretKeys,
104
+ { NIGHT: 500n }, // inputs
105
+ [{ type: 'TOKEN_A', receiverAddress: shieldedAddress, amount: 100n }], // outputs
106
+ );
107
+ ```
108
+
109
+ ## Privacy Model
110
+
111
+ Shielded transactions use zero-knowledge proofs to hide:
112
+
113
+ - Transaction amounts
114
+ - Sender addresses
115
+ - Receiver addresses
116
+
117
+ While still proving:
118
+
119
+ - The sender has sufficient balance
120
+ - No tokens are created or destroyed
121
+ - The transaction is valid
122
+
123
+ ## Exports
124
+
125
+ - `ShieldedWallet` - Main wallet class
126
+ - `ShieldedWalletState` - Wallet state type
127
+ - Version 1 exports via `@midnight-ntwrk/wallet-sdk-shielded/v1`
128
+
129
+ ## License
130
+
131
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-shielded",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -29,14 +29,14 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@midnight-ntwrk/ledger-v7": "7.0.0",
32
- "@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0-beta.10",
33
- "@midnight-ntwrk/wallet-sdk-address-format": "3.0.0-beta.12",
34
- "@midnight-ntwrk/wallet-sdk-capabilities": "3.0.0-beta.12",
35
- "@midnight-ntwrk/wallet-sdk-indexer-client": "1.0.0-beta.17",
36
- "@midnight-ntwrk/wallet-sdk-node-client": "1.0.0-beta.13",
37
- "@midnight-ntwrk/wallet-sdk-prover-client": "1.0.0-beta.14",
38
- "@midnight-ntwrk/wallet-sdk-runtime": "1.0.0-beta.12",
39
- "@midnight-ntwrk/wallet-sdk-utilities": "1.0.0-beta.11",
32
+ "@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0",
33
+ "@midnight-ntwrk/wallet-sdk-address-format": "3.0.0",
34
+ "@midnight-ntwrk/wallet-sdk-capabilities": "3.0.0",
35
+ "@midnight-ntwrk/wallet-sdk-indexer-client": "1.0.0",
36
+ "@midnight-ntwrk/wallet-sdk-node-client": "1.0.0",
37
+ "@midnight-ntwrk/wallet-sdk-prover-client": "1.0.0",
38
+ "@midnight-ntwrk/wallet-sdk-runtime": "1.0.0",
39
+ "@midnight-ntwrk/wallet-sdk-utilities": "1.0.0",
40
40
  "@scure/base": "^1.1.9",
41
41
  "effect": "^3.19.14",
42
42
  "isomorphic-ws": "^5.0.0",