@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/acctV2UiCore.js
ADDED
|
@@ -0,0 +1,857 @@
|
|
|
1
|
+
// acctV2UiCore.js — the account recovery v2 screens and cards (askCode with "Continue with Google", showCode, the devices
|
|
2
|
+
// section, Advanced Backup, start / restore / add a device / delete), for BOTH apps: the regular app's page (acctV2Ui.js
|
|
3
|
+
// wires it to acctV2Wiring.js) and the hosted app's VAULT (acctV2VaultWiring.js — docs/hosted-account-v2-plan.md: the
|
|
4
|
+
// client runs where the master is). It imports no page state: the wiring that loads it hands over the account client, the
|
|
5
|
+
// account's address and the confirm card (setAcctV2UiDeps) — so the vault never loads the regular page's modules.
|
|
6
|
+
import { BASE_KEY, newAccountService, baseOf } from './acctV2Switch.js'
|
|
7
|
+
import { GOOGLE_CLIENT_ID } from './config.js' // the same address as every other importer
|
|
8
|
+
import { onKeyPrompt } from './acctV2WebAuthn.js'
|
|
9
|
+
|
|
10
|
+
// THE WIRING (set once by the page that loads this): { acctV2() → the client (acctV2App.makeAcctV2), accountAddress() → the
|
|
11
|
+
// account's email or null, confirm({ message, confirmLabel, cancelLabel, destructive }) → Promise<boolean>, offerFresh(),
|
|
12
|
+
// onStagingApp(), onProdPreview(), sectionTitle?, and for Release 3's move (§ 12.2) moveService() → the service this account
|
|
13
|
+
// would move to ('' = none here), oldAccountHere() → this device holds an account still on the OLD service, switchOn(svc) → undo,
|
|
14
|
+
// afterMove() → sign out the account's other devices (gracefully: devices.js MOVED_MARK) → their ids, or null when unknown }
|
|
15
|
+
let _deps = null
|
|
16
|
+
export function setAcctV2UiDeps(d) { _deps = d || null }
|
|
17
|
+
const dep = () => { if (!_deps) throw Object.assign(new Error('acct_v2_unwired'), { code: 'acct_v2_unwired' }); return _deps }
|
|
18
|
+
export const acctV2 = () => dep().acctV2()
|
|
19
|
+
export const accountAddress = () => dep().accountAddress()
|
|
20
|
+
const offerFresh = () => { try { return !!(dep().offerFresh && dep().offerFresh()) } catch { return false } }
|
|
21
|
+
const onStagingApp = () => { try { return !!(dep().onStagingApp && dep().onStagingApp()) } catch { return false } }
|
|
22
|
+
const onProdPreview = () => { try { return !!(dep().onProdPreview && dep().onProdPreview()) } catch { return false } }
|
|
23
|
+
const confirmSheet = (o) => dep().confirm(o)
|
|
24
|
+
/** The page's confirm card (acctV2ResetCore.js asks through it too). */
|
|
25
|
+
export const confirmCard = (o) => confirmSheet(o)
|
|
26
|
+
|
|
27
|
+
const MESSAGES = {
|
|
28
|
+
key_registered: 'This browser was used for another account on the new service. Reload the page and try again — if it happens again, clear this site’s data (or use a new browser profile).',
|
|
29
|
+
email_code_wrong: 'That code didn’t match. Nothing changed — try again.',
|
|
30
|
+
need_code: 'This device doesn’t have a copy of your recovery code. Enter it to continue.',
|
|
31
|
+
no_backup: 'This device has no backup to move yet.',
|
|
32
|
+
no_account_key: 'This device doesn’t hold your account key. Move the account from another of your devices.',
|
|
33
|
+
already_migrated: 'This account has already been moved.',
|
|
34
|
+
v2_off: 'The new account service isn’t switched on for this device.',
|
|
35
|
+
not_migrated: 'Move this account to the new account service first.',
|
|
36
|
+
no_legacy_gate: 'The new service can’t find this account’s backup to move. Use “Start on the new service” instead.',
|
|
37
|
+
no_account: 'No account on the new service has that recovery code. Check it and try again.',
|
|
38
|
+
bad_code: 'That doesn’t look like a recovery code. Check it and try again.',
|
|
39
|
+
wrapper_unopened: 'That recovery code doesn’t open this account’s backup. Nothing changed.',
|
|
40
|
+
backup_unopened: 'The backup couldn’t be opened. Nothing changed — try again in a moment.',
|
|
41
|
+
backup_unconfigured: 'That account has no recovery code yet, so it can’t be restored.',
|
|
42
|
+
already_migrated: 'This device already has an account on the new service.',
|
|
43
|
+
need_security_key: 'This needs one of your security keys, and this device can’t ask for one.',
|
|
44
|
+
key_cancelled: 'The security key didn’t answer — the prompt was closed, timed out, or a key that isn’t on this account was touched. Nothing changed.',
|
|
45
|
+
key_wrong_site: 'Security keys can’t be used in this app yet.', // accounts are per app (sync sweep 11-16 #17): never sent to another app's address
|
|
46
|
+
webauthn_unavailable: 'This browser can’t use security keys.',
|
|
47
|
+
key_already_registered: 'That key is already on this account. Use a different key.',
|
|
48
|
+
attestation_refused: 'That key can’t be used for Advanced Backup. It must be a YubiKey with a PIN (or fingerprint) set up.',
|
|
49
|
+
advanced_not_enabled: 'Advanced Backup isn’t available yet.',
|
|
50
|
+
possession_pending: 'Set up your recovery code first.',
|
|
51
|
+
email_only: 'This account was moved with your email only, so Advanced Backup isn’t available for it.',
|
|
52
|
+
too_many_keys: 'This account already has the most security keys it can hold (5).',
|
|
53
|
+
no_other_key: 'Removing a key needs another of your keys to confirm it.',
|
|
54
|
+
keys_mismatch: 'The service answered with keys this device didn’t register. Nothing was changed.',
|
|
55
|
+
session_ended: 'That took too long or something changed meanwhile. Nothing changed — start again.',
|
|
56
|
+
pending_not_kept: 'This device couldn’t save the new recovery code, so it wasn’t activated. Your current code still works — free some space or try again.',
|
|
57
|
+
address_taken: 'That email address already has an account on the new service. Restore it on this device instead (“Restore my account from the new service”).',
|
|
58
|
+
bad_address: 'That doesn’t look like an email address.',
|
|
59
|
+
state_changed: 'Something changed on your account meanwhile. Nothing changed — start again.',
|
|
60
|
+
bad_new_device: 'That device’s code isn’t valid. Show a new code on it and scan again.',
|
|
61
|
+
enrol_key_registered: 'That device was used for another account, or was signed out of this one. On it, use Settings → Reset this device, then show a new code.',
|
|
62
|
+
device_proof: 'This device is no longer one of your account’s devices, so it can’t add another. Nothing was sent.',
|
|
63
|
+
google_not_authoritative: 'Google can’t confirm this address (only a Gmail or Google Workspace address). Use the emailed code instead.',
|
|
64
|
+
google_refused: 'That Google sign-in didn’t check out. Try again, or use the emailed code.',
|
|
65
|
+
google_stale: 'That Google sign-in was too old. Try again, or use the emailed code.',
|
|
66
|
+
not_this_account: 'That Google account isn’t this account’s email. Sign in with the right Google account, or use the emailed code.',
|
|
67
|
+
google_other_address: 'That Google account is a different address from the one you typed. Sign in with that address’s Google account, or use the emailed code.',
|
|
68
|
+
google_used: 'That Google sign-in was already used. Try again.',
|
|
69
|
+
reset_open: 'A move of this email is already under way. It has to finish or be cancelled first.',
|
|
70
|
+
reset_ended: 'That move has ended (it was cancelled, or too much time passed). Start again if you still need it.',
|
|
71
|
+
not_yet: 'The week isn’t over yet — finish the move on the date shown. (A device of the old account may have asked for more time: the move then waits 30 days from its start.)',
|
|
72
|
+
already_objected: 'More time was already asked for on this move — it can be asked for only once. The date shown is when it moves.',
|
|
73
|
+
no_reset: 'There’s no move of this email under way on this device.',
|
|
74
|
+
reset_conflict: 'Something changed on that account meanwhile. Try finishing again.',
|
|
75
|
+
feature_unavailable: 'This isn’t available yet.',
|
|
76
|
+
not_ours: 'That device is no longer one of your account’s devices. Nothing changed.',
|
|
77
|
+
not_this_device: 'That is the device you’re using. Nothing changed.',
|
|
78
|
+
google_unavailable: 'Google sign-in isn’t available for this yet. Use the emailed code.',
|
|
79
|
+
}
|
|
80
|
+
// An unexpected failure names its reason (the service's code, or the browser's error), so a report can say what happened.
|
|
81
|
+
export const messageFor = (e) => {
|
|
82
|
+
if (MESSAGES[e && e.code]) return MESSAGES[e.code]
|
|
83
|
+
try { console.error('account v2:', e) } catch { /* */ }
|
|
84
|
+
const why = e ? [e.code, e.name, e.message].filter(Boolean).join(': ') : 'unknown'
|
|
85
|
+
return `Something went wrong (${why.slice(0, 160)}). Nothing changed — try again in a moment.`
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A small card asking for the 6-digit code (or, with `field: 'recovery'`, the recovery code). → the text, or null. */
|
|
89
|
+
export const RESTORE_INSTEAD = Symbol('restore instead')
|
|
90
|
+
export const MOVE_EMAIL = Symbol('move the email to a new account') // § 11.5, acctV2Reset.js
|
|
91
|
+
/** The email a Google ID token names (its payload's `email`), or null — the address of a restore that went through Google. */
|
|
92
|
+
const googleEmailOf = (idToken) => { try { const b = String(idToken).split('.')[1].replace(/-/g, '+').replace(/_/g, '/'); const j = JSON.parse(atob(b + '='.repeat((4 - b.length % 4) % 4))); return typeof j.email === 'string' ? j.email : null } catch { return null } }
|
|
93
|
+
|
|
94
|
+
/** The nonce a Google sign-in for `action` carries — the service checks the same (acct/googleProof.mjs googleNonce). */
|
|
95
|
+
export async function googleNonce(action) {
|
|
96
|
+
const h = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode('witbitz-acct-google|' + String(action))))
|
|
97
|
+
return btoa(String.fromCharCode(...h)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
98
|
+
}
|
|
99
|
+
/** `alt` = { label, id }: a second way out — resolves RESTORE_INSTEAD. `google` = { action, address }: "Continue with
|
|
100
|
+
* Google" — a Google sign-in for THAT action (its nonce) in place of the code — resolves { google: idToken }. */
|
|
101
|
+
export function askCode({ title, message, field = 'email', alt = null, alts = null, google = null }) {
|
|
102
|
+
const ways = alts || (alt ? [alt] : []) // each { id, label, value? } — resolves its value (RESTORE_INSTEAD by default)
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
const shade = document.createElement('div')
|
|
105
|
+
shade.id = 'acctV2CodeCard'
|
|
106
|
+
shade.style.cssText = 'position:fixed; inset:0; z-index:2147483000; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; padding:16px'
|
|
107
|
+
shade.className = 'kbfit' // with the keys up it fits the visible area (space.html), its field above them
|
|
108
|
+
const card = document.createElement('div')
|
|
109
|
+
card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true')
|
|
110
|
+
card.style.cssText = 'background:var(--bg, #fff); color:var(--fg, #111); border-radius:14px; padding:18px; width:100%; max-width:360px; box-shadow:0 10px 40px rgba(0,0,0,.3)'
|
|
111
|
+
const h = document.createElement('div'); h.textContent = title; h.style.cssText = 'font-weight:600; font-size:17px; margin-bottom:6px'
|
|
112
|
+
const p = document.createElement('div'); p.textContent = message; p.style.cssText = 'font-size:14px; opacity:.8; margin-bottom:12px; line-height:1.4; white-space:pre-line'
|
|
113
|
+
const input = document.createElement('input')
|
|
114
|
+
input.id = 'acctV2CodeInput'
|
|
115
|
+
input.autocomplete = field === 'email' ? 'one-time-code' : field === 'address' ? 'email' : 'off'
|
|
116
|
+
input.inputMode = field === 'email' ? 'numeric' : field === 'address' ? 'email' : 'text'
|
|
117
|
+
input.placeholder = field === 'email' ? '6-digit code' : field === 'address' ? 'you@example.com' : 'XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XX'
|
|
118
|
+
input.style.cssText = 'width:100%; box-sizing:border-box; font-size:18px; padding:10px; border-radius:10px; border:1px solid rgba(127,127,127,.4); background:transparent; color:inherit; letter-spacing:.08em'
|
|
119
|
+
const row = document.createElement('div'); row.style.cssText = 'display:flex; gap:8px; margin-top:14px'
|
|
120
|
+
const cancel = document.createElement('button'); cancel.type = 'button'; cancel.textContent = 'Cancel'
|
|
121
|
+
const ok = document.createElement('button'); ok.type = 'button'; ok.id = 'acctV2CodeOk'; ok.textContent = 'Continue'
|
|
122
|
+
for (const b of [cancel, ok]) b.style.cssText = 'flex:1; padding:11px; border-radius:10px; border:0; font-size:15px; cursor:pointer'
|
|
123
|
+
ok.style.background = 'var(--accent, #1f5fd6)'; ok.style.color = '#fff'
|
|
124
|
+
if (google && field === 'address') ok.textContent = 'Email me a code'
|
|
125
|
+
const done = (v) => { shade.remove(); resolve(v) }
|
|
126
|
+
cancel.onclick = () => done(null)
|
|
127
|
+
ok.onclick = () => { const v = input.value.trim(); if (v) done(field === 'email' ? v.replace(/\D/g, '') : v) }
|
|
128
|
+
input.onkeydown = (e) => { if (e.key === 'Enter') ok.onclick(); if (e.key === 'Escape') done(null) }
|
|
129
|
+
row.append(cancel, ok)
|
|
130
|
+
card.append(h, p)
|
|
131
|
+
// GOOGLE IN PLACE OF THE CODE (owner, 2026-11-15: "Everywhere there is code should also have Gmail also"): the service
|
|
132
|
+
// accepts it only for a Gmail or Google Workspace address, freshly, for this very request (acct/googleProof.mjs)
|
|
133
|
+
if (google && google.action && (field === 'email' || field === 'address')) {
|
|
134
|
+
const g = document.createElement('button'); g.type = 'button'; g.id = 'acctV2Google'; g.textContent = 'Continue with Google'
|
|
135
|
+
g.style.cssText = 'display:block; width:100%; margin:0 0 12px; padding:11px; border-radius:10px; border:1px solid rgba(127,127,127,.4); background:transparent; color:inherit; font-size:15px; cursor:pointer'
|
|
136
|
+
const gmsg = document.createElement('div'); gmsg.style.cssText = 'font-size:13px; color:#c0392b; margin:-6px 0 10px; display:none'
|
|
137
|
+
// READY BEFORE THE TAP: the nonce and the sign-in module are made now, so the tap reaches googleIdToken with nothing awaited.
|
|
138
|
+
// In the hosted app's vault that opens Google's page with window.open, and a browser lets a page open a window only from the
|
|
139
|
+
// tap itself — two awaits first (a digest, an import) could cost Safari's permission, and a blocked window read as "didn't
|
|
140
|
+
// work here" (the owner's iPhone, 2026-11-16, Add a device's approval).
|
|
141
|
+
let pre = null
|
|
142
|
+
const ready = Promise.all([googleNonce(google.action), import('./spaceEmailGate.js')]) // a DYNAMIC import carries its own stamp
|
|
143
|
+
ready.then((v) => { pre = v }, () => {})
|
|
144
|
+
g.onclick = async () => {
|
|
145
|
+
gmsg.style.display = 'none'
|
|
146
|
+
shade.style.display = 'none' // the Google card sits lower on the screen's stack: this card steps aside, and back on a cancel
|
|
147
|
+
try {
|
|
148
|
+
const [nonce, { googleIdToken }] = pre || await ready
|
|
149
|
+
const r = await googleIdToken({ clientId: GOOGLE_CLIENT_ID, nonce, fresh: true, googleOwn: true, copy: { title: 'Confirm with Google', sub: field === 'address' ? 'Sign in with the Google account of your Spaces account.' : 'Instead of the emailed code: sign in with the Google account of ' + (google.address || 'this email') + '.' } })
|
|
150
|
+
if (r && r.idToken) done({ google: r.idToken })
|
|
151
|
+
} catch (e) { if (!(e && /cancel/.test(String(e.message)))) { gmsg.textContent = field === 'address' ? 'Google sign-in didn’t work here — enter your email for a code.' : 'Google sign-in didn’t work here — use the emailed code.'; gmsg.style.display = 'block' } }
|
|
152
|
+
if (shade.isConnected) shade.style.display = 'flex'
|
|
153
|
+
}
|
|
154
|
+
card.append(g, gmsg)
|
|
155
|
+
}
|
|
156
|
+
// the second way out ABOVE the buttons: under them the keyboard hid it (owner's iPhone, 2026-11-15)
|
|
157
|
+
for (const w of ways) {
|
|
158
|
+
const a = document.createElement('button'); a.type = 'button'; a.id = w.id || 'acctV2CodeAlt'; a.textContent = w.label
|
|
159
|
+
a.style.cssText = 'display:block; width:100%; margin:0 0 8px; padding:6px; border:0; background:none; color:var(--accent, #1f5fd6); font-size:14px; cursor:pointer; text-decoration:underline'
|
|
160
|
+
a.onclick = () => done(w.value || RESTORE_INSTEAD)
|
|
161
|
+
card.append(a)
|
|
162
|
+
}
|
|
163
|
+
card.append(input, row)
|
|
164
|
+
shade.append(card)
|
|
165
|
+
document.body.append(shade)
|
|
166
|
+
setTimeout(() => input.focus(), 0)
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Show a new recovery code until the person says it is saved. The code is NOT active yet — the activation follows. */
|
|
171
|
+
export function showCode(code) {
|
|
172
|
+
return new Promise((resolve) => {
|
|
173
|
+
const shade = document.createElement('div')
|
|
174
|
+
shade.id = 'acctV2ShowCode'
|
|
175
|
+
shade.style.cssText = 'position:fixed; inset:0; z-index:2147483000; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; padding:16px'
|
|
176
|
+
shade.className = 'kbfit' // with the keys up it fits the visible area (space.html), its field above them
|
|
177
|
+
const card = document.createElement('div')
|
|
178
|
+
card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true')
|
|
179
|
+
card.style.cssText = 'background:var(--bg, #fff); color:var(--fg, #111); border-radius:14px; padding:18px; width:100%; max-width:380px; box-shadow:0 10px 40px rgba(0,0,0,.3)'
|
|
180
|
+
const h = document.createElement('div'); h.textContent = 'Your new recovery code'; h.style.cssText = 'font-weight:600; font-size:17px; margin-bottom:6px'
|
|
181
|
+
const p = document.createElement('div'); p.textContent = 'Write it down or save it somewhere safe. It replaces your old code once you continue — not before.'; p.style.cssText = 'font-size:14px; opacity:.8; margin-bottom:12px; line-height:1.4'
|
|
182
|
+
const c = document.createElement('div'); c.id = 'acctV2NewCode'; c.textContent = code
|
|
183
|
+
c.style.cssText = 'font-family:ui-monospace, Menlo, monospace; font-size:17px; letter-spacing:.05em; padding:12px; border-radius:10px; background:rgba(127,127,127,.12); text-align:center; user-select:all; word-break:break-all'
|
|
184
|
+
const ok = document.createElement('button'); ok.type = 'button'; ok.id = 'acctV2CodeSaved'; ok.textContent = 'I’ve saved it — continue'
|
|
185
|
+
ok.style.cssText = 'width:100%; margin-top:14px; padding:11px; border-radius:10px; border:0; font-size:15px; cursor:pointer; background:var(--accent, #1f5fd6); color:#fff'
|
|
186
|
+
ok.onclick = () => { shade.remove(); resolve() }
|
|
187
|
+
// A COPY BUTTON (the owner, 2026-11-21: "why dont we have a copy glyph?"), as the old service's sheet has (recCopy): the code goes
|
|
188
|
+
// to the clipboard; where the clipboard is refused, the code is selected for a manual copy.
|
|
189
|
+
const cp = document.createElement('button'); cp.type = 'button'; cp.id = 'acctV2CopyCode'; cp.textContent = 'Copy code'
|
|
190
|
+
cp.style.cssText = 'width:100%; margin-top:10px; padding:10px; border-radius:10px; border:1px solid rgba(127,127,127,.4); background:transparent; color:inherit; font-size:15px; cursor:pointer'
|
|
191
|
+
cp.onclick = async () => {
|
|
192
|
+
try { await navigator.clipboard.writeText(code); cp.textContent = 'Copied ✓'; setTimeout(() => { cp.textContent = 'Copy code' }, 1500) }
|
|
193
|
+
catch { try { const r = document.createRange(); r.selectNodeContents(c); const sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(r) } catch { /* the code is on screen */ } cp.textContent = 'Selected — copy it' }
|
|
194
|
+
}
|
|
195
|
+
card.append(h, p, c, cp, ok)
|
|
196
|
+
shade.append(card)
|
|
197
|
+
document.body.append(shade)
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const notice = (message) => confirmSheet({ message, confirmLabel: 'OK', cancelLabel: '', destructive: false })
|
|
202
|
+
|
|
203
|
+
/** The email code, asked after the service has sent it (the flows call this once the request is on its way). */
|
|
204
|
+
// The service answers alike whether or not it mailed (§ 9.3), so the card names every reason a code may not come:
|
|
205
|
+
// `kind` 'new' = starting an account (no code to an address that already has one), else an action on an account (no code
|
|
206
|
+
// to any address but the account's own). Both: over the per-address limit nothing comes.
|
|
207
|
+
export const noCodeHelp = (kind) => 'Nothing after a minute or two? Check spam. '
|
|
208
|
+
+ (kind === 'new'
|
|
209
|
+
? 'If this email already has an account, nothing is sent: use Restore with your recovery code instead. '
|
|
210
|
+
: kind === 'claim' ? '' // moving the email (§ 11.5): a code is mailed to the address whatever account it has
|
|
211
|
+
: 'A code only goes to the email this account was made with — make sure it’s that one. ')
|
|
212
|
+
+ 'If you’ve asked for several codes in the last hour, a new one may only come once the hour is up.'
|
|
213
|
+
// STARTING an account, the card also offers Restore (owner's iPhone, 2026-11-15: "Start a new account" with an email that
|
|
214
|
+
// already had an account on the new service waited for a code that never comes — one account per email there)
|
|
215
|
+
// GOOGLE OR THE EMAILED CODE, ASKED FIRST (the owner, 2026-11-16: "It should first ask for a choice between sending the code and
|
|
216
|
+
// Google login. Currently it automatically sends the code"): acctV2Client asks `choose` before anything is mailed. → { google }
|
|
217
|
+
// (Google's own token for this action — the code is never sent), { email: true } (send the code), or a `cancelled` error.
|
|
218
|
+
// A Google sign-in that fails leaves the card up with a line saying so: the email is still there to choose.
|
|
219
|
+
export function chooseProof({ address, action }) {
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
const shade = document.createElement('div'); shade.id = 'acctV2Choose'
|
|
222
|
+
shade.style.cssText = 'position:fixed; inset:0; z-index:2147483000; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; padding:16px'
|
|
223
|
+
const card = document.createElement('div'); card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true')
|
|
224
|
+
card.style.cssText = 'background:var(--bg, #fff); color:var(--fg, #111); border-radius:14px; padding:18px; width:100%; max-width:360px; box-shadow:0 10px 40px rgba(0,0,0,.3)'
|
|
225
|
+
const h = document.createElement('div'); h.textContent = 'Confirm it’s you'; h.style.cssText = 'font-weight:600; font-size:17px; margin-bottom:6px'
|
|
226
|
+
const p = document.createElement('div'); p.textContent = `Sign in with the Google account of ${address || 'your email'}, or get a 6-digit code by email.`; p.style.cssText = 'font-size:14px; opacity:.8; margin-bottom:14px; line-height:1.4'
|
|
227
|
+
const btn = (id, label, primary) => { const b = document.createElement('button'); b.type = 'button'; b.id = id; b.textContent = label; b.style.cssText = 'display:block; width:100%; margin:0 0 10px; padding:11px; border-radius:10px; font-size:15px; cursor:pointer; ' + (primary ? 'border:0; background:var(--accent, #1f5fd6); color:#fff' : 'border:1px solid rgba(127,127,127,.4); background:transparent; color:inherit'); return b }
|
|
228
|
+
const g = btn('acctV2ChooseGoogle', 'Continue with Google', true), m = btn('acctV2ChooseEmail', 'Email me a code', false), c = btn('acctV2ChooseCancel', 'Cancel', false)
|
|
229
|
+
c.style.border = '0'
|
|
230
|
+
const gmsg = document.createElement('div'); gmsg.style.cssText = 'font-size:13px; color:#c0392b; margin:-4px 0 10px; display:none'
|
|
231
|
+
const done = (fn) => { shade.remove(); fn() }
|
|
232
|
+
// READY BEFORE THE TAP (as askCode): Safari lets a page open the broker's window only from the tap itself
|
|
233
|
+
let pre = null
|
|
234
|
+
const ready = Promise.all([googleNonce(action), import('./spaceEmailGate.js')])
|
|
235
|
+
ready.then((v) => { pre = v }, () => {})
|
|
236
|
+
g.onclick = async () => {
|
|
237
|
+
gmsg.style.display = 'none'; shade.style.display = 'none'
|
|
238
|
+
try {
|
|
239
|
+
const [nonce, { googleIdToken }] = pre || await ready
|
|
240
|
+
const r = await googleIdToken({ clientId: GOOGLE_CLIENT_ID, nonce, fresh: true, googleOwn: true, copy: { title: 'Confirm with Google', sub: 'Sign in with the Google account of ' + (address || 'this email') + '.' } })
|
|
241
|
+
if (r && r.idToken) return done(() => resolve({ google: r.idToken }))
|
|
242
|
+
} catch (e) { if (!(e && /cancel/.test(String(e.message)))) { gmsg.textContent = 'Google sign-in didn’t work here — get the code by email instead.'; gmsg.style.display = 'block' } }
|
|
243
|
+
if (shade.isConnected) shade.style.display = 'flex'
|
|
244
|
+
}
|
|
245
|
+
m.onclick = () => done(() => resolve({ email: true }))
|
|
246
|
+
c.onclick = () => done(() => reject(Object.assign(new Error('cancelled'), { code: 'cancelled' })))
|
|
247
|
+
card.append(h, p, g, gmsg, m, c); shade.append(card); document.body.append(shade)
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
/** A getCode that asks Google-or-email FIRST (acctV2Client chooseFirst), then the code when the email was chosen. */
|
|
251
|
+
const withChoice = (address, fn) => Object.assign(fn, { choose: ({ action }) => chooseProof({ address, action }) })
|
|
252
|
+
export const emailCode = (address, kind = 'account') => withChoice(address, async (ctx = {}) => {
|
|
253
|
+
const c = await askCode({ title: 'Check your email', message: `We sent a 6-digit code to ${address}. Enter it to continue.\n\n${noCodeHelp(kind)}`, ...(ctx.action && !ctx.chose ? { google: { action: ctx.action, address } } : {}), ...(kind === 'new' ? { alts: [{ id: 'acctV2RestoreInstead', label: 'No code? This email already has an account — restore it' }, { id: 'acctV2MoveEmail', label: 'Lost that account’s recovery code and devices? Move this email to a new account', value: MOVE_EMAIL }] } : {}) })
|
|
254
|
+
if (c === RESTORE_INSTEAD) throw Object.assign(new Error('restore_instead'), { code: 'restore_instead' })
|
|
255
|
+
if (c === MOVE_EMAIL) throw Object.assign(new Error('move_email'), { code: 'move_email' })
|
|
256
|
+
if (c && typeof c === 'object' && c.google) return c // a Google sign-in in place of the code (acctV2Client emailProof)
|
|
257
|
+
if (!c) throw Object.assign(new Error('cancelled'), { code: 'cancelled' })
|
|
258
|
+
return c
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
/** Append the section to the devices box; `rerender` redraws the panel after a change. */
|
|
262
|
+
export function renderAcctV2Section(box, rerender) {
|
|
263
|
+
const a = acctV2()
|
|
264
|
+
if (!a.enabled()) { renderMoveOnly(box, rerender); return } // an account on the OLD service: only the move, where it is open
|
|
265
|
+
const s = a.state()
|
|
266
|
+
const sec = document.createElement('div')
|
|
267
|
+
sec.id = 'acctV2Section'
|
|
268
|
+
sec.style.cssText = 'margin-top:14px; padding-top:10px; border-top:1px solid rgba(127,127,127,.25)'
|
|
269
|
+
const t = document.createElement('div'); t.className = 'sheet-s'; t.style.cssText = 'padding:4px; font-weight:600'; t.textContent = dep().sectionTitle || 'New account service (preview)'
|
|
270
|
+
const d = document.createElement('div'); d.className = 'sheet-s'; d.style.cssText = 'padding:4px 4px 8px; opacity:.75'
|
|
271
|
+
const b = document.createElement('button'); b.className = 'dev-out'; b.type = 'button'; b.style.cssText = 'width:100%; padding:10px'
|
|
272
|
+
const address = accountAddress()
|
|
273
|
+
if (!s) {
|
|
274
|
+
d.textContent = MOVE_TEXT
|
|
275
|
+
b.id = 'acctV2Move'; b.textContent = 'Move to the new account service'
|
|
276
|
+
b.onclick = () => moveAccount(rerender)
|
|
277
|
+
} else {
|
|
278
|
+
d.textContent = s.trust === 'email_only' ? 'This account uses the new account service (moved with your email only).' : 'This account uses the new account service.'
|
|
279
|
+
b.id = 'acctV2SignOutAll'; b.textContent = 'Sign out all other devices now'
|
|
280
|
+
b.onclick = async () => {
|
|
281
|
+
if (!(await confirmSheet({ message: `Sign out every other device now?\n\nFrom this moment they can’t use your account, your backup or your recovery. A device that connects again removes this account from itself. One that never reconnects — lost or stolen — keeps the Spaces already on it: sign-out can’t reach those. We’ll send a code to ${address}.`, confirmLabel: 'Sign out' }))) return
|
|
282
|
+
try {
|
|
283
|
+
await withSteps(() => a.signOutOthers({ address, getCode: emailCode(address) }))
|
|
284
|
+
await notice('Done. Every other device is signed out of your account and backup.')
|
|
285
|
+
} catch (e) { if (!(e && e.code === 'cancelled')) await notice(messageFor(e)) }
|
|
286
|
+
rerender()
|
|
287
|
+
}
|
|
288
|
+
const nc = document.createElement('button'); nc.className = 'dev-out'; nc.type = 'button'; nc.style.cssText = 'width:100%; padding:10px; margin-top:6px'
|
|
289
|
+
nc.id = 'acctV2NewCodeBtn'; nc.textContent = 'New recovery code'
|
|
290
|
+
nc.onclick = async () => {
|
|
291
|
+
if (!(await confirmSheet({ message: `Make a new recovery code?\n\nYour old code stops working, and every other device is signed out of your account and backup — you will need to reconnect them. One that never reconnects keeps the Spaces already on it. Anything on them that hasn’t been backed up may be lost. We’ll send a code to ${address}.`, confirmLabel: 'Make a new code' }))) return
|
|
292
|
+
try {
|
|
293
|
+
await withSteps(() => a.newRecoveryCode({ address, getCode: emailCode(address), showCode }))
|
|
294
|
+
await notice('Done. Your new recovery code is active, and every other device is signed out.')
|
|
295
|
+
} catch (e) { if (!(e && e.code === 'cancelled')) await notice(messageFor(e)) }
|
|
296
|
+
rerender()
|
|
297
|
+
}
|
|
298
|
+
if (s.setup === 'pending') { // the account exists; its first recovery code did not finish
|
|
299
|
+
d.textContent = 'Your account on the new service is made, but it has no recovery code yet.'
|
|
300
|
+
b.id = 'acctV2FinishSetup'; b.textContent = 'Finish: make my recovery code'
|
|
301
|
+
b.onclick = () => startFresh(a, address, rerender)
|
|
302
|
+
sec.append(t, d, b); box.append(sec); return
|
|
303
|
+
}
|
|
304
|
+
sec.append(t, d, serviceDevicesBlock(a, address, rerender), b, nc)
|
|
305
|
+
const mw = moveWarningBlock(rerender) // § 11.5, 3a: a move of this account's address under way — above everything else
|
|
306
|
+
if (mw) sec.prepend(mw)
|
|
307
|
+
box.append(sec)
|
|
308
|
+
renderAdvanced(sec, a, address, rerender)
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
if (onStagingApp()) d.textContent = 'Staging: start an account on the new service from this device (there’s no old backup service here to move from).'
|
|
312
|
+
// the move is offered for an account on the old service, where the service accepts moves (Release 3; moveShown)
|
|
313
|
+
else if (moveShown(rerender)) sec.append(t, d, b)
|
|
314
|
+
else { d.textContent = onProdPreview() ? 'Preview: start an account on the new service from this device, or restore one.' : 'Start an account on the new service from this device, or restore one.'; sec.append(t, d) }
|
|
315
|
+
if (onStagingApp()) sec.append(t, d)
|
|
316
|
+
const rs = document.createElement('button'); rs.className = 'dev-out'; rs.type = 'button'; rs.id = 'acctV2Restore'; rs.textContent = 'Restore my account from the new service'
|
|
317
|
+
rs.style.cssText = 'width:100%; padding:10px; margin-top:6px'
|
|
318
|
+
rs.onclick = () => restoreHere(a, address, rerender)
|
|
319
|
+
sec.append(rs)
|
|
320
|
+
if (offerFresh()) {
|
|
321
|
+
const f = document.createElement('button'); f.className = 'dev-out'; f.type = 'button'; f.id = 'acctV2Fresh'; f.textContent = 'Start on the new service'
|
|
322
|
+
f.style.cssText = 'width:100%; padding:10px; margin-top:6px'
|
|
323
|
+
f.onclick = () => startFresh(a, address, rerender)
|
|
324
|
+
sec.append(f)
|
|
325
|
+
}
|
|
326
|
+
box.append(sec)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ── THE ACCOUNT'S OTHER DEVICES, AS THE SERVICE KNOWS THEM (the owner, 2026-11-17: "Why don't I see the code wsl device here?")
|
|
330
|
+
// The list above the section is the devices' OWN entries in the account's synced list — a computer paired for Code writes
|
|
331
|
+
// none, so it never showed. These rows are the service's devices that the page did not already draw (dep().drawnSpks(): the
|
|
332
|
+
// regular app's own list; the vault's sheet draws none, so it shows them all), each with its own Sign out: that device
|
|
333
|
+
// only, proved as signing out all of them (an email code). Drawn into a slot once the answer comes; nothing on a failure.
|
|
334
|
+
const DEVICES_FRESH_MS = 30_000
|
|
335
|
+
let _devCache = null // { at, list } — Your devices redraws several times as it opens; one question serves them
|
|
336
|
+
export function forgetServiceDevices() { _devCache = null }
|
|
337
|
+
export const CLOUD_DEVICE_LABEL = 'Cloud device' // the label it is registered under (cloudDeviceSheet.js enrolDevice)
|
|
338
|
+
/** The page drew the cloud device's own row: the service's row for it goes (whichever was drawn first). */
|
|
339
|
+
export function cloudDeviceRowShown (row) { try { row.dataset.cloudDeviceRow = '1'; for (const r of document.querySelectorAll('[data-cloud-device-service]')) r.remove() } catch { /* */ } }
|
|
340
|
+
/** SIGN OUT AT THE SERVICE TOO (the owner, 2026-11-18: "Yes, revoke at the service", sync sweep unclear): the regular app's synced
|
|
341
|
+
* list stamped only the account's index, so a signed-out device kept its account-service sign-in until it next checked in. For an
|
|
342
|
+
* account on the new service, a row that knows the device's key revokes it there as well (the email code, as the service row asks).
|
|
343
|
+
* → true revoked · false not on the service / no key · throws a cancel or the service's refusal. */
|
|
344
|
+
export async function revokeAtService(spk) {
|
|
345
|
+
const a = acctV2(); if (!spk || !(a.enabled() && a.state())) return false
|
|
346
|
+
const address = accountAddress()
|
|
347
|
+
await withSteps(() => a.signOutDevice({ spk, address, getCode: emailCode(address) }))
|
|
348
|
+
forgetServiceDevices()
|
|
349
|
+
return true
|
|
350
|
+
}
|
|
351
|
+
const drawnSpks = () => { try { return new Set((dep().drawnSpks && dep().drawnSpks()) || []) } catch { return new Set() } }
|
|
352
|
+
const dayOf = (sec) => { try { return new Date(sec * 1000).toLocaleDateString(undefined, { day: 'numeric', month: 'short' }) } catch { return '' } }
|
|
353
|
+
export function serviceDevicesBlock(a, address, rerender, { now = Date.now } = {}) {
|
|
354
|
+
const slot = document.createElement('div'); slot.id = 'acctV2Devices'
|
|
355
|
+
const draw = (list) => {
|
|
356
|
+
const drawn = drawnSpks()
|
|
357
|
+
// THE CLOUD DEVICE ONCE (sync sweep 11-18 unclear): its own row ("Cloud device · always on", with its Spaces and a Sign out that
|
|
358
|
+
// forgets the account on it) is drawn by the page when the device serves this account — then the service's row for it goes
|
|
359
|
+
const cloudRowShown = () => { try { return !!document.querySelector('[data-cloud-device-row]') } catch { return false } }
|
|
360
|
+
const rows = (list || []).filter((x) => x && typeof x.spk === 'string' && !drawn.has(x.spk) && !(x.me && drawn.size) && !(x.label === CLOUD_DEVICE_LABEL && cloudRowShown()))
|
|
361
|
+
if (!rows.length) { slot.replaceChildren(); return }
|
|
362
|
+
const h = document.createElement('div'); h.className = 'sheet-s'; h.style.cssText = 'padding:4px 4px 2px; opacity:.75'
|
|
363
|
+
h.textContent = drawn.size ? 'Also signed in to your account' : 'Devices signed in to your account'
|
|
364
|
+
const group = document.createElement('div'); group.className = 'dev-list' // one group of rows (vault-loader.html styles it as a card)
|
|
365
|
+
const out = [h, group]
|
|
366
|
+
for (const x of rows) {
|
|
367
|
+
const row = document.createElement('div'); row.className = 'dev-row'; row.dataset.spk = x.spk; if (x.label === CLOUD_DEVICE_LABEL) row.dataset.cloudDeviceService = '1'
|
|
368
|
+
const meta = document.createElement('div'); meta.className = 'dev-meta'
|
|
369
|
+
const name = document.createElement('div'); name.className = 'dev-name'; name.dir = 'auto'; name.textContent = (x.label || 'Device') + (x.me ? ' · this device' : '')
|
|
370
|
+
const sub = document.createElement('div'); sub.className = 'dev-sub'
|
|
371
|
+
sub.textContent = [x.at ? 'added ' + dayOf(x.at) : '', x.state === 'provisional' ? 'not confirmed yet' : ''].filter(Boolean).join(' · ')
|
|
372
|
+
meta.append(name, sub); row.append(meta)
|
|
373
|
+
if (x.me) { const tg = document.createElement('span'); tg.className = 'dev-this'; tg.textContent = 'You'; row.append(tg) }
|
|
374
|
+
else {
|
|
375
|
+
const b = document.createElement('button'); b.className = 'dev-out'; b.type = 'button'; b.textContent = 'Sign out'
|
|
376
|
+
b.onclick = async () => {
|
|
377
|
+
const what = x.label ? `“${x.label}”` : 'this device'
|
|
378
|
+
if (!(await confirmSheet({ message: `Sign out ${what}?\n\nIt can’t use your account, your backup or your recovery any more, and removes your account from itself the next time it checks in. Your other devices stay signed in. We’ll send a code to ${address}.`, confirmLabel: 'Sign out', destructive: true }))) return
|
|
379
|
+
b.disabled = true
|
|
380
|
+
try {
|
|
381
|
+
await withSteps(() => a.signOutDevice({ spk: x.spk, address, getCode: emailCode(address) }))
|
|
382
|
+
forgetServiceDevices()
|
|
383
|
+
await notice(`Done. ${x.label ? '“' + x.label + '”' : 'That device'} is signed out of your account.`)
|
|
384
|
+
} catch (e) { b.disabled = false; if (!(e && e.code === 'cancelled')) await notice(messageFor(e)) }
|
|
385
|
+
rerender()
|
|
386
|
+
}
|
|
387
|
+
row.append(b)
|
|
388
|
+
}
|
|
389
|
+
group.append(row)
|
|
390
|
+
}
|
|
391
|
+
slot.replaceChildren(...out)
|
|
392
|
+
}
|
|
393
|
+
if (_devCache && now() - _devCache.at < DEVICES_FRESH_MS) draw(_devCache.list)
|
|
394
|
+
else {
|
|
395
|
+
Promise.resolve().then(() => a.devices()).then((list) => {
|
|
396
|
+
if (!Array.isArray(list)) return
|
|
397
|
+
_devCache = { at: now(), list }
|
|
398
|
+
draw(list)
|
|
399
|
+
}).catch(() => { /* offline or refused: the section stays as it was — nothing flashed */ })
|
|
400
|
+
}
|
|
401
|
+
return slot
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// ── § 11.5, 3a: SOMEONE IS MOVING THIS ACCOUNT'S EMAIL ADDRESS (docs/account-recovery-email-move-warning.md; owner, 2026-11-16:
|
|
405
|
+
// "Warning the old account's devices about an email move.") The status check tells an active device; these say it, and
|
|
406
|
+
// offer what the reviewed rule allows: cancel with a code to the address (the mailbox decides), or — once — ask for more
|
|
407
|
+
// time (the move then waits 30 days from its start; a device never cancels it).
|
|
408
|
+
const moveDay = (sec) => new Date(sec * 1000).toLocaleDateString(undefined, { weekday: 'long', day: 'numeric', month: 'long' })
|
|
409
|
+
/** The move under way, if the last status answer named one (acctV2App.knownMove). */
|
|
410
|
+
export const knownEmailMove = () => { try { const a = acctV2(); return a.enabled() && a.state() && a.knownMove ? a.knownMove() : null } catch { return null } }
|
|
411
|
+
/** The warning's one line (the banner, the card, the account section). */
|
|
412
|
+
export function moveWarningText(m = knownEmailMove(), address = accountAddress()) {
|
|
413
|
+
if (!m) return ''
|
|
414
|
+
return `Someone is moving your email address${address ? ' ' + address : ''} to a new account. It moves on ${moveDay(m.ready_at)}. If this wasn’t you, act now.`
|
|
415
|
+
}
|
|
416
|
+
/** The warning, step by step: cancel with a code to the address; if that inbox can't be read, ask for more time (once).
|
|
417
|
+
* → 'cancelled' | 'objected' | null (nothing done) */
|
|
418
|
+
export async function reviewEmailMove(rerender = () => {}) {
|
|
419
|
+
const a = acctV2(), m = knownEmailMove(), address = accountAddress()
|
|
420
|
+
if (!m) return null
|
|
421
|
+
let done = null
|
|
422
|
+
try {
|
|
423
|
+
if (!(await confirmSheet({ message: `${moveWarningText(m, address)}
|
|
424
|
+
|
|
425
|
+
Someone who can read ${address || 'your email'} asked to move it to a NEW, empty account. Your account, its Spaces and its devices are not affected — but after the move, this address no longer signs in to it.${m.objected ? `
|
|
426
|
+
|
|
427
|
+
More time was already asked for: it waits until ${moveDay(m.ready_at)}.` : ''}`, confirmLabel: 'This wasn’t me', cancelLabel: 'Not now', destructive: true }))) return null
|
|
428
|
+
const canRead = await confirmSheet({ message: `Cancel the move with a code we send to ${address || 'your email'}.
|
|
429
|
+
|
|
430
|
+
Only someone who can read that inbox can cancel it — not a device. If someone else got into it, change its password with your email provider first.`, confirmLabel: 'Send me a code', cancelLabel: m.objected ? 'Not now' : 'I can’t read that inbox', destructive: false })
|
|
431
|
+
if (canRead) {
|
|
432
|
+
if (!address) { await notice('This device doesn’t know your account’s email address.'); return null }
|
|
433
|
+
await a.cancelMove({ address, getCode: emailCode(address, 'claim') })
|
|
434
|
+
await notice('Cancelled. Your email address stays with your account.')
|
|
435
|
+
done = 'cancelled'
|
|
436
|
+
} else if (!m.objected) {
|
|
437
|
+
if (!(await confirmSheet({ message: `Ask for more time?
|
|
438
|
+
|
|
439
|
+
The move will wait until ${moveDay(m.ready_at - 7 * 86400 + 30 * 86400)} instead, so you can get your inbox back from your email provider — then cancel the move here. More time can be asked for once; it can’t stop the move.`, confirmLabel: 'Ask for more time', cancelLabel: 'Not now', destructive: false }))) return null
|
|
440
|
+
const r = await a.objectMove()
|
|
441
|
+
await notice(`Done. The move now waits until ${moveDay(r.ready_at)}. Get your inbox back from your email provider, then cancel the move here.`)
|
|
442
|
+
done = 'objected'
|
|
443
|
+
}
|
|
444
|
+
} catch (e) { if (!(e && e.code === 'cancelled')) await notice(messageFor(e)) }
|
|
445
|
+
rerender()
|
|
446
|
+
return done
|
|
447
|
+
}
|
|
448
|
+
/** The warning block at the top of the account section, or null. */
|
|
449
|
+
function moveWarningBlock(rerender) {
|
|
450
|
+
const m = knownEmailMove()
|
|
451
|
+
if (!m) return null
|
|
452
|
+
const box = document.createElement('div')
|
|
453
|
+
box.id = 'acctV2MoveWarning'
|
|
454
|
+
box.style.cssText = 'margin:0 0 10px; padding:12px; border-radius:12px; background:rgba(220,38,38,.10); border:1px solid rgba(220,38,38,.35)'
|
|
455
|
+
const t = document.createElement('div'); t.className = 'sheet-s'; t.style.cssText = 'font-weight:600; padding:0 0 6px'; t.textContent = 'Someone is moving your email address'
|
|
456
|
+
const d = document.createElement('div'); d.className = 'sheet-s'; d.style.cssText = 'line-height:1.4'; d.textContent = moveWarningText(m)
|
|
457
|
+
const b = document.createElement('button'); b.className = 'dev-out'; b.type = 'button'; b.id = 'acctV2MoveReview'; b.textContent = 'Review the move'; b.style.cssText = 'width:100%; padding:10px; margin-top:8px'
|
|
458
|
+
b.onclick = () => reviewEmailMove(rerender)
|
|
459
|
+
box.append(t, d, b)
|
|
460
|
+
return box
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// ── RELEASE 3: MOVE AN ACCOUNT FROM THE OLD SERVICE (protocol § 12.2; owner, 2026-11-15: "Let's just add a button in settings
|
|
464
|
+
// that lets you migrate if you are on the old backup") — the REVIEWED transition, from this device, only when the person taps
|
|
465
|
+
// it: the recovery code (gid: L1), an emailed code to the address the old backup was set up with (L2: email only — the
|
|
466
|
+
// service has no Google path for this ticket), the account key's signature where the old backup has one (L3), and this
|
|
467
|
+
// device's new keys (L4). An old backup without an account key moves as `email_only` (lower trust, stated). Then — never
|
|
468
|
+
// before — the account's OTHER devices are signed out, gracefully (owner: "The migration also logs out all other clients
|
|
469
|
+
// (gracefully)"): each wipes itself at its next sync and its first screen says the account moved (devices.js MOVED_MARK).
|
|
470
|
+
const MOVE_TEXT = 'This account still uses the old backup service. Move it to the new account service: your devices are then checked by the service, and signing out a device takes effect at once. Your Spaces and your recovery code stay the same.'
|
|
471
|
+
const MOVE_MESSAGES = {
|
|
472
|
+
already_migrated: 'This account was already moved to the new account service, from another of your devices. To use this device with it: Settings → Reset this device, then restore your Spaces with your recovery code — or add this device from one that moved (Add a device).',
|
|
473
|
+
no_legacy_gate: 'The new service can’t find this account’s backup on the old service. If you typed your recovery code, check it. Nothing changed.',
|
|
474
|
+
nothing_to_migrate: 'This account’s backup on the old service was deleted, so there’s nothing to move. Nothing changed.',
|
|
475
|
+
feature_unavailable: 'Moving accounts to the new service isn’t open yet. Nothing changed.',
|
|
476
|
+
attempt_ended: 'That took too long, or another move of this account is under way. Nothing changed — try again in a few minutes.',
|
|
477
|
+
no_backup: 'This device has no backup to move. Turn on backup first.',
|
|
478
|
+
}
|
|
479
|
+
const _moveProbe = new Map(), _moveKnown = new Map() // service → its answer (asked once per page; a failed ask is asked again)
|
|
480
|
+
/** Does `svc` accept moves now? An UNSIGNED intent: `501 feature_unavailable` while the service's switch (ACCT_FEATURES
|
|
481
|
+
* `migration`) is off; on, its signature check refuses it (401) before anything is read or written. */
|
|
482
|
+
export function moveOpen(svc, fetchImpl = (...x) => fetch(...x)) {
|
|
483
|
+
if (!svc) return Promise.resolve(false)
|
|
484
|
+
if (_moveKnown.has(svc)) return Promise.resolve(_moveKnown.get(svc))
|
|
485
|
+
if (!_moveProbe.has(svc)) {
|
|
486
|
+
_moveProbe.set(svc, (async () => {
|
|
487
|
+
try {
|
|
488
|
+
const r = await fetchImpl(String(svc).replace(/\/+$/, '') + '/v2/account/legacy/intent', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
|
|
489
|
+
const on = r.status !== 501 && r.status !== 404 && r.status < 500
|
|
490
|
+
_moveKnown.set(svc, on)
|
|
491
|
+
return on
|
|
492
|
+
} catch { return false } finally { _moveProbe.delete(svc) }
|
|
493
|
+
})())
|
|
494
|
+
}
|
|
495
|
+
return _moveProbe.get(svc)
|
|
496
|
+
}
|
|
497
|
+
const moveSvc = () => { try { return (dep().moveService && dep().moveService()) || '' } catch { return '' } }
|
|
498
|
+
const oldAccountHere = () => { try { return dep().oldAccountHere ? !!dep().oldAccountHere() : true } catch { return false } }
|
|
499
|
+
/** Offer the move here? An account on the old service, and its service open to moves — not yet known: ask, then redraw. */
|
|
500
|
+
function moveShown(rerender) {
|
|
501
|
+
if (!oldAccountHere()) return false
|
|
502
|
+
const svc = moveSvc()
|
|
503
|
+
if (!svc) return false
|
|
504
|
+
if (_moveKnown.has(svc)) return _moveKnown.get(svc) === true
|
|
505
|
+
moveOpen(svc).then((on) => { if (on) rerender() }).catch(() => {})
|
|
506
|
+
return false
|
|
507
|
+
}
|
|
508
|
+
/** The section of a device whose account is still on the OLD service (the new service's client is off here): the move only. */
|
|
509
|
+
function renderMoveOnly(box, rerender) {
|
|
510
|
+
if (!moveShown(rerender)) return
|
|
511
|
+
const sec = document.createElement('div')
|
|
512
|
+
sec.id = 'acctV2Section'
|
|
513
|
+
sec.style.cssText = 'margin-top:14px; padding-top:10px; border-top:1px solid rgba(127,127,127,.25)'
|
|
514
|
+
const t = document.createElement('div'); t.className = 'sheet-s'; t.style.cssText = 'padding:4px; font-weight:600'; t.textContent = 'New account service'
|
|
515
|
+
const d = document.createElement('div'); d.className = 'sheet-s'; d.style.cssText = 'padding:4px 4px 8px; opacity:.75'; d.textContent = MOVE_TEXT
|
|
516
|
+
const b = document.createElement('button'); b.className = 'dev-out'; b.type = 'button'; b.style.cssText = 'width:100%; padding:10px'
|
|
517
|
+
b.id = 'acctV2Move'; b.textContent = 'Move to the new account service'
|
|
518
|
+
b.onclick = () => moveAccount(rerender)
|
|
519
|
+
sec.append(t, d, b)
|
|
520
|
+
box.append(sec)
|
|
521
|
+
}
|
|
522
|
+
/** THE MOVE, OFFERED WHEN THE APP OPENS (the owner, 2026-11-18: "Yes" — for the old accounts the silent move cannot take: their old
|
|
523
|
+
* backup has no account key, so the reviewed email path is the only safe one). acctSilentMove.js calls it once the silent move
|
|
524
|
+
* stopped with `email_needed`; "Not now" (or any cancel) waits a week, as the silent stop does. → whether the account moved. */
|
|
525
|
+
export async function offerAutoMove(rerender = () => {}) {
|
|
526
|
+
if (!oldAccountHere()) return false
|
|
527
|
+
return moveAccount(rerender, { auto: true })
|
|
528
|
+
}
|
|
529
|
+
const AUTO_MOVE_TEXT = (address) => `Your account needs a one-time move to Witbitz’s new account service.\n\nWe’ll send a code to ${address} — type it in the next step. Your Spaces and your recovery code stay as they are.\n\nWhen the move is done, your OTHER devices are signed out: each clears itself the next time it’s online and says why. To use one again, restore your Spaces on it with your recovery code, or add it from this device (Add a device).\n\nYou can also do it later: Settings → Back up & recovery.`
|
|
530
|
+
/** The move itself. The device is switched onto the service for it, and back if the account did not move. → whether it moved. */
|
|
531
|
+
async function moveAccount(rerender, { auto = false } = {}) {
|
|
532
|
+
const address = accountAddress()
|
|
533
|
+
if (!address) { if (!auto) await notice('Sign in with your email on this device first.'); return false }
|
|
534
|
+
if (!(await confirmSheet(auto ? { message: AUTO_MOVE_TEXT(address), confirmLabel: 'Move now', cancelLabel: 'Not now', destructive: false } : { message: `Move this account to the new account service?\n\nWe’ll send a code to ${address}. Your Spaces and your recovery code stay as they are.\n\nWhen the move is done, your OTHER devices are signed out: each clears itself the next time it’s online and says why. To use one again, restore your Spaces on it with your recovery code, or add it from this device (Add a device).`, confirmLabel: 'Move', destructive: false }))) return false
|
|
535
|
+
let a = acctV2(), undo = () => {}
|
|
536
|
+
if (!a.enabled()) {
|
|
537
|
+
const svc = moveSvc()
|
|
538
|
+
if (!svc || !dep().switchOn) { await notice(MESSAGES.v2_off); return false }
|
|
539
|
+
undo = dep().switchOn(svc) || (() => {})
|
|
540
|
+
a = acctV2()
|
|
541
|
+
if (!a.enabled()) { undo(); await notice(MESSAGES.v2_off); return false }
|
|
542
|
+
}
|
|
543
|
+
let typedCode = null, r = null
|
|
544
|
+
while (!r) {
|
|
545
|
+
try {
|
|
546
|
+
r = await a.migrate({ address, getCode: emailCode(address), typedCode })
|
|
547
|
+
} catch (e0) {
|
|
548
|
+
let e = e0
|
|
549
|
+
if (e && e.code === 'need_code' && !typedCode) { // this device keeps no copy of the code: the person types it
|
|
550
|
+
typedCode = await askCode({ title: 'Your recovery code', message: MESSAGES.need_code, field: 'recovery' })
|
|
551
|
+
if (typedCode) continue
|
|
552
|
+
e = { code: 'cancelled' }
|
|
553
|
+
}
|
|
554
|
+
if (!a.state()) undo() // not moved: this device is left as it was (the old service, its backup, its devices)
|
|
555
|
+
if (!(e && e.code === 'cancelled')) await notice(MOVE_MESSAGES[e && e.code] || messageFor(e))
|
|
556
|
+
rerender()
|
|
557
|
+
return false
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
// MOVED. Only now are the other devices signed out (a move that failed signed out nobody).
|
|
561
|
+
let others = null
|
|
562
|
+
try { others = dep().afterMove ? await dep().afterMove({ trust: r.legacy_trust }) : null } catch { others = null }
|
|
563
|
+
const emailOnly = r.legacy_trust === 'email_only'
|
|
564
|
+
await notice('Done. This account now uses the new account service, with the same recovery code.'
|
|
565
|
+
+ (emailOnly ? '\n\nIt was moved with your email only (its old backup had no account key), so it stays in a lower-trust state: Advanced Backup isn’t available for it, and the original backup is kept as it was for a year.' : '')
|
|
566
|
+
+ (Array.isArray(others) && !others.length ? '' : '\n\nYour other devices are being signed out: each clears itself the next time it’s online and says why. To use one again, restore your Spaces on it with your recovery code, or add it from this device (Add a device).'))
|
|
567
|
+
rerender()
|
|
568
|
+
return true
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** THE NORMAL "Turn on backup" for a NEW account on the new service (recoverySheet.js turnOnBackup, when the release switch
|
|
572
|
+
* or the owner-only preview says so — acctV2Switch.newAccountService): the address this device signed in with, an email
|
|
573
|
+
* code, then the first recovery code (shown until saved). → { ok } | { ok: false, reason } */
|
|
574
|
+
export async function startNewAccountOnV2(address0) {
|
|
575
|
+
const a = acctV2()
|
|
576
|
+
let address = address0
|
|
577
|
+
if (!address) {
|
|
578
|
+
address = await askCode({ title: 'Your email', message: 'Your account is tied to this email address. We’ll send it a code.', field: 'address' })
|
|
579
|
+
if (!address) return { ok: false, reason: 'cancelled' }
|
|
580
|
+
}
|
|
581
|
+
try {
|
|
582
|
+
await withSteps(() => a.startFresh({ address, getCode: emailCode(address, 'new'), showCode }))
|
|
583
|
+
return { ok: true }
|
|
584
|
+
} catch (e) {
|
|
585
|
+
if (e && e.code === 'cancelled') return { ok: false, reason: 'cancelled' }
|
|
586
|
+
if (e && e.code === 'restore_instead') return { ok: false, reason: 'restore_instead' } // recoverySheet opens Restore
|
|
587
|
+
if (e && e.code === 'move_email') return { ok: false, reason: 'move_email' } // recoverySheet starts the move (acctV2Reset.js)
|
|
588
|
+
return { ok: false, reason: messageFor(e) }
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** § 8.6 Add a device, on the APPROVING device (deviceLinkSheet.js giveTo): the service registers the new device's key —
|
|
593
|
+
* this device + an email code, or + a touch of a security key on an Advanced account. → { ok: true, acct, base, address }
|
|
594
|
+
* | { ok: false, reason } (reason '' = cancelled). Nothing of the account's goes to the new device unless this is ok. */
|
|
595
|
+
export async function approveNewDevice({ newSpk, label }) {
|
|
596
|
+
const a = acctV2()
|
|
597
|
+
const address = accountAddress()
|
|
598
|
+
try {
|
|
599
|
+
const r = await withSteps(() => a.enrolDevice({ newSpk, label, address, getCode: emailCode(address) }), 'Touch one of your security keys to add the device, then enter its PIN when asked.')
|
|
600
|
+
return { ok: true, ...r }
|
|
601
|
+
} catch (e) {
|
|
602
|
+
if (e && e.code === 'cancelled') return { ok: false, reason: '' }
|
|
603
|
+
if (e && e.code === 'key_registered') return { ok: false, reason: MESSAGES.enrol_key_registered }
|
|
604
|
+
return { ok: false, reason: messageFor(e) }
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** § 8.6 on the NEW device: the approving device registered it and sent { acct, base, address } with the account's keys.
|
|
609
|
+
* This device is switched on for that service (only the service this app may use — acctV2Switch.baseOf) and reads the
|
|
610
|
+
* backup through it with its own key. → { ok: true, rooms } | { ok: false, reason }; nothing kept on failure. */
|
|
611
|
+
export async function adoptLinkedV2({ v2, master, code }) {
|
|
612
|
+
const base = baseOf(v2 && v2.base, location.hostname)
|
|
613
|
+
if (!base || !v2.acct) return { ok: false, reason: 'This device can’t use the new account service. Use Restore your Spaces with your recovery code instead.' }
|
|
614
|
+
let prev = null
|
|
615
|
+
try { prev = localStorage.getItem(BASE_KEY) } catch { /* */ }
|
|
616
|
+
try { localStorage.setItem(BASE_KEY, base) } catch { return { ok: false, reason: MESSAGES.v2_off } }
|
|
617
|
+
try {
|
|
618
|
+
const r = await acctV2().adoptLinked({ acct: v2.acct, address: v2.address || '', master, code })
|
|
619
|
+
return { ok: true, rooms: r.rooms }
|
|
620
|
+
} catch (e) {
|
|
621
|
+
try { if (prev == null) localStorage.removeItem(BASE_KEY); else localStorage.setItem(BASE_KEY, prev) } catch { /* */ }
|
|
622
|
+
return { ok: false, reason: messageFor(e) }
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Release checklist 1.11 — the "Delete my account" step for an account on the new service (accountEraseUi.js deleteBackup):
|
|
627
|
+
* an email code, then the service signs out every device, frees the address and deletes the backup. → { ok, reason? } —
|
|
628
|
+
* the shape of the old service's backup step, so the erase goes on only when this worked. */
|
|
629
|
+
export async function eraseV2Account() {
|
|
630
|
+
const a = acctV2()
|
|
631
|
+
let address = accountAddress()
|
|
632
|
+
if (!address) {
|
|
633
|
+
address = await askCode({ title: 'Your email', message: 'The email address of this account. We’ll send it a code to confirm the deletion.', field: 'address' })
|
|
634
|
+
if (!address) return { ok: false, reason: 'cancelled' }
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
await withSteps(() => a.eraseAccount({ address, getCode: emailCode(address) }))
|
|
638
|
+
return { ok: true }
|
|
639
|
+
} catch (e) {
|
|
640
|
+
if (e && e.code === 'cancelled') return { ok: false, reason: 'cancelled' }
|
|
641
|
+
return { ok: false, reason: messageFor(e) }
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** SHOW THE RECOVERY CODE ON AN ACCOUNT ON THE NEW SERVICE (the owner, 2026-11-22: it showed with no check): the email check —
|
|
646
|
+
* Google or the emailed code — when no passkey on this device answered. → true when proved; false on a cancel or a failure. */
|
|
647
|
+
export async function proveEmailToShowCode() {
|
|
648
|
+
const a = acctV2()
|
|
649
|
+
const address = accountAddress()
|
|
650
|
+
if (!a.enabled() || !a.state() || !address) return false
|
|
651
|
+
try { await withSteps(() => a.proveEmail({ address, getCode: emailCode(address) })); return true }
|
|
652
|
+
catch (e) { if (!(e && e.code === 'cancelled')) await notice(messageFor(e)); return false }
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** Bring an account on the new service to this device: its email, its recovery code, an email code, and a key if Advanced. */
|
|
656
|
+
async function restoreHere(a, address0, rerender) {
|
|
657
|
+
let address = address0
|
|
658
|
+
if (!address) {
|
|
659
|
+
address = await askCode({ title: 'Your email', message: 'The email address of the account you’re restoring. Next, you confirm it’s you with Google or a code by email.', field: 'address' })
|
|
660
|
+
if (!address) return
|
|
661
|
+
}
|
|
662
|
+
const code = await askCode({ title: 'Your recovery code', message: `The recovery code of the account for ${address}.`, field: 'recovery' })
|
|
663
|
+
if (!code) return
|
|
664
|
+
try {
|
|
665
|
+
const r = await withSteps(() => a.restoreHere({ address, getCode: emailCode(address), typedCode: code }))
|
|
666
|
+
await notice(`Done. Your account is on this device${r.rooms ? ` (${r.rooms} Space${r.rooms === 1 ? '' : 's'})` : ''}.`)
|
|
667
|
+
// finish like every other restore (recoverySheet.js finishRestore, which listens): the account's index and the private
|
|
668
|
+
// lanes registry are read before the list is drawn — without it each private lane showed as a Space of its own (the
|
|
669
|
+
// owner's iPhone, 2026-11-15). An event, not an import: this card also runs where the recovery sheet does not.
|
|
670
|
+
dispatchEvent(new CustomEvent('acctv2:restored', { detail: { rooms: r.rooms || 0 } }))
|
|
671
|
+
} catch (e) { if (!(e && e.code === 'cancelled')) await notice(messageFor(e)) }
|
|
672
|
+
rerender()
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** Start an account on the new service from this device: confirm the address, get the first recovery code. */
|
|
676
|
+
async function startFresh(a, address0, rerender) {
|
|
677
|
+
let address = address0
|
|
678
|
+
if (!address) {
|
|
679
|
+
address = await askCode({ title: 'Your email', message: 'Your account on the new service is tied to this email address. We’ll send it a code.', field: 'address' })
|
|
680
|
+
if (!address) return
|
|
681
|
+
}
|
|
682
|
+
if (!(await confirmSheet({ message: `Start an account on the new service from this device?\n\nWe’ll send a code to ${address}, then show you a new recovery code to save. This device’s current backup and recovery code are replaced by the new ones.`, confirmLabel: 'Start', destructive: false }))) return
|
|
683
|
+
try {
|
|
684
|
+
await a.startFresh({ address, getCode: emailCode(address, 'new'), showCode })
|
|
685
|
+
await notice('Done. This device has an account on the new account service, with your new recovery code.')
|
|
686
|
+
} catch (e) {
|
|
687
|
+
if (e && e.code === 'restore_instead') return restoreHere(a, address, rerender) // the email already has an account: restore it
|
|
688
|
+
if (!(e && e.code === 'cancelled')) await notice(messageFor(e))
|
|
689
|
+
}
|
|
690
|
+
rerender()
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// ── Advanced Backup (docs/account-recovery-design.md § 6; protocol § 10): security keys ──
|
|
694
|
+
|
|
695
|
+
/** Known key models by their model id (AAGUID); every accepted key is a YubiKey (the service pins Yubico's certificates). */
|
|
696
|
+
const MODELS = { 'f4ce5fc057d346f5a736efb7d5bc63b5': 'YubiKey 5 series with NFC' }
|
|
697
|
+
const modelOf = (aaguid) => MODELS[String(aaguid || '').replace(/-/g, '')] || 'YubiKey'
|
|
698
|
+
|
|
699
|
+
/** The card before each security-key prompt: what to touch, and a button whose tap opens the browser's prompt (Safari opens
|
|
700
|
+
* one only in answer to a tap). Hidden until a prompt is due. */
|
|
701
|
+
function stepCard() {
|
|
702
|
+
const shade = document.createElement('div')
|
|
703
|
+
shade.id = 'acctV2KeyStep'
|
|
704
|
+
shade.style.cssText = 'position:fixed; inset:0; z-index:2147482000; background:rgba(0,0,0,.45); display:none; align-items:center; justify-content:center; padding:16px'
|
|
705
|
+
shade.className = 'kbfit' // with the keys up it fits the visible area (space.html), its field above them
|
|
706
|
+
const card = document.createElement('div')
|
|
707
|
+
card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true')
|
|
708
|
+
card.style.cssText = 'background:var(--bg, #fff); color:var(--fg, #111); border-radius:14px; padding:18px; max-width:360px; width:100%; box-shadow:0 10px 40px rgba(0,0,0,.3)'
|
|
709
|
+
const h = document.createElement('div'); h.textContent = 'Security key'; h.style.cssText = 'font-weight:600; font-size:17px; margin-bottom:6px'
|
|
710
|
+
const p = document.createElement('div'); p.id = 'acctV2KeyStepText'; p.style.cssText = 'font-size:14px; opacity:.85; line-height:1.4'
|
|
711
|
+
const row = document.createElement('div'); row.style.cssText = 'display:flex; gap:8px; margin-top:14px'
|
|
712
|
+
const cancel = document.createElement('button'); cancel.type = 'button'; cancel.textContent = 'Cancel'
|
|
713
|
+
const go = document.createElement('button'); go.type = 'button'; go.id = 'acctV2KeyGo'; go.textContent = 'Use security key'
|
|
714
|
+
for (const b of [cancel, go]) b.style.cssText = 'flex:1; padding:11px; border-radius:10px; border:0; font-size:15px; cursor:pointer'
|
|
715
|
+
go.style.background = 'var(--accent, #1f5fd6)'; go.style.color = '#fff'
|
|
716
|
+
row.append(cancel, go); card.append(h, p, row); shade.append(card); document.body.append(shade)
|
|
717
|
+
return {
|
|
718
|
+
/** Show `text`; on the tap, run `call()` inside it and settle with its result. */
|
|
719
|
+
ask: (text, call) => new Promise((resolve, reject) => {
|
|
720
|
+
p.textContent = text
|
|
721
|
+
shade.style.display = 'flex'
|
|
722
|
+
go.onclick = () => { shade.style.display = 'none'; let pr; try { pr = call() } catch (e) { reject(e); return } Promise.resolve(pr).then(resolve, reject) }
|
|
723
|
+
cancel.onclick = () => { shade.style.display = 'none'; reject(Object.assign(new Error('cancelled'), { code: 'cancelled' })) }
|
|
724
|
+
}),
|
|
725
|
+
close: () => shade.remove(),
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const STEP_TEXT = ({ step, index, of }) => step === 'register'
|
|
729
|
+
? (of > 1 ? `Security key ${index + 1} of ${of}: insert or tap it, then enter its PIN when asked.` : 'Insert or tap your new security key, then enter its PIN when asked.')
|
|
730
|
+
: step === 'confirm'
|
|
731
|
+
? (of > 1 ? `Now confirm security key ${index + 1} of ${of}: touch it once more.` : 'Now confirm the new key: touch it once more.')
|
|
732
|
+
: 'Last step: touch one of your existing security keys.'
|
|
733
|
+
|
|
734
|
+
/** Run a flow with the key card: before each prompt it says which key to touch (the flow's latest step, else `fallback`). */
|
|
735
|
+
export async function withSteps(run, fallback = 'Insert or tap one of your security keys, then enter its PIN when asked.') {
|
|
736
|
+
const card = stepCard()
|
|
737
|
+
let text = null
|
|
738
|
+
onKeyPrompt((kind, call) => card.ask(text || fallback, call))
|
|
739
|
+
try { return await run((s) => { text = STEP_TEXT(s) }) } finally { onKeyPrompt(null); card.close() }
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export function renderAdvanced(sec, a, address, rerender, { confirm = confirmSheet, notify = notice, getCode = emailCode(address) } = {}) {
|
|
743
|
+
const box = document.createElement('div')
|
|
744
|
+
box.id = 'acctV2Advanced'
|
|
745
|
+
box.style.cssText = 'margin-top:12px'
|
|
746
|
+
const t = document.createElement('div'); t.className = 'sheet-s'; t.style.cssText = 'padding:4px; font-weight:600'; t.textContent = 'Advanced Backup'
|
|
747
|
+
const d = document.createElement('div'); d.className = 'sheet-s'; d.style.cssText = 'padding:4px 4px 8px; opacity:.75'; d.textContent = 'Checking…'
|
|
748
|
+
box.append(t, d)
|
|
749
|
+
sec.append(box)
|
|
750
|
+
const btn = (id, text) => { const x = document.createElement('button'); x.className = 'dev-out'; x.type = 'button'; x.id = id; x.textContent = text; x.style.cssText = 'width:100%; padding:10px; margin-top:6px'; box.append(x); return x }
|
|
751
|
+
const run = async (fn, done) => {
|
|
752
|
+
try { await fn(); await notify(done) } catch (e) { if (!(e && e.code === 'cancelled')) await notify(messageFor(e)) }
|
|
753
|
+
rerender()
|
|
754
|
+
}
|
|
755
|
+
a.security().then((st) => {
|
|
756
|
+
if (st.mode !== 'advanced') {
|
|
757
|
+
if (!st.advanced_available) { d.textContent = 'Not available for this account yet.'; return }
|
|
758
|
+
d.textContent = 'Restoring your backup also needs one of your security keys (YubiKeys). Someone with your recovery code and your email still can’t restore it without a key.'
|
|
759
|
+
btn('acctV2AdvOn', 'Turn on Advanced Backup').onclick = async () => {
|
|
760
|
+
if (!(await confirm({ message: `Turn on Advanced Backup?\n\nYou’ll register your security keys now — have them ready, with their PINs. Either key works alone.\n\nIf you lose every key AND every device, nobody can restore your backup — not even Spaces support.\n\nWe’ll send a code to ${address}.`, confirmLabel: 'Continue', destructive: false }))) return
|
|
761
|
+
run(() => withSteps((onStep) => a.turnOnAdvanced({ address, getCode, onStep })), 'Advanced Backup is on. Restoring now needs one of your security keys.')
|
|
762
|
+
}
|
|
763
|
+
return
|
|
764
|
+
}
|
|
765
|
+
d.textContent = st.keys.length === 1 ? 'On, with 1 security key.' : `On, with ${st.keys.length} security keys. Any one of them works.`
|
|
766
|
+
for (const k of st.keys) {
|
|
767
|
+
const row = document.createElement('div')
|
|
768
|
+
row.className = 'acctV2Key'
|
|
769
|
+
row.style.cssText = 'display:flex; align-items:center; gap:8px; padding:6px 4px'
|
|
770
|
+
const name = document.createElement('div'); name.style.cssText = 'flex:1; font-size:14px'
|
|
771
|
+
const when = k.activated_at ? new Date(k.activated_at * 1000).toLocaleDateString() : ''
|
|
772
|
+
name.textContent = modelOf(k.aaguid) + (when ? ' · added ' + when : '')
|
|
773
|
+
row.append(name)
|
|
774
|
+
if (st.keys.length > 1) {
|
|
775
|
+
const rm = document.createElement('button'); rm.type = 'button'; rm.className = 'dev-out acctV2KeyRemove'; rm.textContent = 'Remove'; rm.style.cssText = 'padding:6px 10px'
|
|
776
|
+
rm.onclick = async () => {
|
|
777
|
+
if (!(await confirm({ message: `Remove this security key?\n\nYou’ll confirm with one of your OTHER keys. We’ll send a code to ${address}.`, confirmLabel: 'Remove' }))) return
|
|
778
|
+
run(() => withSteps(() => a.removeKey({ address, getCode, credId: k.credId }), 'When asked, touch one of your OTHER security keys — not the one you’re removing.'), 'The key is removed.')
|
|
779
|
+
}
|
|
780
|
+
row.append(rm)
|
|
781
|
+
}
|
|
782
|
+
box.append(row)
|
|
783
|
+
}
|
|
784
|
+
btn('acctV2AddKey', 'Add a security key').onclick = async () => {
|
|
785
|
+
if (!(await confirm({ message: `Add a security key?\n\nHave the new key AND one of your current keys ready. We’ll send a code to ${address}.`, confirmLabel: 'Continue', destructive: false }))) return
|
|
786
|
+
run(() => withSteps((onStep) => a.addKey({ address, getCode, onStep })), 'The new key is added.')
|
|
787
|
+
}
|
|
788
|
+
btn('acctV2AdvOff', 'Turn off Advanced Backup').onclick = async () => {
|
|
789
|
+
if (!(await confirm({ message: `Turn off Advanced Backup?\n\nRestoring will need only your recovery code and your email again, and your security keys are removed. We’ll send a code to ${address} and ask for one of your keys.`, confirmLabel: 'Turn off' }))) return
|
|
790
|
+
run(() => withSteps(() => a.turnOffAdvanced({ address, getCode })), 'Advanced Backup is off.')
|
|
791
|
+
}
|
|
792
|
+
}).catch((e) => { d.textContent = 'Couldn’t check right now.'; void e })
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/** The app's first-run "Restore my Spaces" with a recovery code (recoverySheet.js doRestore), where the new service is on:
|
|
796
|
+
* try it first. → null = not here (switched off, already an account, or the service does not know this code — today's
|
|
797
|
+
* restore goes on), { done, rooms, address } = restored, { message } = stop and show it. */
|
|
798
|
+
export async function restoreFromCode(code, { service = null, signIn = null } = {}) {
|
|
799
|
+
let a = acctV2()
|
|
800
|
+
if (a.enabled() && a.state()) return null // this device already has an account on the new service
|
|
801
|
+
// A DEVICE NOT YET ON THE NEW SERVICE (a new phone, a fresh browser): once new accounts start there (the release switch,
|
|
802
|
+
// acctV2Switch.newAccountService — the same rule, so every account it makes can be restored), the normal Restore asks it
|
|
803
|
+
// too, switching this device on for the try and back if the code is not an account there. Without this, an account made
|
|
804
|
+
// there could not be restored anywhere but a device already switched on (found 2026-11-15, before the switch).
|
|
805
|
+
let undo = null
|
|
806
|
+
if (!a.enabled()) {
|
|
807
|
+
let prev = null
|
|
808
|
+
try { prev = localStorage.getItem(BASE_KEY) } catch { /* */ }
|
|
809
|
+
const svc = service || newAccountService({ host: location.hostname, stored: prev })
|
|
810
|
+
if (!svc) return null
|
|
811
|
+
try { localStorage.setItem(BASE_KEY, svc) } catch { return null }
|
|
812
|
+
undo = () => { try { if (prev == null) localStorage.removeItem(BASE_KEY); else localStorage.setItem(BASE_KEY, prev) } catch { /* */ } }
|
|
813
|
+
a = acctV2()
|
|
814
|
+
if (!a.enabled()) { undo(); return null }
|
|
815
|
+
}
|
|
816
|
+
// the email is asked only once the service has shown the code IS an account there (acctV2Client.restore): an old
|
|
817
|
+
// account's restore falls through below without an email prompt or a code sent
|
|
818
|
+
let address = accountAddress(), found = false, picked = null, signedIn = null
|
|
819
|
+
// ONE CARD, GOOGLE OR THE EMAIL (the owner, 2026-11-22: "We should see the Google login and email code in the same page. No
|
|
820
|
+
// previous page that you enter the email"): with no address known, the card offers Continue with Google (the address is then
|
|
821
|
+
// the Google account's) beside the email field (a code is mailed to it); the choice is kept and `choose` answers it.
|
|
822
|
+
const askAddress = async ({ action } = {}) => {
|
|
823
|
+
found = true // the service knows this code
|
|
824
|
+
// ONE SIGN-IN (the owner, 2026-11-23: "we do the login twice"): where the app hands its own sign-in (`signIn`), the proof IS the
|
|
825
|
+
// app's sign-in card — Google or the app's emailed code — bound to this challenge; the device stays signed in after the restore
|
|
826
|
+
if (signIn && action) {
|
|
827
|
+
signedIn = await signIn({ challenge: action })
|
|
828
|
+
if (!signedIn) throw Object.assign(new Error('cancelled'), { code: 'cancelled' })
|
|
829
|
+
picked = { signIn: { idToken: signedIn.idToken, spk: signedIn.spk, sig: signedIn.sig } }; address = signedIn.email
|
|
830
|
+
return address
|
|
831
|
+
}
|
|
832
|
+
if (!address) {
|
|
833
|
+
const got = await askCode({ title: 'Confirm it’s you', message: 'Continue with the Google account of your Spaces account, or enter its email address for a 6-digit code.', field: 'address', google: action ? { action } : null })
|
|
834
|
+
if (got && typeof got === 'object' && got.google) { picked = { google: got.google }; address = googleEmailOf(got.google) }
|
|
835
|
+
else if (got) { picked = action ? { email: true } : null; address = got }
|
|
836
|
+
}
|
|
837
|
+
if (!address) throw Object.assign(new Error('cancelled'), { code: 'cancelled' })
|
|
838
|
+
return address
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
// GOOGLE OR THE CODE, ASKED FIRST HERE TOO (the owner, 2026-11-21, the iPhone app's restore: "it sends the code automatically
|
|
842
|
+
// and only then I get the Google sign option"): this wrapper (the address is known only once the service knows the code) had no
|
|
843
|
+
// `choose`, so acctV2Client mailed the code at once. The address is set by askAddress before the client asks the choice.
|
|
844
|
+
const getCode = Object.assign((ctx) => emailCode(address)(ctx), { choose: (o) => (picked ? Promise.resolve(picked) : chooseProof({ address, ...o })) })
|
|
845
|
+
const r = await withSteps(() => a.restoreHere({ address: askAddress, getCode, typedCode: code }))
|
|
846
|
+
return { done: true, rooms: r.rooms, address, ...(signedIn ? { signedIn: true } : {}) }
|
|
847
|
+
} catch (e) {
|
|
848
|
+
if (undo) undo()
|
|
849
|
+
if (signedIn && signedIn.undo) { try { signedIn.undo() } catch { /* */ } } // the restore did not happen: neither does its sign-in
|
|
850
|
+
if (e && e.code === 'no_account') return null
|
|
851
|
+
if (e && e.code === 'cancelled') return { message: '' }
|
|
852
|
+
// the service could not be reached (or failed) before it said whether the code is an account there: today's restore
|
|
853
|
+
// goes on — an old account is never stopped by the new service being down
|
|
854
|
+
if (!found && !(e && e.status && e.status < 500)) return null
|
|
855
|
+
return { message: messageFor(e) }
|
|
856
|
+
}
|
|
857
|
+
}
|