fedipod 1.7.0 → 1.8.0

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/web/app/boot.mjs CHANGED
@@ -16,7 +16,7 @@ import { podBaseOfWebId } from '../../lib/pod/urls.mjs';
16
16
  import { podLayout } from '../../lib/pod/root.mjs';
17
17
  import { BrowserRemotePod } from './pod-remote.mjs';
18
18
  import { beginLogin, completeLogin, getSession, signOut } from './oidc-session.mjs';
19
- import { unwrapKeys, isKeyEnvelope } from './keystore.mjs';
19
+ import { generateKeys, wrapKeys, unwrapKeys, isKeyEnvelope } from './keystore.mjs';
20
20
  import { cacheOpenedKeys } from './keys-browser.mjs';
21
21
 
22
22
  const REDIRECT = `${location.origin}/`; // the app root doubles as the OIDC callback
@@ -64,30 +64,50 @@ async function bootWorker({ reset = false } = {}) {
64
64
  //
65
65
  // The unwrap happens HERE, in the page, and not in the worker: the worker boots
66
66
  // itself whenever the browser restarts it, with nobody present to type anything.
67
- window.fedipodUnlock = async (password) => {
68
- if (!password) throw new Error('Enter your account password.');
67
+ //
68
+ // Both paths below read the account's config and key the same way: with the
69
+ // session, as the owner, through the transport rather than the bare session —
70
+ // a pod read like any other, with the retry ladder that exists because the pod
71
+ // host throttles bursts.
72
+ async function readAccountState() {
69
73
  const session = await getSession();
70
74
  if (!session) throw new Error('Sign in first.');
71
- // The config on the pod says where this account's state lives; the key sits
72
- // beside it. Both are read with the session, as the owner.
73
75
  const podFromWebId = podBaseOfWebId(session.webId); // a suffix-based host, or its own host
74
76
  const state = `${podFromWebId}${AP_ROOT}ap-state/`;
75
- // Through the transport rather than the bare session: this is a pod read
76
- // like any other, and going round it skipped the retry ladder that exists
77
- // because the pod host throttles bursts.
78
77
  const remote = new BrowserRemotePod(session, { webId: session.webId, role: 'signup', log: () => {} });
79
78
  const urls = { state };
80
79
  const [cfg, doc] = await Promise.all([
81
80
  podState.readConfig(remote, urls), podState.readWrappedKeys(remote, urls),
82
81
  ]);
83
- if (!cfg || !doc) throw new Error(`could not read this account's config and key under ${state}`);
82
+ if (!cfg) throw new Error(`could not read this account's config under ${state}`);
83
+ const actorUrl = `${cfg.remotePod}${cfg.root || AP_ROOT}ap/actor`;
84
+ return { remote, urls, cfg, doc, actorUrl };
85
+ }
86
+
87
+ window.fedipodUnlock = async (password) => {
88
+ if (!password) throw new Error('Enter your password.');
89
+ const { doc, actorUrl } = await readAccountState();
90
+ if (!doc) throw new Error('could not read this account\'s key on the pod');
84
91
  if (!isKeyEnvelope(doc)) throw new Error('this account\'s key is not locked — nothing to unlock');
85
92
  const rec = await unwrapKeys(doc, password); // throws 'wrong password'
86
- const actorUrl = `${cfg.remotePod}${cfg.root || AP_ROOT}ap/actor`;
87
93
  await cacheOpenedKeys(actorUrl, rec);
88
94
  await bootWorker();
89
95
  };
90
96
 
97
+ // The same pane, for someone who no longer has the sign-up password: a new key,
98
+ // wrapped under the password they use now, written over the pod's copy. Nothing
99
+ // is unwrapped, so the old password is never needed. The boot that follows
100
+ // publishes the new public key (agent.goActive → publishProfile).
101
+ window.fedipodNewKey = async (password) => {
102
+ if (!password) throw new Error('Enter the password you use for your pod now.');
103
+ const { remote, urls, cfg, actorUrl } = await readAccountState();
104
+ const keys = await generateKeys();
105
+ keys.mintedFor = cfg.gateway?.frontActor || actorUrl; // one key, one actor (signup.mjs)
106
+ await podState.writeWrappedKeys(remote, urls, await wrapKeys(keys, password));
107
+ await cacheOpenedKeys(actorUrl, keys);
108
+ await bootWorker();
109
+ };
110
+
91
111
  // New account: create the account, pod, key, config and gateway attach (this
92
112
  // needs the password once), then redirect to the pod's login to establish the
93
113
  // durable session. The agent boots on return, reading config + key from the pod.
@@ -213,6 +233,25 @@ if (typeof document !== 'undefined') (async () => {
213
233
  };
214
234
  $('unlock-go')?.addEventListener('click', doUnlock);
215
235
  $('unlock-password')?.addEventListener('keydown', (e) => { if (e.key === 'Enter') doUnlock(); });
236
+ // The new-key path: one click reveals the confirmation, the second acts.
237
+ $('unlock-newkey')?.addEventListener('click', () => {
238
+ $('unlock-newkey-confirm').hidden = false;
239
+ $('unlock-password').focus();
240
+ });
241
+ const doNewKey = async () => {
242
+ $('unlock-error').textContent = '';
243
+ const btn = $('unlock-newkey-go'); btn.disabled = true;
244
+ try {
245
+ await window.fedipodNewKey($('unlock-password').value);
246
+ $('unlock-password').value = '';
247
+ location.href = '/admin/client/';
248
+ } catch (err) {
249
+ $('unlock-error').textContent = err.message || String(err);
250
+ btn.disabled = false;
251
+ $('unlock-password').select();
252
+ }
253
+ };
254
+ $('unlock-newkey-go')?.addEventListener('click', doNewKey);
216
255
 
217
256
 
218
257
  // The client shell's bar returns here for two things, and neither continues
@@ -33075,7 +33075,7 @@ var PodTransport = class {
33075
33075
  * says all of it. The parsed graph must mention the WebID before anything is
33076
33076
  * written back — an empty or foreign body must never become the new profile.
33077
33077
  */
33078
- async linkAccountInProfile({ actorUrl, accountName, kind = "person" }) {
33078
+ async linkAccountInProfile({ actorUrl, accountName, kind = "person", outbox = null }) {
33079
33079
  const docUrl = this.webId.split("#")[0];
33080
33080
  const res = await this.fetch(docUrl, { headers: { accept: "text/turtle" } });
33081
33081
  if (res.status >= 400) throw new Error(`[${this.label}] GET ${docUrl} \u2192 ${res.status}`);
@@ -33091,10 +33091,16 @@ var PodTransport = class {
33091
33091
  [me, FOAF("account"), actor],
33092
33092
  [actor, RDF3("type"), FOAF("OnlineAccount")],
33093
33093
  [actor, RDF3("type"), kind === "group" ? AS("Group") : AS("Person")],
33094
- [actor, FOAF("accountName"), literal2(accountName)]
33094
+ [actor, FOAF("accountName"), literal2(accountName)],
33095
+ // Where a Solid client posts on this person's behalf (`as:outbox` on the
33096
+ // WebID is what dokieli reads); only where a door exists to take it.
33097
+ ...outbox ? [[me, AS("outbox"), namedNode2(outbox)]] : []
33095
33098
  ];
33096
33099
  const missing = wanted.filter(([s, p, o]) => !g.holds(s, p, o, doc));
33097
- const stale = g.statementsMatching(actor, FOAF("accountName"), null, doc).filter((st2) => st2.object.value !== accountName);
33100
+ const stale = [
33101
+ ...g.statementsMatching(actor, FOAF("accountName"), null, doc).filter((st2) => st2.object.value !== accountName),
33102
+ ...outbox ? g.statementsMatching(me, AS("outbox"), null, doc).filter((st2) => st2.object.value !== outbox) : []
33103
+ ];
33098
33104
  if (!missing.length && !stale.length) return false;
33099
33105
  const deletes = stale.map((st2) => [st2.subject, st2.predicate, st2.object]);
33100
33106
  if (await this.patchDocument(docUrl, missing, deletes)) return true;
@@ -33202,6 +33208,7 @@ var BrowserRemotePod = class extends PodTransport {
33202
33208
  // lib/pod/state.mjs
33203
33209
  var readWrappedKeys = (pod, urls) => pod.getJson(urls.state + "keys.json");
33204
33210
  var readConfig = (pod, urls) => pod.getJson(urls.state + "config.json");
33211
+ var writeWrappedKeys = (pod, urls, envelope) => pod.putJson(urls.state + "keys.json", envelope, "application/json");
33205
33212
  var writeConfig = (pod, urls, config) => pod.putJson(urls.state + "config.json", config, "application/json");
33206
33213
  async function provisionKey(pod, { stateUrl, keysUrl, envelope }) {
33207
33214
  await pod.setAcl(stateUrl, []);
@@ -33737,8 +33744,7 @@ async function bootWorker({ reset = false } = {}) {
33737
33744
  worker.postMessage({ type: "boot", frontOrigin: location.origin });
33738
33745
  await booted;
33739
33746
  }
33740
- window.fedipodUnlock = async (password) => {
33741
- if (!password) throw new Error("Enter your account password.");
33747
+ async function readAccountState() {
33742
33748
  const session = await getSession();
33743
33749
  if (!session) throw new Error("Sign in first.");
33744
33750
  const podFromWebId = podBaseOfWebId(session.webId);
@@ -33750,13 +33756,28 @@ window.fedipodUnlock = async (password) => {
33750
33756
  readConfig(remote, urls),
33751
33757
  readWrappedKeys(remote, urls)
33752
33758
  ]);
33753
- if (!cfg || !doc) throw new Error(`could not read this account's config and key under ${state}`);
33759
+ if (!cfg) throw new Error(`could not read this account's config under ${state}`);
33760
+ const actorUrl = `${cfg.remotePod}${cfg.root || AP_ROOT}ap/actor`;
33761
+ return { remote, urls, cfg, doc, actorUrl };
33762
+ }
33763
+ window.fedipodUnlock = async (password) => {
33764
+ if (!password) throw new Error("Enter your password.");
33765
+ const { doc, actorUrl } = await readAccountState();
33766
+ if (!doc) throw new Error("could not read this account's key on the pod");
33754
33767
  if (!isKeyEnvelope(doc)) throw new Error("this account's key is not locked \u2014 nothing to unlock");
33755
33768
  const rec = await unwrapKeys(doc, password);
33756
- const actorUrl = `${cfg.remotePod}${cfg.root || AP_ROOT}ap/actor`;
33757
33769
  await cacheOpenedKeys(actorUrl, rec);
33758
33770
  await bootWorker();
33759
33771
  };
33772
+ window.fedipodNewKey = async (password) => {
33773
+ if (!password) throw new Error("Enter the password you use for your pod now.");
33774
+ const { remote, urls, cfg, actorUrl } = await readAccountState();
33775
+ const keys = await generateKeys();
33776
+ keys.mintedFor = cfg.gateway?.frontActor || actorUrl;
33777
+ await writeWrappedKeys(remote, urls, await wrapKeys(keys, password));
33778
+ await cacheOpenedKeys(actorUrl, keys);
33779
+ await bootWorker();
33780
+ };
33760
33781
  window.fedipodSignup = async ({ onStep, ...answers }) => {
33761
33782
  await signUp(answers, { onStep, frontOrigin: location.origin });
33762
33783
  const { authorizationUrl } = await beginLogin({ issuer: answers.issuer, redirectUri: REDIRECT });
@@ -33861,6 +33882,25 @@ if (typeof document !== "undefined") (async () => {
33861
33882
  $("unlock-password")?.addEventListener("keydown", (e) => {
33862
33883
  if (e.key === "Enter") doUnlock();
33863
33884
  });
33885
+ $("unlock-newkey")?.addEventListener("click", () => {
33886
+ $("unlock-newkey-confirm").hidden = false;
33887
+ $("unlock-password").focus();
33888
+ });
33889
+ const doNewKey = async () => {
33890
+ $("unlock-error").textContent = "";
33891
+ const btn = $("unlock-newkey-go");
33892
+ btn.disabled = true;
33893
+ try {
33894
+ await window.fedipodNewKey($("unlock-password").value);
33895
+ $("unlock-password").value = "";
33896
+ location.href = "/admin/client/";
33897
+ } catch (err) {
33898
+ $("unlock-error").textContent = err.message || String(err);
33899
+ btn.disabled = false;
33900
+ $("unlock-password").select();
33901
+ }
33902
+ };
33903
+ $("unlock-newkey-go")?.addEventListener("click", doNewKey);
33864
33904
  if (params.has("signout") || params.has("add")) {
33865
33905
  if (params.has("signout")) {
33866
33906
  try {