@midnight-ntwrk/wallet-sdk-shielded 1.0.0-beta.9 → 2.0.0-rc.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 +131 -0
- package/dist/ShieldedWallet.d.ts +30 -32
- package/dist/ShieldedWallet.js +27 -9
- package/dist/index.js +12 -0
- package/dist/v1/CoinsAndBalances.d.ts +1 -1
- package/dist/v1/CoreWallet.d.ts +5 -6
- package/dist/v1/CoreWallet.js +22 -11
- package/dist/v1/Proving.d.ts +14 -5
- package/dist/v1/Proving.js +35 -30
- package/dist/v1/RunningV1Variant.d.ts +17 -20
- package/dist/v1/RunningV1Variant.js +11 -11
- package/dist/v1/Serialization.js +14 -26
- package/dist/v1/Simulator.d.ts +3 -3
- package/dist/v1/Simulator.js +14 -2
- package/dist/v1/Sync.d.ts +5 -4
- package/dist/v1/Sync.js +26 -9
- package/dist/v1/Transacting.d.ts +16 -35
- package/dist/v1/Transacting.js +58 -165
- package/dist/v1/TransactionHistory.d.ts +1 -1
- package/dist/v1/TransactionHistory.js +6 -6
- package/dist/v1/TransactionImbalances.js +12 -0
- package/dist/v1/{Transaction.d.ts → TransactionOps.d.ts} +6 -6
- package/dist/v1/{Transaction.js → TransactionOps.js} +18 -6
- package/dist/v1/V1Builder.d.ts +15 -21
- package/dist/v1/V1Builder.js +14 -17
- package/dist/v1/WalletError.d.ts +1 -1
- package/dist/v1/WalletError.js +12 -0
- package/dist/v1/index.d.ts +1 -3
- package/dist/v1/index.js +13 -3
- package/package.json +19 -16
- package/dist/v1/ProvingRecipe.d.ts +0 -18
- package/dist/v1/ProvingRecipe.js +0 -3
- package/dist/v1/Submission.d.ts +0 -31
- package/dist/v1/Submission.js +0 -57
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).startWithSeed(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/dist/ShieldedWallet.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
-
import { BaseV1Configuration, DefaultV1Configuration, V1Variant, CoreWallet } from './v1/index.js';
|
|
3
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
1
|
+
import { type ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { type BaseV1Configuration, type DefaultV1Configuration, type V1Variant, CoreWallet } from './v1/index.js';
|
|
3
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
4
4
|
import * as rx from 'rxjs';
|
|
5
|
-
import {
|
|
6
|
-
import { SerializationCapability } from './v1/Serialization.js';
|
|
7
|
-
import { ProgressUpdate, TransactionHistoryCapability } from './v1/TransactionHistory.js';
|
|
8
|
-
import { AvailableCoin, CoinsAndBalancesCapability, PendingCoin } from './v1/CoinsAndBalances.js';
|
|
9
|
-
import { KeysCapability } from './v1/Keys.js';
|
|
10
|
-
import { ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { Variant, VariantBuilder, WalletLike } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
5
|
+
import { type BalancingResult } from './v1/Transacting.js';
|
|
6
|
+
import { type SerializationCapability } from './v1/Serialization.js';
|
|
7
|
+
import { type ProgressUpdate, type TransactionHistoryCapability } from './v1/TransactionHistory.js';
|
|
8
|
+
import { type AvailableCoin, type CoinsAndBalancesCapability, type PendingCoin } from './v1/CoinsAndBalances.js';
|
|
9
|
+
import { type KeysCapability } from './v1/Keys.js';
|
|
10
|
+
import { type ShieldedAddress, type ShieldedCoinPublicKey, type ShieldedEncryptionPublicKey } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
11
|
+
import { type TokenTransfer } from './v1/Transacting.js';
|
|
12
|
+
import { type WalletSyncUpdate } from './v1/Sync.js';
|
|
13
|
+
import { type Variant, type VariantBuilder, type WalletLike } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
15
14
|
export type ShieldedWalletCapabilities<TSerialized = string, TTransaction = ledger.FinalizedTransaction> = {
|
|
16
15
|
serialization: SerializationCapability<CoreWallet, null, TSerialized>;
|
|
17
16
|
coinsAndBalances: CoinsAndBalancesCapability<CoreWallet>;
|
|
18
17
|
keys: KeysCapability<CoreWallet>;
|
|
19
18
|
transactionHistory: TransactionHistoryCapability<CoreWallet, TTransaction>;
|
|
20
19
|
};
|
|
20
|
+
export type UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
|
|
21
21
|
export declare class ShieldedWalletState<TSerialized = string, TTransaction = ledger.FinalizedTransaction> {
|
|
22
22
|
static readonly mapState: <TSerialized_1 = string, TTransaction_1 = ledger.FinalizedTransaction>(capabilities: ShieldedWalletCapabilities<TSerialized_1, TTransaction_1>) => (state: ProtocolState.ProtocolState<CoreWallet>) => ShieldedWalletState<TSerialized_1, TTransaction_1>;
|
|
23
23
|
readonly protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
@@ -31,38 +31,36 @@ export declare class ShieldedWalletState<TSerialized = string, TTransaction = le
|
|
|
31
31
|
get encryptionPublicKey(): ShieldedEncryptionPublicKey;
|
|
32
32
|
get address(): ShieldedAddress;
|
|
33
33
|
get progress(): ProgressUpdate;
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Transaction history for the wallet.
|
|
36
|
+
* @throws Error - Not yet implemented
|
|
37
|
+
*/
|
|
38
|
+
get transactionHistory(): never;
|
|
35
39
|
constructor(state: ProtocolState.ProtocolState<CoreWallet>, capabilities: ShieldedWalletCapabilities<TSerialized, TTransaction>);
|
|
36
40
|
serialize(): TSerialized;
|
|
37
41
|
}
|
|
38
|
-
export type SubmitTransactionMethod<TTransaction> = {
|
|
39
|
-
(transaction: TTransaction, waitForStatus: 'Submitted'): Promise<SubmissionEventCases.Submitted>;
|
|
40
|
-
(transaction: TTransaction, waitForStatus: 'InBlock'): Promise<SubmissionEventCases.InBlock>;
|
|
41
|
-
(transaction: TTransaction, waitForStatus: 'Finalized'): Promise<SubmissionEventCases.Finalized>;
|
|
42
|
-
(transaction: TTransaction): Promise<SubmissionEventCases.InBlock>;
|
|
43
|
-
(transaction: TTransaction, waitForStatus?: 'Submitted' | 'InBlock' | 'Finalized'): Promise<SubmissionEvent>;
|
|
44
|
-
};
|
|
45
42
|
export type ShieldedWallet = CustomizedShieldedWallet<ledger.ZswapSecretKeys, ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
46
43
|
export type ShieldedWalletClass = CustomizedShieldedWalletClass<ledger.ZswapSecretKeys, ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
47
|
-
export
|
|
48
|
-
Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>
|
|
49
|
-
]> {
|
|
44
|
+
export type ShieldedWalletAPI<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSerialized = string> = {
|
|
50
45
|
readonly state: rx.Observable<ShieldedWalletState<TSerialized, TTransaction>>;
|
|
51
46
|
start(secretKeys: TStartAux): Promise<void>;
|
|
52
|
-
balanceTransaction(secretKeys: ledger.ZswapSecretKeys, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish
|
|
53
|
-
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: readonly TokenTransfer[]): Promise<
|
|
54
|
-
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: readonly TokenTransfer[]): Promise<
|
|
55
|
-
finalizeTransaction(
|
|
56
|
-
readonly submitTransaction: SubmitTransactionMethod<TTransaction>;
|
|
47
|
+
balanceTransaction(secretKeys: ledger.ZswapSecretKeys, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Promise<BalancingResult>;
|
|
48
|
+
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: readonly TokenTransfer[]): Promise<ledger.UnprovenTransaction>;
|
|
49
|
+
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: readonly TokenTransfer[]): Promise<ledger.UnprovenTransaction>;
|
|
50
|
+
finalizeTransaction(transaction: ledger.UnprovenTransaction): Promise<TTransaction>;
|
|
57
51
|
serializeState(): Promise<TSerialized>;
|
|
58
52
|
waitForSyncedState(allowedGap?: bigint): Promise<ShieldedWalletState<TSerialized, TTransaction>>;
|
|
59
53
|
getAddress(): Promise<ShieldedAddress>;
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
revertTransaction(transaction: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Promise<void>;
|
|
55
|
+
stop(): Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
export type CustomizedShieldedWallet<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSyncUpdate = WalletSyncUpdate, TSerialized = string> = ShieldedWalletAPI<TStartAux, TTransaction, TSerialized> & WalletLike.WalletLike<[Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>]>;
|
|
58
|
+
export type DefaultShieldedConfiguration = DefaultV1Configuration;
|
|
59
|
+
export interface CustomizedShieldedWalletClass<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSyncUpdate = WalletSyncUpdate, TSerialized = string, TConfig extends BaseV1Configuration = DefaultShieldedConfiguration> extends WalletLike.BaseWalletClass<[
|
|
62
60
|
Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>
|
|
63
61
|
]> {
|
|
64
62
|
configuration: TConfig;
|
|
65
|
-
|
|
63
|
+
startWithSeed(seed: Uint8Array): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
66
64
|
startWithSecretKeys(secretKeys: ledger.ZswapSecretKeys): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
67
65
|
restore(serializedState: TSerialized): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
68
66
|
}
|
package/dist/ShieldedWallet.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) 2025 Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
-
import { V1Builder, V1Tag, CoreWallet } from './v1/index.js';
|
|
3
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
14
|
+
import { V1Builder, V1Tag, CoreWallet, } from './v1/index.js';
|
|
15
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
4
16
|
import { Effect, Either } from 'effect';
|
|
5
17
|
import * as rx from 'rxjs';
|
|
6
18
|
import { WalletBuilder } from '@midnight-ntwrk/wallet-sdk-runtime';
|
|
@@ -35,8 +47,12 @@ export class ShieldedWalletState {
|
|
|
35
47
|
get progress() {
|
|
36
48
|
return this.capabilities.transactionHistory.progress(this.state);
|
|
37
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Transaction history for the wallet.
|
|
52
|
+
* @throws Error - Not yet implemented
|
|
53
|
+
*/
|
|
38
54
|
get transactionHistory() {
|
|
39
|
-
|
|
55
|
+
throw new Error('Transaction history is not yet implemented for ShieldedWallet');
|
|
40
56
|
}
|
|
41
57
|
constructor(state, capabilities) {
|
|
42
58
|
this.protocolVersion = state.version;
|
|
@@ -59,7 +75,7 @@ export function CustomShieldedWallet(configuration, builder) {
|
|
|
59
75
|
static startWithSecretKeys(secretKeys) {
|
|
60
76
|
return CustomShieldedWalletImplementation.startFirst(CustomShieldedWalletImplementation, CoreWallet.initEmpty(secretKeys, CustomShieldedWalletImplementation.configuration.networkId));
|
|
61
77
|
}
|
|
62
|
-
static
|
|
78
|
+
static startWithSeed(seed) {
|
|
63
79
|
const secretKeys = ledger.ZswapSecretKeys.fromSeed(seed);
|
|
64
80
|
return CustomShieldedWalletImplementation.startWithSecretKeys(secretKeys);
|
|
65
81
|
}
|
|
@@ -95,18 +111,20 @@ export function CustomShieldedWallet(configuration, builder) {
|
|
|
95
111
|
.dispatch({ [V1Tag]: (v1) => v1.initSwap(secretKeys, desiredInputs, desiredOutputs) })
|
|
96
112
|
.pipe(Effect.runPromise);
|
|
97
113
|
}
|
|
98
|
-
finalizeTransaction(
|
|
114
|
+
finalizeTransaction(transaction) {
|
|
99
115
|
return this.runtime
|
|
100
116
|
.dispatch({
|
|
101
|
-
[V1Tag]: (v1) => v1.finalizeTransaction(
|
|
117
|
+
[V1Tag]: (v1) => v1.finalizeTransaction(transaction),
|
|
102
118
|
})
|
|
103
119
|
.pipe(Effect.runPromise);
|
|
104
120
|
}
|
|
105
|
-
|
|
121
|
+
revertTransaction(transaction) {
|
|
106
122
|
return this.runtime
|
|
107
|
-
.dispatch({
|
|
123
|
+
.dispatch({
|
|
124
|
+
[V1Tag]: (v1) => v1.revertTransaction(transaction),
|
|
125
|
+
})
|
|
108
126
|
.pipe(Effect.runPromise);
|
|
109
|
-
}
|
|
127
|
+
}
|
|
110
128
|
waitForSyncedState(allowedGap = 0n) {
|
|
111
129
|
return rx.firstValueFrom(this.state.pipe(rx.filter((state) => state.state.progress.isCompleteWithin(allowedGap))));
|
|
112
130
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) 2025 Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
export * from './ShieldedWallet.js';
|
package/dist/v1/CoreWallet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
1
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
2
|
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
3
|
import { Either } from 'effect';
|
|
4
4
|
import { SyncProgress, SyncProgressData } from './SyncProgress.js';
|
|
@@ -28,22 +28,21 @@ export type CoreWallet = Readonly<{
|
|
|
28
28
|
protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
29
29
|
progress: SyncProgress;
|
|
30
30
|
networkId: string;
|
|
31
|
-
txHistoryArray: readonly ledger.FinalizedTransaction[];
|
|
32
31
|
coinHashes: CoinHashesMap;
|
|
33
32
|
}>;
|
|
34
33
|
export declare const CoreWallet: {
|
|
35
34
|
init(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys, networkId: string): CoreWallet;
|
|
36
35
|
empty(publicKeys: PublicKeys, networkId: string): CoreWallet;
|
|
37
|
-
restore(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys,
|
|
38
|
-
restoreWithCoinHashes(publicKeys: PublicKeys, localState: ledger.ZswapLocalState,
|
|
36
|
+
restore(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys, syncProgress: Omit<SyncProgressData, "isConnected">, protocolVersion: bigint, networkId: string): CoreWallet;
|
|
37
|
+
restoreWithCoinHashes(publicKeys: PublicKeys, localState: ledger.ZswapLocalState, coinHashes: CoinHashesMap, syncProgress: SyncProgressData, protocolVersion: bigint, networkId: string): Either.Either<CoreWallet, WalletError>;
|
|
39
38
|
initEmpty(keys: ledger.ZswapSecretKeys, networkId: string): CoreWallet;
|
|
40
39
|
applyCollapsedUpdate(wallet: CoreWallet, collapsed: ledger.MerkleTreeCollapsedUpdate): CoreWallet;
|
|
41
40
|
apply<TOffer extends ledger.ZswapOffer<ledger.Proofish>>(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, offer: TOffer): CoreWallet;
|
|
42
41
|
replayEvents(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, events: ledger.Event[]): CoreWallet;
|
|
43
42
|
updateProgress(wallet: CoreWallet, { appliedIndex, highestRelevantWalletIndex, highestIndex, highestRelevantIndex, isConnected, }: Partial<SyncProgressData>): CoreWallet;
|
|
44
|
-
addTransaction(wallet: CoreWallet,
|
|
43
|
+
addTransaction(wallet: CoreWallet, _tx: ledger.FinalizedTransaction): CoreWallet;
|
|
45
44
|
revertTransaction<TTx extends ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>>(wallet: CoreWallet, _tx: TTx): CoreWallet;
|
|
46
|
-
updateTxHistory(wallet: CoreWallet,
|
|
45
|
+
updateTxHistory(wallet: CoreWallet, _newTxs: readonly ledger.FinalizedTransaction[]): CoreWallet;
|
|
47
46
|
spendCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.QualifiedShieldedCoinInfo>, segment: number): [ReadonlyArray<ledger.ZswapOffer<ledger.PreProof>>, CoreWallet];
|
|
48
47
|
watchCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.ShieldedCoinInfo>): CoreWallet;
|
|
49
48
|
};
|
package/dist/v1/CoreWallet.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) 2025 Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
14
|
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
15
|
import { Either, Iterable, pipe, Record, Array as Arr } from 'effect';
|
|
4
16
|
import { createSyncProgress } from './SyncProgress.js';
|
|
@@ -46,7 +58,7 @@ export const CoreWallet = {
|
|
|
46
58
|
const coinHashes = CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState));
|
|
47
59
|
const progress = createSyncProgress();
|
|
48
60
|
const protocolVersion = ProtocolVersion.MinSupportedVersion;
|
|
49
|
-
return { state: localState, publicKeys, networkId, coinHashes,
|
|
61
|
+
return { state: localState, publicKeys, networkId, coinHashes, progress, protocolVersion };
|
|
50
62
|
},
|
|
51
63
|
empty(publicKeys, networkId) {
|
|
52
64
|
return {
|
|
@@ -54,12 +66,11 @@ export const CoreWallet = {
|
|
|
54
66
|
publicKeys,
|
|
55
67
|
networkId,
|
|
56
68
|
coinHashes: CoinHashesMap.empty,
|
|
57
|
-
txHistoryArray: [],
|
|
58
69
|
progress: createSyncProgress(),
|
|
59
70
|
protocolVersion: ProtocolVersion.MinSupportedVersion,
|
|
60
71
|
};
|
|
61
72
|
},
|
|
62
|
-
restore(localState, secretKeys,
|
|
73
|
+
restore(localState, secretKeys, syncProgress, protocolVersion, networkId) {
|
|
63
74
|
const publicKeys = PublicKeys.fromSecretKeys(secretKeys);
|
|
64
75
|
const coinHashes = CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState));
|
|
65
76
|
return {
|
|
@@ -67,12 +78,11 @@ export const CoreWallet = {
|
|
|
67
78
|
publicKeys,
|
|
68
79
|
networkId,
|
|
69
80
|
coinHashes,
|
|
70
|
-
txHistoryArray: txHistory,
|
|
71
81
|
progress: createSyncProgress(syncProgress),
|
|
72
82
|
protocolVersion: ProtocolVersion.ProtocolVersion(protocolVersion),
|
|
73
83
|
};
|
|
74
84
|
},
|
|
75
|
-
restoreWithCoinHashes(publicKeys, localState,
|
|
85
|
+
restoreWithCoinHashes(publicKeys, localState, coinHashes, syncProgress, protocolVersion, networkId) {
|
|
76
86
|
return CoinHashesMap.assertValid(coinHashes, localState).pipe(Either.mapBoth({
|
|
77
87
|
onLeft: (missingNonces) => new InvalidCoinHashesError({ message: 'Missing coin hashes for coins present in the state', missingNonces }),
|
|
78
88
|
onRight: () => ({
|
|
@@ -80,7 +90,6 @@ export const CoreWallet = {
|
|
|
80
90
|
publicKeys,
|
|
81
91
|
networkId,
|
|
82
92
|
coinHashes,
|
|
83
|
-
txHistoryArray: txHistory,
|
|
84
93
|
progress: createSyncProgress(syncProgress),
|
|
85
94
|
protocolVersion: ProtocolVersion.ProtocolVersion(protocolVersion),
|
|
86
95
|
}),
|
|
@@ -113,15 +122,17 @@ export const CoreWallet = {
|
|
|
113
122
|
});
|
|
114
123
|
return { ...wallet, progress: updatedProgress };
|
|
115
124
|
},
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
// TODO: Remove after tx history is implemented
|
|
126
|
+
addTransaction(wallet, _tx) {
|
|
127
|
+
return wallet;
|
|
118
128
|
},
|
|
119
129
|
/* not implemented until this is done https://shielded.atlassian.net/browse/PM-19678 */
|
|
120
130
|
revertTransaction(wallet, _tx) {
|
|
121
131
|
return wallet;
|
|
122
132
|
},
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
// TODO: Remove after tx history is implemented
|
|
134
|
+
updateTxHistory(wallet, _newTxs) {
|
|
135
|
+
return wallet;
|
|
125
136
|
},
|
|
126
137
|
spendCoins(wallet, secretKeys, coins, segment) {
|
|
127
138
|
const [offers, newLocalState] = pipe(coins, Arr.reduce([[], wallet.state], ([accOffers, localState], coinToSpend) => {
|
package/dist/v1/Proving.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
|
+
import type { KeyMaterialProvider } from '@midnight-ntwrk/zkir-v2';
|
|
3
|
+
import { ProverClient } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
4
|
+
import { InvalidProtocolSchemeError } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
5
|
+
import { Effect, Layer } from 'effect';
|
|
4
6
|
import { WalletError } from './WalletError.js';
|
|
5
7
|
export interface ProvingService<TTransaction> {
|
|
6
|
-
prove(
|
|
8
|
+
prove(transaction: ledger.UnprovenTransaction): Effect.Effect<TTransaction, WalletError>;
|
|
7
9
|
}
|
|
8
|
-
export
|
|
10
|
+
export declare const makeProvingService: (clientLayer: Layer.Layer<ProverClient.ProverClient, InvalidProtocolSchemeError>) => ProvingService<ledger.FinalizedTransaction>;
|
|
11
|
+
export type WasmProvingConfiguration = {
|
|
12
|
+
keyMaterialProvider?: KeyMaterialProvider;
|
|
13
|
+
};
|
|
14
|
+
export type ProvingServerConfiguration = {
|
|
9
15
|
provingServerUrl: URL;
|
|
10
16
|
};
|
|
17
|
+
export type DefaultProvingConfiguration = ProvingServerConfiguration;
|
|
11
18
|
export declare const makeDefaultProvingService: (configuration: DefaultProvingConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
19
|
+
export declare const makeServerProvingService: (configuration: ProvingServerConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
20
|
+
export declare const makeWasmProvingService: (configuration: WasmProvingConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
12
21
|
export declare const makeSimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction>;
|
package/dist/v1/Proving.js
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) 2025 Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
14
|
+
import { HttpProverClient, WasmProver, ProverClient } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
3
15
|
import { Effect, pipe } from 'effect';
|
|
4
16
|
import { ProvingError } from './WalletError.js';
|
|
5
|
-
export const
|
|
6
|
-
const clientLayer = HttpProverClient.layer({
|
|
7
|
-
url: configuration.provingServerUrl,
|
|
8
|
-
});
|
|
17
|
+
export const makeProvingService = (clientLayer) => {
|
|
9
18
|
return {
|
|
10
|
-
prove(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
cause: error,
|
|
16
|
-
}))));
|
|
17
|
-
case 'TransactionToProve':
|
|
18
|
-
return pipe(ProverClient.ProverClient, Effect.flatMap((client) => client.proveTransaction(recipe.transaction, ledger.CostModel.initialCostModel())), Effect.map((proven) => proven.bind()), Effect.provide(clientLayer), Effect.catchAll((error) => Effect.fail(new ProvingError({
|
|
19
|
-
message: error.message,
|
|
20
|
-
cause: error,
|
|
21
|
-
}))));
|
|
22
|
-
case 'NothingToProve':
|
|
23
|
-
return Effect.succeed(recipe.transaction);
|
|
24
|
-
}
|
|
19
|
+
prove(transaction) {
|
|
20
|
+
return pipe(ProverClient.ProverClient, Effect.flatMap((client) => client.proveTransaction(transaction, ledger.CostModel.initialCostModel())), Effect.map((transaction) => transaction.bind()), Effect.provide(clientLayer), Effect.catchAll((error) => Effect.fail(new ProvingError({
|
|
21
|
+
message: error.message,
|
|
22
|
+
cause: error,
|
|
23
|
+
}))));
|
|
25
24
|
},
|
|
26
25
|
};
|
|
27
26
|
};
|
|
27
|
+
export const makeDefaultProvingService = (configuration) => makeServerProvingService(configuration);
|
|
28
|
+
export const makeServerProvingService = (configuration) => {
|
|
29
|
+
const clientLayer = HttpProverClient.layer({
|
|
30
|
+
url: configuration.provingServerUrl,
|
|
31
|
+
});
|
|
32
|
+
return makeProvingService(clientLayer);
|
|
33
|
+
};
|
|
34
|
+
export const makeWasmProvingService = (configuration) => {
|
|
35
|
+
const proverLayer = WasmProver.layer({
|
|
36
|
+
keyMaterialProvider: configuration.keyMaterialProvider ?? WasmProver.makeDefaultKeyMaterialProvider(),
|
|
37
|
+
});
|
|
38
|
+
return makeProvingService(proverLayer);
|
|
39
|
+
};
|
|
28
40
|
export const makeSimulatorProvingService = () => {
|
|
29
41
|
return {
|
|
30
|
-
prove(
|
|
31
|
-
|
|
32
|
-
case 'BalanceTransactionToProve':
|
|
33
|
-
return pipe(Effect.succeed(recipe.transactionToProve.eraseProofs()), Effect.map((proven) => recipe.transactionToBalance.merge(proven)));
|
|
34
|
-
case 'TransactionToProve':
|
|
35
|
-
return Effect.succeed(recipe.transaction.eraseProofs());
|
|
36
|
-
case 'NothingToProve':
|
|
37
|
-
return Effect.succeed(recipe.transaction);
|
|
38
|
-
}
|
|
42
|
+
prove(transaction) {
|
|
43
|
+
return Effect.succeed(transaction.eraseProofs());
|
|
39
44
|
},
|
|
40
45
|
};
|
|
41
46
|
};
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
1
|
+
import type * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
2
|
import { Effect, Scope, Stream } from 'effect';
|
|
3
|
-
import { WalletRuntimeError, Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
4
|
-
import { ProvingService } from './Proving.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { CoreWallet } from './CoreWallet.js';
|
|
15
|
-
import { TransactionHistoryCapability } from './TransactionHistory.js';
|
|
3
|
+
import { type WalletRuntimeError, type Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
4
|
+
import { type ProvingService } from './Proving.js';
|
|
5
|
+
import { type SerializationCapability } from './Serialization.js';
|
|
6
|
+
import { type EventsSyncUpdate, type SyncCapability, type SyncService } from './Sync.js';
|
|
7
|
+
import { type TransactingCapability, type TokenTransfer, type BalancingResult } from './Transacting.js';
|
|
8
|
+
import { type WalletError } from './WalletError.js';
|
|
9
|
+
import { type CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
10
|
+
import { type KeysCapability } from './Keys.js';
|
|
11
|
+
import { type CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
12
|
+
import { type CoreWallet } from './CoreWallet.js';
|
|
13
|
+
import { type TransactionHistoryCapability } from './TransactionHistory.js';
|
|
16
14
|
export declare namespace RunningV1Variant {
|
|
17
15
|
type Context<TSerialized, TSyncUpdate, TTransaction, TStartAux> = {
|
|
18
16
|
serializationCapability: SerializationCapability<CoreWallet, null, TSerialized>;
|
|
@@ -22,7 +20,6 @@ export declare namespace RunningV1Variant {
|
|
|
22
20
|
provingService: ProvingService<TTransaction>;
|
|
23
21
|
coinsAndBalancesCapability: CoinsAndBalancesCapability<CoreWallet>;
|
|
24
22
|
keysCapability: KeysCapability<CoreWallet>;
|
|
25
|
-
submissionService: SubmissionService<TTransaction>;
|
|
26
23
|
coinSelection: CoinSelection<ledger.QualifiedShieldedCoinInfo>;
|
|
27
24
|
transactionHistoryCapability: TransactionHistoryCapability<CoreWallet, TTransaction>;
|
|
28
25
|
};
|
|
@@ -37,10 +34,10 @@ export declare class RunningV1Variant<TSerialized, TSyncUpdate, TTransaction, TS
|
|
|
37
34
|
constructor(scope: Scope.Scope, context: Variant.VariantContext<CoreWallet>, v1Context: RunningV1Variant.Context<TSerialized, TSyncUpdate, TTransaction, TStartAux>);
|
|
38
35
|
startSyncInBackground(startAux: TStartAux): Effect.Effect<void>;
|
|
39
36
|
startSync(startAux: TStartAux): Stream.Stream<void, WalletError, Scope.Scope>;
|
|
40
|
-
balanceTransaction(secretKeys: ledger.ZswapSecretKeys, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Effect.Effect<
|
|
41
|
-
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: ReadonlyArray<TokenTransfer>): Effect.Effect<
|
|
42
|
-
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: ReadonlyArray<TokenTransfer>): Effect.Effect<
|
|
43
|
-
finalizeTransaction(
|
|
44
|
-
|
|
37
|
+
balanceTransaction(secretKeys: ledger.ZswapSecretKeys, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Effect.Effect<BalancingResult, WalletError>;
|
|
38
|
+
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: ReadonlyArray<TokenTransfer>): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
39
|
+
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: ReadonlyArray<TokenTransfer>): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
40
|
+
finalizeTransaction(transaction: ledger.UnprovenTransaction): Effect.Effect<TTransaction, WalletError>;
|
|
41
|
+
revertTransaction(transaction: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Effect.Effect<void, WalletError>;
|
|
45
42
|
serializeState(state: CoreWallet): TSerialized;
|
|
46
43
|
}
|