@sharadox/account-web-library 0.1.0-development.3 → 0.1.0-development.33

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 (392) hide show
  1. package/README.md +270 -8
  2. package/distribution/account-activity/index.d.ts +16 -0
  3. package/distribution/account-activity/index.d.ts.map +1 -0
  4. package/distribution/account-activity/index.js +18 -0
  5. package/distribution/account-activity/index.js.map +1 -0
  6. package/distribution/account-activity/type.d.ts +15 -0
  7. package/distribution/account-activity/type.d.ts.map +1 -0
  8. package/distribution/account-activity/type.js.map +1 -0
  9. package/distribution/account-ban/index.d.ts +67 -0
  10. package/distribution/account-ban/index.d.ts.map +1 -0
  11. package/distribution/account-ban/index.js +233 -0
  12. package/distribution/account-ban/index.js.map +1 -0
  13. package/distribution/account-ban/type.d.ts +44 -0
  14. package/distribution/account-ban/type.d.ts.map +1 -0
  15. package/distribution/account-ban/type.js +2 -0
  16. package/distribution/account-ban/type.js.map +1 -0
  17. package/distribution/account-database/type.d.ts +264 -0
  18. package/distribution/account-database/type.d.ts.map +1 -0
  19. package/distribution/account-database/type.js +2 -0
  20. package/distribution/account-database/type.js.map +1 -0
  21. package/distribution/account-deletion/index.d.ts +21 -0
  22. package/distribution/account-deletion/index.d.ts.map +1 -0
  23. package/distribution/account-deletion/index.js +66 -0
  24. package/distribution/account-deletion/index.js.map +1 -0
  25. package/distribution/account-export/index.d.ts +17 -0
  26. package/distribution/account-export/index.d.ts.map +1 -0
  27. package/distribution/account-export/index.js +87 -0
  28. package/distribution/account-export/index.js.map +1 -0
  29. package/distribution/account-export/type.d.ts +40 -0
  30. package/distribution/account-export/type.d.ts.map +1 -0
  31. package/distribution/account-export/type.js +2 -0
  32. package/distribution/account-export/type.js.map +1 -0
  33. package/distribution/account-inactivity/index.d.ts +25 -0
  34. package/distribution/account-inactivity/index.d.ts.map +1 -0
  35. package/distribution/account-inactivity/index.js +100 -0
  36. package/distribution/account-inactivity/index.js.map +1 -0
  37. package/distribution/account-migration/index.d.ts +18 -0
  38. package/distribution/account-migration/index.d.ts.map +1 -0
  39. package/distribution/account-migration/index.js +376 -0
  40. package/distribution/account-migration/index.js.map +1 -0
  41. package/distribution/account-name/index.d.ts +13 -0
  42. package/distribution/account-name/index.d.ts.map +1 -0
  43. package/distribution/account-name/index.js +22 -0
  44. package/distribution/account-name/index.js.map +1 -0
  45. package/distribution/account-name/type.d.ts +9 -0
  46. package/distribution/account-name/type.d.ts.map +1 -0
  47. package/distribution/account-name/type.js +2 -0
  48. package/distribution/account-name/type.js.map +1 -0
  49. package/distribution/account-name-change/index.d.ts +15 -0
  50. package/distribution/account-name-change/index.d.ts.map +1 -0
  51. package/distribution/account-name-change/index.js +26 -0
  52. package/distribution/account-name-change/index.js.map +1 -0
  53. package/distribution/account-name-change/type.d.ts +7 -0
  54. package/distribution/account-name-change/type.d.ts.map +1 -0
  55. package/distribution/account-name-change/type.js +2 -0
  56. package/distribution/account-name-change/type.js.map +1 -0
  57. package/distribution/account-notice/index.d.ts +15 -0
  58. package/distribution/account-notice/index.d.ts.map +1 -0
  59. package/distribution/account-notice/index.js +41 -0
  60. package/distribution/account-notice/index.js.map +1 -0
  61. package/distribution/account-permission/index.d.ts +14 -0
  62. package/distribution/account-permission/index.d.ts.map +1 -0
  63. package/distribution/account-permission/index.js +91 -0
  64. package/distribution/account-permission/index.js.map +1 -0
  65. package/distribution/account-permission/type.d.ts +12 -0
  66. package/distribution/account-permission/type.d.ts.map +1 -0
  67. package/distribution/account-permission/type.js +2 -0
  68. package/distribution/account-permission/type.js.map +1 -0
  69. package/distribution/account-picture-change/index.d.ts +30 -0
  70. package/distribution/account-picture-change/index.d.ts.map +1 -0
  71. package/distribution/account-picture-change/index.js +70 -0
  72. package/distribution/account-picture-change/index.js.map +1 -0
  73. package/distribution/account-picture-change/type.d.ts +11 -0
  74. package/distribution/account-picture-change/type.d.ts.map +1 -0
  75. package/distribution/account-picture-change/type.js +2 -0
  76. package/distribution/account-picture-change/type.js.map +1 -0
  77. package/distribution/account-server/index.d.ts +25 -0
  78. package/distribution/account-server/index.d.ts.map +1 -0
  79. package/distribution/account-server/index.js +34 -0
  80. package/distribution/account-server/index.js.map +1 -0
  81. package/distribution/account-server/type.d.ts +30 -0
  82. package/distribution/account-server/type.d.ts.map +1 -0
  83. package/distribution/account-server/type.js +2 -0
  84. package/distribution/account-server/type.js.map +1 -0
  85. package/distribution/account-session-end/index.d.ts +15 -0
  86. package/distribution/account-session-end/index.d.ts.map +1 -0
  87. package/distribution/account-session-end/index.js +21 -0
  88. package/distribution/account-session-end/index.js.map +1 -0
  89. package/distribution/account-session-list/index.d.ts +16 -0
  90. package/distribution/account-session-list/index.d.ts.map +1 -0
  91. package/distribution/account-session-list/index.js +33 -0
  92. package/distribution/account-session-list/index.js.map +1 -0
  93. package/distribution/account-session-list/type.d.ts +13 -0
  94. package/distribution/account-session-list/type.d.ts.map +1 -0
  95. package/distribution/account-session-list/type.js +2 -0
  96. package/distribution/account-session-list/type.js.map +1 -0
  97. package/distribution/account-session-revocation/index.d.ts +14 -0
  98. package/distribution/account-session-revocation/index.d.ts.map +1 -0
  99. package/distribution/account-session-revocation/index.js +25 -0
  100. package/distribution/account-session-revocation/index.js.map +1 -0
  101. package/distribution/account-sign-in/index.d.ts +15 -0
  102. package/distribution/account-sign-in/index.d.ts.map +1 -0
  103. package/distribution/account-sign-in/index.js +78 -0
  104. package/distribution/account-sign-in/index.js.map +1 -0
  105. package/distribution/account-sign-in/type.d.ts +24 -0
  106. package/distribution/account-sign-in/type.d.ts.map +1 -0
  107. package/distribution/account-sign-in/type.js +2 -0
  108. package/distribution/account-sign-in/type.js.map +1 -0
  109. package/distribution/account-sign-out/index.d.ts +16 -0
  110. package/distribution/account-sign-out/index.d.ts.map +1 -0
  111. package/distribution/account-sign-out/index.js +34 -0
  112. package/distribution/account-sign-out/index.js.map +1 -0
  113. package/distribution/application-sync/index.d.ts +14 -0
  114. package/distribution/application-sync/index.d.ts.map +1 -0
  115. package/distribution/application-sync/index.js +96 -0
  116. package/distribution/application-sync/index.js.map +1 -0
  117. package/distribution/application-sync/type.d.ts +29 -0
  118. package/distribution/application-sync/type.d.ts.map +1 -0
  119. package/distribution/application-sync/type.js +2 -0
  120. package/distribution/application-sync/type.js.map +1 -0
  121. package/distribution/audit-event/index.d.ts +12 -0
  122. package/distribution/audit-event/index.d.ts.map +1 -0
  123. package/distribution/audit-event/index.js +36 -0
  124. package/distribution/audit-event/index.js.map +1 -0
  125. package/distribution/audit-event/type.d.ts +16 -0
  126. package/distribution/audit-event/type.d.ts.map +1 -0
  127. package/distribution/audit-event/type.js +2 -0
  128. package/distribution/audit-event/type.js.map +1 -0
  129. package/distribution/banned-contact/index.d.ts +34 -0
  130. package/distribution/banned-contact/index.d.ts.map +1 -0
  131. package/distribution/banned-contact/index.js +52 -0
  132. package/distribution/banned-contact/index.js.map +1 -0
  133. package/distribution/browser-session-read/index.d.ts +17 -0
  134. package/distribution/browser-session-read/index.d.ts.map +1 -0
  135. package/distribution/browser-session-read/index.js +52 -0
  136. package/distribution/browser-session-read/index.js.map +1 -0
  137. package/distribution/browser-session-read/type.d.ts +18 -0
  138. package/distribution/browser-session-read/type.d.ts.map +1 -0
  139. package/distribution/browser-session-read/type.js +2 -0
  140. package/distribution/browser-session-read/type.js.map +1 -0
  141. package/distribution/challenge-issue/index.d.ts +13 -0
  142. package/distribution/challenge-issue/index.d.ts.map +1 -0
  143. package/distribution/challenge-issue/index.js +18 -0
  144. package/distribution/challenge-issue/index.js.map +1 -0
  145. package/distribution/code-request/index.d.ts +16 -0
  146. package/distribution/code-request/index.d.ts.map +1 -0
  147. package/distribution/code-request/index.js +52 -0
  148. package/distribution/code-request/index.js.map +1 -0
  149. package/distribution/code-request/type.d.ts +25 -0
  150. package/distribution/code-request/type.d.ts.map +1 -0
  151. package/distribution/code-request/type.js +2 -0
  152. package/distribution/code-request/type.js.map +1 -0
  153. package/distribution/code-request-prune/index.d.ts +13 -0
  154. package/distribution/code-request-prune/index.d.ts.map +1 -0
  155. package/distribution/code-request-prune/index.js +12 -0
  156. package/distribution/code-request-prune/index.js.map +1 -0
  157. package/distribution/code-sending/index.d.ts +14 -0
  158. package/distribution/code-sending/index.d.ts.map +1 -0
  159. package/distribution/code-sending/index.js +65 -0
  160. package/distribution/code-sending/index.js.map +1 -0
  161. package/distribution/code-sending/type.d.ts +31 -0
  162. package/distribution/code-sending/type.d.ts.map +1 -0
  163. package/distribution/code-sending/type.js +2 -0
  164. package/distribution/code-sending/type.js.map +1 -0
  165. package/distribution/code-verification/index.d.ts +14 -0
  166. package/distribution/code-verification/index.d.ts.map +1 -0
  167. package/distribution/code-verification/index.js +43 -0
  168. package/distribution/code-verification/index.js.map +1 -0
  169. package/distribution/code-verification/type.d.ts +22 -0
  170. package/distribution/code-verification/type.d.ts.map +1 -0
  171. package/distribution/code-verification/type.js +2 -0
  172. package/distribution/code-verification/type.js.map +1 -0
  173. package/distribution/contact-addition/index.d.ts +13 -0
  174. package/distribution/contact-addition/index.d.ts.map +1 -0
  175. package/distribution/contact-addition/index.js +48 -0
  176. package/distribution/contact-addition/index.js.map +1 -0
  177. package/distribution/contact-addition/type.d.ts +15 -0
  178. package/distribution/contact-addition/type.d.ts.map +1 -0
  179. package/distribution/contact-addition/type.js +2 -0
  180. package/distribution/contact-addition/type.js.map +1 -0
  181. package/distribution/contact-addition-flow/index.d.ts +32 -0
  182. package/distribution/contact-addition-flow/index.d.ts.map +1 -0
  183. package/distribution/contact-addition-flow/index.js +96 -0
  184. package/distribution/contact-addition-flow/index.js.map +1 -0
  185. package/distribution/contact-addition-flow/type.d.ts +25 -0
  186. package/distribution/contact-addition-flow/type.d.ts.map +1 -0
  187. package/distribution/contact-addition-flow/type.js +2 -0
  188. package/distribution/contact-addition-flow/type.js.map +1 -0
  189. package/distribution/contact-channel/type.d.ts +49 -0
  190. package/distribution/contact-channel/type.d.ts.map +1 -0
  191. package/distribution/contact-channel/type.js +2 -0
  192. package/distribution/contact-channel/type.js.map +1 -0
  193. package/distribution/contact-kind/index.d.ts +12 -0
  194. package/distribution/contact-kind/index.d.ts.map +1 -0
  195. package/distribution/contact-kind/index.js +18 -0
  196. package/distribution/contact-kind/index.js.map +1 -0
  197. package/distribution/contact-kind/type.d.ts +6 -0
  198. package/distribution/contact-kind/type.d.ts.map +1 -0
  199. package/distribution/contact-kind/type.js +2 -0
  200. package/distribution/contact-kind/type.js.map +1 -0
  201. package/distribution/contact-lookup/index.d.ts +16 -0
  202. package/distribution/contact-lookup/index.d.ts.map +1 -0
  203. package/distribution/contact-lookup/index.js +20 -0
  204. package/distribution/contact-lookup/index.js.map +1 -0
  205. package/distribution/contact-removal/index.d.ts +19 -0
  206. package/distribution/contact-removal/index.d.ts.map +1 -0
  207. package/distribution/contact-removal/index.js +35 -0
  208. package/distribution/contact-removal/index.js.map +1 -0
  209. package/distribution/contact-verification/index.d.ts +20 -0
  210. package/distribution/contact-verification/index.d.ts.map +1 -0
  211. package/distribution/contact-verification/index.js +37 -0
  212. package/distribution/contact-verification/index.js.map +1 -0
  213. package/distribution/database-error/index.d.ts +12 -0
  214. package/distribution/database-error/index.d.ts.map +1 -0
  215. package/distribution/database-error/index.js +14 -0
  216. package/distribution/database-error/index.js.map +1 -0
  217. package/distribution/email-channel/index.d.ts +13 -0
  218. package/distribution/email-channel/index.d.ts.map +1 -0
  219. package/distribution/email-channel/index.js +185 -0
  220. package/distribution/email-channel/index.js.map +1 -0
  221. package/distribution/email-channel/type.d.ts +17 -0
  222. package/distribution/email-channel/type.d.ts.map +1 -0
  223. package/distribution/email-channel/type.js +2 -0
  224. package/distribution/email-channel/type.js.map +1 -0
  225. package/distribution/identifier/index.d.ts +23 -0
  226. package/distribution/identifier/index.d.ts.map +1 -0
  227. package/distribution/identifier/index.js +32 -0
  228. package/distribution/identifier/index.js.map +1 -0
  229. package/distribution/identifier/type.d.ts +10 -0
  230. package/distribution/identifier/type.d.ts.map +1 -0
  231. package/distribution/identifier/type.js +2 -0
  232. package/distribution/identifier/type.js.map +1 -0
  233. package/distribution/identifier-availability/index.d.ts +11 -0
  234. package/distribution/identifier-availability/index.d.ts.map +1 -0
  235. package/distribution/identifier-availability/index.js +21 -0
  236. package/distribution/identifier-availability/index.js.map +1 -0
  237. package/distribution/identifier-change/index.d.ts +15 -0
  238. package/distribution/identifier-change/index.d.ts.map +1 -0
  239. package/distribution/identifier-change/index.js +43 -0
  240. package/distribution/identifier-change/index.js.map +1 -0
  241. package/distribution/identifier-change/type.d.ts +7 -0
  242. package/distribution/identifier-change/type.d.ts.map +1 -0
  243. package/distribution/identifier-change/type.js +2 -0
  244. package/distribution/identifier-change/type.js.map +1 -0
  245. package/distribution/memory-picture-storage/index.d.ts +15 -0
  246. package/distribution/memory-picture-storage/index.d.ts.map +1 -0
  247. package/distribution/memory-picture-storage/index.js +16 -0
  248. package/distribution/memory-picture-storage/index.js.map +1 -0
  249. package/distribution/one-time-code/index.d.ts +2 -2
  250. package/distribution/one-time-code/index.js +3 -3
  251. package/distribution/person-account/index.d.ts +18 -0
  252. package/distribution/person-account/index.d.ts.map +1 -0
  253. package/distribution/person-account/index.js +65 -0
  254. package/distribution/person-account/index.js.map +1 -0
  255. package/distribution/person-account/type.d.ts +22 -0
  256. package/distribution/person-account/type.d.ts.map +1 -0
  257. package/distribution/person-account/type.js +2 -0
  258. package/distribution/person-account/type.js.map +1 -0
  259. package/distribution/picture-key/index.d.ts +8 -0
  260. package/distribution/picture-key/index.d.ts.map +1 -0
  261. package/distribution/picture-key/index.js +10 -0
  262. package/distribution/picture-key/index.js.map +1 -0
  263. package/distribution/picture-preparation/index.d.ts +18 -0
  264. package/distribution/picture-preparation/index.d.ts.map +1 -0
  265. package/distribution/picture-preparation/index.js +86 -0
  266. package/distribution/picture-preparation/index.js.map +1 -0
  267. package/distribution/picture-preparation/type.d.ts +18 -0
  268. package/distribution/picture-preparation/type.d.ts.map +1 -0
  269. package/distribution/picture-preparation/type.js +2 -0
  270. package/distribution/picture-preparation/type.js.map +1 -0
  271. package/distribution/picture-storage/type.d.ts +11 -0
  272. package/distribution/picture-storage/type.d.ts.map +1 -0
  273. package/distribution/picture-storage/type.js +2 -0
  274. package/distribution/picture-storage/type.js.map +1 -0
  275. package/distribution/recovery-code-regeneration/index.d.ts +19 -0
  276. package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
  277. package/distribution/recovery-code-regeneration/index.js +34 -0
  278. package/distribution/recovery-code-regeneration/index.js.map +1 -0
  279. package/distribution/recovery-code-store/index.d.ts +25 -0
  280. package/distribution/recovery-code-store/index.d.ts.map +1 -0
  281. package/distribution/recovery-code-store/index.js +34 -0
  282. package/distribution/recovery-code-store/index.js.map +1 -0
  283. package/distribution/role-grant/index.d.ts +38 -0
  284. package/distribution/role-grant/index.d.ts.map +1 -0
  285. package/distribution/role-grant/index.js +142 -0
  286. package/distribution/role-grant/index.js.map +1 -0
  287. package/distribution/role-grant/type.d.ts +40 -0
  288. package/distribution/role-grant/type.d.ts.map +1 -0
  289. package/distribution/role-grant/type.js +2 -0
  290. package/distribution/role-grant/type.js.map +1 -0
  291. package/distribution/rule-sync/index.d.ts +28 -0
  292. package/distribution/rule-sync/index.d.ts.map +1 -0
  293. package/distribution/rule-sync/index.js +80 -0
  294. package/distribution/rule-sync/index.js.map +1 -0
  295. package/distribution/rule-sync/type.d.ts +17 -0
  296. package/distribution/rule-sync/type.d.ts.map +1 -0
  297. package/distribution/rule-sync/type.js +2 -0
  298. package/distribution/rule-sync/type.js.map +1 -0
  299. package/distribution/second-factor-finish/index.d.ts +13 -0
  300. package/distribution/second-factor-finish/index.d.ts.map +1 -0
  301. package/distribution/second-factor-finish/index.js +90 -0
  302. package/distribution/second-factor-finish/index.js.map +1 -0
  303. package/distribution/second-factor-finish/type.d.ts +30 -0
  304. package/distribution/second-factor-finish/type.d.ts.map +1 -0
  305. package/distribution/second-factor-finish/type.js +2 -0
  306. package/distribution/second-factor-finish/type.js.map +1 -0
  307. package/distribution/secret-derivation/index.d.ts +10 -0
  308. package/distribution/secret-derivation/index.d.ts.map +1 -0
  309. package/distribution/secret-derivation/index.js +15 -0
  310. package/distribution/secret-derivation/index.js.map +1 -0
  311. package/distribution/secret-encryption/index.d.ts +17 -0
  312. package/distribution/secret-encryption/index.d.ts.map +1 -0
  313. package/distribution/secret-encryption/index.js +37 -0
  314. package/distribution/secret-encryption/index.js.map +1 -0
  315. package/distribution/session-prune/index.d.ts +17 -0
  316. package/distribution/session-prune/index.d.ts.map +1 -0
  317. package/distribution/session-prune/index.js +30 -0
  318. package/distribution/session-prune/index.js.map +1 -0
  319. package/distribution/session-token/index.d.ts +19 -0
  320. package/distribution/session-token/index.d.ts.map +1 -0
  321. package/distribution/session-token/index.js +22 -0
  322. package/distribution/session-token/index.js.map +1 -0
  323. package/distribution/sign-in-finish/index.d.ts +13 -0
  324. package/distribution/sign-in-finish/index.d.ts.map +1 -0
  325. package/distribution/sign-in-finish/index.js +69 -0
  326. package/distribution/sign-in-finish/index.js.map +1 -0
  327. package/distribution/sign-in-finish/type.d.ts +44 -0
  328. package/distribution/sign-in-finish/type.d.ts.map +1 -0
  329. package/distribution/sign-in-finish/type.js +2 -0
  330. package/distribution/sign-in-finish/type.js.map +1 -0
  331. package/distribution/sign-in-start/index.d.ts +17 -0
  332. package/distribution/sign-in-start/index.d.ts.map +1 -0
  333. package/distribution/sign-in-start/index.js +45 -0
  334. package/distribution/sign-in-start/index.js.map +1 -0
  335. package/distribution/sign-in-start/type.d.ts +34 -0
  336. package/distribution/sign-in-start/type.d.ts.map +1 -0
  337. package/distribution/sign-in-start/type.js +2 -0
  338. package/distribution/sign-in-start/type.js.map +1 -0
  339. package/distribution/sign-up-finish/index.d.ts +13 -0
  340. package/distribution/sign-up-finish/index.d.ts.map +1 -0
  341. package/distribution/sign-up-finish/index.js +38 -0
  342. package/distribution/sign-up-finish/index.js.map +1 -0
  343. package/distribution/sign-up-finish/type.d.ts +28 -0
  344. package/distribution/sign-up-finish/type.d.ts.map +1 -0
  345. package/distribution/sign-up-finish/type.js +2 -0
  346. package/distribution/sign-up-finish/type.js.map +1 -0
  347. package/distribution/signed-ticket/index.d.ts +19 -0
  348. package/distribution/signed-ticket/index.d.ts.map +1 -0
  349. package/distribution/signed-ticket/index.js +35 -0
  350. package/distribution/signed-ticket/index.js.map +1 -0
  351. package/distribution/signed-ticket/type.d.ts +16 -0
  352. package/distribution/signed-ticket/type.d.ts.map +1 -0
  353. package/distribution/signed-ticket/type.js +2 -0
  354. package/distribution/signed-ticket/type.js.map +1 -0
  355. package/distribution/step-up/index.d.ts +48 -0
  356. package/distribution/step-up/index.d.ts.map +1 -0
  357. package/distribution/step-up/index.js +83 -0
  358. package/distribution/step-up/index.js.map +1 -0
  359. package/distribution/step-up/type.d.ts +15 -0
  360. package/distribution/step-up/type.d.ts.map +1 -0
  361. package/distribution/step-up/type.js +2 -0
  362. package/distribution/{username → step-up}/type.js.map +1 -1
  363. package/distribution/test-database/index.d.ts +13 -0
  364. package/distribution/test-database/index.d.ts.map +1 -0
  365. package/distribution/test-database/index.js +17 -0
  366. package/distribution/test-database/index.js.map +1 -0
  367. package/distribution/test-person/index.d.ts +14 -0
  368. package/distribution/test-person/index.d.ts.map +1 -0
  369. package/distribution/test-person/index.js +20 -0
  370. package/distribution/test-person/index.js.map +1 -0
  371. package/distribution/test-server/index.d.ts +10 -0
  372. package/distribution/test-server/index.d.ts.map +1 -0
  373. package/distribution/test-server/index.js +16 -0
  374. package/distribution/test-server/index.js.map +1 -0
  375. package/distribution/totp/type.d.ts +1 -1
  376. package/distribution/totp/type.d.ts.map +1 -1
  377. package/distribution/totp-setup/index.d.ts +50 -0
  378. package/distribution/totp-setup/index.d.ts.map +1 -0
  379. package/distribution/totp-setup/index.js +136 -0
  380. package/distribution/totp-setup/index.js.map +1 -0
  381. package/distribution/totp-setup/type.d.ts +24 -0
  382. package/distribution/totp-setup/type.d.ts.map +1 -0
  383. package/distribution/totp-setup/type.js +2 -0
  384. package/distribution/totp-setup/type.js.map +1 -0
  385. package/package.json +9 -2
  386. package/distribution/username/index.d.ts +0 -23
  387. package/distribution/username/index.d.ts.map +0 -1
  388. package/distribution/username/index.js +0 -32
  389. package/distribution/username/index.js.map +0 -1
  390. package/distribution/username/type.d.ts +0 -10
  391. package/distribution/username/type.d.ts.map +0 -1
  392. /package/distribution/{username → account-activity}/type.js +0 -0
@@ -0,0 +1,28 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { PublishedRule, RuleDeclaration } from "@sharadox/account-web-library/rule-sync/type";
4
+ /**
5
+ * Publishes an application's rules (or global ones, `application: null`). A rule whose words or penalties changed gets
6
+ * a new version, and earlier bans keep citing the version they broke. Returns the codes given a new version.
7
+ *
8
+ * @example
9
+ * await syncRules(database, { application: "platform", rules: [{ code: "spam", title, description, schedule }] });
10
+ */
11
+ export declare function syncRules(database: Kysely<AccountDatabase>, { application, rules }: {
12
+ application: string | null;
13
+ rules: RuleDeclaration[];
14
+ }): Promise<{
15
+ versioned: string[];
16
+ unknownApplication?: true;
17
+ }>;
18
+ /**
19
+ * The rules in force for an application, newest versions, global ones first then its own, by code: what the public
20
+ * rules page and `GET /api/rules` show.
21
+ *
22
+ * @example
23
+ * const rules = await listRules(database, { application: "platform" });
24
+ */
25
+ export declare function listRules(database: Kysely<AccountDatabase>, { application }: {
26
+ application: string;
27
+ }): Promise<PublishedRule[]>;
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAUnG;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,eAAe,EAAE,CAAA;CAAE,GAC/E,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CA8B7D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,aAAa,EAAE,CAAC,CA2B1B"}
@@ -0,0 +1,80 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ const same = (first, second) => JSON.stringify(first) === JSON.stringify(second);
3
+ /** The application's id; null for global rules; undefined when it doesn't exist. */
4
+ async function applicationId(database, key) {
5
+ if (key === null)
6
+ return null;
7
+ return (await database.selectFrom("application").select("id").where("key", "=", key).executeTakeFirst())?.id;
8
+ }
9
+ /**
10
+ * Publishes an application's rules (or global ones, `application: null`). A rule whose words or penalties changed gets
11
+ * a new version, and earlier bans keep citing the version they broke. Returns the codes given a new version.
12
+ *
13
+ * @example
14
+ * await syncRules(database, { application: "platform", rules: [{ code: "spam", title, description, schedule }] });
15
+ */
16
+ export async function syncRules(database, { application, rules }) {
17
+ const id = await applicationId(database, application);
18
+ if (id === undefined)
19
+ return { versioned: [], unknownApplication: true };
20
+ const versioned = [];
21
+ for (const rule of rules) {
22
+ let latest = database.selectFrom("rule").selectAll().where("code", "=", rule.code);
23
+ latest = id === null ? latest.where("application_id", "is", null) : latest.where("application_id", "=", id);
24
+ const current = await latest.orderBy("version", "desc").executeTakeFirst();
25
+ if (current &&
26
+ same(current.title, rule.title) &&
27
+ same(current.description, rule.description) &&
28
+ same(current.schedule, rule.schedule))
29
+ continue;
30
+ await database
31
+ .insertInto("rule")
32
+ .values({
33
+ id: uuidVersion7(),
34
+ application_id: id,
35
+ code: rule.code,
36
+ version: (current?.version ?? 0) + 1,
37
+ title: JSON.stringify(rule.title),
38
+ description: JSON.stringify(rule.description),
39
+ schedule: JSON.stringify(rule.schedule),
40
+ })
41
+ .execute();
42
+ versioned.push(rule.code);
43
+ }
44
+ return { versioned };
45
+ }
46
+ /**
47
+ * The rules in force for an application, newest versions, global ones first then its own, by code: what the public
48
+ * rules page and `GET /api/rules` show.
49
+ *
50
+ * @example
51
+ * const rules = await listRules(database, { application: "platform" });
52
+ */
53
+ export async function listRules(database, { application }) {
54
+ const id = await applicationId(database, application);
55
+ const rows = await database
56
+ .selectFrom("rule")
57
+ .selectAll()
58
+ .where((where) => id
59
+ ? where.or([where("application_id", "is", null), where("application_id", "=", id)])
60
+ : where("application_id", "is", null))
61
+ .orderBy("version", "desc")
62
+ .execute();
63
+ const newest = new Map();
64
+ for (const row of rows) {
65
+ const key = `${row.application_id === null ? "0" : "1"}:${row.code}`;
66
+ if (!newest.has(key))
67
+ newest.set(key, row);
68
+ }
69
+ return [...newest.entries()]
70
+ .sort(([first], [second]) => first.localeCompare(second))
71
+ .map(([, row]) => ({
72
+ code: row.code,
73
+ version: row.version,
74
+ title: row.title,
75
+ description: row.description,
76
+ schedule: row.schedule,
77
+ global: row.application_id === null,
78
+ }));
79
+ }
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/rule-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAI/E,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,MAAe,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAEnG,oFAAoF;AACpF,KAAK,UAAU,aAAa,CAAC,QAAiC,EA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,CAAC,SAAS,EAAE,MAAM,CAAC;SAC1B,OAAO,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiC,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,cAAc,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACrE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;SACzB,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SACxD,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QACjB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,cAAc,KAAK,IAAI;KACpC,CAAC,CAAC,CAAC;AACR,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { PenaltySchedule } from "@sharadox/account-web-library/ban-length/type";
2
+ /** A public rule as an application declares it. */
3
+ export interface RuleDeclaration {
4
+ code: string;
5
+ /** In each language: `{ en, pt }`. */
6
+ title: Record<string, string>;
7
+ description: Record<string, string>;
8
+ /** Penalties for the 1st, 2nd… offense: seconds, or "permanent"; the last repeats. */
9
+ schedule: PenaltySchedule;
10
+ }
11
+ /** A rule's newest version, as `/rules` shows it. */
12
+ export interface PublishedRule extends RuleDeclaration {
13
+ version: number;
14
+ /** For every application. */
15
+ global: boolean;
16
+ }
17
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAErF,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,sFAAsF;IACtF,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/rule-sync/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
2
+ import type { SecondFactorFinish, SecondFactorFinishResult } from "@sharadox/account-web-library/second-factor-finish/type";
3
+ /**
4
+ * The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
5
+ * recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
6
+ * per address group. The session is marked as having passed two-factor. After a recovery code or on a new browser,
7
+ * call `notify` after answering, to tell every contact.
8
+ *
9
+ * @example
10
+ * const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
11
+ */
12
+ export declare function finishSecondFactor(server: AccountServer, { ticket, code, address, token, userAgent, now }: SecondFactorFinish): Promise<SecondFactorFinishResult>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAOvF,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,yDAAyD,CAAC;AAIjE;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,kBAAkB,GACvF,OAAO,CAAC,wBAAwB,CAAC,CAqEnC"}
@@ -0,0 +1,90 @@
1
+ import { addressGroup } from "@sharadox/protection-web-library/address-group";
2
+ import { limitRate } from "@sharadox/protection-web-library/rate-limit";
3
+ import { accountTables, signInLimits } from "@sharadox/account-web-library/account-server";
4
+ import { signIn } from "@sharadox/account-web-library/account-sign-in";
5
+ import { notifyAccount } from "@sharadox/account-web-library/account-notice";
6
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
7
+ import { recoveryCodeHash } from "@sharadox/account-web-library/recovery-code-store";
8
+ import { decryptSecret } from "@sharadox/account-web-library/secret-encryption";
9
+ import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
10
+ import { readTicket } from "@sharadox/account-web-library/signed-ticket";
11
+ import { verifyTotp } from "@sharadox/account-web-library/totp";
12
+ /**
13
+ * The two-factor step of signing in: the authenticator app's code (never the same step twice) or a single-use
14
+ * recovery code, after the emailed code passed (`finishSignIn` gave the ticket). Guesses are limited per account and
15
+ * per address group. The session is marked as having passed two-factor. After a recovery code or on a new browser,
16
+ * call `notify` after answering, to tell every contact.
17
+ *
18
+ * @example
19
+ * const result = await finishSecondFactor(server, { ticket, code, address, token: cookie });
20
+ */
21
+ export async function finishSecondFactor(server, { ticket, code, address, token, userAgent = null, now = Date.now() }) {
22
+ const reading = readTicket(ticket, {
23
+ secret: deriveSecret(server.secret, "second-factor-ticket"),
24
+ purpose: "second-factor",
25
+ now,
26
+ });
27
+ if (!reading.valid)
28
+ return { status: "refused", reason: "ticket" };
29
+ const { accountId } = reading.data;
30
+ const limits = signInLimits(server);
31
+ const rate = await limitRate(server.database, [
32
+ { key: `second-factor:${accountId}`, rule: limits.secondFactorPerAccount },
33
+ { key: `verification:${addressGroup(address)}`, rule: limits.verificationsPerAddress },
34
+ ], { secret: deriveSecret(server.secret, "rate-limit"), now });
35
+ if (!rate.allowed)
36
+ return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
37
+ const passed = await accountTables(server)
38
+ .transaction()
39
+ .execute(async (transaction) => {
40
+ const credential = await transaction
41
+ .selectFrom("totp_credential")
42
+ .select(["id", "secret_ciphertext", "last_used_step"])
43
+ .where("account_id", "=", accountId)
44
+ .where("confirmed_at", "is not", null)
45
+ .forUpdate()
46
+ .executeTakeFirst();
47
+ // Two-factor was turned off since the emailed code passed: that code is the proof.
48
+ if (!credential)
49
+ return "passed";
50
+ const typed = code.replace(/\s/g, "");
51
+ const secret = decryptSecret(credential.secret_ciphertext, deriveSecret(server.secret, "totp-encryption"));
52
+ // Confirming the setup stored a step, so a confirmed credential always has one.
53
+ const lastUsedStep = Number(credential.last_used_step);
54
+ const verification = verifyTotp(secret, typed, now, { lastUsedStep });
55
+ if (verification.valid) {
56
+ await transaction
57
+ .updateTable("totp_credential")
58
+ .set({ last_used_step: verification.step })
59
+ .where("id", "=", credential.id)
60
+ .execute();
61
+ return "passed";
62
+ }
63
+ const used = await transaction
64
+ .updateTable("recovery_code")
65
+ .set({ used_at: new Date(now) })
66
+ .where("account_id", "=", accountId)
67
+ .where("code_hash", "=", recoveryCodeHash(code, { accountId, pepper: deriveSecret(server.secret, "recovery-code") }))
68
+ .where("used_at", "is", null)
69
+ .executeTakeFirst();
70
+ if (used.numUpdatedRows === 0n)
71
+ return "wrong";
72
+ await recordAuditEvent(transaction, { accountId, action: "second-factor.recovery-code-used", now });
73
+ return "recovery";
74
+ });
75
+ if (passed === "wrong")
76
+ return { status: "refused", reason: "wrong" };
77
+ const session = await signIn(server.database, { accountId, token, secondFactor: true, userAgent, now });
78
+ const notices = [
79
+ ...(passed === "recovery" ? [{ kind: "recovery-code-used" }] : []),
80
+ ...(session.newBrowser ? [{ kind: "new-sign-in", at: new Date(now) }] : []),
81
+ ];
82
+ if (notices.length === 0)
83
+ return { status: "signed-in", accountId, token: session.token };
84
+ const notify = async () => {
85
+ for (const notice of notices)
86
+ await notifyAccount(server, { accountId, notice });
87
+ };
88
+ return { status: "signed-in", accountId, token: session.token, notify };
89
+ }
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/second-factor-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE3F,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAK/E,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAqB,EACrB,EAAE,MA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AM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,30 @@
1
+ export interface SecondFactorFinish {
2
+ /** From `finishSignIn`'s `second-factor` answer. */
3
+ ticket: string;
4
+ /** The authenticator app's code, or a recovery code. */
5
+ code: string;
6
+ /** The client's IP address. */
7
+ address: string;
8
+ /** The browser's current session cookie, if any. */
9
+ token: string | undefined;
10
+ /** The browser's User-Agent, for the list of devices. */
11
+ userAgent?: string | null;
12
+ /** Milliseconds since 1970 (now by default). */
13
+ now?: number;
14
+ }
15
+ export type SecondFactorFinishResult =
16
+ /** `notify`, after a recovery code: tells every contact (call it after answering). */
17
+ {
18
+ status: "signed-in";
19
+ accountId: string;
20
+ token: string;
21
+ notify?: () => Promise<void>;
22
+ } | {
23
+ status: "refused";
24
+ reason: "ticket" | "wrong";
25
+ } | {
26
+ status: "refused";
27
+ reason: "rate-limit";
28
+ retryAfterSeconds: number;
29
+ };
30
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,wBAAwB;AAClC,sFAAsF;AACpF;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GACvF;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/second-factor-finish/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A separate 256-bit key for one purpose (`one-time-code`, `rate-limit`, `proof-of-work`, `sign-up-ticket`…),
3
+ * derived from the account server's one root secret with HKDF-SHA-256: one secret to keep, and a key leaked from one
4
+ * use reveals nothing about the others.
5
+ *
6
+ * @example
7
+ * const pepper = deriveSecret(process.env.ACCOUNT_SECRET!, "one-time-code");
8
+ */
9
+ export declare function deriveSecret(root: string, purpose: string): string;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/secret-derivation/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGlE"}
@@ -0,0 +1,15 @@
1
+ import { hkdfSync } from "node:crypto";
2
+ /**
3
+ * A separate 256-bit key for one purpose (`one-time-code`, `rate-limit`, `proof-of-work`, `sign-up-ticket`…),
4
+ * derived from the account server's one root secret with HKDF-SHA-256: one secret to keep, and a key leaked from one
5
+ * use reveals nothing about the others.
6
+ *
7
+ * @example
8
+ * const pepper = deriveSecret(process.env.ACCOUNT_SECRET!, "one-time-code");
9
+ */
10
+ export function deriveSecret(root, purpose) {
11
+ if (root.length < 32)
12
+ throw new Error("the account secret must have at least 32 characters");
13
+ return Buffer.from(hkdfSync("sha256", root, "", `sharadox-account:${purpose}`, 32)).toString("base64url");
14
+ }
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/secret-derivation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAe;IACxD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC7F,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,oBAAoB,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC5G,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Encrypts a secret for storing in the database (a TOTP secret) with AES-256-GCM under a key kept outside it
3
+ * (`deriveSecret(ACCOUNT_SECRET, "totp-encryption")`), so a leaked database dump reveals nothing. A fresh random IV
4
+ * every time; the result is text: `v1.<iv>.<ciphertext and tag>`.
5
+ *
6
+ * @example
7
+ * const sealed = encryptSecret(secret, deriveSecret(server.secret, "totp-encryption"));
8
+ */
9
+ export declare function encryptSecret(secret: Uint8Array, key: string): string;
10
+ /**
11
+ * Decrypts what `encryptSecret` made; throws for a wrong key or anything changed.
12
+ *
13
+ * @example
14
+ * const secret = decryptSecret(row.secret_ciphertext, key);
15
+ */
16
+ export declare function decryptSecret(sealed: string, key: string): Uint8Array;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/secret-encryption/index.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAOrE"}
@@ -0,0 +1,37 @@
1
+ import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
2
+ const VERSION = "v1";
3
+ const keyBytes = (key) => {
4
+ if (key.length < 32)
5
+ throw new Error("the encryption key must have at least 32 characters");
6
+ return createHash("sha256").update(key).digest();
7
+ };
8
+ /**
9
+ * Encrypts a secret for storing in the database (a TOTP secret) with AES-256-GCM under a key kept outside it
10
+ * (`deriveSecret(ACCOUNT_SECRET, "totp-encryption")`), so a leaked database dump reveals nothing. A fresh random IV
11
+ * every time; the result is text: `v1.<iv>.<ciphertext and tag>`.
12
+ *
13
+ * @example
14
+ * const sealed = encryptSecret(secret, deriveSecret(server.secret, "totp-encryption"));
15
+ */
16
+ export function encryptSecret(secret, key) {
17
+ const iv = randomBytes(12);
18
+ const cipher = createCipheriv("aes-256-gcm", keyBytes(key), iv);
19
+ const body = Buffer.concat([cipher.update(secret), cipher.final(), cipher.getAuthTag()]);
20
+ return `${VERSION}.${iv.toString("base64url")}.${body.toString("base64url")}`;
21
+ }
22
+ /**
23
+ * Decrypts what `encryptSecret` made; throws for a wrong key or anything changed.
24
+ *
25
+ * @example
26
+ * const secret = decryptSecret(row.secret_ciphertext, key);
27
+ */
28
+ export function decryptSecret(sealed, key) {
29
+ const [version, iv, body] = sealed.split(".");
30
+ if (version !== VERSION || !iv || !body)
31
+ throw new Error("unknown encrypted secret format");
32
+ const bytes = Buffer.from(body, "base64url");
33
+ const decipher = createDecipheriv("aes-256-gcm", keyBytes(key), Buffer.from(iv, "base64url"));
34
+ decipher.setAuthTag(bytes.subarray(-16));
35
+ return new Uint8Array(Buffer.concat([decipher.update(bytes.subarray(0, -16)), decipher.final()]));
36
+ }
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/secret-encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE;IAC/B,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC5F,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,GAAW;IAC3D,MAAM,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACzF,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAChF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,GAAW;IACvD,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC5F,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9F,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AACpG,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Deletes account sessions past their end or idle longer than `idleSeconds` (7 days by default, as
5
+ * `readBrowserSession`), then browser sessions that ended or hold no account; from a daily job. Returns the counts.
6
+ *
7
+ * @example
8
+ * await pruneSessions(database);
9
+ */
10
+ export declare function pruneSessions(database: Kysely<AccountDatabase>, { idleSeconds, now }?: {
11
+ idleSeconds?: number;
12
+ now?: number;
13
+ }): Promise<{
14
+ accountSessions: number;
15
+ browserSessions: number;
16
+ }>;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/session-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,WAAwB,EAAE,GAAgB,EAAE,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1F,OAAO,CAAC;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CA4B/D"}
@@ -0,0 +1,30 @@
1
+ import { sql } from "kysely";
2
+ /**
3
+ * Deletes account sessions past their end or idle longer than `idleSeconds` (7 days by default, as
4
+ * `readBrowserSession`), then browser sessions that ended or hold no account; from a daily job. Returns the counts.
5
+ *
6
+ * @example
7
+ * await pruneSessions(database);
8
+ */
9
+ export async function pruneSessions(database, { idleSeconds = 7 * 86_400, now = Date.now() } = {}) {
10
+ const at = new Date(now);
11
+ const accountSessions = await database
12
+ .deleteFrom("account_session")
13
+ .where((where) => where.or([where("expires_at", "<=", at), where("last_seen_at", "<=", new Date(now - idleSeconds * 1000))]))
14
+ .executeTakeFirst();
15
+ const browserSessions = await database
16
+ .deleteFrom("browser_session")
17
+ .where((where) => where.or([
18
+ where("expires_at", "<=", at),
19
+ where.not(where.exists(where
20
+ .selectFrom("account_session")
21
+ .select(sql `1`.as("one"))
22
+ .whereRef("account_session.browser_session_id", "=", "browser_session.id"))),
23
+ ]))
24
+ .executeTakeFirst();
25
+ return {
26
+ accountSessions: Number(accountSessions.numDeletedRows),
27
+ browserSessions: Number(browserSessions.numDeletedRows),
28
+ };
29
+ }
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/session-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAG1C;;;;;;GAMG;AACH,MAAM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table gives
3
+ * no sessions. A plain SHA-256 is enough for tokens this random.
4
+ *
5
+ * @example
6
+ * const { token, hash } = createSessionToken();
7
+ */
8
+ export declare function createSessionToken(): {
9
+ token: string;
10
+ hash: string;
11
+ };
12
+ /**
13
+ * The stored form of a session token.
14
+ *
15
+ * @example
16
+ * hashSessionToken(cookie); // compare with browser_session.token_hash
17
+ */
18
+ export declare function hashSessionToken(token: string): string;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/session-token/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAGpE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD"}
@@ -0,0 +1,22 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ /**
3
+ * A new session token (256 random bits, base64url) for a cookie, and the hash to store instead: a leaked table gives
4
+ * no sessions. A plain SHA-256 is enough for tokens this random.
5
+ *
6
+ * @example
7
+ * const { token, hash } = createSessionToken();
8
+ */
9
+ export function createSessionToken() {
10
+ const token = randomBytes(32).toString("base64url");
11
+ return { token, hash: hashSessionToken(token) };
12
+ }
13
+ /**
14
+ * The stored form of a session token.
15
+ *
16
+ * @example
17
+ * hashSessionToken(cookie); // compare with browser_session.token_hash
18
+ */
19
+ export function hashSessionToken(token) {
20
+ return createHash("sha256").update(token).digest("base64url");
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/session-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
2
+ import type { SignInFinish, SignInFinishResult } from "@sharadox/account-web-library/sign-in-finish/type";
3
+ /**
4
+ * The second step: the typed code. Guesses are limited per address group (and per request by `verifyCode`). With the
5
+ * right code, an account with that contact is signed in (or, with two-factor on, gets a ticket for that step); on a new browser, call `notify` after answering to tell
6
+ * every email on the browser (the new token goes in its cookie); a contact
7
+ * with no account gets a sign-up ticket for choosing an identifier.
8
+ *
9
+ * @example
10
+ * const result = await finishSignIn(server, { requestId, code, address, token: cookie });
11
+ */
12
+ export declare function finishSignIn(server: AccountServer, { requestId, code, address, token, userAgent, now }: SignInFinish): Promise<SignInFinishResult>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/sign-in-finish/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAO1G;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,GAAgB,EAAE,EAAE,YAAY,GACpF,OAAO,CAAC,kBAAkB,CAAC,CAoD7B"}
@@ -0,0 +1,69 @@
1
+ import { addressGroup } from "@sharadox/protection-web-library/address-group";
2
+ import { limitRate } from "@sharadox/protection-web-library/rate-limit";
3
+ import { notifyAccount } from "@sharadox/account-web-library/account-notice";
4
+ import { signIn } from "@sharadox/account-web-library/account-sign-in";
5
+ import { signInLimits } from "@sharadox/account-web-library/account-server";
6
+ import { verifyCode } from "@sharadox/account-web-library/code-verification";
7
+ import { findAccountByContact } from "@sharadox/account-web-library/contact-lookup";
8
+ import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
9
+ import { createTicket } from "@sharadox/account-web-library/signed-ticket";
10
+ /** How long a sign-up ticket lasts: time to choose an identifier. */
11
+ const SIGN_UP_SECONDS = 900;
12
+ /** How long the two-factor step may take once the emailed code passed. */
13
+ const SECOND_FACTOR_SECONDS = 600;
14
+ /**
15
+ * The second step: the typed code. Guesses are limited per address group (and per request by `verifyCode`). With the
16
+ * right code, an account with that contact is signed in (or, with two-factor on, gets a ticket for that step); on a new browser, call `notify` after answering to tell
17
+ * every email on the browser (the new token goes in its cookie); a contact
18
+ * with no account gets a sign-up ticket for choosing an identifier.
19
+ *
20
+ * @example
21
+ * const result = await finishSignIn(server, { requestId, code, address, token: cookie });
22
+ */
23
+ export async function finishSignIn(server, { requestId, code, address, token, userAgent = null, now = Date.now() }) {
24
+ const rate = await limitRate(server.database, [{ key: `verification:${addressGroup(address)}`, rule: signInLimits(server).verificationsPerAddress }], { secret: deriveSecret(server.secret, "rate-limit"), now });
25
+ if (!rate.allowed)
26
+ return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
27
+ const verification = await verifyCode(server.database, {
28
+ requestId,
29
+ code,
30
+ purpose: "sign-in",
31
+ pepper: deriveSecret(server.secret, "one-time-code"),
32
+ now,
33
+ });
34
+ if (!verification.valid)
35
+ return { status: "refused", reason: verification.reason };
36
+ const found = await findAccountByContact(server.database, verification.contact);
37
+ if (!found) {
38
+ const ticket = createTicket({ contact: verification.contact }, {
39
+ secret: deriveSecret(server.secret, "sign-up-ticket"),
40
+ purpose: "sign-up",
41
+ lifetimeSeconds: SIGN_UP_SECONDS,
42
+ now,
43
+ });
44
+ return { status: "sign-up", ticket };
45
+ }
46
+ if (!found.signIn)
47
+ return { status: "refused", reason: "unknown" };
48
+ const secondFactor = await server.database
49
+ .selectFrom("totp_credential")
50
+ .select("id")
51
+ .where("account_id", "=", found.accountId)
52
+ .where("confirmed_at", "is not", null)
53
+ .executeTakeFirst();
54
+ if (secondFactor) {
55
+ const ticket = createTicket({ accountId: found.accountId }, {
56
+ secret: deriveSecret(server.secret, "second-factor-ticket"),
57
+ purpose: "second-factor",
58
+ lifetimeSeconds: SECOND_FACTOR_SECONDS,
59
+ now,
60
+ });
61
+ return { status: "second-factor", ticket };
62
+ }
63
+ const session = await signIn(server.database, { accountId: found.accountId, token, userAgent, now });
64
+ if (!session.newBrowser)
65
+ return { status: "signed-in", accountId: found.accountId, token: session.token };
66
+ const notify = () => notifyAccount(server, { accountId: found.accountId, notice: { kind: "new-sign-in", at: new Date(now) } });
67
+ return { status: "signed-in", accountId: found.accountId, token: session.token, notify };
68
+ }
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/sign-in-finish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CA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