@spirobel/monero-wallet-api 0.6.7 → 0.6.9

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.
@@ -15,8 +15,7 @@ declare global {
15
15
  var browser: ExtensionBrowser;
16
16
  var chrome: ExtensionBrowser;
17
17
  }
18
- /** send toolCall and openSidebar to worker. after the check, toolCall message to worker again to persist validity status,
19
- * potential second round of communication with backend. */
20
18
  export declare function interceptToolLinkCallback(e: Event): void;
19
+ export declare function deliverToolUrl(url: string): boolean;
21
20
  export declare function installToolLinkEventInterception(): void;
22
21
  export {};
@@ -12,17 +12,23 @@ function processTargetLink(element) {
12
12
  //invo id created here
13
13
  return parseToolInvocation(href, text, location);
14
14
  }
15
+ function anchorFromEvent(e) {
16
+ const host = e.target instanceof Element ? e.target : null;
17
+ const light = host?.closest("a") ?? null;
18
+ if (light)
19
+ return light;
20
+ // open shadow root hides the inner anchor. walk the path only then.
21
+ if (!host?.shadowRoot)
22
+ return null;
23
+ for (const node of e.composedPath()) {
24
+ if (node instanceof HTMLAnchorElement)
25
+ return node;
26
+ }
27
+ return null;
28
+ }
15
29
  /** send toolCall and openSidebar to worker. after the check, toolCall message to worker again to persist validity status,
16
30
  * potential second round of communication with backend. */
17
- export function interceptToolLinkCallback(e) {
18
- if (!(e.target instanceof Element))
19
- return;
20
- const link = e.target.closest("a");
21
- const monerotoolLink = processTargetLink(link);
22
- if (!link || !monerotoolLink)
23
- return;
24
- e.preventDefault();
25
- e.stopImmediatePropagation();
31
+ function deliver(monerotoolLink) {
26
32
  void sendToBackground("toolCall", monerotoolLink).catch(() => { });
27
33
  void sendToBackground("openSidebar", null).catch(() => { });
28
34
  checkToolInvocationValidity(monerotoolLink).then((result) => {
@@ -34,8 +40,36 @@ export function interceptToolLinkCallback(e) {
34
40
  tools[id]?.content.execute_deliver?.(monerotoolLink);
35
41
  });
36
42
  }
43
+ export function interceptToolLinkCallback(e) {
44
+ const link = anchorFromEvent(e);
45
+ const monerotoolLink = processTargetLink(link);
46
+ if (!link || !monerotoolLink)
47
+ return;
48
+ e.preventDefault();
49
+ e.stopImmediatePropagation();
50
+ deliver(monerotoolLink);
51
+ }
52
+ // the page url itself is the tool link. a click never happens.
53
+ export function deliverToolUrl(url) {
54
+ let href = url;
55
+ let hostname = "";
56
+ try {
57
+ const parsed = new URL(url);
58
+ href = parsed.href;
59
+ hostname = parsed.hostname;
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ const invo = parseToolInvocation(href, "", { href, hostname });
65
+ if (!invo)
66
+ return false;
67
+ deliver(invo);
68
+ return true;
69
+ }
37
70
  export function installToolLinkEventInterception() {
38
71
  document.addEventListener("click", interceptToolLinkCallback, true);
39
72
  document.addEventListener("touchend", interceptToolLinkCallback, true);
40
73
  document.addEventListener("keydown", interceptToolLinkCallback, true);
74
+ deliverToolUrl(location.href);
41
75
  }
@@ -45,11 +45,12 @@ export function createToolLink(tool) {
45
45
  throw new Error("unknown tool");
46
46
  return tools[id].counterparty.make(tool.payload);
47
47
  }
48
+ // xmr3.ts API to parse tool links
48
49
  export function parseToolInvocation(link, linkText, context_location) {
49
- const context_domain = getDomainWithTLD(context_location.hostname);
50
- const context_href = context_location.href;
51
50
  const link_parse = parseToolLink(link);
52
51
  if (link_parse) {
52
+ const context_domain = getDomainWithTLD(context_location.hostname);
53
+ const context_href = context_location.href;
53
54
  return {
54
55
  tool: link_parse,
55
56
  destination_domain: parseDestination(link),
@@ -65,6 +66,8 @@ export function parseToolInvocation(link, linkText, context_location) {
65
66
  }
66
67
  const linkText_parse = parseToolLink(linkText);
67
68
  if (linkText_parse) {
69
+ const context_domain = getDomainWithTLD(context_location.hostname);
70
+ const context_href = context_location.href;
68
71
  return {
69
72
  tool: linkText_parse,
70
73
  destination_domain: parseDestination(linkText),
@@ -1,11 +1,14 @@
1
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
1
+ var __esm = (fn, res, err) => () => {
2
+ if (fn)
3
+ try {
4
+ res = fn(fn = 0);
5
+ } catch (e) {
6
+ err = [e];
7
+ }
8
+ if (err)
9
+ throw err[0];
10
+ return res;
11
+ };
9
12
 
10
13
  // wallet-api/actionlog/actionLogTypes.ts
11
14
  var TERMINAL_EVENT_TYPES;
@@ -351,9 +354,9 @@ class TinyWASI {
351
354
  const buffers = [];
352
355
  for (let i = 0;i < iovsLen; i++) {
353
356
  const iov = iovs + i * 8;
354
- const offset2 = view.getUint32(iov, true);
357
+ const offset = view.getUint32(iov, true);
355
358
  const len = view.getUint32(iov + 4, true);
356
- buffers.push(new Uint8Array(memory.buffer, offset2, len));
359
+ buffers.push(new Uint8Array(memory.buffer, offset, len));
357
360
  }
358
361
  const length = buffers.reduce((s, b) => s + b.length, 0);
359
362
  const buffer = new Uint8Array(length);
@@ -668,8 +671,8 @@ async function getBlocksBinScanResponse(processor, getBlocksBinResponseBuffer, m
668
671
  resultMeta = JSON.parse(processor.readString(ptr, len));
669
672
  if (metaCallBack)
670
673
  metaCallBack(resultMeta);
671
- processor.readFromWasmMemory = (ptr2, len2) => {
672
- result = JSON.parse(processor.readString(ptr2, len2), (key, value) => {
674
+ processor.readFromWasmMemory = (ptr, len) => {
675
+ result = JSON.parse(processor.readString(ptr, len), (key, value) => {
673
676
  if (key === "amount")
674
677
  return BigInt(value);
675
678
  return value;
@@ -1113,8 +1116,8 @@ function makeInput(processor, outputToBeSpent, candidates, get_outs_Response) {
1113
1116
  });
1114
1117
  processor.writeToWasmMemory = (ptr, len) => {
1115
1118
  processor.writeString(ptr, len, makeInputArgs);
1116
- processor.writeToWasmMemory = (ptr2, len2) => {
1117
- processor.writeArray(ptr2, len2, get_outs_Response);
1119
+ processor.writeToWasmMemory = (ptr, len) => {
1120
+ processor.writeArray(ptr, len, get_outs_Response);
1118
1121
  };
1119
1122
  };
1120
1123
  let result = null;
@@ -1408,8 +1411,8 @@ class ViewPair extends WasmProcessor {
1408
1411
  const tinywasi = await viewPair.initWasmModule(await getMoneroWasmBytes());
1409
1412
  viewPair.writeToWasmMemory = (ptr, len) => {
1410
1413
  viewPair.writeString(ptr, len, primary_address);
1411
- viewPair.writeToWasmMemory = (ptr2, len2) => {
1412
- viewPair.writeString(ptr2, len2, secret_view_key);
1414
+ viewPair.writeToWasmMemory = (ptr, len) => {
1415
+ viewPair.writeString(ptr, len, secret_view_key);
1413
1416
  };
1414
1417
  };
1415
1418
  let init_viewpair_result = undefined;
@@ -1559,8 +1562,8 @@ async function computeKeyImage(output, sender_spend_key, wasmProcessor) {
1559
1562
  wasmProcessor = await WasmProcessor.init(await getMoneroWasmBytes());
1560
1563
  wasmProcessor.writeToWasmMemory = (ptr, len) => {
1561
1564
  wasmProcessor.writeString(ptr, len, output.serialized);
1562
- wasmProcessor.writeToWasmMemory = (ptr2, len2) => {
1563
- wasmProcessor.writeString(ptr2, len2, sender_spend_key);
1565
+ wasmProcessor.writeToWasmMemory = (ptr, len) => {
1566
+ wasmProcessor.writeString(ptr, len, sender_spend_key);
1564
1567
  };
1565
1568
  };
1566
1569
  let result = undefined;
@@ -1839,8 +1842,8 @@ function connectionStatusFilePath(scan_settings_path = SCAN_SETTINGS_STORE_NAME_
1839
1842
  async function readConnectionStatusDefaultLocation(scan_settings_path) {
1840
1843
  return await readConnectionStatusFile(connectionStatusFilePath(scan_settings_path));
1841
1844
  }
1842
- async function readConnectionStatusFile(connectionStatusFilePath2) {
1843
- const jsonString = await Bun.file(connectionStatusFilePath2).text().catch(() => {
1845
+ async function readConnectionStatusFile(connectionStatusFilePath) {
1846
+ const jsonString = await Bun.file(connectionStatusFilePath).text().catch(() => {
1844
1847
  return;
1845
1848
  });
1846
1849
  return jsonString ? JSON.parse(jsonString) : undefined;
@@ -13336,7 +13339,7 @@ async function handleCpuboundScan(msg, cpu_worker_status) {
13336
13339
  const first_block_meta = item.batch.get_blocks_result_meta.block_infos[0];
13337
13340
  if (!first_block_meta)
13338
13341
  throw new Error("no first block meta");
13339
- const scanResult2 = {
13342
+ const scanResult = {
13340
13343
  outputs: [],
13341
13344
  all_key_images: [],
13342
13345
  new_height: first_block_meta.block_height + item.from,
@@ -13350,9 +13353,9 @@ async function handleCpuboundScan(msg, cpu_worker_status) {
13350
13353
  const blockResult = await viewpair.getBlocksBinScanOneBlock(i);
13351
13354
  if ("error" in blockResult)
13352
13355
  throw new Error(blockResult.error);
13353
- scanResult2.outputs.push(...blockResult.outputs);
13354
- scanResult2.all_key_images.push(...blockResult.all_key_images);
13355
- scanResult2.new_height = first_block_meta.block_height + i;
13356
+ scanResult.outputs.push(...blockResult.outputs);
13357
+ scanResult.all_key_images.push(...blockResult.all_key_images);
13358
+ scanResult.new_height = first_block_meta.block_height + i;
13356
13359
  blockCount++;
13357
13360
  if (blockCount % 10 === 0) {
13358
13361
  log("handleCpuboundScan", [
@@ -13380,7 +13383,7 @@ async function handleCpuboundScan(msg, cpu_worker_status) {
13380
13383
  return {
13381
13384
  type: "Ready",
13382
13385
  work_uuid: item.work_uuid,
13383
- result: scanResult2
13386
+ result: scanResult
13384
13387
  };
13385
13388
  }
13386
13389
  function handleCpuboundScanTry(msg, cpu_worker_status) {
@@ -14015,11 +14018,11 @@ var handleMessage = async (e) => {
14015
14018
  cpuPort = e.ports[0];
14016
14019
  if (cpuPort) {
14017
14020
  cpuPort.onmessage = CPU_PORT_HANDLER;
14018
- cpuPort.addEventListener("message", (e2) => {
14019
- log("handleMessage", ["message received", e2]);
14021
+ cpuPort.addEventListener("message", (e) => {
14022
+ log("handleMessage", ["message received", e]);
14020
14023
  });
14021
- cpuPort.addEventListener("messageerror", (e2) => {
14022
- log("handleMessage", ["messageerror received", e2]);
14024
+ cpuPort.addEventListener("messageerror", (e) => {
14025
+ log("handleMessage", ["messageerror received", e]);
14023
14026
  });
14024
14027
  }
14025
14028
  } else if (msg.role === "coordinator") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spirobel/monero-wallet-api",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "main": "dist/xmr3.js",
5
5
  "module": "dist/xmr3.js",
6
6
  "devDependencies": {