@spirobel/monero-wallet-api 0.6.1 → 0.6.2
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/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 +2 -2
- 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 +1 -1
- package/dist/scansettings/scanSettingsOpened.js +1 -1
- 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,72 +0,0 @@
|
|
|
1
|
-
import { WasmProcessor } from "../wasm-processing/wasmProcessor";
|
|
2
|
-
export type DkgGetPublicKeyResult = {
|
|
3
|
-
dkg_public_key: string;
|
|
4
|
-
};
|
|
5
|
-
export type DkgParticipateParams = {
|
|
6
|
-
dkg_secret_key: string;
|
|
7
|
-
context: string;
|
|
8
|
-
dkg_public_keys: string[];
|
|
9
|
-
t: number;
|
|
10
|
-
};
|
|
11
|
-
export type DkgParticipateResult = {
|
|
12
|
-
participation: string;
|
|
13
|
-
};
|
|
14
|
-
export type DkgVerifyParams = {
|
|
15
|
-
dkg_secret_key: string;
|
|
16
|
-
context: string;
|
|
17
|
-
t: number;
|
|
18
|
-
dkg_public_keys: string[];
|
|
19
|
-
participations: Record<string, string>;
|
|
20
|
-
};
|
|
21
|
-
export type DkgVerifyValidResult = {
|
|
22
|
-
group_key: string;
|
|
23
|
-
t: number;
|
|
24
|
-
n: number;
|
|
25
|
-
};
|
|
26
|
-
export type DkgVerifyInvalidResult = {
|
|
27
|
-
faulty_participants: number[];
|
|
28
|
-
};
|
|
29
|
-
export type DkgVerifyNotEnoughResult = {
|
|
30
|
-
message: "NotEnoughParticipants";
|
|
31
|
-
};
|
|
32
|
-
export type DkgVerifyResult = DkgVerifyValidResult | DkgVerifyInvalidResult | DkgVerifyNotEnoughResult;
|
|
33
|
-
export type DkgErrorResponse = {
|
|
34
|
-
message: string;
|
|
35
|
-
};
|
|
36
|
-
export declare class DistributedKeyGenerator extends WasmProcessor {
|
|
37
|
-
/**
|
|
38
|
-
* set up a distributed key generator with t threshold and n total participants
|
|
39
|
-
* @param t - total number of multisig participants
|
|
40
|
-
* @param n - threshold to sign a transaction
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
static create(t: number, n: number): Promise<DistributedKeyGenerator>;
|
|
44
|
-
/**
|
|
45
|
-
* setupGenerators
|
|
46
|
-
* configure the max threshold and max participants for the DKG generators.
|
|
47
|
-
* if never called, defaults to 16, 16 used automatically on first DKG operation.
|
|
48
|
-
*/
|
|
49
|
-
setupGenerators(t: number, n: number): void;
|
|
50
|
-
/**
|
|
51
|
-
* derive the DKG public key from a 64-byte DKG secret key.
|
|
52
|
-
*
|
|
53
|
-
* @param dkgSecretKeyBytes 64-byte DKG secret key (from seed function)
|
|
54
|
-
* @returns the DKG public key as a hex string, or an error object
|
|
55
|
-
*/
|
|
56
|
-
getPublicKey(dkgSecretKeyBytes: Uint8Array): DkgGetPublicKeyResult | DkgErrorResponse;
|
|
57
|
-
/**
|
|
58
|
-
* participate in a DKG round.
|
|
59
|
-
*
|
|
60
|
-
* @param params dkg_secret_key as 64-byte hex string, context, dkg_public_keys array (length is n implicitly), t (threshold)
|
|
61
|
-
* @returns The participation message as hex, or an error object
|
|
62
|
-
*/
|
|
63
|
-
participate(params: DkgParticipateParams): DkgParticipateResult | DkgErrorResponse;
|
|
64
|
-
/**
|
|
65
|
-
* verify DKG participations and extract the group key.
|
|
66
|
-
*
|
|
67
|
-
* @param params dkg_secret_key as 64-byte hex string, context, t (threshold), dkg_public_keys array (length is n implicitly),
|
|
68
|
-
* participations [ paricipant index -> hex participation message ]
|
|
69
|
-
* @returns The group key and params, faulty participants, not-enough message, or error
|
|
70
|
-
*/
|
|
71
|
-
verify(params: DkgVerifyParams): DkgVerifyResult | DkgErrorResponse;
|
|
72
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { frost_dkg_wasm } from "../wasm-processing/wasmFile";
|
|
2
|
-
import { WasmProcessor } from "../wasm-processing/wasmProcessor";
|
|
3
|
-
export class DistributedKeyGenerator extends WasmProcessor {
|
|
4
|
-
/**
|
|
5
|
-
* set up a distributed key generator with t threshold and n total participants
|
|
6
|
-
* @param t - total number of multisig participants
|
|
7
|
-
* @param n - threshold to sign a transaction
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
static async create(t, n) {
|
|
11
|
-
const dkg = new DistributedKeyGenerator();
|
|
12
|
-
await dkg.initWasmModule(frost_dkg_wasm);
|
|
13
|
-
dkg.setupGenerators(t, n);
|
|
14
|
-
return dkg;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* setupGenerators
|
|
18
|
-
* configure the max threshold and max participants for the DKG generators.
|
|
19
|
-
* if never called, defaults to 16, 16 used automatically on first DKG operation.
|
|
20
|
-
*/
|
|
21
|
-
setupGenerators(t, n) {
|
|
22
|
-
//@ts-ignore
|
|
23
|
-
this.tinywasi.instance.exports.setup_generators(t, n);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* derive the DKG public key from a 64-byte DKG secret key.
|
|
27
|
-
*
|
|
28
|
-
* @param dkgSecretKeyBytes 64-byte DKG secret key (from seed function)
|
|
29
|
-
* @returns the DKG public key as a hex string, or an error object
|
|
30
|
-
*/
|
|
31
|
-
getPublicKey(dkgSecretKeyBytes) {
|
|
32
|
-
// set up write callback: rust will call input(64) to read the secret key bytes
|
|
33
|
-
this.writeToWasmMemory = (ptr, len) => {
|
|
34
|
-
this.writeArray(ptr, len, dkgSecretKeyBytes);
|
|
35
|
-
};
|
|
36
|
-
// set up read callback: rust will call output_string() to return the result JSON
|
|
37
|
-
let result;
|
|
38
|
-
this.readFromWasmMemory = (ptr, len) => {
|
|
39
|
-
result = JSON.parse(this.readString(ptr, len));
|
|
40
|
-
};
|
|
41
|
-
//@ts-ignore
|
|
42
|
-
this.tinywasi.instance.exports.dkg_get_public_key();
|
|
43
|
-
if (!result) {
|
|
44
|
-
return { message: "No response from dkg_get_public_key" };
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* participate in a DKG round.
|
|
50
|
-
*
|
|
51
|
-
* @param params dkg_secret_key as 64-byte hex string, context, dkg_public_keys array (length is n implicitly), t (threshold)
|
|
52
|
-
* @returns The participation message as hex, or an error object
|
|
53
|
-
*/
|
|
54
|
-
participate(params) {
|
|
55
|
-
const jsonStr = JSON.stringify(params);
|
|
56
|
-
// set up write callback: rust will call input_string(json_len) to read the JSON
|
|
57
|
-
this.writeToWasmMemory = (ptr, len) => {
|
|
58
|
-
this.writeString(ptr, len, jsonStr);
|
|
59
|
-
};
|
|
60
|
-
// set up read callback: rust will call output_string() to return the result JSON
|
|
61
|
-
let result;
|
|
62
|
-
this.readFromWasmMemory = (ptr, len) => {
|
|
63
|
-
result = JSON.parse(this.readString(ptr, len));
|
|
64
|
-
};
|
|
65
|
-
//@ts-ignore
|
|
66
|
-
this.tinywasi.instance.exports.dkg_participate(jsonStr.length);
|
|
67
|
-
if (!result) {
|
|
68
|
-
return { message: "No response from dkg_participate" };
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* verify DKG participations and extract the group key.
|
|
74
|
-
*
|
|
75
|
-
* @param params dkg_secret_key as 64-byte hex string, context, t (threshold), dkg_public_keys array (length is n implicitly),
|
|
76
|
-
* participations [ paricipant index -> hex participation message ]
|
|
77
|
-
* @returns The group key and params, faulty participants, not-enough message, or error
|
|
78
|
-
*/
|
|
79
|
-
verify(params) {
|
|
80
|
-
const jsonStr = JSON.stringify(params);
|
|
81
|
-
// set up write callback: rust will call input_string(json_len) to read the JSON
|
|
82
|
-
this.writeToWasmMemory = (ptr, len) => {
|
|
83
|
-
this.writeString(ptr, len, jsonStr);
|
|
84
|
-
};
|
|
85
|
-
// set up read callback: rust will call output_string() to return the result JSON
|
|
86
|
-
let result;
|
|
87
|
-
this.readFromWasmMemory = (ptr, len) => {
|
|
88
|
-
result = JSON.parse(this.readString(ptr, len));
|
|
89
|
-
};
|
|
90
|
-
//@ts-ignore
|
|
91
|
-
this.tinywasi.instance.exports.dkg_verify(jsonStr.length);
|
|
92
|
-
if (!result) {
|
|
93
|
-
return { message: "No response from dkg_verify" };
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* content-script-safe 002 surface (no scansettings / atomicWrite / indexedDB).
|
|
3
|
-
*/
|
|
4
|
-
import { type ToolInvocationValidity } from "../globals";
|
|
5
|
-
import type { ToolInvocationForValidate } from "../toolArm";
|
|
6
|
-
export type CreateAndShareViewOnlyWalletTool = {
|
|
7
|
-
tool_id: "002";
|
|
8
|
-
payload: CreateAndShareViewOnlyWalletToolPayload;
|
|
9
|
-
};
|
|
10
|
-
export type CreateAndShareViewOnlyWalletToolPayload = {
|
|
11
|
-
wallet_slot: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function parseCreateAndShareViewOnlyWalletToolArgs(args: string[]): CreateAndShareViewOnlyWalletTool | null;
|
|
14
|
-
export declare function createCreateAndShareViewOnlyWalletToolLink(wallet_slot?: number): string;
|
|
15
|
-
export declare function make002ToolLink(wallet_slot?: number): string;
|
|
16
|
-
export declare function makeFromPayload(payload: CreateAndShareViewOnlyWalletToolPayload): string;
|
|
17
|
-
export declare function validate(invo: ToolInvocationForValidate): ToolInvocationValidity;
|
|
18
|
-
export type ShareViewkeyPayload = {
|
|
19
|
-
viewkey: string;
|
|
20
|
-
primary_address: string;
|
|
21
|
-
tool_invo: {
|
|
22
|
-
tool: {
|
|
23
|
-
tool_id: string;
|
|
24
|
-
payload: {
|
|
25
|
-
wallet_slot: number;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
found_in: "link" | "linkText";
|
|
29
|
-
link: string;
|
|
30
|
-
linkText: string;
|
|
31
|
-
valid: ToolInvocationValidity;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
export type ShareViewkeyResult = {
|
|
35
|
-
ok: boolean;
|
|
36
|
-
successUrl: string | null;
|
|
37
|
-
error?: string;
|
|
38
|
-
};
|
|
39
|
-
export type ShareViewkey002Pruned = {
|
|
40
|
-
viewkey: string;
|
|
41
|
-
primary_address: string;
|
|
42
|
-
wallet_slot: number;
|
|
43
|
-
};
|
|
44
|
-
export declare function shareViewKey002(payload: ShareViewkeyPayload): Promise<ShareViewkeyResult>;
|
|
45
|
-
export declare function potentialSuccessRedirect002(payload: ShareViewkeyPayload): Promise<ShareViewkeyResult | undefined>;
|
|
46
|
-
export declare function afterValidate(invo: ToolInvocationForValidate): void;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* content-script-safe 002 surface (no scansettings / atomicWrite / indexedDB).
|
|
3
|
-
*/
|
|
4
|
-
import { TOOL_MAGIC_STRING, } from "../globals";
|
|
5
|
-
export function parseCreateAndShareViewOnlyWalletToolArgs(args) {
|
|
6
|
-
const wallet_slot = args[5];
|
|
7
|
-
if (wallet_slot && !isNaN(parseInt(wallet_slot))) {
|
|
8
|
-
return {
|
|
9
|
-
tool_id: "002",
|
|
10
|
-
payload: {
|
|
11
|
-
wallet_slot: parseInt(wallet_slot),
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
export function createCreateAndShareViewOnlyWalletToolLink(wallet_slot) {
|
|
18
|
-
wallet_slot = Number(wallet_slot) || 0;
|
|
19
|
-
return `${TOOL_MAGIC_STRING}002_create_and_share_viewkey_slot_${wallet_slot}`;
|
|
20
|
-
}
|
|
21
|
-
export function make002ToolLink(wallet_slot) {
|
|
22
|
-
return createCreateAndShareViewOnlyWalletToolLink(wallet_slot);
|
|
23
|
-
}
|
|
24
|
-
export function makeFromPayload(payload) {
|
|
25
|
-
return createCreateAndShareViewOnlyWalletToolLink(payload.wallet_slot);
|
|
26
|
-
}
|
|
27
|
-
export function validate(invo) {
|
|
28
|
-
if (invo.tool.tool_id !== "002")
|
|
29
|
-
return "unverified";
|
|
30
|
-
if (invo.context_domain == invo.destination_domain)
|
|
31
|
-
return "valid";
|
|
32
|
-
return "invalid";
|
|
33
|
-
}
|
|
34
|
-
export async function shareViewKey002(payload) {
|
|
35
|
-
const invo = payload.tool_invo;
|
|
36
|
-
if (invo.tool.tool_id !== "002")
|
|
37
|
-
return {
|
|
38
|
-
ok: false,
|
|
39
|
-
successUrl: null,
|
|
40
|
-
};
|
|
41
|
-
if (invo.valid !== "valid")
|
|
42
|
-
return {
|
|
43
|
-
ok: false,
|
|
44
|
-
successUrl: null,
|
|
45
|
-
};
|
|
46
|
-
const link = invo[invo.found_in];
|
|
47
|
-
const invo_link = new URL(link);
|
|
48
|
-
const shareVKUrl = `${invo_link.origin}/monerochan002/`;
|
|
49
|
-
try {
|
|
50
|
-
const result = await fetch(shareVKUrl, {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: { "Content-Type": "application/json" },
|
|
53
|
-
body: JSON.stringify({
|
|
54
|
-
viewkey: payload.viewkey,
|
|
55
|
-
primary_address: payload.primary_address,
|
|
56
|
-
wallet_slot: invo.tool.payload.wallet_slot,
|
|
57
|
-
}),
|
|
58
|
-
});
|
|
59
|
-
if (result.ok) {
|
|
60
|
-
const data = (await result.json());
|
|
61
|
-
if (data && typeof data === "object" && "ok" in data && data.ok === true) {
|
|
62
|
-
return {
|
|
63
|
-
ok: true,
|
|
64
|
-
successUrl: data.successUrl ?? null,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
ok: false,
|
|
69
|
-
successUrl: null,
|
|
70
|
-
error: "counterparty rejected share",
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
ok: false,
|
|
75
|
-
successUrl: null,
|
|
76
|
-
error: `share post failed ${result.status}`,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
return {
|
|
81
|
-
ok: false,
|
|
82
|
-
successUrl: null,
|
|
83
|
-
error: e instanceof Error ? e.message : String(e),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
export async function potentialSuccessRedirect002(payload) {
|
|
88
|
-
const shareVKresult = await shareViewKey002(payload);
|
|
89
|
-
if (shareVKresult.ok && shareVKresult.successUrl) {
|
|
90
|
-
window.location.href = shareVKresult.successUrl;
|
|
91
|
-
window.location.reload();
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return shareVKresult;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
export function afterValidate(invo) {
|
|
98
|
-
const g = globalThis;
|
|
99
|
-
const rt = g.browser?.runtime ?? g.chrome?.runtime;
|
|
100
|
-
if (!rt)
|
|
101
|
-
return;
|
|
102
|
-
const port = rt.connect({ name: invo.invocation_id });
|
|
103
|
-
port.onMessage.addListener((msg) => {
|
|
104
|
-
const m = msg;
|
|
105
|
-
const k = m.kind ?? m.type;
|
|
106
|
-
if (k !== "shareViewkey" || !m.payload)
|
|
107
|
-
return;
|
|
108
|
-
void (async () => {
|
|
109
|
-
try {
|
|
110
|
-
const result = await potentialSuccessRedirect002(m.payload);
|
|
111
|
-
if (result) {
|
|
112
|
-
rt.sendMessage({
|
|
113
|
-
kind: "shareViewkeyFAILED",
|
|
114
|
-
payload: { ...m.payload, error: result.error },
|
|
115
|
-
}).catch(() => { });
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
rt.sendMessage({
|
|
119
|
-
kind: "shareViewkeyOK",
|
|
120
|
-
payload: { invocationId: invo.invocation_id },
|
|
121
|
-
}).catch(() => { });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
rt.sendMessage({
|
|
126
|
-
kind: "shareViewkeyFAILED",
|
|
127
|
-
payload: {
|
|
128
|
-
...m.payload,
|
|
129
|
-
error: e instanceof Error ? e.message : String(e),
|
|
130
|
-
},
|
|
131
|
-
}).catch(() => { });
|
|
132
|
-
}
|
|
133
|
-
})();
|
|
134
|
-
});
|
|
135
|
-
}
|