@midnight-ntwrk/wallet-sdk-abstractions 1.0.0-beta.9

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.
@@ -0,0 +1,10 @@
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 NetworkId = (typeof NetworkId)[keyof typeof NetworkId];
@@ -0,0 +1,21 @@
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
+ 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,11 @@
1
+ import * as ProtocolVersion from './ProtocolVersion.js';
2
+ /**
3
+ * A type that associates some state with a given version of the Midnight protocol.
4
+ *
5
+ * @typeParam TState The type of state.
6
+ */
7
+ export type ProtocolState<TState> = Readonly<{
8
+ version: ProtocolVersion.ProtocolVersion;
9
+ state: TState;
10
+ }>;
11
+ export declare const state: <TState>(ps: ProtocolState<TState>) => TState;
@@ -0,0 +1 @@
1
+ export const state = (ps) => ps.state;
@@ -0,0 +1,54 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as Schema from 'effect/Schema';
3
+ /**
4
+ * A branded `bigint` that represents a protocol version.
5
+ */
6
+ export type ProtocolVersion = Brand.Branded<bigint, 'ProtocolVersion'>;
7
+ /**
8
+ * Constructs a branded `bigint` represents a protocol version.
9
+ */
10
+ export declare const ProtocolVersion: Brand.Brand.Constructor<ProtocolVersion>;
11
+ export declare namespace ProtocolVersion {
12
+ /**
13
+ * A tuple type that represents a start and ending protocol version.
14
+ */
15
+ type Range = readonly [start: ProtocolVersion, end: ProtocolVersion];
16
+ }
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
+ *
24
+ * @throws `TypeError`
25
+ * Thrown when `start` is after `end`, or the difference between them is less than one.
26
+ */
27
+ export declare const makeRange: (start: ProtocolVersion, end: ProtocolVersion) => ProtocolVersion.Range;
28
+ /**
29
+ * Determines if a given protocol version is within a given range.
30
+ *
31
+ * @param version The version to test.
32
+ * @param range The {@link ProtocolVersion.Range} to test `version` against.
33
+ * @returns `true` if `version` is within the range defined by `range`.
34
+ */
35
+ export declare const withinRange: (version: ProtocolVersion, range: ProtocolVersion.Range) => boolean;
36
+ /**
37
+ * A schema that transforms a `bigint` into a {@link ProtocolVersion}.
38
+ */
39
+ export declare const ProtocolVersionSchema: Schema.BrandSchema<bigint & Brand.Brand<"ProtocolVersion">, string, never>;
40
+ /**
41
+ * A type predicate that determines if a given value is a {@link ProtocolVersion}.
42
+ *
43
+ * @param u The value to test.
44
+ * @returns `true` if `u` has the type {@link ProtocolVersion}.
45
+ */
46
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is bigint & Brand.Brand<"ProtocolVersion">;
47
+ /**
48
+ * Represents the minimum supported protocol version.
49
+ */
50
+ export declare const MinSupportedVersion: ProtocolVersion;
51
+ /**
52
+ * Represents the maximum supported protocol version.
53
+ */
54
+ export declare const MaxSupportedVersion: ProtocolVersion;
@@ -0,0 +1,64 @@
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 Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /**
16
+ * Constructs a branded `bigint` represents a protocol version.
17
+ */
18
+ export const ProtocolVersion = Brand.nominal();
19
+ /**
20
+ * Creates a new protocol version range.
21
+ *
22
+ * @param start The start value.
23
+ * @param end The end value.
24
+ * @returns A {@link ProtocolVersion.Range} defined by `start` and `end`.
25
+ *
26
+ * @throws `TypeError`
27
+ * Thrown when `start` is after `end`, or the difference between them is less than one.
28
+ */
29
+ // TODO: make it possible to represent an open range on the end side to remove special "MaxSupportedVersion"
30
+ export const makeRange = (start, end) => {
31
+ if (end - start < 1)
32
+ throw new TypeError('Invalid protocol version range.');
33
+ return [start, end];
34
+ };
35
+ /**
36
+ * Determines if a given protocol version is within a given range.
37
+ *
38
+ * @param version The version to test.
39
+ * @param range The {@link ProtocolVersion.Range} to test `version` against.
40
+ * @returns `true` if `version` is within the range defined by `range`.
41
+ */
42
+ export const withinRange = (version, range) => {
43
+ const [min, max] = range;
44
+ return version >= min && version < max;
45
+ };
46
+ /**
47
+ * A schema that transforms a `bigint` into a {@link ProtocolVersion}.
48
+ */
49
+ export const ProtocolVersionSchema = Schema.BigInt.pipe(Schema.fromBrand(ProtocolVersion));
50
+ /**
51
+ * A type predicate that determines if a given value is a {@link ProtocolVersion}.
52
+ *
53
+ * @param u The value to test.
54
+ * @returns `true` if `u` has the type {@link ProtocolVersion}.
55
+ */
56
+ export const is = Schema.is(ProtocolVersionSchema);
57
+ /**
58
+ * Represents the minimum supported protocol version.
59
+ */
60
+ export const MinSupportedVersion = ProtocolVersion(0n);
61
+ /**
62
+ * Represents the maximum supported protocol version.
63
+ */
64
+ export const MaxSupportedVersion = ProtocolVersion(BigInt(Number.MAX_SAFE_INTEGER));
@@ -0,0 +1,9 @@
1
+ import * as Brand from 'effect/Brand';
2
+ /**
3
+ * A branded `Uint8Array` representing serialized transaction data.
4
+ */
5
+ export type SerializedTransaction = Brand.Branded<Uint8Array, 'SerializedTransaction'>;
6
+ /**
7
+ * Constructs a branded `Uint8Array` representing serialized transaction data.
8
+ */
9
+ export declare const SerializedTransaction: Brand.Brand.Constructor<SerializedTransaction>;
@@ -0,0 +1,17 @@
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 Brand from 'effect/Brand';
14
+ /**
15
+ * Constructs a branded `Uint8Array` representing serialized transaction data.
16
+ */
17
+ export const SerializedTransaction = Brand.nominal();
@@ -0,0 +1,9 @@
1
+ import { Brand } from 'effect';
2
+ /**
3
+ * A branded `Uint8Array` representing serialized unproven transaction data.
4
+ */
5
+ export type SerializedUnprovenTransaction = Brand.Branded<Uint8Array, 'SerializedUnprovenTransaction'>;
6
+ /**
7
+ * Constructs a branded `Uint8Array` representing serialized unproven transaction data.
8
+ */
9
+ export declare const SerializedUnprovenTransaction: Brand.Brand.Constructor<SerializedUnprovenTransaction>;
@@ -0,0 +1,17 @@
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 { Brand } from 'effect';
14
+ /**
15
+ * Constructs a branded `Uint8Array` representing serialized unproven transaction data.
16
+ */
17
+ export const SerializedUnprovenTransaction = Brand.nominal();
@@ -0,0 +1,28 @@
1
+ import * as Brand from 'effect/Brand';
2
+ import * as Schema from 'effect/Schema';
3
+ /**
4
+ * A branded `Uint8Array` that represents a BIP32 compatible seed phrase.
5
+ */
6
+ export type WalletSeed = Brand.Branded<Uint8Array, 'WalletSeed'>;
7
+ /**
8
+ * Constructs a branded `Uint8Array` representing a BIP32 compatible seed phrase.
9
+ */
10
+ export declare const WalletSeed: Brand.Brand.Constructor<WalletSeed>;
11
+ /**
12
+ * A schema that transforms an array of numbers into a {@link WalletSeed}.
13
+ */
14
+ export declare const WalletSeedSchema: Schema.BrandSchema<Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBufferLike> & Brand.Brand<"WalletSeed">, readonly number[], never>;
15
+ /**
16
+ * A type predicate that determines if a given value is a {@link WalletSeed}.
17
+ *
18
+ * @param u The value to test.
19
+ * @returns `true` if `u` has the type {@link WalletSeed}.
20
+ */
21
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBufferLike> & Brand.Brand<"WalletSeed">;
22
+ /**
23
+ * Constructs a {@link WalletSeed} from a string representation of a BIP32 compatible seed phrase.
24
+ *
25
+ * @param strValue The string value.
26
+ * @returns A {@link WalletSeed} created from `strValue`.
27
+ */
28
+ export declare const fromString: (strValue: string) => WalletSeed;
@@ -0,0 +1,36 @@
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 Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /**
16
+ * Constructs a branded `Uint8Array` representing a BIP32 compatible seed phrase.
17
+ */
18
+ export const WalletSeed = Brand.nominal();
19
+ /**
20
+ * A schema that transforms an array of numbers into a {@link WalletSeed}.
21
+ */
22
+ export const WalletSeedSchema = Schema.Uint8Array.pipe(Schema.fromBrand(WalletSeed));
23
+ /**
24
+ * A type predicate that determines if a given value is a {@link WalletSeed}.
25
+ *
26
+ * @param u The value to test.
27
+ * @returns `true` if `u` has the type {@link WalletSeed}.
28
+ */
29
+ export const is = Schema.is(WalletSeedSchema);
30
+ /**
31
+ * Constructs a {@link WalletSeed} from a string representation of a BIP32 compatible seed phrase.
32
+ *
33
+ * @param strValue The string value.
34
+ * @returns A {@link WalletSeed} created from `strValue`.
35
+ */
36
+ export const fromString = (strValue) => WalletSeed(Buffer.from(strValue, 'hex'));
@@ -0,0 +1,22 @@
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,
5
+ * and block height.
6
+ */
7
+ export type WalletState = Brand.Branded<string, 'WalletState'>;
8
+ /**
9
+ * Constructs a branded `string` representing serialized (JSON) wallet state.
10
+ */
11
+ export declare const WalletState: Brand.Brand.Constructor<WalletState>;
12
+ /**
13
+ * A schema that transforms a string into a {@link WalletState}.
14
+ */
15
+ export declare const WalletStateSchema: Schema.BrandSchema<string & Brand.Brand<"WalletState">, string, never>;
16
+ /**
17
+ * A type predicate that determines if a given value is a {@link WalletState}.
18
+ *
19
+ * @param u The value to test.
20
+ * @returns `true` if `u` has the type {@link WalletState}.
21
+ */
22
+ export declare const is: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions | number) => u is string & Brand.Brand<"WalletState">;
@@ -0,0 +1,29 @@
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 Brand from 'effect/Brand';
14
+ import * as Schema from 'effect/Schema';
15
+ /**
16
+ * Constructs a branded `string` representing serialized (JSON) wallet state.
17
+ */
18
+ export const WalletState = Brand.nominal();
19
+ /**
20
+ * A schema that transforms a string into a {@link WalletState}.
21
+ */
22
+ export const WalletStateSchema = Schema.String.pipe(Schema.fromBrand(WalletState));
23
+ /**
24
+ * A type predicate that determines if a given value is a {@link WalletState}.
25
+ *
26
+ * @param u The value to test.
27
+ * @returns `true` if `u` has the type {@link WalletState}.
28
+ */
29
+ export const is = Schema.is(WalletStateSchema);
@@ -0,0 +1,7 @@
1
+ export * as WalletSeed from './WalletSeed.js';
2
+ export * as WalletState from './WalletState.js';
3
+ export * from './SerializedTransaction.js';
4
+ export * from './SerializedUnprovenTransaction.js';
5
+ export * as ProtocolState from './ProtocolState.js';
6
+ export * as ProtocolVersion from './ProtocolVersion.js';
7
+ export * as NetworkId from './NetworkId.js';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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
+ export * as WalletSeed from './WalletSeed.js';
14
+ export * as WalletState from './WalletState.js';
15
+ export * from './SerializedTransaction.js';
16
+ export * from './SerializedUnprovenTransaction.js';
17
+ export * as ProtocolState from './ProtocolState.js';
18
+ export * as ProtocolVersion from './ProtocolVersion.js';
19
+ export * as NetworkId from './NetworkId.js';
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@midnight-ntwrk/wallet-sdk-abstractions",
3
+ "description": "Domain-specific abstractions for the wallet SDK",
4
+ "version": "1.0.0-beta.9",
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://npm.pkg.github.com/"
13
+ },
14
+ "files": [
15
+ "dist/"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/midnight-ntwrk/artifacts.git"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "effect": "^3.17.3"
29
+ },
30
+ "devDependencies": {
31
+ "eslint": "^9.37.0",
32
+ "fast-check": "^4.2.0",
33
+ "publint": "~0.3.14",
34
+ "rimraf": "^6.0.1",
35
+ "to-words": "^4.5.1",
36
+ "typescript": "^5.9.3",
37
+ "vitest": "^3.2.4"
38
+ },
39
+ "scripts": {
40
+ "typecheck": "tsc -b ./tsconfig.json --noEmit",
41
+ "test": "vitest run",
42
+ "lint": "eslint --max-warnings 0",
43
+ "format": "prettier --write \"**/*.{ts,js,json,yaml,yml}\"",
44
+ "format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml}\"",
45
+ "dist": "tsc -b ./tsconfig.build.json",
46
+ "dist:publish": "tsc -b ./tsconfig.publish.json",
47
+ "clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
48
+ "publint": "publint --strict"
49
+ }
50
+ }