@midnightntwrk/wallet-sdk-capabilities 3.3.1
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 +126 -0
- package/dist/balancer/Balancer.d.ts +24 -0
- package/dist/balancer/Balancer.js +68 -0
- package/dist/balancer/CounterOffer.d.ts +19 -0
- package/dist/balancer/CounterOffer.js +65 -0
- package/dist/balancer/Imbalances.d.ts +19 -0
- package/dist/balancer/Imbalances.js +48 -0
- package/dist/balancer/index.d.ts +3 -0
- package/dist/balancer/index.js +15 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/dist/pendingTransactions/index.d.ts +2 -0
- package/dist/pendingTransactions/index.js +16 -0
- package/dist/pendingTransactions/pendingTransactions.d.ts +61 -0
- package/dist/pendingTransactions/pendingTransactions.js +85 -0
- package/dist/pendingTransactions/pendingTransactionsService.d.ts +52 -0
- package/dist/pendingTransactions/pendingTransactionsService.js +146 -0
- package/dist/proving/index.d.ts +1 -0
- package/dist/proving/index.js +15 -0
- package/dist/proving/provingService.d.ts +37 -0
- package/dist/proving/provingService.js +61 -0
- package/dist/simulation/Simulator.d.ts +180 -0
- package/dist/simulation/Simulator.js +453 -0
- package/dist/simulation/SimulatorState.d.ts +349 -0
- package/dist/simulation/SimulatorState.js +323 -0
- package/dist/simulation/index.d.ts +2 -0
- package/dist/simulation/index.js +26 -0
- package/dist/submission/index.d.ts +1 -0
- package/dist/submission/index.js +15 -0
- package/dist/submission/submissionService.d.ts +60 -0
- package/dist/submission/submissionService.js +86 -0
- package/package.json +79 -0
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// Re-export everything from SimulatorState
|
|
14
|
+
export {
|
|
15
|
+
// State accessor functions (composable with simulator.query())
|
|
16
|
+
getLastBlock, getCurrentBlockNumber, getCurrentTime, getBlockByNumber, getLastBlockResults, getLastBlockEvents, getBlockEventsFrom, getBlockEventsSince, hasPendingTransactions,
|
|
17
|
+
// State transformation functions
|
|
18
|
+
resolveFullness, allMempoolTransactions, blankState, addToMempool, removeFromMempool, advanceTime, updateLedger, appendBlock, applyTransaction,
|
|
19
|
+
// Block production functions
|
|
20
|
+
processTransaction, processTransactions, createBlock, createEmptyBlock,
|
|
21
|
+
// Helper functions
|
|
22
|
+
createStrictness, blockHash, assignStrictness, assignStrictnessToAll,
|
|
23
|
+
// Strictness constants
|
|
24
|
+
defaultStrictness, genesisStrictness, } from './SimulatorState.js';
|
|
25
|
+
// Re-export from Simulator
|
|
26
|
+
export { Simulator, immediateBlockProducer } from './Simulator.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './submissionService.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of MIDNIGHT-WALLET-SDK.
|
|
3
|
+
* Copyright (C) Midnight Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* You may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
export * from './submissionService.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { SubmissionEvent as SubmissionEventImported } from '@midnightntwrk/wallet-sdk-node-client/effect';
|
|
3
|
+
import { type FinalizedTransaction } from '@midnight-ntwrk/ledger-v8';
|
|
4
|
+
import { type SimulatorState } from '../simulation/Simulator.js';
|
|
5
|
+
export declare const SubmissionEvent: typeof SubmissionEventImported;
|
|
6
|
+
export type SubmissionEvent = SubmissionEventImported.SubmissionEvent;
|
|
7
|
+
export declare namespace SubmissionEventCases {
|
|
8
|
+
type Finalized = SubmissionEventImported.Cases.Finalized;
|
|
9
|
+
type Submitted = SubmissionEventImported.Cases.Submitted;
|
|
10
|
+
type InBlock = SubmissionEventImported.Cases.InBlock;
|
|
11
|
+
}
|
|
12
|
+
declare const SubmissionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
13
|
+
readonly _tag: "SubmissionError";
|
|
14
|
+
} & Readonly<A>;
|
|
15
|
+
export declare class SubmissionError extends SubmissionError_base<{
|
|
16
|
+
message: string;
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
}> {
|
|
19
|
+
}
|
|
20
|
+
export type SubmitTransactionMethod<TTransaction> = {
|
|
21
|
+
(transaction: TTransaction, waitForStatus: 'Submitted'): Promise<SubmissionEventCases.Submitted>;
|
|
22
|
+
(transaction: TTransaction, waitForStatus: 'InBlock'): Promise<SubmissionEventCases.InBlock>;
|
|
23
|
+
(transaction: TTransaction, waitForStatus: 'Finalized'): Promise<SubmissionEventCases.Finalized>;
|
|
24
|
+
(transaction: TTransaction): Promise<SubmissionEventCases.InBlock>;
|
|
25
|
+
(transaction: TTransaction, waitForStatus?: 'Submitted' | 'InBlock' | 'Finalized'): Promise<SubmissionEvent>;
|
|
26
|
+
};
|
|
27
|
+
export type SubmitTransactionMethodEffect<TTransaction> = {
|
|
28
|
+
(transaction: TTransaction, waitForStatus: 'Submitted'): Effect.Effect<SubmissionEventCases.Submitted, SubmissionError>;
|
|
29
|
+
(transaction: TTransaction, waitForStatus: 'InBlock'): Effect.Effect<SubmissionEventCases.InBlock, SubmissionError>;
|
|
30
|
+
(transaction: TTransaction, waitForStatus: 'Finalized'): Effect.Effect<SubmissionEventCases.Finalized, SubmissionError>;
|
|
31
|
+
(transaction: TTransaction): Effect.Effect<SubmissionEventCases.InBlock, SubmissionError>;
|
|
32
|
+
(transaction: TTransaction, waitForStatus?: 'Submitted' | 'InBlock' | 'Finalized'): Effect.Effect<SubmissionEvent, SubmissionError>;
|
|
33
|
+
};
|
|
34
|
+
export interface SubmissionServiceEffect<TTransaction> {
|
|
35
|
+
submitTransaction: SubmitTransactionMethodEffect<TTransaction>;
|
|
36
|
+
close(): Effect.Effect<void>;
|
|
37
|
+
}
|
|
38
|
+
export interface SubmissionService<TTransaction> {
|
|
39
|
+
submitTransaction: SubmitTransactionMethod<TTransaction>;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export type DefaultSubmissionConfiguration = {
|
|
43
|
+
relayURL: URL;
|
|
44
|
+
};
|
|
45
|
+
export declare const makeDefaultSubmissionServiceEffect: <TTransaction extends {
|
|
46
|
+
serialize: () => Uint8Array;
|
|
47
|
+
} = FinalizedTransaction>(config: DefaultSubmissionConfiguration) => SubmissionServiceEffect<TTransaction>;
|
|
48
|
+
export declare const makeDefaultSubmissionService: <TTransaction extends {
|
|
49
|
+
serialize: () => Uint8Array;
|
|
50
|
+
} = FinalizedTransaction>(config: DefaultSubmissionConfiguration) => SubmissionService<TTransaction>;
|
|
51
|
+
export type SimulatorSubmissionConfiguration<TTransaction> = {
|
|
52
|
+
simulator: {
|
|
53
|
+
submitTransaction: (transaction: TTransaction) => Effect.Effect<void, Error>;
|
|
54
|
+
getLatestState: () => Effect.Effect<SimulatorState>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export declare const makeSimulatorSubmissionService: <TTransaction extends {
|
|
58
|
+
serialize: () => Uint8Array;
|
|
59
|
+
}>(waitForStatus?: "Submitted" | "InBlock" | "Finalized") => (config: SimulatorSubmissionConfiguration<TTransaction>) => SubmissionServiceEffect<TTransaction>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
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 { Data, Deferred, Effect, Encoding, Exit, pipe, Scope } from 'effect';
|
|
14
|
+
import { NodeClient, PolkadotNodeClient, SubmissionEvent as SubmissionEventImported, } from '@midnightntwrk/wallet-sdk-node-client/effect';
|
|
15
|
+
import { SerializedTransaction } from '@midnightntwrk/wallet-sdk-abstractions';
|
|
16
|
+
import { getLastBlock } from '../simulation/Simulator.js';
|
|
17
|
+
export const SubmissionEvent = SubmissionEventImported;
|
|
18
|
+
export class SubmissionError extends Data.TaggedError('SubmissionError') {
|
|
19
|
+
}
|
|
20
|
+
export const makeDefaultSubmissionServiceEffect = (config) => {
|
|
21
|
+
const scopeAndClientDeferred = Deferred.make().pipe(Effect.runSync);
|
|
22
|
+
const makeScopeAndClient = Effect.gen(function* () {
|
|
23
|
+
const scope = yield* Scope.make();
|
|
24
|
+
const client = yield* PolkadotNodeClient.make({
|
|
25
|
+
nodeURL: config.relayURL,
|
|
26
|
+
}).pipe(Effect.provideService(Scope.Scope, scope));
|
|
27
|
+
return { scope, client };
|
|
28
|
+
});
|
|
29
|
+
void pipe(scopeAndClientDeferred, Deferred.complete(makeScopeAndClient), Effect.runPromise);
|
|
30
|
+
const submit = (transaction, waitForStatus = 'InBlock') => {
|
|
31
|
+
return pipe(NodeClient.sendMidnightTransactionAndWait(SerializedTransaction.from(transaction), waitForStatus), Effect.provideServiceEffect(NodeClient.NodeClient, pipe(scopeAndClientDeferred, Deferred.await, Effect.map(({ client }) => client))), Effect.mapError((err) => new SubmissionError({ message: 'Transaction submission error', cause: err })));
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
submitTransaction: submit,
|
|
35
|
+
close() {
|
|
36
|
+
return pipe(scopeAndClientDeferred, Deferred.await, Effect.flatMap(({ scope }) => Scope.close(scope, Exit.void)), Effect.ignoreLogged);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const makeDefaultSubmissionService = (config) => {
|
|
41
|
+
const effectService = makeDefaultSubmissionServiceEffect(config);
|
|
42
|
+
const submit = (transaction, waitForStatus = 'InBlock') => effectService.submitTransaction(transaction, waitForStatus).pipe(Effect.runPromise);
|
|
43
|
+
return {
|
|
44
|
+
submitTransaction: submit,
|
|
45
|
+
close: () => effectService.close().pipe(Effect.runPromise),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export const makeSimulatorSubmissionService = (waitForStatus = 'InBlock') => (config) => {
|
|
49
|
+
const submit = (transaction) => {
|
|
50
|
+
return pipe(config.simulator.submitTransaction(transaction),
|
|
51
|
+
// Wait for stream-based block production
|
|
52
|
+
Effect.andThen(Effect.sleep('100 millis')), Effect.andThen(config.simulator.getLatestState())).pipe(Effect.map((state) => {
|
|
53
|
+
const lastBlock = getLastBlock(state);
|
|
54
|
+
const blockNumber = lastBlock?.number ?? 0n;
|
|
55
|
+
const blockHash = lastBlock?.hash ?? '';
|
|
56
|
+
const serializedTransaction = SerializedTransaction.from(transaction);
|
|
57
|
+
const fakeTxHash = Encoding.encodeHex(serializedTransaction).slice(0, 64);
|
|
58
|
+
// Let's mimic node's client behavior here
|
|
59
|
+
switch (waitForStatus) {
|
|
60
|
+
case 'Submitted':
|
|
61
|
+
return SubmissionEvent.Submitted({
|
|
62
|
+
tx: serializedTransaction,
|
|
63
|
+
txHash: fakeTxHash,
|
|
64
|
+
});
|
|
65
|
+
case 'InBlock':
|
|
66
|
+
return SubmissionEvent.InBlock({
|
|
67
|
+
tx: serializedTransaction,
|
|
68
|
+
blockHash,
|
|
69
|
+
blockHeight: blockNumber,
|
|
70
|
+
txHash: fakeTxHash,
|
|
71
|
+
});
|
|
72
|
+
case 'Finalized':
|
|
73
|
+
return SubmissionEvent.Finalized({
|
|
74
|
+
tx: serializedTransaction,
|
|
75
|
+
blockHash,
|
|
76
|
+
blockHeight: blockNumber,
|
|
77
|
+
txHash: fakeTxHash,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}), Effect.mapError((err) => new SubmissionError({ message: 'Transaction submission error', cause: err })));
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
submitTransaction: submit,
|
|
84
|
+
close: () => Effect.void,
|
|
85
|
+
};
|
|
86
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@midnightntwrk/wallet-sdk-capabilities",
|
|
3
|
+
"version": "3.3.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"author": "Midnight Foundation",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org/",
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/midnightntwrk/midnight-wallet.git",
|
|
20
|
+
"directory": "packages/capabilities"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./balancer": {
|
|
28
|
+
"types": "./dist/balancer/index.d.ts",
|
|
29
|
+
"import": "./dist/balancer/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./submission": {
|
|
32
|
+
"types": "./dist/submission/index.d.ts",
|
|
33
|
+
"import": "./dist/submission/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./pendingTransactions": {
|
|
36
|
+
"types": "./dist/pendingTransactions/index.d.ts",
|
|
37
|
+
"import": "./dist/pendingTransactions/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./proving": {
|
|
40
|
+
"types": "./dist/proving/index.d.ts",
|
|
41
|
+
"import": "./dist/proving/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./simulation": {
|
|
44
|
+
"types": "./dist/simulation/index.d.ts",
|
|
45
|
+
"import": "./dist/simulation/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@midnight-ntwrk/ledger-v8": "^8.1.0",
|
|
50
|
+
"@midnight-ntwrk/zkir-v2": "^2.1.0",
|
|
51
|
+
"@midnightntwrk/wallet-sdk-abstractions": "^2.1.0",
|
|
52
|
+
"@midnightntwrk/wallet-sdk-indexer-client": "^1.2.2",
|
|
53
|
+
"@midnightntwrk/wallet-sdk-node-client": "^1.1.2",
|
|
54
|
+
"@midnightntwrk/wallet-sdk-prover-client": "^1.2.2",
|
|
55
|
+
"@midnightntwrk/wallet-sdk-utilities": "^1.2.0",
|
|
56
|
+
"effect": "^3.19.19",
|
|
57
|
+
"rxjs": "^7.8.2"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@effect/cluster": "0.59.0",
|
|
61
|
+
"@effect/experimental": "0.60.0",
|
|
62
|
+
"@effect/platform": "0.96.1",
|
|
63
|
+
"@effect/platform-node": "0.107.0",
|
|
64
|
+
"@effect/rpc": "0.75.1",
|
|
65
|
+
"@effect/sql": "0.51.1",
|
|
66
|
+
"@effect/workflow": "0.18.2"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"typecheck": "tsc -b ./tsconfig.json --noEmit --force",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"lint": "eslint --max-warnings 0",
|
|
72
|
+
"format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
73
|
+
"format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
74
|
+
"dist": "tsc -b ./tsconfig.build.json",
|
|
75
|
+
"dist:publish": "tsc -b ./tsconfig.publish.json",
|
|
76
|
+
"clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
|
|
77
|
+
"publint": "publint --strict"
|
|
78
|
+
}
|
|
79
|
+
}
|