@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.
Files changed (36) hide show
  1. package/CHANGELOG.md +36 -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 +41 -0
  8. package/src/connectors/MidnightWalletConnector.d.ts +42 -1
  9. package/src/connectors/MidnightWalletConnector.js +41 -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 +584 -0
  24. package/src/waas/connector/DynamicWaasMidnightConnector.d.ts +470 -0
  25. package/src/waas/connector/DynamicWaasMidnightConnector.js +580 -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 +31 -0
  35. package/src/wallet/MidnightWallet.d.ts +15 -0
  36. package/src/wallet/MidnightWallet.js +31 -0
@@ -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;
@@ -0,0 +1,44 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ import type { GenericNetwork } from '@dynamic-labs/types';
3
+ import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector';
4
+ import type { MidnightNetwork, MidnightWalletConnectorProps } from '../types';
5
+ /**
6
+ * Abstract base class for Midnight **WaaS** wallet connectors. Layers the
7
+ * network-management machinery (selectedNetwork, midnightNetworks,
8
+ * getNetworkId, switchNetwork, isTestnet, ...) on top of the shared
9
+ * `MidnightWalletConnector` that injected / external wallets also extend.
10
+ *
11
+ * External / injected connectors (e.g. the 1am wallet) extend
12
+ * `MidnightWalletConnector` directly and don't need this surface area —
13
+ * `connectedChain`, `supportedChains`, and `ChainWallet` are inherited.
14
+ */
15
+ export declare abstract class WaasMidnightWalletConnector extends MidnightWalletConnector {
16
+ name: string;
17
+ logger: Logger;
18
+ protected selectedNetwork: GenericNetwork | undefined;
19
+ midnightNetworks: MidnightNetwork[];
20
+ constructor(name: string, opts: MidnightWalletConnectorProps);
21
+ getEnabledNetworks(): GenericNetwork[];
22
+ supportsNetworkSwitching(): boolean;
23
+ getSelectedNetwork(): GenericNetwork | undefined;
24
+ switchNetwork({ networkChainId, }: {
25
+ networkChainId?: number | string;
26
+ networkName?: string;
27
+ }): Promise<void>;
28
+ getNetwork(): Promise<string | undefined>;
29
+ /**
30
+ * Numeric network ID for the current network. 0 = testnet, 1 = mainnet.
31
+ * Derived from the selected network's name — heuristic matches Midnight's
32
+ * naming convention where testnets contain the substring `"testnet"`.
33
+ */
34
+ getNetworkId(): Promise<number>;
35
+ isTestnet(): Promise<boolean>;
36
+ abstract signMessage(message: string): Promise<string | undefined>;
37
+ /** Signs a serialized (base64) Midnight transaction. */
38
+ abstract signTransaction(serializedTransaction: string): Promise<string>;
39
+ abstract connect(): Promise<void>;
40
+ abstract disconnect(): Promise<void>;
41
+ abstract getAddress(): Promise<string>;
42
+ getConnectedAccounts(): Promise<string[]>;
43
+ endSession(): Promise<void>;
44
+ }
@@ -0,0 +1,105 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { Logger } from '@dynamic-labs/logger';
4
+ import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector.js';
5
+
6
+ /**
7
+ * Abstract base class for Midnight **WaaS** wallet connectors. Layers the
8
+ * network-management machinery (selectedNetwork, midnightNetworks,
9
+ * getNetworkId, switchNetwork, isTestnet, ...) on top of the shared
10
+ * `MidnightWalletConnector` that injected / external wallets also extend.
11
+ *
12
+ * External / injected connectors (e.g. the 1am wallet) extend
13
+ * `MidnightWalletConnector` directly and don't need this surface area —
14
+ * `connectedChain`, `supportedChains`, and `ChainWallet` are inherited.
15
+ */
16
+ class WaasMidnightWalletConnector extends MidnightWalletConnector {
17
+ constructor(name, opts) {
18
+ var _a;
19
+ super({
20
+ metadata: opts.metadata,
21
+ walletBook: opts.walletBook,
22
+ });
23
+ this.name = name;
24
+ this.logger = new Logger(this.name);
25
+ // WaaS connectors keep the raw network configs; the base stores the
26
+ // toMidnightNetworks-converted shape. Cast to satisfy the base field type
27
+ // without altering the stored runtime values.
28
+ this.midnightNetworks = ((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
29
+ this.overrideKey = this.key;
30
+ }
31
+ getEnabledNetworks() {
32
+ return this.midnightNetworks;
33
+ }
34
+ supportsNetworkSwitching() {
35
+ return this.midnightNetworks.length > 1;
36
+ }
37
+ getSelectedNetwork() {
38
+ var _a, _b;
39
+ return (_a = this.selectedNetwork) !== null && _a !== void 0 ? _a : (_b = this.midnightNetworks) === null || _b === void 0 ? void 0 : _b[0];
40
+ }
41
+ switchNetwork(_a) {
42
+ return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
43
+ if (networkChainId === undefined)
44
+ return;
45
+ const idStr = String(networkChainId);
46
+ 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; });
47
+ if (network) {
48
+ this.selectedNetwork = network;
49
+ this.emit('chainChange', { chain: String(network.chainId) });
50
+ }
51
+ });
52
+ }
53
+ getNetwork() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ var _a;
56
+ if (!this.midnightNetworks.length) {
57
+ return undefined;
58
+ }
59
+ if (this.selectedNetwork) {
60
+ return String(this.selectedNetwork.chainId);
61
+ }
62
+ // Default to first network
63
+ [this.selectedNetwork] = this.midnightNetworks;
64
+ return String((_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.chainId);
65
+ });
66
+ }
67
+ /**
68
+ * Numeric network ID for the current network. 0 = testnet, 1 = mainnet.
69
+ * Derived from the selected network's name — heuristic matches Midnight's
70
+ * naming convention where testnets contain the substring `"testnet"`.
71
+ */
72
+ getNetworkId() {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ var _a, _b;
75
+ const network = this.getSelectedNetwork();
76
+ 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 : '';
77
+ if (networkName.includes('testnet')) {
78
+ return 0;
79
+ }
80
+ // Default to mainnet
81
+ return 1;
82
+ });
83
+ }
84
+ isTestnet() {
85
+ var _a, _b;
86
+ const network = this.getSelectedNetwork();
87
+ if (!network) {
88
+ return Promise.resolve(false);
89
+ }
90
+ return Promise.resolve((_b = (_a = network.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('testnet')) !== null && _b !== void 0 ? _b : false);
91
+ }
92
+ getConnectedAccounts() {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const address = yield this.getAddress();
95
+ return address ? [address] : [];
96
+ });
97
+ }
98
+ endSession() {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ // Base implementation — subclasses can override.
101
+ });
102
+ }
103
+ }
104
+
105
+ export { WaasMidnightWalletConnector };