@dynamic-labs/midnight 4.79.1 → 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 +16 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -5
- package/src/MidnightProviderHelper/MidnightProviderHelper.cjs +143 -20
- package/src/MidnightProviderHelper/MidnightProviderHelper.d.ts +18 -2
- package/src/MidnightProviderHelper/MidnightProviderHelper.js +144 -21
- package/src/MidnightWalletConnectors.cjs +13 -0
- package/src/MidnightWalletConnectors.d.ts +3 -0
- package/src/MidnightWalletConnectors.js +9 -0
- package/src/connectors/MidnightWalletConnector.cjs +117 -1
- package/src/connectors/MidnightWalletConnector.d.ts +46 -8
- package/src/connectors/MidnightWalletConnector.js +117 -1
- package/src/constants.cjs +29 -0
- package/src/constants.d.ts +17 -0
- package/src/constants.js +27 -1
- package/src/index.cjs +13 -2
- package/src/index.d.ts +4 -1
- package/src/index.js +7 -2
- package/src/injected/InjectedWalletBase/InjectedWalletBase.cjs +89 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.d.ts +19 -1
- package/src/injected/InjectedWalletBase/InjectedWalletBase.js +89 -1
- package/src/types.d.ts +10 -0
- 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/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 +55 -3
- package/src/wallet/MidnightWallet.d.ts +20 -2
- package/src/wallet/MidnightWallet.js +55 -3
- 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
|
@@ -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,23 @@ 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
|
+
}
|
|
33
|
+
getConnectedAPI() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
16
38
|
isInstalledOnBrowser() {
|
|
17
39
|
return this.midnightProviderHelper.isInstalledHelper();
|
|
18
40
|
}
|
|
@@ -21,6 +43,11 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
21
43
|
yield this.midnightProviderHelper.getConnectedAPI();
|
|
22
44
|
});
|
|
23
45
|
}
|
|
46
|
+
getNetwork() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this.midnightProviderHelper.getNetwork();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
24
51
|
getAddress() {
|
|
25
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
53
|
const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
|
|
@@ -40,6 +67,16 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
40
67
|
return this.signMessage(messageToSign);
|
|
41
68
|
});
|
|
42
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
|
+
}
|
|
43
80
|
setupEventListeners() {
|
|
44
81
|
this.midnightProviderHelper._setupEventListeners();
|
|
45
82
|
}
|
|
@@ -52,10 +89,61 @@ class InjectedWalletBase extends MidnightWalletConnector {
|
|
|
52
89
|
this.teardownEventListeners();
|
|
53
90
|
});
|
|
54
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
|
+
}
|
|
55
131
|
getConnectedAccounts() {
|
|
56
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
133
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
58
|
-
|
|
134
|
+
if (address) {
|
|
135
|
+
yield this.fetchAndSetAdditionalAddresses(address);
|
|
136
|
+
return [address];
|
|
137
|
+
}
|
|
138
|
+
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
139
|
+
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
140
|
+
yield this.midnightProviderHelper.tryAutoConnect();
|
|
141
|
+
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
142
|
+
if (autoAddress) {
|
|
143
|
+
yield this.fetchAndSetAdditionalAddresses(autoAddress);
|
|
144
|
+
return [autoAddress];
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
59
147
|
});
|
|
60
148
|
}
|
|
61
149
|
}
|
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
|
+
};
|
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';
|
|
@@ -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;
|
|
@@ -5,12 +5,64 @@ 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
|
-
|
|
11
|
-
|
|
12
|
+
sendBalance(_a) {
|
|
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.
|
|
16
|
+
const type = toAddress.startsWith('mn_shield') ? 'shielded' : 'unshielded';
|
|
17
|
+
const { serializedTransaction } = yield this._connector.createTransferTransaction({
|
|
18
|
+
transfers: [
|
|
19
|
+
{
|
|
20
|
+
amount,
|
|
21
|
+
recipientAddress: toAddress,
|
|
22
|
+
tokenType: token === null || token === void 0 ? void 0 : token.address,
|
|
23
|
+
type,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
const signedTransaction = yield this._connector.signTransaction(serializedTransaction);
|
|
28
|
+
yield this._connector.submitTransaction(signedTransaction);
|
|
29
|
+
});
|
|
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() {
|
|
12
60
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
|
|
61
|
+
const { balance, cap } = yield this._connector.getDustBalance();
|
|
62
|
+
return {
|
|
63
|
+
balance: formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(balance),
|
|
64
|
+
cap: formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(cap),
|
|
65
|
+
};
|
|
14
66
|
});
|
|
15
67
|
}
|
|
16
68
|
}
|
|
@@ -1,12 +1,30 @@
|
|
|
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
|
-
sendBalance(
|
|
6
|
+
sendBalance({ amount, toAddress, token, }: {
|
|
5
7
|
amount: string;
|
|
6
8
|
toAddress: string;
|
|
7
9
|
token?: {
|
|
8
10
|
address: string;
|
|
9
11
|
decimals?: number;
|
|
10
12
|
};
|
|
11
|
-
|
|
13
|
+
addressType?: WalletAddressType;
|
|
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,12 +1,64 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
+
sendBalance(_a) {
|
|
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.
|
|
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);
|
|
25
|
+
});
|
|
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() {
|
|
8
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9
|
-
|
|
57
|
+
const { balance, cap } = yield this._connector.getDustBalance();
|
|
58
|
+
return {
|
|
59
|
+
balance: formatMidnightNativeUnshieldedBalance(balance),
|
|
60
|
+
cap: formatMidnightNativeUnshieldedBalance(cap),
|
|
61
|
+
};
|
|
10
62
|
});
|
|
11
63
|
}
|
|
12
64
|
}
|
|
@@ -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';
|