@dynamic-labs/midnight 4.90.0 → 4.91.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/CHANGELOG.md +36 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -6
- package/src/MidnightWalletConnectors.cjs +6 -0
- package/src/MidnightWalletConnectors.js +6 -0
- package/src/connectors/MidnightWalletConnector.cjs +41 -0
- package/src/connectors/MidnightWalletConnector.d.ts +42 -1
- package/src/connectors/MidnightWalletConnector.js +41 -0
- package/src/index.cjs +8 -6
- package/src/index.d.ts +1 -1
- package/src/index.js +4 -2
- package/src/types.d.ts +11 -2
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.cjs +109 -0
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.d.ts +2 -2
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.js +105 -0
- package/src/waas/DynamicWaasMidnightConnectors.cjs +16 -0
- package/src/waas/DynamicWaasMidnightConnectors.d.ts +6 -0
- package/src/waas/DynamicWaasMidnightConnectors.js +12 -0
- package/src/waas/WaasMidnightWalletConnector.cjs +109 -0
- package/src/waas/WaasMidnightWalletConnector.d.ts +44 -0
- package/src/waas/WaasMidnightWalletConnector.js +105 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.cjs +584 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.d.ts +470 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.js +580 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.cjs +48 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.d.ts +26 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.js +42 -0
- package/src/waas/connector/index.d.ts +1 -0
- package/src/waas/index.d.ts +4 -0
- package/src/waas/isMidnightWallet.cjs +15 -0
- package/src/waas/isMidnightWallet.d.ts +7 -0
- package/src/waas/isMidnightWallet.js +11 -0
- package/src/wallet/MidnightWallet.cjs +31 -0
- package/src/wallet/MidnightWallet.d.ts +15 -0
- package/src/wallet/MidnightWallet.js +31 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
|
|
4
|
+
const toBigIntBalanceMap = (record) => {
|
|
5
|
+
const out = {};
|
|
6
|
+
for (const [tokenType, value] of Object.entries(record)) {
|
|
7
|
+
out[tokenType] = BigInt(value);
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
};
|
|
11
|
+
// Normalizes the cap-tolerant `dust` field to `{ balance, cap }` bigints.
|
|
12
|
+
// cap is 0n on clients that don't yet surface it.
|
|
13
|
+
const normalizeDustBalance = (dust) => typeof dust === 'string'
|
|
14
|
+
? { balance: BigInt(dust), cap: BigInt(0) }
|
|
15
|
+
: { balance: BigInt(dust.balance), cap: BigInt(dust.cap) };
|
|
16
|
+
/**
|
|
17
|
+
* Builds a minimal `ConnectedAPI` adapter for WaaS Midnight wallets so the
|
|
18
|
+
* shared `MidnightWalletConnector` balance methods — which delegate to
|
|
19
|
+
* `getConnectedAPI()` — behave the same as they do for injected wallets.
|
|
20
|
+
*
|
|
21
|
+
* Only the balance dimensions are derivable from MPC state. Address lookups
|
|
22
|
+
* (which need coin/encryption public keys) and transfers use the
|
|
23
|
+
* WaaS-specific paths (server `additionalAddresses` and the 3-step
|
|
24
|
+
* createTransferTransaction → sign → submit flow), so they throw here.
|
|
25
|
+
*/
|
|
26
|
+
const buildMidnightWaasConnectedApi = (getPrivateBalance) => {
|
|
27
|
+
const unsupported = (method) => () => {
|
|
28
|
+
throw new Error(`${method} is not available on WaaS Midnight wallets; use the WaaS-specific flow`);
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
getDustAddress: unsupported('getDustAddress'),
|
|
32
|
+
getDustBalance: () => __awaiter(void 0, void 0, void 0, function* () { return normalizeDustBalance((yield getPrivateBalance()).dust); }),
|
|
33
|
+
getShieldedAddresses: unsupported('getShieldedAddresses'),
|
|
34
|
+
getShieldedBalances: () => __awaiter(void 0, void 0, void 0, function* () { return toBigIntBalanceMap((yield getPrivateBalance()).shielded); }),
|
|
35
|
+
getUnshieldedAddress: unsupported('getUnshieldedAddress'),
|
|
36
|
+
getUnshieldedBalances: () => __awaiter(void 0, void 0, void 0, function* () { return toBigIntBalanceMap((yield getPrivateBalance()).unshielded); }),
|
|
37
|
+
makeTransfer: unsupported('makeTransfer'),
|
|
38
|
+
submitTransaction: unsupported('submitTransaction'),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { buildMidnightWaasConnectedApi, normalizeDustBalance, toBigIntBalanceMap };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DynamicWaasMidnightConnector } from './DynamicWaasMidnightConnector';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DynamicWaasMidnightConnector } from './connector/DynamicWaasMidnightConnector';
|
|
2
|
+
export { DynamicWaasMidnightConnectors } from './DynamicWaasMidnightConnectors';
|
|
3
|
+
export { WaasMidnightWalletConnector } from './WaasMidnightWalletConnector';
|
|
4
|
+
export { isMidnightWallet } from './isMidnightWallet';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var MidnightWallet = require('../wallet/MidnightWallet.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type guard for the Midnight wallet shape returned by `useUserWallets()`.
|
|
10
|
+
* Useful in consumer code (e.g. demo-v2) that needs to narrow a generic
|
|
11
|
+
* `wallet` down to `MidnightWallet` to access chain-specific methods.
|
|
12
|
+
*/
|
|
13
|
+
const isMidnightWallet = (wallet) => wallet instanceof MidnightWallet.MidnightWallet;
|
|
14
|
+
|
|
15
|
+
exports.isMidnightWallet = isMidnightWallet;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MidnightWallet } from '../wallet/MidnightWallet';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for the Midnight wallet shape returned by `useUserWallets()`.
|
|
4
|
+
* Useful in consumer code (e.g. demo-v2) that needs to narrow a generic
|
|
5
|
+
* `wallet` down to `MidnightWallet` to access chain-specific methods.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isMidnightWallet: (wallet: unknown) => wallet is MidnightWallet;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { MidnightWallet } from '../wallet/MidnightWallet.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for the Midnight wallet shape returned by `useUserWallets()`.
|
|
6
|
+
* Useful in consumer code (e.g. demo-v2) that needs to narrow a generic
|
|
7
|
+
* `wallet` down to `MidnightWallet` to access chain-specific methods.
|
|
8
|
+
*/
|
|
9
|
+
const isMidnightWallet = (wallet) => wallet instanceof MidnightWallet;
|
|
10
|
+
|
|
11
|
+
export { isMidnightWallet };
|
|
@@ -76,6 +76,8 @@ class MidnightWallet extends walletConnectorCore.Wallet {
|
|
|
76
76
|
dustBalance: dustEmpty
|
|
77
77
|
? undefined
|
|
78
78
|
: formatMidnightConnectorDustBalance.formatMidnightConnectorDustBalance(raw.dust.balance, raw.dust.cap),
|
|
79
|
+
// Passthrough (undefined for injected/external wallets, which omit it).
|
|
80
|
+
dustSyncing: raw.dustSyncing,
|
|
79
81
|
shieldedBalance: shieldedRaw !== undefined
|
|
80
82
|
? formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(shieldedRaw)
|
|
81
83
|
: undefined,
|
|
@@ -85,6 +87,35 @@ class MidnightWallet extends walletConnectorCore.Wallet {
|
|
|
85
87
|
};
|
|
86
88
|
});
|
|
87
89
|
}
|
|
90
|
+
// Exclusive for embedded Midnight wallets
|
|
91
|
+
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
92
|
+
createTransferTransaction(...args) {
|
|
93
|
+
return this._connector.createTransferTransaction(...args);
|
|
94
|
+
}
|
|
95
|
+
/** Signs and ZK-proves an unsigned transaction via MPC (step 2). */
|
|
96
|
+
signTransaction(...args) {
|
|
97
|
+
return this._connector.signTransaction(...args);
|
|
98
|
+
}
|
|
99
|
+
/** Broadcasts a finalized transaction (step 3). */
|
|
100
|
+
submitTransaction(...args) {
|
|
101
|
+
return this._connector.submitTransaction(...args);
|
|
102
|
+
}
|
|
103
|
+
/** Registers the wallet's NIGHT for DUST generation. */
|
|
104
|
+
registerDust(...args) {
|
|
105
|
+
return this._connector.registerDust(...args);
|
|
106
|
+
}
|
|
107
|
+
/** Releases the reserved inputs of a specific built/signed transaction. */
|
|
108
|
+
revertTransaction(...args) {
|
|
109
|
+
return this._connector.revertTransaction(...args);
|
|
110
|
+
}
|
|
111
|
+
/** Releases every finalized-but-unsubmitted transaction's reserved inputs. */
|
|
112
|
+
revertAllPending(...args) {
|
|
113
|
+
return this._connector.revertAllPending(...args);
|
|
114
|
+
}
|
|
115
|
+
/** Clears the wallet's persisted state and forces a cold re-sync. */
|
|
116
|
+
resetWalletCache(...args) {
|
|
117
|
+
return this._connector.resetWalletCache(...args);
|
|
118
|
+
}
|
|
88
119
|
}
|
|
89
120
|
|
|
90
121
|
exports.MidnightWallet = MidnightWallet;
|
|
@@ -20,6 +20,7 @@ export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
|
20
20
|
cap: bigint;
|
|
21
21
|
balance: bigint;
|
|
22
22
|
};
|
|
23
|
+
dustSyncing?: boolean;
|
|
23
24
|
}>;
|
|
24
25
|
getShieldedBalance(): Promise<string | undefined>;
|
|
25
26
|
getUnshieldedBalance(): Promise<string | undefined>;
|
|
@@ -28,4 +29,18 @@ export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
|
28
29
|
cap: string;
|
|
29
30
|
}>;
|
|
30
31
|
getFormattedBalances(): Promise<MidnightFormattedBalances>;
|
|
32
|
+
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
33
|
+
createTransferTransaction(...args: Parameters<MidnightWalletConnector['createTransferTransaction']>): ReturnType<MidnightWalletConnector['createTransferTransaction']>;
|
|
34
|
+
/** Signs and ZK-proves an unsigned transaction via MPC (step 2). */
|
|
35
|
+
signTransaction(...args: Parameters<MidnightWalletConnector['signTransaction']>): ReturnType<MidnightWalletConnector['signTransaction']>;
|
|
36
|
+
/** Broadcasts a finalized transaction (step 3). */
|
|
37
|
+
submitTransaction(...args: Parameters<MidnightWalletConnector['submitTransaction']>): ReturnType<MidnightWalletConnector['submitTransaction']>;
|
|
38
|
+
/** Registers the wallet's NIGHT for DUST generation. */
|
|
39
|
+
registerDust(...args: Parameters<MidnightWalletConnector['registerDust']>): ReturnType<MidnightWalletConnector['registerDust']>;
|
|
40
|
+
/** Releases the reserved inputs of a specific built/signed transaction. */
|
|
41
|
+
revertTransaction(...args: Parameters<MidnightWalletConnector['revertTransaction']>): ReturnType<MidnightWalletConnector['revertTransaction']>;
|
|
42
|
+
/** Releases every finalized-but-unsubmitted transaction's reserved inputs. */
|
|
43
|
+
revertAllPending(...args: Parameters<MidnightWalletConnector['revertAllPending']>): ReturnType<MidnightWalletConnector['revertAllPending']>;
|
|
44
|
+
/** Clears the wallet's persisted state and forces a cold re-sync. */
|
|
45
|
+
resetWalletCache(...args: Parameters<MidnightWalletConnector['resetWalletCache']>): ReturnType<MidnightWalletConnector['resetWalletCache']>;
|
|
31
46
|
}
|
|
@@ -72,6 +72,8 @@ class MidnightWallet extends Wallet {
|
|
|
72
72
|
dustBalance: dustEmpty
|
|
73
73
|
? undefined
|
|
74
74
|
: formatMidnightConnectorDustBalance(raw.dust.balance, raw.dust.cap),
|
|
75
|
+
// Passthrough (undefined for injected/external wallets, which omit it).
|
|
76
|
+
dustSyncing: raw.dustSyncing,
|
|
75
77
|
shieldedBalance: shieldedRaw !== undefined
|
|
76
78
|
? formatMidnightNativeUnshieldedBalance(shieldedRaw)
|
|
77
79
|
: undefined,
|
|
@@ -81,6 +83,35 @@ class MidnightWallet extends Wallet {
|
|
|
81
83
|
};
|
|
82
84
|
});
|
|
83
85
|
}
|
|
86
|
+
// Exclusive for embedded Midnight wallets
|
|
87
|
+
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
88
|
+
createTransferTransaction(...args) {
|
|
89
|
+
return this._connector.createTransferTransaction(...args);
|
|
90
|
+
}
|
|
91
|
+
/** Signs and ZK-proves an unsigned transaction via MPC (step 2). */
|
|
92
|
+
signTransaction(...args) {
|
|
93
|
+
return this._connector.signTransaction(...args);
|
|
94
|
+
}
|
|
95
|
+
/** Broadcasts a finalized transaction (step 3). */
|
|
96
|
+
submitTransaction(...args) {
|
|
97
|
+
return this._connector.submitTransaction(...args);
|
|
98
|
+
}
|
|
99
|
+
/** Registers the wallet's NIGHT for DUST generation. */
|
|
100
|
+
registerDust(...args) {
|
|
101
|
+
return this._connector.registerDust(...args);
|
|
102
|
+
}
|
|
103
|
+
/** Releases the reserved inputs of a specific built/signed transaction. */
|
|
104
|
+
revertTransaction(...args) {
|
|
105
|
+
return this._connector.revertTransaction(...args);
|
|
106
|
+
}
|
|
107
|
+
/** Releases every finalized-but-unsubmitted transaction's reserved inputs. */
|
|
108
|
+
revertAllPending(...args) {
|
|
109
|
+
return this._connector.revertAllPending(...args);
|
|
110
|
+
}
|
|
111
|
+
/** Clears the wallet's persisted state and forces a cold re-sync. */
|
|
112
|
+
resetWalletCache(...args) {
|
|
113
|
+
return this._connector.resetWalletCache(...args);
|
|
114
|
+
}
|
|
84
115
|
}
|
|
85
116
|
|
|
86
117
|
export { MidnightWallet };
|