@spirobel/monero-wallet-api 0.6.1 → 0.6.3
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/README.md +40 -4
- package/dist/actionlog/actionLogOpened.js +7 -2
- package/dist/frost_dkg.wasm +0 -0
- package/dist/io/logging.js +1 -1
- package/dist/keypairs-seeds/keypairs.js +5 -5
- package/dist/monero_wallet_api.wasm +0 -0
- package/dist/multisig/DistributedKeyGenerator.js +3 -3
- package/dist/multisig/MultiSigTxSigner.js +2 -2
- package/dist/multisig/escrow.js +1 -1
- package/dist/multisig/multisig.js +4 -0
- package/dist/node-interaction/binaryEndpoints.d.ts +3 -3
- package/dist/node-interaction/nodeUrl.js +2 -2
- package/dist/scanning-syncing/backgroundWorker.d.ts +3 -0
- package/dist/scanning-syncing/backgroundWorker.js +38 -8
- package/dist/scanning-syncing/blocksbuffer/blocksBufferFetchLoop.d.ts +1 -1
- package/dist/scanning-syncing/blocksbuffer/blocksBufferFetchLoop.js +1 -1
- package/dist/scanning-syncing/blocksbuffer/blocksbufferCoordination.d.ts +1 -1
- package/dist/scanning-syncing/blocksbuffer/blocksbufferCoordination.js +1 -1
- package/dist/scanning-syncing/connectionStatus.d.ts +1 -1
- package/dist/scanning-syncing/connectionStatus.js +2 -2
- package/dist/scanning-syncing/openWallet.js +1 -1
- package/dist/scanning-syncing/scanresult/computeKeyImage.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/computeKeyImage.js +2 -2
- package/dist/scanning-syncing/scanresult/scanCache.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/scanCache.js +1 -1
- package/dist/scanning-syncing/scanresult/scanCacheOpened.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/scanCacheOpened.js +33 -16
- package/dist/scanning-syncing/scanresult/scanCoordination.d.ts +2 -2
- package/dist/scanning-syncing/scanresult/scanCoordination.js +2 -2
- package/dist/scanning-syncing/scanresult/scanLoop.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/scanLoop.js +1 -1
- package/dist/scanning-syncing/scanresult/scanResult.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/scanResult.js +3 -3
- package/dist/scanning-syncing/scanresult/scanStats.d.ts +1 -1
- package/dist/scanning-syncing/scanresult/scanStats.js +1 -2
- package/dist/scanning-syncing/worker-entrypoints/worker.js +1 -1
- package/dist/scanning-syncing/worker-mains/cpubound-main.js +1 -1
- package/dist/scanning-syncing/worker-mains/multisig-main.d.ts +1 -1
- package/dist/scanning-syncing/worker-mains/multisig-main.js +1 -1
- package/dist/scanning-syncing/worker-mains/worker.js +9 -1
- package/dist/scansettings/scanSettings.js +1 -1
- package/dist/scansettings/scanSettingsOpened.d.ts +2 -1
- package/dist/scansettings/scanSettingsOpened.js +13 -6
- package/dist/send-functionality/inputSelection.d.ts +1 -1
- package/dist/send-functionality/transactionBuilding.d.ts +1 -1
- package/dist/send-functionality/transactionBuilding.js +3 -3
- package/dist/viewpair/ViewPair.d.ts +4 -4
- package/dist/viewpair/ViewPair.js +4 -4
- package/dist/wasm-processing/wasmLoader.d.ts +10 -0
- package/dist/wasm-processing/wasmLoader.js +108 -0
- package/dist/worker_unpacked.js +14055 -0
- package/dist/xmr3.d.ts +1 -39
- package/dist/xmr3.js +10 -37
- package/dist/xmr3_common.d.ts +39 -0
- package/dist/xmr3_common.js +37 -0
- package/dist/xmr3_unpacked.d.ts +9 -0
- package/dist/xmr3_unpacked.js +14 -0
- package/package.json +9 -2
- package/dist/actionlog/actionLog.d.ts +0 -4
- package/dist/actionlog/actionLog.js +0 -9
- package/dist/actionlog/backend/jsonlBackend.d.ts +0 -19
- package/dist/actionlog/backend/jsonlBackend.js +0 -110
- package/dist/actionlog/backend/memoryBackend.d.ts +0 -11
- package/dist/actionlog/backend/memoryBackend.js +0 -31
- package/dist/actionlog/backend.d.ts +0 -12
- package/dist/actionlog/backend.js +0 -1
- package/dist/actionlog/idbBackend.d.ts +0 -19
- package/dist/actionlog/idbBackend.js +0 -98
- package/dist/actionlog/jsonlBackend.d.ts +0 -19
- package/dist/actionlog/jsonlBackend.js +0 -75
- package/dist/actionlog/memoryBackend.d.ts +0 -14
- package/dist/actionlog/memoryBackend.js +0 -38
- package/dist/actionlog/openMaps.d.ts +0 -11
- package/dist/actionlog/openMaps.js +0 -32
- package/dist/actionlog/sqliteBackend.d.ts +0 -18
- package/dist/actionlog/sqliteBackend.js +0 -105
- package/dist/actionlog/toolContext.d.ts +0 -36
- package/dist/actionlog/toolContext.js +0 -1
- package/dist/actionlog/types.d.ts +0 -62
- package/dist/actionlog/types.js +0 -62
- package/dist/scanning-syncing/blocksbuffer/getBlocksbinBuffer.d.ts +0 -28
- package/dist/scanning-syncing/blocksbuffer/getBlocksbinBuffer.js +0 -54
- package/dist/scanning-syncing/scanSettings.d.ts +0 -165
- package/dist/scanning-syncing/scanSettings.js +0 -338
- package/dist/scanning-syncing/scanresult/reorg.d.ts +0 -3
- package/dist/scanning-syncing/scanresult/reorg.js +0 -101
- package/dist/scanning-syncing/scansettings/scanSettings.d.ts +0 -165
- package/dist/scanning-syncing/scansettings/scanSettings.js +0 -338
- package/dist/send-functionality/multisig.d.ts +0 -72
- package/dist/send-functionality/multisig.js +0 -97
- package/dist/tools/calls/002-content.d.ts +0 -46
- package/dist/tools/calls/002-content.js +0 -135
- package/dist/tools/calls/002-fail-cleanup.d.ts +0 -27
- package/dist/tools/calls/002-fail-cleanup.js +0 -60
- package/dist/tools/counterparty.d.ts +0 -3
- package/dist/tools/counterparty.js +0 -1
- package/dist/tools/monero-tools-content.d.ts +0 -29
- package/dist/tools/monero-tools-content.js +0 -80
- package/dist/tools/runtimeMessages.d.ts +0 -4
- package/dist/tools/runtimeMessages.js +0 -18
- package/dist/tools/toolActionLogContext.d.ts +0 -33
- package/dist/tools/toolActionLogContext.js +0 -1
- package/dist/tools/toolArm.d.ts +0 -47
- package/dist/tools/toolArm.js +0 -1
- package/dist/tools/ui.d.ts +0 -2
- package/dist/tools/ui.js +0 -1
- package/dist/tools/worker.d.ts +0 -1
- package/dist/tools/worker.js +0 -1
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import { get_info } from "../api";
|
|
2
|
-
import { atomicWrite } from "../io/atomicWrite";
|
|
3
|
-
import { refreshEnvIndexedDB } from "../io/indexedDB";
|
|
4
|
-
import { LOCAL_NODE_DEFAULT_URL } from "../node-interaction/nodeUrl";
|
|
5
|
-
export const SCAN_SETTINGS_STORE_NAME_DEFAULT = "ScanSettings.json";
|
|
6
|
-
// default value for subaddress highest minor index eg up to which minor index,
|
|
7
|
-
// to add subaddresses to the scanner
|
|
8
|
-
// (we never touch major index, having two values is just too confusing)
|
|
9
|
-
export const SUB_ADDRESS_INDEX_DEFAULT_VALUE = 1;
|
|
10
|
-
/**
|
|
11
|
-
* Writes scan settings to the default or specified storage file in json.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```
|
|
15
|
-
* const settings: ScanSettings = {
|
|
16
|
-
* wallets: [{
|
|
17
|
-
* primary_address: "5dsf...",
|
|
18
|
-
* start_height: 1741707,
|
|
19
|
-
* }],
|
|
20
|
-
* node_urls: ["https://monerooo.roooo"]
|
|
21
|
-
* };
|
|
22
|
-
* await writeScanSettings(settings);
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @param scan_settings - The complete {@link ScanSettings} configuration to persist.
|
|
26
|
-
* @param scan_settings_path - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
27
|
-
* @returns A promise that resolves when the file is successfully written.
|
|
28
|
-
* @throws Will throw if file writing fails (e.g., permissions, disk space).
|
|
29
|
-
*/
|
|
30
|
-
export async function writeScanSettings(scan_settings, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
31
|
-
return await atomicWrite(scan_settings_path, JSON.stringify(scan_settings, null, 2));
|
|
32
|
-
}
|
|
33
|
-
export async function writeScanSettingsFileDefaultLocation(params) {
|
|
34
|
-
let settings = await openScanSettingsFile(params.scan_settings_path);
|
|
35
|
-
if (!settings) {
|
|
36
|
-
// Create empty ScanSettings object with default values
|
|
37
|
-
settings = {
|
|
38
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
39
|
-
wallets: [],
|
|
40
|
-
start_height: null,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
await params.writeCallback(settings);
|
|
44
|
-
// write to settings file
|
|
45
|
-
await writeScanSettings(settings, params.scan_settings_path);
|
|
46
|
-
}
|
|
47
|
-
export async function writeStartHeightToScanSettings(start_height, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
48
|
-
const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
|
|
49
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
50
|
-
wallets: [],
|
|
51
|
-
start_height: null,
|
|
52
|
-
};
|
|
53
|
-
scanSettings.start_height = start_height;
|
|
54
|
-
return await atomicWrite(SCAN_SETTINGS_STORE_NAME_DEFAULT, JSON.stringify(scanSettings, null, 2));
|
|
55
|
-
}
|
|
56
|
-
export async function writeDaemonHeightAsStartHeightToScanSettings(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
57
|
-
const getInfo = await get_info(node_url);
|
|
58
|
-
const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
|
|
59
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
60
|
-
wallets: [],
|
|
61
|
-
start_height: null,
|
|
62
|
-
};
|
|
63
|
-
scanSettings.start_height = getInfo.height - 1;
|
|
64
|
-
await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
|
|
65
|
-
return getInfo.height;
|
|
66
|
-
}
|
|
67
|
-
export async function cullTooLargeScanHeight(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
68
|
-
const getInfo = await get_info(node_url);
|
|
69
|
-
const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
|
|
70
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
71
|
-
wallets: [],
|
|
72
|
-
start_height: null,
|
|
73
|
-
};
|
|
74
|
-
if (scanSettings.start_height === null ||
|
|
75
|
-
scanSettings.start_height > getInfo.height - 1) {
|
|
76
|
-
scanSettings.start_height = getInfo.height - 1;
|
|
77
|
-
await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
|
|
78
|
-
}
|
|
79
|
-
return scanSettings.start_height;
|
|
80
|
-
}
|
|
81
|
-
export async function writeNodeUrlToScanSettings(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
82
|
-
const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
|
|
83
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
84
|
-
wallets: [],
|
|
85
|
-
start_height: null,
|
|
86
|
-
};
|
|
87
|
-
scanSettings.node_url = node_url;
|
|
88
|
-
return await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
|
|
89
|
-
}
|
|
90
|
-
export async function readNodeUrlFromScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
91
|
-
const scanSettings = await openScanSettingsFile(scan_settings_path);
|
|
92
|
-
return scanSettings?.node_url;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Writes the merchant confirmation threshold to scan settings.
|
|
96
|
-
*
|
|
97
|
-
* This setting only has effect when the wallet is run as part of a checkout system,
|
|
98
|
-
* that accepts payments.
|
|
99
|
-
* It determines after how many confirmations a transaction is accepted
|
|
100
|
-
* for a payment. The actual enforcement of this policy is left to the
|
|
101
|
-
* custom payment-system code that consumes this library.
|
|
102
|
-
*
|
|
103
|
-
* @param merchant_confirmations - Number of confirmations required before
|
|
104
|
-
* accepting a payment, or `null` to leave it unset.
|
|
105
|
-
* @param scan_settings_path - Optional path for the settings file.
|
|
106
|
-
* Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
107
|
-
* @returns A promise that resolves when the file is successfully written.
|
|
108
|
-
*/
|
|
109
|
-
export async function writeMerchantConfirmationsToScanSettings(merchant_confirmations, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
110
|
-
const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
|
|
111
|
-
node_url: LOCAL_NODE_DEFAULT_URL,
|
|
112
|
-
wallets: [],
|
|
113
|
-
start_height: null,
|
|
114
|
-
};
|
|
115
|
-
scanSettings.merchant_confirmations = merchant_confirmations;
|
|
116
|
-
return await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Reads the merchant confirmation threshold from scan settings.
|
|
120
|
-
*
|
|
121
|
-
* This setting only has effect when the wallet is run as part of a checkout system,
|
|
122
|
-
* that accepts payments.
|
|
123
|
-
*
|
|
124
|
-
* It determines after how many confirmations a transaction is accepted
|
|
125
|
-
* for a payment. The actual enforcement of this policy is left to the
|
|
126
|
-
* custom payment-system code that consumes this library.
|
|
127
|
-
*
|
|
128
|
-
* @param scan_settings_path - Optional path for the settings file.
|
|
129
|
-
* Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
130
|
-
* @returns The configured number of confirmations, null, or `undefined`
|
|
131
|
-
* if the setting has not been persisted yet.
|
|
132
|
-
*/
|
|
133
|
-
export async function readMerchantConfirmationsFromScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
134
|
-
const scanSettings = await openScanSettingsFile(scan_settings_path);
|
|
135
|
-
return scanSettings?.merchant_confirmations;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Reads scan settings from the default or specified storage file.
|
|
139
|
-
* secret_view_key and spend_private_key are read from environment variables
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```
|
|
143
|
-
* const settings = await readScanSettings();
|
|
144
|
-
* if (settings) {
|
|
145
|
-
* console.log(settings.wallets?.primary_address);
|
|
146
|
-
* }
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* @param scan_settings_path - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
150
|
-
* @returns The parsed {@link ScanSettings} object if file exists and is valid JSON, otherwise `undefined`.
|
|
151
|
-
*/
|
|
152
|
-
export async function readScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
153
|
-
const scanSettings = await openScanSettingsFile(scan_settings_path);
|
|
154
|
-
if (!scanSettings)
|
|
155
|
-
return undefined;
|
|
156
|
-
const openScanSettings = Object.assign({}, scanSettings);
|
|
157
|
-
for (const [i, wallet] of scanSettings.wallets.entries()) {
|
|
158
|
-
if (!wallet.primary_address)
|
|
159
|
-
throw new Error("The entry ${i} in the wallet settings list in ${scan_settings_path} has no primary address");
|
|
160
|
-
const walletWithKeys = await walletSettingsPlusKeys({
|
|
161
|
-
...wallet,
|
|
162
|
-
node_url: scanSettings.node_url,
|
|
163
|
-
start_height: scanSettings.start_height,
|
|
164
|
-
});
|
|
165
|
-
openScanSettings.wallets[i].secret_view_key =
|
|
166
|
-
walletWithKeys.secret_view_key;
|
|
167
|
-
openScanSettings.wallets[i].secret_spend_key =
|
|
168
|
-
walletWithKeys.secret_spend_key;
|
|
169
|
-
}
|
|
170
|
-
return openScanSettings;
|
|
171
|
-
}
|
|
172
|
-
export function readPrivateSpendKeyFromEnv(primary_address) {
|
|
173
|
-
return Bun.env["sk" + primary_address];
|
|
174
|
-
}
|
|
175
|
-
export function readPrivateViewKeyFromEnv(primary_address) {
|
|
176
|
-
return Bun.env["vk" + primary_address];
|
|
177
|
-
}
|
|
178
|
-
export async function readWalletFromScanSettings(primary_address, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
179
|
-
const scanSettings = await openScanSettingsFile(scan_settings_path);
|
|
180
|
-
if (!scanSettings)
|
|
181
|
-
return undefined;
|
|
182
|
-
const walletSettings = scanSettings.wallets.find((wallet) => wallet?.primary_address === primary_address);
|
|
183
|
-
if (!walletSettings)
|
|
184
|
-
throw new Error(`wallet not found in settings. did you call openwallet with the right params?
|
|
185
|
-
Either wrong file name supplied to params.scan_settings_path: ${scan_settings_path}
|
|
186
|
-
Or wrong primary_address supplied params.primary_address: ${primary_address}`);
|
|
187
|
-
return {
|
|
188
|
-
...walletSettings,
|
|
189
|
-
node_url: scanSettings.node_url,
|
|
190
|
-
start_height: scanSettings.start_height,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
export async function readWalletsFromScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
194
|
-
const scanSettings = await openScanSettingsFile(scan_settings_path);
|
|
195
|
-
const scanSettingsOpened = [];
|
|
196
|
-
for (const wallet of scanSettings?.wallets || []) {
|
|
197
|
-
scanSettingsOpened.push({
|
|
198
|
-
...wallet,
|
|
199
|
-
node_url: scanSettings?.node_url || LOCAL_NODE_DEFAULT_URL,
|
|
200
|
-
start_height: scanSettings?.start_height || null,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
return scanSettingsOpened;
|
|
204
|
-
}
|
|
205
|
-
export async function walletSettingsPlusKeys(wallet_settings, secret_view_key, secret_spend_key) {
|
|
206
|
-
// read secret_view_key and secret_spend_key from env
|
|
207
|
-
if (!secret_view_key)
|
|
208
|
-
secret_view_key = Bun.env[`vk${wallet_settings.primary_address}`];
|
|
209
|
-
if (!secret_view_key) {
|
|
210
|
-
await refreshEnvIndexedDB();
|
|
211
|
-
secret_view_key = Bun.env[`vk${wallet_settings.primary_address}`];
|
|
212
|
-
}
|
|
213
|
-
if (!secret_view_key)
|
|
214
|
-
throw ("no secret_view_key provided and not found in env for address: " +
|
|
215
|
-
wallet_settings.primary_address);
|
|
216
|
-
if (!secret_spend_key)
|
|
217
|
-
secret_spend_key = Bun.env[`sk${wallet_settings.primary_address}`];
|
|
218
|
-
return {
|
|
219
|
-
...wallet_settings,
|
|
220
|
-
secret_view_key,
|
|
221
|
-
secret_spend_key,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
export async function writeWalletToScanSettings(params) {
|
|
225
|
-
if (!params.scan_settings_path)
|
|
226
|
-
params.scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT;
|
|
227
|
-
if (!params.primary_address)
|
|
228
|
-
throw new Error("no primary address provided to writeWalletToScanSettings()");
|
|
229
|
-
const scanSettings = await openScanSettingsFile(params.scan_settings_path);
|
|
230
|
-
if (!scanSettings) {
|
|
231
|
-
if (!params.node_url)
|
|
232
|
-
params.node_url = LOCAL_NODE_DEFAULT_URL;
|
|
233
|
-
// case: no scan settings exist yet
|
|
234
|
-
return await writeScanSettings({
|
|
235
|
-
wallets: [
|
|
236
|
-
{
|
|
237
|
-
primary_address: params.primary_address,
|
|
238
|
-
subaddress_index: params.subaddress_index || SUB_ADDRESS_INDEX_DEFAULT_VALUE,
|
|
239
|
-
halted: params.halted,
|
|
240
|
-
wallet_route: params.wallet_route,
|
|
241
|
-
wallet_name: params.wallet_name,
|
|
242
|
-
wallet_slot: params.wallet_slot,
|
|
243
|
-
},
|
|
244
|
-
],
|
|
245
|
-
node_url: params.node_url,
|
|
246
|
-
logs: params.logs,
|
|
247
|
-
logs_include: params.logs_include,
|
|
248
|
-
logs_exclude: params.logs_exclude,
|
|
249
|
-
start_height: params.start_height || null,
|
|
250
|
-
}, params.scan_settings_path);
|
|
251
|
-
}
|
|
252
|
-
scanSettings.node_url = params.node_url || scanSettings.node_url;
|
|
253
|
-
if (params.logs)
|
|
254
|
-
scanSettings.logs = params.logs;
|
|
255
|
-
if (params.logs_include)
|
|
256
|
-
scanSettings.logs_include = params.logs_include;
|
|
257
|
-
if (params.logs_exclude)
|
|
258
|
-
scanSettings.logs_exclude = params.logs_exclude;
|
|
259
|
-
scanSettings.start_height =
|
|
260
|
-
params.start_height === undefined
|
|
261
|
-
? scanSettings.start_height
|
|
262
|
-
: params.start_height;
|
|
263
|
-
const already_has_settings = scanSettings.wallets.findIndex((wallet) => wallet?.primary_address === params.primary_address);
|
|
264
|
-
if (already_has_settings === -1) {
|
|
265
|
-
// wallet does not exist yet in settings
|
|
266
|
-
scanSettings.wallets.push({
|
|
267
|
-
primary_address: params.primary_address,
|
|
268
|
-
subaddress_index: params.subaddress_index || SUB_ADDRESS_INDEX_DEFAULT_VALUE,
|
|
269
|
-
halted: params.halted,
|
|
270
|
-
wallet_route: params.wallet_route,
|
|
271
|
-
wallet_name: params.wallet_name,
|
|
272
|
-
wallet_slot: params.wallet_slot,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
// wallet already exists
|
|
277
|
-
const wallet = scanSettings.wallets[already_has_settings];
|
|
278
|
-
if (wallet) {
|
|
279
|
-
wallet.subaddress_index =
|
|
280
|
-
params.subaddress_index ||
|
|
281
|
-
wallet.subaddress_index ||
|
|
282
|
-
SUB_ADDRESS_INDEX_DEFAULT_VALUE;
|
|
283
|
-
wallet.halted = params.halted || wallet.halted;
|
|
284
|
-
wallet.wallet_route = params.wallet_route || wallet.wallet_route;
|
|
285
|
-
wallet.wallet_name = params.wallet_name || wallet.wallet_name;
|
|
286
|
-
wallet.wallet_slot = params.wallet_slot || wallet.wallet_slot;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return await atomicWrite(params.scan_settings_path, JSON.stringify(scanSettings, null, 2));
|
|
290
|
-
}
|
|
291
|
-
export async function openScanSettingsFile(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
292
|
-
const jsonString = await Bun.file(scan_settings_path)
|
|
293
|
-
.text()
|
|
294
|
-
.catch(() => undefined);
|
|
295
|
-
return jsonString ? JSON.parse(jsonString) : undefined;
|
|
296
|
-
}
|
|
297
|
-
export async function openNonHaltedWallets(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
298
|
-
const scan_settings = await readWalletsFromScanSettings(scan_settings_path);
|
|
299
|
-
if (!scan_settings)
|
|
300
|
-
throw new Error("no scan settings file found at path: " + scan_settings_path);
|
|
301
|
-
if (!scan_settings)
|
|
302
|
-
throw new Error("no wallets in scan settings");
|
|
303
|
-
const nonHaltedWallets = scan_settings.filter((wallet) => !wallet?.halted);
|
|
304
|
-
if (!nonHaltedWallets.length)
|
|
305
|
-
throw new Error("no non halted wallets in scan settings");
|
|
306
|
-
return nonHaltedWallets;
|
|
307
|
-
}
|
|
308
|
-
export function getNonHaltedWallets(scan_settings) {
|
|
309
|
-
if (!scan_settings)
|
|
310
|
-
return [];
|
|
311
|
-
const nonHaltedWallets = scan_settings.wallets.filter((wallet) => !wallet?.halted);
|
|
312
|
-
return nonHaltedWallets;
|
|
313
|
-
}
|
|
314
|
-
export async function doesScanSettingsFileExist(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
|
|
315
|
-
const scan_settings_file_content = await Bun.file(scan_settings_path)
|
|
316
|
-
.text()
|
|
317
|
-
.catch(() => "");
|
|
318
|
-
if (scan_settings_file_content.length) {
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Either 1. the consumer explicitly sets a pathprefix, we extract it from the scan_settings_path
|
|
327
|
-
* or we pick the default which is nothing
|
|
328
|
-
* @param scan_settings_path optional scan settings path
|
|
329
|
-
* @param pathPrefix optional path prefix
|
|
330
|
-
* @returns definite path prefix
|
|
331
|
-
*/
|
|
332
|
-
export function getPathPrefix(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT, pathPrefix) {
|
|
333
|
-
const parts = scan_settings_path.split("/");
|
|
334
|
-
const basename = parts.pop();
|
|
335
|
-
const dir = parts.join("/");
|
|
336
|
-
const prefix = dir ? `${dir}/` : "";
|
|
337
|
-
return pathPrefix ?? prefix;
|
|
338
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type ScanResult } from "./scanResult";
|
|
2
|
-
import type { CacheRange, ChangedOutput, ScanCache } from "./scanCache";
|
|
3
|
-
export declare function handleReorg(current_range: CacheRange, result: ScanResult, cache: ScanCache, oldRange: CacheRange): [CacheRange, ChangedOutput[]];
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { makeNewRange } from "./scanResult";
|
|
2
|
-
export function handleReorg(current_range, result, cache, oldRange) {
|
|
3
|
-
let changed_outputs = [];
|
|
4
|
-
console.log("[handleReorg] oldRange hashes:", oldRange.block_hashes.map((h) => h.block_height + ":" + h.block_hash.slice(0, 8)));
|
|
5
|
-
console.log("[handleReorg] cache outputs:", Object.entries(cache.outputs).map(([id, o]) => "h=" + o.block_height + " spent=" + (o.spent_block_height ?? "no")));
|
|
6
|
-
console.log("[handleReorg] result infos:", result.block_infos.length +
|
|
7
|
-
" blocks, first=" +
|
|
8
|
-
result.block_infos[0]?.block_height, "last=" + result.block_infos.at(-1)?.block_height);
|
|
9
|
-
// we need to check where anchor candidate is and if not found, try the same for anchor
|
|
10
|
-
// if else throw on catastrophic reorg
|
|
11
|
-
for (const block_hash of oldRange.block_hashes) {
|
|
12
|
-
const split_height_index = result.block_infos.findIndex((b) => b.block_hash === block_hash.block_hash);
|
|
13
|
-
if (!(split_height_index > 0))
|
|
14
|
-
continue;
|
|
15
|
-
console.log("[handleReorg] trying hash", block_hash.block_height, block_hash.block_hash.slice(0, 8), "found at idx", split_height_index);
|
|
16
|
-
const split_height = result.block_infos[split_height_index];
|
|
17
|
-
// still a chance to find the split height, (could be candidate_anchor or anchor)
|
|
18
|
-
if (!split_height)
|
|
19
|
-
continue;
|
|
20
|
-
// we found the split height & do the reorg
|
|
21
|
-
console.log("[handleReorg] SPLIT FOUND at height", split_height.block_height);
|
|
22
|
-
if (!cache.reorg_info) {
|
|
23
|
-
cache.reorg_info = {
|
|
24
|
-
split_heights: [split_height],
|
|
25
|
-
removed_outputs: [],
|
|
26
|
-
reverted_spends: [],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
cache.reorg_info.split_heights.push(split_height);
|
|
31
|
-
}
|
|
32
|
-
// First, collect reverted spends from all outputs (before any removals)
|
|
33
|
-
// so that outputs with block_height < split_height but spent_block_height >= split_height are captured
|
|
34
|
-
const reverted_outputs = Object.entries(cache.outputs).filter(([id, output]) => output.spent_block_height !== undefined &&
|
|
35
|
-
output.spent_block_height >= split_height.block_height);
|
|
36
|
-
const removed_outputs = Object.entries(cache.outputs).filter(([id, output]) => output.block_height >= split_height.block_height);
|
|
37
|
-
console.log("[handleReorg] removed_outputs count:", removed_outputs.length, "reverted count:", reverted_outputs.length);
|
|
38
|
-
for (const [id, old_output_state] of removed_outputs) {
|
|
39
|
-
// 1. find key_image of output to be removed (as it was reorged)
|
|
40
|
-
const [key_image] = Object.entries(cache.own_key_images).find(([own_key_image, globalid]) => globalid === id) || [""]; // if this is viewonly the key_image will be empty
|
|
41
|
-
cache.reorg_info.removed_outputs.push({
|
|
42
|
-
old_output_state,
|
|
43
|
-
key_image,
|
|
44
|
-
split_height,
|
|
45
|
-
});
|
|
46
|
-
// 2. remove from outputs and own_key_images
|
|
47
|
-
delete cache.outputs[id];
|
|
48
|
-
delete cache.own_key_images[key_image];
|
|
49
|
-
changed_outputs.push({
|
|
50
|
-
output: old_output_state,
|
|
51
|
-
change_reason: "reorged",
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
for (const [id, old_output_state_pointer] of reverted_outputs) {
|
|
55
|
-
const [key_image] = Object.entries(cache.own_key_images).find(([own_key_image, globalid]) => globalid === id) || [""]; // if this is viewonly the key_image will be empty
|
|
56
|
-
const old_output_state = Object.assign({}, old_output_state_pointer);
|
|
57
|
-
cache.reorg_info.reverted_spends.push({
|
|
58
|
-
old_output_state,
|
|
59
|
-
key_image, // in this case key_image only used here, does not get removed
|
|
60
|
-
split_height,
|
|
61
|
-
});
|
|
62
|
-
// remove spend info from original cache (if output still exists
|
|
63
|
-
// it may have been deleted above in the removed_outputs loop)
|
|
64
|
-
if (cache.outputs[id]) {
|
|
65
|
-
delete cache.outputs[id].spent_relative_index;
|
|
66
|
-
delete cache.outputs[id].spent_in_tx_hash;
|
|
67
|
-
delete cache.outputs[id].spent_block_height;
|
|
68
|
-
delete cache.outputs[id].spent_block_timestamp;
|
|
69
|
-
}
|
|
70
|
-
changed_outputs.push({
|
|
71
|
-
output: old_output_state,
|
|
72
|
-
change_reason: "reorged_spent",
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
// find current range in scanned ranges and change its end value + latest_block_hash
|
|
76
|
-
oldRange.end = split_height.block_height;
|
|
77
|
-
oldRange.block_hashes[0] = split_height;
|
|
78
|
-
// fix current_range
|
|
79
|
-
let anchor = result.block_infos.slice(-100)[0]; // if we got lots of new blocks
|
|
80
|
-
const old_anchor = oldRange.block_hashes.at(-1);
|
|
81
|
-
if (!anchor &&
|
|
82
|
-
old_anchor &&
|
|
83
|
-
split_height.block_height > old_anchor.block_height //if we did not get many new blocks + split height was candidate anchor
|
|
84
|
-
) {
|
|
85
|
-
anchor = old_anchor; // we keep the anchor the same
|
|
86
|
-
}
|
|
87
|
-
if (!anchor)
|
|
88
|
-
anchor = split_height;
|
|
89
|
-
let last_block_hash_of_result = result.block_infos.at(-1);
|
|
90
|
-
const end = last_block_hash_of_result.block_height;
|
|
91
|
-
const start = current_range.start > end ? end : current_range.start;
|
|
92
|
-
const newRange = {
|
|
93
|
-
start,
|
|
94
|
-
end,
|
|
95
|
-
block_hashes: [last_block_hash_of_result, anchor, anchor],
|
|
96
|
-
};
|
|
97
|
-
return [makeNewRange(newRange, cache), changed_outputs];
|
|
98
|
-
}
|
|
99
|
-
// we tried all the block hashes and could not find the split height
|
|
100
|
-
throw new Error("Could not find reorg split height. Most likely connected to faulty node / catastrophic reorg.");
|
|
101
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import type { LogSetting, PossibleLogs } from "../../io/logging";
|
|
2
|
-
export declare const SCAN_SETTINGS_STORE_NAME_DEFAULT = "ScanSettings.json";
|
|
3
|
-
export declare const SUB_ADDRESS_INDEX_DEFAULT_VALUE = 1;
|
|
4
|
-
export type ScanSetting = {
|
|
5
|
-
primary_address: string;
|
|
6
|
-
subaddress_index?: number;
|
|
7
|
-
halted?: boolean;
|
|
8
|
-
wallet_route?: string;
|
|
9
|
-
wallet_name?: string;
|
|
10
|
-
wallet_slot?: number;
|
|
11
|
-
};
|
|
12
|
-
export type WriteScanSettingParams = {
|
|
13
|
-
primary_address: string;
|
|
14
|
-
start_height?: number | null;
|
|
15
|
-
subaddress_index?: number;
|
|
16
|
-
halted?: boolean;
|
|
17
|
-
scan_settings_path?: string;
|
|
18
|
-
node_url?: string;
|
|
19
|
-
wallet_route?: string;
|
|
20
|
-
wallet_name?: string;
|
|
21
|
-
wallet_slot?: number;
|
|
22
|
-
logs?: LogSetting;
|
|
23
|
-
logs_include?: PossibleLogs[];
|
|
24
|
-
logs_exclude?: PossibleLogs[];
|
|
25
|
-
};
|
|
26
|
-
export type ScanSettingOpened = {
|
|
27
|
-
primary_address: string;
|
|
28
|
-
start_height: number | null;
|
|
29
|
-
node_url: string;
|
|
30
|
-
subaddress_index?: number;
|
|
31
|
-
secret_view_key?: string;
|
|
32
|
-
halted?: boolean;
|
|
33
|
-
secret_spend_key?: string;
|
|
34
|
-
wallet_route?: string;
|
|
35
|
-
wallet_name?: string;
|
|
36
|
-
wallet_slot?: number;
|
|
37
|
-
};
|
|
38
|
-
export type ScanSettings = {
|
|
39
|
-
wallets: ScanSetting[];
|
|
40
|
-
node_url: string;
|
|
41
|
-
start_height: number | null;
|
|
42
|
-
merchant_confirmations?: number | null;
|
|
43
|
-
cpu_worker_count?: number;
|
|
44
|
-
logs?: LogSetting;
|
|
45
|
-
logs_include?: PossibleLogs[];
|
|
46
|
-
logs_exclude?: PossibleLogs[];
|
|
47
|
-
};
|
|
48
|
-
export type ScanSettingsOpened = {
|
|
49
|
-
wallets: (ScanSettingOpened | undefined)[];
|
|
50
|
-
node_url: string;
|
|
51
|
-
start_height: number | null;
|
|
52
|
-
merchant_confirmations?: number | null;
|
|
53
|
-
cpu_worker_count?: number;
|
|
54
|
-
logs?: LogSetting;
|
|
55
|
-
logs_include?: PossibleLogs[];
|
|
56
|
-
logs_exclude?: PossibleLogs[];
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Writes scan settings to the default or specified storage file in json.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```
|
|
63
|
-
* const settings: ScanSettings = {
|
|
64
|
-
* wallets: [{
|
|
65
|
-
* primary_address: "5dsf...",
|
|
66
|
-
* start_height: 1741707,
|
|
67
|
-
* }],
|
|
68
|
-
* node_urls: ["https://monerooo.roooo"]
|
|
69
|
-
* };
|
|
70
|
-
* await writeScanSettings(settings);
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @param scan_settings - The complete {@link ScanSettings} configuration to persist.
|
|
74
|
-
* @param scan_settings_path - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
75
|
-
* @returns A promise that resolves when the file is successfully written.
|
|
76
|
-
* @throws Will throw if file writing fails (e.g., permissions, disk space).
|
|
77
|
-
*/
|
|
78
|
-
export declare function writeScanSettings(scan_settings: ScanSettings, scan_settings_path?: string): Promise<number>;
|
|
79
|
-
export type WriteScanSettingsFileParams = {
|
|
80
|
-
scan_settings_path?: string;
|
|
81
|
-
writeCallback: (settings: ScanSettings) => void | Promise<void>;
|
|
82
|
-
};
|
|
83
|
-
export declare function writeScanSettingsFileDefaultLocation(params: WriteScanSettingsFileParams): Promise<void>;
|
|
84
|
-
export declare function writeStartHeightToScanSettings(start_height: number | null, scan_settings_path?: string): Promise<number>;
|
|
85
|
-
export declare function writeDaemonHeightAsStartHeightToScanSettings(node_url: string, scan_settings_path?: string): Promise<number>;
|
|
86
|
-
export declare function cullTooLargeScanHeight(node_url: string, scan_settings_path?: string): Promise<number>;
|
|
87
|
-
export declare function writeNodeUrlToScanSettings(node_url: string, scan_settings_path?: string): Promise<number>;
|
|
88
|
-
export declare function readNodeUrlFromScanSettings(scan_settings_path?: string): Promise<string | undefined>;
|
|
89
|
-
/**
|
|
90
|
-
* Writes the merchant confirmation threshold to scan settings.
|
|
91
|
-
*
|
|
92
|
-
* This setting only has effect when the wallet is run as part of a checkout system,
|
|
93
|
-
* that accepts payments.
|
|
94
|
-
* It determines after how many confirmations a transaction is accepted
|
|
95
|
-
* for a payment. The actual enforcement of this policy is left to the
|
|
96
|
-
* custom payment-system code that consumes this library.
|
|
97
|
-
*
|
|
98
|
-
* @param merchant_confirmations - Number of confirmations required before
|
|
99
|
-
* accepting a payment, or `null` to leave it unset.
|
|
100
|
-
* @param scan_settings_path - Optional path for the settings file.
|
|
101
|
-
* Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
102
|
-
* @returns A promise that resolves when the file is successfully written.
|
|
103
|
-
*/
|
|
104
|
-
export declare function writeMerchantConfirmationsToScanSettings(merchant_confirmations: number | null, scan_settings_path?: string): Promise<number>;
|
|
105
|
-
/**
|
|
106
|
-
* Reads the merchant confirmation threshold from scan settings.
|
|
107
|
-
*
|
|
108
|
-
* This setting only has effect when the wallet is run as part of a checkout system,
|
|
109
|
-
* that accepts payments.
|
|
110
|
-
*
|
|
111
|
-
* It determines after how many confirmations a transaction is accepted
|
|
112
|
-
* for a payment. The actual enforcement of this policy is left to the
|
|
113
|
-
* custom payment-system code that consumes this library.
|
|
114
|
-
*
|
|
115
|
-
* @param scan_settings_path - Optional path for the settings file.
|
|
116
|
-
* Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
117
|
-
* @returns The configured number of confirmations, null, or `undefined`
|
|
118
|
-
* if the setting has not been persisted yet.
|
|
119
|
-
*/
|
|
120
|
-
export declare function readMerchantConfirmationsFromScanSettings(scan_settings_path?: string): Promise<number | null | undefined>;
|
|
121
|
-
/**
|
|
122
|
-
* Reads scan settings from the default or specified storage file.
|
|
123
|
-
* secret_view_key and spend_private_key are read from environment variables
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```
|
|
127
|
-
* const settings = await readScanSettings();
|
|
128
|
-
* if (settings) {
|
|
129
|
-
* console.log(settings.wallets?.primary_address);
|
|
130
|
-
* }
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* @param scan_settings_path - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
|
|
134
|
-
* @returns The parsed {@link ScanSettings} object if file exists and is valid JSON, otherwise `undefined`.
|
|
135
|
-
*/
|
|
136
|
-
export declare function readScanSettings(scan_settings_path?: string): Promise<ScanSettingsOpened | undefined>;
|
|
137
|
-
export declare function readPrivateSpendKeyFromEnv(primary_address: string): string | undefined;
|
|
138
|
-
export declare function readPrivateViewKeyFromEnv(primary_address: string): string | undefined;
|
|
139
|
-
export declare function readWalletFromScanSettings(primary_address: string, scan_settings_path?: string): Promise<ScanSettingOpened | undefined>;
|
|
140
|
-
export declare function readWalletsFromScanSettings(scan_settings_path?: string): Promise<ScanSettingOpened[]>;
|
|
141
|
-
export declare function walletSettingsPlusKeys(wallet_settings: ScanSettingOpened, secret_view_key?: string, secret_spend_key?: string): Promise<{
|
|
142
|
-
secret_view_key: string;
|
|
143
|
-
secret_spend_key: string | undefined;
|
|
144
|
-
primary_address: string;
|
|
145
|
-
start_height: number | null;
|
|
146
|
-
node_url: string;
|
|
147
|
-
subaddress_index?: number;
|
|
148
|
-
halted?: boolean;
|
|
149
|
-
wallet_route?: string;
|
|
150
|
-
wallet_name?: string;
|
|
151
|
-
wallet_slot?: number;
|
|
152
|
-
}>;
|
|
153
|
-
export declare function writeWalletToScanSettings(params: WriteScanSettingParams): Promise<number>;
|
|
154
|
-
export declare function openScanSettingsFile(scan_settings_path?: string): Promise<ScanSettings | undefined>;
|
|
155
|
-
export declare function openNonHaltedWallets(scan_settings_path?: string): Promise<ScanSettingOpened[]>;
|
|
156
|
-
export declare function getNonHaltedWallets(scan_settings?: ScanSettings): ScanSetting[];
|
|
157
|
-
export declare function doesScanSettingsFileExist(scan_settings_path?: string): Promise<boolean>;
|
|
158
|
-
/**
|
|
159
|
-
* Either 1. the consumer explicitly sets a pathprefix, we extract it from the scan_settings_path
|
|
160
|
-
* or we pick the default which is nothing
|
|
161
|
-
* @param scan_settings_path optional scan settings path
|
|
162
|
-
* @param pathPrefix optional path prefix
|
|
163
|
-
* @returns definite path prefix
|
|
164
|
-
*/
|
|
165
|
-
export declare function getPathPrefix(scan_settings_path?: string, pathPrefix?: string): string;
|