@midnight-ntwrk/wallet-sdk-facade 2.0.0 → 3.0.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/dist/index.d.ts +45 -1
- package/dist/index.js +35 -1
- package/dist/transaction.d.ts +1 -1
- package/dist/transaction.js +1 -1
- package/package.json +9 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
1
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
2
2
|
import { type DefaultSubmissionConfiguration, type SubmissionService } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
3
3
|
import { type DefaultProvingConfiguration, type ProvingService, type UnboundTransaction } from '@midnight-ntwrk/wallet-sdk-capabilities/proving';
|
|
4
4
|
import { type DefaultDustConfiguration, type DustWalletAPI, type DustWalletState } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
|
|
@@ -73,6 +73,27 @@ export declare class FacadeState {
|
|
|
73
73
|
get isSynced(): boolean;
|
|
74
74
|
constructor(shielded: ShieldedWalletState, unshielded: UnshieldedWalletState, dust: DustWalletState, pending: PendingTransactions.PendingTransactions<ledger.FinalizedTransaction>);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The Terms and Conditions returned by the indexer, containing a URL for display
|
|
78
|
+
* and a SHA-256 hash for content verification.
|
|
79
|
+
*/
|
|
80
|
+
export type TermsAndConditions = {
|
|
81
|
+
/** The hex-encoded SHA-256 hash of the Terms and Conditions document. */
|
|
82
|
+
hash: string;
|
|
83
|
+
/** The URL pointing to the Terms and Conditions document. */
|
|
84
|
+
url: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Minimal configuration required for {@link WalletFacade.fetchTermsAndConditions}.
|
|
88
|
+
* Accepts the shared `indexerClientConnection` sub-object found on all wallet configurations,
|
|
89
|
+
* so callers can pass the full wallet configuration directly without any adaptation.
|
|
90
|
+
*/
|
|
91
|
+
export type FetchTermsAndConditionsConfiguration = {
|
|
92
|
+
indexerClientConnection: {
|
|
93
|
+
indexerHttpUrl: string;
|
|
94
|
+
indexerWsUrl?: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
76
97
|
export type DefaultConfiguration = DefaultUnshieldedConfiguration & DefaultShieldedConfiguration & DefaultDustConfiguration & DefaultSubmissionConfiguration & DefaultPendingTransactionsServiceConfiguration & Partial<DefaultProvingConfiguration>;
|
|
77
98
|
type MaybePromise<T> = T | Promise<T>;
|
|
78
99
|
export type InitParams<TConfig extends DefaultConfiguration> = {
|
|
@@ -89,6 +110,23 @@ export declare class WalletFacade {
|
|
|
89
110
|
private static makeDefaultSubmissionService;
|
|
90
111
|
private static makeDefaultPendingTransactionsService;
|
|
91
112
|
private static makeDefaultProvingService;
|
|
113
|
+
/**
|
|
114
|
+
* Fetches the current Terms and Conditions from the network indexer.
|
|
115
|
+
*
|
|
116
|
+
* This is a static, pre-initialization utility — no wallet instance is required.
|
|
117
|
+
* Wallet builders should call this before or independently of wallet initialization
|
|
118
|
+
* to display the current T&C to end users and obtain the hash for content verification.
|
|
119
|
+
*
|
|
120
|
+
* The returned `hash` is the hex-encoded SHA-256 hash of the document at `url`.
|
|
121
|
+
* Wallet builders are responsible for fetching and rendering the document content
|
|
122
|
+
* via `url` in whatever manner suits their application.
|
|
123
|
+
*
|
|
124
|
+
* @param configuration - An object with an `indexerClientConnection.indexerHttpUrl`.
|
|
125
|
+
* Any wallet configuration that satisfies {@link FetchTermsAndConditionsConfiguration} can be passed directly.
|
|
126
|
+
* @returns A promise resolving to the current {@link TermsAndConditions}, or rejecting if
|
|
127
|
+
* no Terms and Conditions have been set on the network yet.
|
|
128
|
+
*/
|
|
129
|
+
static fetchTermsAndConditions(configuration: FetchTermsAndConditionsConfiguration): Promise<TermsAndConditions>;
|
|
92
130
|
static init<TConfig extends DefaultConfiguration>(initParams: InitParams<TConfig>): Promise<WalletFacade>;
|
|
93
131
|
readonly shielded: ShieldedWalletAPI;
|
|
94
132
|
readonly unshielded: UnshieldedWalletAPI;
|
|
@@ -129,7 +167,13 @@ export declare class WalletFacade {
|
|
|
129
167
|
signUnprovenTransaction(tx: ledger.UnprovenTransaction, signSegment: (data: Uint8Array) => ledger.Signature): Promise<ledger.UnprovenTransaction>;
|
|
130
168
|
signUnboundTransaction(tx: UnboundTransaction, signSegment: (data: Uint8Array) => ledger.Signature): Promise<UnboundTransaction>;
|
|
131
169
|
finalizeTransaction(tx: ledger.UnprovenTransaction): Promise<ledger.FinalizedTransaction>;
|
|
170
|
+
/** Estimates the fee for the given transaction only. This lacks the fees of the balancing transaction. */
|
|
132
171
|
calculateTransactionFee(tx: AnyTransaction): Promise<bigint>;
|
|
172
|
+
/** Calculates the total fee for the given transaction plus the fee of the balancing transaction. */
|
|
173
|
+
estimateTransactionFee(tx: AnyTransaction, secretKey: ledger.DustSecretKey, options?: {
|
|
174
|
+
ttl?: Date;
|
|
175
|
+
currentTime?: Date;
|
|
176
|
+
}): Promise<bigint>;
|
|
133
177
|
transferTransaction(outputs: CombinedTokenTransfer[], secretKeys: {
|
|
134
178
|
shieldedSecretKeys: ledger.ZswapSecretKeys;
|
|
135
179
|
dustSecretKey: ledger.DustSecretKey;
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
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-
|
|
13
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
14
14
|
import { makeDefaultSubmissionService, } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
15
15
|
import { makeDefaultProvingService, } from '@midnight-ntwrk/wallet-sdk-capabilities/proving';
|
|
16
|
+
import { FetchTermsAndConditions as FetchTermsAndConditionsQuery } from '@midnight-ntwrk/wallet-sdk-indexer-client';
|
|
17
|
+
import { QueryRunner } from '@midnight-ntwrk/wallet-sdk-indexer-client/effect';
|
|
16
18
|
import { Array as Arr, pipe } from 'effect';
|
|
17
19
|
import { combineLatest, map, firstValueFrom, concatMap } from 'rxjs';
|
|
18
20
|
import { PendingTransactions, PendingTransactionsServiceImpl, } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
@@ -88,6 +90,32 @@ export class WalletFacade {
|
|
|
88
90
|
throw new Error("Missing required configuration: 'provingServerUrl' must be set in config, or provide a custom provingService in init parameters.");
|
|
89
91
|
}
|
|
90
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetches the current Terms and Conditions from the network indexer.
|
|
95
|
+
*
|
|
96
|
+
* This is a static, pre-initialization utility — no wallet instance is required.
|
|
97
|
+
* Wallet builders should call this before or independently of wallet initialization
|
|
98
|
+
* to display the current T&C to end users and obtain the hash for content verification.
|
|
99
|
+
*
|
|
100
|
+
* The returned `hash` is the hex-encoded SHA-256 hash of the document at `url`.
|
|
101
|
+
* Wallet builders are responsible for fetching and rendering the document content
|
|
102
|
+
* via `url` in whatever manner suits their application.
|
|
103
|
+
*
|
|
104
|
+
* @param configuration - An object with an `indexerClientConnection.indexerHttpUrl`.
|
|
105
|
+
* Any wallet configuration that satisfies {@link FetchTermsAndConditionsConfiguration} can be passed directly.
|
|
106
|
+
* @returns A promise resolving to the current {@link TermsAndConditions}, or rejecting if
|
|
107
|
+
* no Terms and Conditions have been set on the network yet.
|
|
108
|
+
*/
|
|
109
|
+
static async fetchTermsAndConditions(configuration) {
|
|
110
|
+
const result = await QueryRunner.runPromise(FetchTermsAndConditionsQuery, {}, {
|
|
111
|
+
url: configuration.indexerClientConnection.indexerHttpUrl,
|
|
112
|
+
});
|
|
113
|
+
const tc = result.block?.systemParameters?.termsAndConditions;
|
|
114
|
+
if (!tc) {
|
|
115
|
+
throw new Error('Terms and Conditions are not currently set on the network.');
|
|
116
|
+
}
|
|
117
|
+
return tc;
|
|
118
|
+
}
|
|
91
119
|
static async init(initParams) {
|
|
92
120
|
const submissionService = await Promise.resolve(initParams.submissionService
|
|
93
121
|
? initParams.submissionService(initParams.configuration)
|
|
@@ -335,9 +363,15 @@ export class WalletFacade {
|
|
|
335
363
|
throw error;
|
|
336
364
|
}
|
|
337
365
|
}
|
|
366
|
+
/** Estimates the fee for the given transaction only. This lacks the fees of the balancing transaction. */
|
|
338
367
|
async calculateTransactionFee(tx) {
|
|
339
368
|
return await this.dust.calculateFee([tx]);
|
|
340
369
|
}
|
|
370
|
+
/** Calculates the total fee for the given transaction plus the fee of the balancing transaction. */
|
|
371
|
+
async estimateTransactionFee(tx, secretKey, options) {
|
|
372
|
+
const ttl = options?.ttl ?? this.defaultTtl();
|
|
373
|
+
return await this.dust.estimateFee(secretKey, [tx], ttl, options?.currentTime);
|
|
374
|
+
}
|
|
341
375
|
async transferTransaction(outputs, secretKeys, options) {
|
|
342
376
|
const { shieldedSecretKeys, dustSecretKey } = secretKeys;
|
|
343
377
|
const { ttl, payFees = true } = options;
|
package/dist/transaction.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PendingTransactions } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
2
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
2
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
3
3
|
export declare const finalizedTransactionTrait: PendingTransactions.TransactionTrait<ledger.FinalizedTransaction>;
|
package/dist/transaction.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { Array as Arr, DateTime, Duration, HashSet, Option, Order, pipe } from 'effect';
|
|
16
|
-
import * as ledger from '@midnight-ntwrk/ledger-
|
|
16
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
17
17
|
export const finalizedTransactionTrait = {
|
|
18
18
|
areAllTxIdsIncluded(tx, txIds) {
|
|
19
19
|
const txIdsSet = HashSet.fromIterable(tx.identifiers());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-facade",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -24,18 +24,19 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@midnight-ntwrk/ledger-
|
|
28
|
-
"@midnight-ntwrk/wallet-sdk-address-format": "^3.0
|
|
29
|
-
"@midnight-ntwrk/wallet-sdk-capabilities": "^3.
|
|
30
|
-
"@midnight-ntwrk/wallet-sdk-dust-wallet": "^
|
|
31
|
-
"@midnight-ntwrk/wallet-sdk-
|
|
32
|
-
"@midnight-ntwrk/wallet-sdk-
|
|
27
|
+
"@midnight-ntwrk/ledger-v8": "^8.0.2",
|
|
28
|
+
"@midnight-ntwrk/wallet-sdk-address-format": "^3.1.0",
|
|
29
|
+
"@midnight-ntwrk/wallet-sdk-capabilities": "^3.2.0",
|
|
30
|
+
"@midnight-ntwrk/wallet-sdk-dust-wallet": "^3.0.0",
|
|
31
|
+
"@midnight-ntwrk/wallet-sdk-indexer-client": "^1.2.0",
|
|
32
|
+
"@midnight-ntwrk/wallet-sdk-shielded": "^2.1.0",
|
|
33
|
+
"@midnight-ntwrk/wallet-sdk-unshielded-wallet": "^2.1.0",
|
|
33
34
|
"rxjs": "^7.8.2"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@midnight-ntwrk/wallet-sdk-abstractions": "^2.0.0",
|
|
37
38
|
"@midnight-ntwrk/wallet-sdk-hd": "^3.0.1",
|
|
38
|
-
"@midnight-ntwrk/wallet-sdk-utilities": "1.0
|
|
39
|
+
"@midnight-ntwrk/wallet-sdk-utilities": "1.1.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"typecheck": "tsc -b ./tsconfig.json --noEmit --force",
|