@witbitz/sdk 4.7.1 → 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/codeCloud.js CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  import { cloudKeyStatus, mintCloudKeys } from './codeCloudKeys.js' // an account-keyed cloud computer's status at each opening; a pasted-key one's move
24
24
  import { verifyAttestation } from './nitroVerify.js'
25
+ import { followedImages } from './followImage.js' // a cloud image this build does not pin, accepted by its release log (docs/release-trust-design.md § 6)
25
26
  import { sealTo } from './sealShare.js'
26
27
  import { trustedSentinelPins } from './connections.js' // the standing Sentinel builds this device trusts — named in the grant (below)
27
28
  import { RELAY_URL, newRelaySecret } from './codeRelay.js'
@@ -49,8 +50,7 @@ export const CLOUD_API = 'https://api.witbitz.chat/v1/cloud-computer'
49
50
  // now seen in the other direction. Per-image epochs remain the fix, and until they land NEITHER number is a usable
50
51
  // stop condition on its own; the check that holds is the file-by-file tarball diff.
51
52
  export const CLOUD_PCR0 = [
52
- '2f92640e0cd5a84e96de0d0fa1857a7643eddd1bac5c6a2512e0a1879919c7720db7b403c9daa0cd088b946aa6ba31f0', // p3j, reproduced on both fleet hosts from 95eaefba
53
- '66c77a098b36a21fa4a7612ecad202ef2c8e46e34f14e9ab56a3a2a9f3108190f6d2bac14c526f501b1e0109d9605a72', // p3i, reproduced twice from c6ca1e6b
53
+ 'dfe9d95d0815c550f423bc48acddcd9a9d48d91859a165278ed97077e0b8178ff7b0ae0a00b454b55b608174e99df9cb', // Privacy logging rollout, independently reproduced from 46478458
54
54
  ]
55
55
  // The published Credential Sentinel image.
56
56
  // ★ A NEW KERNEL MOVES THIS ONE TOO, with an untouched sentinel userland: PCR0 measures kernel and ramdisk together
@@ -89,8 +89,7 @@ export const CLOUD_PCR0 = [
89
89
  // ⚑ So "SENTINEL_PCR0 must not move when the Sentinel did not change" is a usable stop condition again — the check
90
90
  // that caught the esbuild-cwd leak, and which caught nothing for four cycles because the number always moved.
91
91
  export const SENTINEL_PCR0 = [
92
- 'cad3d3e47d1a512fcac60c136b840e83ce28304c37da6e8d66bed205ef5d257cc62e1c118191f1c2561bc749a33cd161', // p3j, reproduced on both fleet hosts from 95eaefba
93
- 'aaeb3d3f64efa4f072372a7f257eaa89fd969614139ca08a8ce817ec46cd0d32cf2b4e6103b984a2b7f9d7ce3354c248', // p3i, reproduced twice from c6ca1e6b
92
+ '1077819d0f0fe4ace12a0250de2ef4aefdeb1a6f91df7b77ba943c07991fd9790d5cba4025e67586bf449778eff76635', // Privacy logging rollout, independently reproduced from 46478458
94
93
  ]
95
94
  export const GRANT_TTL_MS = 24 * 3600_000
96
95
  export const PUSH_PATTERN = 'witbitz/*'
@@ -264,7 +263,7 @@ export async function publishedCloudPins (fetchImpl = (u, o) => fetch(u, o), url
264
263
  }
265
264
  // ★★ A PIN MISMATCH IS USUALLY A STALE PAGE (codeCloudStale.js): the app passes its build and a reload, and a mismatch on a
266
265
  // page older than the published build reloads it once. Without them (the SDK, a test) a mismatch means what it says.
267
- export async function openCloud(computer, { token, aws = null, onStep = () => {}, onSession = () => {}, onGitHub = () => {}, fetchImpl = fetch, verify = verifyAttestation, api = CLOUD_API, pcr0 = CLOUD_PCR0, sentinelPcr0 = SENTINEL_PCR0, waitMs = 600_000, now = () => Date.now(), pageBuild = '', reload = () => {}, publishedBuild = async () => null, follow = null } = {}) {
266
+ export async function openCloud(computer, { token, aws = null, onStep = () => {}, onSession = () => {}, onGitHub = () => {}, fetchImpl = fetch, verify = verifyAttestation, api = CLOUD_API, pcr0 = CLOUD_PCR0, sentinelPcr0 = SENTINEL_PCR0, waitMs = 600_000, now = () => Date.now(), pageBuild = '', reload = () => {}, publishedBuild = async () => null, follow = null, released = followedImages } = {}) {
268
267
  const c = computer && computer.cloud
269
268
  if (!c || !c.workspace || !c.half) throw new CloudError('this is not a cloud computer')
270
269
  if (!c.key) throw new CloudError('no TrustedRouter key is saved for this cloud computer', { code: 'no_key' })
@@ -366,12 +365,31 @@ export async function openCloud(computer, { token, aws = null, onStep = () => {}
366
365
  }
367
366
  return null
368
367
  }
368
+ // ★★ A RELEASED IMAGE IS FOLLOWED BY ITS RECORD (docs/release-trust-design.md § 6; the owner's Windows app, 2026-12-02: the hosts moved
369
+ // to dfe9d95d / 1077819d and every installed app — its code baked in, pins from before — refused them). The newest FOLLOW_WINDOW
370
+ // images of `cloud-computer` / `cc-sentinel` whose build-enclave release records verify HERE (followImage.js: made by a build enclave
371
+ // this app trusts, signed, rebuilt from source) are accepted as the pins are, each on its own (a verifier refuses a set of three).
372
+ // The log is only a carrier — it can withhold a record, never invent one; the KMS key policy stays the hand-moved gate.
373
+ const fromLog = async (docB64, nonce, pins, role) => {
374
+ let more = []
375
+ try { more = (await released(role === 'sentinel' ? 'cc-sentinel' : 'cloud-computer')).filter((p) => !pins.includes(p)) } catch { return null }
376
+ for (const p of more) {
377
+ let doc = null
378
+ try { doc = await verify(unb64(docB64), { nonce, maxAgeMs: 120_000, expectedPCRs: { 0: [p] } }) } catch { continue }
379
+ // A BUILDER'S CHOICE STILL HOLDS (sync sweep 12-04 O1): the SDK passes `follow` with its auto/ask; a released image is
380
+ // accepted on its `auto` or the person's yes, exactly as a claimed one. The app passes none: its own check is the record.
381
+ if (!follow || (typeof follow.auto === 'function' && follow.auto()) || (typeof follow.ask === 'function' && await follow.ask(p, role))) return doc
382
+ throw new CloudError('you did not accept the new Witbitz image, so nothing was sent to your cloud computer', { code: 'declined' })
383
+ }
384
+ return null
385
+ }
369
386
  // The attestation the open answer brought, or — from a controller without it, or one that failed there — asked for alone.
370
387
  const attested = async (op, nonce, brought, pins, role) => {
371
388
  const docB64 = typeof brought === 'string' && brought ? brought : (await call({ action: 'op', workspace: c.workspace, cid: opened.cid, req: { op, nonce: b64(nonce) } })).doc
372
389
  let doc = null, failure = null
373
390
  try { doc = await verify(unb64(docB64), { nonce, maxAgeMs: 120_000, expectedPCRs: { 0: pins } }) } catch (e) { failure = e }
374
391
  const reason = failure ? String((failure && failure.message) || failure).split('\n')[0] : ''
392
+ if (!doc && released && /PCR0/i.test(reason)) doc = await fromLog(docB64, nonce, pins, role)
375
393
  if (!doc && follow && /PCR0/i.test(reason)) doc = await followed(docB64, nonce, pins, role)
376
394
  if (!doc) {
377
395
  if (/PCR/i.test(reason) && pageBuild && pageBuild.indexOf('__') !== 0) {
package/connections.js CHANGED
@@ -22,7 +22,7 @@ import { sealDisp, withDisplay } from './connDisp.js' // step 2: a connection's
22
22
  /** The standing Sentinel's image, a rollover set of PCR0s (docs/standing-sentinel.md; infra/enclave/sentinel-host/README.md
23
23
  * for the repin). Empty would mean attach REFUSES: the page will not seal an API key to an enclave it cannot name.
24
24
  * Pin it here and in the Lambda's SENTINEL_HOP_PCRS together. */
25
- export const STANDING_SENTINEL_PCR0 = ['0e424db41977965bc6edf225229eae70fe162dd8264b1ac0b5670cb3f71bf8b923001341e85a665354b25cd8418ac6d3'] // st57
25
+ export const STANDING_SENTINEL_PCR0 = ['170c11ba34cb4521e138e822ff29ffcf5e78144d344882294a8c00102a6ba8a56d8f36e3ad912f70b799fe7856c46266', '0e424db41977965bc6edf225229eae70fe162dd8264b1ac0b5670cb3f71bf8b923001341e85a665354b25cd8418ac6d3'] // st58 and st57
26
26
 
27
27
  const b64 = (u8) => btoa(String.fromCharCode(...new Uint8Array(u8)))
28
28
  const unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0))
package/followImage.js CHANGED
@@ -10,8 +10,8 @@ import { BUILD_ENCLAVE_PCR0, trustedBuilders, chainFromSite, recordPcrBy } from
10
10
  import { verifyAttestation } from './nitroVerify.js'
11
11
 
12
12
  export const FOLLOW_WINDOW = 2 // the newest two that verify: a rollover's new image and the one it replaces
13
- export const FOLLOWED_SUBJECTS = Object.freeze(['cloud-device', 'tools-enclave'])
14
- export const IMAGE_DENY = Object.freeze({ 'cloud-device': Object.freeze([]), 'tools-enclave': Object.freeze([]) })
13
+ export const FOLLOWED_SUBJECTS = Object.freeze(['cloud-device', 'tools-enclave', 'cloud-computer', 'cc-sentinel'])
14
+ export const IMAGE_DENY = Object.freeze({ 'cloud-device': Object.freeze([]), 'tools-enclave': Object.freeze([]), 'cloud-computer': Object.freeze([]), 'cc-sentinel': Object.freeze([]) })
15
15
  export const TRUST_BASE = 'https://api.witbitz.chat/v1/trust/'
16
16
 
17
17
  /** The passing records of `subject` in a log's text (jsonl), newest first. */
package/idb.js CHANGED
@@ -121,7 +121,18 @@ export const idb = (() => {
121
121
  })().catch(() => []),
122
122
  // §NAMES: the real names under a prefix, values never read (the protection migration and listings).
123
123
  names: (pfx) => (idbNamingState().on && idbNamingState().namer ? nameIndex().then(async (ix) => [...ix.map(([, n]) => n).filter((n) => n.startsWith(pfx)), ...await keysRaw(pfx)]) : keysRaw(pfx)).catch(() => []),
124
- getRaw, setRaw, setRawStrict, delRaw, entriesRaw, keysRaw, nameIndex,
124
+ // Both room frames can boot while the privacy switch is being saved. Initialize only
125
+ // an absent value, in one transaction with the read, so a late boot cannot undo it.
126
+ // HIDE MY IP's push flag (`pushDirectAllowed`) is read by THIS origin's notification and key workers. In the hosted app
127
+ // (vault()) the frame keeps no database: the vault's key worker writes the flag into the vault's own store (l1.js
128
+ // mirrorPushPrivacy → l1relay), where the vault's workers read it — so both writes below are no-ops there.
129
+ initPushDirect: () => vault() ? Promise.resolve() : tx('readwrite', store => {
130
+ const read = store.getKey('pushDirectAllowed')
131
+ read.onsuccess = () => { if (read.result === undefined) store.put(true, 'pushDirectAllowed') }
132
+ }, m => { if (!m.has('pushDirectAllowed')) m.set('pushDirectAllowed', true) }),
133
+ requireLocalDisk: async () => { if (vault()) throw Error('a local database is required'); await open() },
134
+ setDeviceRaw: (k, v) => vault() ? Promise.resolve() : tx('readwrite', (s) => s.put(v, k)),
135
+ getRaw, getRawStrict, setRaw, setRawStrict, delRaw, entriesRaw, keysRaw, nameIndex,
125
136
  /** A read that THROWS when it failed (never null for an error) — for a value that must not be replaced on a failed read. */
126
137
  async getStrict(k) {
127
138
  if (isNamed(k)) {
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
+ }