@dynamic-labs/midnight 4.90.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 +17 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +8 -6
  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
package/CHANGELOG.md CHANGED
@@ -1,4 +1,21 @@
1
1
 
2
+ ## [4.91.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.90.0...v4.91.0) (2026-06-23)
3
+
4
+
5
+ ### Features
6
+
7
+ * **midnight:** add WaaS layer to @dynamic-labs/midnight ([#11006](https://github.com/dynamic-labs/dynamic-auth/issues/11006)) ([01b9d16](https://github.com/dynamic-labs/dynamic-auth/commit/01b9d16d0ba92a141a9be546ca00cca4029894d5))
8
+ * **sdk-react-core:** widget support for Midnight multi-address display + export hiding ([#11008](https://github.com/dynamic-labs/dynamic-auth/issues/11008)) ([87320b4](https://github.com/dynamic-labs/dynamic-auth/commit/87320b4d6e286b88e17f144641346e16a27e9e71))
9
+ * **waas:** wire session public key through host backup ops for keyshare diagnostics [DYNT-1280] ([#11675](https://github.com/dynamic-labs/dynamic-auth/issues/11675)) ([4f7981c](https://github.com/dynamic-labs/dynamic-auth/commit/4f7981c009930469dec7b3dec93f20f99bbe5498))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **ethereum-aa:** make ZeroDevConnector inert instead of throwing when ZeroDev config is absent ([#11610](https://github.com/dynamic-labs/dynamic-auth/issues/11610)) ([a3aab6a](https://github.com/dynamic-labs/dynamic-auth/commit/a3aab6a97e2e996f96b725f9336704b844f79603))
15
+ * **react-native-extension:** fall back to react-native-webview when embedded native module is unavailable ([#11683](https://github.com/dynamic-labs/dynamic-auth/issues/11683)) ([3f8d92c](https://github.com/dynamic-labs/dynamic-auth/commit/3f8d92ca0c327128b16e3355ab2f4e63d2c8e731))
16
+ * **sdk-react-core:** warn instead of throwing when ZeroDev connector is absent ([#11611](https://github.com/dynamic-labs/dynamic-auth/issues/11611)) ([5836252](https://github.com/dynamic-labs/dynamic-auth/commit/58362524e45205399c0fdc5b92414190d1929e0b))
17
+ * **waas-evm:** sign EOA transactions with the resolved chainId, not the connector default ([#11653](https://github.com/dynamic-labs/dynamic-auth/issues/11653)) ([e634098](https://github.com/dynamic-labs/dynamic-auth/commit/e634098f0f23f4c53f92a580db6f4aacbd6b1f92))
18
+
2
19
  ## [4.90.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.89.0...v4.90.0) (2026-06-19)
3
20
 
4
21
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.90.0";
6
+ var version = "4.91.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.90.0";
2
+ var version = "4.91.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/midnight",
3
- "version": "4.90.0",
3
+ "version": "4.91.0",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,13 +18,15 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.90.0",
21
+ "@dynamic-labs/assert-package-version": "4.91.0",
22
22
  "@dynamic-labs/sdk-api-core": "0.0.1046",
23
23
  "@midnight-ntwrk/dapp-connector-api": "4.0.1",
24
- "@dynamic-labs/types": "4.90.0",
25
- "@dynamic-labs/utils": "4.90.0",
26
- "@dynamic-labs/wallet-book": "4.90.0",
27
- "@dynamic-labs/wallet-connector-core": "4.90.0"
24
+ "@dynamic-labs/logger": "4.91.0",
25
+ "@dynamic-labs/types": "4.91.0",
26
+ "@dynamic-labs/utils": "4.91.0",
27
+ "@dynamic-labs/waas": "4.91.0",
28
+ "@dynamic-labs/wallet-book": "4.91.0",
29
+ "@dynamic-labs/wallet-connector-core": "4.91.0"
28
30
  },
29
31
  "peerDependencies": {}
30
32
  }
@@ -4,10 +4,16 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.cjs');
7
+ require('./waas/connector/DynamicWaasMidnightConnector.cjs');
8
+ var DynamicWaasMidnightConnectors = require('./waas/DynamicWaasMidnightConnectors.cjs');
9
+ require('../_virtual/_tslib.cjs');
10
+ require('@dynamic-labs/logger');
11
+ require('@dynamic-labs/wallet-connector-core');
7
12
 
8
13
  const MidnightWalletConnectors = (props) => [
9
14
  ...fetchInjectedWalletConnectors.injectedWalletOverrides,
10
15
  ...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(Object.assign(Object.assign({}, props), { walletsWithCustomConnectors: [] })),
16
+ ...DynamicWaasMidnightConnectors.DynamicWaasMidnightConnectors(),
11
17
  ];
12
18
 
13
19
  exports.MidnightWalletConnectors = MidnightWalletConnectors;
@@ -1,9 +1,15 @@
1
1
  'use client'
2
2
  import { injectedWalletOverrides, fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.js';
3
+ import './waas/connector/DynamicWaasMidnightConnector.js';
4
+ import { DynamicWaasMidnightConnectors } from './waas/DynamicWaasMidnightConnectors.js';
5
+ import '../_virtual/_tslib.js';
6
+ import '@dynamic-labs/logger';
7
+ import '@dynamic-labs/wallet-connector-core';
3
8
 
4
9
  const MidnightWalletConnectors = (props) => [
5
10
  ...injectedWalletOverrides,
6
11
  ...fetchInjectedWalletConnectors(Object.assign(Object.assign({}, props), { walletsWithCustomConnectors: [] })),
12
+ ...DynamicWaasMidnightConnectors(),
7
13
  ];
8
14
 
9
15
  export { MidnightWalletConnectors };
@@ -28,6 +28,15 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
28
28
  getEnabledNetworks() {
29
29
  return this.midnightNetworks;
30
30
  }
31
+ getBlockExplorerUrlsForCurrentNetwork() {
32
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
33
+ // Midnight is preview-only today and the env/network config can carry a
34
+ // stale or incorrect explorer URL, so always return the known-correct
35
+ // preview explorer rather than deferring to config. Detail pages live at
36
+ // `${origin}/transactions/{canonicalTxHash}`.
37
+ return ['https://explorer.preview.midnight.network'];
38
+ });
39
+ }
31
40
  getConnectedAPI() {
32
41
  return _tslib.__awaiter(this, void 0, void 0, function* () {
33
42
  return undefined;
@@ -119,6 +128,9 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
119
128
  return api.getDustAddress();
120
129
  });
121
130
  }
131
+ // Return type is a union so WaaS connectors can override with a richer
132
+ // `{ txHash, balanceAfter }` result while injected/external connectors keep
133
+ // the simple fire-and-forget `void` behavior.
122
134
  submitTransaction(serializedTransaction) {
123
135
  return _tslib.__awaiter(this, void 0, void 0, function* () {
124
136
  const api = yield this.getConnectedAPI();
@@ -17,8 +17,10 @@ export declare abstract class MidnightWalletConnector extends WalletConnectorBas
17
17
  cap: bigint;
18
18
  balance: bigint;
19
19
  };
20
+ dustSyncing?: boolean;
20
21
  }>;
21
22
  getEnabledNetworks(): GenericNetwork[];
23
+ getBlockExplorerUrlsForCurrentNetwork(): Promise<string[]>;
22
24
  protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
23
25
  createTransfer(params: {
24
26
  transfers: Array<{
@@ -46,5 +48,8 @@ export declare abstract class MidnightWalletConnector extends WalletConnectorBas
46
48
  getDustAddress(): Promise<{
47
49
  dustAddress: string;
48
50
  }>;
49
- submitTransaction(serializedTransaction: string): Promise<void>;
51
+ submitTransaction(serializedTransaction: string): Promise<void | {
52
+ txHash: string;
53
+ balanceAfter?: string;
54
+ }>;
50
55
  }
@@ -24,6 +24,15 @@ class MidnightWalletConnector extends WalletConnectorBase {
24
24
  getEnabledNetworks() {
25
25
  return this.midnightNetworks;
26
26
  }
27
+ getBlockExplorerUrlsForCurrentNetwork() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ // Midnight is preview-only today and the env/network config can carry a
30
+ // stale or incorrect explorer URL, so always return the known-correct
31
+ // preview explorer rather than deferring to config. Detail pages live at
32
+ // `${origin}/transactions/{canonicalTxHash}`.
33
+ return ['https://explorer.preview.midnight.network'];
34
+ });
35
+ }
27
36
  getConnectedAPI() {
28
37
  return __awaiter(this, void 0, void 0, function* () {
29
38
  return undefined;
@@ -115,6 +124,9 @@ class MidnightWalletConnector extends WalletConnectorBase {
115
124
  return api.getDustAddress();
116
125
  });
117
126
  }
127
+ // Return type is a union so WaaS connectors can override with a richer
128
+ // `{ txHash, balanceAfter }` result while injected/external connectors keep
129
+ // the simple fire-and-forget `void` behavior.
118
130
  submitTransaction(serializedTransaction) {
119
131
  return __awaiter(this, void 0, void 0, function* () {
120
132
  const api = yield this.getConnectedAPI();
package/src/index.cjs CHANGED
@@ -16,10 +16,12 @@ var toMidnightNetworks = require('./utils/toMidnightNetworks/toMidnightNetworks.
16
16
  var constants = require('./constants.cjs');
17
17
  var formatMidnightNativeUnshieldedBalance = require('./utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
18
18
  var formatMidnightConnectorDustBalance = require('./utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.cjs');
19
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
19
+ var DynamicWaasMidnightConnector = require('./waas/connector/DynamicWaasMidnightConnector.cjs');
20
+ var DynamicWaasMidnightConnectors = require('./waas/DynamicWaasMidnightConnectors.cjs');
21
+ var WaasMidnightWalletConnector = require('./waas/WaasMidnightWalletConnector.cjs');
22
+ var isMidnightWallet = require('./waas/isMidnightWallet.cjs');
20
23
 
21
24
  /* istanbul ignore file */
22
- /* istanbul ignore next */
23
25
  assertPackageVersion.assertPackageVersion('@dynamic-labs/midnight', _package.version);
24
26
 
25
27
  exports.MidnightWalletConnectors = MidnightWalletConnectors.MidnightWalletConnectors;
@@ -39,7 +41,7 @@ exports.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = constants.MIDNIGHT_NATIVE_UNSHIELD
39
41
  exports.MIDNIGHT_NETWORKS = constants.MIDNIGHT_NETWORKS;
40
42
  exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance;
41
43
  exports.formatMidnightConnectorDustBalance = formatMidnightConnectorDustBalance.formatMidnightConnectorDustBalance;
42
- Object.defineProperty(exports, 'isMidnightWallet', {
43
- enumerable: true,
44
- get: function () { return walletConnectorCore.isMidnightWallet; }
45
- });
44
+ exports.DynamicWaasMidnightConnector = DynamicWaasMidnightConnector.DynamicWaasMidnightConnector;
45
+ exports.DynamicWaasMidnightConnectors = DynamicWaasMidnightConnectors.DynamicWaasMidnightConnectors;
46
+ exports.WaasMidnightWalletConnector = WaasMidnightWalletConnector.WaasMidnightWalletConnector;
47
+ exports.isMidnightWallet = isMidnightWallet.isMidnightWallet;
package/src/index.d.ts CHANGED
@@ -10,4 +10,4 @@ export * from './constants';
10
10
  export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance';
11
11
  export { formatMidnightConnectorDustBalance } from './utils/formatMidnightConnectorDustBalance';
12
12
  export * from './types';
13
- export { isMidnightWallet } from './wallet/isMidnightWallet';
13
+ export * from './waas';
package/src/index.js CHANGED
@@ -12,8 +12,10 @@ export { toMidnightNetworks } from './utils/toMidnightNetworks/toMidnightNetwork
12
12
  export { MIDNIGHT_CHAIN, MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS } from './constants.js';
13
13
  export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
14
14
  export { formatMidnightConnectorDustBalance } from './utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.js';
15
- export { isMidnightWallet } from '@dynamic-labs/wallet-connector-core';
15
+ export { DynamicWaasMidnightConnector } from './waas/connector/DynamicWaasMidnightConnector.js';
16
+ export { DynamicWaasMidnightConnectors } from './waas/DynamicWaasMidnightConnectors.js';
17
+ export { WaasMidnightWalletConnector } from './waas/WaasMidnightWalletConnector.js';
18
+ export { isMidnightWallet } from './waas/isMidnightWallet.js';
16
19
 
17
20
  /* istanbul ignore file */
18
- /* istanbul ignore next */
19
21
  assertPackageVersion('@dynamic-labs/midnight', version);
package/src/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { GenericNetwork, WalletMetadata } from '@dynamic-labs/types';
2
- import { WalletBookSchema } from '@dynamic-labs/wallet-book';
1
+ import type { GenericNetwork, WalletMetadata, WalletUiUtils } from '@dynamic-labs/types';
2
+ import type { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
+ import type { InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
3
4
  import { MIDNIGHT_NETWORKS } from './constants';
4
5
  export type MidnightNetwork = Omit<GenericNetwork, 'chainId'> & {
5
6
  chainId: string;
@@ -44,3 +45,11 @@ export type MidnightWalletConnectorOpts = {
44
45
  walletBook: WalletBookSchema;
45
46
  metadata?: WalletMetadata;
46
47
  };
48
+ export interface MidnightWalletConnectorProps {
49
+ metadata?: WalletMetadata;
50
+ walletBook: WalletBookSchema;
51
+ midnightNetworks?: GenericNetwork[];
52
+ }
53
+ export interface DynamicWaasMidnightConnectorProps extends MidnightWalletConnectorProps {
54
+ walletUiUtils: WalletUiUtils<InternalWalletConnector>;
55
+ }
@@ -0,0 +1,109 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var constants = require('../../constants.cjs');
8
+ var formatMidnightAtomicBalance = require('../formatMidnightAtomicBalance/formatMidnightAtomicBalance.cjs');
9
+ var parseMidnightAtomicAmount = require('../parseMidnightAtomicAmount/parseMidnightAtomicAmount.cjs');
10
+
11
+ class MidnightUiTransaction {
12
+ constructor(opts) {
13
+ this.to = undefined;
14
+ this.value = undefined;
15
+ this.data = undefined;
16
+ this.receipt = undefined;
17
+ this.chain = 'MIDNIGHT';
18
+ this.fee = { gas: undefined };
19
+ this.feeTokenSymbol = 'DUST';
20
+ this.pool = 'unshielded';
21
+ this.from = opts.from;
22
+ this.onSubmitFn = opts.onSubmit;
23
+ this.getUnshieldedBalanceFn = opts.getUnshieldedBalance;
24
+ this.getShieldedBalanceFn = opts.getShieldedBalance;
25
+ this.fetchDustFeeFn = opts.fetchDustFee;
26
+ }
27
+ get activePool() {
28
+ return this.pool;
29
+ }
30
+ setSelectedToken(contractAddress) {
31
+ this.pool =
32
+ contractAddress === constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE
33
+ ? 'shielded'
34
+ : 'unshielded';
35
+ this.to = undefined;
36
+ this.value = undefined;
37
+ }
38
+ getSendableTokenBalances() {
39
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
40
+ const [unshieldedRaw, shieldedRaw] = yield Promise.all([
41
+ this.getUnshieldedBalanceFn(),
42
+ this.getShieldedBalanceFn(),
43
+ ]);
44
+ const toDisplay = (raw) => Number(formatMidnightAtomicBalance.formatMidnightAtomicBalance(raw, constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS));
45
+ return [
46
+ {
47
+ address: constants.MIDNIGHT_NATIVE_TOKEN_TYPE,
48
+ balance: toDisplay(unshieldedRaw),
49
+ decimals: constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS,
50
+ isNative: true,
51
+ logoURI: '',
52
+ name: 'NIGHT (Unshielded)',
53
+ rawBalance: Number(unshieldedRaw),
54
+ rawBalanceString: unshieldedRaw.toString(),
55
+ symbol: 'NIGHT',
56
+ },
57
+ {
58
+ address: constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE,
59
+ balance: toDisplay(shieldedRaw),
60
+ decimals: constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS,
61
+ isNative: true,
62
+ logoURI: '',
63
+ name: 'NIGHT (Shielded)',
64
+ rawBalance: Number(shieldedRaw),
65
+ rawBalanceString: shieldedRaw.toString(),
66
+ symbol: 'NIGHT',
67
+ },
68
+ ];
69
+ });
70
+ }
71
+ parse(input) {
72
+ return parseMidnightAtomicAmount.parseMidnightAtomicAmount(input, constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
73
+ }
74
+ format(value) {
75
+ return formatMidnightAtomicBalance.formatMidnightAtomicBalance(value, constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
76
+ }
77
+ getBalance() {
78
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
79
+ return this.pool === 'shielded'
80
+ ? this.getShieldedBalanceFn()
81
+ : this.getUnshieldedBalanceFn();
82
+ });
83
+ }
84
+ fetchFee() {
85
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
86
+ this.fee.gas = yield this.fetchDustFeeFn();
87
+ });
88
+ }
89
+ validateAddressFormat(address) {
90
+ if (this.pool === 'shielded') {
91
+ return address.startsWith('mn_shield');
92
+ }
93
+ return address.length > 0 && !address.startsWith('mn_shield');
94
+ }
95
+ submit() {
96
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
97
+ if (this.to === undefined || this.value === undefined) {
98
+ throw new Error('MidnightUiTransaction: to and value must be set before submitting');
99
+ }
100
+ // Return the tx hash so the Send flow's onSuccess(txHash) advances to the
101
+ // success view (it bails on a falsy hash and stays on the confirm screen).
102
+ const receipt = yield this.onSubmitFn(this);
103
+ this.receipt = receipt;
104
+ return receipt;
105
+ });
106
+ }
107
+ }
108
+
109
+ exports.MidnightUiTransaction = MidnightUiTransaction;
@@ -3,7 +3,7 @@ import type { IUITransaction } from '@dynamic-labs/types';
3
3
  type MidnightPool = 'unshielded' | 'shielded';
4
4
  type MidnightUiTransactionOpts = {
5
5
  from: string;
6
- onSubmit: (tx: MidnightUiTransaction) => Promise<void>;
6
+ onSubmit: (tx: MidnightUiTransaction) => Promise<string>;
7
7
  getUnshieldedBalance: () => Promise<bigint>;
8
8
  getShieldedBalance: () => Promise<bigint>;
9
9
  fetchDustFee: () => Promise<bigint>;
@@ -33,6 +33,6 @@ export declare class MidnightUiTransaction implements IUITransaction {
33
33
  getBalance(): Promise<bigint>;
34
34
  fetchFee(): Promise<void>;
35
35
  validateAddressFormat(address: string): boolean;
36
- submit(): Promise<void>;
36
+ submit(): Promise<string>;
37
37
  }
38
38
  export {};
@@ -0,0 +1,105 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS } from '../../constants.js';
4
+ import { formatMidnightAtomicBalance } from '../formatMidnightAtomicBalance/formatMidnightAtomicBalance.js';
5
+ import { parseMidnightAtomicAmount } from '../parseMidnightAtomicAmount/parseMidnightAtomicAmount.js';
6
+
7
+ class MidnightUiTransaction {
8
+ constructor(opts) {
9
+ this.to = undefined;
10
+ this.value = undefined;
11
+ this.data = undefined;
12
+ this.receipt = undefined;
13
+ this.chain = 'MIDNIGHT';
14
+ this.fee = { gas: undefined };
15
+ this.feeTokenSymbol = 'DUST';
16
+ this.pool = 'unshielded';
17
+ this.from = opts.from;
18
+ this.onSubmitFn = opts.onSubmit;
19
+ this.getUnshieldedBalanceFn = opts.getUnshieldedBalance;
20
+ this.getShieldedBalanceFn = opts.getShieldedBalance;
21
+ this.fetchDustFeeFn = opts.fetchDustFee;
22
+ }
23
+ get activePool() {
24
+ return this.pool;
25
+ }
26
+ setSelectedToken(contractAddress) {
27
+ this.pool =
28
+ contractAddress === MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE
29
+ ? 'shielded'
30
+ : 'unshielded';
31
+ this.to = undefined;
32
+ this.value = undefined;
33
+ }
34
+ getSendableTokenBalances() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const [unshieldedRaw, shieldedRaw] = yield Promise.all([
37
+ this.getUnshieldedBalanceFn(),
38
+ this.getShieldedBalanceFn(),
39
+ ]);
40
+ const toDisplay = (raw) => Number(formatMidnightAtomicBalance(raw, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS));
41
+ return [
42
+ {
43
+ address: MIDNIGHT_NATIVE_TOKEN_TYPE,
44
+ balance: toDisplay(unshieldedRaw),
45
+ decimals: MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS,
46
+ isNative: true,
47
+ logoURI: '',
48
+ name: 'NIGHT (Unshielded)',
49
+ rawBalance: Number(unshieldedRaw),
50
+ rawBalanceString: unshieldedRaw.toString(),
51
+ symbol: 'NIGHT',
52
+ },
53
+ {
54
+ address: MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE,
55
+ balance: toDisplay(shieldedRaw),
56
+ decimals: MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS,
57
+ isNative: true,
58
+ logoURI: '',
59
+ name: 'NIGHT (Shielded)',
60
+ rawBalance: Number(shieldedRaw),
61
+ rawBalanceString: shieldedRaw.toString(),
62
+ symbol: 'NIGHT',
63
+ },
64
+ ];
65
+ });
66
+ }
67
+ parse(input) {
68
+ return parseMidnightAtomicAmount(input, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
69
+ }
70
+ format(value) {
71
+ return formatMidnightAtomicBalance(value, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
72
+ }
73
+ getBalance() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return this.pool === 'shielded'
76
+ ? this.getShieldedBalanceFn()
77
+ : this.getUnshieldedBalanceFn();
78
+ });
79
+ }
80
+ fetchFee() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ this.fee.gas = yield this.fetchDustFeeFn();
83
+ });
84
+ }
85
+ validateAddressFormat(address) {
86
+ if (this.pool === 'shielded') {
87
+ return address.startsWith('mn_shield');
88
+ }
89
+ return address.length > 0 && !address.startsWith('mn_shield');
90
+ }
91
+ submit() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ if (this.to === undefined || this.value === undefined) {
94
+ throw new Error('MidnightUiTransaction: to and value must be set before submitting');
95
+ }
96
+ // Return the tx hash so the Send flow's onSuccess(txHash) advances to the
97
+ // success view (it bails on a falsy hash and stays on the confirm screen).
98
+ const receipt = yield this.onSubmitFn(this);
99
+ this.receipt = receipt;
100
+ return receipt;
101
+ });
102
+ }
103
+ }
104
+
105
+ export { MidnightUiTransaction };
@@ -0,0 +1,16 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicWaasMidnightConnector = require('./connector/DynamicWaasMidnightConnector.cjs');
7
+
8
+ /**
9
+ * Factory function to create Midnight WaaS connectors.
10
+ * Returns an array of connector classes for use with the Dynamic SDK.
11
+ */
12
+ const DynamicWaasMidnightConnectors = () => [
13
+ DynamicWaasMidnightConnector.DynamicWaasMidnightConnector,
14
+ ];
15
+
16
+ exports.DynamicWaasMidnightConnectors = DynamicWaasMidnightConnectors;
@@ -0,0 +1,6 @@
1
+ import { DynamicWaasMidnightConnector } from './connector/DynamicWaasMidnightConnector';
2
+ /**
3
+ * Factory function to create Midnight WaaS connectors.
4
+ * Returns an array of connector classes for use with the Dynamic SDK.
5
+ */
6
+ export declare const DynamicWaasMidnightConnectors: () => (typeof DynamicWaasMidnightConnector)[];
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ import { DynamicWaasMidnightConnector } from './connector/DynamicWaasMidnightConnector.js';
3
+
4
+ /**
5
+ * Factory function to create Midnight WaaS connectors.
6
+ * Returns an array of connector classes for use with the Dynamic SDK.
7
+ */
8
+ const DynamicWaasMidnightConnectors = () => [
9
+ DynamicWaasMidnightConnector,
10
+ ];
11
+
12
+ export { DynamicWaasMidnightConnectors };
@@ -0,0 +1,109 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var logger = require('@dynamic-labs/logger');
8
+ var MidnightWalletConnector = require('../connectors/MidnightWalletConnector.cjs');
9
+
10
+ /**
11
+ * Abstract base class for Midnight **WaaS** wallet connectors. Layers the
12
+ * network-management machinery (selectedNetwork, midnightNetworks,
13
+ * getNetworkId, switchNetwork, isTestnet, ...) on top of the shared
14
+ * `MidnightWalletConnector` that injected / external wallets also extend.
15
+ *
16
+ * External / injected connectors (e.g. the 1am wallet) extend
17
+ * `MidnightWalletConnector` directly and don't need this surface area —
18
+ * `connectedChain`, `supportedChains`, and `ChainWallet` are inherited.
19
+ */
20
+ class WaasMidnightWalletConnector extends MidnightWalletConnector.MidnightWalletConnector {
21
+ constructor(name, opts) {
22
+ var _a;
23
+ super({
24
+ metadata: opts.metadata,
25
+ walletBook: opts.walletBook,
26
+ });
27
+ this.name = name;
28
+ this.logger = new logger.Logger(this.name);
29
+ // WaaS connectors keep the raw network configs; the base stores the
30
+ // toMidnightNetworks-converted shape. Cast to satisfy the base field type
31
+ // without altering the stored runtime values.
32
+ this.midnightNetworks = ((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
33
+ this.overrideKey = this.key;
34
+ }
35
+ getEnabledNetworks() {
36
+ return this.midnightNetworks;
37
+ }
38
+ supportsNetworkSwitching() {
39
+ return this.midnightNetworks.length > 1;
40
+ }
41
+ getSelectedNetwork() {
42
+ var _a, _b;
43
+ return (_a = this.selectedNetwork) !== null && _a !== void 0 ? _a : (_b = this.midnightNetworks) === null || _b === void 0 ? void 0 : _b[0];
44
+ }
45
+ switchNetwork(_a) {
46
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
47
+ if (networkChainId === undefined)
48
+ return;
49
+ const idStr = String(networkChainId);
50
+ const network = this.midnightNetworks.find((n) => { var _a, _b; return ((_a = n.chainId) === null || _a === void 0 ? void 0 : _a.toString()) === idStr || ((_b = n.networkId) === null || _b === void 0 ? void 0 : _b.toString()) === idStr; });
51
+ if (network) {
52
+ this.selectedNetwork = network;
53
+ this.emit('chainChange', { chain: String(network.chainId) });
54
+ }
55
+ });
56
+ }
57
+ getNetwork() {
58
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
59
+ var _a;
60
+ if (!this.midnightNetworks.length) {
61
+ return undefined;
62
+ }
63
+ if (this.selectedNetwork) {
64
+ return String(this.selectedNetwork.chainId);
65
+ }
66
+ // Default to first network
67
+ [this.selectedNetwork] = this.midnightNetworks;
68
+ return String((_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.chainId);
69
+ });
70
+ }
71
+ /**
72
+ * Numeric network ID for the current network. 0 = testnet, 1 = mainnet.
73
+ * Derived from the selected network's name — heuristic matches Midnight's
74
+ * naming convention where testnets contain the substring `"testnet"`.
75
+ */
76
+ getNetworkId() {
77
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
78
+ var _a, _b;
79
+ const network = this.getSelectedNetwork();
80
+ const networkName = (_b = (_a = network === null || network === void 0 ? void 0 : network.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
81
+ if (networkName.includes('testnet')) {
82
+ return 0;
83
+ }
84
+ // Default to mainnet
85
+ return 1;
86
+ });
87
+ }
88
+ isTestnet() {
89
+ var _a, _b;
90
+ const network = this.getSelectedNetwork();
91
+ if (!network) {
92
+ return Promise.resolve(false);
93
+ }
94
+ return Promise.resolve((_b = (_a = network.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('testnet')) !== null && _b !== void 0 ? _b : false);
95
+ }
96
+ getConnectedAccounts() {
97
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
98
+ const address = yield this.getAddress();
99
+ return address ? [address] : [];
100
+ });
101
+ }
102
+ endSession() {
103
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
104
+ // Base implementation — subclasses can override.
105
+ });
106
+ }
107
+ }
108
+
109
+ exports.WaasMidnightWalletConnector = WaasMidnightWalletConnector;