@oxyhq/services 5.17.16 → 5.17.18

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 (403) hide show
  1. package/README.md +32 -38
  2. package/lib/commonjs/core/CrossDomainAuth.js +277 -0
  3. package/lib/commonjs/core/CrossDomainAuth.js.map +1 -0
  4. package/lib/commonjs/core/HttpService.js +82 -15
  5. package/lib/commonjs/core/HttpService.js.map +1 -1
  6. package/lib/commonjs/core/OxyServices.base.js +11 -3
  7. package/lib/commonjs/core/OxyServices.base.js.map +1 -1
  8. package/lib/commonjs/core/OxyServices.js +4 -1
  9. package/lib/commonjs/core/OxyServices.js.map +1 -1
  10. package/lib/commonjs/core/index.js +30 -0
  11. package/lib/commonjs/core/index.js.map +1 -1
  12. package/lib/commonjs/core/mixins/OxyServices.assets.js +16 -3
  13. package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -1
  14. package/lib/commonjs/core/mixins/OxyServices.auth.js +73 -32
  15. package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -1
  16. package/lib/commonjs/core/mixins/OxyServices.fedcm.js +289 -0
  17. package/lib/commonjs/core/mixins/OxyServices.fedcm.js.map +1 -0
  18. package/lib/commonjs/core/mixins/OxyServices.popup.js +352 -0
  19. package/lib/commonjs/core/mixins/OxyServices.popup.js.map +1 -0
  20. package/lib/commonjs/core/mixins/OxyServices.redirect.js +378 -0
  21. package/lib/commonjs/core/mixins/OxyServices.redirect.js.map +1 -0
  22. package/lib/commonjs/core/mixins/OxyServices.user.js +35 -24
  23. package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -1
  24. package/lib/commonjs/core/mixins/index.js +27 -15
  25. package/lib/commonjs/core/mixins/index.js.map +1 -1
  26. package/lib/commonjs/crypto/index.js +30 -0
  27. package/lib/commonjs/crypto/index.js.map +1 -1
  28. package/lib/commonjs/crypto/keyManager.js +902 -0
  29. package/lib/commonjs/crypto/keyManager.js.map +1 -0
  30. package/lib/commonjs/crypto/polyfill.js +14 -5
  31. package/lib/commonjs/crypto/polyfill.js.map +1 -1
  32. package/lib/commonjs/crypto/recoveryPhrase.js +152 -0
  33. package/lib/commonjs/crypto/recoveryPhrase.js.map +1 -0
  34. package/lib/commonjs/crypto/signatureService.js +289 -0
  35. package/lib/commonjs/crypto/signatureService.js.map +1 -0
  36. package/lib/commonjs/i18n/locales/en-US.json +1 -1
  37. package/lib/commonjs/index.js +40 -26
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/commonjs/models/interfaces.js +0 -15
  40. package/lib/commonjs/models/interfaces.js.map +1 -1
  41. package/lib/commonjs/ui/components/BottomSheetRouter.js +9 -1
  42. package/lib/commonjs/ui/components/BottomSheetRouter.js.map +1 -1
  43. package/lib/commonjs/ui/components/Icon.js.map +1 -1
  44. package/lib/commonjs/ui/components/IconButton/utils.js.map +1 -1
  45. package/lib/commonjs/ui/components/OxyProvider.js +41 -11
  46. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  47. package/lib/commonjs/ui/components/TextField/Adornment/utils.js.map +1 -1
  48. package/lib/commonjs/ui/components/TextField/helpers.js.map +1 -1
  49. package/lib/commonjs/ui/components/TouchableRipple/utils.js.map +1 -1
  50. package/lib/commonjs/ui/components/Typography/AnimatedText.js.map +1 -1
  51. package/lib/commonjs/ui/context/OxyContext.js +110 -192
  52. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  53. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +150 -19
  54. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  55. package/lib/commonjs/ui/context/hooks/useSessionManagement.js +279 -0
  56. package/lib/commonjs/ui/context/hooks/useSessionManagement.js.map +1 -0
  57. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +78 -64
  58. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  59. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +38 -51
  60. package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
  61. package/lib/commonjs/ui/hooks/queries/useSecurityQueries.js +3 -3
  62. package/lib/commonjs/ui/hooks/queries/useSecurityQueries.js.map +1 -1
  63. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +18 -12
  64. package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -1
  65. package/lib/commonjs/ui/hooks/useProfileEditing.js +3 -5
  66. package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
  67. package/lib/commonjs/ui/hooks/useSessionManagement.js +4 -8
  68. package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -1
  69. package/lib/commonjs/ui/hooks/useSessionSocket.js +162 -315
  70. package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
  71. package/lib/commonjs/ui/hooks/useStorage.js +24 -58
  72. package/lib/commonjs/ui/hooks/useStorage.js.map +1 -1
  73. package/lib/commonjs/ui/index.js +50 -21
  74. package/lib/commonjs/ui/index.js.map +1 -1
  75. package/lib/commonjs/ui/navigation/routes.js +5 -1
  76. package/lib/commonjs/ui/navigation/routes.js.map +1 -1
  77. package/lib/commonjs/ui/screens/AccountCenterScreen.js +2 -2
  78. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
  79. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
  80. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +29 -24
  81. package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
  82. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +3 -3
  83. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
  84. package/lib/commonjs/ui/screens/OxyAuthScreen.js +134 -66
  85. package/lib/commonjs/ui/screens/OxyAuthScreen.js.map +1 -1
  86. package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +6 -13
  87. package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
  88. package/lib/commonjs/ui/stores/accountStore.js +2 -4
  89. package/lib/commonjs/ui/stores/accountStore.js.map +1 -1
  90. package/lib/commonjs/ui/stores/authStore.js +45 -32
  91. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  92. package/lib/commonjs/ui/styles/spacing.js +54 -2
  93. package/lib/commonjs/ui/styles/spacing.js.map +1 -1
  94. package/lib/commonjs/ui/utils/avatarUtils.js +37 -41
  95. package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
  96. package/lib/commonjs/ui/utils/storageHelpers.js.map +1 -1
  97. package/lib/commonjs/utils/errorUtils.js +13 -0
  98. package/lib/commonjs/utils/errorUtils.js.map +1 -1
  99. package/lib/commonjs/utils/validationUtils.js +15 -1
  100. package/lib/commonjs/utils/validationUtils.js.map +1 -1
  101. package/lib/module/core/CrossDomainAuth.js +271 -0
  102. package/lib/module/core/CrossDomainAuth.js.map +1 -0
  103. package/lib/module/core/HttpService.js +82 -15
  104. package/lib/module/core/HttpService.js.map +1 -1
  105. package/lib/module/core/OxyServices.base.js +11 -4
  106. package/lib/module/core/OxyServices.base.js.map +1 -1
  107. package/lib/module/core/OxyServices.js +4 -1
  108. package/lib/module/core/OxyServices.js.map +1 -1
  109. package/lib/module/core/index.js +6 -1
  110. package/lib/module/core/index.js.map +1 -1
  111. package/lib/module/core/mixins/OxyServices.assets.js +16 -3
  112. package/lib/module/core/mixins/OxyServices.assets.js.map +1 -1
  113. package/lib/module/core/mixins/OxyServices.auth.js +73 -32
  114. package/lib/module/core/mixins/OxyServices.auth.js.map +1 -1
  115. package/lib/module/core/mixins/OxyServices.fedcm.js +286 -0
  116. package/lib/module/core/mixins/OxyServices.fedcm.js.map +1 -0
  117. package/lib/module/core/mixins/OxyServices.popup.js +349 -0
  118. package/lib/module/core/mixins/OxyServices.popup.js.map +1 -0
  119. package/lib/module/core/mixins/OxyServices.redirect.js +375 -0
  120. package/lib/module/core/mixins/OxyServices.redirect.js.map +1 -0
  121. package/lib/module/core/mixins/OxyServices.user.js +35 -24
  122. package/lib/module/core/mixins/OxyServices.user.js.map +1 -1
  123. package/lib/module/core/mixins/index.js +15 -3
  124. package/lib/module/core/mixins/index.js.map +1 -1
  125. package/lib/module/crypto/index.js +8 -4
  126. package/lib/module/crypto/index.js.map +1 -1
  127. package/lib/module/crypto/keyManager.js +899 -0
  128. package/lib/module/crypto/keyManager.js.map +1 -0
  129. package/lib/module/crypto/polyfill.js +6 -5
  130. package/lib/module/crypto/polyfill.js.map +1 -1
  131. package/lib/module/crypto/recoveryPhrase.js +147 -0
  132. package/lib/module/crypto/recoveryPhrase.js.map +1 -0
  133. package/lib/module/crypto/signatureService.js +286 -0
  134. package/lib/module/crypto/signatureService.js.map +1 -0
  135. package/lib/module/i18n/locales/en-US.json +1 -1
  136. package/lib/module/index.js +6 -9
  137. package/lib/module/index.js.map +1 -1
  138. package/lib/module/models/interfaces.js +0 -15
  139. package/lib/module/models/interfaces.js.map +1 -1
  140. package/lib/module/ui/components/BottomSheetRouter.js +6 -2
  141. package/lib/module/ui/components/BottomSheetRouter.js.map +1 -1
  142. package/lib/module/ui/components/Icon.js.map +1 -1
  143. package/lib/module/ui/components/IconButton/utils.js.map +1 -1
  144. package/lib/module/ui/components/OxyProvider.js +41 -11
  145. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  146. package/lib/module/ui/components/TextField/Adornment/utils.js.map +1 -1
  147. package/lib/module/ui/components/TextField/helpers.js.map +1 -1
  148. package/lib/module/ui/components/TouchableRipple/utils.js.map +1 -1
  149. package/lib/module/ui/components/Typography/AnimatedText.js.map +1 -1
  150. package/lib/module/ui/context/OxyContext.js +112 -184
  151. package/lib/module/ui/context/OxyContext.js.map +1 -1
  152. package/lib/module/ui/context/hooks/useAuthOperations.js +150 -19
  153. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  154. package/lib/module/ui/context/hooks/useSessionManagement.js +274 -0
  155. package/lib/module/ui/context/hooks/useSessionManagement.js.map +1 -0
  156. package/lib/module/ui/hooks/mutations/useAccountMutations.js +79 -64
  157. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  158. package/lib/module/ui/hooks/queries/useAccountQueries.js +31 -44
  159. package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
  160. package/lib/module/ui/hooks/queries/useSecurityQueries.js +1 -1
  161. package/lib/module/ui/hooks/queries/useSecurityQueries.js.map +1 -1
  162. package/lib/module/ui/hooks/queries/useServicesQueries.js +13 -7
  163. package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -1
  164. package/lib/module/ui/hooks/useProfileEditing.js +3 -5
  165. package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
  166. package/lib/module/ui/hooks/useSessionManagement.js +4 -8
  167. package/lib/module/ui/hooks/useSessionManagement.js.map +1 -1
  168. package/lib/module/ui/hooks/useSessionSocket.js +162 -315
  169. package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
  170. package/lib/module/ui/hooks/useStorage.js +25 -59
  171. package/lib/module/ui/hooks/useStorage.js.map +1 -1
  172. package/lib/module/ui/index.js +15 -10
  173. package/lib/module/ui/index.js.map +1 -1
  174. package/lib/module/ui/navigation/routes.js +5 -1
  175. package/lib/module/ui/navigation/routes.js.map +1 -1
  176. package/lib/module/ui/screens/AccountCenterScreen.js +2 -2
  177. package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
  178. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
  179. package/lib/module/ui/screens/AccountSettingsScreen.js +29 -24
  180. package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
  181. package/lib/module/ui/screens/AccountSwitcherScreen.js +3 -3
  182. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
  183. package/lib/module/ui/screens/OxyAuthScreen.js +135 -68
  184. package/lib/module/ui/screens/OxyAuthScreen.js.map +1 -1
  185. package/lib/module/ui/screens/PrivacySettingsScreen.js +6 -13
  186. package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
  187. package/lib/module/ui/stores/accountStore.js +2 -4
  188. package/lib/module/ui/stores/accountStore.js.map +1 -1
  189. package/lib/module/ui/stores/authStore.js +45 -32
  190. package/lib/module/ui/stores/authStore.js.map +1 -1
  191. package/lib/module/ui/styles/spacing.js +6 -2
  192. package/lib/module/ui/styles/spacing.js.map +1 -1
  193. package/lib/module/ui/utils/avatarUtils.js +37 -40
  194. package/lib/module/ui/utils/avatarUtils.js.map +1 -1
  195. package/lib/module/ui/utils/storageHelpers.js.map +1 -1
  196. package/lib/module/utils/errorUtils.js +7 -0
  197. package/lib/module/utils/errorUtils.js.map +1 -1
  198. package/lib/module/utils/validationUtils.js +13 -0
  199. package/lib/module/utils/validationUtils.js.map +1 -1
  200. package/lib/typescript/core/CrossDomainAuth.d.ts +161 -0
  201. package/lib/typescript/core/CrossDomainAuth.d.ts.map +1 -0
  202. package/lib/typescript/core/HttpService.d.ts +1 -1
  203. package/lib/typescript/core/HttpService.d.ts.map +1 -1
  204. package/lib/typescript/core/OxyServices.base.d.ts +0 -6
  205. package/lib/typescript/core/OxyServices.base.d.ts.map +1 -1
  206. package/lib/typescript/core/OxyServices.d.ts +5 -36
  207. package/lib/typescript/core/OxyServices.d.ts.map +1 -1
  208. package/lib/typescript/core/index.d.ts +4 -0
  209. package/lib/typescript/core/index.d.ts.map +1 -1
  210. package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -1
  211. package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -1
  212. package/lib/typescript/core/mixins/OxyServices.auth.d.ts +40 -20
  213. package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -1
  214. package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -1
  215. package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -1
  216. package/lib/typescript/core/mixins/OxyServices.fedcm.d.ts +195 -0
  217. package/lib/typescript/core/mixins/OxyServices.fedcm.d.ts.map +1 -0
  218. package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -1
  219. package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -1
  220. package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -1
  221. package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -1
  222. package/lib/typescript/core/mixins/OxyServices.popup.d.ts +206 -0
  223. package/lib/typescript/core/mixins/OxyServices.popup.d.ts.map +1 -0
  224. package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -1
  225. package/lib/typescript/core/mixins/OxyServices.redirect.d.ts +246 -0
  226. package/lib/typescript/core/mixins/OxyServices.redirect.d.ts.map +1 -0
  227. package/lib/typescript/core/mixins/OxyServices.security.d.ts.map +1 -1
  228. package/lib/typescript/core/mixins/OxyServices.user.d.ts +6 -4
  229. package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
  230. package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -1
  231. package/lib/typescript/core/mixins/index.d.ts +220 -8
  232. package/lib/typescript/core/mixins/index.d.ts.map +1 -1
  233. package/lib/typescript/crypto/index.d.ts +6 -3
  234. package/lib/typescript/crypto/index.d.ts.map +1 -1
  235. package/lib/typescript/crypto/keyManager.d.ts +190 -0
  236. package/lib/typescript/crypto/keyManager.d.ts.map +1 -0
  237. package/lib/typescript/crypto/polyfill.d.ts +4 -3
  238. package/lib/typescript/crypto/polyfill.d.ts.map +1 -1
  239. package/lib/typescript/crypto/recoveryPhrase.d.ts +59 -0
  240. package/lib/typescript/crypto/recoveryPhrase.d.ts.map +1 -0
  241. package/lib/typescript/crypto/signatureService.d.ts +87 -0
  242. package/lib/typescript/crypto/signatureService.d.ts.map +1 -0
  243. package/lib/typescript/index.d.ts +5 -6
  244. package/lib/typescript/index.d.ts.map +1 -1
  245. package/lib/typescript/models/interfaces.d.ts +2 -14
  246. package/lib/typescript/models/interfaces.d.ts.map +1 -1
  247. package/lib/typescript/models/session.d.ts +0 -9
  248. package/lib/typescript/models/session.d.ts.map +1 -1
  249. package/lib/typescript/types/bip39.d.ts +32 -0
  250. package/lib/typescript/ui/components/BottomSheetRouter.d.ts +5 -0
  251. package/lib/typescript/ui/components/BottomSheetRouter.d.ts.map +1 -1
  252. package/lib/typescript/ui/components/IconButton/utils.d.ts +1 -1
  253. package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
  254. package/lib/typescript/ui/components/TextField/Addons/Outline.d.ts +2 -2
  255. package/lib/typescript/ui/components/TextField/Adornment/utils.d.ts +1 -1
  256. package/lib/typescript/ui/components/TextField/Adornment/utils.d.ts.map +1 -1
  257. package/lib/typescript/ui/components/TextField/helpers.d.ts +8 -8
  258. package/lib/typescript/ui/components/TextField/types.d.ts +1 -0
  259. package/lib/typescript/ui/components/TextField/types.d.ts.map +1 -1
  260. package/lib/typescript/ui/components/types.d.ts +4 -0
  261. package/lib/typescript/ui/components/types.d.ts.map +1 -1
  262. package/lib/typescript/ui/context/OxyContext.d.ts +57 -3
  263. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  264. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +10 -3
  265. package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  266. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts +41 -0
  267. package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts.map +1 -0
  268. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  269. package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
  270. package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
  271. package/lib/typescript/ui/hooks/useProfileEditing.d.ts.map +1 -1
  272. package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +1 -1
  273. package/lib/typescript/ui/hooks/useSessionSocket.d.ts +1 -2
  274. package/lib/typescript/ui/hooks/useSessionSocket.d.ts.map +1 -1
  275. package/lib/typescript/ui/hooks/useStorage.d.ts +3 -9
  276. package/lib/typescript/ui/hooks/useStorage.d.ts.map +1 -1
  277. package/lib/typescript/ui/index.d.ts +6 -2
  278. package/lib/typescript/ui/index.d.ts.map +1 -1
  279. package/lib/typescript/ui/navigation/routes.d.ts +1 -1
  280. package/lib/typescript/ui/navigation/routes.d.ts.map +1 -1
  281. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
  282. package/lib/typescript/ui/screens/OxyAuthScreen.d.ts +1 -1
  283. package/lib/typescript/ui/screens/OxyAuthScreen.d.ts.map +1 -1
  284. package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
  285. package/lib/typescript/ui/stores/accountStore.d.ts.map +1 -1
  286. package/lib/typescript/ui/stores/authStore.d.ts +8 -7
  287. package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
  288. package/lib/typescript/ui/styles/spacing.d.ts +5 -0
  289. package/lib/typescript/ui/styles/spacing.d.ts.map +1 -1
  290. package/lib/typescript/ui/types/navigation.d.ts +2 -1
  291. package/lib/typescript/ui/types/navigation.d.ts.map +1 -1
  292. package/lib/typescript/ui/utils/avatarUtils.d.ts +2 -13
  293. package/lib/typescript/ui/utils/avatarUtils.d.ts.map +1 -1
  294. package/lib/typescript/ui/utils/storageHelpers.d.ts +0 -3
  295. package/lib/typescript/ui/utils/storageHelpers.d.ts.map +1 -1
  296. package/lib/typescript/utils/errorUtils.d.ts +6 -0
  297. package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
  298. package/lib/typescript/utils/validationUtils.d.ts +8 -0
  299. package/lib/typescript/utils/validationUtils.d.ts.map +1 -1
  300. package/package.json +8 -7
  301. package/src/core/CrossDomainAuth.ts +307 -0
  302. package/src/core/HttpService.ts +99 -16
  303. package/src/core/OxyServices.base.ts +20 -3
  304. package/src/core/OxyServices.ts +7 -3
  305. package/src/core/index.ts +9 -1
  306. package/src/core/mixins/OxyServices.assets.ts +14 -3
  307. package/src/core/mixins/OxyServices.auth.ts +105 -36
  308. package/src/core/mixins/OxyServices.fedcm.ts +315 -0
  309. package/src/core/mixins/OxyServices.popup.ts +402 -0
  310. package/src/core/mixins/OxyServices.redirect.ts +397 -0
  311. package/src/core/mixins/OxyServices.user.ts +39 -24
  312. package/src/core/mixins/index.ts +19 -3
  313. package/src/crypto/index.ts +16 -5
  314. package/src/crypto/keyManager.ts +966 -0
  315. package/src/crypto/polyfill.ts +6 -5
  316. package/src/crypto/recoveryPhrase.ts +166 -0
  317. package/src/crypto/signatureService.ts +323 -0
  318. package/src/i18n/locales/en-US.json +1 -1
  319. package/src/index.ts +19 -15
  320. package/src/models/interfaces.ts +4 -16
  321. package/src/models/session.ts +2 -11
  322. package/src/types/bip39.d.ts +32 -0
  323. package/src/ui/components/BottomSheetRouter.tsx +6 -1
  324. package/src/ui/components/Icon.tsx +1 -1
  325. package/src/ui/components/IconButton/utils.ts +1 -1
  326. package/src/ui/components/OxyProvider.tsx +44 -12
  327. package/src/ui/components/TextField/Addons/Outline.tsx +2 -2
  328. package/src/ui/components/TextField/Adornment/utils.ts +2 -2
  329. package/src/ui/components/TextField/helpers.tsx +10 -10
  330. package/src/ui/components/TextField/types.tsx +1 -1
  331. package/src/ui/components/TouchableRipple/utils.ts +2 -2
  332. package/src/ui/components/Typography/AnimatedText.tsx +2 -2
  333. package/src/ui/components/types.tsx +6 -0
  334. package/src/ui/context/OxyContext.tsx +173 -185
  335. package/src/ui/context/hooks/useAuthOperations.ts +177 -36
  336. package/src/ui/context/hooks/useSessionManagement.ts +399 -0
  337. package/src/ui/hooks/mutations/useAccountMutations.ts +82 -65
  338. package/src/ui/hooks/queries/useAccountQueries.ts +29 -35
  339. package/src/ui/hooks/queries/useSecurityQueries.ts +1 -1
  340. package/src/ui/hooks/queries/useServicesQueries.ts +14 -6
  341. package/src/ui/hooks/useProfileEditing.ts +3 -3
  342. package/src/ui/hooks/useSessionManagement.ts +5 -10
  343. package/src/ui/hooks/useSessionSocket.ts +46 -175
  344. package/src/ui/hooks/useStorage.ts +24 -76
  345. package/src/ui/index.ts +22 -13
  346. package/src/ui/navigation/routes.ts +6 -2
  347. package/src/ui/screens/AccountCenterScreen.tsx +2 -2
  348. package/src/ui/screens/AccountOverviewScreen.tsx +1 -1
  349. package/src/ui/screens/AccountSettingsScreen.tsx +34 -37
  350. package/src/ui/screens/AccountSwitcherScreen.tsx +4 -4
  351. package/src/ui/screens/OxyAuthScreen.tsx +138 -64
  352. package/src/ui/screens/PrivacySettingsScreen.tsx +6 -12
  353. package/src/ui/stores/accountStore.ts +1 -11
  354. package/src/ui/stores/authStore.ts +43 -44
  355. package/src/ui/styles/spacing.ts +15 -2
  356. package/src/ui/types/navigation.ts +2 -2
  357. package/src/ui/utils/avatarUtils.ts +39 -46
  358. package/src/ui/utils/storageHelpers.ts +0 -4
  359. package/src/utils/__tests__/validationUtils.test.ts +16 -1
  360. package/src/utils/errorUtils.ts +8 -1
  361. package/src/utils/validationUtils.ts +12 -0
  362. package/lib/commonjs/core/services/SessionService.js +0 -163
  363. package/lib/commonjs/core/services/SessionService.js.map +0 -1
  364. package/lib/commonjs/core/services/TokenService.js +0 -220
  365. package/lib/commonjs/core/services/TokenService.js.map +0 -1
  366. package/lib/commonjs/crypto/types.js +0 -2
  367. package/lib/commonjs/crypto/types.js.map +0 -1
  368. package/lib/commonjs/ui/context/OxyContextBase.js +0 -21
  369. package/lib/commonjs/ui/context/OxyContextBase.js.map +0 -1
  370. package/lib/commonjs/ui/context/hooks/useStorage.js +0 -79
  371. package/lib/commonjs/ui/context/hooks/useStorage.js.map +0 -1
  372. package/lib/commonjs/ui/hooks/useAvatarPicker.js +0 -56
  373. package/lib/commonjs/ui/hooks/useAvatarPicker.js.map +0 -1
  374. package/lib/module/core/services/SessionService.js +0 -159
  375. package/lib/module/core/services/SessionService.js.map +0 -1
  376. package/lib/module/core/services/TokenService.js +0 -217
  377. package/lib/module/core/services/TokenService.js.map +0 -1
  378. package/lib/module/crypto/types.js +0 -2
  379. package/lib/module/crypto/types.js.map +0 -1
  380. package/lib/module/ui/context/OxyContextBase.js +0 -16
  381. package/lib/module/ui/context/OxyContextBase.js.map +0 -1
  382. package/lib/module/ui/context/hooks/useStorage.js +0 -74
  383. package/lib/module/ui/context/hooks/useStorage.js.map +0 -1
  384. package/lib/module/ui/hooks/useAvatarPicker.js +0 -50
  385. package/lib/module/ui/hooks/useAvatarPicker.js.map +0 -1
  386. package/lib/typescript/core/services/SessionService.d.ts +0 -78
  387. package/lib/typescript/core/services/SessionService.d.ts.map +0 -1
  388. package/lib/typescript/core/services/TokenService.d.ts +0 -72
  389. package/lib/typescript/core/services/TokenService.d.ts.map +0 -1
  390. package/lib/typescript/crypto/types.d.ts +0 -22
  391. package/lib/typescript/crypto/types.d.ts.map +0 -1
  392. package/lib/typescript/ui/context/OxyContextBase.d.ts +0 -63
  393. package/lib/typescript/ui/context/OxyContextBase.d.ts.map +0 -1
  394. package/lib/typescript/ui/context/hooks/useStorage.d.ts +0 -22
  395. package/lib/typescript/ui/context/hooks/useStorage.d.ts.map +0 -1
  396. package/lib/typescript/ui/hooks/useAvatarPicker.d.ts +0 -19
  397. package/lib/typescript/ui/hooks/useAvatarPicker.d.ts.map +0 -1
  398. package/src/core/services/SessionService.ts +0 -173
  399. package/src/core/services/TokenService.ts +0 -237
  400. package/src/crypto/types.ts +0 -23
  401. package/src/ui/context/OxyContextBase.tsx +0 -78
  402. package/src/ui/context/hooks/useStorage.ts +0 -104
  403. package/src/ui/hooks/useAvatarPicker.ts +0 -61
@@ -0,0 +1,966 @@
1
+ /**
2
+ * Key Manager - ECDSA secp256k1 Key Generation and Storage
3
+ *
4
+ * Handles secure generation, storage, and retrieval of cryptographic keys.
5
+ * Private keys are stored securely using expo-secure-store and never leave the device.
6
+ */
7
+
8
+ import { ec as EC } from 'elliptic';
9
+ import type { ECKeyPair } from 'elliptic';
10
+ import { Platform } from 'react-native';
11
+
12
+ // Lazy imports for React Native specific modules
13
+ let SecureStore: typeof import('expo-secure-store') | null = null;
14
+ let ExpoCrypto: typeof import('expo-crypto') | null = null;
15
+
16
+ const ec = new EC('secp256k1');
17
+
18
+ const STORAGE_KEYS = {
19
+ PRIVATE_KEY: 'oxy_identity_private_key',
20
+ PUBLIC_KEY: 'oxy_identity_public_key',
21
+ BACKUP_PRIVATE_KEY: 'oxy_identity_backup_private_key',
22
+ BACKUP_PUBLIC_KEY: 'oxy_identity_backup_public_key',
23
+ BACKUP_TIMESTAMP: 'oxy_identity_backup_timestamp',
24
+ // Shared keys accessible across all Oxy apps (iOS Keychain Group / Android Account Manager)
25
+ SHARED_PRIVATE_KEY: 'oxy_shared_identity_private_key',
26
+ SHARED_PUBLIC_KEY: 'oxy_shared_identity_public_key',
27
+ SHARED_SESSION_TOKEN: 'oxy_shared_session_token',
28
+ SHARED_SESSION_ID: 'oxy_shared_session_id',
29
+ } as const;
30
+
31
+ /**
32
+ * iOS Keychain Access Group for sharing identities across Oxy apps
33
+ * All Oxy apps must have this access group enabled in their entitlements
34
+ * Format: [Team ID].com.oxy.shared or group.com.oxy.shared
35
+ */
36
+ const IOS_KEYCHAIN_GROUP = 'group.com.oxy.shared';
37
+
38
+ /**
39
+ * Android Account Manager type for shared authentication
40
+ * Used with sharedUserId to share sessions across apps
41
+ */
42
+ const ANDROID_ACCOUNT_TYPE = 'com.oxy.account';
43
+
44
+ /**
45
+ * Initialize React Native specific modules
46
+ * This allows the module to work in both Node.js and React Native environments
47
+ */
48
+ async function initSecureStore(): Promise<typeof import('expo-secure-store')> {
49
+ if (!SecureStore) {
50
+ try {
51
+ SecureStore = await import('expo-secure-store');
52
+ } catch (error) {
53
+ const errorMessage = error instanceof Error ? error.message : String(error);
54
+ throw new Error(`Failed to load expo-secure-store: ${errorMessage}. Make sure expo-secure-store is installed and properly configured.`);
55
+ }
56
+ }
57
+ if (!SecureStore) {
58
+ throw new Error('expo-secure-store module is not available');
59
+ }
60
+ return SecureStore;
61
+ }
62
+
63
+ /**
64
+ * Check if we're in a React Native environment
65
+ */
66
+ function isReactNative(): boolean {
67
+ return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
68
+ }
69
+
70
+ /**
71
+ * Check if we're in a Node.js environment
72
+ */
73
+ function isNodeJS(): boolean {
74
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
75
+ }
76
+
77
+ /**
78
+ * Check if we're on web platform
79
+ * Identity storage is only available on native platforms (iOS/Android)
80
+ */
81
+ function isWebPlatform(): boolean {
82
+ try {
83
+ return Platform.OS === 'web';
84
+ } catch {
85
+ // Fallback if Platform is not available
86
+ return typeof window !== 'undefined' && typeof navigator !== 'undefined' && navigator.product !== 'ReactNative';
87
+ }
88
+ }
89
+
90
+ async function initExpoCrypto(): Promise<typeof import('expo-crypto')> {
91
+ if (!ExpoCrypto) {
92
+ ExpoCrypto = await import('expo-crypto');
93
+ }
94
+ return ExpoCrypto;
95
+ }
96
+
97
+ /**
98
+ * Convert Uint8Array to hexadecimal string
99
+ * Works in both Node.js and React Native
100
+ */
101
+ function uint8ArrayToHex(bytes: Uint8Array): string {
102
+ return Array.from(bytes)
103
+ .map(b => b.toString(16).padStart(2, '0'))
104
+ .join('');
105
+ }
106
+
107
+ /**
108
+ * Generate cryptographically secure random bytes
109
+ */
110
+ async function getSecureRandomBytes(length: number): Promise<Uint8Array> {
111
+ // In React Native, always use expo-crypto
112
+ if (isReactNative() || !isNodeJS()) {
113
+ const Crypto = await initExpoCrypto();
114
+ return Crypto.getRandomBytes(length);
115
+ }
116
+
117
+ // In Node.js, use Node's crypto module
118
+ // Use Function constructor to prevent Metro bundler from statically analyzing this require
119
+ // This ensures the require is only evaluated in Node.js runtime, not during Metro bundling
120
+ try {
121
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
122
+ const getCrypto = new Function('return require("crypto")');
123
+ const crypto = getCrypto();
124
+ return new Uint8Array(crypto.randomBytes(length));
125
+ } catch (error) {
126
+ // Fallback to expo-crypto if Node crypto fails
127
+ const Crypto = await initExpoCrypto();
128
+ return Crypto.getRandomBytes(length);
129
+ }
130
+ }
131
+
132
+ export interface KeyPair {
133
+ publicKey: string;
134
+ privateKey: string;
135
+ }
136
+
137
+ export class KeyManager {
138
+ // In-memory cache for identity state (invalidated on identity changes)
139
+ private static cachedPublicKey: string | null = null;
140
+ private static cachedHasIdentity: boolean | null = null;
141
+ private static cachedSharedPublicKey: string | null = null;
142
+ private static cachedHasSharedIdentity: boolean | null = null;
143
+
144
+ /**
145
+ * Invalidate cached identity state
146
+ * Called internally when identity is created/deleted/imported
147
+ */
148
+ private static invalidateCache(): void {
149
+ KeyManager.cachedPublicKey = null;
150
+ KeyManager.cachedHasIdentity = null;
151
+ }
152
+
153
+ /**
154
+ * Invalidate cached shared identity state
155
+ * Called internally when shared identity is created/deleted/imported
156
+ */
157
+ private static invalidateSharedCache(): void {
158
+ KeyManager.cachedSharedPublicKey = null;
159
+ KeyManager.cachedHasSharedIdentity = null;
160
+ }
161
+
162
+ /**
163
+ * Generate a new ECDSA secp256k1 key pair
164
+ * Returns the keys in hexadecimal format
165
+ */
166
+ static generateKeyPairSync(): KeyPair {
167
+ const keyPair = ec.genKeyPair();
168
+ return {
169
+ privateKey: keyPair.getPrivate('hex'),
170
+ publicKey: keyPair.getPublic('hex'),
171
+ };
172
+ }
173
+
174
+ /**
175
+ * Generate a new key pair using secure random bytes
176
+ */
177
+ static async generateKeyPair(): Promise<KeyPair> {
178
+ const randomBytes = await getSecureRandomBytes(32);
179
+ const privateKeyHex = uint8ArrayToHex(randomBytes);
180
+ const keyPair = ec.keyFromPrivate(privateKeyHex);
181
+
182
+ return {
183
+ privateKey: keyPair.getPrivate('hex'),
184
+ publicKey: keyPair.getPublic('hex'),
185
+ };
186
+ }
187
+
188
+ // ==================== SHARED IDENTITY METHODS ====================
189
+ // These methods enable cross-app session sharing (like Google)
190
+ // iOS: Uses Keychain Access Groups
191
+ // Android: Uses Account Manager with shared user ID
192
+ // =================================================================
193
+
194
+ /**
195
+ * Create a shared identity accessible across all Oxy apps
196
+ *
197
+ * iOS: Stores in shared keychain group (requires entitlement configuration)
198
+ * Android: Stores in Account Manager (requires sharedUserId in manifest)
199
+ *
200
+ * This enables true cross-app SSO - when user signs in to one Oxy app,
201
+ * they're automatically signed in to all other Oxy apps.
202
+ *
203
+ * @returns Public key of the shared identity
204
+ * @throws Error if not on native platform or if sharing is not configured
205
+ */
206
+ static async createSharedIdentity(): Promise<string> {
207
+ if (isWebPlatform()) {
208
+ throw new Error('Shared identity is only available on native platforms (iOS/Android).');
209
+ }
210
+
211
+ const store = await initSecureStore();
212
+ const { privateKey, publicKey } = await KeyManager.generateKeyPair();
213
+
214
+ if (Platform.OS === 'ios') {
215
+ // iOS: Store in shared keychain group
216
+ // Note: keychainAccessGroup requires Keychain Sharing capability in Xcode
217
+ try {
218
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY, privateKey, {
219
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
220
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP, // This enables sharing across apps
221
+ } as any); // Type assertion: keychainAccessGroup may not be in older @types but is supported
222
+
223
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY, publicKey, {
224
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
225
+ } as any);
226
+ } catch (error) {
227
+ throw new Error(
228
+ `Failed to create shared identity on iOS. Ensure your app has the Keychain Sharing capability enabled with access group "${IOS_KEYCHAIN_GROUP}". Error: ${error}`
229
+ );
230
+ }
231
+ } else if (Platform.OS === 'android') {
232
+ // Android: Store in secure store (accessible via sharedUserId)
233
+ // Note: All Oxy apps must have the same sharedUserId in AndroidManifest.xml
234
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY, privateKey, {
235
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
236
+ });
237
+
238
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY, publicKey);
239
+ }
240
+
241
+ // Update cache
242
+ KeyManager.cachedSharedPublicKey = publicKey;
243
+ KeyManager.cachedHasSharedIdentity = true;
244
+
245
+ if (__DEV__) {
246
+ console.log('[KeyManager] Shared identity created successfully');
247
+ }
248
+
249
+ return publicKey;
250
+ }
251
+
252
+ /**
253
+ * Get the shared public key (accessible across all Oxy apps)
254
+ *
255
+ * @returns Shared public key or null if no shared identity exists
256
+ */
257
+ static async getSharedPublicKey(): Promise<string | null> {
258
+ if (isWebPlatform()) {
259
+ return null;
260
+ }
261
+
262
+ // Return cached value if available
263
+ if (KeyManager.cachedSharedPublicKey !== null) {
264
+ return KeyManager.cachedSharedPublicKey;
265
+ }
266
+
267
+ try {
268
+ const store = await initSecureStore();
269
+ let publicKey: string | null = null;
270
+
271
+ if (Platform.OS === 'ios') {
272
+ publicKey = await store.getItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY, {
273
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
274
+ } as any);
275
+ } else if (Platform.OS === 'android') {
276
+ publicKey = await store.getItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY);
277
+ }
278
+
279
+ // Cache result
280
+ KeyManager.cachedSharedPublicKey = publicKey;
281
+
282
+ return publicKey;
283
+ } catch (error) {
284
+ if (__DEV__) {
285
+ console.warn('[KeyManager] Failed to get shared public key:', error);
286
+ }
287
+ KeyManager.cachedSharedPublicKey = null;
288
+ return null;
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Get the shared private key (for signing operations)
294
+ *
295
+ * WARNING: Only use this for signing operations within the app.
296
+ * The private key should NEVER be transmitted or exposed.
297
+ *
298
+ * @returns Shared private key or null if no shared identity exists
299
+ */
300
+ static async getSharedPrivateKey(): Promise<string | null> {
301
+ if (isWebPlatform()) {
302
+ return null;
303
+ }
304
+
305
+ try {
306
+ const store = await initSecureStore();
307
+ let privateKey: string | null = null;
308
+
309
+ if (Platform.OS === 'ios') {
310
+ privateKey = await store.getItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY, {
311
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
312
+ } as any);
313
+ } else if (Platform.OS === 'android') {
314
+ privateKey = await store.getItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY);
315
+ }
316
+
317
+ return privateKey;
318
+ } catch (error) {
319
+ if (__DEV__) {
320
+ console.warn('[KeyManager] Failed to get shared private key:', error);
321
+ }
322
+ return null;
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Check if a shared identity exists (accessible across all Oxy apps)
328
+ *
329
+ * @returns True if shared identity exists, false otherwise
330
+ */
331
+ static async hasSharedIdentity(): Promise<boolean> {
332
+ if (isWebPlatform()) {
333
+ return false;
334
+ }
335
+
336
+ // Return cached value if available
337
+ if (KeyManager.cachedHasSharedIdentity !== null) {
338
+ return KeyManager.cachedHasSharedIdentity;
339
+ }
340
+
341
+ try {
342
+ const privateKey = await KeyManager.getSharedPrivateKey();
343
+ const hasShared = privateKey !== null;
344
+
345
+ // Cache result
346
+ KeyManager.cachedHasSharedIdentity = hasShared;
347
+
348
+ return hasShared;
349
+ } catch (error) {
350
+ if (__DEV__) {
351
+ console.warn('[KeyManager] Failed to check shared identity:', error);
352
+ }
353
+ KeyManager.cachedHasSharedIdentity = false;
354
+ return false;
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Import an existing key pair as shared identity
360
+ *
361
+ * This is used when:
362
+ * 1. User signs in to a new Oxy app for the first time
363
+ * 2. User has existing identity on another Oxy app
364
+ * 3. We want to sync the identity across apps
365
+ *
366
+ * @param privateKey - Private key in hex format
367
+ * @returns Public key
368
+ */
369
+ static async importSharedIdentity(privateKey: string): Promise<string> {
370
+ if (isWebPlatform()) {
371
+ throw new Error('Shared identity import is only available on native platforms.');
372
+ }
373
+
374
+ const store = await initSecureStore();
375
+ const keyPair = ec.keyFromPrivate(privateKey);
376
+ const publicKey = keyPair.getPublic('hex');
377
+
378
+ if (Platform.OS === 'ios') {
379
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY, privateKey, {
380
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
381
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
382
+ } as any);
383
+
384
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY, publicKey, {
385
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
386
+ } as any);
387
+ } else if (Platform.OS === 'android') {
388
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PRIVATE_KEY, privateKey, {
389
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
390
+ });
391
+
392
+ await store.setItemAsync(STORAGE_KEYS.SHARED_PUBLIC_KEY, publicKey);
393
+ }
394
+
395
+ // Update cache
396
+ KeyManager.cachedSharedPublicKey = publicKey;
397
+ KeyManager.cachedHasSharedIdentity = true;
398
+
399
+ if (__DEV__) {
400
+ console.log('[KeyManager] Shared identity imported successfully');
401
+ }
402
+
403
+ return publicKey;
404
+ }
405
+
406
+ /**
407
+ * Store session information in shared storage
408
+ *
409
+ * This allows all Oxy apps to access the same session without
410
+ * re-authenticating. When user signs in to one app, all apps
411
+ * get the session automatically.
412
+ *
413
+ * @param sessionId - Session ID from authentication
414
+ * @param accessToken - Access token for API calls
415
+ */
416
+ static async storeSharedSession(sessionId: string, accessToken: string): Promise<void> {
417
+ if (isWebPlatform()) {
418
+ return; // Not supported on web
419
+ }
420
+
421
+ try {
422
+ const store = await initSecureStore();
423
+
424
+ if (Platform.OS === 'ios') {
425
+ await store.setItemAsync(STORAGE_KEYS.SHARED_SESSION_ID, sessionId, {
426
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
427
+ } as any);
428
+
429
+ await store.setItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN, accessToken, {
430
+ keychainAccessible: store.WHEN_UNLOCKED,
431
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
432
+ } as any);
433
+ } else if (Platform.OS === 'android') {
434
+ await store.setItemAsync(STORAGE_KEYS.SHARED_SESSION_ID, sessionId);
435
+ await store.setItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN, accessToken);
436
+ }
437
+
438
+ if (__DEV__) {
439
+ console.log('[KeyManager] Shared session stored successfully');
440
+ }
441
+ } catch (error) {
442
+ if (__DEV__) {
443
+ console.error('[KeyManager] Failed to store shared session:', error);
444
+ }
445
+ throw error;
446
+ }
447
+ }
448
+
449
+ /**
450
+ * Get shared session information
451
+ *
452
+ * This allows any Oxy app to check if user is already signed in
453
+ * via another Oxy app. Enables instant cross-app SSO.
454
+ *
455
+ * @returns Session data or null if no shared session exists
456
+ */
457
+ static async getSharedSession(): Promise<{ sessionId: string; accessToken: string } | null> {
458
+ if (isWebPlatform()) {
459
+ return null;
460
+ }
461
+
462
+ try {
463
+ const store = await initSecureStore();
464
+ let sessionId: string | null = null;
465
+ let accessToken: string | null = null;
466
+
467
+ if (Platform.OS === 'ios') {
468
+ sessionId = await store.getItemAsync(STORAGE_KEYS.SHARED_SESSION_ID, {
469
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
470
+ } as any);
471
+
472
+ accessToken = await store.getItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN, {
473
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
474
+ } as any);
475
+ } else if (Platform.OS === 'android') {
476
+ sessionId = await store.getItemAsync(STORAGE_KEYS.SHARED_SESSION_ID);
477
+ accessToken = await store.getItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN);
478
+ }
479
+
480
+ if (!sessionId || !accessToken) {
481
+ return null;
482
+ }
483
+
484
+ return { sessionId, accessToken };
485
+ } catch (error) {
486
+ if (__DEV__) {
487
+ console.warn('[KeyManager] Failed to get shared session:', error);
488
+ }
489
+ return null;
490
+ }
491
+ }
492
+
493
+ /**
494
+ * Clear shared session (on logout)
495
+ *
496
+ * This signs out the user from ALL Oxy apps simultaneously.
497
+ * Call this when user explicitly logs out.
498
+ */
499
+ static async clearSharedSession(): Promise<void> {
500
+ if (isWebPlatform()) {
501
+ return;
502
+ }
503
+
504
+ try {
505
+ const store = await initSecureStore();
506
+
507
+ if (Platform.OS === 'ios') {
508
+ await store.deleteItemAsync(STORAGE_KEYS.SHARED_SESSION_ID, {
509
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
510
+ } as any);
511
+ await store.deleteItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN, {
512
+ keychainAccessGroup: IOS_KEYCHAIN_GROUP,
513
+ } as any);
514
+ } else if (Platform.OS === 'android') {
515
+ await store.deleteItemAsync(STORAGE_KEYS.SHARED_SESSION_ID);
516
+ await store.deleteItemAsync(STORAGE_KEYS.SHARED_SESSION_TOKEN);
517
+ }
518
+
519
+ if (__DEV__) {
520
+ console.log('[KeyManager] Shared session cleared successfully');
521
+ }
522
+ } catch (error) {
523
+ if (__DEV__) {
524
+ console.error('[KeyManager] Failed to clear shared session:', error);
525
+ }
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Migrate local identity to shared identity
531
+ *
532
+ * Call this when upgrading existing apps to use shared identities.
533
+ * Copies the device-specific identity to shared storage so it can
534
+ * be accessed by other Oxy apps.
535
+ *
536
+ * @returns True if migration was successful, false if no local identity exists
537
+ */
538
+ static async migrateToSharedIdentity(): Promise<boolean> {
539
+ if (isWebPlatform()) {
540
+ return false;
541
+ }
542
+
543
+ try {
544
+ // Check if we already have a shared identity
545
+ const hasShared = await KeyManager.hasSharedIdentity();
546
+ if (hasShared) {
547
+ if (__DEV__) {
548
+ console.log('[KeyManager] Shared identity already exists, skipping migration');
549
+ }
550
+ return true;
551
+ }
552
+
553
+ // Get local identity
554
+ const privateKey = await KeyManager.getPrivateKey();
555
+ if (!privateKey) {
556
+ if (__DEV__) {
557
+ console.log('[KeyManager] No local identity to migrate');
558
+ }
559
+ return false;
560
+ }
561
+
562
+ // Import to shared storage
563
+ await KeyManager.importSharedIdentity(privateKey);
564
+
565
+ if (__DEV__) {
566
+ console.log('[KeyManager] Successfully migrated local identity to shared identity');
567
+ }
568
+
569
+ return true;
570
+ } catch (error) {
571
+ if (__DEV__) {
572
+ console.error('[KeyManager] Failed to migrate to shared identity:', error);
573
+ }
574
+ return false;
575
+ }
576
+ }
577
+
578
+ // ==================== END SHARED IDENTITY METHODS ====================
579
+
580
+ /**
581
+ * Generate and securely store a new key pair on the device
582
+ * Returns only the public key (private key is stored securely)
583
+ */
584
+ static async createIdentity(): Promise<string> {
585
+ if (isWebPlatform()) {
586
+ throw new Error('Identity creation is only available on native platforms (iOS/Android). Please use the native app to create your identity.');
587
+ }
588
+ const store = await initSecureStore();
589
+ const { privateKey, publicKey } = await KeyManager.generateKeyPair();
590
+
591
+ await store.setItemAsync(STORAGE_KEYS.PRIVATE_KEY, privateKey, {
592
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
593
+ });
594
+
595
+ await store.setItemAsync(STORAGE_KEYS.PUBLIC_KEY, publicKey);
596
+
597
+ // Update cache
598
+ KeyManager.cachedPublicKey = publicKey;
599
+ KeyManager.cachedHasIdentity = true;
600
+
601
+ return publicKey;
602
+ }
603
+
604
+ /**
605
+ * Import an existing key pair (e.g., from recovery phrase)
606
+ */
607
+ static async importKeyPair(privateKey: string): Promise<string> {
608
+ if (isWebPlatform()) {
609
+ throw new Error('Identity import is only available on native platforms (iOS/Android). Please use the native app to import your identity.');
610
+ }
611
+ const store = await initSecureStore();
612
+
613
+ const keyPair = ec.keyFromPrivate(privateKey);
614
+ const publicKey = keyPair.getPublic('hex');
615
+
616
+ await store.setItemAsync(STORAGE_KEYS.PRIVATE_KEY, privateKey, {
617
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
618
+ });
619
+ await store.setItemAsync(STORAGE_KEYS.PUBLIC_KEY, publicKey);
620
+
621
+ // Update cache
622
+ KeyManager.cachedPublicKey = publicKey;
623
+ KeyManager.cachedHasIdentity = true;
624
+
625
+ return publicKey;
626
+ }
627
+
628
+ /**
629
+ * Get the stored private key
630
+ * WARNING: Only use this for signing operations within the app
631
+ */
632
+ static async getPrivateKey(): Promise<string | null> {
633
+ if (isWebPlatform()) {
634
+ return null; // Identity storage is only available on native platforms
635
+ }
636
+ try {
637
+ const store = await initSecureStore();
638
+ return await store.getItemAsync(STORAGE_KEYS.PRIVATE_KEY);
639
+ } catch (error) {
640
+ // If secure store is not available, return null (no identity)
641
+ // This allows the app to continue functioning even if secure store fails to load
642
+ if (__DEV__) {
643
+ console.warn('[KeyManager] Failed to access secure store:', error);
644
+ }
645
+ return null;
646
+ }
647
+ }
648
+
649
+ /**
650
+ * Get the stored public key (cached for performance)
651
+ */
652
+ static async getPublicKey(): Promise<string | null> {
653
+ if (isWebPlatform()) {
654
+ return null; // Identity storage is only available on native platforms
655
+ }
656
+ if (KeyManager.cachedPublicKey !== null) {
657
+ return KeyManager.cachedPublicKey;
658
+ }
659
+
660
+ try {
661
+ const store = await initSecureStore();
662
+ const publicKey = await store.getItemAsync(STORAGE_KEYS.PUBLIC_KEY);
663
+
664
+ // Cache result (null is a valid cache value meaning no identity)
665
+ KeyManager.cachedPublicKey = publicKey;
666
+
667
+ return publicKey;
668
+ } catch (error) {
669
+ // If secure store is not available, return null (no identity)
670
+ // Cache null to avoid repeated failed attempts
671
+ KeyManager.cachedPublicKey = null;
672
+ if (__DEV__) {
673
+ console.warn('[KeyManager] Failed to access secure store:', error);
674
+ }
675
+ return null;
676
+ }
677
+ }
678
+
679
+ /**
680
+ * Check if an identity (key pair) exists on this device (cached for performance)
681
+ */
682
+ static async hasIdentity(): Promise<boolean> {
683
+ if (isWebPlatform()) {
684
+ return false; // Identity storage is only available on native platforms
685
+ }
686
+ if (KeyManager.cachedHasIdentity !== null) {
687
+ return KeyManager.cachedHasIdentity;
688
+ }
689
+
690
+ try {
691
+ const privateKey = await KeyManager.getPrivateKey();
692
+ const hasIdentity = privateKey !== null;
693
+
694
+ // Cache result
695
+ KeyManager.cachedHasIdentity = hasIdentity;
696
+
697
+ return hasIdentity;
698
+ } catch (error) {
699
+ // If we can't check, assume no identity (safer default)
700
+ // Cache false to avoid repeated failed attempts
701
+ KeyManager.cachedHasIdentity = false;
702
+ if (__DEV__) {
703
+ console.warn('[KeyManager] Failed to check identity:', error);
704
+ }
705
+ return false;
706
+ }
707
+ }
708
+
709
+ /**
710
+ * Delete the stored identity (both keys)
711
+ * Use with EXTREME caution - this is irreversible without a recovery phrase
712
+ * This should ONLY be called when explicitly requested by the user
713
+ * @param skipBackup - If true, skip backup before deletion (default: false)
714
+ * @param force - If true, skip confirmation checks (default: false)
715
+ * @param userConfirmed - If true, user has explicitly confirmed deletion (default: false)
716
+ */
717
+ static async deleteIdentity(
718
+ skipBackup: boolean = false,
719
+ force: boolean = false,
720
+ userConfirmed: boolean = false
721
+ ): Promise<void> {
722
+ if (isWebPlatform()) {
723
+ return; // Identity storage is only available on native platforms, nothing to delete
724
+ }
725
+ // CRITICAL SAFEGUARD: Require explicit user confirmation unless force is true
726
+ if (!force && !userConfirmed) {
727
+ throw new Error('Identity deletion requires explicit user confirmation. This is a safety measure to prevent accidental data loss.');
728
+ }
729
+
730
+ if (!force) {
731
+ const hasIdentity = await KeyManager.hasIdentity();
732
+ if (!hasIdentity) {
733
+ return; // Nothing to delete
734
+ }
735
+ }
736
+
737
+ const store = await initSecureStore();
738
+
739
+ // ALWAYS create backup before deletion unless explicitly skipped
740
+ if (!skipBackup) {
741
+ try {
742
+ const backupSuccess = await KeyManager.backupIdentity();
743
+ if (!backupSuccess && typeof __DEV__ !== 'undefined' && __DEV__) {
744
+ console.warn('[KeyManager] Failed to backup identity before deletion - proceeding anyway');
745
+ }
746
+ } catch (backupError) {
747
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
748
+ console.warn('[KeyManager] Failed to backup identity before deletion:', backupError);
749
+ }
750
+ }
751
+ }
752
+
753
+ await store.deleteItemAsync(STORAGE_KEYS.PRIVATE_KEY);
754
+ await store.deleteItemAsync(STORAGE_KEYS.PUBLIC_KEY);
755
+
756
+ // Invalidate cache
757
+ KeyManager.invalidateCache();
758
+
759
+ // Also clear backup if force deletion
760
+ if (force) {
761
+ try {
762
+ await store.deleteItemAsync(STORAGE_KEYS.BACKUP_PRIVATE_KEY);
763
+ await store.deleteItemAsync(STORAGE_KEYS.BACKUP_PUBLIC_KEY);
764
+ await store.deleteItemAsync(STORAGE_KEYS.BACKUP_TIMESTAMP);
765
+ } catch (error) {
766
+ // Ignore backup deletion errors
767
+ }
768
+ }
769
+ }
770
+
771
+ /**
772
+ * Backup identity to SecureStore (separate backup storage)
773
+ * This provides a recovery mechanism if primary storage fails
774
+ */
775
+ static async backupIdentity(): Promise<boolean> {
776
+ if (isWebPlatform()) {
777
+ return false; // Identity storage is only available on native platforms
778
+ }
779
+ try {
780
+ const store = await initSecureStore();
781
+ const privateKey = await KeyManager.getPrivateKey();
782
+ const publicKey = await KeyManager.getPublicKey();
783
+
784
+ if (!privateKey || !publicKey) {
785
+ return false; // Nothing to backup
786
+ }
787
+
788
+ // Store backup in SecureStore (still secure, but separate from primary storage)
789
+ await store.setItemAsync(STORAGE_KEYS.BACKUP_PRIVATE_KEY, privateKey, {
790
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
791
+ });
792
+ await store.setItemAsync(STORAGE_KEYS.BACKUP_PUBLIC_KEY, publicKey);
793
+ await store.setItemAsync(STORAGE_KEYS.BACKUP_TIMESTAMP, Date.now().toString());
794
+
795
+ return true;
796
+ } catch (error) {
797
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
798
+ console.error('[KeyManager] Failed to backup identity:', error);
799
+ }
800
+ return false;
801
+ }
802
+ }
803
+
804
+ /**
805
+ * Verify identity integrity - checks if keys are valid and accessible
806
+ */
807
+ static async verifyIdentityIntegrity(): Promise<boolean> {
808
+ if (isWebPlatform()) {
809
+ return false; // Identity storage is only available on native platforms
810
+ }
811
+ try {
812
+ const privateKey = await KeyManager.getPrivateKey();
813
+ const publicKey = await KeyManager.getPublicKey();
814
+
815
+ if (!privateKey || !publicKey) {
816
+ return false;
817
+ }
818
+
819
+ // Validate private key format
820
+ if (!KeyManager.isValidPrivateKey(privateKey)) {
821
+ return false;
822
+ }
823
+
824
+ // Validate public key format
825
+ if (!KeyManager.isValidPublicKey(publicKey)) {
826
+ return false;
827
+ }
828
+
829
+ // Verify public key can be derived from private key
830
+ const derivedPublicKey = KeyManager.derivePublicKey(privateKey);
831
+ if (derivedPublicKey !== publicKey) {
832
+ return false; // Keys don't match
833
+ }
834
+
835
+ // Verify we can create a key pair object (tests elliptic curve operations)
836
+ const keyPair = await KeyManager.getKeyPairObject();
837
+ if (!keyPair) {
838
+ return false;
839
+ }
840
+
841
+ return true;
842
+ } catch (error) {
843
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
844
+ console.error('[KeyManager] Identity integrity check failed:', error);
845
+ }
846
+ return false;
847
+ }
848
+ }
849
+
850
+ /**
851
+ * Restore identity from backup if primary storage is corrupted
852
+ */
853
+ static async restoreIdentityFromBackup(): Promise<boolean> {
854
+ if (isWebPlatform()) {
855
+ return false; // Identity storage is only available on native platforms
856
+ }
857
+ try {
858
+ const store = await initSecureStore();
859
+
860
+ // Check if backup exists
861
+ const backupPrivateKey = await store.getItemAsync(STORAGE_KEYS.BACKUP_PRIVATE_KEY);
862
+ const backupPublicKey = await store.getItemAsync(STORAGE_KEYS.BACKUP_PUBLIC_KEY);
863
+
864
+ if (!backupPrivateKey || !backupPublicKey) {
865
+ return false; // No backup available
866
+ }
867
+
868
+ // Verify backup integrity
869
+ if (!KeyManager.isValidPrivateKey(backupPrivateKey)) {
870
+ return false;
871
+ }
872
+
873
+ if (!KeyManager.isValidPublicKey(backupPublicKey)) {
874
+ return false;
875
+ }
876
+
877
+ // Verify keys match
878
+ const derivedPublicKey = KeyManager.derivePublicKey(backupPrivateKey);
879
+ if (derivedPublicKey !== backupPublicKey) {
880
+ return false; // Backup keys don't match
881
+ }
882
+
883
+ await store.setItemAsync(STORAGE_KEYS.PRIVATE_KEY, backupPrivateKey, {
884
+ keychainAccessible: store.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
885
+ });
886
+ await store.setItemAsync(STORAGE_KEYS.PUBLIC_KEY, backupPublicKey);
887
+
888
+ const restored = await KeyManager.verifyIdentityIntegrity();
889
+ if (restored) {
890
+ // Update cache
891
+ KeyManager.cachedPublicKey = backupPublicKey;
892
+ KeyManager.cachedHasIdentity = true;
893
+
894
+ await store.setItemAsync(STORAGE_KEYS.BACKUP_TIMESTAMP, Date.now().toString());
895
+ return true;
896
+ }
897
+
898
+ return false;
899
+ } catch (error) {
900
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
901
+ console.error('[KeyManager] Failed to restore identity from backup:', error);
902
+ }
903
+ return false;
904
+ }
905
+ }
906
+
907
+ /**
908
+ * Get the elliptic curve key object from the stored private key
909
+ * Used internally for signing operations
910
+ */
911
+ static async getKeyPairObject(): Promise<ECKeyPair | null> {
912
+ if (isWebPlatform()) {
913
+ return null; // Identity storage is only available on native platforms
914
+ }
915
+ const privateKey = await KeyManager.getPrivateKey();
916
+ if (!privateKey) return null;
917
+ return ec.keyFromPrivate(privateKey);
918
+ }
919
+
920
+ /**
921
+ * Derive public key from a private key (without storing)
922
+ */
923
+ static derivePublicKey(privateKey: string): string {
924
+ const keyPair = ec.keyFromPrivate(privateKey);
925
+ return keyPair.getPublic('hex');
926
+ }
927
+
928
+ /**
929
+ * Validate that a string is a valid public key
930
+ */
931
+ static isValidPublicKey(publicKey: string): boolean {
932
+ try {
933
+ ec.keyFromPublic(publicKey, 'hex');
934
+ return true;
935
+ } catch {
936
+ return false;
937
+ }
938
+ }
939
+
940
+ /**
941
+ * Validate that a string is a valid private key
942
+ */
943
+ static isValidPrivateKey(privateKey: string): boolean {
944
+ try {
945
+ const keyPair = ec.keyFromPrivate(privateKey);
946
+ // Verify it can derive a public key
947
+ keyPair.getPublic('hex');
948
+ return true;
949
+ } catch {
950
+ return false;
951
+ }
952
+ }
953
+
954
+ /**
955
+ * Get a shortened version of the public key for display
956
+ * Format: first 8 chars...last 8 chars
957
+ */
958
+ static shortenPublicKey(publicKey: string): string {
959
+ if (publicKey.length <= 20) return publicKey;
960
+ return `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}`;
961
+ }
962
+ }
963
+
964
+ export default KeyManager;
965
+
966
+