@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.
Files changed (108) hide show
  1. package/README.md +40 -4
  2. package/dist/actionlog/actionLogOpened.js +7 -2
  3. package/dist/frost_dkg.wasm +0 -0
  4. package/dist/io/logging.js +1 -1
  5. package/dist/keypairs-seeds/keypairs.js +5 -5
  6. package/dist/monero_wallet_api.wasm +0 -0
  7. package/dist/multisig/DistributedKeyGenerator.js +3 -3
  8. package/dist/multisig/MultiSigTxSigner.js +2 -2
  9. package/dist/multisig/escrow.js +1 -1
  10. package/dist/multisig/multisig.js +4 -0
  11. package/dist/node-interaction/binaryEndpoints.d.ts +3 -3
  12. package/dist/node-interaction/nodeUrl.js +2 -2
  13. package/dist/scanning-syncing/backgroundWorker.d.ts +3 -0
  14. package/dist/scanning-syncing/backgroundWorker.js +38 -8
  15. package/dist/scanning-syncing/blocksbuffer/blocksBufferFetchLoop.d.ts +1 -1
  16. package/dist/scanning-syncing/blocksbuffer/blocksBufferFetchLoop.js +1 -1
  17. package/dist/scanning-syncing/blocksbuffer/blocksbufferCoordination.d.ts +1 -1
  18. package/dist/scanning-syncing/blocksbuffer/blocksbufferCoordination.js +1 -1
  19. package/dist/scanning-syncing/connectionStatus.d.ts +1 -1
  20. package/dist/scanning-syncing/connectionStatus.js +2 -2
  21. package/dist/scanning-syncing/openWallet.js +1 -1
  22. package/dist/scanning-syncing/scanresult/computeKeyImage.d.ts +1 -1
  23. package/dist/scanning-syncing/scanresult/computeKeyImage.js +2 -2
  24. package/dist/scanning-syncing/scanresult/scanCache.d.ts +1 -1
  25. package/dist/scanning-syncing/scanresult/scanCache.js +1 -1
  26. package/dist/scanning-syncing/scanresult/scanCacheOpened.d.ts +1 -1
  27. package/dist/scanning-syncing/scanresult/scanCacheOpened.js +33 -16
  28. package/dist/scanning-syncing/scanresult/scanCoordination.d.ts +2 -2
  29. package/dist/scanning-syncing/scanresult/scanCoordination.js +2 -2
  30. package/dist/scanning-syncing/scanresult/scanLoop.d.ts +1 -1
  31. package/dist/scanning-syncing/scanresult/scanLoop.js +1 -1
  32. package/dist/scanning-syncing/scanresult/scanResult.d.ts +1 -1
  33. package/dist/scanning-syncing/scanresult/scanResult.js +3 -3
  34. package/dist/scanning-syncing/scanresult/scanStats.d.ts +1 -1
  35. package/dist/scanning-syncing/scanresult/scanStats.js +1 -2
  36. package/dist/scanning-syncing/worker-entrypoints/worker.js +1 -1
  37. package/dist/scanning-syncing/worker-mains/cpubound-main.js +1 -1
  38. package/dist/scanning-syncing/worker-mains/multisig-main.d.ts +1 -1
  39. package/dist/scanning-syncing/worker-mains/multisig-main.js +1 -1
  40. package/dist/scanning-syncing/worker-mains/worker.js +9 -1
  41. package/dist/scansettings/scanSettings.js +1 -1
  42. package/dist/scansettings/scanSettingsOpened.d.ts +2 -1
  43. package/dist/scansettings/scanSettingsOpened.js +13 -6
  44. package/dist/send-functionality/inputSelection.d.ts +1 -1
  45. package/dist/send-functionality/transactionBuilding.d.ts +1 -1
  46. package/dist/send-functionality/transactionBuilding.js +3 -3
  47. package/dist/viewpair/ViewPair.d.ts +4 -4
  48. package/dist/viewpair/ViewPair.js +4 -4
  49. package/dist/wasm-processing/wasmLoader.d.ts +10 -0
  50. package/dist/wasm-processing/wasmLoader.js +108 -0
  51. package/dist/worker_unpacked.js +14055 -0
  52. package/dist/xmr3.d.ts +1 -39
  53. package/dist/xmr3.js +10 -37
  54. package/dist/xmr3_common.d.ts +39 -0
  55. package/dist/xmr3_common.js +37 -0
  56. package/dist/xmr3_unpacked.d.ts +9 -0
  57. package/dist/xmr3_unpacked.js +14 -0
  58. package/package.json +9 -2
  59. package/dist/actionlog/actionLog.d.ts +0 -4
  60. package/dist/actionlog/actionLog.js +0 -9
  61. package/dist/actionlog/backend/jsonlBackend.d.ts +0 -19
  62. package/dist/actionlog/backend/jsonlBackend.js +0 -110
  63. package/dist/actionlog/backend/memoryBackend.d.ts +0 -11
  64. package/dist/actionlog/backend/memoryBackend.js +0 -31
  65. package/dist/actionlog/backend.d.ts +0 -12
  66. package/dist/actionlog/backend.js +0 -1
  67. package/dist/actionlog/idbBackend.d.ts +0 -19
  68. package/dist/actionlog/idbBackend.js +0 -98
  69. package/dist/actionlog/jsonlBackend.d.ts +0 -19
  70. package/dist/actionlog/jsonlBackend.js +0 -75
  71. package/dist/actionlog/memoryBackend.d.ts +0 -14
  72. package/dist/actionlog/memoryBackend.js +0 -38
  73. package/dist/actionlog/openMaps.d.ts +0 -11
  74. package/dist/actionlog/openMaps.js +0 -32
  75. package/dist/actionlog/sqliteBackend.d.ts +0 -18
  76. package/dist/actionlog/sqliteBackend.js +0 -105
  77. package/dist/actionlog/toolContext.d.ts +0 -36
  78. package/dist/actionlog/toolContext.js +0 -1
  79. package/dist/actionlog/types.d.ts +0 -62
  80. package/dist/actionlog/types.js +0 -62
  81. package/dist/scanning-syncing/blocksbuffer/getBlocksbinBuffer.d.ts +0 -28
  82. package/dist/scanning-syncing/blocksbuffer/getBlocksbinBuffer.js +0 -54
  83. package/dist/scanning-syncing/scanSettings.d.ts +0 -165
  84. package/dist/scanning-syncing/scanSettings.js +0 -338
  85. package/dist/scanning-syncing/scanresult/reorg.d.ts +0 -3
  86. package/dist/scanning-syncing/scanresult/reorg.js +0 -101
  87. package/dist/scanning-syncing/scansettings/scanSettings.d.ts +0 -165
  88. package/dist/scanning-syncing/scansettings/scanSettings.js +0 -338
  89. package/dist/send-functionality/multisig.d.ts +0 -72
  90. package/dist/send-functionality/multisig.js +0 -97
  91. package/dist/tools/calls/002-content.d.ts +0 -46
  92. package/dist/tools/calls/002-content.js +0 -135
  93. package/dist/tools/calls/002-fail-cleanup.d.ts +0 -27
  94. package/dist/tools/calls/002-fail-cleanup.js +0 -60
  95. package/dist/tools/counterparty.d.ts +0 -3
  96. package/dist/tools/counterparty.js +0 -1
  97. package/dist/tools/monero-tools-content.d.ts +0 -29
  98. package/dist/tools/monero-tools-content.js +0 -80
  99. package/dist/tools/runtimeMessages.d.ts +0 -4
  100. package/dist/tools/runtimeMessages.js +0 -18
  101. package/dist/tools/toolActionLogContext.d.ts +0 -33
  102. package/dist/tools/toolActionLogContext.js +0 -1
  103. package/dist/tools/toolArm.d.ts +0 -47
  104. package/dist/tools/toolArm.js +0 -1
  105. package/dist/tools/ui.d.ts +0 -2
  106. package/dist/tools/ui.js +0 -1
  107. package/dist/tools/worker.d.ts +0 -1
  108. package/dist/tools/worker.js +0 -1
@@ -1,4 +1,4 @@
1
- import { sleep, ViewPair } from "../../xmr3";
1
+ import { sleep, ViewPair } from "../../xmr3_common";
2
2
  import { log } from "../../io/logging";
3
3
  import {} from "../scanresult/scanLoop";
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { DistributedKeyGenerator, type DkgParticipateParams, type DkgVerifyParams } from "../../xmr3";
1
+ import { DistributedKeyGenerator, type DkgParticipateParams, type DkgVerifyParams } from "../../xmr3_common";
2
2
  export type MultiSigParticipateCall = {
3
3
  type: "multisig-call";
4
4
  functionName: "participate";
@@ -1,4 +1,4 @@
1
- import { DistributedKeyGenerator, } from "../../xmr3";
1
+ import { DistributedKeyGenerator, } from "../../xmr3_common";
2
2
  import { log } from "../../io/logging";
3
3
  export function multisigMainWorkerCall(msg, dkg) {
4
4
  if (!dkg) {
@@ -2,7 +2,12 @@ import { coordinatorMainWorker, requestCoordinatorShutdown, } from "./coordinato
2
2
  import { handleCpuboundScanTry, sendFromCpuWorker } from "./cpubound-main";
3
3
  import { log, setupLoggingPath } from "../../io/logging";
4
4
  import { multisigMainWorkerCall } from "./multisig-main";
5
- import { DistributedKeyGenerator, SCAN_SETTINGS_STORE_NAME_DEFAULT, } from "../../xmr3";
5
+ import { DistributedKeyGenerator, SCAN_SETTINGS_STORE_NAME_DEFAULT, } from "../../xmr3_common";
6
+ import { monero_wallet_api_wasm, frost_dkg_wasm } from "../../wasm-processing/wasmFile";
7
+ import { setInlineWasm, setWasmUrls } from "../../wasm-processing/wasmLoader";
8
+ // packed worker bundle has inlined bytes, unpacked has empty bytes
9
+ // setInlineWasm ignores empty input
10
+ setInlineWasm(monero_wallet_api_wasm, frost_dkg_wasm);
6
11
  self.onerror = (e) => self.postMessage({ type: "ERROR", payload: e });
7
12
  self.addEventListener("unhandledrejection", (e) => self.postMessage({ type: "ERROR", payload: e.reason }));
8
13
  let SCAN_SETTINGS_PATH;
@@ -77,6 +82,9 @@ const handleMessage = async (e) => {
77
82
  return;
78
83
  }
79
84
  if (msg.type === "setup") {
85
+ if (msg.moneroWasmUrl || msg.dkgWasmUrl) {
86
+ setWasmUrls({ monero: msg.moneroWasmUrl, dkg: msg.dkgWasmUrl });
87
+ }
80
88
  const settingsPath = msg.scan_settings_path || SCAN_SETTINGS_STORE_NAME_DEFAULT;
81
89
  SCAN_SETTINGS_PATH = settingsPath;
82
90
  PATH_PREFIX = msg.pathPrefix;
@@ -1,4 +1,4 @@
1
- import { get_info } from "../xmr3";
1
+ import { get_info } from "../xmr3_common";
2
2
  import { atomicWrite } from "../io/atomicWrite";
3
3
  import { refreshEnvIndexedDB } from "../io/indexedDB";
4
4
  import { LOCAL_NODE_DEFAULT_URL } from "../node-interaction/nodeUrl";
@@ -1,5 +1,5 @@
1
1
  import { type LogSetting, type PossibleLogs } from "../io/logging";
2
- import { type ScanSetting, type ScanSettingOpened } from "../xmr3";
2
+ import { type ScanSetting, type ScanSettingOpened } from "../xmr3_common";
3
3
  export declare class ScanSettingsOpened {
4
4
  private _scan_settings_path;
5
5
  private _pathPrefix;
@@ -20,6 +20,7 @@ export declare class ScanSettingsOpened {
20
20
  get pathPrefix(): string;
21
21
  setNodeUrl(node_url: string): Promise<void>;
22
22
  setStartHeight(start_height: number | null): Promise<void>;
23
+ setNodeUrlAndStartHeight(node_url?: string, start_height?: number | null): Promise<void>;
23
24
  setMerchantConfirmations(merchant_confirmations: number | undefined | null): Promise<void>;
24
25
  setCpuWorkerCount(cpu_worker_count: number | undefined | null): Promise<void>;
25
26
  setLogSettings(logs?: LogSetting | null, logs_include?: PossibleLogs[] | null, logs_exclude?: PossibleLogs[] | null): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { LOCAL_NODE_DEFAULT_URL } from "../node-interaction/nodeUrl";
2
2
  import { LOGGING_FUNCTIONS, } from "../io/logging";
3
- import { getPathPrefix, makeSpendKeyFromSeed, makeViewKey, openScanSettingsFile, parseAddress, SCAN_SETTINGS_STORE_NAME_DEFAULT, SUB_ADDRESS_INDEX_DEFAULT_VALUE, walletSettingsPlusKeys, writeEnvLineToDotEnvRefresh, writeScanSettings, writeViewKeyToDotEnv, } from "../xmr3";
3
+ import { getPathPrefix, makeSpendKeyFromSeed, makeViewKey, openScanSettingsFile, parseAddress, SCAN_SETTINGS_STORE_NAME_DEFAULT, SUB_ADDRESS_INDEX_DEFAULT_VALUE, walletSettingsPlusKeys, writeEnvLineToDotEnvRefresh, writeScanSettings, writeViewKeyToDotEnv, } from "../xmr3_common";
4
4
  export class ScanSettingsOpened {
5
5
  _scan_settings_path;
6
6
  _pathPrefix;
@@ -54,14 +54,21 @@ export class ScanSettingsOpened {
54
54
  return this._pathPrefix;
55
55
  }
56
56
  async setNodeUrl(node_url) {
57
- await this.reload();
58
- this._settings.node_url = ScanSettingsOpened._validateNodeUrl(node_url);
59
- await this._persist();
57
+ await this.setNodeUrlAndStartHeight(node_url, undefined);
60
58
  }
61
59
  async setStartHeight(start_height) {
60
+ await this.setNodeUrlAndStartHeight(undefined, start_height);
61
+ }
62
+ // one read and one write. a second reload must not put the old url back.
63
+ async setNodeUrlAndStartHeight(node_url, start_height) {
62
64
  await this.reload();
63
- ScanSettingsOpened._validateStartHeight(start_height);
64
- this._settings.start_height = start_height;
65
+ if (node_url !== undefined) {
66
+ this._settings.node_url = ScanSettingsOpened._validateNodeUrl(node_url);
67
+ }
68
+ if (start_height !== undefined) {
69
+ ScanSettingsOpened._validateStartHeight(start_height);
70
+ this._settings.start_height = start_height;
71
+ }
65
72
  await this._persist();
66
73
  }
67
74
  async setMerchantConfirmations(merchant_confirmations) {
@@ -1,4 +1,4 @@
1
- import type { GetOutsResponseBuffer, NodeUrl, Output } from "../xmr3";
1
+ import type { GetOutsResponseBuffer, NodeUrl, Output } from "../xmr3_common";
2
2
  import type { SampledDecoys } from "./transactionBuilding";
3
3
  export type Payment = {
4
4
  address: string;
@@ -1,4 +1,4 @@
1
- import type { GetFeeEstimateResult, Output } from "../xmr3";
1
+ import type { GetFeeEstimateResult, Output } from "../xmr3_common";
2
2
  import { WasmProcessor } from "../wasm-processing/wasmProcessor";
3
3
  export type Input = string;
4
4
  export type UnsignedTransaction = string;
@@ -1,4 +1,4 @@
1
- import { monero_wallet_api_wasm } from "../wasm-processing/wasmFile";
1
+ import { getMoneroWasmBytes } from "../wasm-processing/wasmLoader";
2
2
  import { WasmProcessor } from "../wasm-processing/wasmProcessor";
3
3
  export function makeInput(processor, outputToBeSpent, candidates, get_outs_Response) {
4
4
  const makeInputArgs = JSON.stringify({
@@ -89,7 +89,7 @@ export function makeTransaction(processor, params) {
89
89
  return result["signable_transaction"];
90
90
  }
91
91
  export async function signTransaction(tx, sender_spend_key) {
92
- const wasmProcessor = await WasmProcessor.init(monero_wallet_api_wasm);
92
+ const wasmProcessor = await WasmProcessor.init(await getMoneroWasmBytes());
93
93
  wasmProcessor.writeToWasmMemory = (ptr, len) => {
94
94
  wasmProcessor.writeString(ptr, len, tx);
95
95
  wasmProcessor.writeToWasmMemory = (ptr, len) => {
@@ -108,7 +108,7 @@ export async function signTransaction(tx, sender_spend_key) {
108
108
  return result["signed_transaction"];
109
109
  }
110
110
  export async function parseAddress(address) {
111
- const wasmProcessor = await WasmProcessor.init(monero_wallet_api_wasm);
111
+ const wasmProcessor = await WasmProcessor.init(await getMoneroWasmBytes());
112
112
  wasmProcessor.writeToWasmMemory = (ptr, len) => {
113
113
  wasmProcessor.writeString(ptr, len, address);
114
114
  };
@@ -6,7 +6,7 @@ import { type ScanCache } from "../scanning-syncing/scanresult/scanCache";
6
6
  import { type MakeTransactionParams, type UnsignedTransaction } from "../send-functionality/transactionBuilding";
7
7
  import { WasmProcessor } from "../wasm-processing/wasmProcessor";
8
8
  import { type NETWORKS } from "../node-interaction/nodeUrl";
9
- import { type GetBlockHeadersRangeParams } from "../xmr3";
9
+ import { type GetBlockHeadersRangeParams } from "../xmr3_common";
10
10
  /**
11
11
  * This class is useful to interact with Moneros DaemonRpc binary requests in a convenient way.
12
12
  * (similar to how you would interact with a REST api that gives you json back.)
@@ -35,7 +35,7 @@ export declare class ViewPair extends WasmProcessor {
35
35
  * @param stopSync optional AbortSignal to stop the syncing process
36
36
  * @returns The difference to the same method on NodeUrl is: It returns {@link ScanResult} (outputs that belong to viewpair) and not just the blocks as json.
37
37
  */
38
- getBlocksBin(params: GetBlocksBinRequest, metaCallBack?: GetBlocksBinMetaCallback, stopSync?: AbortSignal): Promise<ScanResult | ErrorResponse | undefined>;
38
+ getBlocksBin(params: GetBlocksBinRequest, metaCallBack?: GetBlocksBinMetaCallback, stopSync?: AbortSignal): Promise<ErrorResponse | ScanResult | undefined>;
39
39
  addGenesisHashToBlockIds(params: GetBlocksBinRequest): Promise<GetBlocksBinRequest>;
40
40
  /**
41
41
  * This function helps with making requests to the get_blocks.bin endpoint of the Monerod nodes.
@@ -66,7 +66,7 @@ export declare class ViewPair extends WasmProcessor {
66
66
  * @param getBlocksBinResponseBuffer the raw binary response from the get_blocks.bin endpoint
67
67
  * @returns metadata about the loaded blocks (new_height, daemon_height, status, block_infos)
68
68
  */
69
- loadGetBlocksBinResponse(getBlocksBinResponseBuffer: Uint8Array): Promise<import("../xmr3").GetBlocksResultMeta>;
69
+ loadGetBlocksBinResponse(getBlocksBinResponseBuffer: Uint8Array): Promise<import("../xmr3_common").GetBlocksResultMeta>;
70
70
  /**
71
71
  * scan one block from a getblocks.bin response that was loaded into wasm memory.
72
72
  * call loadGetBlocksBinResponse first to populate the response in the wasm module.
@@ -134,7 +134,7 @@ export declare class ViewPair extends WasmProcessor {
134
134
  * @param params The parameters including start_height, end_height, and optional fill_pow_hash.
135
135
  * @returns The result object with headers, status, etc. Throws if the range is invalid:(end_height > daemonheight)
136
136
  */
137
- getBlockHeadersRange(params: GetBlockHeadersRangeParams): Promise<import("../xmr3").GetBlockHeadersRange>;
137
+ getBlockHeadersRange(params: GetBlockHeadersRangeParams): Promise<import("../xmr3_common").GetBlockHeadersRange>;
138
138
  /**
139
139
  * Fetch general information about the Monero daemon.
140
140
  * @link https://docs.getmonero.org/rpc-library/monerod-rpc/#get_info
@@ -4,11 +4,11 @@ export { NodeUrl } from "../node-interaction/nodeUrl";
4
4
  import { getBlocksBinScan, getBlocksBinExecuteRequest, getBlocksBinScanOneBlock, loadGetBlocksBinResponse, MAINNET_GENESIS_BLOCK_HASH, STAGENET_GENESIS_BLOCK_HASH, } from "../node-interaction/binaryEndpoints";
5
5
  import { lastRange, writeCacheFileDefaultLocationThrows, } from "../scanning-syncing/scanresult/scanCache";
6
6
  import { makeSweepTransaction, makeTransaction, } from "../send-functionality/transactionBuilding";
7
- import { monero_wallet_api_wasm } from "../wasm-processing/wasmFile";
7
+ import { getMoneroWasmBytes } from "../wasm-processing/wasmLoader";
8
8
  import { WasmProcessor } from "../wasm-processing/wasmProcessor";
9
9
  import { LOCAL_NODE_DEFAULT_URL, } from "../node-interaction/nodeUrl";
10
- import { get_block_headers_range, get_info, } from "../xmr3";
11
- import { readWalletFromScanSettings } from "../xmr3";
10
+ import { get_block_headers_range, get_info, } from "../xmr3_common";
11
+ import { readWalletFromScanSettings } from "../xmr3_common";
12
12
  import { sleep } from "../io/sleep";
13
13
  /**
14
14
  * This class is useful to interact with Moneros DaemonRpc binary requests in a convenient way.
@@ -38,7 +38,7 @@ export class ViewPair extends WasmProcessor {
38
38
  }
39
39
  static async create(primary_address, secret_view_key, subaddress_index = 0, node_url) {
40
40
  const viewPair = new ViewPair(node_url || LOCAL_NODE_DEFAULT_URL, primary_address);
41
- const tinywasi = await viewPair.initWasmModule(monero_wallet_api_wasm);
41
+ const tinywasi = await viewPair.initWasmModule(await getMoneroWasmBytes());
42
42
  viewPair.writeToWasmMemory = (ptr, len) => {
43
43
  viewPair.writeString(ptr, len, primary_address);
44
44
  viewPair.writeToWasmMemory = (ptr, len) => {
@@ -0,0 +1,10 @@
1
+ export type WasmUrls = {
2
+ monero?: string;
3
+ dkg?: string;
4
+ };
5
+ export declare function setInlineWasm(monero?: Uint8Array<ArrayBuffer>, dkg?: Uint8Array<ArrayBuffer>): void;
6
+ export declare function setWasmUrls(urls: WasmUrls): void;
7
+ export declare function getWasmUrls(): WasmUrls;
8
+ export declare function resetWasmLoaderForTests(): void;
9
+ export declare function getMoneroWasmBytes(): Promise<Uint8Array<ArrayBuffer>>;
10
+ export declare function getDkgWasmBytes(): Promise<Uint8Array<ArrayBuffer>>;
@@ -0,0 +1,108 @@
1
+ // loader for wasm bytes in packed and unpacked mode
2
+ // packed mode uses inlined bytes from wasmFile
3
+ // unpacked mode fetches bytes from files
4
+ // this keeps chrome store builds free from base64 blobs
5
+ let inlineMonero;
6
+ let inlineDkg;
7
+ let moneroUrl;
8
+ let dkgUrl;
9
+ let moneroCache;
10
+ let dkgCache;
11
+ let moneroFlight;
12
+ let dkgFlight;
13
+ // set inlined bytes, called once by packed entry
14
+ export function setInlineWasm(monero, dkg) {
15
+ if (monero && monero.length)
16
+ inlineMonero = monero;
17
+ if (dkg && dkg.length)
18
+ inlineDkg = dkg;
19
+ }
20
+ // set file urls, called by unpacked entry
21
+ export function setWasmUrls(urls) {
22
+ if (urls.monero) {
23
+ moneroUrl = urls.monero;
24
+ moneroCache = undefined;
25
+ }
26
+ if (urls.dkg) {
27
+ dkgUrl = urls.dkg;
28
+ dkgCache = undefined;
29
+ }
30
+ }
31
+ // get current urls, used to pass urls to worker
32
+ export function getWasmUrls() {
33
+ return { monero: moneroUrl, dkg: dkgUrl };
34
+ }
35
+ // clear cache and urls, used in tests
36
+ // inline bytes stay set, packed tests need them
37
+ // unpacked tests set urls, urls win over inline so order does not matter
38
+ export function resetWasmLoaderForTests() {
39
+ moneroUrl = undefined;
40
+ dkgUrl = undefined;
41
+ moneroCache = undefined;
42
+ dkgCache = undefined;
43
+ moneroFlight = undefined;
44
+ dkgFlight = undefined;
45
+ }
46
+ async function fetchWasmBytes(url) {
47
+ // bun can read local files directly
48
+ try {
49
+ // @ts-ignore bun only
50
+ if (typeof Bun !== "undefined") {
51
+ // @ts-ignore bun only
52
+ const f = Bun.file(url);
53
+ if (await f.exists())
54
+ return new Uint8Array(await f.arrayBuffer());
55
+ }
56
+ }
57
+ catch {
58
+ // fall through to fetch
59
+ }
60
+ const res = await fetch(url);
61
+ if (!res.ok)
62
+ throw new Error("wasm fetch failed: " + url + " " + res.status);
63
+ return new Uint8Array(await res.arrayBuffer());
64
+ }
65
+ // get monero wasm bytes, urls win over inline when set
66
+ // concurrent calls share one fetch via flight promise
67
+ export async function getMoneroWasmBytes() {
68
+ if (moneroUrl) {
69
+ if (moneroCache)
70
+ return moneroCache;
71
+ if (moneroFlight)
72
+ return moneroFlight;
73
+ moneroFlight = fetchWasmBytes(moneroUrl).then((b) => {
74
+ moneroCache = b;
75
+ moneroFlight = undefined;
76
+ return b;
77
+ }).catch((e) => {
78
+ moneroFlight = undefined;
79
+ throw e;
80
+ });
81
+ return moneroFlight;
82
+ }
83
+ if (inlineMonero && inlineMonero.length)
84
+ return inlineMonero;
85
+ throw new Error("monero wasm has no inline bytes and no url, call setWasmUrls first");
86
+ }
87
+ // get dkg wasm bytes, urls win over inline when set
88
+ // concurrent calls share one fetch via flight promise
89
+ export async function getDkgWasmBytes() {
90
+ if (dkgUrl) {
91
+ if (dkgCache)
92
+ return dkgCache;
93
+ if (dkgFlight)
94
+ return dkgFlight;
95
+ dkgFlight = fetchWasmBytes(dkgUrl).then((b) => {
96
+ dkgCache = b;
97
+ dkgFlight = undefined;
98
+ return b;
99
+ }).catch((e) => {
100
+ dkgFlight = undefined;
101
+ throw e;
102
+ });
103
+ return dkgFlight;
104
+ }
105
+ if (inlineDkg && inlineDkg.length)
106
+ return inlineDkg;
107
+ throw new Error("dkg wasm has no inline bytes and no url, call setWasmUrls first");
108
+ }