@midnight-ntwrk/wallet-sdk-facade 2.0.0-rc.1 → 2.0.0-rc.3

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as ledger from '@midnight-ntwrk/ledger-v7';
2
2
  import { type DefaultSubmissionConfiguration, type SubmissionService } from '@midnight-ntwrk/wallet-sdk-capabilities';
3
+ import { type DefaultProvingConfiguration, type ProvingService, type UnboundTransaction } from '@midnight-ntwrk/wallet-sdk-capabilities/proving';
3
4
  import { type AnyTransaction, type DefaultDustConfiguration, type CoinsAndBalances as DustCoinsAndBalances, type DustWalletAPI, type DustWalletState } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
4
5
  import { type DefaultShieldedConfiguration, type ShieldedWalletAPI, type ShieldedWalletState } from '@midnight-ntwrk/wallet-sdk-shielded';
5
6
  import type { DefaultUnshieldedConfiguration, UnshieldedWalletAPI } from '@midnight-ntwrk/wallet-sdk-unshielded-wallet';
6
7
  import { type UnshieldedWalletState } from '@midnight-ntwrk/wallet-sdk-unshielded-wallet';
7
8
  import { type Observable } from 'rxjs';
8
- import { DefaultPendingTransactionsServiceConfiguration, PendingTransactions, PendingTransactionsService, PendingTransactionsServiceImpl } from '@midnight-ntwrk/wallet-sdk-capabilities';
9
+ import { DefaultPendingTransactionsServiceConfiguration, PendingTransactions, PendingTransactionsService } from '@midnight-ntwrk/wallet-sdk-capabilities';
9
10
  import { DustAddress, ShieldedAddress, UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
10
- export type UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
11
11
  type TokenKind = 'dust' | 'shielded' | 'unshielded';
12
12
  type TokenKindsToBalance = 'all' | TokenKind[];
13
13
  declare const TokenKindsToBalance: {
@@ -61,6 +61,7 @@ export type UtxoWithMeta = {
61
61
  utxo: ledger.Utxo;
62
62
  meta: {
63
63
  ctime: Date;
64
+ registeredForDustGeneration: boolean;
64
65
  };
65
66
  };
66
67
  export declare class FacadeState {
@@ -71,26 +72,29 @@ export declare class FacadeState {
71
72
  get isSynced(): boolean;
72
73
  constructor(shielded: ShieldedWalletState, unshielded: UnshieldedWalletState, dust: DustWalletState, pending: PendingTransactions.PendingTransactions<ledger.FinalizedTransaction>);
73
74
  }
74
- export type DefaultConfiguration = DefaultUnshieldedConfiguration & DefaultShieldedConfiguration & DefaultDustConfiguration & DefaultSubmissionConfiguration & DefaultPendingTransactionsServiceConfiguration;
75
+ export type DefaultConfiguration = DefaultUnshieldedConfiguration & DefaultShieldedConfiguration & DefaultDustConfiguration & DefaultSubmissionConfiguration & DefaultPendingTransactionsServiceConfiguration & Partial<DefaultProvingConfiguration>;
75
76
  type MaybePromise<T> = T | Promise<T>;
76
77
  export type InitParams<TConfig extends DefaultConfiguration> = {
77
78
  configuration: TConfig;
78
79
  submissionService?: (config: TConfig) => MaybePromise<SubmissionService<ledger.FinalizedTransaction>>;
79
80
  pendingTransactionsService?: (config: TConfig) => MaybePromise<PendingTransactionsService<ledger.FinalizedTransaction>>;
81
+ provingService?: (config: TConfig) => MaybePromise<ProvingService<UnboundTransaction>>;
80
82
  shielded: (config: TConfig) => MaybePromise<ShieldedWalletAPI>;
81
83
  unshielded: (config: TConfig) => MaybePromise<UnshieldedWalletAPI>;
82
84
  dust: (config: TConfig) => MaybePromise<DustWalletAPI>;
83
85
  };
84
86
  export declare class WalletFacade {
85
87
  #private;
86
- static makeDefaultSubmissionService<TConfig extends DefaultSubmissionConfiguration>(config: TConfig): SubmissionService<ledger.FinalizedTransaction>;
87
- static makeDefaultPendingTransactionsService<TConfig extends DefaultPendingTransactionsServiceConfiguration>(config: TConfig): Promise<PendingTransactionsServiceImpl<ledger.FinalizedTransaction>>;
88
+ private static makeDefaultSubmissionService;
89
+ private static makeDefaultPendingTransactionsService;
90
+ private static makeDefaultProvingService;
88
91
  static init<TConfig extends DefaultConfiguration>(initParams: InitParams<TConfig>): Promise<WalletFacade>;
89
92
  readonly shielded: ShieldedWalletAPI;
90
93
  readonly unshielded: UnshieldedWalletAPI;
91
94
  readonly dust: DustWalletAPI;
92
95
  readonly submissionService: SubmissionService<ledger.FinalizedTransaction>;
93
96
  readonly pendingTransactionsService: PendingTransactionsService<ledger.FinalizedTransaction>;
97
+ readonly provingService: ProvingService<UnboundTransaction>;
94
98
  private constructor();
95
99
  private defaultTtl;
96
100
  private mergeUnprovenTransactions;
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@
12
12
  // limitations under the License.
13
13
  import * as ledger from '@midnight-ntwrk/ledger-v7';
14
14
  import { makeDefaultSubmissionService, } from '@midnight-ntwrk/wallet-sdk-capabilities';
15
+ import { makeDefaultProvingService, } from '@midnight-ntwrk/wallet-sdk-capabilities/proving';
15
16
  import { Array as Arr, pipe } from 'effect';
16
17
  import { combineLatest, map, firstValueFrom, concatMap } from 'rxjs';
17
18
  import { PendingTransactions, PendingTransactionsServiceImpl, } from '@midnight-ntwrk/wallet-sdk-capabilities';
@@ -77,6 +78,16 @@ export class WalletFacade {
77
78
  txTrait: finalizedTransactionTrait,
78
79
  });
79
80
  }
81
+ static makeDefaultProvingService(config) {
82
+ if (config.provingServerUrl) {
83
+ return makeDefaultProvingService({
84
+ provingServerUrl: config.provingServerUrl,
85
+ });
86
+ }
87
+ else {
88
+ throw new Error("Missing required configuration: 'provingServerUrl' must be set in config, or provide a custom provingService in init parameters.");
89
+ }
90
+ }
80
91
  static async init(initParams) {
81
92
  const submissionService = await Promise.resolve(initParams.submissionService
82
93
  ? initParams.submissionService(initParams.configuration)
@@ -84,23 +95,28 @@ export class WalletFacade {
84
95
  const pendingTransactionsService = await Promise.resolve(initParams.pendingTransactionsService
85
96
  ? initParams.pendingTransactionsService(initParams.configuration)
86
97
  : WalletFacade.makeDefaultPendingTransactionsService(initParams.configuration));
98
+ const provingService = await Promise.resolve(initParams.provingService
99
+ ? initParams.provingService(initParams.configuration)
100
+ : WalletFacade.makeDefaultProvingService(initParams.configuration));
87
101
  const shielded = await Promise.resolve(initParams.shielded(initParams.configuration));
88
102
  const unshielded = await Promise.resolve(initParams.unshielded(initParams.configuration));
89
103
  const dust = await Promise.resolve(initParams.dust(initParams.configuration));
90
- return new WalletFacade(shielded, unshielded, dust, submissionService, pendingTransactionsService);
104
+ return new WalletFacade(shielded, unshielded, dust, submissionService, pendingTransactionsService, provingService);
91
105
  }
92
106
  shielded;
93
107
  unshielded;
94
108
  dust;
95
109
  submissionService;
96
110
  pendingTransactionsService;
111
+ provingService;
97
112
  #pendingSubscription;
98
- constructor(shieldedWallet, unshieldedWallet, dustWallet, submissionService, pendingTransactionsService) {
113
+ constructor(shieldedWallet, unshieldedWallet, dustWallet, submissionService, pendingTransactionsService, provingService) {
99
114
  this.shielded = shieldedWallet;
100
115
  this.unshielded = unshieldedWallet;
101
116
  this.dust = dustWallet;
102
117
  this.submissionService = submissionService;
103
118
  this.pendingTransactionsService = pendingTransactionsService;
119
+ this.provingService = provingService;
104
120
  this.#pendingSubscription = this.pendingTransactionsService
105
121
  .state()
106
122
  .pipe(concatMap((pending) => PendingTransactions.allFailed(pending)), concatMap((item) => this.revert(item.tx)))
@@ -116,7 +132,11 @@ export class WalletFacade {
116
132
  }
117
133
  async createDustActionTransaction(action, nightUtxos, nightVerifyingKey, signDustRegistration) {
118
134
  const ttl = this.defaultTtl();
119
- const transaction = await this.dust.createDustGenerationTransaction(undefined, ttl, nightUtxos.map(({ utxo, meta }) => ({ ...utxo, ctime: meta.ctime })), nightVerifyingKey, action.type === 'registration' ? action.dustReceiverAddress : undefined);
135
+ const transaction = await this.dust.createDustGenerationTransaction(undefined, ttl, nightUtxos.map(({ utxo, meta }) => ({
136
+ ...utxo,
137
+ ctime: meta.ctime,
138
+ registeredForDustGeneration: meta.registeredForDustGeneration,
139
+ })), nightVerifyingKey, action.type === 'registration' ? action.dustReceiverAddress : undefined);
120
140
  const intent = transaction.intents?.get(1);
121
141
  if (!intent) {
122
142
  throw Error('Dust generation transaction is missing intent segment 1.');
@@ -300,9 +320,20 @@ export class WalletFacade {
300
320
  return await this.unshielded.signUnboundTransaction(tx, signSegment);
301
321
  }
302
322
  async finalizeTransaction(tx) {
303
- const finalizedTx = await this.shielded.finalizeTransaction(tx);
304
- await this.pendingTransactionsService.addPendingTransaction(finalizedTx);
305
- return finalizedTx;
323
+ try {
324
+ const unboundTx = await this.provingService.prove(tx);
325
+ const finalizedTx = unboundTx.bind();
326
+ await this.pendingTransactionsService.addPendingTransaction(finalizedTx);
327
+ return finalizedTx;
328
+ }
329
+ catch (error) {
330
+ await Promise.allSettled([
331
+ this.shielded.revertTransaction(tx),
332
+ this.unshielded.revertTransaction(tx),
333
+ this.dust.revertTransaction(tx),
334
+ ]);
335
+ throw error;
336
+ }
306
337
  }
307
338
  async calculateTransactionFee(tx) {
308
339
  return await this.dust.calculateFee([tx]);
@@ -338,7 +369,11 @@ export class WalletFacade {
338
369
  async estimateRegistration(nightUtxos) {
339
370
  const now = new Date();
340
371
  const dustState = await this.dust.waitForSyncedState();
341
- const dustGenerationEstimations = pipe(nightUtxos, Arr.map(({ utxo, meta }) => ({ ...utxo, ctime: meta.ctime })), (utxosWithMeta) => dustState.estimateDustGeneration(utxosWithMeta, now), (estimatedUtxos) => dustState.capabilities.coinsAndBalances.splitNightUtxos(estimatedUtxos), (split) => split.guaranteed);
372
+ const dustGenerationEstimations = pipe(nightUtxos, Arr.map(({ utxo, meta }) => ({
373
+ ...utxo,
374
+ ctime: meta.ctime,
375
+ registeredForDustGeneration: meta.registeredForDustGeneration,
376
+ })), (utxosWithMeta) => dustState.estimateDustGeneration(utxosWithMeta, now), (estimatedUtxos) => dustState.capabilities.coinsAndBalances.splitNightUtxos(estimatedUtxos), (split) => split.guaranteed);
342
377
  const fakeSigningKey = ledger.sampleSigningKey();
343
378
  const fakeVerifyingKey = ledger.signatureVerifyingKey(fakeSigningKey);
344
379
  const fakeRegistrationRecipe = await this.registerNightUtxosForDustGeneration(nightUtxos, fakeVerifyingKey, (payload) => ledger.signData(fakeSigningKey, payload), dustState.address);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-facade",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -25,17 +25,17 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@midnight-ntwrk/ledger-v7": "^7.0.0",
28
- "@midnight-ntwrk/wallet-sdk-abstractions": "^2.0.0-rc.0",
29
28
  "@midnight-ntwrk/wallet-sdk-address-format": "^3.0.0",
30
- "@midnight-ntwrk/wallet-sdk-capabilities": "^3.1.0-rc.1",
31
- "@midnight-ntwrk/wallet-sdk-dust-wallet": "^2.0.0-rc.1",
32
- "@midnight-ntwrk/wallet-sdk-hd": "^3.0.0",
33
- "@midnight-ntwrk/wallet-sdk-shielded": "^2.0.0-rc.1",
34
- "@midnight-ntwrk/wallet-sdk-unshielded-wallet": "^2.0.0-rc.1",
29
+ "@midnight-ntwrk/wallet-sdk-capabilities": "^3.1.0-rc.2",
30
+ "@midnight-ntwrk/wallet-sdk-dust-wallet": "^2.0.0-rc.3",
31
+ "@midnight-ntwrk/wallet-sdk-shielded": "^2.0.0-rc.2",
32
+ "@midnight-ntwrk/wallet-sdk-unshielded-wallet": "^2.0.0-rc.2",
35
33
  "rxjs": "^7.5"
36
34
  },
37
35
  "devDependencies": {
38
- "@midnight-ntwrk/wallet-sdk-prover-client": "^1.1.0-rc.1",
36
+ "@midnight-ntwrk/wallet-sdk-abstractions": "^2.0.0-rc.1",
37
+ "@midnight-ntwrk/wallet-sdk-hd": "^3.0.0",
38
+ "@midnight-ntwrk/wallet-sdk-prover-client": "^1.1.0-rc.2",
39
39
  "eslint": "^9.37.0",
40
40
  "prettier": "^3.7.0",
41
41
  "publint": "~0.3.14",