@spirobel/monero-wallet-api 0.6.0 → 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 +11 -8
- 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/tools/content.js +1 -1
- 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 -0
- package/dist/xmr3.js +10 -0
- package/dist/{api.d.ts → xmr3_common.d.ts} +1 -1
- package/dist/{api.js → xmr3_common.js} +1 -1
- package/dist/xmr3_unpacked.d.ts +9 -0
- package/dist/xmr3_unpacked.js +14 -0
- package/package.json +14 -7
- 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
package/dist/xmr3.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./xmr3_common";
|
package/dist/xmr3.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// packed entry, uses inlined wasm and worker code
|
|
2
|
+
// this file injects inlined bytes into loaders
|
|
3
|
+
// internal code imports from xmr3_common to avoid cycles
|
|
4
|
+
import { monero_wallet_api_wasm, frost_dkg_wasm } from "./wasm-processing/wasmFile";
|
|
5
|
+
import { setInlineWasm } from "./wasm-processing/wasmLoader";
|
|
6
|
+
import { workerMainCode } from "./scanning-syncing/worker-entrypoints/worker";
|
|
7
|
+
import { setInlineWorkerCode } from "./scanning-syncing/backgroundWorker";
|
|
8
|
+
setInlineWasm(monero_wallet_api_wasm, frost_dkg_wasm);
|
|
9
|
+
setInlineWorkerCode(workerMainCode);
|
|
10
|
+
export * from "./xmr3_common";
|
|
@@ -15,7 +15,7 @@ export * from "./multisig/multisig";
|
|
|
15
15
|
export * from "./multisig/DistributedKeyGenerator";
|
|
16
16
|
export * from "./multisig/escrow";
|
|
17
17
|
export * from "./multisig/MultiSigTxSigner";
|
|
18
|
-
export { createWebworker, makeWebworkerScript, } from "./scanning-syncing/backgroundWorker";
|
|
18
|
+
export { createWebworker, makeWebworkerScript, setWorkerUrl, getWorkerUrl, startWebworkerReady, } from "./scanning-syncing/backgroundWorker";
|
|
19
19
|
export { spendable } from "./scanning-syncing/scanresult/scanResult";
|
|
20
20
|
export { openWallets, openWallet } from "./scanning-syncing/openWallet";
|
|
21
21
|
export * from "./scanning-syncing/blocksbuffer/blocksBufferFetchLoop";
|
|
@@ -14,7 +14,7 @@ export * from "./multisig/multisig";
|
|
|
14
14
|
export * from "./multisig/DistributedKeyGenerator";
|
|
15
15
|
export * from "./multisig/escrow";
|
|
16
16
|
export * from "./multisig/MultiSigTxSigner";
|
|
17
|
-
export { createWebworker, makeWebworkerScript, } from "./scanning-syncing/backgroundWorker";
|
|
17
|
+
export { createWebworker, makeWebworkerScript, setWorkerUrl, getWorkerUrl, startWebworkerReady, } from "./scanning-syncing/backgroundWorker";
|
|
18
18
|
export { spendable } from "./scanning-syncing/scanresult/scanResult";
|
|
19
19
|
export { openWallets, openWallet } from "./scanning-syncing/openWallet";
|
|
20
20
|
export * from "./scanning-syncing/blocksbuffer/blocksBufferFetchLoop";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./xmr3_common";
|
|
2
|
+
export { setWasmUrls, getWasmUrls, getMoneroWasmBytes, getDkgWasmBytes, type WasmUrls, } from "./wasm-processing/wasmLoader";
|
|
3
|
+
export { setWorkerUrl, getWorkerUrl } from "./scanning-syncing/backgroundWorker";
|
|
4
|
+
export type UnpackedConfig = {
|
|
5
|
+
workerUrl: string;
|
|
6
|
+
moneroWasmUrl: string;
|
|
7
|
+
dkgWasmUrl: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function configureUnpacked(config: UnpackedConfig): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// unpacked entry for chrome store
|
|
2
|
+
// no inlined wasm, no inlined worker code
|
|
3
|
+
// consumer copies wasm files and worker file to dist
|
|
4
|
+
// then calls configureUnpacked before openWallets
|
|
5
|
+
export * from "./xmr3_common";
|
|
6
|
+
export { setWasmUrls, getWasmUrls, getMoneroWasmBytes, getDkgWasmBytes, } from "./wasm-processing/wasmLoader";
|
|
7
|
+
export { setWorkerUrl, getWorkerUrl } from "./scanning-syncing/backgroundWorker";
|
|
8
|
+
import { setWasmUrls } from "./wasm-processing/wasmLoader";
|
|
9
|
+
import { setWorkerUrl } from "./scanning-syncing/backgroundWorker";
|
|
10
|
+
// set worker url and wasm urls in one call
|
|
11
|
+
export function configureUnpacked(config) {
|
|
12
|
+
setWorkerUrl(config.workerUrl);
|
|
13
|
+
setWasmUrls({ monero: config.moneroWasmUrl, dkg: config.dkgWasmUrl });
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spirobel/monero-wallet-api",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"module": "dist/
|
|
3
|
+
"version": "0.6.2",
|
|
4
|
+
"main": "dist/xmr3.js",
|
|
5
|
+
"module": "dist/xmr3.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/bun": "latest"
|
|
8
8
|
},
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"types": "./dist/
|
|
15
|
-
"import": "./dist/
|
|
14
|
+
"types": "./dist/xmr3.d.ts",
|
|
15
|
+
"import": "./dist/xmr3.js"
|
|
16
|
+
},
|
|
17
|
+
"./unpacked": {
|
|
18
|
+
"types": "./dist/xmr3_unpacked.d.ts",
|
|
19
|
+
"import": "./dist/xmr3_unpacked.js"
|
|
16
20
|
},
|
|
17
21
|
"./tools": {
|
|
18
22
|
"types": "./dist/tools/monero-tools.d.ts",
|
|
@@ -50,11 +54,14 @@
|
|
|
50
54
|
"copydev": "bun run safewasm && bun run safeworker && bun run copydevworker && bun run copydevwasm",
|
|
51
55
|
"restoredev": "bun run restorewasm && bun run restoreworker",
|
|
52
56
|
"refreshdev": "bun run restoredev && bun run inlinesum && bun run copydev",
|
|
53
|
-
"
|
|
57
|
+
"buildworkerunpacked": "bun build ./wallet-api/scanning-syncing/worker-mains/worker.ts --target=browser --outfile dist/worker_unpacked.js",
|
|
58
|
+
"copywasm": "cp ../rust/target/wasm32-wasip1/release/monero_wallet_api.wasm dist/monero_wallet_api.wasm && cp ../frost-dkg/target/wasm32-wasip1/release/frost_dkg.wasm dist/frost_dkg.wasm",
|
|
59
|
+
"buildunpacked": "bun run buildworkerunpacked && bun run copywasm",
|
|
60
|
+
"build": "bun run buildtypescript && bun run inlinesum && bun run buildunpacked",
|
|
54
61
|
"clean": "rm -rf ./dist"
|
|
55
62
|
},
|
|
56
63
|
"type": "module",
|
|
57
|
-
"types": "dist/
|
|
64
|
+
"types": "dist/xmr3.d.ts",
|
|
58
65
|
"dependencies": {
|
|
59
66
|
"@noble/curves": "2.2.0",
|
|
60
67
|
"@noble/hashes": "2.2.0"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// the actionlog datastructure records three types of actions:
|
|
2
|
-
// 1. actions that the user has performed (external choice)
|
|
3
|
-
// 2. actions as the result of business logic during the execution of a tool call
|
|
4
|
-
// 3. actions as the result of business logic during the execution of an automated agreement
|
|
5
|
-
//
|
|
6
|
-
// tool call: privacy preserving interface between wallet and
|
|
7
|
-
// services that manage interaction with other users / wallets,
|
|
8
|
-
// set in motion by a user action (external choice to the whole (distributed, concurrent) system)
|
|
9
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type ActionLogBackend, type ActionLogEvent, type InvocationState, type InvocationStatus } from "../actionLogTypes";
|
|
2
|
-
export declare class ActionLogJsonlBackend implements ActionLogBackend {
|
|
3
|
-
private readonly path;
|
|
4
|
-
private eventLog;
|
|
5
|
-
private active;
|
|
6
|
-
constructor(path: string);
|
|
7
|
-
static open(path: string): Promise<ActionLogJsonlBackend>;
|
|
8
|
-
private invocationsPath;
|
|
9
|
-
private load;
|
|
10
|
-
private loadInvocationsFile;
|
|
11
|
-
private persistEvents;
|
|
12
|
-
private persistInvocations;
|
|
13
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
14
|
-
events(invocationId: string): Promise<ActionLogEvent[]>;
|
|
15
|
-
invocation(invocationId: string): Promise<InvocationState | null>;
|
|
16
|
-
invocations(status?: InvocationStatus): Promise<InvocationState[]>;
|
|
17
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
18
|
-
reload(): Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { atomicWrite } from "../../io/atomicWrite";
|
|
2
|
-
import { ActiveInvocations, invocationStatus, } from "../actionLogTypes";
|
|
3
|
-
export class ActionLogJsonlBackend {
|
|
4
|
-
path;
|
|
5
|
-
eventLog = [];
|
|
6
|
-
active = new ActiveInvocations();
|
|
7
|
-
constructor(path) {
|
|
8
|
-
this.path = path;
|
|
9
|
-
}
|
|
10
|
-
static async open(path) {
|
|
11
|
-
const backend = new ActionLogJsonlBackend(path);
|
|
12
|
-
await backend.load();
|
|
13
|
-
return backend;
|
|
14
|
-
}
|
|
15
|
-
invocationsPath() {
|
|
16
|
-
const p = this.path;
|
|
17
|
-
const i = Math.max(p.lastIndexOf("/"), p.lastIndexOf("\\"));
|
|
18
|
-
const dir = i >= 0 ? p.slice(0, i) : ".";
|
|
19
|
-
return `${dir}/invocations.jsonl`;
|
|
20
|
-
}
|
|
21
|
-
async load() {
|
|
22
|
-
const loaded = await this.loadInvocationsFile();
|
|
23
|
-
const text = await Bun.file(this.path)
|
|
24
|
-
.text()
|
|
25
|
-
.catch(() => "");
|
|
26
|
-
this.eventLog = [];
|
|
27
|
-
if (text.trim()) {
|
|
28
|
-
for (const line of text.split("\n")) {
|
|
29
|
-
const t = line.trim();
|
|
30
|
-
if (!t)
|
|
31
|
-
continue;
|
|
32
|
-
try {
|
|
33
|
-
this.eventLog.push(JSON.parse(t));
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// skip bad line
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (loaded)
|
|
41
|
-
return;
|
|
42
|
-
this.active.clear();
|
|
43
|
-
for (const event of this.eventLog)
|
|
44
|
-
this.active.apply(event);
|
|
45
|
-
await this.persistInvocations();
|
|
46
|
-
}
|
|
47
|
-
async loadInvocationsFile() {
|
|
48
|
-
const text = await Bun.file(this.invocationsPath())
|
|
49
|
-
.text()
|
|
50
|
-
.catch(() => "");
|
|
51
|
-
if (!text.trim())
|
|
52
|
-
return false;
|
|
53
|
-
const states = [];
|
|
54
|
-
for (const line of text.split("\n")) {
|
|
55
|
-
const t = line.trim();
|
|
56
|
-
if (!t)
|
|
57
|
-
continue;
|
|
58
|
-
try {
|
|
59
|
-
states.push(JSON.parse(t));
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
// skip bad line
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (!states.length)
|
|
66
|
-
return false;
|
|
67
|
-
this.active.loadStates(states);
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
async persistEvents() {
|
|
71
|
-
const body = this.eventLog.map((e) => JSON.stringify(e)).join("\n") +
|
|
72
|
-
(this.eventLog.length ? "\n" : "");
|
|
73
|
-
await atomicWrite(this.path, body);
|
|
74
|
-
}
|
|
75
|
-
async persistInvocations() {
|
|
76
|
-
const rows = this.active.invocations();
|
|
77
|
-
const body = rows
|
|
78
|
-
.map((s) => JSON.stringify({ ...s, status: invocationStatus(s) }))
|
|
79
|
-
.join("\n") + (rows.length ? "\n" : "");
|
|
80
|
-
await atomicWrite(this.invocationsPath(), body);
|
|
81
|
-
}
|
|
82
|
-
async append(event) {
|
|
83
|
-
this.eventLog.push(event);
|
|
84
|
-
this.active.apply(event);
|
|
85
|
-
await this.persistEvents();
|
|
86
|
-
await this.persistInvocations();
|
|
87
|
-
}
|
|
88
|
-
async events(invocationId) {
|
|
89
|
-
return this.eventLog.filter((e) => e.invocationId === invocationId);
|
|
90
|
-
}
|
|
91
|
-
async invocation(invocationId) {
|
|
92
|
-
return this.active.invocation(invocationId);
|
|
93
|
-
}
|
|
94
|
-
async invocations(status) {
|
|
95
|
-
return this.active.invocations(status);
|
|
96
|
-
}
|
|
97
|
-
async feed(events) {
|
|
98
|
-
for (const event of events) {
|
|
99
|
-
if (this.eventLog.some((e) => e.id === event.id))
|
|
100
|
-
continue;
|
|
101
|
-
this.eventLog.push(event);
|
|
102
|
-
this.active.apply(event);
|
|
103
|
-
}
|
|
104
|
-
await this.persistEvents();
|
|
105
|
-
await this.persistInvocations();
|
|
106
|
-
}
|
|
107
|
-
async reload() {
|
|
108
|
-
await this.load();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type ActionLogBackend, type ActionLogEvent, type InvocationState, type InvocationStatus } from "../actionLogTypes";
|
|
2
|
-
export declare class ActionLogMemoryBackend implements ActionLogBackend {
|
|
3
|
-
private eventLog;
|
|
4
|
-
private active;
|
|
5
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
6
|
-
events(invocationId: string): Promise<ActionLogEvent[]>;
|
|
7
|
-
invocation(invocationId: string): Promise<InvocationState | null>;
|
|
8
|
-
invocations(status?: InvocationStatus): Promise<InvocationState[]>;
|
|
9
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
10
|
-
reload(): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ActiveInvocations, } from "../actionLogTypes";
|
|
2
|
-
export class ActionLogMemoryBackend {
|
|
3
|
-
eventLog = [];
|
|
4
|
-
active = new ActiveInvocations();
|
|
5
|
-
async append(event) {
|
|
6
|
-
this.eventLog.push(event);
|
|
7
|
-
this.active.apply(event);
|
|
8
|
-
}
|
|
9
|
-
async events(invocationId) {
|
|
10
|
-
return this.eventLog.filter((e) => e.invocationId === invocationId);
|
|
11
|
-
}
|
|
12
|
-
async invocation(invocationId) {
|
|
13
|
-
return this.active.invocation(invocationId);
|
|
14
|
-
}
|
|
15
|
-
async invocations(status) {
|
|
16
|
-
return this.active.invocations(status);
|
|
17
|
-
}
|
|
18
|
-
async feed(events) {
|
|
19
|
-
for (const event of events) {
|
|
20
|
-
if (this.eventLog.some((e) => e.id === event.id))
|
|
21
|
-
continue;
|
|
22
|
-
this.eventLog.push(event);
|
|
23
|
-
this.active.apply(event);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async reload() {
|
|
27
|
-
this.active.clear();
|
|
28
|
-
for (const event of this.eventLog)
|
|
29
|
-
this.active.apply(event);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
2
|
-
import type { ActionLogEvent, OpenInvocationState } from "./types";
|
|
3
|
-
export type ActionLogBackend = {
|
|
4
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
5
|
-
getBranch(invocationId: string): Promise<ActionLogEvent[]>;
|
|
6
|
-
getTip(invocationId: string): Promise<ActionLogEvent | null>;
|
|
7
|
-
getOpenByToolId(toolId: ToolId): Promise<OpenInvocationState | null>;
|
|
8
|
-
getOpenInvocations(): Promise<OpenInvocationState[]>;
|
|
9
|
-
feed?(events: ActionLogEvent[]): Promise<void>;
|
|
10
|
-
reload?(): Promise<void>;
|
|
11
|
-
close?(): Promise<void>;
|
|
12
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ActionLogBackend } from "./backend";
|
|
2
|
-
import type { ActionLogEvent, OpenInvocationState } from "./types";
|
|
3
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
4
|
-
export declare class ActionLogIdbBackend implements ActionLogBackend {
|
|
5
|
-
private readonly db;
|
|
6
|
-
private open;
|
|
7
|
-
private constructor();
|
|
8
|
-
static open(dbName?: string): Promise<ActionLogIdbBackend>;
|
|
9
|
-
private rebuildOpenMaps;
|
|
10
|
-
private getAllEventsOrdered;
|
|
11
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
12
|
-
getBranch(invocationId: string): Promise<ActionLogEvent[]>;
|
|
13
|
-
getTip(invocationId: string): Promise<ActionLogEvent | null>;
|
|
14
|
-
getOpenByToolId(toolId: ToolId): Promise<OpenInvocationState | null>;
|
|
15
|
-
getOpenInvocations(): Promise<OpenInvocationState[]>;
|
|
16
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
17
|
-
reload(): Promise<void>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { OpenInvocationMaps } from "./openMaps";
|
|
2
|
-
const DB_NAME_DEFAULT = "monero-actionlog";
|
|
3
|
-
const STORE_EVENTS = "events";
|
|
4
|
-
export class ActionLogIdbBackend {
|
|
5
|
-
db;
|
|
6
|
-
open = new OpenInvocationMaps();
|
|
7
|
-
constructor(db) {
|
|
8
|
-
this.db = db;
|
|
9
|
-
}
|
|
10
|
-
static async open(dbName = DB_NAME_DEFAULT) {
|
|
11
|
-
if (typeof indexedDB === "undefined") {
|
|
12
|
-
throw new Error("IndexedDB not available");
|
|
13
|
-
}
|
|
14
|
-
const db = await openDb(dbName);
|
|
15
|
-
const backend = new ActionLogIdbBackend(db);
|
|
16
|
-
await backend.rebuildOpenMaps();
|
|
17
|
-
return backend;
|
|
18
|
-
}
|
|
19
|
-
async rebuildOpenMaps() {
|
|
20
|
-
this.open.clear();
|
|
21
|
-
const events = await this.getAllEventsOrdered();
|
|
22
|
-
for (const event of events)
|
|
23
|
-
this.open.apply(event);
|
|
24
|
-
}
|
|
25
|
-
getAllEventsOrdered() {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const tx = this.db.transaction(STORE_EVENTS, "readonly");
|
|
28
|
-
const store = tx.objectStore(STORE_EVENTS);
|
|
29
|
-
const req = store.getAll();
|
|
30
|
-
req.onerror = () => reject(req.error);
|
|
31
|
-
req.onsuccess = () => {
|
|
32
|
-
const rows = req.result ?? [];
|
|
33
|
-
rows.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
34
|
-
resolve(rows);
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
async append(event) {
|
|
39
|
-
await new Promise((resolve, reject) => {
|
|
40
|
-
const tx = this.db.transaction(STORE_EVENTS, "readwrite");
|
|
41
|
-
const store = tx.objectStore(STORE_EVENTS);
|
|
42
|
-
const req = store.put(event);
|
|
43
|
-
req.onerror = () => reject(req.error);
|
|
44
|
-
req.onsuccess = () => resolve();
|
|
45
|
-
});
|
|
46
|
-
this.open.apply(event);
|
|
47
|
-
}
|
|
48
|
-
async getBranch(invocationId) {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const tx = this.db.transaction(STORE_EVENTS, "readonly");
|
|
51
|
-
const store = tx.objectStore(STORE_EVENTS);
|
|
52
|
-
const index = store.index("invocationId");
|
|
53
|
-
const req = index.getAll(invocationId);
|
|
54
|
-
req.onerror = () => reject(req.error);
|
|
55
|
-
req.onsuccess = () => {
|
|
56
|
-
const rows = req.result ?? [];
|
|
57
|
-
rows.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
58
|
-
resolve(rows);
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async getTip(invocationId) {
|
|
63
|
-
const branch = await this.getBranch(invocationId);
|
|
64
|
-
return branch.length ? branch[branch.length - 1] : null;
|
|
65
|
-
}
|
|
66
|
-
async getOpenByToolId(toolId) {
|
|
67
|
-
return this.open.getOpenByToolId(toolId);
|
|
68
|
-
}
|
|
69
|
-
async getOpenInvocations() {
|
|
70
|
-
return this.open.getOpenInvocations();
|
|
71
|
-
}
|
|
72
|
-
async feed(events) {
|
|
73
|
-
for (const event of events)
|
|
74
|
-
await this.append(event);
|
|
75
|
-
}
|
|
76
|
-
async reload() {
|
|
77
|
-
await this.rebuildOpenMaps();
|
|
78
|
-
}
|
|
79
|
-
async close() {
|
|
80
|
-
this.db.close();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function openDb(name) {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
const req = indexedDB.open(name, 1);
|
|
86
|
-
req.onerror = () => reject(req.error);
|
|
87
|
-
req.onupgradeneeded = () => {
|
|
88
|
-
const db = req.result;
|
|
89
|
-
if (!db.objectStoreNames.contains(STORE_EVENTS)) {
|
|
90
|
-
const store = db.createObjectStore(STORE_EVENTS, { keyPath: "id" });
|
|
91
|
-
store.createIndex("invocationId", "invocationId", { unique: false });
|
|
92
|
-
store.createIndex("toolId", "toolId", { unique: false });
|
|
93
|
-
store.createIndex("timestamp", "timestamp", { unique: false });
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
req.onsuccess = () => resolve(req.result);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ActionLogBackend } from "./backend";
|
|
2
|
-
import type { ActionLogEvent, OpenInvocationState } from "./types";
|
|
3
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
4
|
-
export declare class ActionLogJsonlBackend implements ActionLogBackend {
|
|
5
|
-
private readonly path;
|
|
6
|
-
private events;
|
|
7
|
-
private open;
|
|
8
|
-
constructor(path: string);
|
|
9
|
-
static open(path: string): Promise<ActionLogJsonlBackend>;
|
|
10
|
-
private load;
|
|
11
|
-
private persist;
|
|
12
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
13
|
-
getBranch(invocationId: string): Promise<ActionLogEvent[]>;
|
|
14
|
-
getTip(invocationId: string): Promise<ActionLogEvent | null>;
|
|
15
|
-
getOpenByToolId(toolId: ToolId): Promise<OpenInvocationState | null>;
|
|
16
|
-
getOpenInvocations(): Promise<OpenInvocationState[]>;
|
|
17
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
18
|
-
reload(): Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { atomicWrite } from "../io/atomicWrite";
|
|
2
|
-
import { OpenInvocationMaps } from "./openMaps";
|
|
3
|
-
export class ActionLogJsonlBackend {
|
|
4
|
-
path;
|
|
5
|
-
events = [];
|
|
6
|
-
open = new OpenInvocationMaps();
|
|
7
|
-
constructor(path) {
|
|
8
|
-
this.path = path;
|
|
9
|
-
}
|
|
10
|
-
static async open(path) {
|
|
11
|
-
const backend = new ActionLogJsonlBackend(path);
|
|
12
|
-
await backend.load();
|
|
13
|
-
return backend;
|
|
14
|
-
}
|
|
15
|
-
async load() {
|
|
16
|
-
const text = await Bun.file(this.path)
|
|
17
|
-
.text()
|
|
18
|
-
.catch(() => "");
|
|
19
|
-
this.events = [];
|
|
20
|
-
this.open.clear();
|
|
21
|
-
if (!text.trim())
|
|
22
|
-
return;
|
|
23
|
-
for (const line of text.split("\n")) {
|
|
24
|
-
const t = line.trim();
|
|
25
|
-
if (!t)
|
|
26
|
-
continue;
|
|
27
|
-
try {
|
|
28
|
-
const event = JSON.parse(t);
|
|
29
|
-
this.events.push(event);
|
|
30
|
-
this.open.apply(event);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
// skip bad line
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async persist() {
|
|
38
|
-
const body = this.events.map((e) => JSON.stringify(e)).join("\n") +
|
|
39
|
-
(this.events.length ? "\n" : "");
|
|
40
|
-
await atomicWrite(this.path, body);
|
|
41
|
-
}
|
|
42
|
-
async append(event) {
|
|
43
|
-
this.events.push(event);
|
|
44
|
-
this.open.apply(event);
|
|
45
|
-
await this.persist();
|
|
46
|
-
}
|
|
47
|
-
async getBranch(invocationId) {
|
|
48
|
-
return this.events.filter((e) => e.invocationId === invocationId);
|
|
49
|
-
}
|
|
50
|
-
async getTip(invocationId) {
|
|
51
|
-
for (let i = this.events.length - 1; i >= 0; i--) {
|
|
52
|
-
if (this.events[i].invocationId === invocationId)
|
|
53
|
-
return this.events[i];
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
async getOpenByToolId(toolId) {
|
|
58
|
-
return this.open.getOpenByToolId(toolId);
|
|
59
|
-
}
|
|
60
|
-
async getOpenInvocations() {
|
|
61
|
-
return this.open.getOpenInvocations();
|
|
62
|
-
}
|
|
63
|
-
async feed(events) {
|
|
64
|
-
for (const event of events) {
|
|
65
|
-
if (this.events.some((e) => e.id === event.id))
|
|
66
|
-
continue;
|
|
67
|
-
this.events.push(event);
|
|
68
|
-
this.open.apply(event);
|
|
69
|
-
}
|
|
70
|
-
await this.persist();
|
|
71
|
-
}
|
|
72
|
-
async reload() {
|
|
73
|
-
await this.load();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ActionLogBackend } from "./backend";
|
|
2
|
-
import type { ActionLogEvent, OpenInvocationState } from "./types";
|
|
3
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
4
|
-
export declare class ActionLogMemoryBackend implements ActionLogBackend {
|
|
5
|
-
private events;
|
|
6
|
-
private open;
|
|
7
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
8
|
-
getBranch(invocationId: string): Promise<ActionLogEvent[]>;
|
|
9
|
-
getTip(invocationId: string): Promise<ActionLogEvent | null>;
|
|
10
|
-
getOpenByToolId(toolId: ToolId): Promise<OpenInvocationState | null>;
|
|
11
|
-
getOpenInvocations(): Promise<OpenInvocationState[]>;
|
|
12
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
13
|
-
reload(): Promise<void>;
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { OpenInvocationMaps } from "./openMaps";
|
|
2
|
-
export class ActionLogMemoryBackend {
|
|
3
|
-
events = [];
|
|
4
|
-
open = new OpenInvocationMaps();
|
|
5
|
-
async append(event) {
|
|
6
|
-
this.events.push(event);
|
|
7
|
-
this.open.apply(event);
|
|
8
|
-
}
|
|
9
|
-
async getBranch(invocationId) {
|
|
10
|
-
return this.events.filter((e) => e.invocationId === invocationId);
|
|
11
|
-
}
|
|
12
|
-
async getTip(invocationId) {
|
|
13
|
-
for (let i = this.events.length - 1; i >= 0; i--) {
|
|
14
|
-
if (this.events[i].invocationId === invocationId)
|
|
15
|
-
return this.events[i];
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
async getOpenByToolId(toolId) {
|
|
20
|
-
return this.open.getOpenByToolId(toolId);
|
|
21
|
-
}
|
|
22
|
-
async getOpenInvocations() {
|
|
23
|
-
return this.open.getOpenInvocations();
|
|
24
|
-
}
|
|
25
|
-
async feed(events) {
|
|
26
|
-
for (const event of events) {
|
|
27
|
-
if (this.events.some((e) => e.id === event.id))
|
|
28
|
-
continue;
|
|
29
|
-
this.events.push(event);
|
|
30
|
-
this.open.apply(event);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async reload() {
|
|
34
|
-
this.open.clear();
|
|
35
|
-
for (const event of this.events)
|
|
36
|
-
this.open.apply(event);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
2
|
-
import { type ActionLogEvent, type OpenInvocationState } from "./types";
|
|
3
|
-
/** shared open-invocation maps for backends without a native secondary index */
|
|
4
|
-
export declare class OpenInvocationMaps {
|
|
5
|
-
byInvocation: Map<string, OpenInvocationState>;
|
|
6
|
-
byTool: Map<"001" | "002", string>;
|
|
7
|
-
apply(event: ActionLogEvent): void;
|
|
8
|
-
clear(): void;
|
|
9
|
-
getOpenByToolId(toolId: ToolId): OpenInvocationState | null;
|
|
10
|
-
getOpenInvocations(): OpenInvocationState[];
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { applyEventToState, isTerminalEventType, } from "./types";
|
|
2
|
-
/** shared open-invocation maps for backends without a native secondary index */
|
|
3
|
-
export class OpenInvocationMaps {
|
|
4
|
-
byInvocation = new Map();
|
|
5
|
-
byTool = new Map();
|
|
6
|
-
apply(event) {
|
|
7
|
-
const prev = this.byInvocation.get(event.invocationId) ?? null;
|
|
8
|
-
const next = applyEventToState(prev, event);
|
|
9
|
-
if (isTerminalEventType(event.type)) {
|
|
10
|
-
this.byInvocation.delete(event.invocationId);
|
|
11
|
-
if (this.byTool.get(event.toolId) === event.invocationId) {
|
|
12
|
-
this.byTool.delete(event.toolId);
|
|
13
|
-
}
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
this.byInvocation.set(event.invocationId, next);
|
|
17
|
-
this.byTool.set(event.toolId, event.invocationId);
|
|
18
|
-
}
|
|
19
|
-
clear() {
|
|
20
|
-
this.byInvocation.clear();
|
|
21
|
-
this.byTool.clear();
|
|
22
|
-
}
|
|
23
|
-
getOpenByToolId(toolId) {
|
|
24
|
-
const id = this.byTool.get(toolId);
|
|
25
|
-
if (!id)
|
|
26
|
-
return null;
|
|
27
|
-
return this.byInvocation.get(id) ?? null;
|
|
28
|
-
}
|
|
29
|
-
getOpenInvocations() {
|
|
30
|
-
return [...this.byInvocation.values()];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ActionLogBackend } from "./backend";
|
|
2
|
-
import type { ActionLogEvent, OpenInvocationState } from "./types";
|
|
3
|
-
import type { ToolId } from "../tools/monero-tools";
|
|
4
|
-
/** bun-only sqlite backend. do not import from browser worker graphs. */
|
|
5
|
-
export declare class ActionLogSqliteBackend implements ActionLogBackend {
|
|
6
|
-
private open;
|
|
7
|
-
private sql;
|
|
8
|
-
private constructor();
|
|
9
|
-
static open(filename: string): Promise<ActionLogSqliteBackend>;
|
|
10
|
-
private rebuildOpenMaps;
|
|
11
|
-
append(event: ActionLogEvent): Promise<void>;
|
|
12
|
-
getBranch(invocationId: string): Promise<ActionLogEvent[]>;
|
|
13
|
-
getTip(invocationId: string): Promise<ActionLogEvent | null>;
|
|
14
|
-
getOpenByToolId(toolId: ToolId): Promise<OpenInvocationState | null>;
|
|
15
|
-
getOpenInvocations(): Promise<OpenInvocationState[]>;
|
|
16
|
-
feed(events: ActionLogEvent[]): Promise<void>;
|
|
17
|
-
reload(): Promise<void>;
|
|
18
|
-
}
|