@witbitz/sdk 0.0.0-stage → 4.4.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.
Files changed (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/a2aCore.js +221 -0
  4. package/a2aShared.js +27 -0
  5. package/accountErase.js +228 -0
  6. package/accountIndexDoc.js +122 -0
  7. package/accountOwner.js +59 -0
  8. package/accountRecord.js +90 -0
  9. package/accountScope.js +114 -0
  10. package/accountSeal.js +42 -0
  11. package/accountStores.js +173 -0
  12. package/acctV2App.js +619 -0
  13. package/acctV2Check.js +29 -0
  14. package/acctV2Client.js +382 -0
  15. package/acctV2Keys.js +43 -0
  16. package/acctV2Legacy.js +14 -0
  17. package/acctV2Switch.js +80 -0
  18. package/acctV2UiCore.js +857 -0
  19. package/acctV2WebAuthn.js +61 -0
  20. package/acctV2Wire.js +59 -0
  21. package/address.js +42 -0
  22. package/agentDoorTools.js +28 -0
  23. package/attestedBox.js +30 -0
  24. package/attestedRooms.js +78 -0
  25. package/awsKey.js +98 -0
  26. package/backupRecord.js +106 -0
  27. package/backupVault.js +97 -0
  28. package/blocks.js +115 -0
  29. package/blocksPush.js +64 -0
  30. package/browseSeal.js +103 -0
  31. package/cbor.js +225 -0
  32. package/changePush.js +75 -0
  33. package/chatLock.js +165 -0
  34. package/chatLockSw.js +13 -0
  35. package/cloudDeviceBuilds.js +11 -0
  36. package/cloudDevicePins.js +33 -0
  37. package/cloudDeviceSeal.js +53 -0
  38. package/codeAttachments.js +100 -0
  39. package/codeBrowse.js +224 -0
  40. package/codeCache.js +149 -0
  41. package/codeCloud.js +650 -0
  42. package/codeCloudKeys.js +112 -0
  43. package/codeCommands.js +167 -0
  44. package/codeComputers.js +389 -0
  45. package/codeEgress.js +123 -0
  46. package/codeFilesRoutes.js +17 -0
  47. package/codeFolders.js +116 -0
  48. package/codeHistory.js +76 -0
  49. package/codeLanguage.js +54 -0
  50. package/codeMkdir.js +8 -0
  51. package/codeModes.js +59 -0
  52. package/codeOrphanKeys.js +42 -0
  53. package/codeOutputs.js +141 -0
  54. package/codeProgress.js +54 -0
  55. package/codeRelay.js +505 -0
  56. package/codeSent.js +68 -0
  57. package/codeSentinel.js +86 -0
  58. package/codeSubagents.js +107 -0
  59. package/codeTransport.js +317 -0
  60. package/codeUndo.js +48 -0
  61. package/compress.js +24 -0
  62. package/config.js +11 -0
  63. package/connCatalog.js +164 -0
  64. package/connDisp.js +76 -0
  65. package/connOtherWays.js +74 -0
  66. package/connPending.js +16 -0
  67. package/connWrap.js +53 -0
  68. package/connectionEntry.js +89 -0
  69. package/connections.js +561 -0
  70. package/credits.js +30 -0
  71. package/csAttest.js +112 -0
  72. package/decrypt.html +384 -0
  73. package/deviceAttest.js +527 -0
  74. package/deviceCall.js +54 -0
  75. package/deviceKeyCore.js +41 -0
  76. package/deviceSeal.js +59 -0
  77. package/e2ee.js +323 -0
  78. package/eat.js +103 -0
  79. package/emailFork.js +275 -0
  80. package/emailSignIn.js +81 -0
  81. package/emptySpaces.js +111 -0
  82. package/encSource.js +55 -0
  83. package/enclaveAccept.js +214 -0
  84. package/enclaveClaim.js +241 -0
  85. package/enclaveRoute.js +102 -0
  86. package/enclaveSnapshotMerge.js +44 -0
  87. package/entrySig.js +165 -0
  88. package/env.js +73 -0
  89. package/eraseFile.js +58 -0
  90. package/followImage.js +86 -0
  91. package/healNames.js +45 -0
  92. package/idb.js +113 -0
  93. package/idbSeal.js +119 -0
  94. package/indexGone.js +12 -0
  95. package/invite.js +51 -0
  96. package/inviteEnroll.js +67 -0
  97. package/inviteSend.js +68 -0
  98. package/jobAgents.js +87 -0
  99. package/keptMerge.js +91 -0
  100. package/l1-worker-src.js +2 -0
  101. package/l1-worker.js +894 -0
  102. package/laneAssociation.js +68 -0
  103. package/laneConfig.js +58 -0
  104. package/laneLinkCore.js +177 -0
  105. package/ledgerView.js +64 -0
  106. package/manifest.json +239 -0
  107. package/mcpRecommended.js +25 -0
  108. package/memberChange.js +125 -0
  109. package/mirrorBatch.js +47 -0
  110. package/mkseal.js +101 -0
  111. package/nativePush.js +153 -0
  112. package/nitroVerify.js +220 -0
  113. package/noble-p256.js +27 -0
  114. package/notice.js +116 -0
  115. package/notifKey.js +58 -0
  116. package/offlineBundle.js +62 -0
  117. package/ohttp.js +177 -0
  118. package/opRouting.js +10 -0
  119. package/opencodeWire.js +282 -0
  120. package/oprf.js +70 -0
  121. package/ownAgentLink.js +96 -0
  122. package/ownerPolicy.js +117 -0
  123. package/package.json +273 -4
  124. package/pdfOptions.js +13 -0
  125. package/pdfText.js +107 -0
  126. package/pdfjs.mjs +28 -0
  127. package/pdfjs.worker.mjs +28 -0
  128. package/pollVerdict.js +33 -0
  129. package/prefetchPoll.js +60 -0
  130. package/protectedLocal.js +426 -0
  131. package/pushCore.js +42 -0
  132. package/recovery.js +107 -0
  133. package/regions.js +42 -0
  134. package/removedMessage.js +11 -0
  135. package/renameRefusal.js +9 -0
  136. package/replyQuote.js +34 -0
  137. package/reqEnvelope.js +126 -0
  138. package/roomDefaultPrefs.js +76 -0
  139. package/roomDelete.js +109 -0
  140. package/roomEmbed.js +111 -0
  141. package/roomName.js +177 -0
  142. package/roomPass.js +256 -0
  143. package/roomRoster.js +305 -0
  144. package/roomSettings.js +61 -0
  145. package/roomState.js +58 -0
  146. package/roomStreamClient.js +115 -0
  147. package/rosterCount.js +52 -0
  148. package/rosterHash.js +13 -0
  149. package/rowSchema.js +113 -0
  150. package/safeMedia.js +116 -0
  151. package/safeMediaPins.js +17 -0
  152. package/schedulesDoc.js +78 -0
  153. package/sdkA2A.js +524 -0
  154. package/sdkAccount.js +483 -0
  155. package/sdkAccountDoc.js +89 -0
  156. package/sdkAccountSections.js +332 -0
  157. package/sdkAgui.js +141 -0
  158. package/sdkAttest.js +34 -0
  159. package/sdkBackup.js +507 -0
  160. package/sdkBackupV2.js +630 -0
  161. package/sdkBrowserPrivate.js +28 -0
  162. package/sdkBuilds.js +208 -0
  163. package/sdkCloudDevice.js +221 -0
  164. package/sdkComputers.js +1009 -0
  165. package/sdkDictation.js +232 -0
  166. package/sdkErase.js +288 -0
  167. package/sdkExports.js +71 -0
  168. package/sdkInvitations.js +34 -0
  169. package/sdkKeptAgent.js +188 -0
  170. package/sdkLaneLink.js +205 -0
  171. package/sdkPlan.js +96 -0
  172. package/sdkProtect.js +228 -0
  173. package/sdkRedact.js +36 -0
  174. package/sdkRekey.js +340 -0
  175. package/sdkReport.js +68 -0
  176. package/sdkSafeMedia.js +255 -0
  177. package/sdkSchedules.js +39 -0
  178. package/sdkSpeech.js +71 -0
  179. package/sdkTemporaryRooms.js +123 -0
  180. package/sdkTurn.js +117 -0
  181. package/sdkVault.js +180 -0
  182. package/sealShare.js +18 -0
  183. package/sealedNames.js +64 -0
  184. package/sealedReceipt.js +17 -0
  185. package/sentinelRelease.js +155 -0
  186. package/shamir.js +85 -0
  187. package/sharedViews.js +52 -0
  188. package/sheetChrome.js +450 -0
  189. package/siri.js +278 -0
  190. package/spaceClient.js +1429 -0
  191. package/spaceConfig.js +81 -0
  192. package/spaceEmailGate.js +813 -0
  193. package/spaceExport.js +125 -0
  194. package/spaceFork.js +216 -0
  195. package/spaceLock.js +358 -0
  196. package/spacePasskey.js +180 -0
  197. package/spaceTemplates.js +99 -0
  198. package/speechOut.js +102 -0
  199. package/splitKeyClient.js +90 -0
  200. package/store.js +656 -0
  201. package/streamHint.js +36 -0
  202. package/sttCloud.js +220 -0
  203. package/sttWorklet.js +38 -0
  204. package/sw-notif-core.js +540 -0
  205. package/tempList.js +48 -0
  206. package/tinfoilVerifier.js +78 -0
  207. package/toolBooks.js +31 -0
  208. package/toolRules.js +52 -0
  209. package/turnCerts.js +254 -0
  210. package/turnFeed.js +58 -0
  211. package/turnVerdict.js +37 -0
  212. package/usageReceipts.js +176 -0
  213. package/usageSummary.js +90 -0
  214. package/util.js +181 -0
  215. package/vault-core.js +2326 -0
  216. package/vault-kit.mjs +354 -0
  217. package/vault-screens.js +261 -0
  218. package/vaultAtRest.js +208 -0
  219. package/vaultCoreLock.js +111 -0
  220. package/vaultCorePush.js +140 -0
  221. package/vaultDeviceKey.js +95 -0
  222. package/vaultEnclaveHandoff.js +114 -0
  223. package/vaultKeep.js +287 -0
  224. package/vaultSealedStore.js +77 -0
  225. package/vaultWorkerHost.js +117 -0
  226. package/vcWorker.js +34 -0
  227. package/voiceAttest.js +50 -0
  228. package/voiceCert.js +51 -0
  229. package/witbitz-admin.d.ts +135 -0
  230. package/witbitz-admin.js +529 -0
  231. package/witbitz-admin.mjs +1460 -0
  232. package/witbitz-sdk.d.ts +1197 -0
  233. package/witbitz-sdk.js +4258 -0
  234. package/workerClient.js +16 -0
  235. package/workerLiveness.js +21 -0
  236. package/x509.js +218 -0
package/spaceConfig.js ADDED
@@ -0,0 +1,81 @@
1
+ // M3 — Configurable Space: build a Space from a CONFIG (docs/configurable-space-m3.md). Generalizes the shared-presence
2
+ // KEY MODEL — 1-of-1 (solo) / 2-of-2 (couple) / k-of-n (team) — so ONE engine serves any small private AI Space, not
3
+ // just couples. The config is to a Space what the manifest is to an agent: { keyModel, agent(persona), tools,
4
+ // presence }. This module handles the KEY part (mint + distribute + reassemble); the agent/tools/presence are config
5
+ // fields the engine (spaceService) reads. A Space's capabilities are just TOOLS (declaredTools) — already config, no
6
+ // separate "actions" concept; the only async-Space addition is delegatedAuthority (approve-then-execute + audit).
7
+ import { newKey, splitKey, combineShares, commit } from './e2ee.js'
8
+ import { shamirSplit, shamirCombine } from './shamir.js'
9
+ import { newRoomId } from './regions.js'
10
+
11
+ const enc = (s) => encodeURIComponent(String(s))
12
+
13
+ /** Normalize a keyModel → { k, n }. '1-of-1' → {1,1} (solo); '2-of-2' → {2,2} (couple); { k, n } → a k-of-n team. */
14
+ export function normalizeKeyModel(km) {
15
+ if (km == null || km === '1-of-1') return { k: 1, n: 1 }
16
+ if (km === '2-of-2') return { k: 2, n: 2 }
17
+ if (km && Number.isInteger(km.k) && Number.isInteger(km.n) && km.k >= 1 && km.k <= km.n) return { k: km.k, n: km.n }
18
+ throw new Error('bad keyModel')
19
+ }
20
+
21
+ /** Build a Space from a config. Mints mk, distributes it per the key model, returns { room, commit, keyModel:{k,n},
22
+ * links[] }. Each link carries the room (query, server-visible) + ONE piece in the FRAGMENT — a share (`#s=`), or, for
23
+ * 1-of-1, mk itself (`#mk=`). mk is DISCARDED (reconstructable from the shares); the server stores only commit(mk). */
24
+ export async function createConfiguredSpace(config = {}, { base = '' } = {}) {
25
+ const { k, n } = normalizeKeyModel(config.keyModel)
26
+ // A SOLO room may be made with a key the caller derived (the SDK's account index, sdkAccount.js: every device holding
27
+ // the account derives the same room and key, so two devices can never make two indexes). Any other model mints.
28
+ const mk = (n === 1 && typeof config.mk === 'string' && config.mk.length >= 40) ? config.mk : newKey()
29
+ // `region`: the room's HOME region (regions.js, docs/multi-region.md) — the caller decides: a lane takes its shared room's,
30
+ // a moved room keeps its own, a new Space takes its creator's; the account's own rooms (index, pipes) pass none and stay
31
+ // in the default region. Never sealed into the config — it is in the id.
32
+ const room = config.room || newRoomId(config.region)
33
+ const c = await commit(mk)
34
+ const link = (frag) => `${String(base).replace(/\/+$/, '')}/space?room=${enc(room)}#${frag}`
35
+ let links
36
+ if (n === 1) {
37
+ links = [link(`mk=${enc(mk)}`)] // solo: the single member's link carries mk (like the gift today)
38
+ } else if (k === 2 && n === 2) {
39
+ const { shareA, shareB } = splitKey(mk) // couple: XOR 2-of-2 (the simplest, perfect case)
40
+ links = [link(`s=${enc(shareA)}`), link(`s=${enc(shareB)}`)]
41
+ } else {
42
+ links = shamirSplit(mk, k, n).map((s) => link(`s=${enc(s)}`)) // team: Shamir k-of-n
43
+ }
44
+ return { room, commit: c, keyModel: { k, n }, links }
45
+ }
46
+
47
+ /** Assemble the room key from the present members' pieces, per the config's key model, verified against the commitment.
48
+ * `pieces` = the shares from present members (or [mk] for solo). Returns mk, or null if the threshold isn't met / the
49
+ * reconstruction doesn't match the commit (the room stays sealed). */
50
+ export async function assembleConfiguredKey(pieces, config, expectedCommit) {
51
+ const { k, n } = normalizeKeyModel(config && config.keyModel)
52
+ const arr = Array.isArray(pieces) ? pieces.filter(Boolean) : pieces ? [pieces] : []
53
+ let mk = null
54
+ if (n === 1) mk = arr[0] || null // solo: the piece IS mk
55
+ else if (k === 2 && n === 2) mk = arr.length >= 2 ? combineShares(arr[0], arr[1]) : null
56
+ else mk = arr.length >= k ? shamirCombine(arr) : null // team: need ≥ k
57
+ if (mk == null) return null
58
+ // §6.4 (tenant-split-key-design.md): a MULTI-SHARE reconstruction (n > 1: couple/team) is only trustworthy once checked
59
+ // against the room's registered commitment. Refuse to return a combined key with no commit to verify it — the solo case
60
+ // (n === 1: the link IS mk) is exempt, since a wrong link simply fails AES-GCM downstream, not a silent wrong-key.
61
+ if (n > 1 && !expectedCommit) return null
62
+ if (expectedCommit && (await commit(mk)) !== expectedCommit) return null
63
+ return mk
64
+ }
65
+
66
+ /** Read a Space link → { room, share?, mk? } (room from the query; share/mk from the fragment). */
67
+ export function parseConfiguredLink(url) {
68
+ try {
69
+ const u = new URL(url)
70
+ // The fragment is `<space-params>?<identity-params>` — a member link appends `?gk=…&gt=…&sk=…` (see entrySig
71
+ // appendIdentity) after `#mk=…`/`#s=…`. Parse ONLY the part before that first `?`, or `mk`/`s` would swallow the
72
+ // whole identity blob (`mk=<key>?gk=…`) and fail to base64-decode → the invite lands on the create screen. Identity
73
+ // is read separately (readIdentity, from after the `?`).
74
+ const raw = (u.hash || '').replace(/^#/, '')
75
+ const q = raw.indexOf('?')
76
+ const frag = new URLSearchParams(q >= 0 ? raw.slice(0, q) : raw)
77
+ return { room: u.searchParams.get('room') || '', share: frag.get('s') || '', mk: frag.get('mk') || '' }
78
+ } catch {
79
+ return { room: '', share: '', mk: '' }
80
+ }
81
+ }