@midnightntwrk/wallet-sdk-abstractions 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.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @midnightntwrk/wallet-sdk-abstractions
2
+
3
+ Domain-specific abstractions for the Midnight Wallet SDK.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @midnightntwrk/wallet-sdk-abstractions
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ This package provides core types and interfaces used throughout the Midnight Wallet SDK. It defines the fundamental
14
+ abstractions for:
15
+
16
+ - Network identification
17
+ - Protocol state and versioning
18
+ - Wallet seeds and state management
19
+ - Transaction serialization
20
+
21
+ ## Exports
22
+
23
+ ### NetworkId
24
+
25
+ Network identifier types for distinguishing between different Midnight networks (e.g., mainnet, testnet).
26
+
27
+ ### ProtocolState
28
+
29
+ Types representing the current state of the Midnight protocol.
30
+
31
+ ### ProtocolVersion
32
+
33
+ Version information for protocol compatibility.
34
+
35
+ ### WalletSeed
36
+
37
+ Abstractions for wallet seed management and derivation.
38
+
39
+ ### WalletState
40
+
41
+ Types representing the internal state of a wallet instance.
42
+
43
+ ### SerializedTransaction
44
+
45
+ Types for serialized transaction data that can be stored or transmitted.
46
+
47
+ ### SerializedUnprovenTransaction
48
+
49
+ Types for unproven transaction serialization before ZK proofs are generated.
50
+
51
+ ## License
52
+
53
+ Apache-2.0
@@ -0,0 +1,27 @@
1
+ import { Schema } from 'effect';
2
+ import { type TransactionHistoryStorage, type TransactionHash, type TransactionHistoryCommon, type SerializedTransactionHistory } from './TransactionHistoryStorage.js';
3
+ /**
4
+ * In-memory implementation of the TransactionHistoryStorage interface.
5
+ *
6
+ * An optional `merge` function can be provided to control how existing and incoming entries are combined during
7
+ * {@link upsert}. When omitted the default behaviour is a shallow spread (`{ ...existing, ...incoming }`).
8
+ *
9
+ * Because the merge runs **synchronously** inside `upsert`, the single-threaded nature of JavaScript guarantees
10
+ * atomicity — no external semaphore is needed.
11
+ */
12
+ export declare class InMemoryTransactionHistoryStorage<T extends {
13
+ hash: TransactionHash;
14
+ } = TransactionHistoryCommon, I = T> implements TransactionHistoryStorage<T> {
15
+ private storage;
16
+ private readonly schema;
17
+ private readonly merge;
18
+ constructor(schema: Schema.Schema<T, I>, merge?: (existing: T, incoming: T) => T);
19
+ upsert(entry: T): Promise<void>;
20
+ getAll(): Promise<readonly T[]>;
21
+ get(hash: TransactionHash): Promise<T | undefined>;
22
+ reset(): void;
23
+ serialize(): Promise<SerializedTransactionHistory>;
24
+ static restore<T extends {
25
+ hash: string;
26
+ }, I>(serialized: SerializedTransactionHistory, schema: Schema.Schema<T, I>, merge?: (existing: T, incoming: T) => T): InMemoryTransactionHistoryStorage<T, I>;
27
+ }
@@ -0,0 +1,60 @@
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 { Schema } from 'effect';
14
+ /**
15
+ * In-memory implementation of the TransactionHistoryStorage interface.
16
+ *
17
+ * An optional `merge` function can be provided to control how existing and incoming entries are combined during
18
+ * {@link upsert}. When omitted the default behaviour is a shallow spread (`{ ...existing, ...incoming }`).
19
+ *
20
+ * Because the merge runs **synchronously** inside `upsert`, the single-threaded nature of JavaScript guarantees
21
+ * atomicity — no external semaphore is needed.
22
+ */
23
+ export class InMemoryTransactionHistoryStorage {
24
+ storage;
25
+ schema;
26
+ merge;
27
+ constructor(schema, merge) {
28
+ this.storage = new Map();
29
+ this.schema = schema;
30
+ this.merge = merge ?? ((existing, incoming) => ({ ...existing, ...incoming }));
31
+ }
32
+ upsert(entry) {
33
+ const existing = this.storage.get(entry.hash);
34
+ this.storage.set(entry.hash, existing ? this.merge(existing, entry) : entry);
35
+ return Promise.resolve();
36
+ }
37
+ getAll() {
38
+ return Array.fromAsync(this.storage.values());
39
+ }
40
+ get(hash) {
41
+ return Promise.resolve(this.storage.get(hash));
42
+ }
43
+ reset() {
44
+ this.storage.clear();
45
+ }
46
+ async serialize() {
47
+ const allEntries = await this.getAll();
48
+ const encode = Schema.encodeSync(Schema.Array(this.schema));
49
+ return JSON.stringify(encode([...allEntries]));
50
+ }
51
+ static restore(serialized, schema, merge) {
52
+ const decode = Schema.decodeUnknownSync(Schema.Array(schema));
53
+ const decoded = decode(JSON.parse(serialized));
54
+ const storage = new InMemoryTransactionHistoryStorage(schema, merge);
55
+ for (const entry of decoded) {
56
+ storage.storage.set(entry.hash, entry);
57
+ }
58
+ return storage;
59
+ }
60
+ }
@@ -0,0 +1,11 @@
1
+ export declare const NetworkId: {
2
+ readonly MainNet: "mainnet";
3
+ readonly TestNet: "testnet";
4
+ readonly DevNet: "devnet";
5
+ readonly QaNet: "qanet";
6
+ readonly Undeployed: "undeployed";
7
+ readonly Preview: "preview";
8
+ readonly PreProd: "preprod";
9
+ };
10
+ export type WellKnownNetworkId = (typeof NetworkId)[keyof typeof NetworkId];
11
+ export type NetworkId = WellKnownNetworkId | string;
@@ -0,0 +1,21 @@
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
+ export const NetworkId = {
14
+ MainNet: 'mainnet',
15
+ TestNet: 'testnet',
16
+ DevNet: 'devnet',
17
+ QaNet: 'qanet',
18
+ Undeployed: 'undeployed',
19
+ Preview: 'preview',
20
+ PreProd: 'preprod',
21
+ };
@@ -0,0 +1,9 @@
1
+ import { type TransactionHistoryStorage, type TransactionHash, type TransactionHistoryCommon, type SerializedTransactionHistory } from './TransactionHistoryStorage.js';
2
+ export declare class NoOpTransactionHistoryStorage<T extends {
3
+ hash: TransactionHash;
4
+ } = TransactionHistoryCommon> implements TransactionHistoryStorage<T> {
5
+ upsert(_entry: T): Promise<void>;
6
+ getAll(): Promise<readonly T[]>;
7
+ get(_hash: TransactionHash): Promise<T | undefined>;
8
+ serialize(): Promise<SerializedTransactionHistory>;
9
+ }
@@ -0,0 +1,14 @@
1
+ export class NoOpTransactionHistoryStorage {
2
+ upsert(_entry) {
3
+ return Promise.resolve();
4
+ }
5
+ getAll() {
6
+ return Promise.resolve([]);
7
+ }
8
+ get(_hash) {
9
+ return Promise.resolve(undefined);
10
+ }
11
+ serialize() {
12
+ return Promise.resolve('[]');
13
+ }
14
+ }
@@ -0,0 +1,20 @@
1
+ import { Equivalence } from 'effect';
2
+ import type * as ProtocolVersion from './ProtocolVersion.js';
3
+ /**
4
+ * A type that associates some state with a given version of the Midnight protocol.
5
+ *
6
+ * @typeParam TState The type of state.
7
+ */
8
+ export type ProtocolState<TState> = Readonly<{
9
+ version: ProtocolVersion.ProtocolVersion;
10
+ state: TState;
11
+ }>;
12
+ export declare const state: <TState>(ps: ProtocolState<TState>) => TState;
13
+ /**
14
+ * Derives an {@link Equivalence.Equivalence} for {@link ProtocolState} values from an equivalence of the underlying
15
+ * state. Versions are compared strictly.
16
+ *
17
+ * @param stateEquivalence The equivalence used to compare the `state` field.
18
+ * @returns An equivalence over `ProtocolState<TState>`.
19
+ */
20
+ export declare const getEquivalence: <TState>(stateEquivalence: Equivalence.Equivalence<TState>) => Equivalence.Equivalence<ProtocolState<TState>>;
@@ -0,0 +1,25 @@
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 { Equivalence } from 'effect';
14
+ export const state = (ps) => ps.state;
15
+ /**
16
+ * Derives an {@link Equivalence.Equivalence} for {@link ProtocolState} values from an equivalence of the underlying
17
+ * state. Versions are compared strictly.
18
+ *
19
+ * @param stateEquivalence The equivalence used to compare the `state` field.
20
+ * @returns An equivalence over `ProtocolState<TState>`.
21
+ */
22
+ export const getEquivalence = (stateEquivalence) => Equivalence.struct({
23
+ version: Equivalence.strict(),
24
+ state: stateEquivalence,
25
+ });
@@ -0,0 +1,40 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as Schema from 'effect/Schema';
3
+ /** A branded `bigint` that represents a protocol version. */
4
+ export type ProtocolVersion = Brand.Branded<bigint, 'ProtocolVersion'>;
5
+ /** Constructs a branded `bigint` represents a protocol version. */
6
+ export declare const ProtocolVersion: Brand.Brand.Constructor<ProtocolVersion>;
7
+ export declare namespace ProtocolVersion {
8
+ /** A tuple type that represents a start and ending protocol version. */
9
+ type Range = readonly [start: ProtocolVersion, end: ProtocolVersion];
10
+ }
11
+ /**
12
+ * Creates a new protocol version range.
13
+ *
14
+ * @param start The start value.
15
+ * @param end The end value.
16
+ * @returns A {@link ProtocolVersion.Range} defined by `start` and `end`.
17
+ * @throws `TypeError` Thrown when `start` is after `end`, or the difference between them is less than one.
18
+ */
19
+ export declare const makeRange: (start: ProtocolVersion, end: ProtocolVersion) => ProtocolVersion.Range;
20
+ /**
21
+ * Determines if a given protocol version is within a given range.
22
+ *
23
+ * @param version The version to test.
24
+ * @param range The {@link ProtocolVersion.Range} to test `version` against.
25
+ * @returns `true` if `version` is within the range defined by `range`.
26
+ */
27
+ export declare const withinRange: (version: ProtocolVersion, range: ProtocolVersion.Range) => boolean;
28
+ /** A schema that transforms a `bigint` into a {@link ProtocolVersion}. */
29
+ export declare const ProtocolVersionSchema: Schema.BrandSchema<bigint & Brand.Brand<"ProtocolVersion">, string, never>;
30
+ /**
31
+ * A type predicate that determines if a given value is a {@link ProtocolVersion}.
32
+ *
33
+ * @param u The value to test.
34
+ * @returns `true` if `u` has the type {@link ProtocolVersion}.
35
+ */
36
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is bigint & Brand.Brand<"ProtocolVersion">;
37
+ /** Represents the minimum supported protocol version. */
38
+ export declare const MinSupportedVersion: ProtocolVersion;
39
+ /** Represents the maximum supported protocol version. */
40
+ export declare const MaxSupportedVersion: ProtocolVersion;
@@ -0,0 +1,54 @@
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 * as Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /** Constructs a branded `bigint` represents a protocol version. */
16
+ export const ProtocolVersion = Brand.nominal();
17
+ /**
18
+ * Creates a new protocol version range.
19
+ *
20
+ * @param start The start value.
21
+ * @param end The end value.
22
+ * @returns A {@link ProtocolVersion.Range} defined by `start` and `end`.
23
+ * @throws `TypeError` Thrown when `start` is after `end`, or the difference between them is less than one.
24
+ */
25
+ // TODO: make it possible to represent an open range on the end side to remove special "MaxSupportedVersion"
26
+ export const makeRange = (start, end) => {
27
+ if (end - start < 1)
28
+ throw new TypeError('Invalid protocol version range.');
29
+ return [start, end];
30
+ };
31
+ /**
32
+ * Determines if a given protocol version is within a given range.
33
+ *
34
+ * @param version The version to test.
35
+ * @param range The {@link ProtocolVersion.Range} to test `version` against.
36
+ * @returns `true` if `version` is within the range defined by `range`.
37
+ */
38
+ export const withinRange = (version, range) => {
39
+ const [min, max] = range;
40
+ return version >= min && version < max;
41
+ };
42
+ /** A schema that transforms a `bigint` into a {@link ProtocolVersion}. */
43
+ export const ProtocolVersionSchema = Schema.BigInt.pipe(Schema.fromBrand(ProtocolVersion));
44
+ /**
45
+ * A type predicate that determines if a given value is a {@link ProtocolVersion}.
46
+ *
47
+ * @param u The value to test.
48
+ * @returns `true` if `u` has the type {@link ProtocolVersion}.
49
+ */
50
+ export const is = Schema.is(ProtocolVersionSchema);
51
+ /** Represents the minimum supported protocol version. */
52
+ export const MinSupportedVersion = ProtocolVersion(0n);
53
+ /** Represents the maximum supported protocol version. */
54
+ export const MaxSupportedVersion = ProtocolVersion(BigInt(Number.MAX_SAFE_INTEGER));
@@ -0,0 +1,9 @@
1
+ import * as Brand from 'effect/Brand';
2
+ /** A branded `Uint8Array` representing serialized transaction data. */
3
+ export type SerializedTransaction = Brand.Branded<Uint8Array, 'SerializedTransaction'>;
4
+ /** Constructs a branded `Uint8Array` representing serialized transaction data. */
5
+ export declare const SerializedTransaction: Brand.Brand.Constructor<SerializedTransaction>;
6
+ export declare const of: (serialized: Uint8Array) => SerializedTransaction;
7
+ export declare const from: <T extends {
8
+ serialize: () => Uint8Array;
9
+ }>(serializable: T) => SerializedTransaction;
@@ -0,0 +1,22 @@
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 * as Brand from 'effect/Brand';
14
+ /** Constructs a branded `Uint8Array` representing serialized transaction data. */
15
+ export const SerializedTransaction = Brand.nominal();
16
+ export const of = (serialized) => {
17
+ return SerializedTransaction(serialized);
18
+ };
19
+ export const from = (serializable) => {
20
+ const serialized = serializable.serialize();
21
+ return SerializedTransaction(serialized);
22
+ };
@@ -0,0 +1,22 @@
1
+ export interface SyncProgressData {
2
+ readonly appliedIndex: bigint;
3
+ readonly highestRelevantWalletIndex: bigint;
4
+ readonly highestIndex: bigint;
5
+ readonly highestRelevantIndex: bigint;
6
+ readonly isConnected: boolean;
7
+ }
8
+ export interface SyncProgressOps {
9
+ isCompleteWithin(data: SyncProgressData, maxGap?: bigint): boolean;
10
+ }
11
+ export interface SyncProgress extends SyncProgressData {
12
+ isStrictlyComplete(): boolean;
13
+ isCompleteWithin(maxGap?: bigint): boolean;
14
+ }
15
+ export declare const SyncProgress: SyncProgressOps;
16
+ export declare const createSyncProgress: (params?: {
17
+ appliedIndex?: bigint;
18
+ highestRelevantWalletIndex?: bigint;
19
+ highestIndex?: bigint;
20
+ highestRelevantIndex?: bigint;
21
+ isConnected?: boolean;
22
+ }) => SyncProgress;
@@ -0,0 +1,25 @@
1
+ export const SyncProgress = {
2
+ isCompleteWithin(data, maxGap = 50n) {
3
+ const applyLag = BigInt(Math.abs(Number(data.highestRelevantWalletIndex - data.appliedIndex)));
4
+ return data.isConnected && applyLag <= maxGap;
5
+ },
6
+ };
7
+ export const createSyncProgress = (params = {}) => {
8
+ const { appliedIndex = 0n, highestRelevantWalletIndex = 0n, highestIndex = 0n, highestRelevantIndex = 0n, isConnected = false, } = params;
9
+ const data = {
10
+ appliedIndex,
11
+ highestRelevantWalletIndex,
12
+ highestIndex,
13
+ highestRelevantIndex,
14
+ isConnected,
15
+ };
16
+ return {
17
+ ...data,
18
+ isStrictlyComplete() {
19
+ return SyncProgress.isCompleteWithin(this, 0n);
20
+ },
21
+ isCompleteWithin(maxGap) {
22
+ return SyncProgress.isCompleteWithin(this, maxGap);
23
+ },
24
+ };
25
+ };
@@ -0,0 +1,33 @@
1
+ import { Schema } from 'effect';
2
+ export declare const TransactionHashSchema: typeof Schema.String;
3
+ export type TransactionHash = Schema.Schema.Type<typeof TransactionHashSchema>;
4
+ export declare const TransactionHistoryStatusSchema: Schema.Literal<["SUCCESS", "FAILURE", "PARTIAL_SUCCESS"]>;
5
+ export type TransactionHistoryStatus = Schema.Schema.Type<typeof TransactionHistoryStatusSchema>;
6
+ export declare const TransactionHistoryCommonSchema: Schema.Struct<{
7
+ hash: typeof Schema.String;
8
+ protocolVersion: typeof Schema.Number;
9
+ status: Schema.Literal<["SUCCESS", "FAILURE", "PARTIAL_SUCCESS"]>;
10
+ identifiers: Schema.optional<Schema.Array$<typeof Schema.String>>;
11
+ timestamp: Schema.optional<typeof Schema.Date>;
12
+ fees: Schema.optional<Schema.NullOr<typeof Schema.BigInt>>;
13
+ }>;
14
+ export type TransactionHistoryCommon = Schema.Schema.Type<typeof TransactionHistoryCommonSchema>;
15
+ export type SerializedTransactionHistory = string;
16
+ /**
17
+ * An entry with common fields plus any additional properties (wallet sections). Used by wallet packages for
18
+ * projection/filtering when the exact type is not known.
19
+ */
20
+ export type TransactionHistoryEntryWithHash = TransactionHistoryCommon & Record<string, unknown>;
21
+ /**
22
+ * Storage interface for transaction history entries keyed by their `hash` property.
23
+ *
24
+ * Pass a full entry schema to the implementation constructor to enable serialization.
25
+ */
26
+ export interface TransactionHistoryStorage<T extends {
27
+ hash: TransactionHash;
28
+ } = TransactionHistoryCommon> {
29
+ upsert(entry: T): Promise<void>;
30
+ getAll(): Promise<readonly T[]>;
31
+ get(hash: TransactionHash): Promise<T | undefined>;
32
+ serialize(): Promise<SerializedTransactionHistory>;
33
+ }
@@ -0,0 +1,23 @@
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 { Schema } from 'effect';
14
+ export const TransactionHashSchema = Schema.String;
15
+ export const TransactionHistoryStatusSchema = Schema.Literal('SUCCESS', 'FAILURE', 'PARTIAL_SUCCESS');
16
+ export const TransactionHistoryCommonSchema = Schema.Struct({
17
+ hash: TransactionHashSchema,
18
+ protocolVersion: Schema.Number,
19
+ status: TransactionHistoryStatusSchema,
20
+ identifiers: Schema.optional(Schema.Array(Schema.String)),
21
+ timestamp: Schema.optional(Schema.Date),
22
+ fees: Schema.optional(Schema.NullOr(Schema.BigInt)),
23
+ });
@@ -0,0 +1,22 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as Schema from 'effect/Schema';
3
+ /** A branded `Uint8Array` that represents a BIP32 compatible seed phrase. */
4
+ export type WalletSeed = Brand.Branded<Uint8Array, 'WalletSeed'>;
5
+ /** Constructs a branded `Uint8Array` representing a BIP32 compatible seed phrase. */
6
+ export declare const WalletSeed: Brand.Brand.Constructor<WalletSeed>;
7
+ /** A schema that transforms an array of numbers into a {@link WalletSeed}. */
8
+ export declare const WalletSeedSchema: Schema.BrandSchema<Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBufferLike> & Brand.Brand<"WalletSeed">, readonly number[], never>;
9
+ /**
10
+ * A type predicate that determines if a given value is a {@link WalletSeed}.
11
+ *
12
+ * @param u The value to test.
13
+ * @returns `true` if `u` has the type {@link WalletSeed}.
14
+ */
15
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBufferLike> & Brand.Brand<"WalletSeed">;
16
+ /**
17
+ * Constructs a {@link WalletSeed} from a string representation of a BIP32 compatible seed phrase.
18
+ *
19
+ * @param strValue The string value.
20
+ * @returns A {@link WalletSeed} created from `strValue`.
21
+ */
22
+ export declare const fromString: (strValue: string) => WalletSeed;
@@ -0,0 +1,32 @@
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 * as Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /** Constructs a branded `Uint8Array` representing a BIP32 compatible seed phrase. */
16
+ export const WalletSeed = Brand.nominal();
17
+ /** A schema that transforms an array of numbers into a {@link WalletSeed}. */
18
+ export const WalletSeedSchema = Schema.Uint8Array.pipe(Schema.fromBrand(WalletSeed));
19
+ /**
20
+ * A type predicate that determines if a given value is a {@link WalletSeed}.
21
+ *
22
+ * @param u The value to test.
23
+ * @returns `true` if `u` has the type {@link WalletSeed}.
24
+ */
25
+ export const is = Schema.is(WalletSeedSchema);
26
+ /**
27
+ * Constructs a {@link WalletSeed} from a string representation of a BIP32 compatible seed phrase.
28
+ *
29
+ * @param strValue The string value.
30
+ * @returns A {@link WalletSeed} created from `strValue`.
31
+ */
32
+ export const fromString = (strValue) => WalletSeed(Buffer.from(strValue, 'hex'));
@@ -0,0 +1,18 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as Schema from 'effect/Schema';
3
+ /**
4
+ * A branded `string` representing serialized (JSON) wallet state made up of local state, transaction history, and block
5
+ * height.
6
+ */
7
+ export type WalletState = Brand.Branded<string, 'WalletState'>;
8
+ /** Constructs a branded `string` representing serialized (JSON) wallet state. */
9
+ export declare const WalletState: Brand.Brand.Constructor<WalletState>;
10
+ /** A schema that transforms a string into a {@link WalletState}. */
11
+ export declare const WalletStateSchema: Schema.BrandSchema<string & Brand.Brand<"WalletState">, string, never>;
12
+ /**
13
+ * A type predicate that determines if a given value is a {@link WalletState}.
14
+ *
15
+ * @param u The value to test.
16
+ * @returns `true` if `u` has the type {@link WalletState}.
17
+ */
18
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is string & Brand.Brand<"WalletState">;
@@ -0,0 +1,25 @@
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 * as Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /** Constructs a branded `string` representing serialized (JSON) wallet state. */
16
+ export const WalletState = Brand.nominal();
17
+ /** A schema that transforms a string into a {@link WalletState}. */
18
+ export const WalletStateSchema = Schema.String.pipe(Schema.fromBrand(WalletState));
19
+ /**
20
+ * A type predicate that determines if a given value is a {@link WalletState}.
21
+ *
22
+ * @param u The value to test.
23
+ * @returns `true` if `u` has the type {@link WalletState}.
24
+ */
25
+ export const is = Schema.is(WalletStateSchema);
@@ -0,0 +1,10 @@
1
+ export * as WalletSeed from './WalletSeed.js';
2
+ export * as WalletState from './WalletState.js';
3
+ export * as SerializedTransaction from './SerializedTransaction.js';
4
+ export * as ProtocolState from './ProtocolState.js';
5
+ export * as ProtocolVersion from './ProtocolVersion.js';
6
+ export * as NetworkId from './NetworkId.js';
7
+ export * as SyncProgress from './SyncProgress.js';
8
+ export * from './InMemoryTransactionHistoryStorage.js';
9
+ export * from './NoOpTransactionHistoryStorage.js';
10
+ export * as TransactionHistoryStorage from './TransactionHistoryStorage.js';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
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
+ export * as WalletSeed from './WalletSeed.js';
14
+ export * as WalletState from './WalletState.js';
15
+ export * as SerializedTransaction from './SerializedTransaction.js';
16
+ export * as ProtocolState from './ProtocolState.js';
17
+ export * as ProtocolVersion from './ProtocolVersion.js';
18
+ export * as NetworkId from './NetworkId.js';
19
+ export * as SyncProgress from './SyncProgress.js';
20
+ export * from './InMemoryTransactionHistoryStorage.js';
21
+ export * from './NoOpTransactionHistoryStorage.js';
22
+ export * as TransactionHistoryStorage from './TransactionHistoryStorage.js';
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@midnightntwrk/wallet-sdk-abstractions",
3
+ "description": "Domain-specific abstractions for the wallet SDK",
4
+ "version": "2.1.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "author": "Midnight Foundation",
10
+ "license": "Apache-2.0",
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org/",
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/midnightntwrk/midnight-wallet.git",
21
+ "directory": "packages/abstractions"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "effect": "^3.19.19"
31
+ },
32
+ "scripts": {
33
+ "typecheck": "tsc -b ./tsconfig.json --noEmit --force",
34
+ "test": "vitest run",
35
+ "lint": "eslint --max-warnings 0",
36
+ "format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
37
+ "format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml,md}\"",
38
+ "dist": "tsc -b ./tsconfig.build.json",
39
+ "dist:publish": "tsc -b ./tsconfig.publish.json",
40
+ "clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
41
+ "publint": "publint --strict"
42
+ }
43
+ }