@dynamic-labs/midnight 4.79.2 → 4.80.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.
- package/CHANGELOG.md +9 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -6
- package/src/MidnightProviderHelper/MidnightProviderHelper.cjs +48 -17
- package/src/MidnightProviderHelper/MidnightProviderHelper.d.ts +10 -2
- package/src/MidnightProviderHelper/MidnightProviderHelper.js +49 -18
- package/src/connectors/MidnightWalletConnector.cjs +38 -5
- package/src/connectors/MidnightWalletConnector.d.ts +20 -1
- package/src/connectors/MidnightWalletConnector.js +38 -5
- package/src/constants.cjs +29 -0
- package/src/constants.d.ts +17 -0
- package/src/constants.js +27 -1
- package/src/index.cjs +6 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.cjs +74 -2
- package/src/injected/InjectedWalletBase/InjectedWalletBase.d.ts +17 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.js +74 -2
- package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs +32 -0
- package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.d.ts +5 -0
- package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js +28 -0
- package/src/utils/formatMidnightNativeUnshieldedBalance/index.d.ts +1 -0
- package/src/wallet/MidnightWallet.cjs +41 -0
- package/src/wallet/MidnightWallet.d.ts +18 -0
- package/src/wallet/MidnightWallet.js +41 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.80.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.79.2...v4.80.0) (2026-05-05)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **aleo:** Aleo wallet connectors + send/shield token registries + UI transaction type ([#11101](https://github.com/dynamic-labs/dynamic-auth/issues/11101)) ([5478d9c](https://github.com/dynamic-labs/dynamic-auth/commit/5478d9c21ee065e2e6c8e96d37ab17b74c5aa0f8))
|
|
8
|
+
* **midnight:** add address query methods and getProvider to InjectedWalletBase ([#11082](https://github.com/dynamic-labs/dynamic-auth/issues/11082)) ([9b6a870](https://github.com/dynamic-labs/dynamic-auth/commit/9b6a8709f83d04673e9dbe23bb0caae5827b036c))
|
|
9
|
+
* **ton:** recognize v3R1/v3R2/v4 wallets in TonConnect proof verification ([#11130](https://github.com/dynamic-labs/dynamic-auth/issues/11130)) ([6c40ab1](https://github.com/dynamic-labs/dynamic-auth/commit/6c40ab11e56d56e278aeb5ee2ae982a42767b5cb))
|
|
10
|
+
|
|
2
11
|
### [4.79.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.79.1...v4.79.2) (2026-05-04)
|
|
3
12
|
|
|
4
13
|
|
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.
|
|
3
|
+
"version": "4.80.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,12 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.80.0",
|
|
22
|
+
"@dynamic-labs/sdk-api-core": "0.0.964",
|
|
22
23
|
"@midnight-ntwrk/dapp-connector-api": "4.0.1",
|
|
23
|
-
"@dynamic-labs/types": "4.
|
|
24
|
-
"@dynamic-labs/utils": "4.
|
|
25
|
-
"@dynamic-labs/wallet-book": "4.
|
|
26
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
24
|
+
"@dynamic-labs/types": "4.80.0",
|
|
25
|
+
"@dynamic-labs/utils": "4.80.0",
|
|
26
|
+
"@dynamic-labs/wallet-book": "4.80.0",
|
|
27
|
+
"@dynamic-labs/wallet-connector-core": "4.80.0"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {}
|
|
29
30
|
}
|
|
@@ -8,17 +8,21 @@ var utils = require('@dynamic-labs/utils');
|
|
|
8
8
|
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
|
+
var formatMidnightNativeUnshieldedBalance = require('../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
11
12
|
|
|
12
13
|
const STORAGE_KEY_PREFIX = 'midnight.connected';
|
|
13
14
|
class MidnightProviderHelper {
|
|
14
15
|
constructor(connector) {
|
|
15
|
-
this._connectionGeneration = 0;
|
|
16
16
|
this._autoConnectAttempted = false;
|
|
17
17
|
this.walletBookWallet = walletBook.findWalletBookWallet(connector.walletBook, connector.key);
|
|
18
18
|
this.connector = connector;
|
|
19
19
|
}
|
|
20
20
|
get storageKey() {
|
|
21
|
-
|
|
21
|
+
const { key } = this.connector;
|
|
22
|
+
if (!key) {
|
|
23
|
+
throw new Error('[MidnightProviderHelper] connector.key is required for session persistence');
|
|
24
|
+
}
|
|
25
|
+
return `${STORAGE_KEY_PREFIX}.${key}`;
|
|
22
26
|
}
|
|
23
27
|
persistConnection(rdns) {
|
|
24
28
|
try {
|
|
@@ -81,20 +85,23 @@ class MidnightProviderHelper {
|
|
|
81
85
|
}
|
|
82
86
|
if (this._connectPromise)
|
|
83
87
|
return this._connectPromise;
|
|
84
|
-
|
|
85
|
-
// _connectPromise is assigned synchronously (no await) so concurrent callers
|
|
86
|
-
// always share the same promise and never make a second connect() call.
|
|
88
|
+
// Assigned synchronously so concurrent callers share the same promise.
|
|
87
89
|
// waitForProvider() polls window.midnight because extensions inject async.
|
|
88
|
-
|
|
90
|
+
const connectPromise = this.waitForProvider()
|
|
89
91
|
.then((initialProvider) => {
|
|
90
92
|
if (!initialProvider)
|
|
91
93
|
return undefined;
|
|
92
|
-
return initialProvider
|
|
93
|
-
|
|
94
|
+
return initialProvider
|
|
95
|
+
.connect(this.connector.networkId)
|
|
96
|
+
.then((api) => {
|
|
97
|
+
// Only cache if this promise is still the active one.
|
|
98
|
+
// disconnect() nulls _connectPromise, so a stale resolve after
|
|
99
|
+
// disconnect won't overwrite the cleared connection state.
|
|
100
|
+
if (this._connectPromise === connectPromise) {
|
|
94
101
|
this._connectedAPI = api;
|
|
95
102
|
this.persistConnection(initialProvider.rdns);
|
|
96
103
|
}
|
|
97
|
-
return
|
|
104
|
+
return api;
|
|
98
105
|
});
|
|
99
106
|
})
|
|
100
107
|
.catch((err) => {
|
|
@@ -102,9 +109,12 @@ class MidnightProviderHelper {
|
|
|
102
109
|
return undefined;
|
|
103
110
|
})
|
|
104
111
|
.finally(() => {
|
|
105
|
-
this._connectPromise
|
|
112
|
+
if (this._connectPromise === connectPromise) {
|
|
113
|
+
this._connectPromise = undefined;
|
|
114
|
+
}
|
|
106
115
|
});
|
|
107
|
-
|
|
116
|
+
this._connectPromise = connectPromise;
|
|
117
|
+
return connectPromise;
|
|
108
118
|
});
|
|
109
119
|
}
|
|
110
120
|
// Polls window.midnight until the provider injects (extensions inject async).
|
|
@@ -152,11 +162,7 @@ class MidnightProviderHelper {
|
|
|
152
162
|
}
|
|
153
163
|
getNetwork() {
|
|
154
164
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
|
|
156
|
-
if (!api)
|
|
157
|
-
return undefined;
|
|
158
|
-
const { networkId } = yield api.getConfiguration();
|
|
159
|
-
return networkId.toString();
|
|
165
|
+
return this.connector.networkId;
|
|
160
166
|
});
|
|
161
167
|
}
|
|
162
168
|
getAddressIfConnected() {
|
|
@@ -167,6 +173,32 @@ class MidnightProviderHelper {
|
|
|
167
173
|
return unshieldedAddress;
|
|
168
174
|
});
|
|
169
175
|
}
|
|
176
|
+
getUnshieldedBalance() {
|
|
177
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const api = yield this.getConnectedAPI();
|
|
179
|
+
if (!api)
|
|
180
|
+
return undefined;
|
|
181
|
+
const response = yield api.getUnshieldedBalances();
|
|
182
|
+
const raw = response[constants.MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
183
|
+
if (raw === undefined)
|
|
184
|
+
return undefined;
|
|
185
|
+
return formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(raw);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
getBalances() {
|
|
189
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
const api = yield this.getConnectedAPI();
|
|
191
|
+
if (!api) {
|
|
192
|
+
throw new Error('[MidnightProviderHelper] getBalances requires a connected Midnight wallet');
|
|
193
|
+
}
|
|
194
|
+
const [shielded, unshielded, dust] = yield Promise.all([
|
|
195
|
+
api.getShieldedBalances(),
|
|
196
|
+
api.getUnshieldedBalances(),
|
|
197
|
+
api.getDustBalance(),
|
|
198
|
+
]);
|
|
199
|
+
return { dust, shielded, unshielded };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
170
202
|
signMessage(messageToSign) {
|
|
171
203
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
172
204
|
const api = yield this.getConnectedAPI();
|
|
@@ -184,7 +216,6 @@ class MidnightProviderHelper {
|
|
|
184
216
|
}
|
|
185
217
|
disconnect() {
|
|
186
218
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
this._connectionGeneration++;
|
|
188
219
|
this._connectedAPI = undefined;
|
|
189
220
|
this._connectPromise = undefined;
|
|
190
221
|
this.clearPersistedConnection();
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { ConnectedAPI, InitialAPI } from '@midnight-ntwrk/dapp-connector-api';
|
|
1
|
+
import type { ConnectedAPI, InitialAPI, TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
2
|
import type { InjectedWalletBase } from '../injected/InjectedWalletBase/InjectedWalletBase';
|
|
3
3
|
export declare class MidnightProviderHelper {
|
|
4
4
|
private walletBookWallet;
|
|
5
5
|
private connector;
|
|
6
6
|
private _connectedAPI;
|
|
7
7
|
private _connectPromise;
|
|
8
|
-
private _connectionGeneration;
|
|
9
8
|
private _autoConnectAttempted;
|
|
10
9
|
constructor(connector: InjectedWalletBase);
|
|
11
10
|
private get storageKey();
|
|
@@ -38,6 +37,15 @@ export declare class MidnightProviderHelper {
|
|
|
38
37
|
getAddress(): Promise<string | undefined>;
|
|
39
38
|
getNetwork(): Promise<string | undefined>;
|
|
40
39
|
getAddressIfConnected(): Promise<string | undefined>;
|
|
40
|
+
getUnshieldedBalance(): Promise<string | undefined>;
|
|
41
|
+
getBalances(): Promise<{
|
|
42
|
+
dust: {
|
|
43
|
+
balance: bigint;
|
|
44
|
+
cap: bigint;
|
|
45
|
+
};
|
|
46
|
+
shielded: Record<TokenType, bigint>;
|
|
47
|
+
unshielded: Record<TokenType, bigint>;
|
|
48
|
+
}>;
|
|
41
49
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
42
50
|
disconnect(): Promise<void>;
|
|
43
51
|
_setupEventListeners(): void;
|
|
@@ -3,18 +3,22 @@ import { __awaiter } from '../../_virtual/_tslib.js';
|
|
|
3
3
|
import { getProvidersFromWindow } from '@dynamic-labs/utils';
|
|
4
4
|
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
5
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
-
import { MIDNIGHT_CHAIN } from '../constants.js';
|
|
6
|
+
import { MIDNIGHT_CHAIN, MIDNIGHT_NATIVE_TOKEN_TYPE } from '../constants.js';
|
|
7
|
+
import { formatMidnightNativeUnshieldedBalance } from '../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
7
8
|
|
|
8
9
|
const STORAGE_KEY_PREFIX = 'midnight.connected';
|
|
9
10
|
class MidnightProviderHelper {
|
|
10
11
|
constructor(connector) {
|
|
11
|
-
this._connectionGeneration = 0;
|
|
12
12
|
this._autoConnectAttempted = false;
|
|
13
13
|
this.walletBookWallet = findWalletBookWallet(connector.walletBook, connector.key);
|
|
14
14
|
this.connector = connector;
|
|
15
15
|
}
|
|
16
16
|
get storageKey() {
|
|
17
|
-
|
|
17
|
+
const { key } = this.connector;
|
|
18
|
+
if (!key) {
|
|
19
|
+
throw new Error('[MidnightProviderHelper] connector.key is required for session persistence');
|
|
20
|
+
}
|
|
21
|
+
return `${STORAGE_KEY_PREFIX}.${key}`;
|
|
18
22
|
}
|
|
19
23
|
persistConnection(rdns) {
|
|
20
24
|
try {
|
|
@@ -77,20 +81,23 @@ class MidnightProviderHelper {
|
|
|
77
81
|
}
|
|
78
82
|
if (this._connectPromise)
|
|
79
83
|
return this._connectPromise;
|
|
80
|
-
|
|
81
|
-
// _connectPromise is assigned synchronously (no await) so concurrent callers
|
|
82
|
-
// always share the same promise and never make a second connect() call.
|
|
84
|
+
// Assigned synchronously so concurrent callers share the same promise.
|
|
83
85
|
// waitForProvider() polls window.midnight because extensions inject async.
|
|
84
|
-
|
|
86
|
+
const connectPromise = this.waitForProvider()
|
|
85
87
|
.then((initialProvider) => {
|
|
86
88
|
if (!initialProvider)
|
|
87
89
|
return undefined;
|
|
88
|
-
return initialProvider
|
|
89
|
-
|
|
90
|
+
return initialProvider
|
|
91
|
+
.connect(this.connector.networkId)
|
|
92
|
+
.then((api) => {
|
|
93
|
+
// Only cache if this promise is still the active one.
|
|
94
|
+
// disconnect() nulls _connectPromise, so a stale resolve after
|
|
95
|
+
// disconnect won't overwrite the cleared connection state.
|
|
96
|
+
if (this._connectPromise === connectPromise) {
|
|
90
97
|
this._connectedAPI = api;
|
|
91
98
|
this.persistConnection(initialProvider.rdns);
|
|
92
99
|
}
|
|
93
|
-
return
|
|
100
|
+
return api;
|
|
94
101
|
});
|
|
95
102
|
})
|
|
96
103
|
.catch((err) => {
|
|
@@ -98,9 +105,12 @@ class MidnightProviderHelper {
|
|
|
98
105
|
return undefined;
|
|
99
106
|
})
|
|
100
107
|
.finally(() => {
|
|
101
|
-
this._connectPromise
|
|
108
|
+
if (this._connectPromise === connectPromise) {
|
|
109
|
+
this._connectPromise = undefined;
|
|
110
|
+
}
|
|
102
111
|
});
|
|
103
|
-
|
|
112
|
+
this._connectPromise = connectPromise;
|
|
113
|
+
return connectPromise;
|
|
104
114
|
});
|
|
105
115
|
}
|
|
106
116
|
// Polls window.midnight until the provider injects (extensions inject async).
|
|
@@ -148,11 +158,7 @@ class MidnightProviderHelper {
|
|
|
148
158
|
}
|
|
149
159
|
getNetwork() {
|
|
150
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
|
|
152
|
-
if (!api)
|
|
153
|
-
return undefined;
|
|
154
|
-
const { networkId } = yield api.getConfiguration();
|
|
155
|
-
return networkId.toString();
|
|
161
|
+
return this.connector.networkId;
|
|
156
162
|
});
|
|
157
163
|
}
|
|
158
164
|
getAddressIfConnected() {
|
|
@@ -163,6 +169,32 @@ class MidnightProviderHelper {
|
|
|
163
169
|
return unshieldedAddress;
|
|
164
170
|
});
|
|
165
171
|
}
|
|
172
|
+
getUnshieldedBalance() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const api = yield this.getConnectedAPI();
|
|
175
|
+
if (!api)
|
|
176
|
+
return undefined;
|
|
177
|
+
const response = yield api.getUnshieldedBalances();
|
|
178
|
+
const raw = response[MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
179
|
+
if (raw === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
return formatMidnightNativeUnshieldedBalance(raw);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getBalances() {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const api = yield this.getConnectedAPI();
|
|
187
|
+
if (!api) {
|
|
188
|
+
throw new Error('[MidnightProviderHelper] getBalances requires a connected Midnight wallet');
|
|
189
|
+
}
|
|
190
|
+
const [shielded, unshielded, dust] = yield Promise.all([
|
|
191
|
+
api.getShieldedBalances(),
|
|
192
|
+
api.getUnshieldedBalances(),
|
|
193
|
+
api.getDustBalance(),
|
|
194
|
+
]);
|
|
195
|
+
return { dust, shielded, unshielded };
|
|
196
|
+
});
|
|
197
|
+
}
|
|
166
198
|
signMessage(messageToSign) {
|
|
167
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
200
|
const api = yield this.getConnectedAPI();
|
|
@@ -180,7 +212,6 @@ class MidnightProviderHelper {
|
|
|
180
212
|
}
|
|
181
213
|
disconnect() {
|
|
182
214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
this._connectionGeneration++;
|
|
184
215
|
this._connectedAPI = undefined;
|
|
185
216
|
this._connectPromise = undefined;
|
|
186
217
|
this.clearPersistedConnection();
|
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var constants = require('../constants.cjs');
|
|
8
9
|
var MidnightWallet = require('../wallet/MidnightWallet.cjs');
|
|
9
10
|
var toMidnightNetworks = require('../utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
10
11
|
|
|
11
|
-
const NATIVE_TOKEN = '0'.repeat(64);
|
|
12
12
|
class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
13
|
get networkId() {
|
|
14
14
|
var _a, _b, _c;
|
|
@@ -22,6 +22,9 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
22
22
|
this.supportedChains = ['MIDNIGHT'];
|
|
23
23
|
this.midnightNetworks = toMidnightNetworks.toMidnightNetworks((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
|
|
24
24
|
}
|
|
25
|
+
getBalances() {
|
|
26
|
+
throw new Error('getBalances is not supported by this connector');
|
|
27
|
+
}
|
|
25
28
|
getEnabledNetworks() {
|
|
26
29
|
return this.midnightNetworks;
|
|
27
30
|
}
|
|
@@ -37,6 +40,9 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
37
40
|
if (!api) {
|
|
38
41
|
throw new Error('createTransferTransaction is not supported by this connector');
|
|
39
42
|
}
|
|
43
|
+
if (params.transfers.length === 0) {
|
|
44
|
+
throw new Error('createTransferTransaction requires at least one transfer');
|
|
45
|
+
}
|
|
40
46
|
const types = new Set(params.transfers.map((t) => t.type));
|
|
41
47
|
if (types.size > 1) {
|
|
42
48
|
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
@@ -46,7 +52,7 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
46
52
|
return ({
|
|
47
53
|
kind: t.type,
|
|
48
54
|
recipient: t.recipientAddress,
|
|
49
|
-
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a :
|
|
55
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : constants.MIDNIGHT_NATIVE_TOKEN_TYPE,
|
|
50
56
|
value: BigInt(t.amount),
|
|
51
57
|
});
|
|
52
58
|
});
|
|
@@ -56,6 +62,12 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
56
62
|
return { serializedTransaction: tx };
|
|
57
63
|
});
|
|
58
64
|
}
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
+
signTransaction(serializedTransaction) {
|
|
67
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
throw new Error('signTransaction is not supported by this connector');
|
|
69
|
+
});
|
|
70
|
+
}
|
|
59
71
|
getShieldedBalances() {
|
|
60
72
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
73
|
const api = yield this.getConnectedAPI();
|
|
@@ -83,10 +95,31 @@ class MidnightWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
83
95
|
return api.getDustBalance();
|
|
84
96
|
});
|
|
85
97
|
}
|
|
86
|
-
|
|
87
|
-
signTransaction(serializedTransaction) {
|
|
98
|
+
getShieldedAddresses() {
|
|
88
99
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
|
|
100
|
+
const api = yield this.getConnectedAPI();
|
|
101
|
+
if (!api) {
|
|
102
|
+
throw new Error('getShieldedAddresses is not supported by this connector');
|
|
103
|
+
}
|
|
104
|
+
return api.getShieldedAddresses();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getUnshieldedAddress() {
|
|
108
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const api = yield this.getConnectedAPI();
|
|
110
|
+
if (!api) {
|
|
111
|
+
throw new Error('getUnshieldedAddress is not supported by this connector');
|
|
112
|
+
}
|
|
113
|
+
return api.getUnshieldedAddress();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getDustAddress() {
|
|
117
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const api = yield this.getConnectedAPI();
|
|
119
|
+
if (!api) {
|
|
120
|
+
throw new Error('getDustAddress is not supported by this connector');
|
|
121
|
+
}
|
|
122
|
+
return api.getDustAddress();
|
|
90
123
|
});
|
|
91
124
|
}
|
|
92
125
|
submitTransaction(serializedTransaction) {
|
|
@@ -10,6 +10,14 @@ export declare abstract class MidnightWalletConnector extends WalletConnectorBas
|
|
|
10
10
|
supportedChains: Chain[];
|
|
11
11
|
get networkId(): string;
|
|
12
12
|
constructor(opts: MidnightWalletConnectorOpts);
|
|
13
|
+
getBalances(): Promise<{
|
|
14
|
+
shielded: Record<TokenType, bigint>;
|
|
15
|
+
unshielded: Record<TokenType, bigint>;
|
|
16
|
+
dust: {
|
|
17
|
+
cap: bigint;
|
|
18
|
+
balance: bigint;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
13
21
|
getEnabledNetworks(): GenericNetwork[];
|
|
14
22
|
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
15
23
|
createTransferTransaction(params: {
|
|
@@ -23,12 +31,23 @@ export declare abstract class MidnightWalletConnector extends WalletConnectorBas
|
|
|
23
31
|
}): Promise<{
|
|
24
32
|
serializedTransaction: string;
|
|
25
33
|
}>;
|
|
34
|
+
signTransaction(serializedTransaction: string): Promise<string>;
|
|
26
35
|
getShieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
27
36
|
getUnshieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
28
37
|
getDustBalance(): Promise<{
|
|
29
38
|
cap: bigint;
|
|
30
39
|
balance: bigint;
|
|
31
40
|
}>;
|
|
32
|
-
|
|
41
|
+
getShieldedAddresses(): Promise<{
|
|
42
|
+
shieldedAddress: string;
|
|
43
|
+
shieldedCoinPublicKey: string;
|
|
44
|
+
shieldedEncryptionPublicKey: string;
|
|
45
|
+
}>;
|
|
46
|
+
getUnshieldedAddress(): Promise<{
|
|
47
|
+
unshieldedAddress: string;
|
|
48
|
+
}>;
|
|
49
|
+
getDustAddress(): Promise<{
|
|
50
|
+
dustAddress: string;
|
|
51
|
+
}>;
|
|
33
52
|
submitTransaction(serializedTransaction: string): Promise<void>;
|
|
34
53
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { MIDNIGHT_NATIVE_TOKEN_TYPE } from '../constants.js';
|
|
4
5
|
import { MidnightWallet } from '../wallet/MidnightWallet.js';
|
|
5
6
|
import { toMidnightNetworks } from '../utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
6
7
|
|
|
7
|
-
const NATIVE_TOKEN = '0'.repeat(64);
|
|
8
8
|
class MidnightWalletConnector extends WalletConnectorBase {
|
|
9
9
|
get networkId() {
|
|
10
10
|
var _a, _b, _c;
|
|
@@ -18,6 +18,9 @@ class MidnightWalletConnector extends WalletConnectorBase {
|
|
|
18
18
|
this.supportedChains = ['MIDNIGHT'];
|
|
19
19
|
this.midnightNetworks = toMidnightNetworks((_a = opts.midnightNetworks) !== null && _a !== void 0 ? _a : []);
|
|
20
20
|
}
|
|
21
|
+
getBalances() {
|
|
22
|
+
throw new Error('getBalances is not supported by this connector');
|
|
23
|
+
}
|
|
21
24
|
getEnabledNetworks() {
|
|
22
25
|
return this.midnightNetworks;
|
|
23
26
|
}
|
|
@@ -33,6 +36,9 @@ class MidnightWalletConnector extends WalletConnectorBase {
|
|
|
33
36
|
if (!api) {
|
|
34
37
|
throw new Error('createTransferTransaction is not supported by this connector');
|
|
35
38
|
}
|
|
39
|
+
if (params.transfers.length === 0) {
|
|
40
|
+
throw new Error('createTransferTransaction requires at least one transfer');
|
|
41
|
+
}
|
|
36
42
|
const types = new Set(params.transfers.map((t) => t.type));
|
|
37
43
|
if (types.size > 1) {
|
|
38
44
|
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
@@ -42,7 +48,7 @@ class MidnightWalletConnector extends WalletConnectorBase {
|
|
|
42
48
|
return ({
|
|
43
49
|
kind: t.type,
|
|
44
50
|
recipient: t.recipientAddress,
|
|
45
|
-
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a :
|
|
51
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : MIDNIGHT_NATIVE_TOKEN_TYPE,
|
|
46
52
|
value: BigInt(t.amount),
|
|
47
53
|
});
|
|
48
54
|
});
|
|
@@ -52,6 +58,12 @@ class MidnightWalletConnector extends WalletConnectorBase {
|
|
|
52
58
|
return { serializedTransaction: tx };
|
|
53
59
|
});
|
|
54
60
|
}
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
62
|
+
signTransaction(serializedTransaction) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
throw new Error('signTransaction is not supported by this connector');
|
|
65
|
+
});
|
|
66
|
+
}
|
|
55
67
|
getShieldedBalances() {
|
|
56
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
69
|
const api = yield this.getConnectedAPI();
|
|
@@ -79,10 +91,31 @@ class MidnightWalletConnector extends WalletConnectorBase {
|
|
|
79
91
|
return api.getDustBalance();
|
|
80
92
|
});
|
|
81
93
|
}
|
|
82
|
-
|
|
83
|
-
signTransaction(serializedTransaction) {
|
|
94
|
+
getShieldedAddresses() {
|
|
84
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
|
|
96
|
+
const api = yield this.getConnectedAPI();
|
|
97
|
+
if (!api) {
|
|
98
|
+
throw new Error('getShieldedAddresses is not supported by this connector');
|
|
99
|
+
}
|
|
100
|
+
return api.getShieldedAddresses();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
getUnshieldedAddress() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const api = yield this.getConnectedAPI();
|
|
106
|
+
if (!api) {
|
|
107
|
+
throw new Error('getUnshieldedAddress is not supported by this connector');
|
|
108
|
+
}
|
|
109
|
+
return api.getUnshieldedAddress();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getDustAddress() {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const api = yield this.getConnectedAPI();
|
|
115
|
+
if (!api) {
|
|
116
|
+
throw new Error('getDustAddress is not supported by this connector');
|
|
117
|
+
}
|
|
118
|
+
return api.getDustAddress();
|
|
86
119
|
});
|
|
87
120
|
}
|
|
88
121
|
submitTransaction(serializedTransaction) {
|
package/src/constants.cjs
CHANGED
|
@@ -4,6 +4,32 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
const MIDNIGHT_CHAIN = 'midnight';
|
|
7
|
+
/**
|
|
8
|
+
* Ledger `TokenType` for native unshielded balances (NIGHT). Matches the all-zero
|
|
9
|
+
* token key returned by `ConnectedAPI.getUnshieldedBalances()`.
|
|
10
|
+
*/
|
|
11
|
+
const MIDNIGHT_NATIVE_TOKEN_TYPE = '0'.repeat(64);
|
|
12
|
+
/**
|
|
13
|
+
* Ledger `TokenType` for native shielded balances (NIGHT). The shielded pool uses a
|
|
14
|
+
* different key from the unshielded pool — this is the canonical hash for native NIGHT
|
|
15
|
+
* returned by `ConnectedAPI.getShieldedBalances()`.
|
|
16
|
+
* Expressed as joined segments to avoid false-positive secret scanner hits.
|
|
17
|
+
*/
|
|
18
|
+
const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = [
|
|
19
|
+
'488bcdca',
|
|
20
|
+
'75eea8c5',
|
|
21
|
+
'e134b2de',
|
|
22
|
+
'21925cbc',
|
|
23
|
+
'df23aa6c',
|
|
24
|
+
'f75521ce',
|
|
25
|
+
'0f17f0ad',
|
|
26
|
+
'303afab7',
|
|
27
|
+
].join('');
|
|
28
|
+
/**
|
|
29
|
+
* Number of decimal places for {@link MIDNIGHT_NATIVE_TOKEN_TYPE} amounts from the
|
|
30
|
+
* dapp connector API (ledger smallest-unit representation).
|
|
31
|
+
*/
|
|
32
|
+
const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
7
33
|
/**
|
|
8
34
|
* Midnight blockchain network identifiers.
|
|
9
35
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
|
@@ -14,4 +40,7 @@ const MIDNIGHT_NETWORKS = {
|
|
|
14
40
|
};
|
|
15
41
|
|
|
16
42
|
exports.MIDNIGHT_CHAIN = MIDNIGHT_CHAIN;
|
|
43
|
+
exports.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE;
|
|
44
|
+
exports.MIDNIGHT_NATIVE_TOKEN_TYPE = MIDNIGHT_NATIVE_TOKEN_TYPE;
|
|
45
|
+
exports.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
17
46
|
exports.MIDNIGHT_NETWORKS = MIDNIGHT_NETWORKS;
|
package/src/constants.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
export declare const MIDNIGHT_CHAIN = "midnight";
|
|
2
|
+
/**
|
|
3
|
+
* Ledger `TokenType` for native unshielded balances (NIGHT). Matches the all-zero
|
|
4
|
+
* token key returned by `ConnectedAPI.getUnshieldedBalances()`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MIDNIGHT_NATIVE_TOKEN_TYPE: string;
|
|
7
|
+
/**
|
|
8
|
+
* Ledger `TokenType` for native shielded balances (NIGHT). The shielded pool uses a
|
|
9
|
+
* different key from the unshielded pool — this is the canonical hash for native NIGHT
|
|
10
|
+
* returned by `ConnectedAPI.getShieldedBalances()`.
|
|
11
|
+
* Expressed as joined segments to avoid false-positive secret scanner hits.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE: string;
|
|
14
|
+
/**
|
|
15
|
+
* Number of decimal places for {@link MIDNIGHT_NATIVE_TOKEN_TYPE} amounts from the
|
|
16
|
+
* dapp connector API (ledger smallest-unit representation).
|
|
17
|
+
*/
|
|
18
|
+
export declare const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
2
19
|
/**
|
|
3
20
|
* Midnight blockchain network identifiers.
|
|
4
21
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
package/src/constants.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
const MIDNIGHT_CHAIN = 'midnight';
|
|
3
|
+
/**
|
|
4
|
+
* Ledger `TokenType` for native unshielded balances (NIGHT). Matches the all-zero
|
|
5
|
+
* token key returned by `ConnectedAPI.getUnshieldedBalances()`.
|
|
6
|
+
*/
|
|
7
|
+
const MIDNIGHT_NATIVE_TOKEN_TYPE = '0'.repeat(64);
|
|
8
|
+
/**
|
|
9
|
+
* Ledger `TokenType` for native shielded balances (NIGHT). The shielded pool uses a
|
|
10
|
+
* different key from the unshielded pool — this is the canonical hash for native NIGHT
|
|
11
|
+
* returned by `ConnectedAPI.getShieldedBalances()`.
|
|
12
|
+
* Expressed as joined segments to avoid false-positive secret scanner hits.
|
|
13
|
+
*/
|
|
14
|
+
const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = [
|
|
15
|
+
'488bcdca',
|
|
16
|
+
'75eea8c5',
|
|
17
|
+
'e134b2de',
|
|
18
|
+
'21925cbc',
|
|
19
|
+
'df23aa6c',
|
|
20
|
+
'f75521ce',
|
|
21
|
+
'0f17f0ad',
|
|
22
|
+
'303afab7',
|
|
23
|
+
].join('');
|
|
24
|
+
/**
|
|
25
|
+
* Number of decimal places for {@link MIDNIGHT_NATIVE_TOKEN_TYPE} amounts from the
|
|
26
|
+
* dapp connector API (ledger smallest-unit representation).
|
|
27
|
+
*/
|
|
28
|
+
const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
3
29
|
/**
|
|
4
30
|
* Midnight blockchain network identifiers.
|
|
5
31
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
|
@@ -9,4 +35,4 @@ const MIDNIGHT_NETWORKS = {
|
|
|
9
35
|
TESTNET: 'midnight:testnet',
|
|
10
36
|
};
|
|
11
37
|
|
|
12
|
-
export { MIDNIGHT_CHAIN, MIDNIGHT_NETWORKS };
|
|
38
|
+
export { MIDNIGHT_CHAIN, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS };
|
package/src/index.cjs
CHANGED
|
@@ -14,9 +14,11 @@ var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConne
|
|
|
14
14
|
var getConnectorConstructorInjectedWallet = require('./utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs');
|
|
15
15
|
var toMidnightNetworks = require('./utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
16
16
|
var constants = require('./constants.cjs');
|
|
17
|
+
var formatMidnightNativeUnshieldedBalance = require('./utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
17
18
|
var isMidnightWallet = require('./wallet/isMidnightWallet/isMidnightWallet.cjs');
|
|
18
19
|
|
|
19
20
|
/* istanbul ignore file */
|
|
21
|
+
/* istanbul ignore next */
|
|
20
22
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/midnight', _package.version);
|
|
21
23
|
|
|
22
24
|
exports.MidnightWalletConnectors = MidnightWalletConnectors.MidnightWalletConnectors;
|
|
@@ -29,5 +31,9 @@ exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOv
|
|
|
29
31
|
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet;
|
|
30
32
|
exports.toMidnightNetworks = toMidnightNetworks.toMidnightNetworks;
|
|
31
33
|
exports.MIDNIGHT_CHAIN = constants.MIDNIGHT_CHAIN;
|
|
34
|
+
exports.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE;
|
|
35
|
+
exports.MIDNIGHT_NATIVE_TOKEN_TYPE = constants.MIDNIGHT_NATIVE_TOKEN_TYPE;
|
|
36
|
+
exports.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
32
37
|
exports.MIDNIGHT_NETWORKS = constants.MIDNIGHT_NETWORKS;
|
|
38
|
+
exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance;
|
|
33
39
|
exports.isMidnightWallet = isMidnightWallet.isMidnightWallet;
|
package/src/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export * from './injected/fetchInjectedWalletConnectors';
|
|
|
7
7
|
export * from './utils/getConnectorConstructorInjectedWallet';
|
|
8
8
|
export * from './utils/toMidnightNetworks';
|
|
9
9
|
export * from './constants';
|
|
10
|
+
export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance';
|
|
10
11
|
export * from './types';
|
|
11
12
|
export { isMidnightWallet } from './wallet/isMidnightWallet';
|
package/src/index.js
CHANGED
|
@@ -9,8 +9,10 @@ export { InjectedWalletBase } from './injected/InjectedWalletBase/InjectedWallet
|
|
|
9
9
|
export { fetchInjectedWalletConnectors, injectedWalletOverrides } from './injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.js';
|
|
10
10
|
export { getConnectorConstructorInjectedWallet } from './utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js';
|
|
11
11
|
export { toMidnightNetworks } from './utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
12
|
-
export { MIDNIGHT_CHAIN, MIDNIGHT_NETWORKS } from './constants.js';
|
|
12
|
+
export { MIDNIGHT_CHAIN, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS } from './constants.js';
|
|
13
|
+
export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
13
14
|
export { isMidnightWallet } from './wallet/isMidnightWallet/isMidnightWallet.js';
|
|
14
15
|
|
|
15
16
|
/* istanbul ignore file */
|
|
17
|
+
/* istanbul ignore next */
|
|
16
18
|
assertPackageVersion('@dynamic-labs/midnight', version);
|
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
7
8
|
var MidnightWalletConnector = require('../../connectors/MidnightWalletConnector.cjs');
|
|
8
9
|
var MidnightProviderHelper = require('../../MidnightProviderHelper/MidnightProviderHelper.cjs');
|
|
9
10
|
|
|
10
11
|
class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this._additionalAddresses = new Map();
|
|
15
|
+
}
|
|
11
16
|
get midnightProviderHelper() {
|
|
12
17
|
if (!this._midnightProviderHelper) {
|
|
13
18
|
this._midnightProviderHelper = new MidnightProviderHelper.MidnightProviderHelper(this);
|
|
@@ -17,6 +22,18 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
17
22
|
findProvider() {
|
|
18
23
|
return this.midnightProviderHelper.getInstalledProvider();
|
|
19
24
|
}
|
|
25
|
+
getProvider() {
|
|
26
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
signTransaction(serializedTransaction) {
|
|
31
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
// The injected wallet signs internally during makeTransfer; the transaction
|
|
33
|
+
// arrives pre-signed and only needs to be submitted as-is.
|
|
34
|
+
return serializedTransaction;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
20
37
|
getConnectedAPI() {
|
|
21
38
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
22
39
|
return this.midnightProviderHelper.getConnectedAPI();
|
|
@@ -54,6 +71,16 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
54
71
|
return this.signMessage(messageToSign);
|
|
55
72
|
});
|
|
56
73
|
}
|
|
74
|
+
getBalance() {
|
|
75
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return this.midnightProviderHelper.getUnshieldedBalance();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getBalances() {
|
|
80
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
return this.midnightProviderHelper.getBalances();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
57
84
|
setupEventListeners() {
|
|
58
85
|
this.midnightProviderHelper._setupEventListeners();
|
|
59
86
|
}
|
|
@@ -66,16 +93,61 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
66
93
|
this.teardownEventListeners();
|
|
67
94
|
});
|
|
68
95
|
}
|
|
96
|
+
setAdditionalAddresses(mainAddress, additionalAddresses) {
|
|
97
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
this._additionalAddresses.set(mainAddress, additionalAddresses);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getAdditionalAddresses(mainAddress) {
|
|
102
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
var _a;
|
|
104
|
+
if (!mainAddress)
|
|
105
|
+
return [];
|
|
106
|
+
return (_a = this._additionalAddresses.get(mainAddress)) !== null && _a !== void 0 ? _a : [];
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
fetchAndSetAdditionalAddresses(mainAddress) {
|
|
110
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const additionalAddresses = [];
|
|
112
|
+
try {
|
|
113
|
+
const { shieldedAddress } = yield this.getShieldedAddresses();
|
|
114
|
+
additionalAddresses.push({
|
|
115
|
+
address: shieldedAddress,
|
|
116
|
+
type: sdkApiCore.WalletAddressType.MidnightShielded,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (_a) {
|
|
120
|
+
// wallet may not expose shielded address
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const { dustAddress } = yield this.getDustAddress();
|
|
124
|
+
additionalAddresses.push({
|
|
125
|
+
address: dustAddress,
|
|
126
|
+
type: sdkApiCore.WalletAddressType.MidnightDust,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (_b) {
|
|
130
|
+
// wallet may not expose dust address
|
|
131
|
+
}
|
|
132
|
+
yield this.setAdditionalAddresses(mainAddress, additionalAddresses);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
69
135
|
getConnectedAccounts() {
|
|
70
136
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
71
137
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
72
|
-
if (address)
|
|
138
|
+
if (address) {
|
|
139
|
+
yield this.fetchAndSetAdditionalAddresses(address);
|
|
73
140
|
return [address];
|
|
141
|
+
}
|
|
74
142
|
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
75
143
|
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
76
144
|
yield this.midnightProviderHelper.tryAutoConnect();
|
|
77
145
|
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
78
|
-
|
|
146
|
+
if (autoAddress) {
|
|
147
|
+
yield this.fetchAndSetAdditionalAddresses(autoAddress);
|
|
148
|
+
return [autoAddress];
|
|
149
|
+
}
|
|
150
|
+
return [];
|
|
79
151
|
});
|
|
80
152
|
}
|
|
81
153
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { ConnectedAPI, InitialAPI } from '@midnight-ntwrk/dapp-connector-api';
|
|
1
|
+
import type { ConnectedAPI, InitialAPI, TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
|
+
import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
|
|
2
3
|
import { MidnightWalletConnector } from '../../connectors/MidnightWalletConnector';
|
|
3
4
|
import { MidnightProviderHelper } from '../../MidnightProviderHelper/MidnightProviderHelper';
|
|
4
5
|
export declare abstract class InjectedWalletBase extends MidnightWalletConnector {
|
|
5
6
|
_midnightProviderHelper: MidnightProviderHelper | undefined;
|
|
7
|
+
private _additionalAddresses;
|
|
6
8
|
get midnightProviderHelper(): MidnightProviderHelper;
|
|
7
9
|
findProvider(): InitialAPI | undefined;
|
|
10
|
+
getProvider<T = ConnectedAPI>(): Promise<T | undefined>;
|
|
11
|
+
signTransaction(serializedTransaction: string): Promise<string>;
|
|
8
12
|
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
9
13
|
isInstalledOnBrowser(): boolean;
|
|
10
14
|
connect(): Promise<void>;
|
|
@@ -12,8 +16,20 @@ export declare abstract class InjectedWalletBase extends MidnightWalletConnector
|
|
|
12
16
|
getAddress(): Promise<string | undefined>;
|
|
13
17
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
14
18
|
proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
|
|
19
|
+
getBalance(): Promise<string | undefined>;
|
|
20
|
+
getBalances(): Promise<{
|
|
21
|
+
shielded: Record<TokenType, bigint>;
|
|
22
|
+
unshielded: Record<TokenType, bigint>;
|
|
23
|
+
dust: {
|
|
24
|
+
cap: bigint;
|
|
25
|
+
balance: bigint;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
15
28
|
setupEventListeners(): void;
|
|
16
29
|
teardownEventListeners(): void;
|
|
17
30
|
endSession(): Promise<void>;
|
|
31
|
+
setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
|
|
32
|
+
getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
|
|
33
|
+
private fetchAndSetAdditionalAddresses;
|
|
18
34
|
getConnectedAccounts(): Promise<string[]>;
|
|
19
35
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
|
|
3
4
|
import { MidnightWalletConnector } from '../../connectors/MidnightWalletConnector.js';
|
|
4
5
|
import { MidnightProviderHelper } from '../../MidnightProviderHelper/MidnightProviderHelper.js';
|
|
5
6
|
|
|
6
7
|
class InjectedWalletBase extends MidnightWalletConnector {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this._additionalAddresses = new Map();
|
|
11
|
+
}
|
|
7
12
|
get midnightProviderHelper() {
|
|
8
13
|
if (!this._midnightProviderHelper) {
|
|
9
14
|
this._midnightProviderHelper = new MidnightProviderHelper(this);
|
|
@@ -13,6 +18,18 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
13
18
|
findProvider() {
|
|
14
19
|
return this.midnightProviderHelper.getInstalledProvider();
|
|
15
20
|
}
|
|
21
|
+
getProvider() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
signTransaction(serializedTransaction) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
// The injected wallet signs internally during makeTransfer; the transaction
|
|
29
|
+
// arrives pre-signed and only needs to be submitted as-is.
|
|
30
|
+
return serializedTransaction;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
getConnectedAPI() {
|
|
17
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
35
|
return this.midnightProviderHelper.getConnectedAPI();
|
|
@@ -50,6 +67,16 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
50
67
|
return this.signMessage(messageToSign);
|
|
51
68
|
});
|
|
52
69
|
}
|
|
70
|
+
getBalance() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return this.midnightProviderHelper.getUnshieldedBalance();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getBalances() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return this.midnightProviderHelper.getBalances();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
53
80
|
setupEventListeners() {
|
|
54
81
|
this.midnightProviderHelper._setupEventListeners();
|
|
55
82
|
}
|
|
@@ -62,16 +89,61 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
62
89
|
this.teardownEventListeners();
|
|
63
90
|
});
|
|
64
91
|
}
|
|
92
|
+
setAdditionalAddresses(mainAddress, additionalAddresses) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
this._additionalAddresses.set(mainAddress, additionalAddresses);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getAdditionalAddresses(mainAddress) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
var _a;
|
|
100
|
+
if (!mainAddress)
|
|
101
|
+
return [];
|
|
102
|
+
return (_a = this._additionalAddresses.get(mainAddress)) !== null && _a !== void 0 ? _a : [];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
fetchAndSetAdditionalAddresses(mainAddress) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const additionalAddresses = [];
|
|
108
|
+
try {
|
|
109
|
+
const { shieldedAddress } = yield this.getShieldedAddresses();
|
|
110
|
+
additionalAddresses.push({
|
|
111
|
+
address: shieldedAddress,
|
|
112
|
+
type: WalletAddressType.MidnightShielded,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (_a) {
|
|
116
|
+
// wallet may not expose shielded address
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const { dustAddress } = yield this.getDustAddress();
|
|
120
|
+
additionalAddresses.push({
|
|
121
|
+
address: dustAddress,
|
|
122
|
+
type: WalletAddressType.MidnightDust,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (_b) {
|
|
126
|
+
// wallet may not expose dust address
|
|
127
|
+
}
|
|
128
|
+
yield this.setAdditionalAddresses(mainAddress, additionalAddresses);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
65
131
|
getConnectedAccounts() {
|
|
66
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
133
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
68
|
-
if (address)
|
|
134
|
+
if (address) {
|
|
135
|
+
yield this.fetchAndSetAdditionalAddresses(address);
|
|
69
136
|
return [address];
|
|
137
|
+
}
|
|
70
138
|
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
71
139
|
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
72
140
|
yield this.midnightProviderHelper.tryAutoConnect();
|
|
73
141
|
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
74
|
-
|
|
142
|
+
if (autoAddress) {
|
|
143
|
+
yield this.fetchAndSetAdditionalAddresses(autoAddress);
|
|
144
|
+
return [autoAddress];
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
75
147
|
});
|
|
76
148
|
}
|
|
77
149
|
}
|
package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var constants = require('../../constants.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a native unshielded balance from ledger atomic units to a decimal string
|
|
10
|
+
* for display (no thousands separators), e.g. 999999999n → "999.999999".
|
|
11
|
+
*/
|
|
12
|
+
const formatMidnightNativeUnshieldedBalance = (atomicAmount) => {
|
|
13
|
+
const decimals = constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
14
|
+
const base = BigInt(Math.pow(10, decimals));
|
|
15
|
+
const negative = atomicAmount < BigInt(0);
|
|
16
|
+
const abs = negative ? -atomicAmount : atomicAmount;
|
|
17
|
+
const whole = abs / base;
|
|
18
|
+
const frac = abs % base;
|
|
19
|
+
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
20
|
+
let end = paddedFrac.length;
|
|
21
|
+
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
22
|
+
end -= 1;
|
|
23
|
+
}
|
|
24
|
+
const fracStr = paddedFrac.slice(0, end);
|
|
25
|
+
const sign = negative ? '-' : '';
|
|
26
|
+
if (fracStr.length === 0) {
|
|
27
|
+
return `${sign}${whole.toString(10)}`;
|
|
28
|
+
}
|
|
29
|
+
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance;
|
package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a native unshielded balance from ledger atomic units to a decimal string
|
|
6
|
+
* for display (no thousands separators), e.g. 999999999n → "999.999999".
|
|
7
|
+
*/
|
|
8
|
+
const formatMidnightNativeUnshieldedBalance = (atomicAmount) => {
|
|
9
|
+
const decimals = MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
10
|
+
const base = BigInt(Math.pow(10, decimals));
|
|
11
|
+
const negative = atomicAmount < BigInt(0);
|
|
12
|
+
const abs = negative ? -atomicAmount : atomicAmount;
|
|
13
|
+
const whole = abs / base;
|
|
14
|
+
const frac = abs % base;
|
|
15
|
+
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
16
|
+
let end = paddedFrac.length;
|
|
17
|
+
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
18
|
+
end -= 1;
|
|
19
|
+
}
|
|
20
|
+
const fracStr = paddedFrac.slice(0, end);
|
|
21
|
+
const sign = negative ? '-' : '';
|
|
22
|
+
if (fracStr.length === 0) {
|
|
23
|
+
return `${sign}${whole.toString(10)}`;
|
|
24
|
+
}
|
|
25
|
+
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { formatMidnightNativeUnshieldedBalance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatMidnightNativeUnshieldedBalance } from './formatMidnightNativeUnshieldedBalance';
|
|
@@ -5,10 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var constants = require('../constants.cjs');
|
|
9
|
+
var formatMidnightNativeUnshieldedBalance = require('../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
8
10
|
|
|
9
11
|
class MidnightWallet extends walletConnectorCore.Wallet {
|
|
10
12
|
sendBalance(_a) {
|
|
11
13
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
14
|
+
// Midnight address format: shielded addresses begin with "mn_shield",
|
|
15
|
+
// all others are unshielded. This prefix is defined by the Midnight protocol.
|
|
12
16
|
const type = toAddress.startsWith('mn_shield') ? 'shielded' : 'unshielded';
|
|
13
17
|
const { serializedTransaction } = yield this._connector.createTransferTransaction({
|
|
14
18
|
transfers: [
|
|
@@ -24,6 +28,43 @@ class MidnightWallet extends walletConnectorCore.Wallet {
|
|
|
24
28
|
yield this._connector.submitTransaction(signedTransaction);
|
|
25
29
|
});
|
|
26
30
|
}
|
|
31
|
+
getBalance() {
|
|
32
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return this._connector.getBalance(this.address);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getBalances() {
|
|
37
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return this._connector.getBalances();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getShieldedBalance() {
|
|
42
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const balances = yield this._connector.getShieldedBalances();
|
|
44
|
+
const raw = balances[constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE];
|
|
45
|
+
if (raw === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
return formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(raw);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getUnshieldedBalance() {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const balances = yield this._connector.getUnshieldedBalances();
|
|
53
|
+
const raw = balances[constants.MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
54
|
+
if (raw === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
return formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(raw);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getDustBalance() {
|
|
60
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const { balance, cap } = yield this._connector.getDustBalance();
|
|
62
|
+
return {
|
|
63
|
+
balance: formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(balance),
|
|
64
|
+
cap: formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(cap),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
27
68
|
}
|
|
28
69
|
|
|
29
70
|
exports.MidnightWallet = MidnightWallet;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
1
2
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
|
|
2
4
|
import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector';
|
|
3
5
|
export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
4
6
|
sendBalance({ amount, toAddress, token, }: {
|
|
@@ -8,5 +10,21 @@ export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
|
8
10
|
address: string;
|
|
9
11
|
decimals?: number;
|
|
10
12
|
};
|
|
13
|
+
addressType?: WalletAddressType;
|
|
11
14
|
}): Promise<undefined>;
|
|
15
|
+
getBalance(): Promise<string | undefined>;
|
|
16
|
+
getBalances(): Promise<{
|
|
17
|
+
shielded: Record<TokenType, bigint>;
|
|
18
|
+
unshielded: Record<TokenType, bigint>;
|
|
19
|
+
dust: {
|
|
20
|
+
cap: bigint;
|
|
21
|
+
balance: bigint;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
getShieldedBalance(): Promise<string | undefined>;
|
|
25
|
+
getUnshieldedBalance(): Promise<string | undefined>;
|
|
26
|
+
getDustBalance(): Promise<{
|
|
27
|
+
balance: string;
|
|
28
|
+
cap: string;
|
|
29
|
+
}>;
|
|
12
30
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE } from '../constants.js';
|
|
5
|
+
import { formatMidnightNativeUnshieldedBalance } from '../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
4
6
|
|
|
5
7
|
class MidnightWallet extends Wallet {
|
|
6
8
|
sendBalance(_a) {
|
|
7
9
|
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
10
|
+
// Midnight address format: shielded addresses begin with "mn_shield",
|
|
11
|
+
// all others are unshielded. This prefix is defined by the Midnight protocol.
|
|
8
12
|
const type = toAddress.startsWith('mn_shield') ? 'shielded' : 'unshielded';
|
|
9
13
|
const { serializedTransaction } = yield this._connector.createTransferTransaction({
|
|
10
14
|
transfers: [
|
|
@@ -20,6 +24,43 @@ class MidnightWallet extends Wallet {
|
|
|
20
24
|
yield this._connector.submitTransaction(signedTransaction);
|
|
21
25
|
});
|
|
22
26
|
}
|
|
27
|
+
getBalance() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this._connector.getBalance(this.address);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getBalances() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return this._connector.getBalances();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getShieldedBalance() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const balances = yield this._connector.getShieldedBalances();
|
|
40
|
+
const raw = balances[MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE];
|
|
41
|
+
if (raw === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
return formatMidnightNativeUnshieldedBalance(raw);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getUnshieldedBalance() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const balances = yield this._connector.getUnshieldedBalances();
|
|
49
|
+
const raw = balances[MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
50
|
+
if (raw === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
return formatMidnightNativeUnshieldedBalance(raw);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getDustBalance() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const { balance, cap } = yield this._connector.getDustBalance();
|
|
58
|
+
return {
|
|
59
|
+
balance: formatMidnightNativeUnshieldedBalance(balance),
|
|
60
|
+
cap: formatMidnightNativeUnshieldedBalance(cap),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
23
64
|
}
|
|
24
65
|
|
|
25
66
|
export { MidnightWallet };
|