@dynamic-labs-wallet/midnight 1.0.68 → 1.0.69
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/index.cjs.js +150 -70
- package/index.esm.js +151 -71
- package/package.json +2 -2
- package/src/client/client.d.ts +23 -5
- package/src/client/client.d.ts.map +1 -1
- package/src/client/constants.d.ts +26 -0
- package/src/client/constants.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -43,6 +43,32 @@ var MIDNIGHT_NETWORK_IDS = {
|
|
|
43
43
|
preprod: 0,
|
|
44
44
|
undeployed: 0
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the caller-supplied network identifier (numeric 0/1, network name,
|
|
48
|
+
* or "midnight:<network>" chainId) to the facade network tag. Defaults to
|
|
49
|
+
* 'preview' when absent — the legacy single-network behavior, so requests from
|
|
50
|
+
* hosts that predate per-network support are unchanged.
|
|
51
|
+
*/ var resolveMidnightNetworkTag = function(networkId) {
|
|
52
|
+
if (networkId === undefined || networkId === null) return 'preview';
|
|
53
|
+
if (typeof networkId === 'number') return networkId === 1 ? 'mainnet' : 'preview';
|
|
54
|
+
var name = networkId.includes(':') ? networkId.split(':')[1] : networkId;
|
|
55
|
+
return name === 'mainnet' ? 'mainnet' : 'preview';
|
|
56
|
+
};
|
|
57
|
+
var MIDNIGHT_PROOF_SERVER_URL = 'https://proof-server.us-east-1.dynamic-preprod.xyz';
|
|
58
|
+
var MIDNIGHT_INFRA = {
|
|
59
|
+
mainnet: {
|
|
60
|
+
relayUrl: 'wss://rpc.mainnet.midnight.network',
|
|
61
|
+
provingServerUrl: MIDNIGHT_PROOF_SERVER_URL,
|
|
62
|
+
indexerHttpUrl: 'https://indexer.mainnet.midnight.network/api/v4/graphql',
|
|
63
|
+
indexerWsUrl: 'wss://indexer.mainnet.midnight.network/api/v4/graphql/ws'
|
|
64
|
+
},
|
|
65
|
+
preview: {
|
|
66
|
+
relayUrl: 'wss://rpc.preview.midnight.network',
|
|
67
|
+
provingServerUrl: MIDNIGHT_PROOF_SERVER_URL,
|
|
68
|
+
indexerHttpUrl: 'https://indexer.preview.midnight.network/api/v4/graphql',
|
|
69
|
+
indexerWsUrl: 'wss://indexer.preview.midnight.network/api/v4/graphql/ws'
|
|
70
|
+
}
|
|
71
|
+
};
|
|
46
72
|
// Error messages
|
|
47
73
|
var ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
48
74
|
var ERROR_NETWORK_ID_REQUIRED = 'Network ID is required for Midnight transactions';
|
|
@@ -920,7 +946,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
920
946
|
}
|
|
921
947
|
return [
|
|
922
948
|
4,
|
|
923
|
-
putWalletState(cached.accountAddress, {
|
|
949
|
+
putWalletState(DynamicMidnightWalletClient.walletStateKey(cached.accountAddress, cached.network), {
|
|
924
950
|
shielded: shielded,
|
|
925
951
|
dust: dust
|
|
926
952
|
})
|
|
@@ -956,7 +982,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
956
982
|
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId, businessAccountId = param.businessAccountId;
|
|
957
983
|
var _this = this;
|
|
958
984
|
return _async_to_generator(function() {
|
|
959
|
-
var ceremonyCeremonyCompleteResolver, serverAccountAddress, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, roleKeys, shieldedSecretKeys, shieldedAddr,
|
|
985
|
+
var ceremonyCeremonyCompleteResolver, serverAccountAddress, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, roleKeys, shieldedSecretKeys, shieldedAddr, dustSecretKey, toHex, correctionNetworks, correctAddresses, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, tag, encodeId, dustAddr, wallet, addrError, error;
|
|
960
986
|
return _ts_generator(this, function(_state) {
|
|
961
987
|
switch(_state.label){
|
|
962
988
|
case 0:
|
|
@@ -1053,13 +1079,10 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1053
1079
|
roleKeys = _state.sent();
|
|
1054
1080
|
shieldedSecretKeys = ledger__namespace.ZswapSecretKeys.fromSeed(new Uint8Array(Buffer.from(roleKeys.shielded, 'hex')));
|
|
1055
1081
|
shieldedAddr = new walletSdkAddressFormat.ShieldedAddress(new walletSdkAddressFormat.ShieldedCoinPublicKey(Buffer.from(shieldedSecretKeys.coinPublicKey, 'hex')), new walletSdkAddressFormat.ShieldedEncryptionPublicKey(Buffer.from(shieldedSecretKeys.encryptionPublicKey, 'hex')));
|
|
1056
|
-
shieldedBech32m = walletSdkAddressFormat.MidnightBech32m.encode('preview', shieldedAddr).toString();
|
|
1057
1082
|
try {
|
|
1058
1083
|
dustSecretKey = ledger__namespace.DustSecretKey.fromSeed(new Uint8Array(Buffer.from(roleKeys.dust, 'hex')));
|
|
1059
|
-
dustAddr = new walletSdkAddressFormat.DustAddress(dustSecretKey.publicKey);
|
|
1060
|
-
dustBech32m = walletSdkAddressFormat.MidnightBech32m.encode('preview', dustAddr).toString();
|
|
1061
1084
|
} catch (dustErr) {
|
|
1062
|
-
_this.logger.warn('[Midnight] Dust
|
|
1085
|
+
_this.logger.warn('[Midnight] Dust key derivation failed (skipping dust addresses):', dustErr);
|
|
1063
1086
|
}
|
|
1064
1087
|
toHex = function(val) {
|
|
1065
1088
|
if (typeof val === 'string') return val;
|
|
@@ -1067,24 +1090,58 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1067
1090
|
if ((typeof val === "undefined" ? "undefined" : _type_of(val)) === 'bigint') return val.toString(16);
|
|
1068
1091
|
return String(val);
|
|
1069
1092
|
};
|
|
1070
|
-
|
|
1093
|
+
// One key, one encoding per network — only the bech32m HRP differs.
|
|
1094
|
+
// Preview first: Midnight's legacy default, so legacy first-match
|
|
1095
|
+
// lookups keep resolving the preview encoding. The mainnet network id
|
|
1096
|
+
// is the library's `mainnet` symbol (bare HRP, no network segment).
|
|
1097
|
+
correctionNetworks = [
|
|
1071
1098
|
{
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
publicKey: toHex(publicKeyHex)
|
|
1099
|
+
tag: 'preview',
|
|
1100
|
+
encodeId: 'preview'
|
|
1075
1101
|
},
|
|
1076
1102
|
{
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
publicKey: toHex(shieldedSecretKeys.coinPublicKey)
|
|
1103
|
+
tag: 'mainnet',
|
|
1104
|
+
encodeId: walletSdkAddressFormat.mainnet
|
|
1080
1105
|
}
|
|
1081
1106
|
];
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1107
|
+
correctAddresses = [];
|
|
1108
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1109
|
+
try {
|
|
1110
|
+
for(_iterator = correctionNetworks[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1111
|
+
_step_value = _step.value, tag = _step_value.tag, encodeId = _step_value.encodeId;
|
|
1112
|
+
correctAddresses.push({
|
|
1113
|
+
address: walletSdkAddressFormat.MidnightBech32m.encode(encodeId, shieldedAddr).toString(),
|
|
1114
|
+
type: 'midnight_shielded',
|
|
1115
|
+
publicKey: toHex(shieldedSecretKeys.coinPublicKey),
|
|
1116
|
+
network: tag
|
|
1117
|
+
});
|
|
1118
|
+
if (dustSecretKey) {
|
|
1119
|
+
try {
|
|
1120
|
+
dustAddr = new walletSdkAddressFormat.DustAddress(dustSecretKey.publicKey);
|
|
1121
|
+
correctAddresses.push({
|
|
1122
|
+
address: walletSdkAddressFormat.MidnightBech32m.encode(encodeId, dustAddr).toString(),
|
|
1123
|
+
type: 'midnight_dust',
|
|
1124
|
+
publicKey: toHex(dustSecretKey.publicKey),
|
|
1125
|
+
network: tag
|
|
1126
|
+
});
|
|
1127
|
+
} catch (dustErr) {
|
|
1128
|
+
_this.logger.warn('[Midnight] Dust address encoding failed (skipping):', dustErr);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
} catch (err) {
|
|
1133
|
+
_didIteratorError = true;
|
|
1134
|
+
_iteratorError = err;
|
|
1135
|
+
} finally{
|
|
1136
|
+
try {
|
|
1137
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1138
|
+
_iterator.return();
|
|
1139
|
+
}
|
|
1140
|
+
} finally{
|
|
1141
|
+
if (_didIteratorError) {
|
|
1142
|
+
throw _iteratorError;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1088
1145
|
}
|
|
1089
1146
|
_this.logger.info('[Midnight] Updating additional addresses with correct derivation');
|
|
1090
1147
|
return [
|
|
@@ -1267,7 +1324,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1267
1324
|
signedSessionId: signedSessionId,
|
|
1268
1325
|
mfaToken: mfaToken,
|
|
1269
1326
|
elevatedAccessToken: elevatedAccessToken
|
|
1270
|
-
})
|
|
1327
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
1271
1328
|
];
|
|
1272
1329
|
case 3:
|
|
1273
1330
|
wallet = _state.sent().wallet;
|
|
@@ -1703,28 +1760,29 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1703
1760
|
{
|
|
1704
1761
|
key: "initMidnightWallet",
|
|
1705
1762
|
value: function initMidnightWallet(label, mpcParams) {
|
|
1706
|
-
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full';
|
|
1763
|
+
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full', network = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 'preview';
|
|
1707
1764
|
var _this = this;
|
|
1708
1765
|
return _async_to_generator(function() {
|
|
1709
|
-
var accountAddress, inFlight, initPromise;
|
|
1766
|
+
var accountAddress, initKey, inFlight, initPromise;
|
|
1710
1767
|
return _ts_generator(this, function(_state) {
|
|
1711
1768
|
switch(_state.label){
|
|
1712
1769
|
case 0:
|
|
1713
1770
|
accountAddress = mpcParams.accountAddress;
|
|
1714
|
-
|
|
1715
|
-
//
|
|
1716
|
-
//
|
|
1717
|
-
//
|
|
1718
|
-
|
|
1771
|
+
initKey = "".concat(accountAddress, "::").concat(network);
|
|
1772
|
+
// If another init for this same (account, network) is in flight, return its
|
|
1773
|
+
// promise instead of kicking off a second, redundant WalletFacade.init. The
|
|
1774
|
+
// first caller's `mode` wins; that's fine — the wallet is created/cached once
|
|
1775
|
+
// and keeps syncing dust in the background regardless of who waited for what.
|
|
1776
|
+
inFlight = _this.pendingInits.get(initKey);
|
|
1719
1777
|
if (inFlight) {
|
|
1720
|
-
_this.logger.info("[Midnight] ".concat(label, ": joining in-flight init for ").concat(
|
|
1778
|
+
_this.logger.info("[Midnight] ".concat(label, ": joining in-flight init for ").concat(initKey));
|
|
1721
1779
|
return [
|
|
1722
1780
|
2,
|
|
1723
1781
|
inFlight
|
|
1724
1782
|
];
|
|
1725
1783
|
}
|
|
1726
|
-
initPromise = _this.runMidnightWalletInit(label, mpcParams, mode);
|
|
1727
|
-
_this.pendingInits.set(
|
|
1784
|
+
initPromise = _this.runMidnightWalletInit(label, mpcParams, mode, network);
|
|
1785
|
+
_this.pendingInits.set(initKey, initPromise);
|
|
1728
1786
|
_state.label = 1;
|
|
1729
1787
|
case 1:
|
|
1730
1788
|
_state.trys.push([
|
|
@@ -1743,7 +1801,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1743
1801
|
_state.sent()
|
|
1744
1802
|
];
|
|
1745
1803
|
case 3:
|
|
1746
|
-
_this.pendingInits.delete(
|
|
1804
|
+
_this.pendingInits.delete(initKey);
|
|
1747
1805
|
return [
|
|
1748
1806
|
7
|
|
1749
1807
|
];
|
|
@@ -1759,10 +1817,10 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1759
1817
|
{
|
|
1760
1818
|
key: "runMidnightWalletInit",
|
|
1761
1819
|
value: function runMidnightWalletInit(label, mpcParams) {
|
|
1762
|
-
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full';
|
|
1820
|
+
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full', network = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 'preview';
|
|
1763
1821
|
var _this = this;
|
|
1764
1822
|
return _async_to_generator(function() {
|
|
1765
|
-
var _this_cachedWallet, roleKeys, accountAddress, state, _this_cachedWallet_diagnosticSub, shieldedSecretKeys, dustSecretKey, unshieldedKeystore, config, savedState, _savedState_shielded, _savedState_dust, _savedState_shielded_length, _savedState_dust_length, wallet, syncStart, lastLogTime, SIDE_NAMES, lastApplied, sideDoneAtMs, readProgress, fmtSide, state1,
|
|
1823
|
+
var _this_cachedWallet, _this_cachedWallet1, roleKeys, accountAddress, state, _this_cachedWallet_diagnosticSub, shieldedSecretKeys, dustSecretKey, unshieldedKeystore, infra, config, savedState, _savedState_shielded, _savedState_dust, _savedState_shielded_length, _savedState_dust_length, wallet, syncStart, lastLogTime, SIDE_NAMES, lastApplied, sideDoneAtMs, readProgress, fmtSide, state1, err1, lastPendingCount, lastPendingSig, lastDustLogTime, dustDoneLogged, diagnosticSub;
|
|
1766
1824
|
return _ts_generator(this, function(_state) {
|
|
1767
1825
|
switch(_state.label){
|
|
1768
1826
|
case 0:
|
|
@@ -1773,7 +1831,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1773
1831
|
case 1:
|
|
1774
1832
|
roleKeys = _state.sent();
|
|
1775
1833
|
accountAddress = mpcParams.accountAddress;
|
|
1776
|
-
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress)) return [
|
|
1834
|
+
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress && ((_this_cachedWallet1 = _this.cachedWallet) === null || _this_cachedWallet1 === void 0 ? void 0 : _this_cachedWallet1.network) === network)) return [
|
|
1777
1835
|
3,
|
|
1778
1836
|
3
|
|
1779
1837
|
];
|
|
@@ -1854,17 +1912,18 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1854
1912
|
case 8:
|
|
1855
1913
|
shieldedSecretKeys = ledger__namespace.ZswapSecretKeys.fromSeed(new Uint8Array(Buffer.from(roleKeys.shielded, 'hex')));
|
|
1856
1914
|
dustSecretKey = ledger__namespace.DustSecretKey.fromSeed(new Uint8Array(Buffer.from(roleKeys.dust, 'hex')));
|
|
1857
|
-
unshieldedKeystore = walletSdkUnshieldedWallet.createKeystore(new Uint8Array(Buffer.from(roleKeys.unshielded, 'hex')),
|
|
1915
|
+
unshieldedKeystore = walletSdkUnshieldedWallet.createKeystore(new Uint8Array(Buffer.from(roleKeys.unshielded, 'hex')), network);
|
|
1916
|
+
infra = MIDNIGHT_INFRA[network];
|
|
1858
1917
|
config = {
|
|
1859
|
-
networkId:
|
|
1918
|
+
networkId: network,
|
|
1860
1919
|
costParameters: {
|
|
1861
1920
|
feeBlocksMargin: 5
|
|
1862
1921
|
},
|
|
1863
|
-
relayURL: new URL(
|
|
1864
|
-
provingServerUrl: new URL(
|
|
1922
|
+
relayURL: new URL(infra.relayUrl),
|
|
1923
|
+
provingServerUrl: new URL(infra.provingServerUrl),
|
|
1865
1924
|
indexerClientConnection: {
|
|
1866
|
-
indexerHttpUrl:
|
|
1867
|
-
indexerWsUrl:
|
|
1925
|
+
indexerHttpUrl: infra.indexerHttpUrl,
|
|
1926
|
+
indexerWsUrl: infra.indexerWsUrl
|
|
1868
1927
|
},
|
|
1869
1928
|
// v4 sync batching. `size` = updates fetched per indexer round-trip.
|
|
1870
1929
|
// Measured: 2000 vs 10000 gave the same ~750 entries/sec (≈130s dust cold
|
|
@@ -1877,7 +1936,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1877
1936
|
};
|
|
1878
1937
|
return [
|
|
1879
1938
|
4,
|
|
1880
|
-
getWalletState(accountAddress)
|
|
1939
|
+
getWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, network))
|
|
1881
1940
|
];
|
|
1882
1941
|
case 9:
|
|
1883
1942
|
savedState = _state.sent();
|
|
@@ -2052,7 +2111,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2052
2111
|
19
|
|
2053
2112
|
];
|
|
2054
2113
|
case 14:
|
|
2055
|
-
|
|
2114
|
+
err1 = _state.sent();
|
|
2056
2115
|
_state.label = 15;
|
|
2057
2116
|
case 15:
|
|
2058
2117
|
_state.trys.push([
|
|
@@ -2078,7 +2137,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2078
2137
|
18
|
|
2079
2138
|
];
|
|
2080
2139
|
case 18:
|
|
2081
|
-
throw
|
|
2140
|
+
throw err1;
|
|
2082
2141
|
case 19:
|
|
2083
2142
|
// Diagnostic: track pending-tx transitions so we can observe TTL
|
|
2084
2143
|
// auto-revert (entry flips from result=undefined → result.status='FAILURE'
|
|
@@ -2183,6 +2242,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2183
2242
|
ledger: ledger__namespace,
|
|
2184
2243
|
roleKeys: roleKeys,
|
|
2185
2244
|
accountAddress: accountAddress,
|
|
2245
|
+
network: network,
|
|
2186
2246
|
shieldedSecretKeys: shieldedSecretKeys,
|
|
2187
2247
|
dustSecretKey: dustSecretKey,
|
|
2188
2248
|
diagnosticSub: diagnosticSub
|
|
@@ -2248,7 +2308,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2248
2308
|
{
|
|
2249
2309
|
key: "getPrivateBalance",
|
|
2250
2310
|
value: function getPrivateBalance(param) {
|
|
2251
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2311
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2252
2312
|
var _this = this;
|
|
2253
2313
|
return _async_to_generator(function() {
|
|
2254
2314
|
var _state_unshielded, _state_shielded, _state_dust_balance, _state_dust, _state_dust1, _ref, state, addr, unshieldedByToken, _state_unshielded_balances, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, tokenType, value, shieldedByToken, _state_shielded_balances, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value1, tokenType1, value1, now, _state_dust_balance1, dustBalance, _state_dust_totalCoins, dustCap, result;
|
|
@@ -2266,7 +2326,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2266
2326
|
}, // Resolve once shielded + unshielded are ready; let dust finish in the
|
|
2267
2327
|
// background so the public/shielded balance shows without the ~130s
|
|
2268
2328
|
// dust cold-sync.
|
|
2269
|
-
'shielded-unshielded')
|
|
2329
|
+
'shielded-unshielded', resolveMidnightNetworkTag(networkId))
|
|
2270
2330
|
];
|
|
2271
2331
|
case 1:
|
|
2272
2332
|
_ref = _state.sent(), state = _ref.state, addr = _ref.accountAddress;
|
|
@@ -2345,7 +2405,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2345
2405
|
{
|
|
2346
2406
|
key: "registerDust",
|
|
2347
2407
|
value: function registerDust(param) {
|
|
2348
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2408
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2349
2409
|
var _this = this;
|
|
2350
2410
|
return _async_to_generator(function() {
|
|
2351
2411
|
var _state_dust_balance, _state_dust, _state_unshielded, _state_dust_balance1, _state_dust1, _ref, wallet, state, ledger, roleKeys, _state_dust_balance2, existingDust, _state_unshielded_availableCoins, allUtxos, nightUtxos, _state_dust_balance3, _state_dust2, _state_dust_balance4, dustBalance, verifyingKey, recipe, finalized, submitId, submitIdStr, _state_dust_balance5;
|
|
@@ -2360,7 +2420,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2360
2420
|
signedSessionId: signedSessionId,
|
|
2361
2421
|
mfaToken: mfaToken,
|
|
2362
2422
|
elevatedAccessToken: elevatedAccessToken
|
|
2363
|
-
})
|
|
2423
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
2364
2424
|
];
|
|
2365
2425
|
case 1:
|
|
2366
2426
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, ledger = _ref.ledger, roleKeys = _ref.roleKeys;
|
|
@@ -2460,13 +2520,14 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2460
2520
|
* No MPC, no proof server, no broadcast — pair with signTransaction and
|
|
2461
2521
|
* submitTransaction.
|
|
2462
2522
|
*/ function createTransferTransaction(param) {
|
|
2463
|
-
var accountAddress = param.accountAddress, transfers = param.transfers, ttlMinutes = param.ttlMinutes, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2523
|
+
var accountAddress = param.accountAddress, transfers = param.transfers, ttlMinutes = param.ttlMinutes, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2464
2524
|
var _this = this;
|
|
2465
2525
|
return _async_to_generator(function() {
|
|
2466
|
-
var _state_dust_balance, _state_dust, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, _state_dust_balance1, dustBalance, nativeToken, requiredByKey, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, t, _t_tokenType, token, key, existing, _existing_required, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, side, token1, required, _state_unshielded, _state_shielded, balances, _balances_token, have, sdkTransfers, ttlMs, recipe;
|
|
2526
|
+
var _state_dust_balance, _state_dust, network, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, _state_dust_balance1, dustBalance, nativeToken, requiredByKey, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, t, _t_tokenType, token, key, existing, _existing_required, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, side, token1, required, _state_unshielded, _state_shielded, balances, _balances_token, have, sdkTransfers, ttlMs, recipe;
|
|
2467
2527
|
return _ts_generator(this, function(_state) {
|
|
2468
2528
|
switch(_state.label){
|
|
2469
2529
|
case 0:
|
|
2530
|
+
network = resolveMidnightNetworkTag(networkId);
|
|
2470
2531
|
if (!transfers || transfers.length === 0) {
|
|
2471
2532
|
throw new Error('At least one transfer is required');
|
|
2472
2533
|
}
|
|
@@ -2478,7 +2539,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2478
2539
|
signedSessionId: signedSessionId,
|
|
2479
2540
|
mfaToken: mfaToken,
|
|
2480
2541
|
elevatedAccessToken: elevatedAccessToken
|
|
2481
|
-
})
|
|
2542
|
+
}, 'full', network)
|
|
2482
2543
|
];
|
|
2483
2544
|
case 1:
|
|
2484
2545
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, shieldedSecretKeys = _ref.shieldedSecretKeys, dustSecretKey = _ref.dustSecretKey;
|
|
@@ -2558,7 +2619,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2558
2619
|
var receiverAddress;
|
|
2559
2620
|
try {
|
|
2560
2621
|
var parsed = walletSdkAddressFormat.MidnightBech32m.parse(t.recipientAddress);
|
|
2561
|
-
receiverAddress = t.type === 'unshielded' ? parsed.decode(walletSdkAddressFormat.UnshieldedAddress,
|
|
2622
|
+
receiverAddress = t.type === 'unshielded' ? parsed.decode(walletSdkAddressFormat.UnshieldedAddress, network) : parsed.decode(walletSdkAddressFormat.ShieldedAddress, network);
|
|
2562
2623
|
} catch (err) {
|
|
2563
2624
|
throw new Error("Invalid ".concat(t.type, " recipient address ").concat(t.recipientAddress, ": ").concat(err.message));
|
|
2564
2625
|
}
|
|
@@ -2613,7 +2674,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2613
2674
|
* server; reuses the cached wallet's node connection. Optionally blocks
|
|
2614
2675
|
* until the unshielded balance for tokenType stabilizes.
|
|
2615
2676
|
*/ function submitTransaction(param) {
|
|
2616
|
-
var accountAddress = param.accountAddress, transaction = param.transaction, _param_waitForBalance = param.waitForBalance, waitForBalance = _param_waitForBalance === void 0 ? false : _param_waitForBalance, tokenType = param.tokenType, balanceBefore = param.balanceBefore, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2677
|
+
var accountAddress = param.accountAddress, transaction = param.transaction, _param_waitForBalance = param.waitForBalance, waitForBalance = _param_waitForBalance === void 0 ? false : _param_waitForBalance, tokenType = param.tokenType, balanceBefore = param.balanceBefore, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2617
2678
|
var _this = this;
|
|
2618
2679
|
return _async_to_generator(function() {
|
|
2619
2680
|
var _updatedState_unshielded_balances, _updatedState_unshielded, wallet, txBytes, finalized, txIdentifier, txHash, canonicalHash, balanceBeforeBig, updatedState, _updatedState_unshielded_balances_tokenType, balanceAfter;
|
|
@@ -2628,7 +2689,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2628
2689
|
signedSessionId: signedSessionId,
|
|
2629
2690
|
mfaToken: mfaToken,
|
|
2630
2691
|
elevatedAccessToken: elevatedAccessToken
|
|
2631
|
-
})
|
|
2692
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
2632
2693
|
];
|
|
2633
2694
|
case 1:
|
|
2634
2695
|
wallet = _state.sent().wallet;
|
|
@@ -2780,9 +2841,9 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2780
2841
|
case 1:
|
|
2781
2842
|
_state.trys.push([
|
|
2782
2843
|
1,
|
|
2783
|
-
|
|
2844
|
+
9,
|
|
2784
2845
|
,
|
|
2785
|
-
|
|
2846
|
+
10
|
|
2786
2847
|
]);
|
|
2787
2848
|
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress)) return [
|
|
2788
2849
|
3,
|
|
@@ -2821,20 +2882,28 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2821
2882
|
_this.cachedWallet = null;
|
|
2822
2883
|
_state.label = 6;
|
|
2823
2884
|
case 6:
|
|
2885
|
+
// Nuclear reset is network-agnostic: clear both networks' checkpoints so
|
|
2886
|
+
// no stale snapshot survives on either facade.
|
|
2824
2887
|
return [
|
|
2825
2888
|
4,
|
|
2826
|
-
deleteWalletState(accountAddress)
|
|
2889
|
+
deleteWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, 'preview'))
|
|
2827
2890
|
];
|
|
2828
2891
|
case 7:
|
|
2829
2892
|
_state.sent();
|
|
2830
2893
|
return [
|
|
2831
|
-
|
|
2832
|
-
|
|
2894
|
+
4,
|
|
2895
|
+
deleteWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, 'mainnet'))
|
|
2833
2896
|
];
|
|
2834
2897
|
case 8:
|
|
2898
|
+
_state.sent();
|
|
2899
|
+
return [
|
|
2900
|
+
3,
|
|
2901
|
+
10
|
|
2902
|
+
];
|
|
2903
|
+
case 9:
|
|
2835
2904
|
err = _state.sent();
|
|
2836
2905
|
throw new Error("resetCache failed: ".concat(err.message));
|
|
2837
|
-
case
|
|
2906
|
+
case 10:
|
|
2838
2907
|
_this.logger.info('[Midnight] revertTransaction[resetCache]: cache cleared');
|
|
2839
2908
|
return [
|
|
2840
2909
|
2,
|
|
@@ -2867,7 +2936,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2867
2936
|
signedSessionId: params.signedSessionId,
|
|
2868
2937
|
mfaToken: params.mfaToken,
|
|
2869
2938
|
elevatedAccessToken: params.elevatedAccessToken
|
|
2870
|
-
})
|
|
2939
|
+
}, 'full', resolveMidnightNetworkTag(params.networkId))
|
|
2871
2940
|
];
|
|
2872
2941
|
case 1:
|
|
2873
2942
|
wallet = _state.sent().wallet;
|
|
@@ -2912,7 +2981,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2912
2981
|
signedSessionId: params.signedSessionId,
|
|
2913
2982
|
mfaToken: params.mfaToken,
|
|
2914
2983
|
elevatedAccessToken: params.elevatedAccessToken
|
|
2915
|
-
})
|
|
2984
|
+
}, 'full', resolveMidnightNetworkTag(params.networkId))
|
|
2916
2985
|
];
|
|
2917
2986
|
case 1:
|
|
2918
2987
|
wallet = _state.sent().wallet;
|
|
@@ -3219,13 +3288,14 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3219
3288
|
* Returns a Midnight.js-compatible WalletProvider for use with
|
|
3220
3289
|
* midnight-js-contracts. Signing goes through MPC — no private key exposed.
|
|
3221
3290
|
*/ function getWalletProvider(param) {
|
|
3222
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
3291
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
3223
3292
|
var _this = this;
|
|
3224
3293
|
return _async_to_generator(function() {
|
|
3225
|
-
var _ref, wallet, state, shieldedSecretKeys, dustSecretKey, walletProvider;
|
|
3294
|
+
var network, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, walletProvider;
|
|
3226
3295
|
return _ts_generator(this, function(_state) {
|
|
3227
3296
|
switch(_state.label){
|
|
3228
3297
|
case 0:
|
|
3298
|
+
network = resolveMidnightNetworkTag(networkId);
|
|
3229
3299
|
return [
|
|
3230
3300
|
4,
|
|
3231
3301
|
_this.initMidnightWallet('walletProvider', {
|
|
@@ -3234,7 +3304,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3234
3304
|
signedSessionId: signedSessionId,
|
|
3235
3305
|
mfaToken: mfaToken,
|
|
3236
3306
|
elevatedAccessToken: elevatedAccessToken
|
|
3237
|
-
})
|
|
3307
|
+
}, 'full', network)
|
|
3238
3308
|
];
|
|
3239
3309
|
case 1:
|
|
3240
3310
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, shieldedSecretKeys = _ref.shieldedSecretKeys, dustSecretKey = _ref.dustSecretKey;
|
|
@@ -3263,8 +3333,8 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3263
3333
|
];
|
|
3264
3334
|
case 1:
|
|
3265
3335
|
recipe = _state.sent();
|
|
3266
|
-
// The proven base tx uses the 'proof' marker.
|
|
3267
|
-
// the
|
|
3336
|
+
// The proven base tx uses the 'proof' marker. The numeric networkId
|
|
3337
|
+
// must match the facade network this provider was configured for.
|
|
3268
3338
|
baseTxB64 = Buffer.from(recipe.baseTransaction.serialize()).toString('base64');
|
|
3269
3339
|
return [
|
|
3270
3340
|
4,
|
|
@@ -3275,7 +3345,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3275
3345
|
mfaToken: mfaToken,
|
|
3276
3346
|
elevatedAccessToken: elevatedAccessToken,
|
|
3277
3347
|
fullTxBase64: baseTxB64,
|
|
3278
|
-
networkId:
|
|
3348
|
+
networkId: MIDNIGHT_NETWORK_IDS[network],
|
|
3279
3349
|
proofMarker: 'proof'
|
|
3280
3350
|
})
|
|
3281
3351
|
];
|
|
@@ -3295,7 +3365,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3295
3365
|
mfaToken: mfaToken,
|
|
3296
3366
|
elevatedAccessToken: elevatedAccessToken,
|
|
3297
3367
|
fullTxBase64: balancingTxB64,
|
|
3298
|
-
networkId:
|
|
3368
|
+
networkId: MIDNIGHT_NETWORK_IDS[network],
|
|
3299
3369
|
proofMarker: 'pre-proof'
|
|
3300
3370
|
})
|
|
3301
3371
|
];
|
|
@@ -3337,13 +3407,23 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3337
3407
|
}
|
|
3338
3408
|
], [
|
|
3339
3409
|
{
|
|
3340
|
-
key: "
|
|
3410
|
+
key: "walletStateKey",
|
|
3341
3411
|
value: /**
|
|
3342
3412
|
* Coerce the value returned by `wallet.submitTransaction(...)` to a string.
|
|
3343
3413
|
* Midnight's facade returns either a string txId, or a TransactionIdentifier
|
|
3344
3414
|
* object with a `.toHex()` method. We normalize so callers always see a
|
|
3345
3415
|
* string, and fall back to `String(...)` if neither shape matches.
|
|
3346
|
-
*/
|
|
3416
|
+
*/ /**
|
|
3417
|
+
* IndexedDB checkpoint key. Sync state is per (account, network) — restoring
|
|
3418
|
+
* a preview snapshot into a mainnet facade would corrupt sync. Preview keeps
|
|
3419
|
+
* the bare-address key so pre-existing checkpoints stay valid.
|
|
3420
|
+
*/ function walletStateKey(accountAddress, network) {
|
|
3421
|
+
return network === 'mainnet' ? "".concat(accountAddress, "::mainnet") : accountAddress;
|
|
3422
|
+
}
|
|
3423
|
+
},
|
|
3424
|
+
{
|
|
3425
|
+
key: "toTxHashString",
|
|
3426
|
+
value: function toTxHashString(txIdentifier) {
|
|
3347
3427
|
if (typeof txIdentifier === 'string') return txIdentifier;
|
|
3348
3428
|
var maybeHex = txIdentifier === null || txIdentifier === void 0 ? void 0 : txIdentifier.toHex;
|
|
3349
3429
|
if (typeof maybeHex === 'function') return txIdentifier.toHex();
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicWalletClient, ERROR_PASSWORD_MISMATCH, getMPCChainConfig, getMPCSigner, WalletOperation } from '@dynamic-labs-wallet/browser';
|
|
2
2
|
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
3
|
-
import { ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey, MidnightBech32m, DustAddress, UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
3
|
+
import { ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey, MidnightBech32m, DustAddress, mainnet, UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
4
4
|
import { DustWallet } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
|
|
5
5
|
import { WalletFacade } from '@midnight-ntwrk/wallet-sdk-facade';
|
|
6
6
|
import { ShieldedWallet } from '@midnight-ntwrk/wallet-sdk-shielded';
|
|
@@ -22,6 +22,32 @@ var MIDNIGHT_NETWORK_IDS = {
|
|
|
22
22
|
preprod: 0,
|
|
23
23
|
undeployed: 0
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the caller-supplied network identifier (numeric 0/1, network name,
|
|
27
|
+
* or "midnight:<network>" chainId) to the facade network tag. Defaults to
|
|
28
|
+
* 'preview' when absent — the legacy single-network behavior, so requests from
|
|
29
|
+
* hosts that predate per-network support are unchanged.
|
|
30
|
+
*/ var resolveMidnightNetworkTag = function(networkId) {
|
|
31
|
+
if (networkId === undefined || networkId === null) return 'preview';
|
|
32
|
+
if (typeof networkId === 'number') return networkId === 1 ? 'mainnet' : 'preview';
|
|
33
|
+
var name = networkId.includes(':') ? networkId.split(':')[1] : networkId;
|
|
34
|
+
return name === 'mainnet' ? 'mainnet' : 'preview';
|
|
35
|
+
};
|
|
36
|
+
var MIDNIGHT_PROOF_SERVER_URL = 'https://proof-server.us-east-1.dynamic-preprod.xyz';
|
|
37
|
+
var MIDNIGHT_INFRA = {
|
|
38
|
+
mainnet: {
|
|
39
|
+
relayUrl: 'wss://rpc.mainnet.midnight.network',
|
|
40
|
+
provingServerUrl: MIDNIGHT_PROOF_SERVER_URL,
|
|
41
|
+
indexerHttpUrl: 'https://indexer.mainnet.midnight.network/api/v4/graphql',
|
|
42
|
+
indexerWsUrl: 'wss://indexer.mainnet.midnight.network/api/v4/graphql/ws'
|
|
43
|
+
},
|
|
44
|
+
preview: {
|
|
45
|
+
relayUrl: 'wss://rpc.preview.midnight.network',
|
|
46
|
+
provingServerUrl: MIDNIGHT_PROOF_SERVER_URL,
|
|
47
|
+
indexerHttpUrl: 'https://indexer.preview.midnight.network/api/v4/graphql',
|
|
48
|
+
indexerWsUrl: 'wss://indexer.preview.midnight.network/api/v4/graphql/ws'
|
|
49
|
+
}
|
|
50
|
+
};
|
|
25
51
|
// Error messages
|
|
26
52
|
var ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
27
53
|
var ERROR_NETWORK_ID_REQUIRED = 'Network ID is required for Midnight transactions';
|
|
@@ -899,7 +925,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
899
925
|
}
|
|
900
926
|
return [
|
|
901
927
|
4,
|
|
902
|
-
putWalletState(cached.accountAddress, {
|
|
928
|
+
putWalletState(DynamicMidnightWalletClient.walletStateKey(cached.accountAddress, cached.network), {
|
|
903
929
|
shielded: shielded,
|
|
904
930
|
dust: dust
|
|
905
931
|
})
|
|
@@ -935,7 +961,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
935
961
|
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId, businessAccountId = param.businessAccountId;
|
|
936
962
|
var _this = this;
|
|
937
963
|
return _async_to_generator(function() {
|
|
938
|
-
var ceremonyCeremonyCompleteResolver, serverAccountAddress, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, roleKeys, shieldedSecretKeys, shieldedAddr,
|
|
964
|
+
var ceremonyCeremonyCompleteResolver, serverAccountAddress, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, roleKeys, shieldedSecretKeys, shieldedAddr, dustSecretKey, toHex, correctionNetworks, correctAddresses, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, tag, encodeId, dustAddr, wallet, addrError, error;
|
|
939
965
|
return _ts_generator(this, function(_state) {
|
|
940
966
|
switch(_state.label){
|
|
941
967
|
case 0:
|
|
@@ -1032,13 +1058,10 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1032
1058
|
roleKeys = _state.sent();
|
|
1033
1059
|
shieldedSecretKeys = ledger.ZswapSecretKeys.fromSeed(new Uint8Array(Buffer.from(roleKeys.shielded, 'hex')));
|
|
1034
1060
|
shieldedAddr = new ShieldedAddress(new ShieldedCoinPublicKey(Buffer.from(shieldedSecretKeys.coinPublicKey, 'hex')), new ShieldedEncryptionPublicKey(Buffer.from(shieldedSecretKeys.encryptionPublicKey, 'hex')));
|
|
1035
|
-
shieldedBech32m = MidnightBech32m.encode('preview', shieldedAddr).toString();
|
|
1036
1061
|
try {
|
|
1037
1062
|
dustSecretKey = ledger.DustSecretKey.fromSeed(new Uint8Array(Buffer.from(roleKeys.dust, 'hex')));
|
|
1038
|
-
dustAddr = new DustAddress(dustSecretKey.publicKey);
|
|
1039
|
-
dustBech32m = MidnightBech32m.encode('preview', dustAddr).toString();
|
|
1040
1063
|
} catch (dustErr) {
|
|
1041
|
-
_this.logger.warn('[Midnight] Dust
|
|
1064
|
+
_this.logger.warn('[Midnight] Dust key derivation failed (skipping dust addresses):', dustErr);
|
|
1042
1065
|
}
|
|
1043
1066
|
toHex = function(val) {
|
|
1044
1067
|
if (typeof val === 'string') return val;
|
|
@@ -1046,24 +1069,58 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1046
1069
|
if ((typeof val === "undefined" ? "undefined" : _type_of(val)) === 'bigint') return val.toString(16);
|
|
1047
1070
|
return String(val);
|
|
1048
1071
|
};
|
|
1049
|
-
|
|
1072
|
+
// One key, one encoding per network — only the bech32m HRP differs.
|
|
1073
|
+
// Preview first: Midnight's legacy default, so legacy first-match
|
|
1074
|
+
// lookups keep resolving the preview encoding. The mainnet network id
|
|
1075
|
+
// is the library's `mainnet` symbol (bare HRP, no network segment).
|
|
1076
|
+
correctionNetworks = [
|
|
1050
1077
|
{
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
publicKey: toHex(publicKeyHex)
|
|
1078
|
+
tag: 'preview',
|
|
1079
|
+
encodeId: 'preview'
|
|
1054
1080
|
},
|
|
1055
1081
|
{
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
publicKey: toHex(shieldedSecretKeys.coinPublicKey)
|
|
1082
|
+
tag: 'mainnet',
|
|
1083
|
+
encodeId: mainnet
|
|
1059
1084
|
}
|
|
1060
1085
|
];
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1086
|
+
correctAddresses = [];
|
|
1087
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1088
|
+
try {
|
|
1089
|
+
for(_iterator = correctionNetworks[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1090
|
+
_step_value = _step.value, tag = _step_value.tag, encodeId = _step_value.encodeId;
|
|
1091
|
+
correctAddresses.push({
|
|
1092
|
+
address: MidnightBech32m.encode(encodeId, shieldedAddr).toString(),
|
|
1093
|
+
type: 'midnight_shielded',
|
|
1094
|
+
publicKey: toHex(shieldedSecretKeys.coinPublicKey),
|
|
1095
|
+
network: tag
|
|
1096
|
+
});
|
|
1097
|
+
if (dustSecretKey) {
|
|
1098
|
+
try {
|
|
1099
|
+
dustAddr = new DustAddress(dustSecretKey.publicKey);
|
|
1100
|
+
correctAddresses.push({
|
|
1101
|
+
address: MidnightBech32m.encode(encodeId, dustAddr).toString(),
|
|
1102
|
+
type: 'midnight_dust',
|
|
1103
|
+
publicKey: toHex(dustSecretKey.publicKey),
|
|
1104
|
+
network: tag
|
|
1105
|
+
});
|
|
1106
|
+
} catch (dustErr) {
|
|
1107
|
+
_this.logger.warn('[Midnight] Dust address encoding failed (skipping):', dustErr);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
} catch (err) {
|
|
1112
|
+
_didIteratorError = true;
|
|
1113
|
+
_iteratorError = err;
|
|
1114
|
+
} finally{
|
|
1115
|
+
try {
|
|
1116
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1117
|
+
_iterator.return();
|
|
1118
|
+
}
|
|
1119
|
+
} finally{
|
|
1120
|
+
if (_didIteratorError) {
|
|
1121
|
+
throw _iteratorError;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1067
1124
|
}
|
|
1068
1125
|
_this.logger.info('[Midnight] Updating additional addresses with correct derivation');
|
|
1069
1126
|
return [
|
|
@@ -1246,7 +1303,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1246
1303
|
signedSessionId: signedSessionId,
|
|
1247
1304
|
mfaToken: mfaToken,
|
|
1248
1305
|
elevatedAccessToken: elevatedAccessToken
|
|
1249
|
-
})
|
|
1306
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
1250
1307
|
];
|
|
1251
1308
|
case 3:
|
|
1252
1309
|
wallet = _state.sent().wallet;
|
|
@@ -1682,28 +1739,29 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1682
1739
|
{
|
|
1683
1740
|
key: "initMidnightWallet",
|
|
1684
1741
|
value: function initMidnightWallet(label, mpcParams) {
|
|
1685
|
-
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full';
|
|
1742
|
+
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full', network = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 'preview';
|
|
1686
1743
|
var _this = this;
|
|
1687
1744
|
return _async_to_generator(function() {
|
|
1688
|
-
var accountAddress, inFlight, initPromise;
|
|
1745
|
+
var accountAddress, initKey, inFlight, initPromise;
|
|
1689
1746
|
return _ts_generator(this, function(_state) {
|
|
1690
1747
|
switch(_state.label){
|
|
1691
1748
|
case 0:
|
|
1692
1749
|
accountAddress = mpcParams.accountAddress;
|
|
1693
|
-
|
|
1694
|
-
//
|
|
1695
|
-
//
|
|
1696
|
-
//
|
|
1697
|
-
|
|
1750
|
+
initKey = "".concat(accountAddress, "::").concat(network);
|
|
1751
|
+
// If another init for this same (account, network) is in flight, return its
|
|
1752
|
+
// promise instead of kicking off a second, redundant WalletFacade.init. The
|
|
1753
|
+
// first caller's `mode` wins; that's fine — the wallet is created/cached once
|
|
1754
|
+
// and keeps syncing dust in the background regardless of who waited for what.
|
|
1755
|
+
inFlight = _this.pendingInits.get(initKey);
|
|
1698
1756
|
if (inFlight) {
|
|
1699
|
-
_this.logger.info("[Midnight] ".concat(label, ": joining in-flight init for ").concat(
|
|
1757
|
+
_this.logger.info("[Midnight] ".concat(label, ": joining in-flight init for ").concat(initKey));
|
|
1700
1758
|
return [
|
|
1701
1759
|
2,
|
|
1702
1760
|
inFlight
|
|
1703
1761
|
];
|
|
1704
1762
|
}
|
|
1705
|
-
initPromise = _this.runMidnightWalletInit(label, mpcParams, mode);
|
|
1706
|
-
_this.pendingInits.set(
|
|
1763
|
+
initPromise = _this.runMidnightWalletInit(label, mpcParams, mode, network);
|
|
1764
|
+
_this.pendingInits.set(initKey, initPromise);
|
|
1707
1765
|
_state.label = 1;
|
|
1708
1766
|
case 1:
|
|
1709
1767
|
_state.trys.push([
|
|
@@ -1722,7 +1780,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1722
1780
|
_state.sent()
|
|
1723
1781
|
];
|
|
1724
1782
|
case 3:
|
|
1725
|
-
_this.pendingInits.delete(
|
|
1783
|
+
_this.pendingInits.delete(initKey);
|
|
1726
1784
|
return [
|
|
1727
1785
|
7
|
|
1728
1786
|
];
|
|
@@ -1738,10 +1796,10 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1738
1796
|
{
|
|
1739
1797
|
key: "runMidnightWalletInit",
|
|
1740
1798
|
value: function runMidnightWalletInit(label, mpcParams) {
|
|
1741
|
-
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full';
|
|
1799
|
+
var mode = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'full', network = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 'preview';
|
|
1742
1800
|
var _this = this;
|
|
1743
1801
|
return _async_to_generator(function() {
|
|
1744
|
-
var _this_cachedWallet, roleKeys, accountAddress, state, _this_cachedWallet_diagnosticSub, shieldedSecretKeys, dustSecretKey, unshieldedKeystore, config, savedState, _savedState_shielded, _savedState_dust, _savedState_shielded_length, _savedState_dust_length, wallet, syncStart, lastLogTime, SIDE_NAMES, lastApplied, sideDoneAtMs, readProgress, fmtSide, state1,
|
|
1802
|
+
var _this_cachedWallet, _this_cachedWallet1, roleKeys, accountAddress, state, _this_cachedWallet_diagnosticSub, shieldedSecretKeys, dustSecretKey, unshieldedKeystore, infra, config, savedState, _savedState_shielded, _savedState_dust, _savedState_shielded_length, _savedState_dust_length, wallet, syncStart, lastLogTime, SIDE_NAMES, lastApplied, sideDoneAtMs, readProgress, fmtSide, state1, err1, lastPendingCount, lastPendingSig, lastDustLogTime, dustDoneLogged, diagnosticSub;
|
|
1745
1803
|
return _ts_generator(this, function(_state) {
|
|
1746
1804
|
switch(_state.label){
|
|
1747
1805
|
case 0:
|
|
@@ -1752,7 +1810,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1752
1810
|
case 1:
|
|
1753
1811
|
roleKeys = _state.sent();
|
|
1754
1812
|
accountAddress = mpcParams.accountAddress;
|
|
1755
|
-
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress)) return [
|
|
1813
|
+
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress && ((_this_cachedWallet1 = _this.cachedWallet) === null || _this_cachedWallet1 === void 0 ? void 0 : _this_cachedWallet1.network) === network)) return [
|
|
1756
1814
|
3,
|
|
1757
1815
|
3
|
|
1758
1816
|
];
|
|
@@ -1833,17 +1891,18 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1833
1891
|
case 8:
|
|
1834
1892
|
shieldedSecretKeys = ledger.ZswapSecretKeys.fromSeed(new Uint8Array(Buffer.from(roleKeys.shielded, 'hex')));
|
|
1835
1893
|
dustSecretKey = ledger.DustSecretKey.fromSeed(new Uint8Array(Buffer.from(roleKeys.dust, 'hex')));
|
|
1836
|
-
unshieldedKeystore = createKeystore(new Uint8Array(Buffer.from(roleKeys.unshielded, 'hex')),
|
|
1894
|
+
unshieldedKeystore = createKeystore(new Uint8Array(Buffer.from(roleKeys.unshielded, 'hex')), network);
|
|
1895
|
+
infra = MIDNIGHT_INFRA[network];
|
|
1837
1896
|
config = {
|
|
1838
|
-
networkId:
|
|
1897
|
+
networkId: network,
|
|
1839
1898
|
costParameters: {
|
|
1840
1899
|
feeBlocksMargin: 5
|
|
1841
1900
|
},
|
|
1842
|
-
relayURL: new URL(
|
|
1843
|
-
provingServerUrl: new URL(
|
|
1901
|
+
relayURL: new URL(infra.relayUrl),
|
|
1902
|
+
provingServerUrl: new URL(infra.provingServerUrl),
|
|
1844
1903
|
indexerClientConnection: {
|
|
1845
|
-
indexerHttpUrl:
|
|
1846
|
-
indexerWsUrl:
|
|
1904
|
+
indexerHttpUrl: infra.indexerHttpUrl,
|
|
1905
|
+
indexerWsUrl: infra.indexerWsUrl
|
|
1847
1906
|
},
|
|
1848
1907
|
// v4 sync batching. `size` = updates fetched per indexer round-trip.
|
|
1849
1908
|
// Measured: 2000 vs 10000 gave the same ~750 entries/sec (≈130s dust cold
|
|
@@ -1856,7 +1915,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
1856
1915
|
};
|
|
1857
1916
|
return [
|
|
1858
1917
|
4,
|
|
1859
|
-
getWalletState(accountAddress)
|
|
1918
|
+
getWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, network))
|
|
1860
1919
|
];
|
|
1861
1920
|
case 9:
|
|
1862
1921
|
savedState = _state.sent();
|
|
@@ -2031,7 +2090,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2031
2090
|
19
|
|
2032
2091
|
];
|
|
2033
2092
|
case 14:
|
|
2034
|
-
|
|
2093
|
+
err1 = _state.sent();
|
|
2035
2094
|
_state.label = 15;
|
|
2036
2095
|
case 15:
|
|
2037
2096
|
_state.trys.push([
|
|
@@ -2057,7 +2116,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2057
2116
|
18
|
|
2058
2117
|
];
|
|
2059
2118
|
case 18:
|
|
2060
|
-
throw
|
|
2119
|
+
throw err1;
|
|
2061
2120
|
case 19:
|
|
2062
2121
|
// Diagnostic: track pending-tx transitions so we can observe TTL
|
|
2063
2122
|
// auto-revert (entry flips from result=undefined → result.status='FAILURE'
|
|
@@ -2162,6 +2221,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2162
2221
|
ledger: ledger,
|
|
2163
2222
|
roleKeys: roleKeys,
|
|
2164
2223
|
accountAddress: accountAddress,
|
|
2224
|
+
network: network,
|
|
2165
2225
|
shieldedSecretKeys: shieldedSecretKeys,
|
|
2166
2226
|
dustSecretKey: dustSecretKey,
|
|
2167
2227
|
diagnosticSub: diagnosticSub
|
|
@@ -2227,7 +2287,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2227
2287
|
{
|
|
2228
2288
|
key: "getPrivateBalance",
|
|
2229
2289
|
value: function getPrivateBalance(param) {
|
|
2230
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2290
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2231
2291
|
var _this = this;
|
|
2232
2292
|
return _async_to_generator(function() {
|
|
2233
2293
|
var _state_unshielded, _state_shielded, _state_dust_balance, _state_dust, _state_dust1, _ref, state, addr, unshieldedByToken, _state_unshielded_balances, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, tokenType, value, shieldedByToken, _state_shielded_balances, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value1, tokenType1, value1, now, _state_dust_balance1, dustBalance, _state_dust_totalCoins, dustCap, result;
|
|
@@ -2245,7 +2305,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2245
2305
|
}, // Resolve once shielded + unshielded are ready; let dust finish in the
|
|
2246
2306
|
// background so the public/shielded balance shows without the ~130s
|
|
2247
2307
|
// dust cold-sync.
|
|
2248
|
-
'shielded-unshielded')
|
|
2308
|
+
'shielded-unshielded', resolveMidnightNetworkTag(networkId))
|
|
2249
2309
|
];
|
|
2250
2310
|
case 1:
|
|
2251
2311
|
_ref = _state.sent(), state = _ref.state, addr = _ref.accountAddress;
|
|
@@ -2324,7 +2384,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2324
2384
|
{
|
|
2325
2385
|
key: "registerDust",
|
|
2326
2386
|
value: function registerDust(param) {
|
|
2327
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2387
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2328
2388
|
var _this = this;
|
|
2329
2389
|
return _async_to_generator(function() {
|
|
2330
2390
|
var _state_dust_balance, _state_dust, _state_unshielded, _state_dust_balance1, _state_dust1, _ref, wallet, state, ledger, roleKeys, _state_dust_balance2, existingDust, _state_unshielded_availableCoins, allUtxos, nightUtxos, _state_dust_balance3, _state_dust2, _state_dust_balance4, dustBalance, verifyingKey, recipe, finalized, submitId, submitIdStr, _state_dust_balance5;
|
|
@@ -2339,7 +2399,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2339
2399
|
signedSessionId: signedSessionId,
|
|
2340
2400
|
mfaToken: mfaToken,
|
|
2341
2401
|
elevatedAccessToken: elevatedAccessToken
|
|
2342
|
-
})
|
|
2402
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
2343
2403
|
];
|
|
2344
2404
|
case 1:
|
|
2345
2405
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, ledger = _ref.ledger, roleKeys = _ref.roleKeys;
|
|
@@ -2439,13 +2499,14 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2439
2499
|
* No MPC, no proof server, no broadcast — pair with signTransaction and
|
|
2440
2500
|
* submitTransaction.
|
|
2441
2501
|
*/ function createTransferTransaction(param) {
|
|
2442
|
-
var accountAddress = param.accountAddress, transfers = param.transfers, ttlMinutes = param.ttlMinutes, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2502
|
+
var accountAddress = param.accountAddress, transfers = param.transfers, ttlMinutes = param.ttlMinutes, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2443
2503
|
var _this = this;
|
|
2444
2504
|
return _async_to_generator(function() {
|
|
2445
|
-
var _state_dust_balance, _state_dust, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, _state_dust_balance1, dustBalance, nativeToken, requiredByKey, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, t, _t_tokenType, token, key, existing, _existing_required, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, side, token1, required, _state_unshielded, _state_shielded, balances, _balances_token, have, sdkTransfers, ttlMs, recipe;
|
|
2505
|
+
var _state_dust_balance, _state_dust, network, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, _state_dust_balance1, dustBalance, nativeToken, requiredByKey, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, t, _t_tokenType, token, key, existing, _existing_required, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, side, token1, required, _state_unshielded, _state_shielded, balances, _balances_token, have, sdkTransfers, ttlMs, recipe;
|
|
2446
2506
|
return _ts_generator(this, function(_state) {
|
|
2447
2507
|
switch(_state.label){
|
|
2448
2508
|
case 0:
|
|
2509
|
+
network = resolveMidnightNetworkTag(networkId);
|
|
2449
2510
|
if (!transfers || transfers.length === 0) {
|
|
2450
2511
|
throw new Error('At least one transfer is required');
|
|
2451
2512
|
}
|
|
@@ -2457,7 +2518,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2457
2518
|
signedSessionId: signedSessionId,
|
|
2458
2519
|
mfaToken: mfaToken,
|
|
2459
2520
|
elevatedAccessToken: elevatedAccessToken
|
|
2460
|
-
})
|
|
2521
|
+
}, 'full', network)
|
|
2461
2522
|
];
|
|
2462
2523
|
case 1:
|
|
2463
2524
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, shieldedSecretKeys = _ref.shieldedSecretKeys, dustSecretKey = _ref.dustSecretKey;
|
|
@@ -2537,7 +2598,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2537
2598
|
var receiverAddress;
|
|
2538
2599
|
try {
|
|
2539
2600
|
var parsed = MidnightBech32m.parse(t.recipientAddress);
|
|
2540
|
-
receiverAddress = t.type === 'unshielded' ? parsed.decode(UnshieldedAddress,
|
|
2601
|
+
receiverAddress = t.type === 'unshielded' ? parsed.decode(UnshieldedAddress, network) : parsed.decode(ShieldedAddress, network);
|
|
2541
2602
|
} catch (err) {
|
|
2542
2603
|
throw new Error("Invalid ".concat(t.type, " recipient address ").concat(t.recipientAddress, ": ").concat(err.message));
|
|
2543
2604
|
}
|
|
@@ -2592,7 +2653,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2592
2653
|
* server; reuses the cached wallet's node connection. Optionally blocks
|
|
2593
2654
|
* until the unshielded balance for tokenType stabilizes.
|
|
2594
2655
|
*/ function submitTransaction(param) {
|
|
2595
|
-
var accountAddress = param.accountAddress, transaction = param.transaction, _param_waitForBalance = param.waitForBalance, waitForBalance = _param_waitForBalance === void 0 ? false : _param_waitForBalance, tokenType = param.tokenType, balanceBefore = param.balanceBefore, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
2656
|
+
var accountAddress = param.accountAddress, transaction = param.transaction, _param_waitForBalance = param.waitForBalance, waitForBalance = _param_waitForBalance === void 0 ? false : _param_waitForBalance, tokenType = param.tokenType, balanceBefore = param.balanceBefore, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
2596
2657
|
var _this = this;
|
|
2597
2658
|
return _async_to_generator(function() {
|
|
2598
2659
|
var _updatedState_unshielded_balances, _updatedState_unshielded, wallet, txBytes, finalized, txIdentifier, txHash, canonicalHash, balanceBeforeBig, updatedState, _updatedState_unshielded_balances_tokenType, balanceAfter;
|
|
@@ -2607,7 +2668,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2607
2668
|
signedSessionId: signedSessionId,
|
|
2608
2669
|
mfaToken: mfaToken,
|
|
2609
2670
|
elevatedAccessToken: elevatedAccessToken
|
|
2610
|
-
})
|
|
2671
|
+
}, 'full', resolveMidnightNetworkTag(networkId))
|
|
2611
2672
|
];
|
|
2612
2673
|
case 1:
|
|
2613
2674
|
wallet = _state.sent().wallet;
|
|
@@ -2759,9 +2820,9 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2759
2820
|
case 1:
|
|
2760
2821
|
_state.trys.push([
|
|
2761
2822
|
1,
|
|
2762
|
-
|
|
2823
|
+
9,
|
|
2763
2824
|
,
|
|
2764
|
-
|
|
2825
|
+
10
|
|
2765
2826
|
]);
|
|
2766
2827
|
if (!(((_this_cachedWallet = _this.cachedWallet) === null || _this_cachedWallet === void 0 ? void 0 : _this_cachedWallet.accountAddress) === accountAddress)) return [
|
|
2767
2828
|
3,
|
|
@@ -2800,20 +2861,28 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2800
2861
|
_this.cachedWallet = null;
|
|
2801
2862
|
_state.label = 6;
|
|
2802
2863
|
case 6:
|
|
2864
|
+
// Nuclear reset is network-agnostic: clear both networks' checkpoints so
|
|
2865
|
+
// no stale snapshot survives on either facade.
|
|
2803
2866
|
return [
|
|
2804
2867
|
4,
|
|
2805
|
-
deleteWalletState(accountAddress)
|
|
2868
|
+
deleteWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, 'preview'))
|
|
2806
2869
|
];
|
|
2807
2870
|
case 7:
|
|
2808
2871
|
_state.sent();
|
|
2809
2872
|
return [
|
|
2810
|
-
|
|
2811
|
-
|
|
2873
|
+
4,
|
|
2874
|
+
deleteWalletState(DynamicMidnightWalletClient.walletStateKey(accountAddress, 'mainnet'))
|
|
2812
2875
|
];
|
|
2813
2876
|
case 8:
|
|
2877
|
+
_state.sent();
|
|
2878
|
+
return [
|
|
2879
|
+
3,
|
|
2880
|
+
10
|
|
2881
|
+
];
|
|
2882
|
+
case 9:
|
|
2814
2883
|
err = _state.sent();
|
|
2815
2884
|
throw new Error("resetCache failed: ".concat(err.message));
|
|
2816
|
-
case
|
|
2885
|
+
case 10:
|
|
2817
2886
|
_this.logger.info('[Midnight] revertTransaction[resetCache]: cache cleared');
|
|
2818
2887
|
return [
|
|
2819
2888
|
2,
|
|
@@ -2846,7 +2915,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2846
2915
|
signedSessionId: params.signedSessionId,
|
|
2847
2916
|
mfaToken: params.mfaToken,
|
|
2848
2917
|
elevatedAccessToken: params.elevatedAccessToken
|
|
2849
|
-
})
|
|
2918
|
+
}, 'full', resolveMidnightNetworkTag(params.networkId))
|
|
2850
2919
|
];
|
|
2851
2920
|
case 1:
|
|
2852
2921
|
wallet = _state.sent().wallet;
|
|
@@ -2891,7 +2960,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
2891
2960
|
signedSessionId: params.signedSessionId,
|
|
2892
2961
|
mfaToken: params.mfaToken,
|
|
2893
2962
|
elevatedAccessToken: params.elevatedAccessToken
|
|
2894
|
-
})
|
|
2963
|
+
}, 'full', resolveMidnightNetworkTag(params.networkId))
|
|
2895
2964
|
];
|
|
2896
2965
|
case 1:
|
|
2897
2966
|
wallet = _state.sent().wallet;
|
|
@@ -3198,13 +3267,14 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3198
3267
|
* Returns a Midnight.js-compatible WalletProvider for use with
|
|
3199
3268
|
* midnight-js-contracts. Signing goes through MPC — no private key exposed.
|
|
3200
3269
|
*/ function getWalletProvider(param) {
|
|
3201
|
-
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
3270
|
+
var accountAddress = param.accountAddress, password = param.password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken, networkId = param.networkId;
|
|
3202
3271
|
var _this = this;
|
|
3203
3272
|
return _async_to_generator(function() {
|
|
3204
|
-
var _ref, wallet, state, shieldedSecretKeys, dustSecretKey, walletProvider;
|
|
3273
|
+
var network, _ref, wallet, state, shieldedSecretKeys, dustSecretKey, walletProvider;
|
|
3205
3274
|
return _ts_generator(this, function(_state) {
|
|
3206
3275
|
switch(_state.label){
|
|
3207
3276
|
case 0:
|
|
3277
|
+
network = resolveMidnightNetworkTag(networkId);
|
|
3208
3278
|
return [
|
|
3209
3279
|
4,
|
|
3210
3280
|
_this.initMidnightWallet('walletProvider', {
|
|
@@ -3213,7 +3283,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3213
3283
|
signedSessionId: signedSessionId,
|
|
3214
3284
|
mfaToken: mfaToken,
|
|
3215
3285
|
elevatedAccessToken: elevatedAccessToken
|
|
3216
|
-
})
|
|
3286
|
+
}, 'full', network)
|
|
3217
3287
|
];
|
|
3218
3288
|
case 1:
|
|
3219
3289
|
_ref = _state.sent(), wallet = _ref.wallet, state = _ref.state, shieldedSecretKeys = _ref.shieldedSecretKeys, dustSecretKey = _ref.dustSecretKey;
|
|
@@ -3242,8 +3312,8 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3242
3312
|
];
|
|
3243
3313
|
case 1:
|
|
3244
3314
|
recipe = _state.sent();
|
|
3245
|
-
// The proven base tx uses the 'proof' marker.
|
|
3246
|
-
// the
|
|
3315
|
+
// The proven base tx uses the 'proof' marker. The numeric networkId
|
|
3316
|
+
// must match the facade network this provider was configured for.
|
|
3247
3317
|
baseTxB64 = Buffer.from(recipe.baseTransaction.serialize()).toString('base64');
|
|
3248
3318
|
return [
|
|
3249
3319
|
4,
|
|
@@ -3254,7 +3324,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3254
3324
|
mfaToken: mfaToken,
|
|
3255
3325
|
elevatedAccessToken: elevatedAccessToken,
|
|
3256
3326
|
fullTxBase64: baseTxB64,
|
|
3257
|
-
networkId:
|
|
3327
|
+
networkId: MIDNIGHT_NETWORK_IDS[network],
|
|
3258
3328
|
proofMarker: 'proof'
|
|
3259
3329
|
})
|
|
3260
3330
|
];
|
|
@@ -3274,7 +3344,7 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3274
3344
|
mfaToken: mfaToken,
|
|
3275
3345
|
elevatedAccessToken: elevatedAccessToken,
|
|
3276
3346
|
fullTxBase64: balancingTxB64,
|
|
3277
|
-
networkId:
|
|
3347
|
+
networkId: MIDNIGHT_NETWORK_IDS[network],
|
|
3278
3348
|
proofMarker: 'pre-proof'
|
|
3279
3349
|
})
|
|
3280
3350
|
];
|
|
@@ -3316,13 +3386,23 @@ var DynamicMidnightWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
|
3316
3386
|
}
|
|
3317
3387
|
], [
|
|
3318
3388
|
{
|
|
3319
|
-
key: "
|
|
3389
|
+
key: "walletStateKey",
|
|
3320
3390
|
value: /**
|
|
3321
3391
|
* Coerce the value returned by `wallet.submitTransaction(...)` to a string.
|
|
3322
3392
|
* Midnight's facade returns either a string txId, or a TransactionIdentifier
|
|
3323
3393
|
* object with a `.toHex()` method. We normalize so callers always see a
|
|
3324
3394
|
* string, and fall back to `String(...)` if neither shape matches.
|
|
3325
|
-
*/
|
|
3395
|
+
*/ /**
|
|
3396
|
+
* IndexedDB checkpoint key. Sync state is per (account, network) — restoring
|
|
3397
|
+
* a preview snapshot into a mainnet facade would corrupt sync. Preview keeps
|
|
3398
|
+
* the bare-address key so pre-existing checkpoints stay valid.
|
|
3399
|
+
*/ function walletStateKey(accountAddress, network) {
|
|
3400
|
+
return network === 'mainnet' ? "".concat(accountAddress, "::mainnet") : accountAddress;
|
|
3401
|
+
}
|
|
3402
|
+
},
|
|
3403
|
+
{
|
|
3404
|
+
key: "toTxHashString",
|
|
3405
|
+
value: function toTxHashString(txIdentifier) {
|
|
3326
3406
|
if (typeof txIdentifier === 'string') return txIdentifier;
|
|
3327
3407
|
var maybeHex = txIdentifier === null || txIdentifier === void 0 ? void 0 : txIdentifier.toHex;
|
|
3328
3408
|
if (typeof maybeHex === 'function') return txIdentifier.toHex();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/midnight",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.69",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/browser": "1.0.
|
|
7
|
+
"@dynamic-labs-wallet/browser": "1.0.69",
|
|
8
8
|
"@dynamic-labs/sdk-api-core": "^0.0.984",
|
|
9
9
|
"@midnight-ntwrk/ledger-v8": "^8.1.0",
|
|
10
10
|
"@midnight-ntwrk/wallet-sdk-abstractions": "2.1.0",
|
package/src/client/client.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
26
26
|
* object with a `.toHex()` method. We normalize so callers always see a
|
|
27
27
|
* string, and fall back to `String(...)` if neither shape matches.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* IndexedDB checkpoint key. Sync state is per (account, network) — restoring
|
|
31
|
+
* a preview snapshot into a mainnet facade would corrupt sync. Preview keeps
|
|
32
|
+
* the bare-address key so pre-existing checkpoints stay valid.
|
|
33
|
+
*/
|
|
34
|
+
private static walletStateKey;
|
|
29
35
|
private static toTxHashString;
|
|
30
36
|
/**
|
|
31
37
|
* Snapshot the current shielded + dust state to IndexedDB so the next
|
|
@@ -117,12 +123,14 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
117
123
|
private getRoleKeys;
|
|
118
124
|
private initMidnightWallet;
|
|
119
125
|
private runMidnightWalletInit;
|
|
120
|
-
getPrivateBalance({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
|
|
126
|
+
getPrivateBalance({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, }: {
|
|
121
127
|
accountAddress: string;
|
|
122
128
|
password?: string;
|
|
123
129
|
signedSessionId: string;
|
|
124
130
|
mfaToken?: string;
|
|
125
131
|
elevatedAccessToken?: string;
|
|
132
|
+
/** Network to read balances on: 0/'preview' (default) or 1/'mainnet'. */
|
|
133
|
+
networkId?: number | string;
|
|
126
134
|
}): Promise<{
|
|
127
135
|
unshielded: Record<string, string>;
|
|
128
136
|
shielded: Record<string, string>;
|
|
@@ -137,12 +145,14 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
137
145
|
* can show a "dust loading" state and poll until this is true. */
|
|
138
146
|
dustSynced: boolean;
|
|
139
147
|
}>;
|
|
140
|
-
registerDust({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
|
|
148
|
+
registerDust({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, }: {
|
|
141
149
|
accountAddress: string;
|
|
142
150
|
password?: string;
|
|
143
151
|
signedSessionId: string;
|
|
144
152
|
mfaToken?: string;
|
|
145
153
|
elevatedAccessToken?: string;
|
|
154
|
+
/** Network to register dust on: 0/'preview' (default) or 1/'mainnet'. */
|
|
155
|
+
networkId?: number | string;
|
|
146
156
|
}): Promise<{
|
|
147
157
|
/** Current dust balance at time of this call. 0 is normal for fresh
|
|
148
158
|
* registrations — dust generation is continuous on-chain, poll
|
|
@@ -167,7 +177,7 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
167
177
|
* No MPC, no proof server, no broadcast — pair with signTransaction and
|
|
168
178
|
* submitTransaction.
|
|
169
179
|
*/
|
|
170
|
-
createTransferTransaction({ accountAddress, transfers, ttlMinutes, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
|
|
180
|
+
createTransferTransaction({ accountAddress, transfers, ttlMinutes, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, }: {
|
|
171
181
|
accountAddress: string;
|
|
172
182
|
transfers: Array<{
|
|
173
183
|
type: 'unshielded' | 'shielded';
|
|
@@ -181,6 +191,8 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
181
191
|
signedSessionId: string;
|
|
182
192
|
mfaToken?: string;
|
|
183
193
|
elevatedAccessToken?: string;
|
|
194
|
+
/** Network to build the transfer on: 0/'preview' (default) or 1/'mainnet'. */
|
|
195
|
+
networkId?: number | string;
|
|
184
196
|
}): Promise<{
|
|
185
197
|
serializedTransaction: string;
|
|
186
198
|
}>;
|
|
@@ -189,7 +201,7 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
189
201
|
* server; reuses the cached wallet's node connection. Optionally blocks
|
|
190
202
|
* until the unshielded balance for tokenType stabilizes.
|
|
191
203
|
*/
|
|
192
|
-
submitTransaction({ accountAddress, transaction, waitForBalance, tokenType, balanceBefore, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
|
|
204
|
+
submitTransaction({ accountAddress, transaction, waitForBalance, tokenType, balanceBefore, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, }: {
|
|
193
205
|
accountAddress: string;
|
|
194
206
|
/** Base64-encoded FinalizedTransaction */
|
|
195
207
|
transaction: string;
|
|
@@ -201,6 +213,8 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
201
213
|
signedSessionId: string;
|
|
202
214
|
mfaToken?: string;
|
|
203
215
|
elevatedAccessToken?: string;
|
|
216
|
+
/** Network to broadcast on: 0/'preview' (default) or 1/'mainnet'. */
|
|
217
|
+
networkId?: number | string;
|
|
204
218
|
}): Promise<{
|
|
205
219
|
txHash: string;
|
|
206
220
|
balanceAfter?: string;
|
|
@@ -235,6 +249,8 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
235
249
|
signedSessionId: string;
|
|
236
250
|
mfaToken?: string;
|
|
237
251
|
elevatedAccessToken?: string;
|
|
252
|
+
/** Network the pending txs live on: 0/'preview' (default) or 1/'mainnet'. */
|
|
253
|
+
networkId?: number | string;
|
|
238
254
|
}): Promise<{
|
|
239
255
|
reverted: boolean;
|
|
240
256
|
count: number;
|
|
@@ -260,12 +276,14 @@ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
|
|
|
260
276
|
* Returns a Midnight.js-compatible WalletProvider for use with
|
|
261
277
|
* midnight-js-contracts. Signing goes through MPC — no private key exposed.
|
|
262
278
|
*/
|
|
263
|
-
getWalletProvider({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
|
|
279
|
+
getWalletProvider({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, }: {
|
|
264
280
|
accountAddress: string;
|
|
265
281
|
password?: string;
|
|
266
282
|
signedSessionId: string;
|
|
267
283
|
mfaToken?: string;
|
|
268
284
|
elevatedAccessToken?: string;
|
|
285
|
+
/** Network the provider targets: 0/'preview' (default) or 1/'mainnet'. */
|
|
286
|
+
networkId?: number | string;
|
|
269
287
|
}): Promise<{
|
|
270
288
|
walletProvider: any;
|
|
271
289
|
wallet: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAKnB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAKnB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAsCrE;;;;;;;;;GASG;AACH,KAAK,cAAc,GAAG,MAAM,GAAG,qBAAqB,CAAC;AAErD;+EAC+E;AAC/E,eAAO,MAAM,YAAY,SAAU,GAAG,KAAG,OAOxC,CAAC;AAEF,qDAAqD;AACrD,eAAO,MAAM,cAAc,MAAO,GAAG,QAAQ,cAAc,KAAG,OACkC,CAAC;AAEjG,qBAAa,2BAA4B,SAAQ,mBAAmB;IAClE,QAAQ,CAAC,SAAS,cAAc;IAMhC,OAAO,CAAC,YAAY,CASJ;IAOhB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;IAEhE;;;;;OAKG;IACH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AM,CAAC;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,0EAA0E;QAC1E,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,GAAG,CAAC;QACpB,MAAM,EAAE,GAAG,CAAC;QACZ,KAAK,EAAE,GAAG,CAAC;QACX,kBAAkB,EAAE,GAAG,CAAC;QACxB,aAAa,EAAE,GAAG,CAAC;KACpB,CAAC;CAoEH"}
|
|
@@ -5,6 +5,32 @@ export declare const MIDNIGHT_NETWORK_IDS: {
|
|
|
5
5
|
readonly undeployed: 0;
|
|
6
6
|
};
|
|
7
7
|
export type MidnightNetwork = keyof typeof MIDNIGHT_NETWORK_IDS;
|
|
8
|
+
/**
|
|
9
|
+
* Facade network tag: which Midnight network the wallet runtime (relay,
|
|
10
|
+
* indexer, proof server, sync state) operates against. Distinct from the
|
|
11
|
+
* numeric replay-protection id — see MIDNIGHT_NETWORK_IDS.
|
|
12
|
+
*/
|
|
13
|
+
export type MidnightNetworkTag = 'preview' | 'mainnet';
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the caller-supplied network identifier (numeric 0/1, network name,
|
|
16
|
+
* or "midnight:<network>" chainId) to the facade network tag. Defaults to
|
|
17
|
+
* 'preview' when absent — the legacy single-network behavior, so requests from
|
|
18
|
+
* hosts that predate per-network support are unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export declare const resolveMidnightNetworkTag: (networkId?: number | string) => MidnightNetworkTag;
|
|
21
|
+
/**
|
|
22
|
+
* Wallet-facade infrastructure (relay / indexer / proving server) per Midnight
|
|
23
|
+
* network. RPC + indexer hosts are the official per-network endpoints. There
|
|
24
|
+
* is no public mainnet proof server, so Dynamic's own proof server is shared
|
|
25
|
+
* across networks for now — revisit if a dedicated mainnet one is stood up.
|
|
26
|
+
*/
|
|
27
|
+
export type MidnightWalletInfraConfig = {
|
|
28
|
+
relayUrl: string;
|
|
29
|
+
provingServerUrl: string;
|
|
30
|
+
indexerHttpUrl: string;
|
|
31
|
+
indexerWsUrl: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const MIDNIGHT_INFRA: Record<MidnightNetworkTag, MidnightWalletInfraConfig>;
|
|
8
34
|
export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
|
|
9
35
|
export declare const ERROR_NETWORK_ID_REQUIRED = "Network ID is required for Midnight transactions";
|
|
10
36
|
export declare const ERROR_UNKNOWN_NETWORK = "Unknown Midnight network";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAEhE;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,eAAgB,MAAM,GAAG,MAAM,KAAG,kBAKvE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,kBAAkB,EAAE,yBAAyB,CAahF,CAAC;AAGF,eAAO,MAAM,8BAA8B,gCAAgC,CAAC;AAC5E,eAAO,MAAM,yBAAyB,qDAAqD,CAAC;AAC5F,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,2BAA2B,6CAA6C,CAAC;AACtF,eAAO,MAAM,wBAAwB,0CAA0C,CAAC;AAChF,eAAO,MAAM,wBAAwB,0CAA0C,CAAC;AAChF,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAC/E,eAAO,MAAM,kBAAkB,oCAAoC,CAAC;AACpE,eAAO,MAAM,sBAAsB,wCAAwC,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,qBAAsB,MAAM,KAAG,MAgBlE,CAAC"}
|