@oxy.so/core 1.13.0 → 1.18.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 (117) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/crypto/identityLink.js +18 -0
  3. package/dist/cjs/i18n/locales/ar-SA.json +105 -85
  4. package/dist/cjs/i18n/locales/ca-ES.json +107 -87
  5. package/dist/cjs/i18n/locales/de-DE.json +105 -85
  6. package/dist/cjs/i18n/locales/en-US.json +105 -164
  7. package/dist/cjs/i18n/locales/es-ES.json +104 -163
  8. package/dist/cjs/i18n/locales/fr-FR.json +105 -85
  9. package/dist/cjs/i18n/locales/it-IT.json +105 -85
  10. package/dist/cjs/i18n/locales/ja-JP.json +105 -85
  11. package/dist/cjs/i18n/locales/ko-KR.json +105 -85
  12. package/dist/cjs/i18n/locales/locales/ar-SA.json +105 -85
  13. package/dist/cjs/i18n/locales/locales/ca-ES.json +107 -87
  14. package/dist/cjs/i18n/locales/locales/de-DE.json +105 -85
  15. package/dist/cjs/i18n/locales/locales/en-US.json +105 -164
  16. package/dist/cjs/i18n/locales/locales/es-ES.json +104 -163
  17. package/dist/cjs/i18n/locales/locales/fr-FR.json +105 -85
  18. package/dist/cjs/i18n/locales/locales/it-IT.json +105 -85
  19. package/dist/cjs/i18n/locales/locales/ja-JP.json +105 -85
  20. package/dist/cjs/i18n/locales/locales/ko-KR.json +105 -85
  21. package/dist/cjs/i18n/locales/locales/pt-PT.json +105 -85
  22. package/dist/cjs/i18n/locales/locales/zh-CN.json +106 -86
  23. package/dist/cjs/i18n/locales/pt-PT.json +105 -85
  24. package/dist/cjs/i18n/locales/zh-CN.json +106 -86
  25. package/dist/cjs/index.js +10 -43
  26. package/dist/cjs/mixins/OxyServices.auth.js +54 -16
  27. package/dist/cjs/mixins/OxyServices.identity.js +128 -8
  28. package/dist/cjs/mixins/OxyServices.user.js +42 -7
  29. package/dist/cjs/server/securityHeaders.js +19 -1
  30. package/dist/cjs/session/accountDialogController.js +37 -142
  31. package/dist/cjs/utils/authWebUrl.js +6 -6
  32. package/dist/cjs/utils/oauthPkce.js +5 -1
  33. package/dist/esm/.tsbuildinfo +1 -1
  34. package/dist/esm/crypto/identityLink.js +15 -0
  35. package/dist/esm/i18n/locales/ar-SA.json +105 -85
  36. package/dist/esm/i18n/locales/ca-ES.json +107 -87
  37. package/dist/esm/i18n/locales/de-DE.json +105 -85
  38. package/dist/esm/i18n/locales/en-US.json +105 -164
  39. package/dist/esm/i18n/locales/es-ES.json +104 -163
  40. package/dist/esm/i18n/locales/fr-FR.json +105 -85
  41. package/dist/esm/i18n/locales/it-IT.json +105 -85
  42. package/dist/esm/i18n/locales/ja-JP.json +105 -85
  43. package/dist/esm/i18n/locales/ko-KR.json +105 -85
  44. package/dist/esm/i18n/locales/locales/ar-SA.json +105 -85
  45. package/dist/esm/i18n/locales/locales/ca-ES.json +107 -87
  46. package/dist/esm/i18n/locales/locales/de-DE.json +105 -85
  47. package/dist/esm/i18n/locales/locales/en-US.json +105 -164
  48. package/dist/esm/i18n/locales/locales/es-ES.json +104 -163
  49. package/dist/esm/i18n/locales/locales/fr-FR.json +105 -85
  50. package/dist/esm/i18n/locales/locales/it-IT.json +105 -85
  51. package/dist/esm/i18n/locales/locales/ja-JP.json +105 -85
  52. package/dist/esm/i18n/locales/locales/ko-KR.json +105 -85
  53. package/dist/esm/i18n/locales/locales/pt-PT.json +105 -85
  54. package/dist/esm/i18n/locales/locales/zh-CN.json +106 -86
  55. package/dist/esm/i18n/locales/pt-PT.json +105 -85
  56. package/dist/esm/i18n/locales/zh-CN.json +106 -86
  57. package/dist/esm/index.js +5 -5
  58. package/dist/esm/mixins/OxyServices.auth.js +55 -17
  59. package/dist/esm/mixins/OxyServices.identity.js +128 -8
  60. package/dist/esm/mixins/OxyServices.user.js +42 -7
  61. package/dist/esm/server/securityHeaders.js +19 -1
  62. package/dist/esm/session/accountDialogController.js +37 -142
  63. package/dist/esm/utils/authWebUrl.js +5 -5
  64. package/dist/esm/utils/oauthPkce.js +5 -1
  65. package/dist/types/.tsbuildinfo +1 -1
  66. package/dist/types/crypto/identityLink.d.ts +8 -0
  67. package/dist/types/index.d.ts +5 -8
  68. package/dist/types/mixins/OxyServices.auth.d.ts +35 -25
  69. package/dist/types/mixins/OxyServices.identity.d.ts +34 -34
  70. package/dist/types/mixins/OxyServices.user.d.ts +29 -6
  71. package/dist/types/models/interfaces.d.ts +46 -13
  72. package/dist/types/server/securityHeaders.d.ts +9 -12
  73. package/dist/types/session/accountDialogController.d.ts +29 -98
  74. package/dist/types/utils/authWebUrl.d.ts +5 -5
  75. package/dist/types/utils/oauthPkce.d.ts +10 -0
  76. package/package.json +3 -3
  77. package/src/crypto/__tests__/identityLink.test.ts +18 -0
  78. package/src/crypto/__tests__/identityProof.test.ts +6 -6
  79. package/src/crypto/identityLink.ts +18 -0
  80. package/src/i18n/locales/ar-SA.json +105 -85
  81. package/src/i18n/locales/ca-ES.json +107 -87
  82. package/src/i18n/locales/de-DE.json +105 -85
  83. package/src/i18n/locales/en-US.json +105 -164
  84. package/src/i18n/locales/es-ES.json +104 -163
  85. package/src/i18n/locales/fr-FR.json +105 -85
  86. package/src/i18n/locales/it-IT.json +105 -85
  87. package/src/i18n/locales/ja-JP.json +105 -85
  88. package/src/i18n/locales/ko-KR.json +105 -85
  89. package/src/i18n/locales/pt-PT.json +105 -85
  90. package/src/i18n/locales/zh-CN.json +106 -86
  91. package/src/index.ts +8 -51
  92. package/src/mixins/OxyServices.auth.ts +72 -24
  93. package/src/mixins/OxyServices.identity.ts +126 -8
  94. package/src/mixins/OxyServices.user.ts +51 -10
  95. package/src/mixins/__tests__/identityLink.test.ts +89 -0
  96. package/src/mixins/__tests__/notifications.read.test.ts +82 -0
  97. package/src/mixins/__tests__/preSessionSkipAuth.test.ts +1 -1
  98. package/src/mixins/__tests__/webauthnAuth.test.ts +75 -1
  99. package/src/models/interfaces.ts +46 -12
  100. package/src/server/__tests__/securityHeaders.test.ts +17 -0
  101. package/src/server/securityHeaders.ts +29 -1
  102. package/src/session/__tests__/accountDialogController.test.ts +42 -184
  103. package/src/session/accountDialogController.ts +50 -185
  104. package/src/utils/__tests__/oauthPkce.test.ts +7 -0
  105. package/src/utils/authWebUrl.ts +5 -5
  106. package/src/utils/oauthPkce.ts +16 -1
  107. package/dist/cjs/crypto/identityMove.js +0 -142
  108. package/dist/cjs/crypto/webIdentityCarrier.js +0 -325
  109. package/dist/esm/crypto/identityMove.js +0 -128
  110. package/dist/esm/crypto/webIdentityCarrier.js +0 -303
  111. package/dist/types/crypto/identityMove.d.ts +0 -75
  112. package/dist/types/crypto/webIdentityCarrier.d.ts +0 -150
  113. package/src/crypto/__tests__/identityMove.test.ts +0 -146
  114. package/src/crypto/__tests__/webIdentityCarrier.test.ts +0 -169
  115. package/src/crypto/__tests__/webIdentityRecoveryMaterial.test.ts +0 -117
  116. package/src/crypto/identityMove.ts +0 -167
  117. package/src/crypto/webIdentityCarrier.ts +0 -394
@@ -1,53 +1,48 @@
1
1
  {
2
2
  "signin": {
3
3
  "title": "登录",
4
- "subtitle": "登录以继续",
5
- "addAccountTitle": "添加另一个账户",
4
+ "subtitle": "使用你的 Oxy 账号",
5
+ "addAccountTitle": "添加其他账号",
6
6
  "addAccountSubtitle": "使用另一个账户登录",
7
7
  "username": {
8
8
  "label": "用户名",
9
- "placeholder": "输入您的用户名",
10
- "helper": "3-30个字符,仅字母和数字",
11
- "required": "请输入您的用户名。",
12
- "minLength": "用户名必须至少包含3个字符。"
13
- },
14
- "password": {
15
- "label": "密码",
16
- "placeholder": "输入您的密码",
17
- "required": "请输入您的密码。",
18
- "hint": "输入您的密码以登录"
9
+ "placeholder": "yourname",
10
+ "required": "请输入您的用户名。"
19
11
  },
20
12
  "actions": {
21
13
  "continue": "继续",
22
- "back": "返回",
23
- "signIn": "登录",
24
- "verify": "验证",
25
- "openAccountSwitcher": "切换到另一个账户",
26
- "openAccountSwitcherSubtitle": "{{count}}个其他账户可用",
27
- "openAccountSwitcherSubtitle_singular": "1个其他账户可用",
28
- "openAccountSwitcherSubtitle_zero": "查看您保存的账户",
29
- "manageAccounts": "管理保存的账户",
30
- "manageAccountsSubtitle": "查看会话、删除或登出",
31
- "loadingOtherAccounts": "加载其他账户中…",
32
- "switchAccountFailed": "无法切换账户。请重试。"
14
+ "back": "返回"
33
15
  },
34
- "forgotPrompt": "忘记密码?",
35
- "security": {
36
- "dataSecure": "您的数据已加密且安全"
37
- },
38
- "currentlySignedInAs": "当前登录为",
39
- "alreadySignedInWith": "已登录",
40
- "alreadySignedIn": "已登录",
41
- "alreadySignedInMessage": "此账户已登录。继续使用此账户?",
42
- "continueWithAccount": "继续",
43
- "currentAccount": "当前",
44
- "or": "或",
45
- "viewAllAccounts": "查看更多{{count}}个",
46
16
  "createAccountLink": "初次使用 Oxy?创建账户",
47
17
  "status": {
48
- "accountSwitched": "正在使用{{name}}",
49
18
  "signingIn": "正在登录…"
50
- }
19
+ },
20
+ "subtitleToApp": "以继续前往 {{app}}",
21
+ "orContinueWith": "或使用以下方式继续",
22
+ "qr": {
23
+ "caption": "使用 Commons 扫码登录",
24
+ "renew": "显示新的二维码"
25
+ },
26
+ "methods": {
27
+ "passkey": "使用通行密钥登录"
28
+ },
29
+ "errors": {
30
+ "rateLimited": "尝试次数过多。请在 {{seconds}} 秒后重试。",
31
+ "passkeyCancelled": "通行密钥提示已关闭。准备好后请重试。",
32
+ "passkeyFailed": "无法完成通行密钥验证。请重试。"
33
+ },
34
+ "chooser": {
35
+ "subtitleToApp": "以继续前往 {{app}}"
36
+ },
37
+ "terms": {
38
+ "before": "继续即表示你同意我们的",
39
+ "termsLink": "服务条款",
40
+ "and": "和",
41
+ "privacyLink": "隐私政策"
42
+ },
43
+ "noAccount": "还没有账号?",
44
+ "createAccount": "创建账号",
45
+ "recoverLink": "丢失了通行密钥?恢复你的账号"
51
46
  },
52
47
  "signup": {
53
48
  "title": "创建您的账户",
@@ -55,56 +50,28 @@
55
50
  "createInCommons": "在 Commons 中创建您的身份",
56
51
  "createAccount": "创建账户",
57
52
  "backToSignInLink": "已有账户?登录",
58
- "welcome": {
59
- "title": "欢迎使用Oxy!",
60
- "subtitle": "只需几步即可创建您的账户",
61
- "haveAccount": "已有账户?",
62
- "signInCta": "登录"
63
- },
64
- "identity": {
65
- "title": "您是谁?",
66
- "subtitle": "选择您的用户名并输入您的电子邮件"
67
- },
53
+ "webSubtitle": "无需密码:你的设备会创建一个通行密钥,丢失时可通过恢复邮箱重新进入。",
68
54
  "username": {
69
- "helper": "3-30个字符,仅字母和数字",
70
- "required": "请输入用户名",
71
- "minLength": "用户名必须至少包含3个字符"
55
+ "label": "用户名",
56
+ "placeholder": "yourname",
57
+ "required": "请选择用户名。",
58
+ "taken": "该用户名已被占用。"
72
59
  },
73
60
  "email": {
74
- "required": "请输入电子邮件地址",
75
- "invalid": "请输入有效的电子邮件地址",
76
- "helper": "我们绝不会分享您的电子邮件"
77
- },
78
- "security": {
79
- "title": "保护您的账户",
80
- "subtitle": "创建强密码以保护您的账户"
61
+ "title": "你的恢复邮箱",
62
+ "subtitle": "如果你丢失了通行密钥,我们会向这里发送验证码让你重新进入。它不作其他用途。",
63
+ "label": "邮箱",
64
+ "placeholder": "you@example.com",
65
+ "invalid": "请输入有效的邮箱地址。"
81
66
  },
82
- "password": {
83
- "helper": "至少8个字符",
84
- "required": "请输入密码",
85
- "minLength": "密码必须至少包含8个字符",
86
- "confirmRequired": "请确认您的密码",
87
- "mismatch": "密码不匹配",
88
- "confirmHint": "重新输入您的密码以确认"
67
+ "passkey": {
68
+ "title": "创建你的通行密钥",
69
+ "subtitle": "用指纹、面容或屏幕锁登录,无需记住任何东西。",
70
+ "action": "创建通行密钥"
89
71
  },
90
- "summary": {
91
- "title": "快完成了!",
92
- "subtitle": "查看您的信息并创建账户",
93
- "sectionTitle": "账户信息",
94
- "fields": {
95
- "username": "用户名",
96
- "email": "电子邮件",
97
- "password": "密码"
98
- },
99
- "notSet": "未设置",
100
- "securityTip": "为了更强的安全性,创建账户后,请在账户设置中启用生物识别身份验证。",
101
- "legalReminder": "创建账户即表示您同意我们的服务条款和隐私政策。"
102
- }
72
+ "commonsInstead": "想自己保管密钥?改用 Commons"
103
73
  },
104
74
  "accountSwitcher": {
105
- "sections": {
106
- "yourAccounts": "你的账户"
107
- },
108
75
  "loading": "正在加载账户...",
109
76
  "qrHeadline": "使用您的 Oxy 身份登录",
110
77
  "signInWithOxy": "使用 Oxy 登录",
@@ -136,10 +103,7 @@
136
103
  "claimFailed": "登录已获批准,但未能完成。请重试。",
137
104
  "generic": "登录失败,请重试。"
138
105
  },
139
- "linkOpenFailed": "无法打开链接,请重试。",
140
- "continueWithPasskey": "继续",
141
- "passkeyHint": "使用指纹、面容或设备 PIN 码。",
142
- "otherDeviceCommons": "账号在其他设备上?用 Commons 扫码"
106
+ "linkOpenFailed": "无法打开链接,请重试。"
143
107
  },
144
108
  "common": {
145
109
  "actions": {
@@ -280,7 +244,63 @@
280
244
  "help": "帮助与反馈",
281
245
  "signOut": "退出登录",
282
246
  "privacy": "隐私政策",
283
- "terms": "服务条款",
284
- "identity": "你的身份"
247
+ "terms": "服务条款"
248
+ },
249
+ "recover": {
250
+ "title": "恢复你的账户",
251
+ "subtitle": "输入你的用户名或恢复邮箱。我们会向该账户的恢复邮箱发送验证码。",
252
+ "identifier": {
253
+ "label": "用户名或邮箱",
254
+ "placeholder": "yourname",
255
+ "required": "请输入用户名或邮箱。"
256
+ },
257
+ "commonsNote": "你的账户使用 Commons?请在 Commons 中用恢复短语恢复。",
258
+ "passkey": {
259
+ "title": "添加新的通行密钥",
260
+ "subtitle": "用于 @{{username}}。丢失的通行密钥可稍后在账户安全设置中移除。",
261
+ "action": "创建通行密钥"
262
+ },
263
+ "backToSignIn": "返回登录"
264
+ },
265
+ "emailCode": {
266
+ "title": "查看你的邮箱",
267
+ "sentTo": "我们已向 {{email}} 发送了 6 位验证码。",
268
+ "sentIfAccount": "如果该账户有恢复邮箱,我们已向其发送 6 位验证码。",
269
+ "label": "验证码",
270
+ "resend": "发送新验证码",
271
+ "resent": "我们已发送新验证码。",
272
+ "changeEmail": "使用其他邮箱",
273
+ "errors": {
274
+ "codeInvalid": "验证码不正确或已过期。",
275
+ "tooManyAttempts": "错误次数过多,请重新获取验证码。",
276
+ "expired": "耗时过长,请重新开始。",
277
+ "unavailable": "Oxy 暂时无法发送邮件,请稍后再试。",
278
+ "rateLimited": "验证码请求过多,请稍后再试。"
279
+ }
280
+ },
281
+ "deleteAccount": {
282
+ "passkey": {
283
+ "subtitle": "请用通行密钥确认。@{{username}} 及其中的一切将被永久删除。",
284
+ "action": "用通行密钥删除",
285
+ "done": "你的账户已删除。",
286
+ "closeWindow": "你可以关闭此窗口。",
287
+ "commons": "此账户使用 Commons:请在 Oxy Commons 的“设置 > 删除账户”中用其密钥删除。"
288
+ }
289
+ },
290
+ "linkCommons": {
291
+ "title": "关联 Commons",
292
+ "subtitle": "自己保管密钥:关联 Commons 后,此账户只属于你。它的恢复邮箱会被删除,今后用 Commons 中的恢复短语找回账户。",
293
+ "scan": "在手机上打开 Commons,选择“我在网页上有 Oxy 账户”,然后扫描此码。",
294
+ "waiting": "正在等待 Commons…",
295
+ "compareTitle": "核对代码",
296
+ "compare": "Commons 会显示相同的代码。如果不同,请取消。",
297
+ "confirm": "是的,关联 Commons",
298
+ "cancel": "取消",
299
+ "doneTitle": "Commons 已关联",
300
+ "done": "此账户现在由你自己保管。它的恢复邮箱已删除:今后用 Commons 中的恢复短语找回账户。",
301
+ "already": "此账户已在使用 Commons。",
302
+ "expired": "此代码已过期。",
303
+ "renew": "显示新代码",
304
+ "failed": "无法关联 Commons,请重试。"
285
305
  }
286
306
  }
package/dist/esm/index.js CHANGED
@@ -85,11 +85,11 @@ export { RecoveryPhraseService } from './crypto/recoveryPhrase.js';
85
85
  export { hkdfSha256 } from './crypto/kdf.js';
86
86
  export { encryptAead, decryptAead, AEAD_KEY_LENGTH, AEAD_NONCE_LENGTH, } from './crypto/aead.js';
87
87
  export { deriveSharedSecret } from './crypto/ecdh.js';
88
- // Web identity holder — the same root as Commons, sealed under a passkey's PRF
89
- // output; identity proofs; transfer to Commons (docs/adr/0024-one-oxy-account-root-holders.md)
90
- export { WEB_IDENTITY_PRF_INPUT, WebIdentityUnlockError, WEB_IDENTITY_PRF_OUTPUT_LENGTH, addWrap, deriveIdentityFromMnemonic, deriveIdentityFromPrivateKey, deriveIdentityFromRecoveryMaterial, deriveKeyEncryptionKey, generateDataKey, generateWebIdentity, isUsablePrfOutput, markWrapVerified, normalizeMnemonic, openWebIdentity, parseRecoveryMaterial, removeWrap, sealWebIdentity, unlockWebIdentity, unwrapDataKey, wipeBytes, wipeOpenedIdentity, } from './crypto/webIdentityCarrier.js';
88
+ // Identity proofs — the one signed format for operations on a personal root
89
+ // (docs/adr/0024-one-oxy-account-root-holders.md D7)
91
90
  export { digestIdentityPayload, signIdentityProof } from './crypto/identityProof.js';
92
- export { buildMoveQrPayload, createMoveCommitment, deriveMoveKey, deriveMoveSas, digestMoveCiphertext, generateMoveEphemeralKeyPair, openMovedIdentity, parseMoveQrPayload, sealIdentityForMove, signMoveReceipt, verifyMoveCommitment, verifyMoveReceipt, } from './crypto/identityMove.js';
91
+ // Linking Commons to a passkey account: the code both screens compare (ADR 0029 D3)
92
+ export { deriveIdentityLinkCode } from './crypto/identityLink.js';
93
93
  // ---------------------------------------------------------------------------
94
94
  // Devices
95
95
  // ---------------------------------------------------------------------------
@@ -158,7 +158,7 @@ export { buildAccountsArray, createQuickAccount, getAccountDisplayName, getAccou
158
158
  // `*.oxy.so`).
159
159
  // ---------------------------------------------------------------------------
160
160
  export { registrableApex } from './utils/registrableApex.js';
161
- export { CENTRAL_IDP_APEX, IDENTITY_WEB_ORIGIN } from './utils/authWebUrl.js';
161
+ export { AUTH_WEB_ORIGIN, CENTRAL_IDP_APEX } from './utils/authWebUrl.js';
162
162
  // WebAuthn relying-party origin guard (client side). Mirrors the server's
163
163
  // `isOxyApexOrigin` so consumers can decide whether to offer passkey UI on the
164
164
  // current page (first-party Oxy origin / loopback only).
@@ -1,4 +1,4 @@
1
- import { loginResultSchema, safeParseContract } from '@oxy.so/contracts';
1
+ import { emailVerificationConfirmResponseSchema, emailVerificationStartResponseSchema, loginResultSchema, safeParseContract, } from '@oxy.so/contracts';
2
2
  export { getCommonsApprovalBlockingReason, parseCommonsApprovalExpiresAt, } from '../utils/commonsApproval.js';
3
3
  import { OxyAuthenticationError } from '../OxyServices.errors.js';
4
4
  import { KeyManager } from '../crypto/keyManager.js';
@@ -1126,12 +1126,40 @@ export function OxyServicesAuthMixin(Base) {
1126
1126
  }
1127
1127
  }
1128
1128
  /**
1129
- * Check email availability
1129
+ * Send a 6-digit code to an email (ADR 0029 D3): the recovery email of a
1130
+ * new passkey account (`purpose: 'signup'`), or — named by username or
1131
+ * email — the recovery email of an account being recovered
1132
+ * (`purpose: 'recovery'`). The answer is the same whether or not an
1133
+ * account exists; nothing is revealed about who has one.
1130
1134
  */
1131
- async checkEmailAvailability(email) {
1135
+ async startEmailVerification(request) {
1132
1136
  try {
1133
- // Public availability lookup (pre-session) — skip the bearer preflight.
1134
- return await this.makeRequest('GET', `/auth/check-email/${email}`, undefined, { cache: false, skipAuth: true });
1137
+ const res = await this.makeRequest('POST', '/auth/email/verify/start', request, {
1138
+ cache: false,
1139
+ skipAuth: true,
1140
+ });
1141
+ const parsed = safeParseContract(emailVerificationStartResponseSchema, res);
1142
+ if (!parsed)
1143
+ throw new Error('auth/email/verify/start returned an unexpected response shape');
1144
+ return parsed;
1145
+ }
1146
+ catch (error) {
1147
+ throw this.handleError(error);
1148
+ }
1149
+ }
1150
+ /**
1151
+ * Confirm the code {@link startEmailVerification} sent. Resolves to a
1152
+ * short-lived one-use ticket: a sign-up passes it (with the email) to
1153
+ * {@link webauthnRegisterVerify}; a recovery passes it as `recoveryTicket`
1154
+ * to {@link webauthnRegisterOptions} and {@link webauthnRegisterVerify}.
1155
+ */
1156
+ async confirmEmailVerification(verificationId, code) {
1157
+ try {
1158
+ const res = await this.makeRequest('POST', '/auth/email/verify/confirm', { verificationId, code }, { cache: false, skipAuth: true });
1159
+ const parsed = safeParseContract(emailVerificationConfirmResponseSchema, res);
1160
+ if (!parsed)
1161
+ throw new Error('auth/email/verify/confirm returned an unexpected response shape');
1162
+ return parsed;
1135
1163
  }
1136
1164
  catch (error) {
1137
1165
  throw this.handleError(error);
@@ -1142,15 +1170,20 @@ export function OxyServicesAuthMixin(Base) {
1142
1170
  * `PublicKeyCredentialCreationOptions` the browser's `navigator.credentials
1143
1171
  * .create()` (or `@simplewebauthn/browser`'s `startRegistration`) needs.
1144
1172
  *
1145
- * With a bearer token planted this links a passkey to the signed-in account
1146
- * (`username` ignored); without one it is a prospective signup and `username`
1147
- * is the desired handle. The returned options are OPAQUE — Oxy does not own
1148
- * their shape (the browser / `@simplewebauthn` does), so they pass through
1149
- * as `unknown` for the caller to hand straight to the ceremony.
1173
+ * With a bearer token planted this adds a passkey to the signed-in account.
1174
+ * Without one, `username` is a prospective sign-up's handle, and
1175
+ * `recoveryTicket` a recovery's new passkey for the account it names. The
1176
+ * returned options are OPAQUE — Oxy does not own their shape (the browser /
1177
+ * `@simplewebauthn` does), so they pass through as `unknown` for the caller
1178
+ * to hand straight to the ceremony.
1150
1179
  */
1151
- async webauthnRegisterOptions(username) {
1180
+ async webauthnRegisterOptions(request = {}) {
1181
+ const signedOut = request.username !== undefined || request.recoveryTicket !== undefined;
1152
1182
  try {
1153
- return await this.makeRequest('POST', '/auth/webauthn/register/options', { ...(username !== undefined ? { username } : {}) }, { cache: false, ...(username !== undefined ? { skipAuth: true } : {}) });
1183
+ return await this.makeRequest('POST', '/auth/webauthn/register/options', {
1184
+ ...(request.username !== undefined ? { username: request.username } : {}),
1185
+ ...(request.recoveryTicket !== undefined ? { recoveryTicket: request.recoveryTicket } : {}),
1186
+ }, { cache: false, ...(signedOut ? { skipAuth: true } : {}) });
1154
1187
  }
1155
1188
  catch (error) {
1156
1189
  throw this.handleError(error);
@@ -1161,17 +1194,22 @@ export function OxyServicesAuthMixin(Base) {
1161
1194
  * browser `RegistrationResponseJSON` (`response`) alongside the Oxy envelope
1162
1195
  * (desired `username` for signup + the device-session naming fields).
1163
1196
  *
1164
- * Two server branches, disambiguated by the response shape:
1165
- * - **Signup** (no bearer): the account is created and a session minted —
1166
- * the response carries `sessionId`, is the SAME {@link LoginResult}
1167
- * contract as `POST /auth/verify`, and its access token is planted here.
1197
+ * Server branches, disambiguated by the response shape:
1198
+ * - **Sign-up** (no bearer; `username`, `email`, `emailTicket`) and
1199
+ * **recovery** (no bearer; `recoveryTicket`): the account is created, or
1200
+ * gains the passkey, and a session is minted — the response carries
1201
+ * `sessionId`, is the SAME {@link LoginResult} contract as
1202
+ * `POST /auth/verify`, and its access token is planted here.
1168
1203
  * - **Link** (bearer present): the passkey is attached to the signed-in
1169
1204
  * account and the server returns `{ success, message }` with no session,
1170
1205
  * which is returned verbatim (no token planting).
1171
1206
  */
1172
1207
  async webauthnRegisterVerify(response, envelope = {}) {
1173
1208
  try {
1174
- const res = await this.makeRequest('POST', '/auth/webauthn/register/verify', { response, ...envelope }, { cache: false, ...(envelope.username !== undefined ? { skipAuth: true } : {}) });
1209
+ const res = await this.makeRequest('POST', '/auth/webauthn/register/verify', { response, ...envelope }, {
1210
+ cache: false,
1211
+ ...(envelope.username !== undefined || envelope.recoveryTicket !== undefined ? { skipAuth: true } : {}),
1212
+ });
1175
1213
  if (res && typeof res === 'object') {
1176
1214
  const record = res;
1177
1215
  // Signup branch: mints a session (LoginSessionResult, carries
@@ -1,5 +1,33 @@
1
+ /**
2
+ * Identity Methods Mixin (self-sovereign identity layer)
3
+ *
4
+ * Provides typed access to Oxy's AtProto/Bluesky-flavoured identity &
5
+ * portability layer:
6
+ * - DID resolution (`did:web:oxy.so:u:<userId>`, derived on demand by the API).
7
+ * - The auth-method ↔ DID verification-method mapping (`GET /auth/methods`) and
8
+ * passkey removal. A root is linked by the holder flows (ADR 0024) and never
9
+ * unlinked; it is replaced by rotation.
10
+ * - Signed records: clients sign an envelope with their own cryptographic key
11
+ * (`SignatureService.signRecord` + the shared `canonicalize`) and publish it;
12
+ * anyone can fetch and verify it.
13
+ * - The signed data-export ("credible exit") bundle.
14
+ * - Verified-domain badges (prove ownership of `nate.com`).
15
+ *
16
+ * Wire shapes come from `@oxy.so/contracts` (`DidDocument`,
17
+ * `SignedRecordEnvelope`, `AuthMethodsResponse`, `VerifiedDomain`,
18
+ * `DomainVerificationInstructions`, `ExportBundle`) — the single source of truth
19
+ * the API validates its output against, so producer and consumer cannot drift.
20
+ *
21
+ * Identity signing is NATIVE-ONLY: the private key lives in native secure
22
+ * storage, so `signRecord` and `publishRecord` require an
23
+ * on-device identity and throw on web (where `KeyManager.getPublicKey()` is
24
+ * always `null`).
25
+ */
26
+ import { IDENTITY_PROOF_ACTIONS, identityLinkCreateResponseSchema, identityLinkStateSchema, safeParseContract, } from '@oxy.so/contracts';
1
27
  import { signMessage } from '@oxy.so/protocol';
2
28
  import { KeyManager } from '../crypto/keyManager.js';
29
+ import { deriveIdentityLinkCode } from '../crypto/identityLink.js';
30
+ import { signIdentityProof } from '../crypto/identityProof.js';
3
31
  import { SignatureService } from '../crypto/signatureService.js';
4
32
  import { RecoveryPhraseService } from '../crypto/recoveryPhrase.js';
5
33
  import { isWeb } from '../utils/platform.js';
@@ -71,11 +99,9 @@ export function OxyServicesIdentityMixin(Base) {
71
99
  }
72
100
  }
73
101
  /**
74
- * The signed-in account's root readiness (ADR 0024 D5): whether a root is
75
- * linked, how many passkeys can open the web holder, whether the root has a
76
- * phrase and whether it is saved and was shown to recover it. Metadata only —
77
- * nothing here can open the root — so any first-party surface may show a
78
- * "save your recovery phrase" reminder from it.
102
+ * How the signed-in account is kept (ADR 0029 D3): whether Commons' root is
103
+ * linked (self-custody), or the recovery email of a passkey account. Any
104
+ * first-party surface may read it to recommend linking Commons.
79
105
  */
80
106
  async getIdentityRootStatus() {
81
107
  try {
@@ -85,15 +111,109 @@ export function OxyServicesIdentityMixin(Base) {
85
111
  throw this.handleError(error);
86
112
  }
87
113
  }
114
+ /**
115
+ * Open a request to link Commons to the signed-in passkey account (ADR 0029
116
+ * D3). auth.oxy.so shows its `qrPayload`; Commons scans it and signs with
117
+ * {@link signIdentityLink}.
118
+ */
119
+ async createIdentityLink() {
120
+ try {
121
+ const res = await this.makeRequest('POST', '/identity/link', undefined, { cache: false });
122
+ const parsed = safeParseContract(identityLinkCreateResponseSchema, res);
123
+ if (!parsed)
124
+ throw new Error('identity/link returned an unexpected response shape');
125
+ return parsed;
126
+ }
127
+ catch (error) {
128
+ throw this.handleError(error);
129
+ }
130
+ }
131
+ /** Where a link request stands. Both devices poll it; it needs no session. */
132
+ async getIdentityLink(linkId) {
133
+ try {
134
+ const res = await this.makeRequest('GET', `/identity/link/${encodeURIComponent(linkId)}`, undefined, {
135
+ cache: false,
136
+ skipAuth: true,
137
+ });
138
+ const parsed = safeParseContract(identityLinkStateSchema, res);
139
+ if (!parsed)
140
+ throw new Error('identity/link returned an unexpected response shape');
141
+ return parsed;
142
+ }
143
+ catch (error) {
144
+ throw this.handleError(error);
145
+ }
146
+ }
147
+ /**
148
+ * Commons' half: sign the scanned request's `link_identity` proof with THIS
149
+ * device's identity key and post it. NATIVE-ONLY (the key lives in native
150
+ * secure storage). Resolves to the key and the 6-digit code auth.oxy.so will
151
+ * show for it, for the person to compare.
152
+ */
153
+ async signIdentityLink(linkId, challenge) {
154
+ try {
155
+ const [privateKey, publicKey] = await Promise.all([KeyManager.getPrivateKey(), KeyManager.getPublicKey()]);
156
+ if (!privateKey || !publicKey) {
157
+ throw new Error('No identity on this device to link');
158
+ }
159
+ const root = publicKey.trim().toLowerCase();
160
+ const state = await this.getIdentityLink(linkId);
161
+ const proof = await signIdentityProof({ privateKey, publicKey: root }, {
162
+ action: IDENTITY_PROOF_ACTIONS.link,
163
+ subject: state.userId,
164
+ actor: state.userId,
165
+ rootPublicKey: root,
166
+ payloadDigest: null,
167
+ expectedRevision: null,
168
+ audience: state.audience,
169
+ challenge,
170
+ expiresAt: state.expiresAt,
171
+ });
172
+ await this.makeRequest('POST', `/identity/link/${encodeURIComponent(linkId)}/proof`, { publicKey: root, proof }, { cache: false, skipAuth: true });
173
+ return { publicKey: root, code: deriveIdentityLinkCode(linkId, root), username: state.username };
174
+ }
175
+ catch (error) {
176
+ throw this.handleError(error);
177
+ }
178
+ }
179
+ /** WebAuthn request options over the account's passkeys, whose challenge is the link's. Opaque. */
180
+ async getIdentityLinkAssertionOptions(linkId, challenge) {
181
+ try {
182
+ return await this.makeRequest('POST', `/identity/link/${encodeURIComponent(linkId)}/options`, { challenge }, { cache: false });
183
+ }
184
+ catch (error) {
185
+ throw this.handleError(error);
186
+ }
187
+ }
188
+ /**
189
+ * auth.oxy.so's half: the passkey assertion over the link's challenge. The
190
+ * account gains Commons' root and loses its recovery email.
191
+ */
192
+ async completeIdentityLink(linkId, assertion) {
193
+ try {
194
+ const result = await this.makeRequest('POST', `/identity/link/${encodeURIComponent(linkId)}/complete`, { assertion }, { cache: false });
195
+ this._invalidateIdentityCaches(this.getCurrentUserId());
196
+ return result;
197
+ }
198
+ catch (error) {
199
+ throw this.handleError(error);
200
+ }
201
+ }
202
+ /** Withdraw a link request that has not completed. */
203
+ async cancelIdentityLink(linkId) {
204
+ try {
205
+ await this.makeRequest('DELETE', `/identity/link/${encodeURIComponent(linkId)}`, undefined, { cache: false });
206
+ }
207
+ catch (error) {
208
+ throw this.handleError(error);
209
+ }
210
+ }
88
211
  /**
89
212
  * Remove ONE passkey (WebAuthn credential) from the current account.
90
213
  *
91
214
  * Passkeys are per-credential, so this targets a specific credential id.
92
215
  * The server refuses to remove the last remaining auth method (the account
93
216
  * would become inaccessible) and deletes the stored `WebauthnCredential`.
94
- * A passkey that also opens the account's root on the web takes its wrap with
95
- * it, and the ONLY such passkey is refused with
96
- * `code: 'IDENTITY_LAST_WEB_HOLDER'` (ADR 0024 D6).
97
217
  *
98
218
  * @param credentialId - The passkey's public credential id
99
219
  * (`AuthMethodEntry.credentialId`).
@@ -532,6 +532,35 @@ export function OxyServicesUserMixin(Base) {
532
532
  throw this.handleError(error);
533
533
  }
534
534
  }
535
+ /**
536
+ * WebAuthn request options to delete a PASSKEY account (ADR 0029 D3): its own
537
+ * passkeys, user verification required, and a challenge bound to it. Opaque —
538
+ * hand them to the browser's authentication ceremony, on auth.oxy.so. An
539
+ * account with a Commons key deletes with {@link deleteAccount} instead.
540
+ */
541
+ async getAccountDeletionOptions() {
542
+ try {
543
+ return await this.makeRequest('POST', '/users/me/delete/options', undefined, { cache: false });
544
+ }
545
+ catch (error) {
546
+ throw this.handleError(error);
547
+ }
548
+ }
549
+ /**
550
+ * Delete a PASSKEY account permanently, with an assertion by one of its
551
+ * passkeys over {@link getAccountDeletionOptions}' challenge.
552
+ *
553
+ * @param confirmText - Must equal the user's username (verified server-side)
554
+ * @param assertion - The ceremony's opaque `AuthenticationResponseJSON`
555
+ */
556
+ async deleteAccountWithPasskey(confirmText, assertion) {
557
+ try {
558
+ return await this.makeRequest('DELETE', '/users/me', { confirmText, assertion }, { cache: false });
559
+ }
560
+ catch (error) {
561
+ throw this.handleError(error);
562
+ }
563
+ }
535
564
  /**
536
565
  * Invalidate every cached read a follow/unfollow write invalidates.
537
566
  *
@@ -841,11 +870,13 @@ export function OxyServicesUserMixin(Base) {
841
870
  }
842
871
  }
843
872
  /**
844
- * Get notifications
873
+ * One page of the signed-in user's Oxy notifications, newest first
874
+ * (`GET /notifications`), with the unread count across all pages.
845
875
  */
846
- async getNotifications() {
876
+ async getNotifications(params = {}) {
877
+ const query = buildQueryParams({ page: params.page, limit: params.limit });
847
878
  return this.withAuthRetry(async () => {
848
- return await this.makeRequest('GET', '/notifications', undefined, {
879
+ return await this.makeRequest('GET', '/notifications', query, {
849
880
  cache: false, // Don't cache notifications - always get fresh data
850
881
  });
851
882
  }, 'getNotifications');
@@ -858,7 +889,7 @@ export function OxyServicesUserMixin(Base) {
858
889
  const res = await this.makeRequest('GET', '/notifications/unread-count', undefined, {
859
890
  cache: false, // Don't cache unread count - always get fresh data
860
891
  });
861
- return res.count;
892
+ return res.unreadCount;
862
893
  }
863
894
  catch (error) {
864
895
  throw this.handleError(error);
@@ -873,18 +904,22 @@ export function OxyServicesUserMixin(Base) {
873
904
  */
874
905
  async createNotification(data) {
875
906
  try {
876
- return await this.makeRequest('POST', '/notifications', data, { cache: false });
907
+ const res = await this.makeRequest('POST', '/notifications', data, { cache: false });
908
+ return res.notification;
877
909
  }
878
910
  catch (error) {
879
911
  throw this.handleError(error);
880
912
  }
881
913
  }
882
914
  /**
883
- * Mark notification as read
915
+ * Mark one of the signed-in user's notifications read and return it as
916
+ * stored. Scoped to the recipient server-side, so it is also the
917
+ * authoritative read of a notification by id: a foreign or unknown id 404s.
884
918
  */
885
919
  async markNotificationAsRead(notificationId) {
886
920
  try {
887
- await this.makeRequest('PUT', `/notifications/${notificationId}/read`, undefined, { cache: false });
921
+ const res = await this.makeRequest('PUT', `/notifications/${encodeURIComponent(notificationId)}/read`, undefined, { cache: false });
922
+ return res.notification;
888
923
  }
889
924
  catch (error) {
890
925
  throw this.handleError(error);