@midnight-ntwrk/wallet-sdk-shielded 2.0.0 → 2.1.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.
@@ -1,6 +1,6 @@
1
1
  import { type ProtocolState, ProtocolVersion, SyncProgress } from '@midnight-ntwrk/wallet-sdk-abstractions';
2
2
  import { type BaseV1Configuration, type DefaultV1Configuration, type V1Variant, CoreWallet } from './v1/index.js';
3
- import * as ledger from '@midnight-ntwrk/ledger-v7';
3
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
4
4
  import * as rx from 'rxjs';
5
5
  import { type BalancingResult } from './v1/Transacting.js';
6
6
  import { type SerializationCapability } from './v1/Serialization.js';
@@ -12,7 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
14
14
  import { V1Builder, V1Tag, CoreWallet, } from './v1/index.js';
15
- import * as ledger from '@midnight-ntwrk/ledger-v7';
15
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
16
16
  import { Effect, Either } from 'effect';
17
17
  import * as rx from 'rxjs';
18
18
  import { WalletBuilder } from '@midnight-ntwrk/wallet-sdk-runtime';
@@ -1,5 +1,5 @@
1
1
  import { CoreWallet } from './CoreWallet.js';
2
- import * as ledger from '@midnight-ntwrk/ledger-v7';
2
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
3
3
  export type AvailableCoin = {
4
4
  coin: ledger.QualifiedShieldedCoinInfo;
5
5
  commitment: ledger.CoinCommitment;
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { ProtocolVersion, SyncProgress } from '@midnight-ntwrk/wallet-sdk-abstractions';
3
3
  import { Either } from 'effect';
4
4
  import { WalletError } from './WalletError.js';
@@ -40,7 +40,7 @@ export declare const CoreWallet: {
40
40
  replayEvents(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, events: ledger.Event[]): CoreWallet;
41
41
  updateProgress(wallet: CoreWallet, { appliedIndex, highestRelevantWalletIndex, highestIndex, highestRelevantIndex, isConnected, }: Partial<SyncProgress.SyncProgressData>): CoreWallet;
42
42
  addTransaction(wallet: CoreWallet, _tx: ledger.FinalizedTransaction): CoreWallet;
43
- revertTransaction<TTx extends ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>>(wallet: CoreWallet, _tx: TTx): CoreWallet;
43
+ revertTransaction<TTx extends ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>>(wallet: CoreWallet, tx: TTx): CoreWallet;
44
44
  updateTxHistory(wallet: CoreWallet, _newTxs: readonly ledger.FinalizedTransaction[]): CoreWallet;
45
45
  spendCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.QualifiedShieldedCoinInfo>, segment: number): [ReadonlyArray<ledger.ZswapOffer<ledger.PreProof>>, CoreWallet];
46
46
  watchCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.ShieldedCoinInfo>): CoreWallet;
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import * as ledger from '@midnight-ntwrk/ledger-v7';
13
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
14
14
  import { ProtocolVersion, SyncProgress } from '@midnight-ntwrk/wallet-sdk-abstractions';
15
15
  import { Either, Iterable, pipe, Record, Array as Arr } from 'effect';
16
16
  import { InvalidCoinHashesError } from './WalletError.js';
@@ -126,8 +126,9 @@ export const CoreWallet = {
126
126
  return wallet;
127
127
  },
128
128
  /* not implemented until this is done https://shielded.atlassian.net/browse/PM-19678 */
129
- revertTransaction(wallet, _tx) {
130
- return wallet;
129
+ revertTransaction(wallet, tx) {
130
+ const newState = wallet.state.revertTransaction(tx);
131
+ return { ...wallet, state: newState };
131
132
  },
132
133
  // TODO: Remove after tx history is implemented
133
134
  updateTxHistory(wallet, _newTxs) {
@@ -1,4 +1,4 @@
1
- import type * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import type * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { Effect, Scope, Stream } from 'effect';
3
3
  import { type WalletRuntimeError, type Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
4
4
  import { type SerializationCapability } from './Serialization.js';
@@ -12,7 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { Effect, ParseResult, Either, pipe, Schema } from 'effect';
14
14
  import { WalletError } from './WalletError.js';
15
- import * as ledger from '@midnight-ntwrk/ledger-v7';
15
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
16
16
  import { CoreWallet } from './CoreWallet.js';
17
17
  const StateSchema = Schema.declare((input) => input instanceof ledger.ZswapLocalState).annotations({
18
18
  identifier: 'ledger.ZswapLocalState',
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { Array as Arr, Effect, type Scope, Stream, SubscriptionRef } from 'effect';
3
3
  export type SimulatorState = Readonly<{
4
4
  ledger: ledger.LedgerState;
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import * as ledger from '@midnight-ntwrk/ledger-v7';
13
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
14
14
  import { Array as Arr, Effect, Encoding, pipe, Stream, SubscriptionRef, Clock } from 'effect';
15
15
  import { ArrayOps, EitherOps } from '@midnight-ntwrk/wallet-sdk-utilities';
16
16
  import * as crypto from 'crypto';
@@ -33,6 +33,7 @@ export class Simulator {
33
33
  parentBlockHash: hash,
34
34
  secondsSinceEpoch: number,
35
35
  secondsSinceEpochErr: 1,
36
+ lastBlockTime: 1n,
36
37
  })));
37
38
  static init(genesisMints) {
38
39
  const emptyState = ledger.LedgerState.blank(NetworkId.NetworkId.Undeployed);
package/dist/v1/Sync.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { Schema, Scope, Stream } from 'effect';
3
3
  import { CoreWallet } from './CoreWallet.js';
4
4
  import { Simulator, SimulatorState } from './Simulator.js';
@@ -22,13 +22,13 @@ export type DefaultSyncConfiguration = {
22
22
  export type DefaultSyncContext = {
23
23
  transactionHistoryCapability: TransactionHistoryCapability<CoreWallet, ledger.FinalizedTransaction>;
24
24
  };
25
- type SecretKeysResource = <A>(cb: (keys: ledger.ZswapSecretKeys) => A) => A;
25
+ export type SecretKeysResource = <A>(cb: (keys: ledger.ZswapSecretKeys) => A) => A;
26
26
  export declare const SecretKeysResource: {
27
27
  create: (secretKeys: ledger.ZswapSecretKeys) => SecretKeysResource;
28
28
  };
29
29
  export type WalletSyncUpdate = {
30
30
  updates: EventsSyncUpdate[];
31
- secretKeys: SecretKeysResource;
31
+ secretKeys: ledger.ZswapSecretKeys;
32
32
  };
33
33
  export declare const WalletSyncUpdate: {
34
34
  create: (updates: EventsSyncUpdate[], secretKeys: ledger.ZswapSecretKeys) => WalletSyncUpdate;
@@ -50,4 +50,3 @@ export type SimulatorSyncUpdate = {
50
50
  };
51
51
  export declare const makeSimulatorSyncService: (config: SimulatorSyncConfiguration) => SyncService<CoreWallet, ledger.ZswapSecretKeys, SimulatorSyncUpdate>;
52
52
  export declare const makeSimulatorSyncCapability: () => SyncCapability<CoreWallet, SimulatorSyncUpdate>;
53
- export {};
package/dist/v1/Sync.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import * as ledger from '@midnight-ntwrk/ledger-v7';
13
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
14
14
  import { Chunk, Duration, Effect, Either, ParseResult, pipe, Schedule, Schema, Stream } from 'effect';
15
15
  import { CoreWallet } from './CoreWallet.js';
16
16
  import { ZswapEvents } from '@midnight-ntwrk/wallet-sdk-indexer-client';
@@ -23,17 +23,9 @@ const Uint8ArraySchema = Schema.declare((input) => input instanceof Uint8Array).
23
23
  });
24
24
  export const SecretKeysResource = {
25
25
  create: (secretKeys) => {
26
- /**
27
- * TODO: future Ledger version will include `clear` function to clear the secret keys,
28
- * it is intentend to be used here instead of `null`
29
- */
30
- let sk = secretKeys;
31
26
  return (cb) => {
32
- if (sk === null) {
33
- throw new Error('Secret keys have been consumed');
34
- }
35
- const result = cb(sk);
36
- sk = null;
27
+ const result = cb(secretKeys);
28
+ secretKeys.clear();
37
29
  return result;
38
30
  };
39
31
  },
@@ -42,7 +34,7 @@ export const WalletSyncUpdate = {
42
34
  create: (updates, secretKeys) => {
43
35
  return {
44
36
  updates,
45
- secretKeys: SecretKeysResource.create(secretKeys),
37
+ secretKeys,
46
38
  };
47
39
  },
48
40
  };
@@ -119,12 +111,10 @@ export const makeEventsSyncCapability = () => {
119
111
  isConnected: true,
120
112
  });
121
113
  }
122
- return wrappedUpdate.secretKeys((keys) => {
123
- return CoreWallet.updateProgress(CoreWallet.replayEvents(state, keys, wrappedUpdate.updates.map((u) => u.event)), {
124
- highestRelevantWalletIndex,
125
- appliedIndex: nextIndex,
126
- isConnected: true,
127
- });
114
+ return CoreWallet.updateProgress(CoreWallet.replayEvents(state, wrappedUpdate.secretKeys, wrappedUpdate.updates.map((u) => u.event)), {
115
+ highestRelevantWalletIndex,
116
+ appliedIndex: nextIndex,
117
+ isConnected: true,
128
118
  });
129
119
  },
130
120
  };
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
3
3
  import { Array as Arr, Either } from 'effect';
4
4
  import { CoreWallet } from './CoreWallet.js';
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import * as ledger from '@midnight-ntwrk/ledger-v7';
13
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
14
14
  import { Array as Arr, Either, Option, pipe, Record } from 'effect';
15
15
  import { ArrayOps } from '@midnight-ntwrk/wallet-sdk-utilities';
16
16
  import { CoreWallet } from './CoreWallet.js';
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { CoreWallet } from './CoreWallet.js';
3
3
  export type TransactionHistoryCapability<TState, TTransaction> = {
4
4
  updateTxHistory(state: TState, newTxs: TTransaction[]): TState;
@@ -1,6 +1,6 @@
1
1
  import { Imbalances } from '@midnight-ntwrk/wallet-sdk-capabilities';
2
2
  import { TransactionImbalances } from './TransactionImbalances.js';
3
- import * as ledger from '@midnight-ntwrk/ledger-v7';
3
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
4
4
  export type TransactionOps<Tx> = {
5
5
  getImbalances(tx: Tx): TransactionImbalances;
6
6
  id(tx: Tx): string;
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { type Either, type Types } from 'effect';
3
3
  import { type NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
4
4
  import { type Variant, type VariantBuilder } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import * as ledger from '@midnight-ntwrk/ledger-v7';
13
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
14
14
  import { Effect, Scope } from 'effect';
15
15
  import { WalletSeed } from '@midnight-ntwrk/wallet-sdk-abstractions';
16
16
  import { RunningV1Variant, V1Tag } from './RunningV1Variant.js';
@@ -1,4 +1,4 @@
1
- import * as ledger from '@midnight-ntwrk/ledger-v7';
1
+ import * as ledger from '@midnight-ntwrk/ledger-v8';
2
2
  import { LedgerOps } from '@midnight-ntwrk/wallet-sdk-utilities';
3
3
  export declare const WalletError: {
4
4
  other(err: unknown): WalletError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-shielded",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -28,13 +28,13 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@midnight-ntwrk/ledger-v7": "^7.0.2",
31
+ "@midnight-ntwrk/ledger-v8": "^8.0.2",
32
32
  "@midnight-ntwrk/wallet-sdk-abstractions": "2.0.0",
33
- "@midnight-ntwrk/wallet-sdk-address-format": "3.0.1",
34
- "@midnight-ntwrk/wallet-sdk-capabilities": "3.1.0",
35
- "@midnight-ntwrk/wallet-sdk-indexer-client": "1.1.0",
36
- "@midnight-ntwrk/wallet-sdk-runtime": "1.0.1",
37
- "@midnight-ntwrk/wallet-sdk-utilities": "1.0.1",
33
+ "@midnight-ntwrk/wallet-sdk-address-format": "3.1.0",
34
+ "@midnight-ntwrk/wallet-sdk-capabilities": "3.2.0",
35
+ "@midnight-ntwrk/wallet-sdk-indexer-client": "1.2.0",
36
+ "@midnight-ntwrk/wallet-sdk-runtime": "1.0.2",
37
+ "@midnight-ntwrk/wallet-sdk-utilities": "1.1.0",
38
38
  "effect": "^3.19.19",
39
39
  "rxjs": "^7.8.2"
40
40
  },