@witbitz/sdk 0.0.0-stage → 4.3.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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +200 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +223 -0
- package/accountIndexDoc.js +122 -0
- package/accountOwner.js +59 -0
- package/accountRecord.js +90 -0
- package/accountScope.js +114 -0
- package/accountSeal.js +42 -0
- package/accountStores.js +173 -0
- package/acctV2App.js +619 -0
- package/acctV2Check.js +29 -0
- package/acctV2Client.js +382 -0
- package/acctV2Keys.js +43 -0
- package/acctV2Legacy.js +14 -0
- package/acctV2Switch.js +80 -0
- package/acctV2UiCore.js +857 -0
- package/acctV2WebAuthn.js +61 -0
- package/acctV2Wire.js +59 -0
- package/address.js +42 -0
- package/attestedBox.js +30 -0
- package/attestedRooms.js +78 -0
- package/awsKey.js +98 -0
- package/backupRecord.js +106 -0
- package/backupVault.js +97 -0
- package/blocks.js +115 -0
- package/blocksPush.js +64 -0
- package/browseSeal.js +103 -0
- package/cbor.js +225 -0
- package/changePush.js +75 -0
- package/chatLock.js +149 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeBrowse.js +224 -0
- package/codeCloud.js +652 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +388 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +57 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeRelay.js +505 -0
- package/codeSentinel.js +86 -0
- package/codeTransport.js +295 -0
- package/codeUndo.js +48 -0
- package/compress.js +24 -0
- package/config.js +11 -0
- package/connCatalog.js +164 -0
- package/connDisp.js +76 -0
- package/connOtherWays.js +74 -0
- package/connPending.js +16 -0
- package/connWrap.js +53 -0
- package/connectionEntry.js +89 -0
- package/connections.js +562 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +521 -0
- package/deviceCall.js +54 -0
- package/deviceKeyCore.js +41 -0
- package/deviceSeal.js +59 -0
- package/e2ee.js +323 -0
- package/eat.js +103 -0
- package/emailFork.js +275 -0
- package/emailSignIn.js +81 -0
- package/emptySpaces.js +111 -0
- package/encSource.js +55 -0
- package/enclaveAccept.js +214 -0
- package/enclaveClaim.js +241 -0
- package/enclaveRoute.js +102 -0
- package/enclaveSnapshotMerge.js +44 -0
- package/entrySig.js +165 -0
- package/env.js +73 -0
- package/eraseFile.js +58 -0
- package/followImage.js +86 -0
- package/healNames.js +45 -0
- package/idb.js +97 -0
- package/idbSeal.js +119 -0
- package/indexGone.js +12 -0
- package/invite.js +51 -0
- package/inviteEnroll.js +67 -0
- package/inviteSend.js +68 -0
- package/jobAgents.js +87 -0
- package/keptMerge.js +84 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +831 -0
- package/laneConfig.js +57 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +220 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +123 -0
- package/mkseal.js +101 -0
- package/nativePush.js +153 -0
- package/nitroVerify.js +220 -0
- package/noble-p256.js +27 -0
- package/notice.js +116 -0
- package/notifKey.js +58 -0
- package/offlineBundle.js +62 -0
- package/ohttp.js +177 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +254 -4
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +410 -0
- package/pushCore.js +42 -0
- package/recovery.js +107 -0
- package/regions.js +42 -0
- package/removedMessage.js +11 -0
- package/renameRefusal.js +9 -0
- package/replyQuote.js +34 -0
- package/reqEnvelope.js +126 -0
- package/roomDefaultPrefs.js +76 -0
- package/roomDelete.js +109 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +289 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +49 -0
- package/rosterHash.js +13 -0
- package/rowSchema.js +113 -0
- package/safeMedia.js +116 -0
- package/safeMediaPins.js +17 -0
- package/schedulesDoc.js +78 -0
- package/sdkA2A.js +404 -0
- package/sdkAccount.js +470 -0
- package/sdkAccountDoc.js +81 -0
- package/sdkAccountSections.js +223 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +480 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +215 -0
- package/sdkComputers.js +480 -0
- package/sdkDictation.js +142 -0
- package/sdkErase.js +283 -0
- package/sdkExports.js +69 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +94 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +307 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +54 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +124 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +154 -0
- package/shamir.js +85 -0
- package/sharedViews.js +38 -0
- package/sheetChrome.js +450 -0
- package/siri.js +171 -0
- package/spaceClient.js +1418 -0
- package/spaceConfig.js +81 -0
- package/spaceEmailGate.js +813 -0
- package/spaceExport.js +125 -0
- package/spaceFork.js +216 -0
- package/spaceLock.js +358 -0
- package/spacePasskey.js +180 -0
- package/speechOut.js +100 -0
- package/splitKeyClient.js +90 -0
- package/store.js +587 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +538 -0
- package/tempList.js +48 -0
- package/tinfoilVerifier.js +78 -0
- package/toolBooks.js +31 -0
- package/toolRules.js +52 -0
- package/turnCerts.js +254 -0
- package/turnFeed.js +58 -0
- package/turnVerdict.js +36 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +1958 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +263 -0
- package/vaultAtRest.js +177 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +281 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +98 -0
- package/vcWorker.js +34 -0
- package/voiceAttest.js +50 -0
- package/voiceCert.js +51 -0
- package/witbitz-admin.d.ts +135 -0
- package/witbitz-admin.js +529 -0
- package/witbitz-admin.mjs +1459 -0
- package/witbitz-sdk.d.ts +1106 -0
- package/witbitz-sdk.js +3835 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/sealedNames.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// sealedNames.js — OPAQUE NAMES for a protected device's stores (docs/desktop-protection.md, phase 2; the owner, 2026-10-11:
|
|
2
|
+
// "Some metadata stays readable — why?"). Sealing a VALUE under its own name still told a disk copy which rooms this device
|
|
3
|
+
// holds (`space:mk:<room>`, idb `chat:<room>`) and every reviewed-clear flag around them. On a protected device every entry is
|
|
4
|
+
// stored under `p:` + an encryption of its real name instead.
|
|
5
|
+
//
|
|
6
|
+
// The name is encrypted DETERMINISTICALLY (a synthetic IV: the AES-GCM nonce is HMAC(name), as in SIV), so the page finds an
|
|
7
|
+
// entry by computing its stored name, and a listing recovers every real name by decrypting the KEYS alone — no value is read
|
|
8
|
+
// (reading every value at unlock is what once killed the page on an iPhone, idb.js § A PREFIX READ). Equal names give equal
|
|
9
|
+
// stored names; that is all a disk copy learns: how many entries there are, and their sizes.
|
|
10
|
+
//
|
|
11
|
+
// Both keys come from the device key's raw bytes by HKDF with their own labels — never the value-sealing key itself.
|
|
12
|
+
const enc = new TextEncoder(), dec = new TextDecoder()
|
|
13
|
+
const SALT = enc.encode('witbitz-sealed-names')
|
|
14
|
+
export const NAME_PREFIX = 'p:'
|
|
15
|
+
export const isOpaqueName = (k) => typeof k === 'string' && k.startsWith(NAME_PREFIX)
|
|
16
|
+
|
|
17
|
+
const subtle = () => { const s = globalThis.crypto && globalThis.crypto.subtle; if (!s) throw new Error('no WebCrypto'); return s }
|
|
18
|
+
const toB64u = (u8) => { let s = ''; for (let i = 0; i < u8.length; i++) s += String.fromCharCode(u8[i]); return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') }
|
|
19
|
+
const fromB64u = (s) => { const b = atob(String(s).replace(/-/g, '+').replace(/_/g, '/')); const u = new Uint8Array(b.length); for (let i = 0; i < b.length; i++) u[i] = b.charCodeAt(i); return u }
|
|
20
|
+
const bytes = (x) => (x instanceof Uint8Array ? x : x instanceof ArrayBuffer ? new Uint8Array(x) : Array.isArray(x) ? Uint8Array.from(x) : null)
|
|
21
|
+
|
|
22
|
+
/** The two name keys from the device key's 32 raw bytes. */
|
|
23
|
+
export async function nameKeys (raw) {
|
|
24
|
+
const r = bytes(raw); if (!r || r.length < 16) throw new Error('bad device key')
|
|
25
|
+
const base = await subtle().importKey('raw', r, 'HKDF', false, ['deriveKey'])
|
|
26
|
+
const hk = (info) => ({ name: 'HKDF', hash: 'SHA-256', salt: SALT, info: enc.encode(info) })
|
|
27
|
+
const mac = await subtle().deriveKey(hk('witbitz-names-v1-mac'), base, { name: 'HMAC', hash: 'SHA-256', length: 256 }, false, ['sign'])
|
|
28
|
+
const aes = await subtle().deriveKey(hk('witbitz-names-v1-enc'), base, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
|
|
29
|
+
return { mac, aes }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function ivFor (keys, name) { return new Uint8Array(await subtle().sign('HMAC', keys.mac, enc.encode(name))).slice(0, 12) }
|
|
33
|
+
|
|
34
|
+
/** The stored name for a real name. */
|
|
35
|
+
export async function opaqueName (keys, name) {
|
|
36
|
+
const iv = await ivFor(keys, String(name))
|
|
37
|
+
const ct = new Uint8Array(await subtle().encrypt({ name: 'AES-GCM', iv }, keys.aes, enc.encode(String(name))))
|
|
38
|
+
const out = new Uint8Array(iv.length + ct.length); out.set(iv); out.set(ct, iv.length)
|
|
39
|
+
return NAME_PREFIX + toB64u(out)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The real name behind a stored name, or null (not ours, another key, or damaged). */
|
|
43
|
+
export async function realName (keys, stored) {
|
|
44
|
+
if (!isOpaqueName(stored)) return null
|
|
45
|
+
try {
|
|
46
|
+
const all = fromB64u(stored.slice(NAME_PREFIX.length)); if (all.length < 29) return null
|
|
47
|
+
const iv = all.slice(0, 12)
|
|
48
|
+
const name = dec.decode(await subtle().decrypt({ name: 'AES-GCM', iv }, keys.aes, all.slice(12)))
|
|
49
|
+
const want = await ivFor(keys, name) // the IV IS the name's MAC: a stored name made by another key, or edited, fails here
|
|
50
|
+
for (let i = 0; i < 12; i++) if (want[i] !== iv[i]) return null
|
|
51
|
+
return name
|
|
52
|
+
} catch { return null }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A cached namer over one device key: opaque(name) and real(stored), both memoised (names repeat on every write). */
|
|
56
|
+
export async function makeNamer (raw) {
|
|
57
|
+
const keys = await nameKeys(raw)
|
|
58
|
+
const fwd = new Map(), back = new Map()
|
|
59
|
+
return {
|
|
60
|
+
async opaque (name) { const n = String(name); let o = fwd.get(n); if (!o) { o = await opaqueName(keys, n); fwd.set(n, o); back.set(o, n) } return o },
|
|
61
|
+
async real (stored) { if (back.has(stored)) return back.get(stored); const n = await realName(keys, stored); if (n != null) { back.set(stored, n); fwd.set(n, stored) } return n },
|
|
62
|
+
known (name) { return fwd.get(String(name)) || null }, // synchronous: the stored name if computed before
|
|
63
|
+
}
|
|
64
|
+
}
|
package/sealedReceipt.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// sealedReceipt.js — the TRUST RECEIPT a member computes from the ciphertext the server stores: its size, its SHA-256 and
|
|
2
|
+
// who it is sealed to (sync sweep, 2026-10-10). An open room's receipt comes from the keyless `sealed` read, which the
|
|
3
|
+
// server computes; a VERIFIED room refuses that read to non-members on purpose, so a member reads the same stored bytes
|
|
4
|
+
// through the authenticated pollsealed path and computes the receipt here. The SDK's sealedProof() uses it (the app's
|
|
5
|
+
// Trust sheet that also did was removed on 2026-10-10).
|
|
6
|
+
/** `sealed` = what pollsealed / exportSealed returns as `sealed` (a string, or the v3 `{ v, boxes }` wrapper). */
|
|
7
|
+
export async function receiptOf(sealed) {
|
|
8
|
+
if (sealed == null) return null
|
|
9
|
+
const raw = typeof sealed === 'string' ? sealed : JSON.stringify(sealed)
|
|
10
|
+
let env = null; try { env = typeof sealed === 'string' ? JSON.parse(sealed) : sealed } catch { /* opaque */ }
|
|
11
|
+
// v3 (what production writes): `boxes` are per-entry envelopes stored as JSON STRINGS (agent/spaceLedgerV3.mjs).
|
|
12
|
+
const box0 = env && Array.isArray(env.boxes) && env.boxes.length ? (typeof env.boxes[0] === 'string' ? (() => { try { return JSON.parse(env.boxes[0]) } catch { return null } })() : env.boxes[0]) : null
|
|
13
|
+
const rec = env && env.recipients ? env.recipients : (box0 && box0.recipients) || null
|
|
14
|
+
const bytes = new TextEncoder().encode(raw)
|
|
15
|
+
const sha256 = [...new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))].map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
16
|
+
return { bytes: bytes.length, sha256, recipients: rec && typeof rec === 'object' ? Object.keys(rec) : [], alg: env && env.v ? `AES-256-GCM · multi-recipient envelope v${env.v}` : 'opaque', sealed: raw }
|
|
17
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// sentinelRelease.js — A STANDING SENTINEL BUILD THE APP DOES NOT PIN, CHECKED BY ITS RELEASE RECORD, IN THE BROWSER (docs/standing-sentinel.md
|
|
2
|
+
// § Following verified releases; the owner, 2026-11-17: "Make it cheaper"). The Sentinel's front hands, with each attestation, the
|
|
3
|
+
// build enclave's signed verdict for the running build. Here it must hold: made by a build-enclave image pinned below (its AWS
|
|
4
|
+
// Nitro attestation, verified against the pinned AWS root), for THIS verdict (user_data = sha256 of the verdict without its proofs),
|
|
5
|
+
// signed by the key that attestation names (ECDSA P-256), subject standing-sentinel, verdict pass, the image rebuilt from its source.
|
|
6
|
+
// Rekor is checked by the Space Lambda and the turn enclave (agent/sentinelFollow.mjs), not here. A build that passes is then
|
|
7
|
+
// followed exactly as a published one is: at once with "Accept new Witbitz builds automatically", else the person is asked.
|
|
8
|
+
import { verifyAttestation } from './nitroVerify.js'
|
|
9
|
+
import { derSigToRaw } from './x509.js'
|
|
10
|
+
|
|
11
|
+
/** The build-enclave images whose verdicts count — infra/build-enclave/pins.json `buildEnclave` (held equal by a test). */
|
|
12
|
+
export const BUILD_ENCLAVE_PCR0 = Object.freeze([
|
|
13
|
+
"f490096d57e4287146e8b8d7bf4c75f423984ca52199efab0ee8684fbee6cfe6ab82c72d54f05a38f24a0d4ad6e2f557",
|
|
14
|
+
"41ec7e0e54beac5759fba7efa06c48081dbd96c7299c29c92a9c619036ce057cec357ad4ad71a165d7f881df120b043b",
|
|
15
|
+
"9f0801335a952bdbac70b6793150738d7ce30bc3a0d520fec6f573de22a822aa5ef762f78648bc8608ca0b2eeccda556",
|
|
16
|
+
"a145e8524bbe8764d4db6b81b4e18d72eae42e8b9e1c834e62e22aba18cce318f9eaa84942671c688c3eeb89ec30b0e8",
|
|
17
|
+
"5d29c3691cd38f6c6ce0da2b2f9d1da82712d9da12a89c99d38a03cae6369ebe6ba7a1ab1060cfa9daf6a19228c7a2dc",
|
|
18
|
+
"6c962286faed81c395bcf3d319011f91893cfec723c2dc7069ad8805980d77e99f75c94671881cc793794521fe5d2ff0",
|
|
19
|
+
"578945d0342d346d72e50b36ffe74a3631e53e111bc010394108457e362d10830ebadcc7ec5ffa4445d5b10b9c522d28",
|
|
20
|
+
"7e9f760db923c6f31fd18db06f6b60a53902beb6b0d80b91b5355d33c461e43bcddc31c08e2380ff9dc75c10909e6acb",
|
|
21
|
+
"5b6bffe6953eef271a69e453072b6e202ae024cd3983fff3a637b7421a60ad92ab3fd19f8ae809e19182a3feebbe94c2",
|
|
22
|
+
"551006e397efd43a619b370ef336a6a594d8a8338cd49860e54845330354c73afd3ba673360d50f78e5f1d702e19946b",
|
|
23
|
+
"eecf817c561e633b30632ca434a28ad56ed46395d765172fedcc0742d8d5c9982845d6ce32b6451b943f4b6f0a55ea36",
|
|
24
|
+
"3df18dce5385b467208bfa325d2f812bd622ef6def87ef97e63116310a896427db9f2c69d7c2631bccc9c65549b3d512",
|
|
25
|
+
"a51fcaeafa6d188b46d11710442f981169304aa4feecc4b40263943966c3dd8ff9b986d30989b4152fa1540c85a76b5e",
|
|
26
|
+
"f977e0490f5abfc77c311b426399bddd6909848bb8175db4142885c839e9cc23c3ca0047317b039883dce4b1a2efe096",
|
|
27
|
+
"d5f13dff5647f5f4ee351dd9e1ba9348ecd39da88acd6ffd9c324897b0ca7563da974b08c2e84504a76dc98b48700b74",
|
|
28
|
+
"2babe4262b2a00949eeef5b04a81327eb606dc347caaf507527d04f8847730a31dd26d6d7be3e0a672c537b51c914133",
|
|
29
|
+
"25a0967ec1366bc0ec43e45e2f89c435adb1a3e54d8702d89599acb442337afcb36f8f64d51a6608cefb3bb1e4f6b8ed",
|
|
30
|
+
"8665867cbb86ea3178f4179cf040fdec9e6df22bdd4f1e3d8df6b2d9096db5aecd8420b42203969bbe9446b585c78870",
|
|
31
|
+
"ef738ca713ddc39dc29505d857c2aac22a0598a714163ae01e2879085e1c262cc5bde3c239b7ce76385d10c5910ed487",
|
|
32
|
+
"41de07c0c12f388f9dc7d87cfa835edce2c58be42f6893f227002329d263285bf78bb209cd69c384dd7566097f2a3d47",
|
|
33
|
+
"a77141c4ac00099cbdd9053e0190b70234aa2eccdb22cb358e9b8b0fef5bef6b7ad6d9b5eb73137244a3790f98869505",
|
|
34
|
+
"70dde35fed128d1cb007f8c6edfa3de70e991955e1748aa500ad4685d1c752b1775565fb9a6d11c483969d5596e3b159",
|
|
35
|
+
"f0ea83ee58b3a4a9ebe7c8c74f102eba17118711573b6ce773b6f31ed223564cbf215992b5a7a30462b70281ae624453",
|
|
36
|
+
"f7adfbec8cf3a014f9585c7decc21bb03a50484339811ea3b44947d23fc16aff8eedb56346915b816e83fc5faad55e7a",
|
|
37
|
+
"917f7d95eabd64eabd1145cc0898c08ff414037775fd416162002c4783b4f95dcb550c3c5493baadaf41eaceb0e7da0d",
|
|
38
|
+
"74b1cbd4398f319a636de05d36eaa40953df4dc0bb86769f7ac4e0fe2c576f55b3c4a15a5583048ded80b0b4d303f55e",
|
|
39
|
+
"420088665bd62edcba51dfbcc55cbc85611529985fde54b655a3476198a8f9421e02d1898db28180b153550ceeb66798",
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
const enc = new TextEncoder()
|
|
43
|
+
const unb64 = (s) => Uint8Array.from(atob(String(s)), (c) => c.charCodeAt(0))
|
|
44
|
+
const hex = (u8) => [...new Uint8Array(u8)].map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
45
|
+
const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i])
|
|
46
|
+
const PROOFS = ['attestation', 'signature', 'rekor']
|
|
47
|
+
|
|
48
|
+
/** A release record → the standing Sentinel PCR0 it vouches for, or throws with why. `links`: the build-enclave links its front handed
|
|
49
|
+
* beside it (docs/trust-root.md) — the record's builder may be one they make trusted from the anchors. */
|
|
50
|
+
export async function sentinelPcrOfRelease (r, { builders = BUILD_ENCLAVE_PCR0, links = null, verify = verifyAttestation, site = chainFromSite } = {}) {
|
|
51
|
+
const trusted = Array.isArray(links) && links.length ? await trustedBuilders(links, { anchors: builders, verify }) : builders
|
|
52
|
+
try { return await recordPcr(r, 'standing-sentinel', trusted, verify) } catch (e) {
|
|
53
|
+
// NO LIMIT ON THE CHAIN (the owner, 2026-11-23): the record's builder is newer than this app's anchors and the links handed beside
|
|
54
|
+
// it did not reach it — read the WHOLE log from this app's own site and walk it (each link verified here; the site can withhold
|
|
55
|
+
// one, never invent one). Once per page; a site without the log changes nothing.
|
|
56
|
+
if (!site || !/not made by a build enclave this app trusts/.test(String((e && e.message) || e))) throw e
|
|
57
|
+
const all = [...(Array.isArray(links) ? links : []), ...await site()]
|
|
58
|
+
if (!all.length) throw e
|
|
59
|
+
return recordPcr(r, 'standing-sentinel', await trustedBuilders(all, { anchors: builders, verify, max: Infinity }), verify)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Every passing build-enclave link Witbitz publishes (CHAIN_URLS), newest first — read once per page. */
|
|
64
|
+
let _siteChain = null
|
|
65
|
+
// Witbitz's server first (always the current log: published with each build enclave), then this app's own site (the log as of its deploy).
|
|
66
|
+
export const CHAIN_URLS = Object.freeze(['https://api.witbitz.chat/v1/trust/build-enclave.jsonl', '/audit/releases/build-enclave.jsonl'])
|
|
67
|
+
export function chainFromSite ({ fetchFn = (typeof fetch === 'function' ? fetch : null), urls = CHAIN_URLS } = {}) {
|
|
68
|
+
if (!fetchFn) return Promise.resolve([])
|
|
69
|
+
const own = fetchFn === globalThis.fetch && urls === CHAIN_URLS // only the page's own read is remembered (a caller's fetch is read each time)
|
|
70
|
+
if (own && typeof process !== 'undefined' && process.env && process.env.NODE_TEST_CONTEXT) return Promise.resolve([]) // tests read no network
|
|
71
|
+
if (!own) return readChain(fetchFn, urls)
|
|
72
|
+
return _siteChain || (_siteChain = readChain(fetchFn, urls).then((l) => { if (!l.length) _siteChain = null; return l })) // nothing read: ask again next time
|
|
73
|
+
}
|
|
74
|
+
function readChain (fetchFn, urls) {
|
|
75
|
+
return (async () => {
|
|
76
|
+
for (const u of urls) {
|
|
77
|
+
try {
|
|
78
|
+
const res = await fetchFn(u, { cache: 'no-store' })
|
|
79
|
+
if (!res || res.status !== 200 || /text\/html/.test((res.headers && res.headers.get && res.headers.get('content-type')) || '')) continue
|
|
80
|
+
const l = linksOfLogText(await res.text())
|
|
81
|
+
if (l.length) return l
|
|
82
|
+
} catch { /* the next */ }
|
|
83
|
+
}
|
|
84
|
+
return []
|
|
85
|
+
})()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The passing `build-enclave` records in a release log's text (jsonl), newest first — tools/build-enclave/trustedNow.mjs linksOfLog. */
|
|
89
|
+
export function linksOfLogText (text) {
|
|
90
|
+
const out = []
|
|
91
|
+
for (const l of String(text || '').split('\n')) { try { const r = JSON.parse(l); if (r && r.subject === 'build-enclave' && r.verdict === 'pass') out.push(r) } catch { /* not a record */ } }
|
|
92
|
+
return out.reverse()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// THE CHAIN OF BUILD ENCLAVES, the browser's twin of agent/buildEnclaveChain.mjs (held equal by spaces/test/buildEnclaveChainTwin.test.mjs):
|
|
96
|
+
// the anchors + every build enclave a trusted one rebuilt (a `build-enclave` record, checked here as every record is), minus the deny list.
|
|
97
|
+
export const BUILD_ENCLAVE_DENY = Object.freeze([])
|
|
98
|
+
export const LINKS_MAX = 4 // links one ANSWER may carry (agent/buildEnclaveChain.mjs) — the log read here (chainFromSite) is not capped
|
|
99
|
+
// VERIFIED ONCE (as the server's chain): a link that verified is remembered by its signature for this page's life, reused only while
|
|
100
|
+
// the builder that signed it is trusted in this walk — never a wider trust, only the same checks not repeated.
|
|
101
|
+
const verified = new Map()
|
|
102
|
+
export async function trustedBuilders (links = [], { anchors = BUILD_ENCLAVE_PCR0, deny = BUILD_ENCLAVE_DENY, verify = verifyAttestation, max = LINKS_MAX } = {}) {
|
|
103
|
+
const denied = new Set((deny || []).map((x) => String(x).toLowerCase()))
|
|
104
|
+
const trusted = new Set((anchors || []).map((x) => String(x).toLowerCase()).filter((x) => !denied.has(x)))
|
|
105
|
+
const cache = verify === verifyAttestation
|
|
106
|
+
let pending = Array.isArray(links) ? links.slice(0, max) : []
|
|
107
|
+
for (let grew = true; grew && pending.length;) {
|
|
108
|
+
grew = false
|
|
109
|
+
const left = []
|
|
110
|
+
for (const l of pending) {
|
|
111
|
+
try {
|
|
112
|
+
const sig = l && l.signature && typeof l.signature.sig === 'string' ? l.signature.sig : ''
|
|
113
|
+
const known = sig && cache ? verified.get(sig) : null
|
|
114
|
+
let p
|
|
115
|
+
if (known && trusted.has(known.builder) && String((l.measurement && l.measurement.pcr0) || '').toLowerCase() === known.pcr0) p = known.pcr0
|
|
116
|
+
else {
|
|
117
|
+
const got = await recordPcrBy(l, 'build-enclave', [...trusted], verify)
|
|
118
|
+
p = got.pcr0
|
|
119
|
+
if (sig && cache) { if (verified.size >= 4096) verified.delete(verified.keys().next().value); verified.set(sig, got) }
|
|
120
|
+
}
|
|
121
|
+
if (!denied.has(p) && !trusted.has(p)) { trusted.add(p); grew = true }
|
|
122
|
+
} catch (e) { if (/not made by a build enclave this app trusts/.test(String((e && e.message) || e))) left.push(l) }
|
|
123
|
+
}
|
|
124
|
+
pending = left
|
|
125
|
+
}
|
|
126
|
+
return [...trusted]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A release record of `subject` → the PCR0 it vouches for, made by one of `builders`; or throws with why. */
|
|
130
|
+
async function recordPcr (r, subject, builders, verify) { return (await recordPcrBy(r, subject, builders, verify)).pcr0 }
|
|
131
|
+
|
|
132
|
+
/** The same, with the builder that made it: { pcr0, builder } — any subject (followImage.js uses it for the images the apps follow). */
|
|
133
|
+
export async function recordPcrBy (r, subject, builders, verify = verifyAttestation) {
|
|
134
|
+
if (!r || typeof r !== 'object') throw new Error('no release record came with the attestation')
|
|
135
|
+
if (r.subject !== subject || r.verdict !== 'pass') throw new Error(`the record is not a passing ${subject} release`)
|
|
136
|
+
const repro = Array.isArray(r.checks) && r.checks.find((c) => c && c.name === 'reproducible-build')
|
|
137
|
+
if (!repro || repro.ok !== true) throw new Error('the record does not say the image was rebuilt from its source')
|
|
138
|
+
const pcr0 = String((r.measurement && r.measurement.pcr0) || '').toLowerCase()
|
|
139
|
+
if (!/^[0-9a-f]{96}$/.test(pcr0) || (r.claim && String(r.claim.pcr0 || '').toLowerCase() !== pcr0)) throw new Error('the record names no single PCR0')
|
|
140
|
+
if (!r.attestation || !r.attestation.doc || !r.signature || !r.signature.key || !r.signature.sig) throw new Error('the record carries no proof')
|
|
141
|
+
const rest = {}; for (const [k, v] of Object.entries(r)) if (!PROOFS.includes(k)) rest[k] = v
|
|
142
|
+
const art = enc.encode(JSON.stringify(rest))
|
|
143
|
+
const doc = await verify(unb64(r.attestation.doc), { atDocTime: true })
|
|
144
|
+
const builder = String((doc.pcrs && doc.pcrs[0]) || '').toLowerCase()
|
|
145
|
+
if (!builders.includes(builder)) throw new Error('the record was not made by a build enclave this app trusts')
|
|
146
|
+
const want = enc.encode(JSON.stringify({ role: 'build-enclave', verdict: hex(await crypto.subtle.digest('SHA-256', art)) }))
|
|
147
|
+
if (!doc.userData || !same(new Uint8Array(doc.userData), want)) throw new Error('the build enclave\'s attestation is not for this record')
|
|
148
|
+
const spki = unb64(r.signature.key)
|
|
149
|
+
if (!doc.publicKey || !same(new Uint8Array(doc.publicKey), spki)) throw new Error('the record is not signed by the key the build enclave attested')
|
|
150
|
+
const key = await crypto.subtle.importKey('spki', spki, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify'])
|
|
151
|
+
const ok = await crypto.subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key, derSigToRaw(unb64(r.signature.sig), 32), art)
|
|
152
|
+
if (!ok) throw new Error('the record\'s signature does not verify')
|
|
153
|
+
return { pcr0, builder }
|
|
154
|
+
}
|
package/shamir.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// witz/public/shamir.js — Shamir's Secret Sharing over GF(256) (M3, docs/configurable-space-m3.md).
|
|
2
|
+
//
|
|
3
|
+
// The GENERAL shared-presence key model for a Space: split the room key `mk` into `n` shares so that ANY `k` of them
|
|
4
|
+
// reconstruct it and any `k-1` reveal NOTHING (information-theoretic). Generalizes the 2-of-2 XOR split (the k=n=2 case)
|
|
5
|
+
// to teams — "N members, any k present to open". Pure JS (no WebCrypto) → runs in the browser AND Node.
|
|
6
|
+
//
|
|
7
|
+
// Byte-wise: for each secret byte, a random degree-(k-1) polynomial with the byte as f(0); share j = f(j) at x=1..n;
|
|
8
|
+
// reconstruct via Lagrange interpolation at x=0. A share's wire form is base64url([x, ...yBytes]) — x is the 1-byte
|
|
9
|
+
// evaluation point, the rest are one y-byte per secret byte.
|
|
10
|
+
|
|
11
|
+
// base64url without Buffer (browser-safe; atob/btoa exist in Node 18+ too — same as e2ee.js).
|
|
12
|
+
const b64 = (bytes) => btoa(String.fromCharCode.apply(null, Array.from(bytes))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
13
|
+
const ub64 = (s) => {
|
|
14
|
+
const bin = atob(String(s).replace(/-/g, '+').replace(/_/g, '/'))
|
|
15
|
+
const a = new Uint8Array(bin.length)
|
|
16
|
+
for (let i = 0; i < bin.length; i++) a[i] = bin.charCodeAt(i)
|
|
17
|
+
return a
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── GF(256) tables (AES field x^8+x^4+x^3+x+1 = 0x11b, generator 3) ──
|
|
21
|
+
const EXP = new Uint8Array(512)
|
|
22
|
+
const LOG = new Uint8Array(256)
|
|
23
|
+
;(function initField() {
|
|
24
|
+
let x = 1
|
|
25
|
+
for (let i = 0; i < 255; i++) {
|
|
26
|
+
EXP[i] = x
|
|
27
|
+
LOG[x] = i
|
|
28
|
+
let x2 = x << 1
|
|
29
|
+
if (x2 & 0x100) x2 ^= 0x11b // x*2 in GF(256)
|
|
30
|
+
x = (x2 ^ x) & 0xff // x = x*3 (the generator)
|
|
31
|
+
}
|
|
32
|
+
for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255] // doubled so mul/div need no modulo
|
|
33
|
+
})()
|
|
34
|
+
const mul = (a, b) => (a === 0 || b === 0 ? 0 : EXP[LOG[a] + LOG[b]])
|
|
35
|
+
const div = (a, b) => (a === 0 ? 0 : EXP[LOG[a] + 255 - LOG[b]]) // b must be non-zero
|
|
36
|
+
|
|
37
|
+
// random bytes (WebCrypto's getRandomValues is a global in browser + Node — it's not part of subtle)
|
|
38
|
+
const rand = (n) => crypto.getRandomValues(new Uint8Array(n))
|
|
39
|
+
|
|
40
|
+
/** Split mk (base64url) into `n` shares (base64url strings); any `k` reconstruct it. Requires 2 ≤ k ≤ n ≤ 255. */
|
|
41
|
+
export function shamirSplit(mk, k, n) {
|
|
42
|
+
const secret = ub64(mk)
|
|
43
|
+
if (!secret.length) throw new Error('shamirSplit needs a key')
|
|
44
|
+
if (!(k >= 2 && k <= n && n <= 255)) throw new Error('need 2 ≤ k ≤ n ≤ 255')
|
|
45
|
+
const shares = []
|
|
46
|
+
for (let j = 1; j <= n; j++) shares.push({ x: j, y: new Uint8Array(secret.length) })
|
|
47
|
+
for (let bi = 0; bi < secret.length; bi++) {
|
|
48
|
+
const coeffs = new Uint8Array(k)
|
|
49
|
+
coeffs[0] = secret[bi] // f(0) = the secret byte
|
|
50
|
+
const rc = rand(k - 1)
|
|
51
|
+
for (let c = 1; c < k; c++) coeffs[c] = rc[c - 1] // random higher coefficients
|
|
52
|
+
for (const s of shares) {
|
|
53
|
+
let y = 0 // Horner: f(x) = ((c_{k-1}·x + c_{k-2})·x + …)·x + c_0
|
|
54
|
+
for (let c = k - 1; c >= 0; c--) y = mul(y, s.x) ^ coeffs[c]
|
|
55
|
+
s.y[bi] = y
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return shares.map((s) => b64(Uint8Array.of(s.x, ...s.y)))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Reconstruct mk (base64url) from ≥ k shares. Fewer than k → a WRONG value (verify with commit()). Order-independent;
|
|
62
|
+
* duplicate x's are rejected. */
|
|
63
|
+
export function shamirCombine(shareStrings) {
|
|
64
|
+
const pts = (shareStrings || []).map((s) => { const a = ub64(s); return { x: a[0], y: a.slice(1) } }).filter((p) => p.x)
|
|
65
|
+
if (pts.length < 2) return null
|
|
66
|
+
const xs = pts.map((p) => p.x)
|
|
67
|
+
if (new Set(xs).size !== xs.length) return null // duplicate share indices
|
|
68
|
+
const len = pts[0].y.length
|
|
69
|
+
const out = new Uint8Array(len)
|
|
70
|
+
for (let bi = 0; bi < len; bi++) {
|
|
71
|
+
let acc = 0
|
|
72
|
+
for (let j = 0; j < pts.length; j++) {
|
|
73
|
+
let num = 1
|
|
74
|
+
let den = 1
|
|
75
|
+
for (let m = 0; m < pts.length; m++) {
|
|
76
|
+
if (m === j) continue
|
|
77
|
+
num = mul(num, pts[m].x) // (0 - x_m) = x_m in GF(256)
|
|
78
|
+
den = mul(den, pts[j].x ^ pts[m].x) // (x_j - x_m) = x_j XOR x_m
|
|
79
|
+
}
|
|
80
|
+
acc ^= mul(pts[j].y[bi], div(num, den)) // y_j · L_j(0)
|
|
81
|
+
}
|
|
82
|
+
out[bi] = acc
|
|
83
|
+
}
|
|
84
|
+
return b64(out)
|
|
85
|
+
}
|
package/sharedViews.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// sharedViews.js — a shared room's VIEWS (its itinerary and maps) as compact text for a private lane's assistant, one
|
|
2
|
+
// rendering for the Spaces app (mirrorLoop.js) and the SDK (witbitz-sdk.js Lane). The lane's assistant cannot read the
|
|
3
|
+
// shared room's widget docs — another room, another key — so the member's device, which holds both keys, writes this text
|
|
4
|
+
// into the lane's sealed `sharedviews` doc, and the lane's turn reads it (agent/asyncTurn.mjs). The SDK never wrote it
|
|
5
|
+
// (sync sweep, 2026-10-10): an SDK lane's assistant could not see the plan everyone else was looking at.
|
|
6
|
+
// Pure — no DOM, no network. spaces/test/sharedViews.test.mjs.
|
|
7
|
+
|
|
8
|
+
export const SHARED_VIEWS_DOC = 'sharedviews'
|
|
9
|
+
export const SHARED_VIEWS_MAX = 12000 // the state allows 32 KB; a long multi-week plan must arrive whole
|
|
10
|
+
|
|
11
|
+
/** `views` = [{ label, state }] (a widget's label and its doc's state) → the text, or '' when there is nothing to say. */
|
|
12
|
+
export function renderSharedViews(views) {
|
|
13
|
+
const parts = []
|
|
14
|
+
for (const v of Array.isArray(views) ? views : []) {
|
|
15
|
+
const st = v && v.state
|
|
16
|
+
if (!st || typeof st !== 'object') continue
|
|
17
|
+
if (Array.isArray(st.days) && st.days.length) {
|
|
18
|
+
parts.push('ITINERARY' + (st.title ? ' — ' + st.title : '') + '\n' + st.days.map((d) => `${(d && d.name) || 'Day'}: ${((d && d.items) || []).map((i) => `${i && i.when ? i.when + ' — ' : ''}${(i && i.text) || ''}`).filter(Boolean).join('; ')}`).join('\n'))
|
|
19
|
+
} else if (Array.isArray(st.places) && st.places.length) {
|
|
20
|
+
parts.push('MAP (' + String((v && v.label) || 'map').replace(/^\W+\s*/, '') + '): ' + st.places.map((pl) => `${(pl && pl.name) || 'place'}${pl && Number.isFinite(pl.rating) ? ` ★${pl.rating}` : ''}${pl && pl.chosen ? ' (shortlisted)' : ''}`).join(', '))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return parts.join('\n\n').slice(0, SHARED_VIEWS_MAX)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The views a room's log names: each widget's doc name and label, newest first, at most `max`. */
|
|
27
|
+
export function viewsNamedIn(entries, max = 12) {
|
|
28
|
+
const out = [], seen = new Set()
|
|
29
|
+
const list = Array.isArray(entries) ? entries : []
|
|
30
|
+
for (let i = list.length - 1; i >= 0 && out.length < max; i--) {
|
|
31
|
+
const ws = list[i] && Array.isArray(list[i].widgets) ? list[i].widgets : []
|
|
32
|
+
for (const w of ws) {
|
|
33
|
+
if (!w || typeof w.name !== 'string' || !w.name || seen.has(w.name)) continue
|
|
34
|
+
seen.add(w.name); out.push({ name: w.name, label: typeof w.title === 'string' && w.title ? w.title : w.name })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out
|
|
38
|
+
}
|