@dynamic-labs/midnight 4.79.0 → 4.79.2
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 +18 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -5
- package/src/MidnightProviderHelper/MidnightProviderHelper.cjs +107 -15
- package/src/MidnightProviderHelper/MidnightProviderHelper.d.ts +8 -0
- package/src/MidnightProviderHelper/MidnightProviderHelper.js +107 -15
- package/src/MidnightWalletConnectors.cjs +13 -0
- package/src/MidnightWalletConnectors.d.ts +3 -0
- package/src/MidnightWalletConnectors.js +9 -0
- package/src/connectors/MidnightWalletConnector.cjs +84 -1
- package/src/connectors/MidnightWalletConnector.d.ts +27 -8
- package/src/connectors/MidnightWalletConnector.js +84 -1
- package/src/index.cjs +7 -2
- package/src/index.d.ts +3 -1
- package/src/index.js +4 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.cjs +17 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.d.ts +3 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.js +17 -1
- package/src/types.d.ts +10 -0
- package/src/utils/toMidnightNetworks/index.d.ts +1 -0
- package/src/utils/toMidnightNetworks/toMidnightNetworks.cjs +8 -0
- package/src/utils/toMidnightNetworks/toMidnightNetworks.d.ts +3 -0
- package/src/utils/toMidnightNetworks/toMidnightNetworks.js +4 -0
- package/src/wallet/MidnightWallet.cjs +15 -4
- package/src/wallet/MidnightWallet.d.ts +2 -2
- package/src/wallet/MidnightWallet.js +15 -4
- package/src/wallet/isMidnightWallet/index.d.ts +1 -0
- package/src/wallet/isMidnightWallet/isMidnightWallet.cjs +8 -0
- package/src/wallet/isMidnightWallet/isMidnightWallet.d.ts +3 -0
- package/src/wallet/isMidnightWallet/isMidnightWallet.js +4 -0
- package/src/injected/Midnight1am/Midnight1am.cjs +0 -16
- package/src/injected/Midnight1am/Midnight1am.d.ts +0 -5
- package/src/injected/Midnight1am/Midnight1am.js +0 -12
- package/src/injected/Midnight1am/index.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.79.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.79.1...v4.79.2) (2026-05-04)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **react-native:** remove extra react-native turbo modules instructions ([#11126](https://github.com/dynamic-labs/dynamic-auth/issues/11126))
|
|
8
|
+
|
|
9
|
+
### [4.79.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.79.0...v4.79.1) (2026-05-01)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **playwright:** tolerate confirm-only transfer wallet modal ([#11081](https://github.com/dynamic-labs/dynamic-auth/issues/11081)) ([f4f2b85](https://github.com/dynamic-labs/dynamic-auth/commit/f4f2b85e515a3dfb7f54bd1dd697fa8fddea74f0))
|
|
15
|
+
* **sdk-react-core:** replace rAF polling with setTimeout in animationFrameTimeout ([#11086](https://github.com/dynamic-labs/dynamic-auth/issues/11086)) ([73cad2a](https://github.com/dynamic-labs/dynamic-auth/commit/73cad2a1be0a331b7504aca2b6dcb1ef770a6b37))
|
|
16
|
+
* **wagmi-connector:** emit change on wallet-internal MM account switch DYNT-549 ([#11044](https://github.com/dynamic-labs/dynamic-auth/issues/11044)) ([4345aa2](https://github.com/dynamic-labs/dynamic-auth/commit/4345aa2a96bc0fac5a5c8280875e6ab122391b98)), closes [#11043](https://github.com/dynamic-labs/dynamic-auth/issues/11043) [#11045](https://github.com/dynamic-labs/dynamic-auth/issues/11045) [#10945](https://github.com/dynamic-labs/dynamic-auth/issues/10945) [#10945](https://github.com/dynamic-labs/dynamic-auth/issues/10945)
|
|
17
|
+
* **wagmi-connector:** fix accountChange listener leak DYNT-549 ([#11043](https://github.com/dynamic-labs/dynamic-auth/issues/11043)) ([e4652aa](https://github.com/dynamic-labs/dynamic-auth/commit/e4652aa3b3c586bd4648deda4a0406ca555f3481)), closes [#11044](https://github.com/dynamic-labs/dynamic-auth/issues/11044) [#11045](https://github.com/dynamic-labs/dynamic-auth/issues/11045)
|
|
18
|
+
* **wagmi-connector:** use accountChange event payload as authoritative address in SyncDynamicWagmi DYNT-549 ([#11045](https://github.com/dynamic-labs/dynamic-auth/issues/11045)) ([77a300b](https://github.com/dynamic-labs/dynamic-auth/commit/77a300be77d90dc3c1aefe02a2074764d89a1cb7)), closes [#11043](https://github.com/dynamic-labs/dynamic-auth/issues/11043) [#11044](https://github.com/dynamic-labs/dynamic-auth/issues/11044) [#11044](https://github.com/dynamic-labs/dynamic-auth/issues/11044)
|
|
19
|
+
|
|
2
20
|
## [4.79.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.78.1...v4.79.0) (2026-04-30)
|
|
3
21
|
|
|
4
22
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/midnight",
|
|
3
|
-
"version": "4.79.
|
|
3
|
+
"version": "4.79.2",
|
|
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,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.79.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.79.2",
|
|
22
22
|
"@midnight-ntwrk/dapp-connector-api": "4.0.1",
|
|
23
|
-
"@dynamic-labs/
|
|
24
|
-
"@dynamic-labs/
|
|
25
|
-
"@dynamic-labs/wallet-
|
|
23
|
+
"@dynamic-labs/types": "4.79.2",
|
|
24
|
+
"@dynamic-labs/utils": "4.79.2",
|
|
25
|
+
"@dynamic-labs/wallet-book": "4.79.2",
|
|
26
|
+
"@dynamic-labs/wallet-connector-core": "4.79.2"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {}
|
|
28
29
|
}
|
|
@@ -9,12 +9,41 @@ var walletBook = require('@dynamic-labs/wallet-book');
|
|
|
9
9
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
10
|
var constants = require('../constants.cjs');
|
|
11
11
|
|
|
12
|
+
const STORAGE_KEY_PREFIX = 'midnight.connected';
|
|
12
13
|
class MidnightProviderHelper {
|
|
13
14
|
constructor(connector) {
|
|
14
15
|
this._connectionGeneration = 0;
|
|
16
|
+
this._autoConnectAttempted = false;
|
|
15
17
|
this.walletBookWallet = walletBook.findWalletBookWallet(connector.walletBook, connector.key);
|
|
16
18
|
this.connector = connector;
|
|
17
19
|
}
|
|
20
|
+
get storageKey() {
|
|
21
|
+
return `${STORAGE_KEY_PREFIX}.${this.connector.key}`;
|
|
22
|
+
}
|
|
23
|
+
persistConnection(rdns) {
|
|
24
|
+
try {
|
|
25
|
+
localStorage.setItem(this.storageKey, rdns);
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
// localStorage may be unavailable (SSR, private mode, quota exceeded)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
clearPersistedConnection() {
|
|
32
|
+
try {
|
|
33
|
+
localStorage.removeItem(this.storageKey);
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
// localStorage may be unavailable
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
hasPersistedConnection() {
|
|
40
|
+
try {
|
|
41
|
+
return localStorage.getItem(this.storageKey) !== null;
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
18
47
|
getInjectedConfig() {
|
|
19
48
|
var _a, _b;
|
|
20
49
|
return (_b = (_a = this.walletBookWallet) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.find((c) => c.chain === constants.MIDNIGHT_CHAIN);
|
|
@@ -26,7 +55,10 @@ class MidnightProviderHelper {
|
|
|
26
55
|
return undefined;
|
|
27
56
|
for (const windowLocation of config.windowLocations) {
|
|
28
57
|
const [provider] = utils.getProvidersFromWindow(windowLocation);
|
|
29
|
-
|
|
58
|
+
// Guard against a partially-initialised provider: the wallet shell can
|
|
59
|
+
// appear in window.midnight before its internal registry is ready.
|
|
60
|
+
// rdns being present signals the provider is fully initialised.
|
|
61
|
+
if (provider === null || provider === void 0 ? void 0 : provider.rdns)
|
|
30
62
|
return provider;
|
|
31
63
|
}
|
|
32
64
|
return undefined;
|
|
@@ -36,21 +68,34 @@ class MidnightProviderHelper {
|
|
|
36
68
|
}
|
|
37
69
|
getConnectedAPI() {
|
|
38
70
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if (this._connectedAPI)
|
|
40
|
-
|
|
71
|
+
if (this._connectedAPI) {
|
|
72
|
+
try {
|
|
73
|
+
const { status } = yield this._connectedAPI.getConnectionStatus();
|
|
74
|
+
if (status === 'connected')
|
|
75
|
+
return this._connectedAPI;
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
// Status check failed — treat as disconnected and reconnect below.
|
|
79
|
+
}
|
|
80
|
+
this._connectedAPI = undefined;
|
|
81
|
+
}
|
|
41
82
|
if (this._connectPromise)
|
|
42
83
|
return this._connectPromise;
|
|
43
|
-
const initialProvider = this.getInstalledProvider();
|
|
44
|
-
if (!initialProvider)
|
|
45
|
-
return undefined;
|
|
46
84
|
const generation = this._connectionGeneration;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
85
|
+
// _connectPromise is assigned synchronously (no await) so concurrent callers
|
|
86
|
+
// always share the same promise and never make a second connect() call.
|
|
87
|
+
// waitForProvider() polls window.midnight because extensions inject async.
|
|
88
|
+
this._connectPromise = this.waitForProvider()
|
|
89
|
+
.then((initialProvider) => {
|
|
90
|
+
if (!initialProvider)
|
|
91
|
+
return undefined;
|
|
92
|
+
return initialProvider.connect(this.connector.networkId).then((api) => {
|
|
93
|
+
if (this._connectionGeneration === generation) {
|
|
94
|
+
this._connectedAPI = api;
|
|
95
|
+
this.persistConnection(initialProvider.rdns);
|
|
96
|
+
}
|
|
97
|
+
return this._connectedAPI;
|
|
98
|
+
});
|
|
54
99
|
})
|
|
55
100
|
.catch((err) => {
|
|
56
101
|
walletConnectorCore.logger.error('[MidnightProviderHelper] getConnectedAPI - Error connecting to wallet', err);
|
|
@@ -62,6 +107,40 @@ class MidnightProviderHelper {
|
|
|
62
107
|
return this._connectPromise;
|
|
63
108
|
});
|
|
64
109
|
}
|
|
110
|
+
// Polls window.midnight until the provider injects (extensions inject async).
|
|
111
|
+
// Resolves undefined after timeoutMs if still not present.
|
|
112
|
+
waitForProvider(timeoutMs = 2000) {
|
|
113
|
+
const immediate = this.getInstalledProvider();
|
|
114
|
+
if (immediate)
|
|
115
|
+
return Promise.resolve(immediate);
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const deadline = Date.now() + timeoutMs;
|
|
118
|
+
const poll = () => {
|
|
119
|
+
const provider = this.getInstalledProvider();
|
|
120
|
+
if (provider)
|
|
121
|
+
return resolve(provider);
|
|
122
|
+
if (Date.now() >= deadline)
|
|
123
|
+
return resolve(undefined);
|
|
124
|
+
setTimeout(poll, 100);
|
|
125
|
+
};
|
|
126
|
+
setTimeout(poll, 100);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Attempts a silent reconnect using the persisted session. Only tries once per
|
|
130
|
+
// page load — PermissionRejected is tab-scoped so retrying would just fail again.
|
|
131
|
+
// Delegates to getConnectedAPI() so status checks and deduplication are shared.
|
|
132
|
+
tryAutoConnect() {
|
|
133
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (this._connectPromise)
|
|
135
|
+
return this._connectPromise;
|
|
136
|
+
if (this._autoConnectAttempted)
|
|
137
|
+
return undefined;
|
|
138
|
+
if (!this.hasPersistedConnection())
|
|
139
|
+
return undefined;
|
|
140
|
+
this._autoConnectAttempted = true;
|
|
141
|
+
return this.getConnectedAPI();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
65
144
|
getAddress() {
|
|
66
145
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
67
146
|
const api = yield this.getConnectedAPI();
|
|
@@ -71,6 +150,15 @@ class MidnightProviderHelper {
|
|
|
71
150
|
return unshieldedAddress;
|
|
72
151
|
});
|
|
73
152
|
}
|
|
153
|
+
getNetwork() {
|
|
154
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const api = yield this.getConnectedAPI();
|
|
156
|
+
if (!api)
|
|
157
|
+
return undefined;
|
|
158
|
+
const { networkId } = yield api.getConfiguration();
|
|
159
|
+
return networkId.toString();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
74
162
|
getAddressIfConnected() {
|
|
75
163
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
164
|
if (!this._connectedAPI)
|
|
@@ -84,11 +172,14 @@ class MidnightProviderHelper {
|
|
|
84
172
|
const api = yield this.getConnectedAPI();
|
|
85
173
|
if (!api)
|
|
86
174
|
return undefined;
|
|
87
|
-
|
|
175
|
+
// hintUsage pre-fetches signing permission; wallet resolves this only after
|
|
176
|
+
// the user grants it, ensuring signData succeeds immediately on first call.
|
|
177
|
+
yield api.hintUsage(['signData']);
|
|
178
|
+
const { signature, verifyingKey } = yield api.signData(messageToSign, {
|
|
88
179
|
encoding: 'text',
|
|
89
180
|
keyType: 'unshielded',
|
|
90
181
|
});
|
|
91
|
-
return signature;
|
|
182
|
+
return JSON.stringify({ signature, verifyingKey });
|
|
92
183
|
});
|
|
93
184
|
}
|
|
94
185
|
disconnect() {
|
|
@@ -96,6 +187,7 @@ class MidnightProviderHelper {
|
|
|
96
187
|
this._connectionGeneration++;
|
|
97
188
|
this._connectedAPI = undefined;
|
|
98
189
|
this._connectPromise = undefined;
|
|
190
|
+
this.clearPersistedConnection();
|
|
99
191
|
});
|
|
100
192
|
}
|
|
101
193
|
// Midnight ConnectedAPI does not expose event listeners.
|
|
@@ -6,7 +6,12 @@ export declare class MidnightProviderHelper {
|
|
|
6
6
|
private _connectedAPI;
|
|
7
7
|
private _connectPromise;
|
|
8
8
|
private _connectionGeneration;
|
|
9
|
+
private _autoConnectAttempted;
|
|
9
10
|
constructor(connector: InjectedWalletBase);
|
|
11
|
+
private get storageKey();
|
|
12
|
+
private persistConnection;
|
|
13
|
+
private clearPersistedConnection;
|
|
14
|
+
hasPersistedConnection(): boolean;
|
|
10
15
|
getInjectedConfig(): {
|
|
11
16
|
chain: string;
|
|
12
17
|
extensionLocators: {
|
|
@@ -28,7 +33,10 @@ export declare class MidnightProviderHelper {
|
|
|
28
33
|
getInstalledProvider(): InitialAPI | undefined;
|
|
29
34
|
isInstalledHelper(): boolean;
|
|
30
35
|
getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
36
|
+
private waitForProvider;
|
|
37
|
+
tryAutoConnect(): Promise<ConnectedAPI | undefined>;
|
|
31
38
|
getAddress(): Promise<string | undefined>;
|
|
39
|
+
getNetwork(): Promise<string | undefined>;
|
|
32
40
|
getAddressIfConnected(): Promise<string | undefined>;
|
|
33
41
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
34
42
|
disconnect(): Promise<void>;
|
|
@@ -5,12 +5,41 @@ import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
|
5
5
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
6
6
|
import { MIDNIGHT_CHAIN } from '../constants.js';
|
|
7
7
|
|
|
8
|
+
const STORAGE_KEY_PREFIX = 'midnight.connected';
|
|
8
9
|
class MidnightProviderHelper {
|
|
9
10
|
constructor(connector) {
|
|
10
11
|
this._connectionGeneration = 0;
|
|
12
|
+
this._autoConnectAttempted = false;
|
|
11
13
|
this.walletBookWallet = findWalletBookWallet(connector.walletBook, connector.key);
|
|
12
14
|
this.connector = connector;
|
|
13
15
|
}
|
|
16
|
+
get storageKey() {
|
|
17
|
+
return `${STORAGE_KEY_PREFIX}.${this.connector.key}`;
|
|
18
|
+
}
|
|
19
|
+
persistConnection(rdns) {
|
|
20
|
+
try {
|
|
21
|
+
localStorage.setItem(this.storageKey, rdns);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
// localStorage may be unavailable (SSR, private mode, quota exceeded)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
clearPersistedConnection() {
|
|
28
|
+
try {
|
|
29
|
+
localStorage.removeItem(this.storageKey);
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
// localStorage may be unavailable
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
hasPersistedConnection() {
|
|
36
|
+
try {
|
|
37
|
+
return localStorage.getItem(this.storageKey) !== null;
|
|
38
|
+
}
|
|
39
|
+
catch (_a) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
14
43
|
getInjectedConfig() {
|
|
15
44
|
var _a, _b;
|
|
16
45
|
return (_b = (_a = this.walletBookWallet) === null || _a === void 0 ? void 0 : _a.injectedConfig) === null || _b === void 0 ? void 0 : _b.find((c) => c.chain === MIDNIGHT_CHAIN);
|
|
@@ -22,7 +51,10 @@ class MidnightProviderHelper {
|
|
|
22
51
|
return undefined;
|
|
23
52
|
for (const windowLocation of config.windowLocations) {
|
|
24
53
|
const [provider] = getProvidersFromWindow(windowLocation);
|
|
25
|
-
|
|
54
|
+
// Guard against a partially-initialised provider: the wallet shell can
|
|
55
|
+
// appear in window.midnight before its internal registry is ready.
|
|
56
|
+
// rdns being present signals the provider is fully initialised.
|
|
57
|
+
if (provider === null || provider === void 0 ? void 0 : provider.rdns)
|
|
26
58
|
return provider;
|
|
27
59
|
}
|
|
28
60
|
return undefined;
|
|
@@ -32,21 +64,34 @@ class MidnightProviderHelper {
|
|
|
32
64
|
}
|
|
33
65
|
getConnectedAPI() {
|
|
34
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (this._connectedAPI)
|
|
36
|
-
|
|
67
|
+
if (this._connectedAPI) {
|
|
68
|
+
try {
|
|
69
|
+
const { status } = yield this._connectedAPI.getConnectionStatus();
|
|
70
|
+
if (status === 'connected')
|
|
71
|
+
return this._connectedAPI;
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
// Status check failed — treat as disconnected and reconnect below.
|
|
75
|
+
}
|
|
76
|
+
this._connectedAPI = undefined;
|
|
77
|
+
}
|
|
37
78
|
if (this._connectPromise)
|
|
38
79
|
return this._connectPromise;
|
|
39
|
-
const initialProvider = this.getInstalledProvider();
|
|
40
|
-
if (!initialProvider)
|
|
41
|
-
return undefined;
|
|
42
80
|
const generation = this._connectionGeneration;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
81
|
+
// _connectPromise is assigned synchronously (no await) so concurrent callers
|
|
82
|
+
// always share the same promise and never make a second connect() call.
|
|
83
|
+
// waitForProvider() polls window.midnight because extensions inject async.
|
|
84
|
+
this._connectPromise = this.waitForProvider()
|
|
85
|
+
.then((initialProvider) => {
|
|
86
|
+
if (!initialProvider)
|
|
87
|
+
return undefined;
|
|
88
|
+
return initialProvider.connect(this.connector.networkId).then((api) => {
|
|
89
|
+
if (this._connectionGeneration === generation) {
|
|
90
|
+
this._connectedAPI = api;
|
|
91
|
+
this.persistConnection(initialProvider.rdns);
|
|
92
|
+
}
|
|
93
|
+
return this._connectedAPI;
|
|
94
|
+
});
|
|
50
95
|
})
|
|
51
96
|
.catch((err) => {
|
|
52
97
|
logger.error('[MidnightProviderHelper] getConnectedAPI - Error connecting to wallet', err);
|
|
@@ -58,6 +103,40 @@ class MidnightProviderHelper {
|
|
|
58
103
|
return this._connectPromise;
|
|
59
104
|
});
|
|
60
105
|
}
|
|
106
|
+
// Polls window.midnight until the provider injects (extensions inject async).
|
|
107
|
+
// Resolves undefined after timeoutMs if still not present.
|
|
108
|
+
waitForProvider(timeoutMs = 2000) {
|
|
109
|
+
const immediate = this.getInstalledProvider();
|
|
110
|
+
if (immediate)
|
|
111
|
+
return Promise.resolve(immediate);
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
const deadline = Date.now() + timeoutMs;
|
|
114
|
+
const poll = () => {
|
|
115
|
+
const provider = this.getInstalledProvider();
|
|
116
|
+
if (provider)
|
|
117
|
+
return resolve(provider);
|
|
118
|
+
if (Date.now() >= deadline)
|
|
119
|
+
return resolve(undefined);
|
|
120
|
+
setTimeout(poll, 100);
|
|
121
|
+
};
|
|
122
|
+
setTimeout(poll, 100);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// Attempts a silent reconnect using the persisted session. Only tries once per
|
|
126
|
+
// page load — PermissionRejected is tab-scoped so retrying would just fail again.
|
|
127
|
+
// Delegates to getConnectedAPI() so status checks and deduplication are shared.
|
|
128
|
+
tryAutoConnect() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (this._connectPromise)
|
|
131
|
+
return this._connectPromise;
|
|
132
|
+
if (this._autoConnectAttempted)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (!this.hasPersistedConnection())
|
|
135
|
+
return undefined;
|
|
136
|
+
this._autoConnectAttempted = true;
|
|
137
|
+
return this.getConnectedAPI();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
61
140
|
getAddress() {
|
|
62
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
142
|
const api = yield this.getConnectedAPI();
|
|
@@ -67,6 +146,15 @@ class MidnightProviderHelper {
|
|
|
67
146
|
return unshieldedAddress;
|
|
68
147
|
});
|
|
69
148
|
}
|
|
149
|
+
getNetwork() {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const api = yield this.getConnectedAPI();
|
|
152
|
+
if (!api)
|
|
153
|
+
return undefined;
|
|
154
|
+
const { networkId } = yield api.getConfiguration();
|
|
155
|
+
return networkId.toString();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
70
158
|
getAddressIfConnected() {
|
|
71
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
160
|
if (!this._connectedAPI)
|
|
@@ -80,11 +168,14 @@ class MidnightProviderHelper {
|
|
|
80
168
|
const api = yield this.getConnectedAPI();
|
|
81
169
|
if (!api)
|
|
82
170
|
return undefined;
|
|
83
|
-
|
|
171
|
+
// hintUsage pre-fetches signing permission; wallet resolves this only after
|
|
172
|
+
// the user grants it, ensuring signData succeeds immediately on first call.
|
|
173
|
+
yield api.hintUsage(['signData']);
|
|
174
|
+
const { signature, verifyingKey } = yield api.signData(messageToSign, {
|
|
84
175
|
encoding: 'text',
|
|
85
176
|
keyType: 'unshielded',
|
|
86
177
|
});
|
|
87
|
-
return signature;
|
|
178
|
+
return JSON.stringify({ signature, verifyingKey });
|
|
88
179
|
});
|
|
89
180
|
}
|
|
90
181
|
disconnect() {
|
|
@@ -92,6 +183,7 @@ class MidnightProviderHelper {
|
|
|
92
183
|
this._connectionGeneration++;
|
|
93
184
|
this._connectedAPI = undefined;
|
|
94
185
|
this._connectPromise = undefined;
|
|
186
|
+
this.clearPersistedConnection();
|
|
95
187
|
});
|
|
96
188
|
}
|
|
97
189
|
// Midnight ConnectedAPI does not expose event listeners.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.cjs');
|
|
7
|
+
|
|
8
|
+
const MidnightWalletConnectors = (props) => [
|
|
9
|
+
...fetchInjectedWalletConnectors.injectedWalletOverrides,
|
|
10
|
+
...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(Object.assign(Object.assign({}, props), { walletsWithCustomConnectors: [] })),
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
exports.MidnightWalletConnectors = MidnightWalletConnectors;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { injectedWalletOverrides, fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.js';
|
|
3
|
+
|
|
4
|
+
const MidnightWalletConnectors = (props) => [
|
|
5
|
+
...injectedWalletOverrides,
|
|
6
|
+
...fetchInjectedWalletConnectors(Object.assign(Object.assign({}, props), { walletsWithCustomConnectors: [] })),
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export { MidnightWalletConnectors };
|
|
@@ -3,17 +3,100 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
6
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
8
|
var MidnightWallet = require('../wallet/MidnightWallet.cjs');
|
|
9
|
+
var toMidnightNetworks = require('../utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
8
10
|
|
|
11
|
+
const NATIVE_TOKEN = '0'.repeat(64);
|
|
9
12
|
class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
|
+
get networkId() {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
return (_c = (_b = (_a = this.midnightNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '';
|
|
16
|
+
}
|
|
10
17
|
constructor(opts) {
|
|
11
18
|
var _a;
|
|
12
19
|
super(opts);
|
|
13
20
|
this.ChainWallet = MidnightWallet.MidnightWallet;
|
|
14
21
|
this.connectedChain = 'MIDNIGHT';
|
|
15
22
|
this.supportedChains = ['MIDNIGHT'];
|
|
16
|
-
this.
|
|
23
|
+
this.midnightNetworks = toMidnightNetworks.toMidnightNetworks((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
|
|
24
|
+
}
|
|
25
|
+
getEnabledNetworks() {
|
|
26
|
+
return this.midnightNetworks;
|
|
27
|
+
}
|
|
28
|
+
getConnectedAPI() {
|
|
29
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return undefined;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
createTransferTransaction(params) {
|
|
34
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
const api = yield this.getConnectedAPI();
|
|
37
|
+
if (!api) {
|
|
38
|
+
throw new Error('createTransferTransaction is not supported by this connector');
|
|
39
|
+
}
|
|
40
|
+
const types = new Set(params.transfers.map((t) => t.type));
|
|
41
|
+
if (types.size > 1) {
|
|
42
|
+
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
43
|
+
}
|
|
44
|
+
const desiredOutputs = params.transfers.map((t) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return ({
|
|
47
|
+
kind: t.type,
|
|
48
|
+
recipient: t.recipientAddress,
|
|
49
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : NATIVE_TOKEN,
|
|
50
|
+
value: BigInt(t.amount),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
const { tx } = yield api.makeTransfer(desiredOutputs, {
|
|
54
|
+
payFees: (_a = params.payFees) !== null && _a !== void 0 ? _a : false,
|
|
55
|
+
});
|
|
56
|
+
return { serializedTransaction: tx };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getShieldedBalances() {
|
|
60
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const api = yield this.getConnectedAPI();
|
|
62
|
+
if (!api) {
|
|
63
|
+
throw new Error('getShieldedBalances is not supported by this connector');
|
|
64
|
+
}
|
|
65
|
+
return api.getShieldedBalances();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getUnshieldedBalances() {
|
|
69
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const api = yield this.getConnectedAPI();
|
|
71
|
+
if (!api) {
|
|
72
|
+
throw new Error('getUnshieldedBalances is not supported by this connector');
|
|
73
|
+
}
|
|
74
|
+
return api.getUnshieldedBalances();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
getDustBalance() {
|
|
78
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const api = yield this.getConnectedAPI();
|
|
80
|
+
if (!api) {
|
|
81
|
+
throw new Error('getDustBalance is not supported by this connector');
|
|
82
|
+
}
|
|
83
|
+
return api.getDustBalance();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
+
signTransaction(serializedTransaction) {
|
|
88
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
throw new Error('signTransaction is not supported by this connector');
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
submitTransaction(serializedTransaction) {
|
|
93
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const api = yield this.getConnectedAPI();
|
|
95
|
+
if (!api) {
|
|
96
|
+
throw new Error('submitTransaction is not supported by this connector');
|
|
97
|
+
}
|
|
98
|
+
yield api.submitTransaction(serializedTransaction);
|
|
99
|
+
});
|
|
17
100
|
}
|
|
18
101
|
}
|
|
19
102
|
|
|
@@ -1,15 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ConnectedAPI, TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
|
+
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { GenericNetwork } from '@dynamic-labs/types';
|
|
3
4
|
import { MidnightWallet } from '../wallet/MidnightWallet';
|
|
4
|
-
|
|
5
|
-
walletBook: WalletBookSchema;
|
|
6
|
-
metadata?: WalletMetadata;
|
|
7
|
-
networkId?: string;
|
|
8
|
-
};
|
|
5
|
+
import { MidnightNetwork, MidnightWalletConnectorOpts } from '../types';
|
|
9
6
|
export declare abstract class MidnightWalletConnector extends WalletConnectorBase<typeof MidnightWallet> {
|
|
7
|
+
midnightNetworks: MidnightNetwork[];
|
|
10
8
|
ChainWallet: typeof MidnightWallet;
|
|
11
9
|
connectedChain: Chain;
|
|
12
10
|
supportedChains: Chain[];
|
|
13
|
-
networkId: string;
|
|
11
|
+
get networkId(): string;
|
|
14
12
|
constructor(opts: MidnightWalletConnectorOpts);
|
|
13
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
14
|
+
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
15
|
+
createTransferTransaction(params: {
|
|
16
|
+
transfers: Array<{
|
|
17
|
+
type: 'unshielded' | 'shielded';
|
|
18
|
+
recipientAddress: string;
|
|
19
|
+
amount: string;
|
|
20
|
+
tokenType?: string;
|
|
21
|
+
}>;
|
|
22
|
+
payFees?: boolean;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
serializedTransaction: string;
|
|
25
|
+
}>;
|
|
26
|
+
getShieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
27
|
+
getUnshieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
28
|
+
getDustBalance(): Promise<{
|
|
29
|
+
cap: bigint;
|
|
30
|
+
balance: bigint;
|
|
31
|
+
}>;
|
|
32
|
+
signTransaction(serializedTransaction: string): Promise<string>;
|
|
33
|
+
submitTransaction(serializedTransaction: string): Promise<void>;
|
|
15
34
|
}
|
|
@@ -1,15 +1,98 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
3
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
import { MidnightWallet } from '../wallet/MidnightWallet.js';
|
|
5
|
+
import { toMidnightNetworks } from '../utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
4
6
|
|
|
7
|
+
const NATIVE_TOKEN = '0'.repeat(64);
|
|
5
8
|
class MidnightWalletConnector extends WalletConnectorBase {
|
|
9
|
+
get networkId() {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
return (_c = (_b = (_a = this.midnightNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '';
|
|
12
|
+
}
|
|
6
13
|
constructor(opts) {
|
|
7
14
|
var _a;
|
|
8
15
|
super(opts);
|
|
9
16
|
this.ChainWallet = MidnightWallet;
|
|
10
17
|
this.connectedChain = 'MIDNIGHT';
|
|
11
18
|
this.supportedChains = ['MIDNIGHT'];
|
|
12
|
-
this.
|
|
19
|
+
this.midnightNetworks = toMidnightNetworks((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
|
|
20
|
+
}
|
|
21
|
+
getEnabledNetworks() {
|
|
22
|
+
return this.midnightNetworks;
|
|
23
|
+
}
|
|
24
|
+
getConnectedAPI() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return undefined;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
createTransferTransaction(params) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a;
|
|
32
|
+
const api = yield this.getConnectedAPI();
|
|
33
|
+
if (!api) {
|
|
34
|
+
throw new Error('createTransferTransaction is not supported by this connector');
|
|
35
|
+
}
|
|
36
|
+
const types = new Set(params.transfers.map((t) => t.type));
|
|
37
|
+
if (types.size > 1) {
|
|
38
|
+
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
39
|
+
}
|
|
40
|
+
const desiredOutputs = params.transfers.map((t) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return ({
|
|
43
|
+
kind: t.type,
|
|
44
|
+
recipient: t.recipientAddress,
|
|
45
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : NATIVE_TOKEN,
|
|
46
|
+
value: BigInt(t.amount),
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const { tx } = yield api.makeTransfer(desiredOutputs, {
|
|
50
|
+
payFees: (_a = params.payFees) !== null && _a !== void 0 ? _a : false,
|
|
51
|
+
});
|
|
52
|
+
return { serializedTransaction: tx };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getShieldedBalances() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const api = yield this.getConnectedAPI();
|
|
58
|
+
if (!api) {
|
|
59
|
+
throw new Error('getShieldedBalances is not supported by this connector');
|
|
60
|
+
}
|
|
61
|
+
return api.getShieldedBalances();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getUnshieldedBalances() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const api = yield this.getConnectedAPI();
|
|
67
|
+
if (!api) {
|
|
68
|
+
throw new Error('getUnshieldedBalances is not supported by this connector');
|
|
69
|
+
}
|
|
70
|
+
return api.getUnshieldedBalances();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
getDustBalance() {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const api = yield this.getConnectedAPI();
|
|
76
|
+
if (!api) {
|
|
77
|
+
throw new Error('getDustBalance is not supported by this connector');
|
|
78
|
+
}
|
|
79
|
+
return api.getDustBalance();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
signTransaction(serializedTransaction) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
throw new Error('signTransaction is not supported by this connector');
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
submitTransaction(serializedTransaction) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const api = yield this.getConnectedAPI();
|
|
91
|
+
if (!api) {
|
|
92
|
+
throw new Error('submitTransaction is not supported by this connector');
|
|
93
|
+
}
|
|
94
|
+
yield api.submitTransaction(serializedTransaction);
|
|
95
|
+
});
|
|
13
96
|
}
|
|
14
97
|
}
|
|
15
98
|
|
package/src/index.cjs
CHANGED
|
@@ -5,24 +5,29 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
7
|
var _package = require('../package.cjs');
|
|
8
|
+
var MidnightWalletConnectors = require('./MidnightWalletConnectors.cjs');
|
|
8
9
|
var MidnightWalletConnector = require('./connectors/MidnightWalletConnector.cjs');
|
|
9
10
|
var MidnightWallet = require('./wallet/MidnightWallet.cjs');
|
|
10
11
|
var MidnightProviderHelper = require('./MidnightProviderHelper/MidnightProviderHelper.cjs');
|
|
11
12
|
var InjectedWalletBase = require('./injected/InjectedWalletBase/InjectedWalletBase.cjs');
|
|
12
|
-
var Midnight1am = require('./injected/Midnight1am/Midnight1am.cjs');
|
|
13
13
|
var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.cjs');
|
|
14
14
|
var getConnectorConstructorInjectedWallet = require('./utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs');
|
|
15
|
+
var toMidnightNetworks = require('./utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
15
16
|
var constants = require('./constants.cjs');
|
|
17
|
+
var isMidnightWallet = require('./wallet/isMidnightWallet/isMidnightWallet.cjs');
|
|
16
18
|
|
|
19
|
+
/* istanbul ignore file */
|
|
17
20
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/midnight', _package.version);
|
|
18
21
|
|
|
22
|
+
exports.MidnightWalletConnectors = MidnightWalletConnectors.MidnightWalletConnectors;
|
|
19
23
|
exports.MidnightWalletConnector = MidnightWalletConnector.MidnightWalletConnector;
|
|
20
24
|
exports.MidnightWallet = MidnightWallet.MidnightWallet;
|
|
21
25
|
exports.MidnightProviderHelper = MidnightProviderHelper.MidnightProviderHelper;
|
|
22
26
|
exports.InjectedWalletBase = InjectedWalletBase.InjectedWalletBase;
|
|
23
|
-
exports.Midnight1am = Midnight1am.Midnight1am;
|
|
24
27
|
exports.fetchInjectedWalletConnectors = fetchInjectedWalletConnectors.fetchInjectedWalletConnectors;
|
|
25
28
|
exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOverrides;
|
|
26
29
|
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet;
|
|
30
|
+
exports.toMidnightNetworks = toMidnightNetworks.toMidnightNetworks;
|
|
27
31
|
exports.MIDNIGHT_CHAIN = constants.MIDNIGHT_CHAIN;
|
|
28
32
|
exports.MIDNIGHT_NETWORKS = constants.MIDNIGHT_NETWORKS;
|
|
33
|
+
exports.isMidnightWallet = isMidnightWallet.isMidnightWallet;
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export * from './MidnightWalletConnectors';
|
|
1
2
|
export * from './connectors';
|
|
2
3
|
export * from './wallet';
|
|
3
4
|
export * from './MidnightProviderHelper';
|
|
4
5
|
export * from './injected/InjectedWalletBase';
|
|
5
|
-
export * from './injected/Midnight1am';
|
|
6
6
|
export * from './injected/fetchInjectedWalletConnectors';
|
|
7
7
|
export * from './utils/getConnectorConstructorInjectedWallet';
|
|
8
|
+
export * from './utils/toMidnightNetworks';
|
|
8
9
|
export * from './constants';
|
|
9
10
|
export * from './types';
|
|
11
|
+
export { isMidnightWallet } from './wallet/isMidnightWallet';
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
|
+
export { MidnightWalletConnectors } from './MidnightWalletConnectors.js';
|
|
4
5
|
export { MidnightWalletConnector } from './connectors/MidnightWalletConnector.js';
|
|
5
6
|
export { MidnightWallet } from './wallet/MidnightWallet.js';
|
|
6
7
|
export { MidnightProviderHelper } from './MidnightProviderHelper/MidnightProviderHelper.js';
|
|
7
8
|
export { InjectedWalletBase } from './injected/InjectedWalletBase/InjectedWalletBase.js';
|
|
8
|
-
export { Midnight1am } from './injected/Midnight1am/Midnight1am.js';
|
|
9
9
|
export { fetchInjectedWalletConnectors, injectedWalletOverrides } from './injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.js';
|
|
10
10
|
export { getConnectorConstructorInjectedWallet } from './utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js';
|
|
11
|
+
export { toMidnightNetworks } from './utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
11
12
|
export { MIDNIGHT_CHAIN, MIDNIGHT_NETWORKS } from './constants.js';
|
|
13
|
+
export { isMidnightWallet } from './wallet/isMidnightWallet/isMidnightWallet.js';
|
|
12
14
|
|
|
15
|
+
/* istanbul ignore file */
|
|
13
16
|
assertPackageVersion('@dynamic-labs/midnight', version);
|
|
@@ -17,6 +17,11 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
17
17
|
findProvider() {
|
|
18
18
|
return this.midnightProviderHelper.getInstalledProvider();
|
|
19
19
|
}
|
|
20
|
+
getConnectedAPI() {
|
|
21
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
20
25
|
isInstalledOnBrowser() {
|
|
21
26
|
return this.midnightProviderHelper.isInstalledHelper();
|
|
22
27
|
}
|
|
@@ -25,6 +30,11 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
25
30
|
yield this.midnightProviderHelper.getConnectedAPI();
|
|
26
31
|
});
|
|
27
32
|
}
|
|
33
|
+
getNetwork() {
|
|
34
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return this.midnightProviderHelper.getNetwork();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
28
38
|
getAddress() {
|
|
29
39
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
40
|
const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
|
|
@@ -59,7 +69,13 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
59
69
|
getConnectedAccounts() {
|
|
60
70
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
71
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
62
|
-
|
|
72
|
+
if (address)
|
|
73
|
+
return [address];
|
|
74
|
+
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
75
|
+
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
76
|
+
yield this.midnightProviderHelper.tryAutoConnect();
|
|
77
|
+
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
78
|
+
return autoAddress ? [autoAddress] : [];
|
|
63
79
|
});
|
|
64
80
|
}
|
|
65
81
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { InitialAPI } from '@midnight-ntwrk/dapp-connector-api';
|
|
1
|
+
import type { ConnectedAPI, InitialAPI } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
2
|
import { MidnightWalletConnector } from '../../connectors/MidnightWalletConnector';
|
|
3
3
|
import { MidnightProviderHelper } from '../../MidnightProviderHelper/MidnightProviderHelper';
|
|
4
4
|
export declare abstract class InjectedWalletBase extends MidnightWalletConnector {
|
|
5
5
|
_midnightProviderHelper: MidnightProviderHelper | undefined;
|
|
6
6
|
get midnightProviderHelper(): MidnightProviderHelper;
|
|
7
7
|
findProvider(): InitialAPI | undefined;
|
|
8
|
+
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
8
9
|
isInstalledOnBrowser(): boolean;
|
|
9
10
|
connect(): Promise<void>;
|
|
11
|
+
getNetwork(): Promise<string | undefined>;
|
|
10
12
|
getAddress(): Promise<string | undefined>;
|
|
11
13
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
12
14
|
proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
|
|
@@ -13,6 +13,11 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
13
13
|
findProvider() {
|
|
14
14
|
return this.midnightProviderHelper.getInstalledProvider();
|
|
15
15
|
}
|
|
16
|
+
getConnectedAPI() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
isInstalledOnBrowser() {
|
|
17
22
|
return this.midnightProviderHelper.isInstalledHelper();
|
|
18
23
|
}
|
|
@@ -21,6 +26,11 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
21
26
|
yield this.midnightProviderHelper.getConnectedAPI();
|
|
22
27
|
});
|
|
23
28
|
}
|
|
29
|
+
getNetwork() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return this.midnightProviderHelper.getNetwork();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
24
34
|
getAddress() {
|
|
25
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
36
|
const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
|
|
@@ -55,7 +65,13 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
55
65
|
getConnectedAccounts() {
|
|
56
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
67
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
58
|
-
|
|
68
|
+
if (address)
|
|
69
|
+
return [address];
|
|
70
|
+
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
71
|
+
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
72
|
+
yield this.midnightProviderHelper.tryAutoConnect();
|
|
73
|
+
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
74
|
+
return autoAddress ? [autoAddress] : [];
|
|
59
75
|
});
|
|
60
76
|
}
|
|
61
77
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { GenericNetwork, WalletMetadata } from '@dynamic-labs/types';
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
1
3
|
import { MIDNIGHT_NETWORKS } from './constants';
|
|
4
|
+
export type MidnightNetwork = Omit<GenericNetwork, 'chainId'> & {
|
|
5
|
+
chainId: string;
|
|
6
|
+
};
|
|
2
7
|
export type MidnightNetworkId = typeof MIDNIGHT_NETWORKS[keyof typeof MIDNIGHT_NETWORKS];
|
|
3
8
|
/**
|
|
4
9
|
* A single proof-based call to a Midnight contract circuit.
|
|
@@ -34,3 +39,8 @@ export type IMidnightWalletProvider = {
|
|
|
34
39
|
getNetwork(): Promise<MidnightNetworkId>;
|
|
35
40
|
};
|
|
36
41
|
export type { InitialAPI as Midnight1amInitialAPI, ConnectedAPI as Midnight1amConnectedAPI, WalletConnectedAPI as Midnight1amWalletConnectedAPI, HintUsage as Midnight1amHintUsage, Configuration as Midnight1amConfiguration, ConnectionStatus as Midnight1amConnectionStatus, TxStatus as Midnight1amTxStatus, ExecutionStatus as Midnight1amExecutionStatus, HistoryEntry as Midnight1amHistoryEntry, DesiredOutput as Midnight1amDesiredOutput, DesiredInput as Midnight1amDesiredInput, TokenType as Midnight1amTokenType, SignDataOptions as Midnight1amSignDataOptions, Signature as Midnight1amSignature, KeyMaterialProvider as Midnight1amKeyMaterialProvider, ProvingProvider as Midnight1amProvingProvider, } from '@midnight-ntwrk/dapp-connector-api';
|
|
42
|
+
export type MidnightWalletConnectorOpts = {
|
|
43
|
+
midnightNetworks?: GenericNetwork[];
|
|
44
|
+
walletBook: WalletBookSchema;
|
|
45
|
+
metadata?: WalletMetadata;
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './toMidnightNetworks';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const toMidnightNetworks = (networks) => networks.map((network) => (Object.assign(Object.assign({}, network), { chainId: network.name })));
|
|
7
|
+
|
|
8
|
+
exports.toMidnightNetworks = toMidnightNetworks;
|
|
@@ -7,10 +7,21 @@ var _tslib = require('../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
8
|
|
|
9
9
|
class MidnightWallet extends walletConnectorCore.Wallet {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
sendBalance(_a) {
|
|
11
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
12
|
+
const type = toAddress.startsWith('mn_shield') ? 'shielded' : 'unshielded';
|
|
13
|
+
const { serializedTransaction } = yield this._connector.createTransferTransaction({
|
|
14
|
+
transfers: [
|
|
15
|
+
{
|
|
16
|
+
amount,
|
|
17
|
+
recipientAddress: toAddress,
|
|
18
|
+
tokenType: token === null || token === void 0 ? void 0 : token.address,
|
|
19
|
+
type,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
const signedTransaction = yield this._connector.signTransaction(serializedTransaction);
|
|
24
|
+
yield this._connector.submitTransaction(signedTransaction);
|
|
14
25
|
});
|
|
15
26
|
}
|
|
16
27
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
2
|
import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector';
|
|
3
3
|
export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
4
|
-
sendBalance(
|
|
4
|
+
sendBalance({ amount, toAddress, token, }: {
|
|
5
5
|
amount: string;
|
|
6
6
|
toAddress: string;
|
|
7
7
|
token?: {
|
|
8
8
|
address: string;
|
|
9
9
|
decimals?: number;
|
|
10
10
|
};
|
|
11
|
-
}): Promise<
|
|
11
|
+
}): Promise<undefined>;
|
|
12
12
|
}
|
|
@@ -3,10 +3,21 @@ import { __awaiter } from '../../_virtual/_tslib.js';
|
|
|
3
3
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
|
|
5
5
|
class MidnightWallet extends Wallet {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
sendBalance(_a) {
|
|
7
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
8
|
+
const type = toAddress.startsWith('mn_shield') ? 'shielded' : 'unshielded';
|
|
9
|
+
const { serializedTransaction } = yield this._connector.createTransferTransaction({
|
|
10
|
+
transfers: [
|
|
11
|
+
{
|
|
12
|
+
amount,
|
|
13
|
+
recipientAddress: toAddress,
|
|
14
|
+
tokenType: token === null || token === void 0 ? void 0 : token.address,
|
|
15
|
+
type,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
const signedTransaction = yield this._connector.signTransaction(serializedTransaction);
|
|
20
|
+
yield this._connector.submitTransaction(signedTransaction);
|
|
10
21
|
});
|
|
11
22
|
}
|
|
12
23
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isMidnightWallet } from './isMidnightWallet';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var InjectedWalletBase = require('../InjectedWalletBase/InjectedWalletBase.cjs');
|
|
7
|
-
|
|
8
|
-
class Midnight1am extends InjectedWalletBase.InjectedWalletBase {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.name = '1am';
|
|
12
|
-
this.overrideKey = '1ammidnight';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.Midnight1am = Midnight1am;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { InjectedWalletBase } from '../InjectedWalletBase/InjectedWalletBase.js';
|
|
3
|
-
|
|
4
|
-
class Midnight1am extends InjectedWalletBase {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.name = '1am';
|
|
8
|
-
this.overrideKey = '1ammidnight';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { Midnight1am };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Midnight1am';
|