@midnight-ntwrk/wallet-sdk-facade 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.
- package/README.md +130 -0
- package/package.json +8 -8
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @midnight-ntwrk/wallet-sdk-facade
|
|
2
|
+
|
|
3
|
+
Unified facade for the Midnight Wallet SDK that combines all wallet types into a single API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @midnight-ntwrk/wallet-sdk-facade
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The Wallet Facade provides a high-level unified interface that aggregates the functionality of all wallet types
|
|
14
|
+
(shielded, unshielded, and dust). It simplifies wallet operations by providing:
|
|
15
|
+
|
|
16
|
+
- Combined state management across all wallet types
|
|
17
|
+
- Unified transaction balancing for shielded, unshielded, and dust tokens
|
|
18
|
+
- Coordinated transfer and swap operations
|
|
19
|
+
- Simplified transaction finalization flow
|
|
20
|
+
- Dust registration management
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Initializing the Facade
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { WalletFacade } from '@midnight-ntwrk/wallet-sdk-facade';
|
|
28
|
+
|
|
29
|
+
const facade = new WalletFacade(shieldedWallet, unshieldedWallet, dustWallet);
|
|
30
|
+
|
|
31
|
+
// Start all wallets
|
|
32
|
+
await facade.start(shieldedSecretKeys, dustSecretKey);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Observing Combined State
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
facade.state().subscribe((state) => {
|
|
39
|
+
console.log('Shielded:', state.shielded);
|
|
40
|
+
console.log('Unshielded:', state.unshielded);
|
|
41
|
+
console.log('Dust:', state.dust);
|
|
42
|
+
console.log('All synced:', state.isSynced);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Or wait for full sync
|
|
46
|
+
const syncedState = await facade.waitForSyncedState();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Creating Transfer Transactions
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const recipe = await facade.transferTransaction(
|
|
53
|
+
[
|
|
54
|
+
{
|
|
55
|
+
type: 'shielded',
|
|
56
|
+
outputs: [{ type: 'TOKEN_B', receiverAddress: shieldedAddr, amount: 1000n }],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'unshielded',
|
|
60
|
+
outputs: [{ type: 'TOKEN_A', receiverAddress: unshieldedAddr, amount: 500n }],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
{ shieldedSecretKeys, dustSecretKey },
|
|
64
|
+
{ ttl: new Date(Date.now() + 3600000) },
|
|
65
|
+
);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Balancing Transactions
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Balance a finalized transaction
|
|
72
|
+
const recipe = await facade.balanceFinalizedTransaction(
|
|
73
|
+
finalizedTx,
|
|
74
|
+
{ shieldedSecretKeys, dustSecretKey },
|
|
75
|
+
{ ttl, tokenKindsToBalance: 'all' }, // or ['shielded', 'dust']
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Finalize the balanced recipe
|
|
79
|
+
const finalTx = await facade.finalizeRecipe(recipe);
|
|
80
|
+
|
|
81
|
+
// Submit to the network
|
|
82
|
+
const txId = await facade.submitTransaction(finalTx);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Creating Swap Offers
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const swapRecipe = await facade.initSwap(
|
|
89
|
+
{ shielded: { NIGHT: 1000n } }, // inputs
|
|
90
|
+
[{ type: 'shielded', outputs: [{ type: 'TOKEN_A', receiverAddress, amount: 100n }] }], // outputs
|
|
91
|
+
{ shieldedSecretKeys, dustSecretKey },
|
|
92
|
+
{ ttl, payFees: false },
|
|
93
|
+
);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Dust Registration
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// Register Night UTXOs for dust generation
|
|
100
|
+
const registrationRecipe = await facade.registerNightUtxosForDustGeneration(
|
|
101
|
+
nightUtxos,
|
|
102
|
+
nightVerifyingKey,
|
|
103
|
+
signDustRegistration,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Estimate registration costs
|
|
107
|
+
const { fee, dustGenerationEstimations } = await facade.estimateRegistration(nightUtxos);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Types
|
|
111
|
+
|
|
112
|
+
### BalancingRecipe
|
|
113
|
+
|
|
114
|
+
The facade returns different recipe types depending on the input transaction:
|
|
115
|
+
|
|
116
|
+
- `FinalizedTransactionRecipe` - For finalized transactions
|
|
117
|
+
- `UnboundTransactionRecipe` - For unbound transactions
|
|
118
|
+
- `UnprovenTransactionRecipe` - For unproven transactions
|
|
119
|
+
|
|
120
|
+
### TokenKindsToBalance
|
|
121
|
+
|
|
122
|
+
Control which token types to balance:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
type TokenKindsToBalance = 'all' | ('dust' | 'shielded' | 'unshielded')[];
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-facade",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@midnight-ntwrk/ledger-v7": "7.0.0",
|
|
28
|
-
"@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0
|
|
29
|
-
"@midnight-ntwrk/wallet-sdk-address-format": "3.0.0
|
|
30
|
-
"@midnight-ntwrk/wallet-sdk-dust-wallet": "1.0.0
|
|
31
|
-
"@midnight-ntwrk/wallet-sdk-hd": "3.0.0
|
|
32
|
-
"@midnight-ntwrk/wallet-sdk-shielded": "1.0.0
|
|
33
|
-
"@midnight-ntwrk/wallet-sdk-unshielded-wallet": "1.0.0
|
|
28
|
+
"@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0",
|
|
29
|
+
"@midnight-ntwrk/wallet-sdk-address-format": "3.0.0",
|
|
30
|
+
"@midnight-ntwrk/wallet-sdk-dust-wallet": "1.0.0",
|
|
31
|
+
"@midnight-ntwrk/wallet-sdk-hd": "3.0.0",
|
|
32
|
+
"@midnight-ntwrk/wallet-sdk-shielded": "1.0.0",
|
|
33
|
+
"@midnight-ntwrk/wallet-sdk-unshielded-wallet": "1.0.0",
|
|
34
34
|
"rxjs": "^7.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@midnight-ntwrk/wallet-sdk-prover-client": "1.0.0
|
|
37
|
+
"@midnight-ntwrk/wallet-sdk-prover-client": "1.0.0",
|
|
38
38
|
"eslint": "^9.37.0",
|
|
39
39
|
"prettier": "^3.7.0",
|
|
40
40
|
"publint": "~0.3.14",
|