@midnight-ntwrk/wallet-sdk-facade 1.0.0-beta.11 → 1.0.0-beta.13
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 +8 -3
- package/dist/index.js +12 -14
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { ShieldedWalletState, type ShieldedWallet } from '@midnight-ntwrk/wallet-sdk-shielded';
|
|
3
3
|
import { type UnshieldedWallet, UnshieldedWalletState } from '@midnight-ntwrk/wallet-sdk-unshielded-wallet';
|
|
4
|
-
import { type Utxo } from '@midnight-ntwrk/wallet-sdk-unshielded-state';
|
|
5
4
|
import { AnyTransaction, DustWallet, DustWalletState } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
|
|
6
5
|
import { ProvingRecipe } from '@midnight-ntwrk/wallet-sdk-shielded/v1';
|
|
7
6
|
import * as ledger from '@midnight-ntwrk/ledger-v6';
|
|
@@ -20,6 +19,12 @@ export type CombinedSwapInputs = {
|
|
|
20
19
|
};
|
|
21
20
|
export type CombinedSwapOutputs = CombinedTokenTransfer;
|
|
22
21
|
export type TransactionIdentifier = string;
|
|
22
|
+
export type UtxoWithMeta = {
|
|
23
|
+
utxo: ledger.Utxo;
|
|
24
|
+
meta: {
|
|
25
|
+
ctime: Date;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
23
28
|
export declare class FacadeState {
|
|
24
29
|
readonly shielded: ShieldedWalletState;
|
|
25
30
|
readonly unshielded: UnshieldedWalletState;
|
|
@@ -39,9 +44,9 @@ export declare class WalletFacade {
|
|
|
39
44
|
signTransaction(tx: ledger.UnprovenTransaction, signSegment: (data: Uint8Array) => ledger.Signature): Promise<ledger.UnprovenTransaction>;
|
|
40
45
|
calculateTransactionFee(tx: AnyTransaction): Promise<bigint>;
|
|
41
46
|
transferTransaction(zswapSecretKeys: ledger.ZswapSecretKeys, dustSecretKey: ledger.DustSecretKey, outputs: CombinedTokenTransfer[], ttl: Date): Promise<ProvingRecipe.TransactionToProve>;
|
|
42
|
-
registerNightUtxosForDustGeneration(nightUtxos: readonly
|
|
47
|
+
registerNightUtxosForDustGeneration(nightUtxos: readonly UtxoWithMeta[], nightVerifyingKey: ledger.SignatureVerifyingKey, signDustRegistration: (payload: Uint8Array) => Promise<ledger.Signature> | ledger.Signature, dustReceiverAddress?: string): Promise<ProvingRecipe.TransactionToProve>;
|
|
43
48
|
initSwap(zswapSecretKeys: ledger.ZswapSecretKeys, desiredInputs: CombinedSwapInputs, desiredOutputs: CombinedSwapOutputs[], ttl: Date): Promise<ledger.UnprovenTransaction>;
|
|
44
|
-
deregisterFromDustGeneration(nightUtxos:
|
|
49
|
+
deregisterFromDustGeneration(nightUtxos: UtxoWithMeta[], nightVerifyingKey: ledger.SignatureVerifyingKey, signDustRegistration: (payload: Uint8Array) => Promise<ledger.Signature> | ledger.Signature): Promise<ProvingRecipe.TransactionToProve>;
|
|
45
50
|
start(zswapSecretKeys: ledger.ZswapSecretKeys, dustSecretKey: ledger.DustSecretKey): Promise<void>;
|
|
46
51
|
stop(): Promise<void>;
|
|
47
52
|
}
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export class FacadeState {
|
|
|
19
19
|
get isSynced() {
|
|
20
20
|
return (this.shielded.state.progress.isStrictlyComplete() &&
|
|
21
21
|
this.dust.state.progress.isStrictlyComplete() &&
|
|
22
|
-
this.unshielded.
|
|
22
|
+
this.unshielded.progress.isStrictlyComplete());
|
|
23
23
|
}
|
|
24
24
|
constructor(shielded, unshielded, dust) {
|
|
25
25
|
this.shielded = shielded;
|
|
@@ -37,7 +37,7 @@ export class WalletFacade {
|
|
|
37
37
|
this.dust = dustWallet;
|
|
38
38
|
}
|
|
39
39
|
state() {
|
|
40
|
-
return combineLatest([this.shielded.state, this.unshielded.state
|
|
40
|
+
return combineLatest([this.shielded.state, this.unshielded.state, this.dust.state]).pipe(map(([shieldedState, unshieldedState, dustState]) => new FacadeState(shieldedState, unshieldedState, dustState)));
|
|
41
41
|
}
|
|
42
42
|
async submitTransaction(tx) {
|
|
43
43
|
await this.shielded.submitTransaction(tx, 'Finalized');
|
|
@@ -48,10 +48,10 @@ export class WalletFacade {
|
|
|
48
48
|
const recipe = await this.shielded.balanceTransaction(zswapSecretKeys, unshieldedBalancedTx, []);
|
|
49
49
|
switch (recipe.type) {
|
|
50
50
|
case ProvingRecipe.TRANSACTION_TO_PROVE:
|
|
51
|
-
return await this.dust.addFeePayment(dustSecretKeys, recipe.transaction,
|
|
51
|
+
return await this.dust.addFeePayment(dustSecretKeys, recipe.transaction, ttl);
|
|
52
52
|
case ProvingRecipe.BALANCE_TRANSACTION_TO_PROVE: {
|
|
53
53
|
// if the shielded wallet returned a proven transaction, we need to pay fees with the dust wallet
|
|
54
|
-
const balancedTx = await this.dust.addFeePayment(dustSecretKeys, recipe.transactionToProve,
|
|
54
|
+
const balancedTx = await this.dust.addFeePayment(dustSecretKeys, recipe.transactionToProve, ttl);
|
|
55
55
|
if (balancedTx.type !== ProvingRecipe.TRANSACTION_TO_PROVE) {
|
|
56
56
|
throw Error('Unexpected transaction type after adding fee payment.');
|
|
57
57
|
}
|
|
@@ -63,7 +63,7 @@ export class WalletFacade {
|
|
|
63
63
|
case ProvingRecipe.NOTHING_TO_PROVE: {
|
|
64
64
|
// @TODO fix casting
|
|
65
65
|
const txToBalance = recipe.transaction;
|
|
66
|
-
return await this.dust.addFeePayment(dustSecretKeys, txToBalance,
|
|
66
|
+
return await this.dust.addFeePayment(dustSecretKeys, txToBalance, ttl);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -97,7 +97,7 @@ export class WalletFacade {
|
|
|
97
97
|
if (shieldedTxRecipe.type !== 'TransactionToProve') {
|
|
98
98
|
throw Error('Unexpected transaction type.');
|
|
99
99
|
}
|
|
100
|
-
const recipe = await this.dust.addFeePayment(dustSecretKey, shieldedTxRecipe.transaction,
|
|
100
|
+
const recipe = await this.dust.addFeePayment(dustSecretKey, shieldedTxRecipe.transaction, ttl);
|
|
101
101
|
if (recipe.type !== 'TransactionToProve') {
|
|
102
102
|
throw Error('Unexpected transaction type after adding fee payment.');
|
|
103
103
|
}
|
|
@@ -105,7 +105,7 @@ export class WalletFacade {
|
|
|
105
105
|
}
|
|
106
106
|
// if there's an unshielded tx only, pay fees (balance) with shielded wallet
|
|
107
107
|
if (shieldedTxRecipe === undefined && unshieldedTx !== undefined) {
|
|
108
|
-
const recipe = await this.dust.addFeePayment(dustSecretKey, unshieldedTx,
|
|
108
|
+
const recipe = await this.dust.addFeePayment(dustSecretKey, unshieldedTx, ttl);
|
|
109
109
|
if (recipe.type !== 'TransactionToProve') {
|
|
110
110
|
throw Error('Unexpected transaction type after adding fee payment.');
|
|
111
111
|
}
|
|
@@ -117,7 +117,7 @@ export class WalletFacade {
|
|
|
117
117
|
throw Error('Unexpected transaction type.');
|
|
118
118
|
}
|
|
119
119
|
const txToBalance = shieldedTxRecipe.transaction.merge(unshieldedTx);
|
|
120
|
-
const recipe = await this.dust.addFeePayment(dustSecretKey, txToBalance,
|
|
120
|
+
const recipe = await this.dust.addFeePayment(dustSecretKey, txToBalance, ttl);
|
|
121
121
|
if (recipe.type !== 'TransactionToProve') {
|
|
122
122
|
throw Error('Unexpected transaction type after adding fee payment.');
|
|
123
123
|
}
|
|
@@ -131,9 +131,8 @@ export class WalletFacade {
|
|
|
131
131
|
}
|
|
132
132
|
const dustState = await this.dust.waitForSyncedState();
|
|
133
133
|
const receiverAddress = dustReceiverAddress ?? dustState.dustAddress;
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const transaction = await this.dust.createDustGenerationTransaction(nextBlock, ttl, nightUtxos.map((utxo) => ({ ...utxo, ctime: new Date(utxo.ctime) })), nightVerifyingKey, receiverAddress);
|
|
134
|
+
const ttl = new Date(Date.now() + 60 * 60 * 1000);
|
|
135
|
+
const transaction = await this.dust.createDustGenerationTransaction(undefined, ttl, nightUtxos.map(({ utxo, meta }) => ({ ...utxo, ctime: meta.ctime })), nightVerifyingKey, receiverAddress);
|
|
137
136
|
const intent = transaction.intents?.get(1);
|
|
138
137
|
if (!intent) {
|
|
139
138
|
throw Error('Dust generation transaction is missing intent segment 1.');
|
|
@@ -180,9 +179,8 @@ export class WalletFacade {
|
|
|
180
179
|
throw Error('Unexpected transaction state.');
|
|
181
180
|
}
|
|
182
181
|
async deregisterFromDustGeneration(nightUtxos, nightVerifyingKey, signDustRegistration) {
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const transaction = await this.dust.createDustGenerationTransaction(nextBlock, ttl, nightUtxos.map((utxo) => ({ ...utxo, ctime: new Date(utxo.ctime) })), nightVerifyingKey, undefined);
|
|
182
|
+
const ttl = new Date(Date.now() + 60 * 60 * 1000);
|
|
183
|
+
const transaction = await this.dust.createDustGenerationTransaction(undefined, ttl, nightUtxos.map(({ utxo, meta }) => ({ ...utxo, ctime: meta.ctime })), nightVerifyingKey, undefined);
|
|
186
184
|
const intent = transaction.intents?.get(1);
|
|
187
185
|
if (!intent) {
|
|
188
186
|
throw Error('Dust generation transaction is missing intent segment 1.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-facade",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@midnight-ntwrk/ledger-v6": "6.1.0-alpha.6",
|
|
28
28
|
"@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0-beta.9",
|
|
29
29
|
"@midnight-ntwrk/wallet-sdk-address-format": "3.0.0-beta.9",
|
|
30
|
-
"@midnight-ntwrk/wallet-sdk-dust-wallet": "1.0.0-beta.
|
|
30
|
+
"@midnight-ntwrk/wallet-sdk-dust-wallet": "1.0.0-beta.12",
|
|
31
31
|
"@midnight-ntwrk/wallet-sdk-hd": "3.0.0-beta.7",
|
|
32
|
-
"@midnight-ntwrk/wallet-sdk-shielded": "1.0.0-beta.
|
|
33
|
-
"@midnight-ntwrk/wallet-sdk-unshielded-wallet": "1.0.0-beta.
|
|
32
|
+
"@midnight-ntwrk/wallet-sdk-shielded": "1.0.0-beta.13",
|
|
33
|
+
"@midnight-ntwrk/wallet-sdk-unshielded-wallet": "1.0.0-beta.15",
|
|
34
34
|
"rxjs": "^7.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"typecheck": "tsc -b ./tsconfig.json --noEmit",
|
|
46
46
|
"test": "vitest run",
|
|
47
47
|
"lint": "eslint --max-warnings 0",
|
|
48
|
-
"format": "prettier --write \"**/*.{ts,js,json,yaml,yml}\"",
|
|
49
|
-
"format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml}\"",
|
|
48
|
+
"format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
49
|
+
"format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
50
50
|
"dist": "tsc -b ./tsconfig.build.json",
|
|
51
51
|
"dist:publish": "tsc -b ./tsconfig.publish.json",
|
|
52
52
|
"clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
|