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