@midnight-ntwrk/wallet-sdk-runtime 1.0.4 → 1.0.5

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,3 +1,10 @@
1
+ > [!IMPORTANT]
2
+ > **This package has moved.** The `@midnight-ntwrk` scope is published only
3
+ > during the migration window and will stop receiving updates. Please migrate to
4
+ > [`@midnightntwrk/wallet-sdk-runtime`](https://www.npmjs.com/package/@midnightntwrk/wallet-sdk-runtime).
5
+
6
+ ---
7
+
1
8
  # @midnight-ntwrk/wallet-sdk-runtime
2
9
 
3
10
  Runtime infrastructure for Midnight wallet variants.
package/dist/Runtime.js CHANGED
@@ -33,17 +33,25 @@ export const init = (initArgs) => {
33
33
  return runVariantStream(initiatedFirstVariant, currentStateRef, progressRef, currentVariantRef).pipe(Effect.catchAll((error) => {
34
34
  return SubscriptionRef.set(currentStateRef, Either.left(error));
35
35
  }), Effect.forkScoped);
36
- }), Effect.flatMap(({ currentStateRef, progressRef, currentVariantRef }) => {
37
- return Effect.gen(function* () {
38
- const changesStream = yield* currentStateRef.changes.pipe(Stream.mapEffect((value) => EitherOps.toEffect(value)), Stream.share({ capacity: 'unbounded', replay: 1 }));
39
- const runtime = {
40
- stateChanges: changesStream,
41
- progress: progressRef.get,
42
- currentVariant: currentVariantRef.get,
43
- dispatch: (impl) => dispatch(runtime, impl),
44
- };
45
- return runtime;
46
- });
36
+ }), Effect.map(({ currentStateRef, progressRef, currentVariantRef }) => {
37
+ // Latest-value semantics with bounded memory: each subscriber gets the current state on
38
+ // subscription (SubscriptionRef.changes emits it atomically with subsequent changes) and
39
+ // may skip intermediate states when it lags behind the producer — the sliding buffer of
40
+ // capacity 1 keeps only the latest state, so past state instances (which hold wasm
41
+ // resources) can be released.
42
+ //
43
+ // Deliberately NOT Stream.share with `replay`: Effect's PubSub replay buffer (up to and
44
+ // including effect 3.21.3) appends every published value to a shared linked list, and a
45
+ // subscription's ReplayWindowImpl never releases its head node after the replay window is
46
+ // exhausted — any long-lived subscriber pins every state published during its lifetime.
47
+ const changesStream = currentStateRef.changes.pipe(Stream.mapEffect((value) => EitherOps.toEffect(value)), Stream.buffer({ capacity: 1, strategy: 'sliding' }));
48
+ const runtime = {
49
+ stateChanges: changesStream,
50
+ progress: progressRef.get,
51
+ currentVariant: currentVariantRef.get,
52
+ dispatch: (impl) => dispatch(runtime, impl),
53
+ };
54
+ return runtime;
47
55
  }));
48
56
  };
49
57
  export const dispatch = (runtime, impl) => {
@@ -1,5 +1,5 @@
1
- import { type ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
2
- import { Chunk } from 'effect';
1
+ import { ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
2
+ import { Chunk, Equivalence } from 'effect';
3
3
  import { type Observable, type OperatorFunction } from 'rxjs';
4
4
  /**
5
5
  * Utility function that takes state values from an RxJS observable until it completes or errors.
@@ -11,4 +11,22 @@ import { type Observable, type OperatorFunction } from 'rxjs';
11
11
  */
12
12
  export declare const toProtocolStateArray: <T>(observable: Observable<ProtocolState.ProtocolState<T>>, onErrCallback?: (err: unknown) => void) => Promise<ProtocolState.ProtocolState<T>[]>;
13
13
  export declare const reduceToChunk: <T>() => OperatorFunction<T, Chunk.Chunk<T>>;
14
+ /**
15
+ * Checks whether `received` is an ordered subsequence of `expected` — every received element appears in `expected` in
16
+ * the same relative order, though elements of `expected` may be skipped.
17
+ *
18
+ * This matches the runtime's latest-value state stream contract: a subscriber always converges on the latest state, but
19
+ * may skip intermediate states when it lags behind the producer. Received states must therefore never be reordered,
20
+ * fabricated, or repeated out of order — but any prefix of intermediate states may be missing.
21
+ *
22
+ * @internal
23
+ */
24
+ export declare const isOrderedSubsequenceOf: <T>(received: readonly T[], expected: readonly T[], equals: Equivalence.Equivalence<T>) => boolean;
25
+ /**
26
+ * Equality of {@link ProtocolState.ProtocolState} values over primitive states, for use with
27
+ * {@link isOrderedSubsequenceOf}.
28
+ *
29
+ * @internal
30
+ */
31
+ export declare const protocolStateEquals: Equivalence.Equivalence<ProtocolState.ProtocolState<unknown>>;
14
32
  export declare const isRange: (values: Chunk.Chunk<number>) => boolean;
@@ -1,4 +1,17 @@
1
- import { Chunk } from 'effect';
1
+ // This file is part of MIDNIGHT-WALLET-SDK.
2
+ // Copyright (C) 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 { ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
14
+ import { Chunk, Equivalence } from 'effect';
2
15
  import { reduce } from 'rxjs';
3
16
  /**
4
17
  * Utility function that takes state values from an RxJS observable until it completes or errors.
@@ -24,6 +37,33 @@ export const toProtocolStateArray = (observable, onErrCallback) => new Promise((
24
37
  });
25
38
  });
26
39
  export const reduceToChunk = () => reduce((chunk, value) => Chunk.append(chunk, value), Chunk.empty());
40
+ /**
41
+ * Checks whether `received` is an ordered subsequence of `expected` — every received element appears in `expected` in
42
+ * the same relative order, though elements of `expected` may be skipped.
43
+ *
44
+ * This matches the runtime's latest-value state stream contract: a subscriber always converges on the latest state, but
45
+ * may skip intermediate states when it lags behind the producer. Received states must therefore never be reordered,
46
+ * fabricated, or repeated out of order — but any prefix of intermediate states may be missing.
47
+ *
48
+ * @internal
49
+ */
50
+ export const isOrderedSubsequenceOf = (received, expected, equals) => {
51
+ const searchEnd = received.reduce((searchFrom, value) => {
52
+ if (searchFrom < 0) {
53
+ return searchFrom;
54
+ }
55
+ const index = expected.findIndex((candidate, i) => i >= searchFrom && equals(candidate, value));
56
+ return index < 0 ? -1 : index + 1;
57
+ }, 0);
58
+ return searchEnd >= 0;
59
+ };
60
+ /**
61
+ * Equality of {@link ProtocolState.ProtocolState} values over primitive states, for use with
62
+ * {@link isOrderedSubsequenceOf}.
63
+ *
64
+ * @internal
65
+ */
66
+ export const protocolStateEquals = ProtocolState.getEquivalence(Equivalence.strict());
27
67
  export const isRange = (values) => {
28
68
  const firstDropped = Chunk.drop(values, 1);
29
69
  const lastDropped = Chunk.dropRight(values, 1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-runtime",
3
3
  "description": "Runtime for the wallet variants",
4
- "version": "1.0.4",
4
+ "version": "1.0.5",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -9,14 +9,16 @@
9
9
  "author": "Midnight Foundation",
10
10
  "license": "Apache-2.0",
11
11
  "publishConfig": {
12
- "registry": "https://npm.pkg.github.com/"
12
+ "registry": "https://registry.npmjs.org/",
13
+ "access": "public"
13
14
  },
14
15
  "files": [
15
16
  "dist/"
16
17
  ],
17
18
  "repository": {
18
19
  "type": "git",
19
- "url": "git+https://github.com/midnight-ntwrk/artifacts.git"
20
+ "url": "git+https://github.com/midnightntwrk/midnight-wallet.git",
21
+ "directory": "packages/runtime"
20
22
  },
21
23
  "exports": {
22
24
  ".": {