@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
|
@@ -3,17 +3,133 @@
|
|
|
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');
|
|
8
|
+
var constants = require('../constants.cjs');
|
|
7
9
|
var MidnightWallet = require('../wallet/MidnightWallet.cjs');
|
|
10
|
+
var toMidnightNetworks = require('../utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
8
11
|
|
|
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
|
+
getBalances() {
|
|
26
|
+
throw new Error('getBalances is not supported by this connector');
|
|
27
|
+
}
|
|
28
|
+
getEnabledNetworks() {
|
|
29
|
+
return this.midnightNetworks;
|
|
30
|
+
}
|
|
31
|
+
getConnectedAPI() {
|
|
32
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return undefined;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
createTransferTransaction(params) {
|
|
37
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var _a;
|
|
39
|
+
const api = yield this.getConnectedAPI();
|
|
40
|
+
if (!api) {
|
|
41
|
+
throw new Error('createTransferTransaction is not supported by this connector');
|
|
42
|
+
}
|
|
43
|
+
if (params.transfers.length === 0) {
|
|
44
|
+
throw new Error('createTransferTransaction requires at least one transfer');
|
|
45
|
+
}
|
|
46
|
+
const types = new Set(params.transfers.map((t) => t.type));
|
|
47
|
+
if (types.size > 1) {
|
|
48
|
+
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
49
|
+
}
|
|
50
|
+
const desiredOutputs = params.transfers.map((t) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return ({
|
|
53
|
+
kind: t.type,
|
|
54
|
+
recipient: t.recipientAddress,
|
|
55
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : constants.MIDNIGHT_NATIVE_TOKEN_TYPE,
|
|
56
|
+
value: BigInt(t.amount),
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
const { tx } = yield api.makeTransfer(desiredOutputs, {
|
|
60
|
+
payFees: (_a = params.payFees) !== null && _a !== void 0 ? _a : false,
|
|
61
|
+
});
|
|
62
|
+
return { serializedTransaction: tx };
|
|
63
|
+
});
|
|
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
|
+
}
|
|
71
|
+
getShieldedBalances() {
|
|
72
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const api = yield this.getConnectedAPI();
|
|
74
|
+
if (!api) {
|
|
75
|
+
throw new Error('getShieldedBalances is not supported by this connector');
|
|
76
|
+
}
|
|
77
|
+
return api.getShieldedBalances();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getUnshieldedBalances() {
|
|
81
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const api = yield this.getConnectedAPI();
|
|
83
|
+
if (!api) {
|
|
84
|
+
throw new Error('getUnshieldedBalances is not supported by this connector');
|
|
85
|
+
}
|
|
86
|
+
return api.getUnshieldedBalances();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
getDustBalance() {
|
|
90
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const api = yield this.getConnectedAPI();
|
|
92
|
+
if (!api) {
|
|
93
|
+
throw new Error('getDustBalance is not supported by this connector');
|
|
94
|
+
}
|
|
95
|
+
return api.getDustBalance();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getShieldedAddresses() {
|
|
99
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
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();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
submitTransaction(serializedTransaction) {
|
|
126
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const api = yield this.getConnectedAPI();
|
|
128
|
+
if (!api) {
|
|
129
|
+
throw new Error('submitTransaction is not supported by this connector');
|
|
130
|
+
}
|
|
131
|
+
yield api.submitTransaction(serializedTransaction);
|
|
132
|
+
});
|
|
17
133
|
}
|
|
18
134
|
}
|
|
19
135
|
|
|
@@ -1,15 +1,53 @@
|
|
|
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
|
+
getBalances(): Promise<{
|
|
14
|
+
shielded: Record<TokenType, bigint>;
|
|
15
|
+
unshielded: Record<TokenType, bigint>;
|
|
16
|
+
dust: {
|
|
17
|
+
cap: bigint;
|
|
18
|
+
balance: bigint;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
22
|
+
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
23
|
+
createTransferTransaction(params: {
|
|
24
|
+
transfers: Array<{
|
|
25
|
+
type: 'unshielded' | 'shielded';
|
|
26
|
+
recipientAddress: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
tokenType?: string;
|
|
29
|
+
}>;
|
|
30
|
+
payFees?: boolean;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
serializedTransaction: string;
|
|
33
|
+
}>;
|
|
34
|
+
signTransaction(serializedTransaction: string): Promise<string>;
|
|
35
|
+
getShieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
36
|
+
getUnshieldedBalances(): Promise<Record<TokenType, bigint>>;
|
|
37
|
+
getDustBalance(): Promise<{
|
|
38
|
+
cap: bigint;
|
|
39
|
+
balance: bigint;
|
|
40
|
+
}>;
|
|
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
|
+
}>;
|
|
52
|
+
submitTransaction(serializedTransaction: string): Promise<void>;
|
|
15
53
|
}
|
|
@@ -1,15 +1,131 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
3
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { MIDNIGHT_NATIVE_TOKEN_TYPE } from '../constants.js';
|
|
3
5
|
import { MidnightWallet } from '../wallet/MidnightWallet.js';
|
|
6
|
+
import { toMidnightNetworks } from '../utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
4
7
|
|
|
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
|
+
getBalances() {
|
|
22
|
+
throw new Error('getBalances is not supported by this connector');
|
|
23
|
+
}
|
|
24
|
+
getEnabledNetworks() {
|
|
25
|
+
return this.midnightNetworks;
|
|
26
|
+
}
|
|
27
|
+
getConnectedAPI() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return undefined;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
createTransferTransaction(params) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
35
|
+
const api = yield this.getConnectedAPI();
|
|
36
|
+
if (!api) {
|
|
37
|
+
throw new Error('createTransferTransaction is not supported by this connector');
|
|
38
|
+
}
|
|
39
|
+
if (params.transfers.length === 0) {
|
|
40
|
+
throw new Error('createTransferTransaction requires at least one transfer');
|
|
41
|
+
}
|
|
42
|
+
const types = new Set(params.transfers.map((t) => t.type));
|
|
43
|
+
if (types.size > 1) {
|
|
44
|
+
throw new Error('Cross-pool transfers are not supported: all transfers must be the same type (shielded or unshielded)');
|
|
45
|
+
}
|
|
46
|
+
const desiredOutputs = params.transfers.map((t) => {
|
|
47
|
+
var _a;
|
|
48
|
+
return ({
|
|
49
|
+
kind: t.type,
|
|
50
|
+
recipient: t.recipientAddress,
|
|
51
|
+
type: (_a = t.tokenType) !== null && _a !== void 0 ? _a : MIDNIGHT_NATIVE_TOKEN_TYPE,
|
|
52
|
+
value: BigInt(t.amount),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const { tx } = yield api.makeTransfer(desiredOutputs, {
|
|
56
|
+
payFees: (_a = params.payFees) !== null && _a !== void 0 ? _a : false,
|
|
57
|
+
});
|
|
58
|
+
return { serializedTransaction: tx };
|
|
59
|
+
});
|
|
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
|
+
}
|
|
67
|
+
getShieldedBalances() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const api = yield this.getConnectedAPI();
|
|
70
|
+
if (!api) {
|
|
71
|
+
throw new Error('getShieldedBalances is not supported by this connector');
|
|
72
|
+
}
|
|
73
|
+
return api.getShieldedBalances();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getUnshieldedBalances() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const api = yield this.getConnectedAPI();
|
|
79
|
+
if (!api) {
|
|
80
|
+
throw new Error('getUnshieldedBalances is not supported by this connector');
|
|
81
|
+
}
|
|
82
|
+
return api.getUnshieldedBalances();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
getDustBalance() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const api = yield this.getConnectedAPI();
|
|
88
|
+
if (!api) {
|
|
89
|
+
throw new Error('getDustBalance is not supported by this connector');
|
|
90
|
+
}
|
|
91
|
+
return api.getDustBalance();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getShieldedAddresses() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
submitTransaction(serializedTransaction) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const api = yield this.getConnectedAPI();
|
|
124
|
+
if (!api) {
|
|
125
|
+
throw new Error('submitTransaction is not supported by this connector');
|
|
126
|
+
}
|
|
127
|
+
yield api.submitTransaction(serializedTransaction);
|
|
128
|
+
});
|
|
13
129
|
}
|
|
14
130
|
}
|
|
15
131
|
|
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
|
@@ -5,24 +5,35 @@ 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 formatMidnightNativeUnshieldedBalance = require('./utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
18
|
+
var isMidnightWallet = require('./wallet/isMidnightWallet/isMidnightWallet.cjs');
|
|
16
19
|
|
|
20
|
+
/* istanbul ignore file */
|
|
21
|
+
/* istanbul ignore next */
|
|
17
22
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/midnight', _package.version);
|
|
18
23
|
|
|
24
|
+
exports.MidnightWalletConnectors = MidnightWalletConnectors.MidnightWalletConnectors;
|
|
19
25
|
exports.MidnightWalletConnector = MidnightWalletConnector.MidnightWalletConnector;
|
|
20
26
|
exports.MidnightWallet = MidnightWallet.MidnightWallet;
|
|
21
27
|
exports.MidnightProviderHelper = MidnightProviderHelper.MidnightProviderHelper;
|
|
22
28
|
exports.InjectedWalletBase = InjectedWalletBase.InjectedWalletBase;
|
|
23
|
-
exports.Midnight1am = Midnight1am.Midnight1am;
|
|
24
29
|
exports.fetchInjectedWalletConnectors = fetchInjectedWalletConnectors.fetchInjectedWalletConnectors;
|
|
25
30
|
exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOverrides;
|
|
26
31
|
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet;
|
|
32
|
+
exports.toMidnightNetworks = toMidnightNetworks.toMidnightNetworks;
|
|
27
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;
|
|
28
37
|
exports.MIDNIGHT_NETWORKS = constants.MIDNIGHT_NETWORKS;
|
|
38
|
+
exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance;
|
|
39
|
+
exports.isMidnightWallet = isMidnightWallet.isMidnightWallet;
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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';
|
|
10
|
+
export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance';
|
|
9
11
|
export * from './types';
|
|
12
|
+
export { isMidnightWallet } from './wallet/isMidnightWallet';
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
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 {
|
|
11
|
+
export { toMidnightNetworks } from './utils/toMidnightNetworks/toMidnightNetworks.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';
|
|
14
|
+
export { isMidnightWallet } from './wallet/isMidnightWallet/isMidnightWallet.js';
|
|
12
15
|
|
|
16
|
+
/* istanbul ignore file */
|
|
17
|
+
/* istanbul ignore next */
|
|
13
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,23 @@ 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
|
+
}
|
|
37
|
+
getConnectedAPI() {
|
|
38
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return this.midnightProviderHelper.getConnectedAPI();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
20
42
|
isInstalledOnBrowser() {
|
|
21
43
|
return this.midnightProviderHelper.isInstalledHelper();
|
|
22
44
|
}
|
|
@@ -25,6 +47,11 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
25
47
|
yield this.midnightProviderHelper.getConnectedAPI();
|
|
26
48
|
});
|
|
27
49
|
}
|
|
50
|
+
getNetwork() {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return this.midnightProviderHelper.getNetwork();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
28
55
|
getAddress() {
|
|
29
56
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
57
|
const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
|
|
@@ -44,6 +71,16 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
44
71
|
return this.signMessage(messageToSign);
|
|
45
72
|
});
|
|
46
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
|
+
}
|
|
47
84
|
setupEventListeners() {
|
|
48
85
|
this.midnightProviderHelper._setupEventListeners();
|
|
49
86
|
}
|
|
@@ -56,10 +93,61 @@ class InjectedWalletBase extends MidnightWalletConnector.MidnightWalletConnector
|
|
|
56
93
|
this.teardownEventListeners();
|
|
57
94
|
});
|
|
58
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
|
+
}
|
|
59
135
|
getConnectedAccounts() {
|
|
60
136
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
137
|
const address = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
62
|
-
|
|
138
|
+
if (address) {
|
|
139
|
+
yield this.fetchAndSetAdditionalAddresses(address);
|
|
140
|
+
return [address];
|
|
141
|
+
}
|
|
142
|
+
// Attempt a silent reconnect when a previous session exists. If the wallet
|
|
143
|
+
// remembers this origin, connect() resolves without showing an approval prompt.
|
|
144
|
+
yield this.midnightProviderHelper.tryAutoConnect();
|
|
145
|
+
const autoAddress = yield this.midnightProviderHelper.getAddressIfConnected();
|
|
146
|
+
if (autoAddress) {
|
|
147
|
+
yield this.fetchAndSetAdditionalAddresses(autoAddress);
|
|
148
|
+
return [autoAddress];
|
|
149
|
+
}
|
|
150
|
+
return [];
|
|
63
151
|
});
|
|
64
152
|
}
|
|
65
153
|
}
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import type { 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>;
|
|
12
|
+
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
8
13
|
isInstalledOnBrowser(): boolean;
|
|
9
14
|
connect(): Promise<void>;
|
|
15
|
+
getNetwork(): Promise<string | undefined>;
|
|
10
16
|
getAddress(): Promise<string | undefined>;
|
|
11
17
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
12
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
|
+
}>;
|
|
13
28
|
setupEventListeners(): void;
|
|
14
29
|
teardownEventListeners(): void;
|
|
15
30
|
endSession(): Promise<void>;
|
|
31
|
+
setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
|
|
32
|
+
getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
|
|
33
|
+
private fetchAndSetAdditionalAddresses;
|
|
16
34
|
getConnectedAccounts(): Promise<string[]>;
|
|
17
35
|
}
|