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