@dynamic-labs/midnight 4.89.0 → 4.91.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +9 -7
  5. package/src/MidnightWalletConnectors.cjs +6 -0
  6. package/src/MidnightWalletConnectors.js +6 -0
  7. package/src/connectors/MidnightWalletConnector.cjs +12 -0
  8. package/src/connectors/MidnightWalletConnector.d.ts +6 -1
  9. package/src/connectors/MidnightWalletConnector.js +12 -0
  10. package/src/index.cjs +8 -6
  11. package/src/index.d.ts +1 -1
  12. package/src/index.js +4 -2
  13. package/src/types.d.ts +11 -2
  14. package/src/utils/MidnightUiTransaction/MidnightUiTransaction.cjs +109 -0
  15. package/src/utils/MidnightUiTransaction/MidnightUiTransaction.d.ts +2 -2
  16. package/src/utils/MidnightUiTransaction/MidnightUiTransaction.js +105 -0
  17. package/src/waas/DynamicWaasMidnightConnectors.cjs +16 -0
  18. package/src/waas/DynamicWaasMidnightConnectors.d.ts +6 -0
  19. package/src/waas/DynamicWaasMidnightConnectors.js +12 -0
  20. package/src/waas/WaasMidnightWalletConnector.cjs +109 -0
  21. package/src/waas/WaasMidnightWalletConnector.d.ts +44 -0
  22. package/src/waas/WaasMidnightWalletConnector.js +105 -0
  23. package/src/waas/connector/DynamicWaasMidnightConnector.cjs +571 -0
  24. package/src/waas/connector/DynamicWaasMidnightConnector.d.ts +444 -0
  25. package/src/waas/connector/DynamicWaasMidnightConnector.js +567 -0
  26. package/src/waas/connector/buildMidnightWaasConnectedApi.cjs +48 -0
  27. package/src/waas/connector/buildMidnightWaasConnectedApi.d.ts +26 -0
  28. package/src/waas/connector/buildMidnightWaasConnectedApi.js +42 -0
  29. package/src/waas/connector/index.d.ts +1 -0
  30. package/src/waas/index.d.ts +4 -0
  31. package/src/waas/isMidnightWallet.cjs +15 -0
  32. package/src/waas/isMidnightWallet.d.ts +7 -0
  33. package/src/waas/isMidnightWallet.js +11 -0
  34. package/src/wallet/MidnightWallet.cjs +2 -0
  35. package/src/wallet/MidnightWallet.js +2 -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,
@@ -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,