@decentnetwork/beagle 0.1.59 → 0.1.60

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.
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.59";
1
+ window.__DK_UI_VERSION="0.1.60";
2
2
  "use strict";
3
3
  (() => {
4
4
  // packages/beagle-ui/dist/beagle-ui.js
@@ -4983,7 +4983,8 @@ ${peer.address}`
4983
4983
  onTakeover: () => window.BeagleWeb.takeover().then((st) => {
4984
4984
  data.refresh();
4985
4985
  return st;
4986
- })
4986
+ }),
4987
+ onLocate: () => window.BeagleWeb.locate()
4987
4988
  }
4988
4989
  ), !data.locked && welcome && /* @__PURE__ */ React.createElement(
4989
4990
  DkWelcome,
package/dist/server.js CHANGED
@@ -55,7 +55,7 @@ async function fetchDiscoverJson(url) {
55
55
  // ── beagles.eth names (ens-gateway worker) ──────────────────────────────────
56
56
  // The same registry the mobile apps register into. Web-side registration
57
57
  // signs the record with THIS node's Carrier identity (XEdDSA via the backend
58
- // `sign` op) — the gateway verifies it the same way Sign in with Decent does.
58
+ // `sign` op) — the gateway verifies it the same way Sign in with Beagle does.
59
59
  const ENS_GATEWAY = process.env.BEAGLE_ENS_GATEWAY || "https://ens-gateway.beaglechat.workers.dev";
60
60
  async function ensFetchJson(path) {
61
61
  const ctl = new AbortController();
@@ -414,7 +414,7 @@ function findSavedFile(downloadsDir, name) {
414
414
  return null;
415
415
  }
416
416
  /** True only when the request came from the local machine. Used to gate the
417
- * "Sign in with Decent" routes so binding the UI to a LAN IP can't expose
417
+ * "Sign in with Beagle" routes so binding the UI to a LAN IP cannot expose
418
418
  * identity signing to other hosts. The popup always runs in the local user's
419
419
  * browser, so it connects over the loopback interface. */
420
420
  function isLocalRequest(req) {
@@ -508,7 +508,7 @@ function validateOrigin(raw) {
508
508
  return null;
509
509
  }
510
510
  }
511
- // The "Sign in with Decent" consent popup. Self-contained (no external assets),
511
+ // The "Sign in with Beagle" consent popup. Self-contained (no external assets),
512
512
  // dark theme matching the desktop UI. Reads origin+nonce from its own query,
513
513
  // shows the requesting site and this node's identity, and on Approve calls the
514
514
  // local /api/connect-approve to sign, then postMessages the result to the
@@ -517,7 +517,7 @@ function validateOrigin(raw) {
517
517
  const CONNECT_PAGE = `<!doctype html>
518
518
  <html lang="en"><head><meta charset="utf-8">
519
519
  <meta name="viewport" content="width=device-width,initial-scale=1">
520
- <title>Sign in with Decent</title>
520
+ <title>Sign in with Beagle</title>
521
521
  <style>
522
522
  :root{--bg:#0c0d11;--panel:#14161d;--line:#262a35;--text:#e7e9ef;--faint:#8b91a3;
523
523
  --accent:#5b8cff;--good:#46a758;--bad:#e5604d;--mono:ui-monospace,SFMono-Regular,Menlo,monospace}
@@ -534,7 +534,9 @@ const CONNECT_PAGE = `<!doctype html>
534
534
  .origin{color:var(--text);font-weight:600;word-break:break-all}
535
535
  .id{background:#0e1016;border:1px solid var(--line);border-radius:10px;padding:11px 12px;margin-bottom:14px}
536
536
  .lbl{font-size:11px;text-transform:uppercase;letter-spacing:.6px;color:var(--faint);margin-bottom:4px}
537
+ .who{font-size:13.5px;font-weight:600;margin-bottom:3px}
537
538
  .userid{font-family:var(--mono);font-size:12.5px;color:var(--text);word-break:break-all}
539
+ [hidden]{display:none !important}
538
540
  .err{background:rgba(229,96,77,.12);border:1px solid rgba(229,96,77,.4);color:#ffb4a8;
539
541
  border-radius:9px;padding:9px 11px;font-size:12.5px;margin-bottom:13px}
540
542
  .row{display:flex;gap:10px;margin-top:4px}
@@ -547,10 +549,14 @@ const CONNECT_PAGE = `<!doctype html>
547
549
  </style></head>
548
550
  <body>
549
551
  <div class="card">
550
- <div class="brand"><span class="d"></span>Decent</div>
552
+ <div class="brand"><span class="d"></span>Beagle</div>
551
553
  <h1>Sign in</h1>
552
- <p class="sub"><span id="origin" class="origin">…</span> wants to sign you in with your Decent identity.</p>
553
- <div class="id"><div class="lbl">Your identity</div><div id="userid" class="userid">loading…</div></div>
554
+ <p class="sub"><span id="origin" class="origin">…</span> wants to sign you in with your Beagle identity.</p>
555
+ <div class="id">
556
+ <div class="lbl">Your identity</div>
557
+ <div id="who" class="who" hidden></div>
558
+ <div id="userid" class="userid">loading…</div>
559
+ </div>
554
560
  <div id="err" class="err" hidden></div>
555
561
  <div class="row">
556
562
  <button id="deny" class="btn ghost">Deny</button>
@@ -572,10 +578,11 @@ const CONNECT_PAGE = `<!doctype html>
572
578
  if(!validOrigin) fail("This sign-in request has an invalid origin and was blocked.");
573
579
  if(nonce.length===0||nonce.length>512){ validOrigin=false; fail("This sign-in request is missing a valid nonce."); }
574
580
  fetch("/api/state").then(function(r){return r.json();}).then(function(s){
575
- var uid=(s.me&&s.me.userid)||"";
581
+ var uid=(s.me&&s.me.userid)||"", nm=(s.me&&s.me.name)||"";
576
582
  document.getElementById("userid").textContent=uid||"(no identity)";
583
+ if(nm){var w=document.getElementById("who"); w.textContent=nm; w.hidden=false;}
577
584
  if(uid&&validOrigin) approve.disabled=false;
578
- else if(!uid) fail("No local Decent identity found — is the daemon running?");
585
+ else if(!uid) fail("No local Beagle identity found — is the daemon running?");
579
586
  }).catch(function(){ fail("Could not reach the local agentnet daemon."); });
580
587
  deny.onclick=function(){ reply({error:"denied"}); setTimeout(function(){window.close();},60); };
581
588
  approve.onclick=function(){
@@ -584,7 +591,7 @@ const CONNECT_PAGE = `<!doctype html>
584
591
  body:JSON.stringify({origin:origin,nonce:nonce})})
585
592
  .then(function(r){return r.json();})
586
593
  .then(function(j){ if(!j.ok) throw new Error(j.error||"sign failed");
587
- reply({userid:j.userid,sig:j.sig}); setTimeout(function(){window.close();},60); })
594
+ reply({userid:j.userid,sig:j.sig,name:j.name,avatar:j.avatar}); setTimeout(function(){window.close();},60); })
588
595
  .catch(function(e){ approve.disabled=false; approve.textContent="Approve"; fail("Signing failed: "+e.message); });
589
596
  };
590
597
  })();
@@ -679,7 +686,7 @@ export function startBeagleServer(opts) {
679
686
  res.end("not found");
680
687
  return;
681
688
  }
682
- // ── Sign in with Decent ────────────────────────────────────────────
689
+ // ── Sign in with Beagle ────────────────────────────────────────────
683
690
  // A website opens http://localhost:8765/connect?origin=…&nonce=… in a
684
691
  // popup; on Approve we sign "decent-auth\n<origin>\n<nonce>" with this
685
692
  // node's Carrier identity and postMessage {userid,nonce,sig} back to the
@@ -690,7 +697,7 @@ export function startBeagleServer(opts) {
690
697
  if (url === "/connect" || url === "/api/connect-approve") {
691
698
  if (!isLocalRequest(req)) {
692
699
  res.writeHead(403, { "content-type": "text/plain" });
693
- res.end("Sign in with Decent is available only on this machine (localhost).");
700
+ res.end("Sign in with Beagle is available only on this machine (localhost).");
694
701
  return;
695
702
  }
696
703
  }
@@ -719,11 +726,30 @@ export function startBeagleServer(opts) {
719
726
  sendJson(res, 502, { ok: false, error: r.error || "sign failed" });
720
727
  return;
721
728
  }
722
- sendJson(res, 200, {
723
- ok: true,
724
- userid: r.data?.userid ?? "",
725
- sig: r.data?.sig ?? "",
726
- });
729
+ const userid = r.data?.userid ?? "";
730
+ // Name and avatar ride along so the site can render the person without
731
+ // a second lookup it has no way to make — nothing public maps a userid
732
+ // to a display name unless that user registered a beagles.eth name.
733
+ // Additive: a caller that ignores them behaves exactly as before, and
734
+ // neither is part of what the signature proves.
735
+ let name = "";
736
+ let avatar = null;
737
+ try {
738
+ const diag = await opts.call({ op: "diag" });
739
+ name = ((diag.ok ? diag.data : {})?.node?.name) ?? "";
740
+ const pub = (await ensPublicByUserid(1200)).get(userid);
741
+ if (pub) {
742
+ if (!name)
743
+ name = pub.displayName ?? "";
744
+ avatar = pub.avatarUrl ?? null;
745
+ if (!avatar && pub.punkId != null) {
746
+ const punk = await punksFetch(`/api/punks/${pub.punkId}`).catch(() => null);
747
+ avatar = punk?.image ?? null;
748
+ }
749
+ }
750
+ }
751
+ catch { /* identity is what matters; the trimmings are best-effort */ }
752
+ sendJson(res, 200, { ok: true, userid, sig: r.data?.sig ?? "", name, avatar });
727
753
  return;
728
754
  }
729
755
  // ── beagles.eth name registration ──
@@ -1321,9 +1347,13 @@ export function startBeagleServer(opts) {
1321
1347
  const d = diag.ok ? (diag.data ?? {}) : {};
1322
1348
  const identity = d.identity ?? {};
1323
1349
  const tun = d.tun ?? {};
1350
+ const node = d.node ?? {};
1324
1351
  const me = {
1325
1352
  userid: identity.userid,
1326
1353
  address: identity.address,
1354
+ // The sign-in popup shows this above the key: a userid alone does not
1355
+ // tell you which of your identities is about to answer.
1356
+ name: node.name ?? "",
1327
1357
  // The configured TUN address is what this host can actually route.
1328
1358
  // Prefer it over a stale init/default allocation during Dora outage.
1329
1359
  ip: tun.ip ?? d.allocatedIp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "yargs": "^17.7.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@decentnetwork/beagle-ui": "0.1.0",
36
+ "@decentnetwork/beagle-ui": "0.1.1",
37
37
  "@types/js-yaml": "^4.0.9",
38
38
  "@types/node": "^20.11.0",
39
39
  "@types/yargs": "^17.0.32",