@witbitz/sdk 4.8.0 → 4.9.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/idbSeal.js CHANGED
@@ -23,7 +23,9 @@ import { makeNamer, isOpaqueName } from './sealedNames.js'
23
23
  // `devkey:v1` (devices.js) keeps its name and is never sealed either: it holds a NON-EXTRACTABLE CryptoKey, which no page
24
24
  // or disk copy can turn into bytes, so sealing protects nothing — and sealing is JSON, which turned the key into `{}` (every
25
25
  // protected device lost its device key at switch-on; account recovery v2's staging test, 2026-11-14).
26
- export const IDB_SHARED_NAMES = Object.freeze(['notifTap', 'notifPreview', 'protectedNames', 'swTrail', 'codeRemindKey', 'devkey:v1', 'blocks:sw', 'chatlocked:sw'])
26
+ // sync sweep 2026-12-04 O11: + `pushDirectAllowed` (Hide my IP's push flag, a boolean): the notification and key workers read it by
27
+ // its real name — renamed at switch-on, the key worker read "absent" and sent its traffic direct while Hide my IP was on.
28
+ export const IDB_SHARED_NAMES = Object.freeze(['notifTap', 'notifPreview', 'protectedNames', 'swTrail', 'codeRemindKey', 'devkey:v1', 'blocks:sw', 'chatlocked:sw', 'pushDirectAllowed'])
27
29
  const naming = { on: false, key: null, namer: null }
28
30
  /** { on, key (CryptoKey for values), namer (sealedNames.makeNamer) } — on without a namer = locked. */
29
31
  export function setIdbNaming ({ on = false, key = null, namer = null } = {}) { naming.on = !!on; naming.key = key; naming.namer = namer }
@@ -97,7 +99,7 @@ export async function migrateIdbProtection (idb, rawKey) {
97
99
  /** Switch off: open every sealed protected entry and write it back in the clear, one at a time; then pass-through. */
98
100
  export async function unprotectIdb (idb, rawKey) {
99
101
  const key = await importRaw(rawKey), namer = await makeNamer(rawKey)
100
- for (const o of await idb.keysRaw('p:')) { const name = await namer.real(o); const v = await idb.getRaw(o); if (name != null && v != null) { let back; try { back = await open(key, v) } catch { back = undefined /* junk: dropped */ } if (back !== undefined) { await idb.setRaw(name, back); if ((await idb.getRaw(name)) == null) continue /* not written: the sealed copy stays (side sweep) */ } } await idb.delRaw(o) } // back under real names (the key worker opens its own keys after)
102
+ for (const o of await idb.keysRaw('p:')) { const name = await namer.real(o); const v = await idb.getRaw(o); if (name != null && IDB_SHARED_NAMES.includes(name) && (await idb.getRaw(name)) != null) { await idb.delRaw(o); continue } /* sync sweep 2026-12-04 O11: a shared name renamed by an older build — the live copy under the real name wins over that stale one */ if (name != null && v != null) { let back; try { back = await open(key, v) } catch { back = undefined /* junk: dropped */ } if (back !== undefined) { await idb.setRaw(name, back); if ((await idb.getRaw(name)) == null) continue /* not written: the sealed copy stays (side sweep) */ } } await idb.delRaw(o) } // back under real names (the key worker opens its own keys after)
101
103
  for (const k of await protectedKeys(idb)) { const v = await idb.getRaw(k); if (isSealed(v)) { try { await idb.setRaw(k, await openIf(key, v)) } catch { await idb.delRaw(k) } } } // an entry the key cannot open is junk: drop it
102
104
  try { await idb.delRaw('protectedNames') } catch { /* */ }
103
105
  setIdbProtection({ active: false, key: null })
package/inviteReceive.js CHANGED
@@ -2,9 +2,10 @@
2
2
  // and hand the recovered { room, mk, title, from } to onInvite (which adds it to your Space list when it's new). The
3
3
  // inbox is append-only, so this re-reads every box each poll — onInvite MUST be idempotent (no-op a room you already
4
4
  // have or have deleted; recents + tombstones are the dedup). onInvite returns truthy when it actually added a room.
5
+ import { validPilotHandoff, isSealedAppRoom, sealedAppRoomFromHash } from './sealedRoomWire.js'
5
6
  import { openBox } from './e2ee.js'
6
7
 
7
- export async function checkInbox({ client, inviteKey, onInvite }) {
8
+ export async function checkInbox({ client, inviteKey, onInvite, onSealedPilotInvite }) {
8
9
  if (!client || !inviteKey || !inviteKey.inbox || !inviteKey.boxPriv || typeof onInvite !== 'function') return 0
9
10
  const r = await client.inboxFetch(inviteKey.inbox, 0)
10
11
  if (!r || r.status !== 200 || !Array.isArray(r.boxes)) return -1 // NOT READ (offline, refused): -1, so a caller can tell it from "nothing new" (emailInvites.js pollInbox's first pass)
@@ -15,6 +16,19 @@ export async function checkInbox({ client, inviteKey, onInvite }) {
15
16
  if (!plain) continue
16
17
  let inv = null
17
18
  try { inv = JSON.parse(plain) } catch { continue }
19
+ if (inv?.v === 3 || inv && Object.hasOwn(inv, 'sealedRoom')) {
20
+ if (inv.v === 3 && Object.keys(inv).length === 2 && validPilotHandoff(inv.sealedRoom) && onSealedPilotInvite) {
21
+ try { if (await onSealedPilotInvite(inv.sealedRoom)) added++ } catch { /* retry at the next inbox read */ }
22
+ }
23
+ continue
24
+ }
25
+ if (isSealedAppRoom(inv?.room)) continue
26
+ if (typeof inv?.link === 'string') {
27
+ try {
28
+ const url = new URL(inv.link)
29
+ if (isSealedAppRoom(url.searchParams.get('room')) || sealedAppRoomFromHash(url.hash)) continue
30
+ } catch { /* older invites can use their explicit room and key */ }
31
+ }
18
32
  if (!inv || !inv.room || (!inv.mk && !inv.link && !inv.us)) continue // a SPLIT invite carries the key in `link` (#us=), not `mk` — onInvite reverse-parses it; an ATTESTED split invite carries `us` itself (2026-11-24: skipped here, never reached onInvite)
19
33
  try { if (await onInvite(inv)) added++ } catch { /* one bad invite must not stop the rest */ }
20
34
  }
package/inviteSend.js CHANGED
@@ -5,6 +5,8 @@
5
5
  // name, and an anonymous ciphertext landing in some inbox — never the email, the room, or the key.
6
6
  import { resolveHandle, usernameSlotApp } from './inviteEnroll.js' // ⛔ THIS address: the vault sets the hosted app's directory scope on it (setDirScope); its build leaves a plain './inviteEnroll.js' plain = a second, unscoped copy, and every invitee was looked up in the regular app's directory (2026-11-17; vaultModuleOneAddress.test.mjs)
7
7
  import { validUsername } from './address.js'
8
+ import { isSealedAppRoom, validPilotHandoff } from './sealedRoomWire.js'
9
+ import { boxApp } from './attestedBox.js'
8
10
  import { sealTo } from './e2ee.js'
9
11
 
10
12
  // ≡ agent/spaceHandlerCommon.mjs appTag: the names a directory slot can have
@@ -58,6 +60,10 @@ export async function sendInvite({ email, username, room, mk, title, from, gate,
58
60
  // EITHER an mk or a link is present. (`mk` is still delivered for a plain room, and as a v1 fallback field below.)
59
61
  // AN ATTESTED SPLIT ROOM (the hosted app's — 2026-11-24, every attested invite there failed bad_args): no mk and no link, the user
60
62
  // share and its commitment instead — only into an attested kind's box (an ordinary split room's invite is its link)
63
+ if (isSealedAppRoom(room)) {
64
+ if (kind !== 'attested' || !enc || link || us || (gate && gate !== 'email') || scope) return { ok: false, reason: 'unsupported_sealed_invite' }
65
+ return sendSealedPilotInvite({ email, username, room, mk, gate, client })
66
+ }
61
67
  if (us && !kind) return { ok: false, reason: 'bad_args' }
62
68
  if ((!email && !username) || !room || (!mk && !link && !us) || !client) return { ok: false, reason: 'bad_args' }
63
69
  const f = await findInvitee({ email, username, app, scope }, client)
@@ -67,8 +73,22 @@ export async function sendInvite({ email, username, room, mk, title, from, gate,
67
73
  // so no field is ever hand-dropped again (that was the "synced, can't open" bug — the gate marker went missing). room/mk
68
74
  // /gate are ALSO carried for now so a not-yet-updated recipient (a v1 reader) still works during rollout.
69
75
  const box = await sealTo(JSON.stringify({ v: 2, ...(link ? { link } : {}), room, ...(mk ? { mk } : {}), ...(us ? { us: String(us), ...(spc ? { spc: String(spc) } : {}) } : {}), ...(gate ? { gate } : {}), title: title || '', from: from || '', ...(kind ? { kind, ...(enc === true ? { enc: true } : {}) } : {}), ...(direct ? { direct: String(direct).slice(0, 254) } : {}), at: Date.now() }), g.entry.boxPub)
70
- const r = await client.drop(g.entry.inbox, box)
76
+ return dropBox(client, g.entry.inbox, box)
77
+ }
78
+
79
+ async function dropBox (client, inbox, box) {
80
+ const r = await client.drop(inbox, box)
71
81
  if (r && r.status === 200) return { ok: true }
72
82
  if (r && r.status === 507) return { ok: false, reason: 'inbox_full' }
73
83
  return { ok: false, reason: 'drop_failed:' + (r ? r.status : 'net') }
74
84
  }
85
+
86
+ // A v2-only invite has no legacy room/key fields. An older inbox reader skips it.
87
+ export async function sendSealedPilotInvite ({ email, username, room, mk, gate, client }) {
88
+ const handoff = { room, mk, ...(gate ? { gate } : {}) }
89
+ if (!validPilotHandoff(handoff)) return { ok: false, reason: 'bad_args' }
90
+ const found = await findInvitee({ email, username, app: boxApp('attested') }, client)
91
+ if (!found.ok) return found
92
+ const box = await sealTo(JSON.stringify({ v: 3, sealedRoom: handoff }), found.entry.boxPub)
93
+ return dropBox(client, found.entry.inbox, box)
94
+ }